Make WordPress Core

Changeset 114


Ignore:
Timestamp:
05/29/2003 02:04:30 PM (22 years ago)
Author:
saxmatt
Message:

ezSQL mods.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/b2-include/b2functions.php

    r111 r114  
    433433        $sql = "SELECT * FROM $tableposts WHERE $showcatzero post_date <= '$now' ORDER BY post_date DESC LIMIT 1";
    434434        $result = mysql_query($sql) or die("Your SQL query: <br />$sql<br /><br />MySQL said:<br />".mysql_error());
    435         $querycount++;
     435        ++$querycount;
    436436        $myrow = mysql_fetch_object($result);
    437437        $lastpostdate = $myrow->post_date;
     
    460460        $result = mysql_query($sql) or die("Your SQL query: <br />$sql<br /><br />MySQL said:<br />".mysql_error());
    461461        $myrow = mysql_fetch_array($result);
    462         $querycount++;
     462        ++$querycount;
    463463        $cache_userdata[$userid] = $myrow;
    464464    } else {
     
    469469
    470470function get_userdata2($userid) { // for team-listing
    471     global $tableusers,$row;
     471    global $tableusers,$post;
    472472    $user_data['ID'] = $userid;
    473     $user_data['user_login'] = $row->user_login;
    474     $user_data['user_firstname'] = $row->user_firstname;
    475     $user_data['user_lastname'] = $row->user_lastname;
    476     $user_data['user_nickname'] = $row->user_nickname;
    477     $user_data['user_level'] = $row->user_level;
    478     $user_data['user_email'] = $row->user_email;
    479     $user_data['user_url'] = $row->user_url;
     473    $user_data['user_login'] = $post->user_login;
     474    $user_data['user_firstname'] = $post->user_firstname;
     475    $user_data['user_lastname'] = $post->user_lastname;
     476    $user_data['user_nickname'] = $post->user_nickname;
     477    $user_data['user_level'] = $post->user_level;
     478    $user_data['user_email'] = $post->user_email;
     479    $user_data['user_url'] = $post->user_url;
    480480    return($user_data);
    481481}
     
    488488        if (!$result)   die($sql."<br /><br />".mysql_error());
    489489        $myrow = mysql_fetch_array($result);
    490         $querycount++;
     490        ++$querycount;
    491491        $cache_userdata["$user_login"] = $myrow;
    492492    } else {
     
    502502        $result = mysql_query($sql) or die("No user with the login <i>$user_login</i>");
    503503        $myrow = mysql_fetch_array($result);
    504         $querycount++;
     504        ++$querycount;
    505505        $cache_userdata["$user_login"] = $myrow;
    506506    } else {
     
    514514    $sql = "SELECT * FROM $tableposts WHERE post_author = $userid";
    515515    $result = mysql_query($sql) or die("Your SQL query: <br />$sql<br /><br />MySQL said:<br />".mysql_error());
    516     $querycount++;
     516    ++$querycount;
    517517    return mysql_num_rows($result);
    518518}
    519519
    520520function get_settings($setting) {
    521     global $tablesettings,$querycount,$cache_settings,$use_cache;
     521    global $tablesettings, $wpdb, $cache_settings, $use_cache, $querycount;
    522522    if ((empty($cache_settings)) OR (!$use_cache)) {
    523         $sql = "SELECT * FROM $tablesettings";
    524         $result = mysql_query($sql) or die("Your SQL query: <br />$sql<br /><br />MySQL said:<br />".mysql_error());
    525         $querycount++;
    526         $myrow = mysql_fetch_object($result);
    527         $cache_settings = $myrow;
    528     } else {
    529         $myrow = $cache_settings;
    530     }
    531     return($myrow->$setting);
     523        $settings = $wpdb->get_row("SELECT * FROM $tablesettings");
     524        ++$querycount;
     525        $cache_settings = $settings;
     526    } else {
     527        $settings = $cache_settings;
     528    }
     529    return($settings->$setting);
    532530}
    533531
    534532function get_postdata($postid) {
    535     global $tableusers,$tablesettings,$tablecategories,$tableposts,$tablecomments,$querycount;
    536     $sql = "SELECT * FROM $tableposts WHERE ID = $postid";
    537     $result = mysql_query($sql) or die("Your SQL query: <br />$sql<br /><br />MySQL said:<br />".mysql_error());
    538     $querycount++;
    539     if (mysql_num_rows($result)) {
    540         $myrow = mysql_fetch_object($result);
    541         $postdata = array (
    542             'ID' => $myrow->ID,
    543             'Author_ID' => $myrow->post_author,
    544             'Date' => $myrow->post_date,
    545             'Content' => $myrow->post_content,
    546             'Excerpt' => $myrow->post_excerpt,
    547             'Title' => $myrow->post_title,
    548             'Category' => $myrow->post_category,
    549             );
    550         return($postdata);
    551     } else {
    552         return false;
    553     }
     533    global $tableusers, $tablesettings, $tablecategories, $tableposts, $tablecomments, $querycount, $wpdb;
     534    $post = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID = $postid");
     535    ++$querycount;
     536   
     537    $postdata = array (
     538        'ID' => $post->ID,
     539        'Author_ID' => $post->post_author,
     540        'Date' => $post->post_date,
     541        'Content' => $post->post_content,
     542        'Excerpt' => $post->post_excerpt,
     543        'Title' => $post->post_title,
     544        'Category' => $post->post_category,
     545    );
     546    return($postdata);
    554547}
    555548
    556549function get_postdata2($postid=0) { // less flexible, but saves mysql queries
    557     global $row;
     550    global $post;
    558551    $postdata = array (
    559         'ID' => $row->ID,
    560         'Author_ID' => $row->post_author,
    561         'Date' => $row->post_date,
    562         'Content' => $row->post_content,
    563         'Excerpt' => $row->post_excerpt,
    564         'Title' => $row->post_title,
    565         'Category' => $row->post_category,
    566 #       'Notify' => $row->post_notifycomments,
    567 #       'Clickable' => $row->post_make_clickable,
    568         'Karma' => $row->post_karma // this isn't used yet
     552        'ID' => $post->ID,
     553        'Author_ID' => $post->post_author,
     554        'Date' => $post->post_date,
     555        'Content' => $post->post_content,
     556        'Excerpt' => $post->post_excerpt,
     557        'Title' => $post->post_title,
     558        'Category' => $post->post_category,
     559#       'Notify' => $post->post_notifycomments,
     560#       'Clickable' => $post->post_make_clickable,
     561        'Karma' => $post->post_karma // this isn't used yet
    569562        );
    570563    return($postdata);
     
    572565
    573566function get_commentdata($comment_ID,$no_cache=0) { // less flexible, but saves mysql queries
    574     global $rowc,$id,$commentdata,$tablecomments,$querycount;
     567    global $postc,$id,$commentdata,$tablecomments,$querycount;
    575568    if ($no_cache) {
    576569        $query="SELECT * FROM $tablecomments WHERE comment_ID = $comment_ID";
    577570        $result=mysql_query($query);
    578         $querycount++;
     571        ++$querycount;
    579572        $myrow = mysql_fetch_array($result);
    580573    } else {
    581         $myrow['comment_ID']=$rowc->comment_ID;
    582         $myrow['comment_post_ID']=$rowc->comment_post_ID;
    583         $myrow['comment_author']=$rowc->comment_author;
    584         $myrow['comment_author_email']=$rowc->comment_author_email;
    585         $myrow['comment_author_url']=$rowc->comment_author_url;
    586         $myrow['comment_author_IP']=$rowc->comment_author_IP;
    587         $myrow['comment_date']=$rowc->comment_date;
    588         $myrow['comment_content']=$rowc->comment_content;
    589         $myrow['comment_karma']=$rowc->comment_karma;
     574        $myrow['comment_ID']=$postc->comment_ID;
     575        $myrow['comment_post_ID']=$postc->comment_post_ID;
     576        $myrow['comment_author']=$postc->comment_author;
     577        $myrow['comment_author_email']=$postc->comment_author_email;
     578        $myrow['comment_author_url']=$postc->comment_author_url;
     579        $myrow['comment_author_IP']=$postc->comment_author_IP;
     580        $myrow['comment_date']=$postc->comment_date;
     581        $myrow['comment_content']=$postc->comment_content;
     582        $myrow['comment_karma']=$postc->comment_karma;
    590583        if (strstr($myrow['comment_content'], '<trackback />')) {
    591584            $myrow['comment_type'] = 'trackback';
     
    605598        $result = mysql_query($sql) or die('Oops, couldn\'t query the db for categories.');
    606599        $querycount;
    607         while ($row = mysql_fetch_object($result)) {
    608             $cache_catnames[$row->cat_ID] = $row->cat_name;
     600        while ($post = mysql_fetch_object($result)) {
     601            $cache_catnames[$post->cat_ID] = $post->cat_name;
    609602        }
    610603    }
     
    622615    $query="SELECT * FROM $tablecategories";
    623616    $result=mysql_query($query);
    624     $querycount++;
     617    ++$querycount;
    625618    $width = ($mode=="sidebar") ? "100%" : "170px";
    626619    echo '<select name="post_category" style="width:'.$width.';" tabindex="2" id="category">';
    627     while($row = mysql_fetch_object($result)) {
    628         echo "<option value=\"".$row->cat_ID."\"";
    629         if ($row->cat_ID == $postdata["Category"])
     620    while($post = mysql_fetch_object($result)) {
     621        echo "<option value=\"".$post->cat_ID."\"";
     622        if ($post->cat_ID == $postdata["Category"])
    630623            echo " selected";
    631         echo ">".$row->cat_name."</option>";
     624        echo ">".$post->cat_name."</option>";
    632625    }
    633626    echo "</select>";
     
    892885    }
    893886    die();
    894 }
    895 
    896 // updates the RSS feed !
    897 function rss_update($blog_ID, $num_posts="", $file="./b2rss.xml") {
    898 
    899     global $use_rss, $b2_version, $querystring_start, $querystring_equal, $querystring_separator;
    900     global $admin_email,$blogname,$siteurl,$blogfilename,$blogdescription,$posts_per_rss,$rss_language;
    901     global $tableposts,$postdata,$row;
    902 
    903     if ($rss_language == '') {
    904         $rss_language = 'en';
    905     }
    906 
    907     if ($use_rss) {
    908 
    909         $num_posts = ($num_posts=="") ? $posts_per_rss : 5;
    910 
    911         $date_now = gmdate("D, d M Y H:i:s")." GMT";
    912 
    913         # let's build the rss file
    914         $rss = '';
    915 
    916         $rss .= '<?xml version="1.0"?'.">\n";
    917         $rss .= "<!-- generator=\"b2/$b2_version\" -->\n";
    918         $rss .= "<rss version=\"0.92\">\n";
    919         $rss .= "\t<channel>\n";
    920         $rss .= "\t\t<title>".convert_chars(strip_tags(get_bloginfo("name")),"unicode")."</title>\n";
    921         $rss .= "\t\t<link>".convert_chars(strip_tags(get_bloginfo("url")),"unicode")."</link>\n";
    922         $rss .= "\t\t<description>".convert_chars(strip_tags(get_bloginfo("description")),"unicode")."</description>\n";
    923         $rss .= "\t\t<lastBuildDate>$date_now</lastBuildDate>\n";
    924         $rss .= "\t\t<docs>http://backend.userland.com/rss092</docs>\n";
    925         $rss .= "\t\t<managingEditor>$admin_email</managingEditor>\n";
    926         $rss .= "\t\t<webMaster>$admin_email</webMaster>\n";
    927         $rss .= "\t\t<language>$rss_language</language>\n";
    928        
    929         $now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600)));
    930         $sql = "SELECT * FROM $tableposts WHERE post_date <= '$now' AND post_category > 0 ORDER BY post_date DESC LIMIT $num_posts";
    931         $result = mysql_query($sql) or die("Your SQL query: <br />$sql<br /><br />MySQL said:<br />".mysql_error());
    932 
    933         while($row = mysql_fetch_object($result)) {
    934 
    935             $id = $row->ID;
    936             $postdata=get_postdata2($id);
    937 
    938             $rss .= "\t\t<item>\n";
    939             $rss .= "\t\t\t<title>".convert_chars(strip_tags(get_the_title()),"unicode")."</title>\n";
    940 
    941 //      we could add some specific RSS here, but not yet. uncomment if you wish, it's functionnal
    942 //          $rss .= "\t\t\t<category>".convert_chars(strip_tags(get_the_category()),"unicode")."</category>\n";
    943 
    944             $content = stripslashes($row->post_content);
    945             $content = explode("<!--more-->",$content);
    946             $content = $content[0];
    947             $rss .= "\t\t\t<description>".convert_chars(make_url_footnote($content),"unicode")."</description>\n";
    948 
    949             $rss .= "\t\t\t<link>".htmlentities("$siteurl/$blogfilename".$querystring_start.'p'.$querystring_equal.$row->ID.$querystring_separator.'c'.$querystring_equal.'1')."</link>\n";
    950             $rss .= "\t\t</item>\n";
    951 
    952         }
    953 
    954         $rss .= "\t</channel>\n";
    955         $rss .= "</rss>";
    956 
    957         $f=@fopen("$file","w+");
    958         if ($f) {
    959             @fwrite($f,$rss);
    960             @fclose($f);
    961 
    962             return(true);
    963         } else {
    964             return(false);
    965         }
    966     } else {
    967         return(false);
    968     }
    969887}
    970888
  • trunk/b2-include/b2template.functions.php

    r91 r114  
    7272}
    7373
    74 function single_post_title($prefix = '', $display = 1) {
     74function single_post_title($prefix = '', $display = true) {
    7575    global $p;
    7676    if (intval($p)) {
     
    8686}
    8787
    88 function single_cat_title($prefix = '', $display = 1 ) {
     88function single_cat_title($prefix = '', $display = true ) {
    8989    global $cat;
    9090    if(!empty($cat) && !(strtoupper($cat) == 'ALL')) {
     
    9999}
    100100
    101 function single_month_title($prefix = '', $display = 1 ) {
     101function single_month_title($prefix = '', $display = true ) {
    102102    global $m, $month;
    103103    if(!empty($m)) {
     
    112112
    113113function get_archives($type, $limit='') {
    114     global $tableposts, $dateformat, $time_difference, $siteurl, $blogfilename, $querystring_start, $querystring_equal, $month;
     114    global $tableposts, $dateformat, $time_difference, $siteurl, $blogfilename, $querystring_start, $querystring_equal, $month, $wpdb;
    115115    // weekly and daily are *broken*
    116     dbconnect();
    117116    if ('' != $limit) {
    118117        $limit = (int) $limit;
     
    131130    $now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600)));
    132131   
    133     if ($type == 'monthly') {
    134         $arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date) FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC" . $limit;
    135         $querycount++;
    136         $arc_result=mysql_query($arc_sql) or die($arc_sql.'<br />'.mysql_error());
    137         while($arc_row = mysql_fetch_array($arc_result)) {
    138             $arc_year  = $arc_row['YEAR(post_date)'];
    139             $arc_month = $arc_row['MONTH(post_date)'];
    140             echo "<li><a href=\"$archive_link_m$arc_year".zeroise($arc_month,2).'">';
    141             echo $month[zeroise($arc_month,2)].' '.$arc_year;
     132    if ('monthly' == $type) {
     133        ++$querycount;
     134        $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month` FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC" . $limit);
     135        foreach ($arcresults as $arcresult) {
     136            echo "<li><a href=\"$archive_link_m$arcresult->year".zeroise($arcresult->month, 2).'">';
     137            echo $month[zeroise($arcresult->month, 2)].' '.$arcresult->year;
    142138            echo "</a></li>\n";
    143139        }
    144     } elseif ($type == 'daily') {
    145         $arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC" . $limit;
    146         $querycount++;
    147         $arc_result=mysql_query($arc_sql) or die($arc_sql.'<br />'.mysql_error());
    148         while($arc_row = mysql_fetch_array($arc_result)) {
    149             $arc_year  = $arc_row['YEAR(post_date)'];
    150             $arc_month = $arc_row['MONTH(post_date)'];
    151             $arc_dayofmonth = $arc_row['DAYOFMONTH(post_date)'];
    152             echo "<li><a href=\"$archive_link_m$arc_year".zeroise($arc_month,2).zeroise($arc_dayofmonth,2).'">';
    153             echo mysql2date($archive_day_date_format, $arc_year.'-'.zeroise($arc_month,2).'-'.zeroise($arc_dayofmonth,2).' 00:00:00');
     140    } elseif ('daily' == $type) {
     141        ++$querycount;
     142        $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth` FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC" . $limit);
     143        foreach ($arcresults as $arcresult) {
     144            echo "<li><a href=\"$archive_link_m$arcresult->year".zeroise($arcresult->month, 2).zeroise($arcresult->dayofmonth, 2).'">';
     145            echo mysql2date($archive_day_date_format, $arcresult->year.'-'.zeroise($arcresult->month,2).'-'.zeroise($arcresult->dayofmonth,2).' 00:00:00');
    154146            echo "</a></li>\n";
    155147        }
    156     } elseif ($type == 'weekly') {
     148    } elseif ('weekly' == $type) {
    157149        if (!isset($start_of_week)) {
    158150            $start_of_week = 1;
    159151        }
    160         $arc_sql = "SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date), WEEK(post_date) FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC" . $limit;
    161         $querycount++;
    162         $arc_result=mysql_query($arc_sql) or die($arc_sql.'<br />'.mysql_error());
     152        ++$querycount;
     153        $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, WEEK(post_date) AS `week` FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC" . $limit);
    163154        $arc_w_last = '';
    164         while($arc_row = mysql_fetch_array($arc_result)) {
    165             $arc_year = $arc_row['YEAR(post_date)'];
    166             $arc_w = $arc_row['WEEK(post_date)'];
    167             if ($arc_w != $arc_w_last) {
    168                 $arc_w_last = $arc_w;
    169                 $arc_ymd = $arc_year.'-'.zeroise($arc_row['MONTH(post_date)'],2).'-' .zeroise($arc_row['DAYOFMONTH(post_date)'],2);
     155        foreach ($arcresults as $arcresult) {
     156            if ($arcresult->week != $arc_w_last) {
     157                $arc_w_last = $arcresult->week;
     158                $arc_ymd = $arcresult->year.'-'.zeroise($arcresult->month, 2).'-' .zeroise($arcresult->dayofmonth, 2);
    170159                $arc_week = get_weekstartend($arc_ymd, $start_of_week);
    171160                $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
    172161                $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
    173                 echo "<li><a href=\"$siteurl/".$blogfilename."?m=$arc_year&amp;w=$arc_w\">";
     162                echo "<li><a href='$siteurl/".$blogfilename."?m=$arc_year&amp;w=$arc_w'>";
    174163                echo $arc_week_start.$archive_week_separator.$arc_week_end;
    175164                echo "</a></li>\n";
    176165            }
    177166        }
    178     } elseif ($type == 'postbypost') {
    179         $requestarc = " SELECT ID,post_date,post_title FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC" . $limit;
    180         $querycount++;
    181         $resultarc = mysql_query($requestarc);
    182         while($row=mysql_fetch_object($resultarc)) {
    183             if ($row->post_date != '0000-00-00 00:00:00') {
    184                 echo "<li><a href=\"$archive_link_p".$row->ID.'">';
    185                 $arc_title = stripslashes($row->post_title);
     167    } elseif ('postbypost' == $type) {
     168        ++$querycount;
     169        $arcresults = $wpdb->get_results("SELECT ID, post_date, post_title FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC" . $limit);
     170        foreach ($arcresults as $arcresult) {
     171            if ($arcresult->post_date != '0000-00-00 00:00:00') {
     172                echo "<li><a href=\"$archive_link_p".$arcresult->ID.'">';
     173                $arc_title = stripslashes($arcresult->post_title);
    186174                if ($arc_title) {
    187175                    echo strip_tags($arc_title);
    188176                } else {
    189                     echo $row->ID;
     177                    echo $arcresult->ID;
    190178                }
    191179                echo "</a></li>\n";
     
    201189/***** Date/Time tags *****/
    202190
    203 function the_date($d='', $before='', $after='', $echo = 1) {
    204     global $id, $postdata, $day, $previousday,$dateformat,$newday;
     191function the_date($d='', $before='', $after='', $echo = true) {
     192    global $id, $postdata, $day, $previousday, $dateformat, $newday;
    205193    $the_date = '';
    206194    if ($day != $previousday) {
     
    222210}
    223211
    224 function the_time($d='', $echo = 1) {
     212function the_time($d='', $echo = true) {
    225213    global $id,$postdata,$timeformat;
    226214    if ($d=='') {
     
    365353}
    366354function get_the_title() {
    367     global $id,$postdata;
     355    global $id, $postdata;
    368356    $output = stripslashes($postdata['Title']);
    369357    $output = apply_filters('the_title', $output);
     
    613601
    614602        $query = @mysql_query($sql);
    615         $querycount++;
     603        ++$querycount;
    616604        if (($query) && (mysql_num_rows($query))) {
    617605            $p_info = mysql_fetch_object($query);
     
    658646
    659647        $query = @mysql_query($sql);
    660         $querycount++;
     648        ++$querycount;
    661649        if (($query) && (mysql_num_rows($query))) {
    662650            $p_info = mysql_fetch_object($query);
     
    806794        $query="SELECT cat_name FROM $tablecategories WHERE cat_ID = '$cat_ID'";
    807795        $result=mysql_query($query);
    808         $querycount++;
     796        ++$querycount;
    809797        $myrow = mysql_fetch_array($result);
    810798        $cat_name = $myrow[0];
     
    821809        $query="SELECT cat_name FROM $tablecategories WHERE cat_ID = '$cat_ID'";
    822810        $result=mysql_query($query);
    823         $querycount++;
     811        ++$querycount;
    824812        $myrow = mysql_fetch_array($result);
    825813        $cat_name = $myrow[0];
     
    851839    $query="SELECT * FROM $tablecategories";
    852840    $result=mysql_query($query);
    853     $querycount++;
     841    ++$querycount;
    854842    echo "<select name=\"cat\" class=\"postform\">\n";
    855843    if (intval($optionall) == 1) {
     
    874862    $query="SELECT * FROM $tablecategories WHERE cat_ID > 0 ORDER BY $sort_column $sort_order";
    875863    $result=mysql_query($query);
    876     $querycount++;
     864    ++$querycount;
    877865    if (intval($optionall) == 1) {
    878866        $all = apply_filters('list_cats', $all);
     
    910898
    911899// generic comments/trackbacks/pingbacks numbering
    912 function generic_ctp_number($post_id, $mode = 'comments') {
    913     global $postdata, $tablecomments, $querycount, $cache_ctp_number, $use_cache;
    914     if (!isset($cache_ctp_number[$post_id]) || (!$use_cache)) {
    915         $post_id = intval($post_id);
    916         $query = "SELECT * FROM $tablecomments WHERE comment_post_ID = $post_id";
    917         $result = mysql_query($query) or die('SQL query: '.$query.'<br />MySQL Error: '.mysql_error());
    918         $querycount++;
    919         $ctp_number = array();
    920         while($row = mysql_fetch_object($result)) {
    921             if (substr($row->comment_content, 0, 13) == '<trackback />') {
    922                 $ctp_number['trackbacks']++;
    923             } elseif (substr($row->comment_content, 0, 12) == '<pingback />') {
    924                 $ctp_number['pingbacks']++;
    925             } else {
    926                 $ctp_number['comments']++;
    927             }
    928             $ctp_number['ctp']++;
    929         }
    930         $cache_ctp_number[$post_id] = $ctp_number;
    931     } else {
    932         $ctp_number = $cache_ctp_number[$post_id];
    933     }
    934     if (($mode != 'comments') && ($mode != 'trackbacks') && ($mode != 'pingbacks') && ($mode != 'ctp')) {
    935         $mode = 'ctp';
    936     }
    937     return $ctp_number[$mode];
    938 }
    939 
    940 function comments_number($zero='no comment', $one='1 comment', $more='% comments') {
    941     // original hack by dodo@regretless.com
    942     global $id,$postdata,$tablecomments,$c,$querycount,$cache_commentsnumber,$use_cache;
    943     $number = generic_ctp_number($id, 'comments');
     900
     901function comments_number($zero='No Comments', $one='1 Comment', $more='% Comments') {
     902    global $id, $comment, $tablecomments, $querycount, $wpdb;
     903    $number = $wpdb->get_var("SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = $id");
    944904    if ($number == 0) {
    945905        $blah = $zero;
     
    947907        $blah = $one;
    948908    } elseif ($number  > 1) {
    949         $n = $number;
    950         $more=str_replace('%', $n, $more);
    951         $blah = $more;
     909        $blah = str_replace('%', $number, $more);
    952910    }
    953911    echo $blah;
    954912}
    955913
    956 function comments_link($file='',$echo=true) {
    957     global $id,$pagenow;
     914function comments_link($file='', $echo=true) {
     915    global $id, $pagenow;
    958916    global $querystring_start, $querystring_equal, $querystring_separator;
    959917    if ($file == '')    $file = $pagenow;
     
    963921}
    964922
    965 function comments_popup_script($width=400, $height=400, $file='b2commentspopup.php', $trackbackfile='b2trackbackpopup.php', $pingbackfile='b2pingbackspopup.php') {
     923function comments_popup_script($width=400, $height=400, $file='b2commentspopup.php') {
    966924    global $b2commentspopupfile, $b2trackbackpopupfile, $b2pingbackpopupfile, $b2commentsjavascript;
    967925    $b2commentspopupfile = $file;
    968     $b2trackbackpopupfile = $trackbackfile;
    969     $b2pingbackpopupfile = $pingbackfile;
    970926    $b2commentsjavascript = 1;
    971     $javascript = "<script language=\"javascript\" type=\"text/javascript\">\n<!--\nfunction b2open (macagna) {\n    window.open(macagna, '_blank', 'width=$width,height=$height,scrollbars=yes,status=yes');\n}\n//-->\n</script>\n";
     927    $javascript = "<script language='javascript' type='text/javascript'>\n<!--\nfunction b2open (macagna) {\n    window.open(macagna, '_blank', 'width=$width,height=$height,scrollbars=yes,status=yes');\n}\n//-->\n</script>\n";
    972928    echo $javascript;
    973929}
    974930
    975 function comments_popup_link($zero='no comment', $one='1 comment', $more='% comments', $CSSclass='') {
     931function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='') {
    976932    global $id, $b2commentspopupfile, $b2commentsjavascript;
    977933    global $querystring_start, $querystring_equal, $querystring_separator, $siteurl;
    978     echo '<a href="'.$siteurl.'/';
     934    echo "<a href=\"$siteurl/";
    979935    if ($b2commentsjavascript) {
    980936        echo $b2commentspopupfile.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'c'.$querystring_equal.'1';
    981         echo '" onclick="b2open(this.href); return false"';
     937        echo '\' onclick="b2open(this.href); return false"';
    982938    } else {
    983939        // if comments_popup_script() is not in the template, display simple comment link
     
    994950
    995951function comment_ID() {
    996     global $commentdata;    echo $commentdata['comment_ID'];
     952    global $comment;
     953    echo $comment->comment_ID;
    997954}
    998955
    999956function comment_author() {
    1000     global $commentdata;    echo stripslashes($commentdata['comment_author']);
     957    global $comment;
     958    echo stripslashes($comment->comment_author);
    1001959}
    1002960
    1003961function comment_author_email() {
    1004     global $commentdata;    echo antispambot(stripslashes($commentdata['comment_author_email']));
    1005 }
    1006 
     962    global $comment;
     963    echo antispambot(stripslashes($comment->comment_author_email));
     964}
     965
     966function comment_author_link() {
     967    global $comment;
     968    $url = trim(stripslashes(&$comment->comment_author_url));
     969    $email = &$comment->comment_author_email;
     970    $author = stripslashes(&$comment->comment_author);
     971
     972    $url = str_replace('http://url', '', $url);
     973   
     974    if (empty($url) && empty($email)) return $author;
     975    echo '<a href="';
     976    if ($url) {
     977        $url = str_replace(';//', '://', $url);
     978        $url = (!strstr($url, '://')) ? 'http://'.$url : $url;
     979        $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
     980        echo $url;
     981    } else {
     982        echo antispambot($email);
     983    }
     984    echo '" rel="external">' . $author . '</a>';
     985}
     986
     987function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') {
     988    global $comment;
     989    if (preg_match('|<trackback />|', $comment->comment_content)) echo $trackbacktxt;
     990    elseif (preg_match('|<pingback />|', $comment->comment_content)) echo $pingbacktxt;
     991    else echo $commenttxt;
     992}
    1007993function comment_author_url() {
    1008     global $commentdata;
    1009     $url = trim(stripslashes($commentdata['comment_author_url']));
    1010     $url = (!stristr($url, '://')) ? 'http://'.$url : $url;
     994    global $comment;
     995    $url = trim(stripslashes($comment->comment_author_url));
     996    $url = str_replace(';//', '://', $url);
     997    $url = (!strstr($url, '://')) ? 'http://'.$url : $url;
    1011998    // convert & into &amp;
    1012     $url = preg_replace('#&([^amp\;])#is', '&amp;$1', $url);
     999    $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
    10131000    if ($url != 'http://url') {
    10141001        echo $url;
     
    10171004
    10181005function comment_author_email_link($linktext='', $before='', $after='') {
    1019     global $commentdata;
    1020     $email=$commentdata['comment_author_email'];
     1006    global $comment;
     1007    $email = $comment->comment_author_email;
    10211008    if ((!empty($email)) && ($email != '@')) {
    10221009        $display = ($linktext != '') ? $linktext : antispambot(stripslashes($email));
     
    10281015
    10291016function comment_author_url_link($linktext='', $before='', $after='') {
    1030     global $commentdata;
    1031     $url = trim(stripslashes($commentdata['comment_author_url']));
    1032     $url = preg_replace('#&([^amp\;])#is', '&amp;$1', $url);
     1017    global $comment;
     1018    $url = trim(stripslashes($comment->comment_author_url));
     1019    $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
    10331020    $url = (!stristr($url, '://')) ? 'http://'.$url : $url;
    10341021    if ((!empty($url)) && ($url != 'http://') && ($url != 'http://url')) {
     
    10411028
    10421029function comment_author_IP() {
    1043     global $commentdata;    echo stripslashes($commentdata['comment_author_IP']);
     1030    global $comment;
     1031    echo stripslashes($comment->comment_author_IP);
    10441032}
    10451033
    10461034function comment_text() {
    1047     global $commentdata;
    1048     $comment = stripslashes($commentdata['comment_content']);
    1049     $comment = str_replace('<trackback />', '', $comment);
    1050     $comment = str_replace('<pingback />', '', $comment);
    1051     $comment = convert_chars($comment);
    1052     $comment = convert_bbcode($comment);
    1053     $comment = convert_gmcode($comment);
    1054     $comment = convert_smilies($comment);
    1055     $comment = make_clickable($comment);
    1056     $comment = balanceTags($comment);
    1057     $comment = apply_filters('comment_text', $comment);
    1058     echo $comment;
     1035    global $comment;
     1036    $comment_text = stripslashes($comment->comment_content);
     1037    $comment_text = str_replace('<trackback />', '', $comment_text);
     1038    $comment_text = str_replace('<pingback />', '', $comment_text);
     1039    $comment_text = convert_chars($comment_text);
     1040    $comment_text = convert_bbcode($comment_text);
     1041    $comment_text = convert_gmcode($comment_text);
     1042    $comment_text = convert_smilies($comment_text);
     1043    $comment_text = make_clickable($comment_text);
     1044    $comment_text = balanceTags($comment_text);
     1045    $comment_text = apply_filters('comment_text', $comment_text);
     1046    echo $comment_text;
    10591047}
    10601048
    10611049function comment_date($d='') {
    1062     global $commentdata,$dateformat;
     1050    global $comment, $dateformat;
    10631051    if ($d == '') {
    1064         echo mysql2date($dateformat, $commentdata['comment_date']);
    1065     } else {
    1066         echo mysql2date($d, $commentdata['comment_date']);
     1052        echo mysql2date($dateformat, $comment->comment_date);
     1053    } else {
     1054        echo mysql2date($d, $comment->comment_date);
    10671055    }
    10681056}
    10691057
    10701058function comment_time($d='') {
    1071     global $commentdata,$timeformat;
     1059    global $comment, $timeformat;
    10721060    if ($d == '') {
    1073         echo mysql2date($timeformat, $commentdata['comment_date']);
    1074     } else {
    1075         echo mysql2date($d, $commentdata['comment_date']);
     1061        echo mysql2date($timeformat, $comment->comment_date);
     1062    } else {
     1063        echo mysql2date($d, $comment->comment_date);
    10761064    }
    10771065}
     
    10831071/***** TrackBack tags *****/
    10841072
    1085 function trackback_url($display = 1) {
     1073function trackback_url($display = true) {
    10861074    global $siteurl, $id;
    10871075    $tb_url = $siteurl.'/b2trackback.php/'.$id;
     
    12851273
    12861274function start_b2() {
    1287     global $row, $id, $postdata, $authordata, $day, $preview, $page, $pages, $multipage, $more, $numpages;
     1275    global $post, $id, $postdata, $authordata, $day, $preview, $page, $pages, $multipage, $more, $numpages;
    12881276    global $preview_userid,$preview_date,$preview_content,$preview_title,$preview_category,$preview_notify,$preview_make_clickable,$preview_autobr;
    12891277    global $pagenow;
    12901278    global $HTTP_GET_VARS;
    12911279    if (!$preview) {
    1292         $id = $row->ID;
     1280        $id = $post->ID;
    12931281        $postdata=get_postdata2($id);
    12941282    } else {
  • trunk/b2-include/wp-db.php

    r112 r114  
    99    //  We have modified the HTML it returns slightly.
    1010
    11     define('EZSQL_DB_USER', "");            // <-- mysql db user
    12     define('EZSQL_DB_PASSWORD', "");        // <-- mysql db password
    13     define('EZSQL_DB_NAME', "mysql");       // <-- mysql db pname
    14     define('EZSQL_DB_HOST', 'localhost');   // <-- mysql server host
    15 
    1611    define('EZSQL_VERSION', '1.21');
    1712    define('OBJECT', 'OBJECT', true);
     
    400395    }
    401396
    402 $wpdb = new wpdb(EZSQL_DB_USER, EZSQL_DB_PASSWORD, EZSQL_DB_NAME, EZSQL_DB_HOST);
     397$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
    403398
    404399?>
  • trunk/b2comments.post.php

    r96 r114  
    99include($abspath.$b2inc.'/b2functions.php');
    1010
    11 dbconnect();
    1211
    1312function add_magic_quotes($array) {
     
    7473
    7574/* flood-protection */
    76 $query = "SELECT * FROM $tablecomments WHERE comment_author_IP='$user_ip' ORDER BY comment_date DESC LIMIT 1";
    77 $result = mysql_query($query);
     75$lasttime = $wpdb->get_var("SELECT comment_date FROM $tablecomments WHERE comment_author_IP = '$user_ip' ORDER BY comment_date DESC LIMIT 1");
    7876$ok=1;
    79 if (!empty($result)) {
    80     while($row = mysql_fetch_object($result)) {
    81         $then=$row->comment_date;
    82     }
    83     $time_lastcomment=mysql2date("U","$then");
    84     $time_newcomment=mysql2date("U","$now");
     77if (!empty($lasttime)) {
     78    $time_lastcomment= mysql2date('U', $lasttime);
     79    $time_newcomment= mysql2date('U', "$now");
    8580    if (($time_newcomment - $time_lastcomment) < 30)
    8681        $ok=0;
     
    9085if ($ok) {
    9186
    92     $query = "INSERT INTO $tablecomments VALUES ('0','$comment_post_ID','$author','$email','$url','$user_ip','$now','$comment','0')";
    93     $result = mysql_query($query);
    94     if (!$result)
    95         die ("There is an error with the database, it can&#8217;t store your comment...<br />Contact the <a href=\"mailto:$admin_email\">webmaster</a>.");
     87    $wpdb->query("INSERT INTO $tablecomments VALUES ('0','$comment_post_ID','$author','$email','$url','$user_ip','$now','$comment','0')");
    9688
    9789    if ($comments_notify) {
     
    111103        $subject = "[$blogname] Comment: \"".stripslashes($postdata['Title']).'"';
    112104
    113         @mail($recipient, $subject, $notify_message, "From: \"$comment_author\" <$comment_author_email>\r\n"."X-Mailer: wordpress $b2_version with PHP/".phpversion());
     105        @mail($recipient, $subject, $notify_message, "From: \"$comment_author\" <$comment_author_email>\r\n"."X-Mailer: WordPress $b2_version with PHP/".phpversion());
    114106       
    115107    }
     
    121113        $url = ' '; // this to make sure a cookie is set for 'no url'
    122114    }
    123     setcookie("comment_author", $author, time()+30000000);
    124     setcookie("comment_author_email", $email, time()+30000000);
    125     setcookie("comment_author_url", $url, time()+30000000);
     115    setcookie('comment_author', $author, time()+30000000);
     116    setcookie('comment_author_email', $email, time()+30000000);
     117    setcookie('comment_author_url', $url, time()+30000000);
    126118
    127119    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    128     header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
     120    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
    129121    header('Cache-Control: no-cache, must-revalidate');
    130122    header('Pragma: no-cache');
  • trunk/b2config.php

    r96 r114  
    2222// ** MySQL settings **
    2323
    24 $dbname = 'b2';             // The name of the database
    25 $dbusername = 'user';       // Your MySQL username
    26 $dbpassword = 'pass';       // ...and password
    27 $dbhost = 'localhost';      // 99% chance you won't need to change this value
     24define('DB_NAME', 'b2');        // The name of the database
     25define('DB_USER', 'user');      // Your MySQL username
     26define('DB_PASSWORD', 'pass');  // ...and password
     27define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value   
    2828
    2929
  • trunk/blog.header.php

    r107 r114  
    3131    }
    3232
    33 /* Connecting to the db */
    34 dbconnect();
    3533
    3634/* Sending HTTP headers */
     
    268266
    269267//echo $request;
    270 $result = mysql_query($request);
     268$posts = $wpdb->get_results($request);
    271269?>
  • trunk/index.php

    r105 r114  
    3030
    3131<!-- // b2 loop start -->
    32 <?php while($row = mysql_fetch_object($result)) { start_b2(); ?>
     32<?php foreach ($posts as $post) { start_b2(); ?>
    3333
    3434
     
    4848    <?php link_pages('<br />Pages: ', '<br />', 'number'); ?>
    4949    <?php comments_popup_link('Comments (0)', 'Comments (1)', 'Comments (%)'); ?>
    50     <?php trackback_popup_link('TrackBack (0)', 'TrackBack (1)', 'TrackBack (%)'); ?>
    51     <?php pingback_popup_link('PingBack (0)', 'PingBack (1)', 'PingBack (%)'); ?>
    5250</div>
    5351
     
    5755<?php include('b2comments.php'); ?>
    5856
    59 <!-- this includes the trackbacks -->
    60 <?php include('b2trackback.php'); ?>
    61 
    62 <!-- this includes the pingbacks -->
    63 <?php include('b2pingbacks.php'); ?>
    6457
    6558<!-- // this is just the end of the motor - don't touch that line either :) -->
Note: See TracChangeset for help on using the changeset viewer.