From d37d5204a95fd4dfdbc7f44a204b9b2acdbd169e Mon Sep 17 00:00:00 2001 From: saxmatt Date: Thu, 29 May 2003 14:04:30 +0000 Subject: [PATCH] ezSQL mods. git-svn-id: http://svn.automattic.com/wordpress/trunk@114 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- b2-include/b2functions.php | 206 +++++++---------------- b2-include/b2template.functions.php | 250 +++++++++++++--------------- b2-include/wp-db.php | 7 +- b2comments.post.php | 28 ++-- b2config.php | 8 +- blog.header.php | 4 +- index.php | 9 +- 7 files changed, 198 insertions(+), 314 deletions(-) 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:
$sql

MySQL 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:
$sql

MySQL 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:
$sql

MySQL 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:
$sql

MySQL 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:
$sql

MySQL 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:
$sql

MySQL 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 '"; } @@ -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:
$sql

MySQL 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 "