diff --git a/b2-include/b2functions.php b/b2-include/b2functions.php index 8fead8121f..0041f17ed6 100644 --- a/b2-include/b2functions.php +++ b/b2-include/b2functions.php @@ -432,7 +432,7 @@ function get_lastpostdate() { } $sql = "SELECT * FROM $tableposts WHERE $showcatzero post_date <= '$now' ORDER BY post_date DESC LIMIT 1"; $result = mysql_query($sql) or die("Your SQL query: $sqlMySQL said:".mysql_error()); - $querycount++; + ++$querycount; $myrow = mysql_fetch_object($result); $lastpostdate = $myrow->post_date; $cache_lastpostdate = $lastpostdate; @@ -459,7 +459,7 @@ function get_userdata($userid) { $sql = "SELECT * FROM $tableusers WHERE ID = '$userid'"; $result = mysql_query($sql) or die("Your SQL query: $sqlMySQL said:".mysql_error()); $myrow = mysql_fetch_array($result); - $querycount++; + ++$querycount; $cache_userdata[$userid] = $myrow; } else { $myrow = $cache_userdata[$userid]; @@ -468,15 +468,15 @@ function get_userdata($userid) { } function get_userdata2($userid) { // for team-listing - global $tableusers,$row; + global $tableusers,$post; $user_data['ID'] = $userid; - $user_data['user_login'] = $row->user_login; - $user_data['user_firstname'] = $row->user_firstname; - $user_data['user_lastname'] = $row->user_lastname; - $user_data['user_nickname'] = $row->user_nickname; - $user_data['user_level'] = $row->user_level; - $user_data['user_email'] = $row->user_email; - $user_data['user_url'] = $row->user_url; + $user_data['user_login'] = $post->user_login; + $user_data['user_firstname'] = $post->user_firstname; + $user_data['user_lastname'] = $post->user_lastname; + $user_data['user_nickname'] = $post->user_nickname; + $user_data['user_level'] = $post->user_level; + $user_data['user_email'] = $post->user_email; + $user_data['user_url'] = $post->user_url; return($user_data); } @@ -487,7 +487,7 @@ function get_userdatabylogin($user_login) { $result = mysql_query($sql) or die("Your SQL query: $sqlMySQL said:".mysql_error()); if (!$result) die($sql."".mysql_error()); $myrow = mysql_fetch_array($result); - $querycount++; + ++$querycount; $cache_userdata["$user_login"] = $myrow; } else { $myrow = $cache_userdata["$user_login"]; @@ -501,7 +501,7 @@ function get_userid($user_login) { $sql = "SELECT ID FROM $tableusers WHERE user_login = '$user_login'"; $result = mysql_query($sql) or die("No user with the login $user_login"); $myrow = mysql_fetch_array($result); - $querycount++; + ++$querycount; $cache_userdata["$user_login"] = $myrow; } else { $myrow = $cache_userdata["$user_login"]; @@ -513,80 +513,73 @@ function get_usernumposts($userid) { global $tableusers,$tablesettings,$tablecategories,$tableposts,$tablecomments,$querycount; $sql = "SELECT * FROM $tableposts WHERE post_author = $userid"; $result = mysql_query($sql) or die("Your SQL query: $sqlMySQL said:".mysql_error()); - $querycount++; + ++$querycount; return mysql_num_rows($result); } function get_settings($setting) { - global $tablesettings,$querycount,$cache_settings,$use_cache; + global $tablesettings, $wpdb, $cache_settings, $use_cache, $querycount; if ((empty($cache_settings)) OR (!$use_cache)) { - $sql = "SELECT * FROM $tablesettings"; - $result = mysql_query($sql) or die("Your SQL query: $sqlMySQL said:".mysql_error()); - $querycount++; - $myrow = mysql_fetch_object($result); - $cache_settings = $myrow; + $settings = $wpdb->get_row("SELECT * FROM $tablesettings"); + ++$querycount; + $cache_settings = $settings; } else { - $myrow = $cache_settings; + $settings = $cache_settings; } - return($myrow->$setting); + return($settings->$setting); } function get_postdata($postid) { - global $tableusers,$tablesettings,$tablecategories,$tableposts,$tablecomments,$querycount; - $sql = "SELECT * FROM $tableposts WHERE ID = $postid"; - $result = mysql_query($sql) or die("Your SQL query: $sqlMySQL said:".mysql_error()); - $querycount++; - if (mysql_num_rows($result)) { - $myrow = mysql_fetch_object($result); - $postdata = array ( - 'ID' => $myrow->ID, - 'Author_ID' => $myrow->post_author, - 'Date' => $myrow->post_date, - 'Content' => $myrow->post_content, - 'Excerpt' => $myrow->post_excerpt, - 'Title' => $myrow->post_title, - 'Category' => $myrow->post_category, - ); - return($postdata); - } else { - return false; - } + global $tableusers, $tablesettings, $tablecategories, $tableposts, $tablecomments, $querycount, $wpdb; + $post = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID = $postid"); + ++$querycount; + + $postdata = array ( + 'ID' => $post->ID, + 'Author_ID' => $post->post_author, + 'Date' => $post->post_date, + 'Content' => $post->post_content, + 'Excerpt' => $post->post_excerpt, + 'Title' => $post->post_title, + 'Category' => $post->post_category, + ); + return($postdata); } function get_postdata2($postid=0) { // less flexible, but saves mysql queries - global $row; + global $post; $postdata = array ( - 'ID' => $row->ID, - 'Author_ID' => $row->post_author, - 'Date' => $row->post_date, - 'Content' => $row->post_content, - 'Excerpt' => $row->post_excerpt, - 'Title' => $row->post_title, - 'Category' => $row->post_category, -# 'Notify' => $row->post_notifycomments, -# 'Clickable' => $row->post_make_clickable, - 'Karma' => $row->post_karma // this isn't used yet + 'ID' => $post->ID, + 'Author_ID' => $post->post_author, + 'Date' => $post->post_date, + 'Content' => $post->post_content, + 'Excerpt' => $post->post_excerpt, + 'Title' => $post->post_title, + 'Category' => $post->post_category, +# 'Notify' => $post->post_notifycomments, +# 'Clickable' => $post->post_make_clickable, + 'Karma' => $post->post_karma // this isn't used yet ); return($postdata); } function get_commentdata($comment_ID,$no_cache=0) { // less flexible, but saves mysql queries - global $rowc,$id,$commentdata,$tablecomments,$querycount; + global $postc,$id,$commentdata,$tablecomments,$querycount; if ($no_cache) { $query="SELECT * FROM $tablecomments WHERE comment_ID = $comment_ID"; $result=mysql_query($query); - $querycount++; + ++$querycount; $myrow = mysql_fetch_array($result); } else { - $myrow['comment_ID']=$rowc->comment_ID; - $myrow['comment_post_ID']=$rowc->comment_post_ID; - $myrow['comment_author']=$rowc->comment_author; - $myrow['comment_author_email']=$rowc->comment_author_email; - $myrow['comment_author_url']=$rowc->comment_author_url; - $myrow['comment_author_IP']=$rowc->comment_author_IP; - $myrow['comment_date']=$rowc->comment_date; - $myrow['comment_content']=$rowc->comment_content; - $myrow['comment_karma']=$rowc->comment_karma; + $myrow['comment_ID']=$postc->comment_ID; + $myrow['comment_post_ID']=$postc->comment_post_ID; + $myrow['comment_author']=$postc->comment_author; + $myrow['comment_author_email']=$postc->comment_author_email; + $myrow['comment_author_url']=$postc->comment_author_url; + $myrow['comment_author_IP']=$postc->comment_author_IP; + $myrow['comment_date']=$postc->comment_date; + $myrow['comment_content']=$postc->comment_content; + $myrow['comment_karma']=$postc->comment_karma; if (strstr($myrow['comment_content'], '')) { $myrow['comment_type'] = 'trackback'; } elseif (strstr($myrow['comment_content'], '')) { @@ -604,8 +597,8 @@ function get_catname($cat_ID) { $sql = "SELECT * FROM $tablecategories"; $result = mysql_query($sql) or die('Oops, couldn\'t query the db for categories.'); $querycount; - while ($row = mysql_fetch_object($result)) { - $cache_catnames[$row->cat_ID] = $row->cat_name; + while ($post = mysql_fetch_object($result)) { + $cache_catnames[$post->cat_ID] = $post->cat_name; } } $cat_name = $cache_catnames[$cat_ID]; @@ -621,14 +614,14 @@ function dropdown_categories($blog_ID=1) { global $postdata,$tablecategories,$mode,$querycount; $query="SELECT * FROM $tablecategories"; $result=mysql_query($query); - $querycount++; + ++$querycount; $width = ($mode=="sidebar") ? "100%" : "170px"; echo ''; - while($row = mysql_fetch_object($result)) { - echo "cat_ID."\""; - if ($row->cat_ID == $postdata["Category"]) + while($post = mysql_fetch_object($result)) { + echo "cat_ID."\""; + if ($post->cat_ID == $postdata["Category"]) echo " selected"; - echo ">".$row->cat_name.""; + echo ">".$post->cat_name.""; } echo ""; } @@ -893,81 +886,6 @@ function trackback_response($error = 0, $error_message = '') { die(); } -// updates the RSS feed ! -function rss_update($blog_ID, $num_posts="", $file="./b2rss.xml") { - - global $use_rss, $b2_version, $querystring_start, $querystring_equal, $querystring_separator; - global $admin_email,$blogname,$siteurl,$blogfilename,$blogdescription,$posts_per_rss,$rss_language; - global $tableposts,$postdata,$row; - - if ($rss_language == '') { - $rss_language = 'en'; - } - - if ($use_rss) { - - $num_posts = ($num_posts=="") ? $posts_per_rss : 5; - - $date_now = gmdate("D, d M Y H:i:s")." GMT"; - - # let's build the rss file - $rss = ''; - - $rss .= '\n"; - $rss .= "\n"; - $rss .= "\n"; - $rss .= "\t\n"; - $rss .= "\t\t".convert_chars(strip_tags(get_bloginfo("name")),"unicode")."\n"; - $rss .= "\t\t".convert_chars(strip_tags(get_bloginfo("url")),"unicode")."\n"; - $rss .= "\t\t".convert_chars(strip_tags(get_bloginfo("description")),"unicode")."\n"; - $rss .= "\t\t$date_now\n"; - $rss .= "\t\thttp://backend.userland.com/rss092\n"; - $rss .= "\t\t$admin_email\n"; - $rss .= "\t\t$admin_email\n"; - $rss .= "\t\t$rss_language\n"; - - $now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600))); - $sql = "SELECT * FROM $tableposts WHERE post_date <= '$now' AND post_category > 0 ORDER BY post_date DESC LIMIT $num_posts"; - $result = mysql_query($sql) or die("Your SQL query: $sqlMySQL said:".mysql_error()); - - while($row = mysql_fetch_object($result)) { - - $id = $row->ID; - $postdata=get_postdata2($id); - - $rss .= "\t\t\n"; - $rss .= "\t\t\t".convert_chars(strip_tags(get_the_title()),"unicode")."\n"; - -// we could add some specific RSS here, but not yet. uncomment if you wish, it's functionnal -// $rss .= "\t\t\t".convert_chars(strip_tags(get_the_category()),"unicode")."\n"; - - $content = stripslashes($row->post_content); - $content = explode("",$content); - $content = $content[0]; - $rss .= "\t\t\t".convert_chars(make_url_footnote($content),"unicode")."\n"; - - $rss .= "\t\t\t".htmlentities("$siteurl/$blogfilename".$querystring_start.'p'.$querystring_equal.$row->ID.$querystring_separator.'c'.$querystring_equal.'1')."\n"; - $rss .= "\t\t\n"; - - } - - $rss .= "\t\n"; - $rss .= ""; - - $f=@fopen("$file","w+"); - if ($f) { - @fwrite($f,$rss); - @fclose($f); - - return(true); - } else { - return(false); - } - } else { - return(false); - } -} - function make_url_footnote($content) { global $siteurl; preg_match_all('/(.+?)<\/a>/', $content, $matches); diff --git a/b2-include/b2template.functions.php b/b2-include/b2template.functions.php index 23bd039c1e..19f45113e7 100644 --- a/b2-include/b2template.functions.php +++ b/b2-include/b2template.functions.php @@ -71,7 +71,7 @@ function get_bloginfo($show='') { return($output); } -function single_post_title($prefix = '', $display = 1) { +function single_post_title($prefix = '', $display = true) { global $p; if (intval($p)) { $post_data = get_postdata($p); @@ -85,7 +85,7 @@ function single_post_title($prefix = '', $display = 1) { } } -function single_cat_title($prefix = '', $display = 1 ) { +function single_cat_title($prefix = '', $display = true ) { global $cat; if(!empty($cat) && !(strtoupper($cat) == 'ALL')) { $my_cat_name = get_the_category_by_ID($cat); @@ -98,7 +98,7 @@ function single_cat_title($prefix = '', $display = 1 ) { } } -function single_month_title($prefix = '', $display = 1 ) { +function single_month_title($prefix = '', $display = true ) { global $m, $month; if(!empty($m)) { $my_year = substr($m,0,4); @@ -111,9 +111,8 @@ function single_month_title($prefix = '', $display = 1 ) { } function get_archives($type, $limit='') { - global $tableposts, $dateformat, $time_difference, $siteurl, $blogfilename, $querystring_start, $querystring_equal, $month; + global $tableposts, $dateformat, $time_difference, $siteurl, $blogfilename, $querystring_start, $querystring_equal, $month, $wpdb; // weekly and daily are *broken* - dbconnect(); if ('' != $limit) { $limit = (int) $limit; $limit= " LIMIT $limit"; @@ -130,63 +129,52 @@ function get_archives($type, $limit='') { $now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600))); - if ($type == 'monthly') { - $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; - $querycount++; - $arc_result=mysql_query($arc_sql) or die($arc_sql.''.mysql_error()); - while($arc_row = mysql_fetch_array($arc_result)) { - $arc_year = $arc_row['YEAR(post_date)']; - $arc_month = $arc_row['MONTH(post_date)']; - echo "'; - echo $month[zeroise($arc_month,2)].' '.$arc_year; + if ('monthly' == $type) { + ++$querycount; + $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); + foreach ($arcresults as $arcresult) { + echo "year".zeroise($arcresult->month, 2).'">'; + echo $month[zeroise($arcresult->month, 2)].' '.$arcresult->year; echo "\n"; } - } elseif ($type == 'daily') { - $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; - $querycount++; - $arc_result=mysql_query($arc_sql) or die($arc_sql.''.mysql_error()); - while($arc_row = mysql_fetch_array($arc_result)) { - $arc_year = $arc_row['YEAR(post_date)']; - $arc_month = $arc_row['MONTH(post_date)']; - $arc_dayofmonth = $arc_row['DAYOFMONTH(post_date)']; - echo "'; - echo mysql2date($archive_day_date_format, $arc_year.'-'.zeroise($arc_month,2).'-'.zeroise($arc_dayofmonth,2).' 00:00:00'); + } elseif ('daily' == $type) { + ++$querycount; + $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); + foreach ($arcresults as $arcresult) { + echo "year".zeroise($arcresult->month, 2).zeroise($arcresult->dayofmonth, 2).'">'; + echo mysql2date($archive_day_date_format, $arcresult->year.'-'.zeroise($arcresult->month,2).'-'.zeroise($arcresult->dayofmonth,2).' 00:00:00'); echo "\n"; } - } elseif ($type == 'weekly') { + } elseif ('weekly' == $type) { if (!isset($start_of_week)) { $start_of_week = 1; } - $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; - $querycount++; - $arc_result=mysql_query($arc_sql) or die($arc_sql.''.mysql_error()); + ++$querycount; + $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); $arc_w_last = ''; - while($arc_row = mysql_fetch_array($arc_result)) { - $arc_year = $arc_row['YEAR(post_date)']; - $arc_w = $arc_row['WEEK(post_date)']; - if ($arc_w != $arc_w_last) { - $arc_w_last = $arc_w; - $arc_ymd = $arc_year.'-'.zeroise($arc_row['MONTH(post_date)'],2).'-' .zeroise($arc_row['DAYOFMONTH(post_date)'],2); + foreach ($arcresults as $arcresult) { + if ($arcresult->week != $arc_w_last) { + $arc_w_last = $arcresult->week; + $arc_ymd = $arcresult->year.'-'.zeroise($arcresult->month, 2).'-' .zeroise($arcresult->dayofmonth, 2); $arc_week = get_weekstartend($arc_ymd, $start_of_week); $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']); $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); - echo ""; + echo ""; echo $arc_week_start.$archive_week_separator.$arc_week_end; echo "\n"; } } - } elseif ($type == 'postbypost') { - $requestarc = " SELECT ID,post_date,post_title FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC" . $limit; - $querycount++; - $resultarc = mysql_query($requestarc); - while($row=mysql_fetch_object($resultarc)) { - if ($row->post_date != '0000-00-00 00:00:00') { - echo "ID.'">'; - $arc_title = stripslashes($row->post_title); + } elseif ('postbypost' == $type) { + ++$querycount; + $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); + foreach ($arcresults as $arcresult) { + if ($arcresult->post_date != '0000-00-00 00:00:00') { + echo "ID.'">'; + $arc_title = stripslashes($arcresult->post_title); if ($arc_title) { echo strip_tags($arc_title); } else { - echo $row->ID; + echo $arcresult->ID; } echo "\n"; } @@ -200,8 +188,8 @@ function get_archives($type, $limit='') { /***** Date/Time tags *****/ -function the_date($d='', $before='', $after='', $echo = 1) { - global $id, $postdata, $day, $previousday,$dateformat,$newday; +function the_date($d='', $before='', $after='', $echo = true) { + global $id, $postdata, $day, $previousday, $dateformat, $newday; $the_date = ''; if ($day != $previousday) { $the_date .= $before; @@ -221,7 +209,7 @@ function the_date($d='', $before='', $after='', $echo = 1) { } } -function the_time($d='', $echo = 1) { +function the_time($d='', $echo = true) { global $id,$postdata,$timeformat; if ($d=='') { $the_time = mysql2date($timeformat, $postdata['Date']); @@ -364,7 +352,7 @@ function the_title_unicode($before='',$after='') { } } function get_the_title() { - global $id,$postdata; + global $id, $postdata; $output = stripslashes($postdata['Title']); $output = apply_filters('the_title', $output); return($output); @@ -612,7 +600,7 @@ function previous_post($format='%', $previous='previous post: ', $title='yes', $ $sql = "SELECT ID,post_title FROM $tableposts WHERE post_date < '$current_post_date' AND post_category > 0 $sqlcat $sql_exclude_cats ORDER BY post_date DESC LIMIT $limitprev,1"; $query = @mysql_query($sql); - $querycount++; + ++$querycount; if (($query) && (mysql_num_rows($query))) { $p_info = mysql_fetch_object($query); $p_title = $p_info->post_title; @@ -657,7 +645,7 @@ function next_post($format='%', $next='next post: ', $title='yes', $in_same_cat= $sql = "SELECT ID,post_title FROM $tableposts WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_category > 0 $sqlcat $sql_exclude_cats ORDER BY post_date ASC LIMIT $limitnext,1"; $query = @mysql_query($sql); - $querycount++; + ++$querycount; if (($query) && (mysql_num_rows($query))) { $p_info = mysql_fetch_object($query); $p_title = $p_info->post_title; @@ -805,7 +793,7 @@ function get_the_category() { if ((empty($cache_categories[$cat_ID])) OR (!$use_cache)) { $query="SELECT cat_name FROM $tablecategories WHERE cat_ID = '$cat_ID'"; $result=mysql_query($query); - $querycount++; + ++$querycount; $myrow = mysql_fetch_array($result); $cat_name = $myrow[0]; $cache_categories[$cat_ID] = $cat_name; @@ -820,7 +808,7 @@ function get_the_category_by_ID($cat_ID) { if ((!$cache_categories[$cat_ID]) OR (!$use_cache)) { $query="SELECT cat_name FROM $tablecategories WHERE cat_ID = '$cat_ID'"; $result=mysql_query($query); - $querycount++; + ++$querycount; $myrow = mysql_fetch_array($result); $cat_name = $myrow[0]; $cache_categories[$cat_ID] = $cat_name; @@ -850,7 +838,7 @@ function dropdown_cats($optionall = 1, $all = 'All') { global $cat, $tablecategories, $querycount; $query="SELECT * FROM $tablecategories"; $result=mysql_query($query); - $querycount++; + ++$querycount; echo "\n"; if (intval($optionall) == 1) { echo "\t$all\n"; @@ -873,7 +861,7 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde $sort_column = 'cat_'.$sort_column; $query="SELECT * FROM $tablecategories WHERE cat_ID > 0 ORDER BY $sort_column $sort_order"; $result=mysql_query($query); - $querycount++; + ++$querycount; if (intval($optionall) == 1) { $all = apply_filters('list_cats', $all); if ($list) echo "\n\t'.$all.""; @@ -909,52 +897,22 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde /***** Comment tags *****/ // generic comments/trackbacks/pingbacks numbering -function generic_ctp_number($post_id, $mode = 'comments') { - global $postdata, $tablecomments, $querycount, $cache_ctp_number, $use_cache; - if (!isset($cache_ctp_number[$post_id]) || (!$use_cache)) { - $post_id = intval($post_id); - $query = "SELECT * FROM $tablecomments WHERE comment_post_ID = $post_id"; - $result = mysql_query($query) or die('SQL query: '.$query.'MySQL Error: '.mysql_error()); - $querycount++; - $ctp_number = array(); - while($row = mysql_fetch_object($result)) { - if (substr($row->comment_content, 0, 13) == '') { - $ctp_number['trackbacks']++; - } elseif (substr($row->comment_content, 0, 12) == '') { - $ctp_number['pingbacks']++; - } else { - $ctp_number['comments']++; - } - $ctp_number['ctp']++; - } - $cache_ctp_number[$post_id] = $ctp_number; - } else { - $ctp_number = $cache_ctp_number[$post_id]; - } - if (($mode != 'comments') && ($mode != 'trackbacks') && ($mode != 'pingbacks') && ($mode != 'ctp')) { - $mode = 'ctp'; - } - return $ctp_number[$mode]; -} -function comments_number($zero='no comment', $one='1 comment', $more='% comments') { - // original hack by dodo@regretless.com - global $id,$postdata,$tablecomments,$c,$querycount,$cache_commentsnumber,$use_cache; - $number = generic_ctp_number($id, 'comments'); +function comments_number($zero='No Comments', $one='1 Comment', $more='% Comments') { + global $id, $comment, $tablecomments, $querycount, $wpdb; + $number = $wpdb->get_var("SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = $id"); if ($number == 0) { $blah = $zero; } elseif ($number == 1) { $blah = $one; } elseif ($number > 1) { - $n = $number; - $more=str_replace('%', $n, $more); - $blah = $more; + $blah = str_replace('%', $number, $more); } echo $blah; } -function comments_link($file='',$echo=true) { - global $id,$pagenow; +function comments_link($file='', $echo=true) { + global $id, $pagenow; global $querystring_start, $querystring_equal, $querystring_separator; if ($file == '') $file = $pagenow; if ($file == '/') $file = ''; @@ -962,23 +920,21 @@ function comments_link($file='',$echo=true) { else echo $file.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'c'.$querystring_equal.'1#comments'; } -function comments_popup_script($width=400, $height=400, $file='b2commentspopup.php', $trackbackfile='b2trackbackpopup.php', $pingbackfile='b2pingbackspopup.php') { +function comments_popup_script($width=400, $height=400, $file='b2commentspopup.php') { global $b2commentspopupfile, $b2trackbackpopupfile, $b2pingbackpopupfile, $b2commentsjavascript; $b2commentspopupfile = $file; - $b2trackbackpopupfile = $trackbackfile; - $b2pingbackpopupfile = $pingbackfile; $b2commentsjavascript = 1; - $javascript = "\n"; + $javascript = "\n"; echo $javascript; } -function comments_popup_link($zero='no comment', $one='1 comment', $more='% comments', $CSSclass='') { +function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='') { global $id, $b2commentspopupfile, $b2commentsjavascript; global $querystring_start, $querystring_equal, $querystring_separator, $siteurl; - echo 'comment_ID; } function comment_author() { - global $commentdata; echo stripslashes($commentdata['comment_author']); + global $comment; + echo stripslashes($comment->comment_author); } function comment_author_email() { - global $commentdata; echo antispambot(stripslashes($commentdata['comment_author_email'])); + global $comment; + echo antispambot(stripslashes($comment->comment_author_email)); } +function comment_author_link() { + global $comment; + $url = trim(stripslashes(&$comment->comment_author_url)); + $email = &$comment->comment_author_email; + $author = stripslashes(&$comment->comment_author); + + $url = str_replace('http://url', '', $url); + + if (empty($url) && empty($email)) return $author; + echo '' . $author . ''; +} + +function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') { + global $comment; + if (preg_match('||', $comment->comment_content)) echo $trackbacktxt; + elseif (preg_match('||', $comment->comment_content)) echo $pingbacktxt; + else echo $commenttxt; +} function comment_author_url() { - global $commentdata; - $url = trim(stripslashes($commentdata['comment_author_url'])); - $url = (!stristr($url, '://')) ? 'http://'.$url : $url; + global $comment; + $url = trim(stripslashes($comment->comment_author_url)); + $url = str_replace(';//', '://', $url); + $url = (!strstr($url, '://')) ? 'http://'.$url : $url; // convert & into & - $url = preg_replace('#&([^amp\;])#is', '&$1', $url); + $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&$1', $url); if ($url != 'http://url') { echo $url; } } function comment_author_email_link($linktext='', $before='', $after='') { - global $commentdata; - $email=$commentdata['comment_author_email']; + global $comment; + $email = $comment->comment_author_email; if ((!empty($email)) && ($email != '@')) { $display = ($linktext != '') ? $linktext : antispambot(stripslashes($email)); echo $before; @@ -1027,9 +1014,9 @@ function comment_author_email_link($linktext='', $before='', $after='') { } function comment_author_url_link($linktext='', $before='', $after='') { - global $commentdata; - $url = trim(stripslashes($commentdata['comment_author_url'])); - $url = preg_replace('#&([^amp\;])#is', '&$1', $url); + global $comment; + $url = trim(stripslashes($comment->comment_author_url)); + $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&$1', $url); $url = (!stristr($url, '://')) ? 'http://'.$url : $url; if ((!empty($url)) && ($url != 'http://') && ($url != 'http://url')) { $display = ($linktext != '') ? $linktext : stripslashes($url); @@ -1040,39 +1027,40 @@ function comment_author_url_link($linktext='', $before='', $after='') { } function comment_author_IP() { - global $commentdata; echo stripslashes($commentdata['comment_author_IP']); + global $comment; + echo stripslashes($comment->comment_author_IP); } function comment_text() { - global $commentdata; - $comment = stripslashes($commentdata['comment_content']); - $comment = str_replace('', '', $comment); - $comment = str_replace('', '', $comment); - $comment = convert_chars($comment); - $comment = convert_bbcode($comment); - $comment = convert_gmcode($comment); - $comment = convert_smilies($comment); - $comment = make_clickable($comment); - $comment = balanceTags($comment); - $comment = apply_filters('comment_text', $comment); - echo $comment; + global $comment; + $comment_text = stripslashes($comment->comment_content); + $comment_text = str_replace('', '', $comment_text); + $comment_text = str_replace('', '', $comment_text); + $comment_text = convert_chars($comment_text); + $comment_text = convert_bbcode($comment_text); + $comment_text = convert_gmcode($comment_text); + $comment_text = convert_smilies($comment_text); + $comment_text = make_clickable($comment_text); + $comment_text = balanceTags($comment_text); + $comment_text = apply_filters('comment_text', $comment_text); + echo $comment_text; } function comment_date($d='') { - global $commentdata,$dateformat; + global $comment, $dateformat; if ($d == '') { - echo mysql2date($dateformat, $commentdata['comment_date']); + echo mysql2date($dateformat, $comment->comment_date); } else { - echo mysql2date($d, $commentdata['comment_date']); + echo mysql2date($d, $comment->comment_date); } } function comment_time($d='') { - global $commentdata,$timeformat; + global $comment, $timeformat; if ($d == '') { - echo mysql2date($timeformat, $commentdata['comment_date']); + echo mysql2date($timeformat, $comment->comment_date); } else { - echo mysql2date($d, $commentdata['comment_date']); + echo mysql2date($d, $comment->comment_date); } } @@ -1082,7 +1070,7 @@ function comment_time($d='') { /***** TrackBack tags *****/ -function trackback_url($display = 1) { +function trackback_url($display = true) { global $siteurl, $id; $tb_url = $siteurl.'/b2trackback.php/'.$id; if ($display) { @@ -1284,12 +1272,12 @@ function permalink_single_rss($file='b2rss.xml') { // @@@ These aren't template tags, do not edit them function start_b2() { - global $row, $id, $postdata, $authordata, $day, $preview, $page, $pages, $multipage, $more, $numpages; + global $post, $id, $postdata, $authordata, $day, $preview, $page, $pages, $multipage, $more, $numpages; global $preview_userid,$preview_date,$preview_content,$preview_title,$preview_category,$preview_notify,$preview_make_clickable,$preview_autobr; global $pagenow; global $HTTP_GET_VARS; if (!$preview) { - $id = $row->ID; + $id = $post->ID; $postdata=get_postdata2($id); } else { $id = 0; diff --git a/b2-include/wp-db.php b/b2-include/wp-db.php index d4af06d8b0..34a9b00382 100644 --- a/b2-include/wp-db.php +++ b/b2-include/wp-db.php @@ -8,11 +8,6 @@ // We highly recommend it. // We have modified the HTML it returns slightly. - define('EZSQL_DB_USER', ""); // <-- mysql db user - define('EZSQL_DB_PASSWORD', ""); // <-- mysql db password - define('EZSQL_DB_NAME', "mysql"); // <-- mysql db pname - define('EZSQL_DB_HOST', 'localhost'); // <-- mysql server host - define('EZSQL_VERSION', '1.21'); define('OBJECT', 'OBJECT', true); define('ARRAY_A', 'ARRAY_A', true); @@ -399,6 +394,6 @@ } -$wpdb = new wpdb(EZSQL_DB_USER, EZSQL_DB_PASSWORD, EZSQL_DB_NAME, EZSQL_DB_HOST); +$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); ?> \ No newline at end of file diff --git a/b2comments.post.php b/b2comments.post.php index 7b5f78e090..795c836282 100644 --- a/b2comments.post.php +++ b/b2comments.post.php @@ -8,7 +8,6 @@ require($abspath.$b2inc.'/b2template.functions.php'); include($abspath.$b2inc.'/b2vars.php'); include($abspath.$b2inc.'/b2functions.php'); -dbconnect(); function add_magic_quotes($array) { foreach ($array as $k => $v) { @@ -73,15 +72,11 @@ $email = addslashes($email); $url = addslashes($url); /* flood-protection */ -$query = "SELECT * FROM $tablecomments WHERE comment_author_IP='$user_ip' ORDER BY comment_date DESC LIMIT 1"; -$result = mysql_query($query); +$lasttime = $wpdb->get_var("SELECT comment_date FROM $tablecomments WHERE comment_author_IP = '$user_ip' ORDER BY comment_date DESC LIMIT 1"); $ok=1; -if (!empty($result)) { - while($row = mysql_fetch_object($result)) { - $then=$row->comment_date; - } - $time_lastcomment=mysql2date("U","$then"); - $time_newcomment=mysql2date("U","$now"); +if (!empty($lasttime)) { + $time_lastcomment= mysql2date('U', $lasttime); + $time_newcomment= mysql2date('U', "$now"); if (($time_newcomment - $time_lastcomment) < 30) $ok=0; } @@ -89,10 +84,7 @@ if (!empty($result)) { if ($ok) { - $query = "INSERT INTO $tablecomments VALUES ('0','$comment_post_ID','$author','$email','$url','$user_ip','$now','$comment','0')"; - $result = mysql_query($query); - if (!$result) - die ("There is an error with the database, it can’t store your comment...Contact the webmaster."); + $wpdb->query("INSERT INTO $tablecomments VALUES ('0','$comment_post_ID','$author','$email','$url','$user_ip','$now','$comment','0')"); if ($comments_notify) { @@ -110,7 +102,7 @@ if ($ok) { $recipient = $authordata['user_email']; $subject = "[$blogname] Comment: \"".stripslashes($postdata['Title']).'"'; - @mail($recipient, $subject, $notify_message, "From: \"$comment_author\" <$comment_author_email>\r\n"."X-Mailer: wordpress $b2_version with PHP/".phpversion()); + @mail($recipient, $subject, $notify_message, "From: \"$comment_author\" <$comment_author_email>\r\n"."X-Mailer: WordPress $b2_version with PHP/".phpversion()); } @@ -120,12 +112,12 @@ if ($ok) { if ($url == '') { $url = ' '; // this to make sure a cookie is set for 'no url' } - setcookie("comment_author", $author, time()+30000000); - setcookie("comment_author_email", $email, time()+30000000); - setcookie("comment_author_url", $url, time()+30000000); + setcookie('comment_author', $author, time()+30000000); + setcookie('comment_author_email', $email, time()+30000000); + setcookie('comment_author_url', $url, time()+30000000); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); - header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT'); + header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); $location = (!empty($HTTP_POST_VARS['redirect_to'])) ? $HTTP_POST_VARS['redirect_to'] : $HTTP_SERVER_VARS["HTTP_REFERER"]; diff --git a/b2config.php b/b2config.php index 09b6b7345a..8af4225b08 100644 --- a/b2config.php +++ b/b2config.php @@ -21,10 +21,10 @@ $admin_email = 'you@example.com'; // ** MySQL settings ** -$dbname = 'b2'; // The name of the database -$dbusername = 'user'; // Your MySQL username -$dbpassword = 'pass'; // ...and password -$dbhost = 'localhost'; // 99% chance you won't need to change this value +define('DB_NAME', 'b2'); // The name of the database +define('DB_USER', 'user'); // Your MySQL username +define('DB_PASSWORD', 'pass'); // ...and password +define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value // If you've finished up to here you should be able to install now. diff --git a/blog.header.php b/blog.header.php index be3332fcd5..810dbc73c9 100644 --- a/blog.header.php +++ b/blog.header.php @@ -30,8 +30,6 @@ $b2varstoreset = array('m','p','posts','w','c', 'cat','withcomments','s','search } } -/* Connecting to the db */ -dbconnect(); /* Sending HTTP headers */ @header ("X-Pingback: $siteurl/xmlrpc.php"); @@ -267,5 +265,5 @@ if ($preview) { } //echo $request; -$result = mysql_query($request); +$posts = $wpdb->get_results($request); ?> \ No newline at end of file diff --git a/index.php b/index.php index be0e233661..02c38d399e 100644 --- a/index.php +++ b/index.php @@ -29,7 +29,7 @@ require($abspath.'wp-links/links.weblogs.com.php'); - + ',''); ?> @@ -47,8 +47,6 @@ require($abspath.'wp-links/links.weblogs.com.php'); Pages: ', '', 'number'); ?> - - @@ -56,11 +54,6 @@ require($abspath.'wp-links/links.weblogs.com.php'); - - - - -