Changeset 801 for trunk/wp-includes/template-functions.php
- Timestamp:
- 01/27/2004 09:58:01 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/template-functions.php
r799 r801 1 1 <?php 2 3 /* new and improved ! now with more querystring stuff ! */ 4 5 if (!isset($querystring_start)) { 6 $querystring_start = '?'; 7 $querystring_equal = '='; 8 $querystring_separator = '&'; 9 } 10 11 /* template functions... */ 12 13 14 // @@@ These are template tags, you can edit them if you know what you're doing... 15 16 2 $curpath = dirname(__FILE__).'/'; 17 3 18 4 /***** About-the-blog tags *****/ 19 /* Note: these tags go anywhere in the template */ 20 21 function bloginfo($show='') { 22 $info = get_bloginfo($show); 23 $info = convert_bbcode($info); 24 $info = convert_gmcode($info); 25 $info = convert_smilies($info); 26 $info = apply_filters('bloginfo', $info); 27 echo convert_chars($info, 'html'); 28 } 29 30 function bloginfo_rss($show='') { 31 $info = strip_tags(get_bloginfo($show)); 32 echo convert_chars($info, 'unicode'); 33 } 34 35 function bloginfo_unicode($show='') { 36 $info = get_bloginfo($show); 37 echo convert_chars($info, 'unicode'); 38 } 39 40 function get_bloginfo($show='') { 41 global $siteurl, $blogfilename, $blogname, $blogdescription, $siteurl, $admin_email; 42 switch($show) { 43 case "url": 44 $output = $siteurl."/".$blogfilename; 45 break; 46 case "description": 47 $output = $blogdescription; 48 break; 49 case "rdf_url": 50 $output = $siteurl.'/wp-rdf.php'; 51 break; 52 case "rss_url": 53 $output = $siteurl.'/wp-rss.php'; 54 break; 55 case "rss2_url": 56 $output = $siteurl.'/wp-rss2.php'; 57 break; 58 case "atom_url": 59 $output = $siteurl.'/wp-atom.php'; 60 break; 61 case "comments_rss2_url": 62 $output = $siteurl.'/wp-commentsrss2.php'; 63 break; 64 case "pingback_url": 65 $output = $siteurl.'/xmlrpc.php'; 66 break; 67 case "admin_email": 68 $output = $admin_email; 69 break; 70 case "name": 71 default: 72 $output = $blogname; 73 break; 74 } 75 return $output; 76 } 77 78 function wp_title($sep = '»', $display = true) { 79 global $wpdb, $tableposts, $tablecategories; 80 global $year, $monthnum, $day, $cat, $p, $name, $month; 81 82 // If there's a category 83 if(!empty($cat)) { 84 $title = stripslashes(get_the_category_by_ID($cat)); 85 } 86 if (!empty($category_name)) { 87 $title = stripslashes($wpdb->get_var("SELECT cat_name FROM $tablecategories WHERE category_nicename = '$category_name'")); 88 } 89 90 // If there's a month 91 if(!empty($m)) { 92 $my_year = substr($m, 0, 4); 93 $my_month = $month[substr($m, 4, 2)]; 94 $title = "$my_year $sep $my_month"; 95 96 } 97 if (!empty($year)) { 98 $title = $year; 99 if (!empty($monthnum)) { 100 $title .= " $sep ".$month[zeroise($monthnum, 2)]; 101 } 102 if (!empty($day)) { 103 $title .= " $sep ".zeroise($day, 2); 104 } 105 } 106 107 // If there's a post 108 if (intval($p) || '' != $name) { 109 if (!$p) { 110 if ($year != '') { 111 $year = '' . intval($year); 112 $where .= ' AND YEAR(post_date)=' . $year; 113 } 114 115 if ($monthnum != '') { 116 $monthnum = '' . intval($monthnum); 117 $where .= ' AND MONTH(post_date)=' . $monthnum; 118 } 119 120 if ($day != '') { 121 $day = '' . intval($day); 122 $where .= ' AND DAYOFMONTH(post_date)=' . $day; 123 } 124 $p = $wpdb->get_var("SELECT ID FROM $tableposts WHERE post_name = '$name' $where"); 125 } 126 $post_data = get_postdata($p); 127 $title = strip_tags(stripslashes($post_data['Title'])); 128 $title = apply_filters('single_post_title', $title); 129 } 130 131 // Send it out 132 if ($display && isset($title)) { 133 echo " $sep $title"; 134 } elseif (!$display && isset($title)) { 135 return " $sep $title"; 136 } 137 } 138 139 function single_post_title($prefix = '', $display = true) { 140 global $p, $name, $wpdb, $tableposts; 141 if (intval($p) || '' != $name) { 142 if (!$p) { 143 $p = $wpdb->get_var("SELECT ID FROM $tableposts WHERE post_name = '$name'"); 144 } 145 $post_data = get_postdata($p); 146 $title = $post_data['Title']; 147 $title = apply_filters('single_post_title', $title); 148 if ($display) { 149 echo $prefix.strip_tags(stripslashes($title)); 150 } else { 151 return strip_tags(stripslashes($title)); 152 } 153 } 154 } 155 156 function single_cat_title($prefix = '', $display = true ) { 157 global $cat; 158 if(!empty($cat) && !(strtoupper($cat) == 'ALL')) { 159 $my_cat_name = get_the_category_by_ID($cat); 160 if(!empty($my_cat_name)) { 161 if ($display) 162 echo $prefix.strip_tags(stripslashes($my_cat_name)); 163 else 164 return strip_tags(stripslashes($my_cat_name)); 165 } 166 } 167 } 168 169 function single_month_title($prefix = '', $display = true ) { 170 global $m, $month; 171 if(!empty($m)) { 172 $my_year = substr($m,0,4); 173 $my_month = $month[substr($m,4,2)]; 174 if ($display) 175 echo $prefix.$my_month.$prefix.$my_year; 176 else 177 return $m; 178 } 179 } 180 181 /* link navigation hack by Orien http://icecode.com/ */ 182 function get_archives_link($url, $text, $format = "html", $before = "", $after = "") { 183 if ('link' == $format) { 184 return "\t".'<link rel="archives" title="'.$text.'" href="'.$url.'" />'."\n"; 185 } else if ('option' == $format) { 186 return '<option value="'.$url.'">'.$text.'</option>'."\n"; 187 } else if ('html' == $format) { 188 return "\t".'<li><a href="'.$url.'" title="'.$text.'">'.$text.'</a>'.$after.'</li>'."\n"; 189 } else { // custom 190 return "\t".$before.'<a href="'.$url.'" title="'.$text.'">'.$text.'</a>'.$after."\n"; 191 } 192 } 193 194 function get_archives($type='', $limit='', $format='html', $before = "", $after = "", $show_post_count = false) { 195 global $tableposts, $dateformat, $time_difference, $siteurl, $blogfilename; 196 global $querystring_start, $querystring_equal, $querystring_separator, $month, $wpdb, $start_of_week; 197 198 if ('' == $type) { 199 $type = get_settings('archive_mode'); 200 } 201 202 if ('' != $limit) { 203 $limit = (int) $limit; 204 $limit = " LIMIT $limit"; 205 } 206 // this is what will separate dates on weekly archive links 207 $archive_week_separator = '–'; 208 209 // archive link url 210 $archive_link_m = $siteurl.'/'.$blogfilename.$querystring_start.'m'.$querystring_equal; # monthly archive; 211 $archive_link_w = $siteurl.'/'.$blogfilename.$querystring_start.'w'.$querystring_equal; # weekly archive; 212 $archive_link_p = $siteurl.'/'.$blogfilename.$querystring_start.'p'.$querystring_equal; # post-by-post archive; 213 214 // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride 215 $archive_date_format_over_ride = 0; 216 217 // options for daily archive (only if you over-ride the general date format) 218 $archive_day_date_format = 'Y/m/d'; 219 220 // options for weekly archive (only if you over-ride the general date format) 221 $archive_week_start_date_format = 'Y/m/d'; 222 $archive_week_end_date_format = 'Y/m/d'; 223 224 if (!$archive_date_format_over_ride) { 225 $archive_day_date_format = $dateformat; 226 $archive_week_start_date_format = $dateformat; 227 $archive_week_end_date_format = $dateformat; 228 } 229 230 $now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600))); 231 232 if ('monthly' == $type) { 233 $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $tableposts WHERE post_date < '$now' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit); 234 if ($arcresults) { 235 foreach ($arcresults as $arcresult) { 236 $url = get_month_link($arcresult->year, $arcresult->month); 237 if ($show_post_count) { 238 $text = sprintf("%s %d", $month[zeroise($arcresult->month,2)], $arcresult->year); 239 $after = " ($arcresult->posts)"; 240 } else { 241 $text = sprintf("%s %d", $month[zeroise($arcresult->month,2)], $arcresult->year); 242 } 243 echo get_archives_link($url, $text, $format, $before, $after); 244 } 245 } 246 } elseif ('daily' == $type) { 247 $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_status = 'publish' ORDER BY post_date DESC" . $limit); 248 if ($arcresults) { 249 foreach ($arcresults as $arcresult) { 250 $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth); 251 $date = sprintf("%d-%02d-%02d 00:00:00", $arcresult->year, $arcresult->month, $arcresult->dayofmonth); 252 $text = mysql2date($archive_day_date_format, $date); 253 echo get_archives_link($url, $text, $format, $before, $after); 254 } 255 } 256 } elseif ('weekly' == $type) { 257 if (!isset($start_of_week)) { 258 $start_of_week = 1; 259 } 260 $arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd FROM $tableposts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit); 261 $arc_w_last = ''; 262 if ($arcresults) { 263 foreach ($arcresults as $arcresult) { 264 if ($arcresult->week != $arc_w_last) { 265 $arc_year = $arcresult->yr; 266 $arc_w_last = $arcresult->week; 267 $arc_week = get_weekstartend($arcresult->yyyymmdd, $start_of_week); 268 $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']); 269 $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); 270 $url = sprintf("%s/%s%sm%s%s%sw%s%d", $siteurl, $blogfilename, $querystring_start, 271 $querystring_equal, $arc_year, $querystring_separator, 272 $querystring_equal, $arcresult->week); 273 $text = $arc_week_start . $archive_week_separator . $arc_week_end; 274 echo get_archives_link($url, $text, $format, $before, $after); 275 } 276 } 277 } 278 } elseif ('postbypost' == $type) { 279 $arcresults = $wpdb->get_results("SELECT ID, post_date, post_title FROM $tableposts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit); 280 if ($arcresults) { 281 foreach ($arcresults as $arcresult) { 282 if ($arcresult->post_date != '0000-00-00 00:00:00') { 283 $url = get_permalink($arcresult->ID); 284 $arc_title = stripslashes($arcresult->post_title); 285 if ($arc_title) { 286 $text = strip_tags($arc_title); 287 } else { 288 $text = $arcresult->ID; 289 } 290 echo get_archives_link($url, $text, $format, $before, $after); 291 } 292 } 293 } 294 } 295 } 296 297 function get_calendar($daylength = 1) { 298 global $wpdb, $HTTP_GET_VARS, $m, $monthnum, $year, $timedifference, $month, $weekday, $tableposts, $posts; 299 300 // Quick check. If we have no posts at all, abort! 301 if (!$posts) { 302 $gotsome = $wpdb->get_var("SELECT ID from $tableposts WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); 303 if (!$gotsome) 304 return; 305 } 306 307 if (isset($HTTP_GET_VARS['w'])) { 308 $w = ''.intval($HTTP_GET_VARS['w']); 309 } 310 $time_difference = get_settings('time_difference'); 311 312 // Let's figure out when we are 313 if (!empty($monthnum) && !empty($year)) { 314 $thismonth = ''.intval($monthnum); 315 $thisyear = ''.intval($year); 316 } elseif (!empty($w)) { 317 // We need to get the month from MySQL 318 $thisyear = ''.intval(substr($m, 0, 4)); 319 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's 320 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')"); 321 } elseif (!empty($m)) { 322 $calendar = substr($m, 0, 6); 323 $thisyear = ''.intval(substr($m, 0, 4)); 324 if (strlen($m) < 6) { 325 $thismonth = '01'; 326 } else { 327 $thismonth = ''.intval(substr($m, 4, 2)); 328 } 329 } else { 330 $thisyear = intval(date('Y', time()+($time_difference * 3600))); 331 $thismonth = intval(date('m', time()+($time_difference * 3600))); 332 } 333 334 $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); 335 336 // Get the next and previous month and year with at least one post 337 $previous = $wpdb->get_row("SELECT DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year 338 FROM $tableposts 339 WHERE post_date < '$thisyear-$thismonth-01' 340 AND post_status = 'publish' 341 ORDER BY post_date DESC 342 LIMIT 1"); 343 $next = $wpdb->get_row("SELECT DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year 344 FROM $tableposts 345 WHERE post_date > '$thisyear-$thismonth-01' 346 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' ) 347 AND post_status = 'publish' 348 ORDER BY post_date ASC 349 LIMIT 1"); 350 351 echo '<table id="wp-calendar"> 352 <caption>' . $month[zeroise($thismonth, 2)] . ' ' . date('Y', $unixmonth) . '</caption> 353 <thead> 354 <tr>'; 355 foreach ($weekday as $wd) { 356 echo "\n\t\t<th abbr='$wd' scope='col' title='$wd'>" . substr($wd, 0, $daylength) . '</th>'; 357 } 358 359 echo ' 360 </tr> 361 </thead> 362 363 <tfoot> 364 <tr>'; 365 366 if ($previous) { 367 echo "\n\t\t".'<td abbr="' . $month[zeroise($previous->month, 2)] . '" colspan="3" id="prev"><a href="' . 368 get_month_link($previous->year, $previous->month) . '" title="View posts for ' . $month[zeroise($previous->month, 2)] . ' ' . 369 date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)) . '">« ' . substr($month[zeroise($previous->month, 2)], 0, 3) . '</a></td>'; 370 } else { 371 echo "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>'; 372 } 373 374 echo "\n\t\t".'<td class="pad"> </td>'; 375 376 if ($next) { 377 echo "\n\t\t".'<td abbr="' . $month[zeroise($next->month, 2)] . '" colspan="3" id="next"><a href="' . 378 get_month_link($next->year, $next->month) . '" title="View posts for ' . $month[zeroise($next->month, 2)] . ' ' . 379 date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year)) . '">' . substr($month[zeroise($next->month, 2)], 0, 3) . ' »</a></td>'; 380 } else { 381 echo "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>'; 382 } 383 384 echo ' 385 </tr> 386 </tfoot> 387 388 <tbody> 389 <tr>'; 390 391 // Get days with posts 392 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) 393 FROM $tableposts WHERE MONTH(post_date) = $thismonth 394 AND YEAR(post_date) = $thisyear 395 AND post_status = 'publish' 396 AND post_date < '" . date("Y-m-d H:i:s", (time() + ($time_difference * 3600)))."'", ARRAY_N); 397 if ($dayswithposts) { 398 foreach ($dayswithposts as $daywith) { 399 $daywithpost[] = $daywith[0]; 400 } 401 } else { 402 $daywithpost = array(); 403 } 404 405 406 407 if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") || 408 strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), "camino") || 409 strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), "safari")) { 410 $ak_title_separator = "\n"; 411 } else { 412 $ak_title_separator = ", "; 413 } 414 415 $ak_titles_for_day = array(); 416 $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom " 417 ."FROM $tableposts " 418 ."WHERE YEAR(post_date) = '$thisyear' " 419 ."AND MONTH(post_date) = '$thismonth' " 420 ."AND post_date < '".date("Y-m-d H:i:s", (time() + ($time_difference * 3600)))."' " 421 ."AND post_status = 'publish'" 422 ); 423 if ($ak_post_titles) { 424 foreach ($ak_post_titles as $ak_post_title) { 425 if (empty($ak_titles_for_day["day_".$ak_post_title->dom])) { 426 $ak_titles_for_day["day_".$ak_post_title->dom] = ''; 427 } 428 if (empty($ak_titles_for_day["$ak_post_title->dom"])) { // first one 429 $ak_titles_for_day["$ak_post_title->dom"] .= htmlspecialchars(stripslashes($ak_post_title->post_title)); 430 } else { 431 $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . htmlspecialchars(stripslashes($ak_post_title->post_title)); 432 } 433 } 434 } 435 436 437 // See how much we should pad in the beginning 438 $pad = intval(date('w', $unixmonth)); 439 if (0 != $pad) echo "\n\t\t<td colspan='$pad' class='pad'> </td>"; 440 441 $daysinmonth = intval(date('t', $unixmonth)); 442 for ($day = 1; $day <= $daysinmonth; ++$day) { 443 if (isset($newrow) && $newrow) 444 echo "\n\t</tr>\n\t<tr>\n\t\t"; 445 $newrow = false; 446 447 if ($day == date('j', (time() + ($time_difference * 3600))) && $thismonth == date('m', time()+($time_difference * 3600))) 448 echo '<td id="today">'; 449 else 450 echo "<td>"; 451 452 if (in_array($day, $daywithpost)) { // any posts today? 453 echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>"; 454 } else { 455 echo $day; 456 } 457 echo '</td>'; 458 459 if (6 == date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))) 460 $newrow = true; 461 } 462 463 $pad = 7 - date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear)); 464 if ($pad != 0 && $pad != 7) 465 echo "\n\t\t<td class='pad' colspan='$pad'> </td>"; 466 467 echo "\n\t</tr>\n\t</tbody>\n\t</table>"; 468 } 469 470 /***** // About-the-blog tags *****/ 471 5 require($curpath . 'template-functions-general.php'); 472 6 473 7 /***** Links *****/ 474 function get_permalink($id=false) { 475 global $post, $wpdb, $tableposts; 476 global $siteurl, $blogfilename, $querystring_start, $querystring_equal; 477 478 $rewritecode = array( 479 '%year%', 480 '%monthnum%', 481 '%day%', 482 '%postname%', 483 '%post_id%' 484 ); 485 if (!$id) { 486 if ('' != get_settings('permalink_structure')) { 487 $unixtime = strtotime($post->post_date); 488 $rewritereplace = array( 489 date('Y', $unixtime), 490 date('m', $unixtime), 491 date('d', $unixtime), 492 $post->post_name, 493 $post->ID 494 ); 495 return $siteurl . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure')); 496 } else { // if they're not using the fancy permalink option 497 return $siteurl . '/' . $blogfilename.$querystring_start.'p'.$querystring_equal.$post->ID; 498 } 499 } else { // if an ID is given 500 $idpost = $wpdb->get_row("SELECT post_date, post_name FROM $tableposts WHERE ID = $id"); 501 if ('' != get_settings('permalink_structure')) { 502 $unixtime = strtotime($idpost->post_date); 503 $rewritereplace = array( 504 date('Y', $unixtime), 505 date('m', $unixtime), 506 date('d', $unixtime), 507 $idpost->post_name, 508 $id 509 ); 510 return $siteurl . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure')); 511 } else { 512 return $siteurl . '/' . $blogfilename.$querystring_start.'p'.$querystring_equal.$id; 513 } 514 } 515 } 516 517 function get_month_link($year, $month) { 518 global $siteurl, $blogfilename, $querystring_start, $querystring_equal; 519 if (!$year) $year = date('Y', time()+($time_difference * 3600)); 520 if (!$month) $month = date('m', time()+($time_difference * 3600)); 521 if ('' != get_settings('permalink_structure')) { 522 $off = strpos(get_settings('permalink_structure'), '%monthnum%'); 523 $offset = $off + 11; 524 $monthlink = substr(get_settings('permalink_structure'), 0, $offset); 525 if ('/' != substr($monthlink, -1)) $monthlink = substr($monthlink, 0, -1); 526 $monthlink = str_replace('%year%', $year, $monthlink); 527 $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink); 528 $monthlink = str_replace('%post_id%', '', $monthlink); 529 return $siteurl . $monthlink; 530 } else { 531 return $siteurl.'/'.$blogfilename.$querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2); 532 } 533 } 534 535 function get_day_link($year, $month, $day) { 536 global $siteurl, $blogfilename, $querystring_start, $querystring_equal; 537 if (!$year) $year = date('Y', time()+($time_difference * 3600)); 538 if (!$month) $month = date('m', time()+($time_difference * 3600)); 539 if (!$day) $day = date('j', time()+($time_difference * 3600)); 540 if ('' != get_settings('permalink_structure')) { 541 $off = strpos(get_settings('permalink_structure'), '%day%'); 542 $offset = $off + 6; 543 $daylink = substr(get_settings('permalink_structure'), 0, $offset); 544 if ('/' != substr($daylink, -1)) $daylink = substr($daylink, 0, -1); 545 $daylink = str_replace('%year%', $year, $daylink); 546 $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink); 547 $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink); 548 $daylink = str_replace('%post_id%', '', $daylink); 549 return $siteurl . $daylink; 550 } else { 551 return $siteurl.'/'.$blogfilename.$querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2).zeroise($day, 2); 552 } 553 } 554 555 function edit_post_link($link = 'Edit This', $before = '', $after = '') { 556 global $user_level, $post, $siteurl; 557 558 get_currentuserinfo(); 559 560 if ($user_level > 0) { 561 $authordata = get_userdata($post->post_author); 562 if ($user_level < $authordata->user_level) { 563 return; 564 } 565 } else { 566 return; 567 } 568 569 $location = "$siteurl/wp-admin/post.php?action=edit&post=$post->ID"; 570 echo "$before <a href='$location'>$link</a> $after"; 571 } 572 573 function edit_comment_link($link = 'Edit This', $before = '', $after = '') { 574 global $user_level, $post, $comment, $siteurl; 575 576 get_currentuserinfo(); 577 578 if ($user_level > 0) { 579 $authordata = get_userdata($post->post_author); 580 if ($user_level < $authordata->user_level) { 581 return; 582 } 583 } else { 584 return; 585 } 586 587 $location = "$siteurl/wp-admin/post.php?action=editcomment&comment=$comment->comment_ID"; 588 echo "$before <a href='$location'>$link</a> $after"; 589 } 590 591 /***** Date/Time tags *****/ 592 593 function the_date_xml() { 594 global $post; 595 echo mysql2date("Y-m-d",$post->post_date); 596 //echo ""+$post->post_date; 597 } 598 599 function the_date($d='', $before='', $after='', $echo = true) { 600 global $id, $post, $day, $previousday, $dateformat, $newday; 601 $the_date = ''; 602 if ($day != $previousday) { 603 $the_date .= $before; 604 if ($d=='') { 605 $the_date .= mysql2date($dateformat, $post->post_date); 606 } else { 607 $the_date .= mysql2date($d, $post->post_date); 608 } 609 $the_date .= $after; 610 $previousday = $day; 611 } 612 $the_date = apply_filters('the_date', $the_date); 613 if ($echo) { 614 echo $the_date; 615 } else { 616 return $the_date; 617 } 618 } 619 620 function the_time($d='', $echo = true) { 621 global $id, $post, $timeformat; 622 if ($d=='') { 623 $the_time = mysql2date($timeformat, $post->post_date); 624 } else { 625 $the_time = mysql2date($d, $post->post_date); 626 } 627 $the_time = apply_filters('the_time', $the_time); 628 if ($echo) { 629 echo $the_time; 630 } else { 631 return $the_time; 632 } 633 } 634 635 function the_weekday() { 636 global $weekday, $id, $post; 637 $the_weekday = $weekday[mysql2date('w', $post->post_date)]; 638 $the_weekday = apply_filters('the_weekday', $the_weekday); 639 echo $the_weekday; 640 } 641 642 function the_weekday_date($before='',$after='') { 643 global $weekday, $id, $post, $day, $previousweekday; 644 $the_weekday_date = ''; 645 if ($day != $previousweekday) { 646 $the_weekday_date .= $before; 647 $the_weekday_date .= $weekday[mysql2date('w', $post->post_date)]; 648 $the_weekday_date .= $after; 649 $previousweekday = $day; 650 } 651 $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date); 652 echo $the_weekday_date; 653 } 654 655 /***** // Date/Time tags *****/ 8 require($curpath . 'template-functions-links.php'); 656 9 657 10 /**** // Geo Tags ****/ 658 function get_Lat() { 659 global $post; 660 return $post->post_lat; 661 } 662 663 function get_Lon() { 664 global $post; 665 return $post->post_lon; 666 } 667 668 function print_Lat() { 669 if(get_settings('use_geo_positions')) { 670 if(get_Lat() > 0) { 671 echo "".get_Lat()."N"; 672 } else { 673 echo "".get_Lat()."S"; 674 } 675 } 676 } 677 678 function print_Lon() { 679 global $id, $postdata; 680 if(get_settings('use_geo_positions')) { 681 if(get_Lon() < 0) { 682 $temp = get_Lon() * -1; 683 echo "".$temp."W"; 684 } else { 685 echo "".get_Lon()."E"; 686 } 687 } 688 } 689 690 function print_PopUpScript() { 691 echo " 692 <script type='text/javascript'> 693 <!-- This script and many more are available free online at --> 694 <!-- The JavaScript Source!! http://javascript.internet.com --> 695 function formHandler(form) { 696 var URL = form.site.options[form.site.selectedIndex].value; 697 if(URL != \".\") { 698 popup = window.open(URL,\"MenuPopup\"); 699 } 700 } 701 </script> "; 702 } 703 704 function print_UrlPopNav() { 705 $sites = array( 706 array('http://www.acme.com/mapper/?lat='.get_Lat().'&long='.get_Lon().'&scale=11&theme=Image&width=3&height=2&dot=Yes', 707 'Acme Mapper'), 708 array('http://geourl.org/near/?lat='.get_Lat().'&lon='.get_Lon().'&dist=500', 709 'GeoURLs near here'), 710 array('http://www.geocaching.com/seek/nearest.aspx?origin_lat='.get_Lat().'&origin_long='.get_Lon().'&dist=5', 711 'Geocaches Near Nere'), 712 array('http://www.mapquest.com/maps/map.adp?latlongtype=decimal&latitude='.get_Lat().'&longitude='.get_Lon(), 713 'Mapquest map of this spot'), 714 array('http://www.sidebit.com/ProjectGeoURLMap.php?lat='.get_Lat().'&lon='.get_Lon(), 715 'SideBit URL Map of this spot'), 716 array('http://confluence.org/confluence.php?lat='.get_Lat().'&lon='.get_Lon(), 717 'Confluence.org near here'), 718 array('http://www.topozone.com/map.asp?lat='.get_Lat().'&lon='.get_Lon(), 719 'Topozone near here'), 720 array('http://www.findu.com/cgi-bin/near.cgi?lat='.get_Lat().'&lon='.get_Lon(), 721 'FindU near here'), 722 array('http://mapserver.maptech.com/api/espn/index.cfm?lat='.get_Lat().'&lon='.get_Lon().'&scale=100000&zoom=50&type=1&icon=0&&scriptfile=http://mapserver.maptech.com/api/espn/index.cfm', 723 'Maptech near here') 724 ); 725 echo '<form action=""><div> 726 <select name="site" size="1" onchange="formHandler(this.form);" >'."\n"; 727 echo '<option value=".">Sites referencing '.get_Lat().' x '.get_Lon()."</option>\n"; 728 foreach($sites as $site) { 729 echo "\t".'<option value="'.$site[0].'">'.$site[1]."</option>\n"; 730 } 731 echo '</select></div> 732 </form>'."\n"; 733 } 734 735 function longitude_invalid() { 736 if (get_Lon() == null) return true; 737 if (get_Lon() > 360) return true; 738 if (get_Lon() < -360) return true; 739 } 740 741 function print_AcmeMap_Url() { 742 if (!get_settings('use_geo_positions')) return; 743 if (longitude_invalid()) return; 744 echo "http://www.acme.com/mapper/?lat=".get_Lat()."&long=".get_Lon()."&scale=11&theme=Image&width=3&height=2&dot=Yes"; 745 } 746 747 function print_GeoURL_Url() { 748 if (!get_settings('use_geo_positions')) return; 749 if (longitude_invalid()) return; 750 echo "http://geourl.org/near/?lat=".get_Lat()."&lon=".get_Lon()."&dist=500"; 751 } 752 753 function print_GeoCache_Url() { 754 if (!get_settings('use_geo_positions')) return; 755 if (longitude_invalid()) return; 756 echo "http://www.geocaching.com/seek/nearest.aspx?origin_lat=".get_Lat()."&origin_long=".get_Lon()."&dist=5"; 757 } 758 759 function print_MapQuest_Url() { 760 if (!get_settings('use_geo_positions')) return; 761 if (longitude_invalid()) return; 762 echo "http://www.mapquest.com/maps/map.adp?latlongtype=decimal&latitude=".get_Lat()."&longitude=".get_Lon(); 763 } 764 765 function print_SideBit_Url() { 766 if (!get_settings('use_geo_positions')) return; 767 if (longitude_invalid()) return; 768 echo "http://www.sidebit.com/ProjectGeoURLMap.php?lat=".get_Lat()."&lon=".get_Lon(); 769 } 770 771 function print_DegreeConfluence_Url() { 772 if (!get_settings('use_geo_positions')) return; 773 if (longitude_invalid()) return; 774 echo "http://confluence.org/confluence.php?lat=".get_Lat()."&lon=".get_Lon(); 775 } 776 777 11 require($curpath . 'template-functions-geo.php'); 778 12 779 13 /***** Author tags *****/ 780 781 function the_author() { 782 global $id, $authordata; 783 $i = $authordata->user_idmode; 784 if ($i == 'nickname') echo $authordata->user_nickname; 785 if ($i == 'login') echo $authordata->user_login; 786 if ($i == 'firstname') echo $authordata->user_firstname; 787 if ($i == 'lastname') echo $authordata->user_lastname; 788 if ($i == 'namefl') echo $authordata->user_firstname.' '.$authordata->user_lastname; 789 if ($i == 'namelf') echo $authordata->user_lastname.' '.$authordata->user_firstname; 790 if (!$i) echo $authordata->user_nickname; 791 } 792 function the_author_description() { 793 global $authordata; 794 echo $authordata->user_description; 795 } 796 function the_author_login() { 797 global $id,$authordata; echo $authordata->user_login; 798 } 799 800 function the_author_firstname() { 801 global $id,$authordata; echo $authordata->user_firstname; 802 } 803 804 function the_author_lastname() { 805 global $id,$authordata; echo $authordata->user_lastname; 806 } 807 808 function the_author_nickname() { 809 global $id,$authordata; echo $authordata->user_nickname; 810 } 811 812 function the_author_ID() { 813 global $id,$authordata; echo $authordata->ID; 814 } 815 816 function the_author_email() { 817 global $id,$authordata; echo antispambot($authordata->user_email); 818 } 819 820 function the_author_url() { 821 global $id,$authordata; echo $authordata->user_url; 822 } 823 824 function the_author_icq() { 825 global $id,$authordata; echo $authordata->user_icq; 826 } 827 828 function the_author_aim() { 829 global $id,$authordata; echo str_replace(' ', '+', $authordata->user_aim); 830 } 831 832 function the_author_yim() { 833 global $id,$authordata; echo $authordata->user_yim; 834 } 835 836 function the_author_msn() { 837 global $id,$authordata; echo $authordata->user_msn; 838 } 839 840 function the_author_posts() { 841 global $id,$postdata; $posts=get_usernumposts($post->post_author); echo $posts; 842 } 843 844 /***** // Author tags *****/ 845 846 847 14 require($curpath . 'template-functions-author.php'); 848 15 849 16 /***** Post tags *****/ 850 851 function get_the_password_form() { 852 $output = "<form action='" . get_settings('siteurl') . "/wp-pass.php' method='post'> 853 <p>This post is password protected. To view it please enter your password below:</p> 854 <p><label>Password: <input name='post_password' type='text' size='20' /></label> <input type='submit' name='Submit' value='Submit' /></p> 855 </form> 856 "; 857 return $output; 858 } 859 860 function the_ID() { 861 global $id; 862 echo $id; 863 } 864 865 function the_title($before = '', $after = '', $echo = true) { 866 $title = get_the_title(); 867 $title = convert_smilies($title); 868 if (!empty($title)) { 869 $title = convert_chars($before.$title.$after); 870 $title = apply_filters('the_title', $title); 871 if ($echo) 872 echo $title; 873 else 874 return $title; 875 } 876 } 877 function the_title_rss() { 878 $title = get_the_title(); 879 $title = strip_tags($title); 880 if (trim($title)) { 881 echo convert_chars($title, 'unicode'); 882 } 883 } 884 function the_title_unicode($before='',$after='') { 885 $title = get_the_title(); 886 $title = convert_bbcode($title); 887 $title = convert_gmcode($title); 888 if ($title) { 889 $title = convert_chars($before.$title.$after); 890 $title = apply_filters('the_title_unicode', $title); 891 echo $title; 892 } 893 } 894 function get_the_title() { 895 global $post; 896 $output = stripslashes($post->post_title); 897 if (!empty($post->post_password)) { // if there's a password 898 $output = 'Protected: ' . $output; 899 } 900 return $output; 901 } 902 903 function the_content($more_link_text='(more...)', $stripteaser=0, $more_file='') { 904 $content = get_the_content($more_link_text, $stripteaser, $more_file); 905 $content = convert_bbcode($content); 906 $content = convert_gmcode($content); 907 $content = convert_smilies($content); 908 $content = convert_chars($content, 'html'); 909 $content = apply_filters('the_content', $content); 910 echo $content; 911 } 912 913 function the_content_rss($more_link_text='(more...)', $stripteaser=0, $more_file='', $cut = 0, $encode_html = 0) { 914 $content = get_the_content($more_link_text, $stripteaser, $more_file); 915 $content = convert_bbcode($content); 916 $content = convert_gmcode($content); 917 $content = convert_chars($content, 'unicode'); 918 if ($cut && !$encode_html) { 919 $encode_html = 2; 920 } 921 if ($encode_html == 1) { 922 $content = htmlspecialchars($content); 923 $cut = 0; 924 } elseif ($encode_html == 0) { 925 $content = make_url_footnote($content); 926 } elseif ($encode_html == 2) { 927 $content = strip_tags($content); 928 } 929 if ($cut) { 930 $blah = explode(' ', $content); 931 if (count($blah) > $cut) { 932 $k = $cut; 933 $use_dotdotdot = 1; 934 } else { 935 $k = count($blah); 936 $use_dotdotdot = 0; 937 } 938 for ($i=0; $i<$k; $i++) { 939 $excerpt .= $blah[$i].' '; 940 } 941 $excerpt .= ($use_dotdotdot) ? '...' : ''; 942 $content = $excerpt; 943 } 944 echo $content; 945 } 946 947 function the_content_unicode($more_link_text='(more...)', $stripteaser=0, $more_file='') { 948 $content = get_the_content($more_link_text, $stripteaser, $more_file); 949 $content = convert_bbcode($content); 950 $content = convert_gmcode($content); 951 $content = convert_smilies($content); 952 $content = convert_chars($content, 'unicode'); 953 $content = apply_filters('the_content_unicode', $content); 954 echo $content; 955 } 956 957 function get_the_content($more_link_text='(more...)', $stripteaser=0, $more_file='') { 958 global $id, $post, $more, $c, $withcomments, $page, $pages, $multipage, $numpages; 959 global $HTTP_SERVER_VARS, $HTTP_COOKIE_VARS, $preview, $cookiehash; 960 global $querystring_start, $querystring_equal, $querystring_separator; 961 global $pagenow; 962 $output = ''; 963 964 if (!empty($post->post_password)) { // if there's a password 965 if ($HTTP_COOKIE_VARS['wp-postpass_'.$cookiehash] != $post->post_password) { // and it doesn't match the cookie 966 $output = get_the_password_form(); 967 return $output; 968 } 969 } 970 971 if ($more_file != '') { 972 $file = $more_file; 973 } else { 974 $file = $pagenow; //$HTTP_SERVER_VARS['PHP_SELF']; 975 } 976 $content = $pages[$page-1]; 977 $content = explode('<!--more-->', $content); 978 if ((preg_match('/<!--noteaser-->/', $post->post_content) && ((!$multipage) || ($page==1)))) 979 $stripteaser = 1; 980 $teaser = $content[0]; 981 if (($more) && ($stripteaser)) 982 $teaser = ''; 983 $output .= $teaser; 984 if (count($content)>1) { 985 if ($more) { 986 $output .= '<a id="more-'.$id.'"></a>'.$content[1]; 987 } else { 988 $output .= " <a href='". get_permalink() . "#more-$id'>$more_link_text</a>"; 989 } 990 } 991 if ($preview) { // preview fix for javascript bug with foreign languages 992 $output = preg_replace('/\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10).';'", $output); 993 } 994 return $output; 995 } 996 997 function the_excerpt() { 998 $excerpt = get_the_excerpt(); 999 $excerpt = convert_bbcode($excerpt); 1000 $excerpt = convert_gmcode($excerpt); 1001 $excerpt = convert_smilies($excerpt); 1002 $excerpt = convert_chars($excerpt, 'html'); 1003 $excerpt = apply_filters('the_excerpt', $excerpt); 1004 echo $excerpt; 1005 } 1006 1007 function the_excerpt_rss($cut = 0, $encode_html = 0) { 1008 $output = get_the_excerpt(true); 1009 $output = convert_bbcode($output); 1010 $output = convert_gmcode($output); 1011 $output = convert_chars($output, 'unicode'); 1012 if ($cut && !$encode_html) { 1013 $encode_html = 2; 1014 } 1015 if ($encode_html == 1) { 1016 $output = htmlspecialchars($output); 1017 $cut = 0; 1018 } elseif ($encode_html == 0) { 1019 $output = make_url_footnote($output); 1020 } elseif ($encode_html == 2) { 1021 $output = strip_tags($output); 1022 } 1023 if ($cut) { 1024 $excerpt = ''; 1025 $blah = explode(' ', $output); 1026 if (count($blah) > $cut) { 1027 $k = $cut; 1028 $use_dotdotdot = 1; 1029 } else { 1030 $k = count($blah); 1031 $use_dotdotdot = 0; 1032 } 1033 for ($i=0; $i<$k; $i++) { 1034 $excerpt .= $blah[$i].' '; 1035 } 1036 $excerpt .= ($use_dotdotdot) ? '...' : ''; 1037 $output = $excerpt; 1038 } 1039 echo $output; 1040 } 1041 1042 function the_excerpt_unicode() { 1043 $excerpt = get_the_excerpt(); 1044 $excerpt = convert_bbcode($excerpt); 1045 $excerpt = convert_gmcode($excerpt); 1046 $excerpt = convert_smilies($excerpt); 1047 $excerpt = convert_chars($excerpt, 'unicode'); 1048 $excerpt = apply_filters('the_excerpt_unicode', $excerpt); 1049 echo $excerpt; 1050 } 1051 1052 function get_the_excerpt($fakeit = false) { 1053 global $id, $post; 1054 global $HTTP_SERVER_VARS, $HTTP_COOKIE_VARS, $preview, $cookiehash; 1055 $output = ''; 1056 $output = stripslashes($post->post_excerpt); 1057 if (!empty($post->post_password)) { // if there's a password 1058 if ($HTTP_COOKIE_VARS['wp-postpass_'.$cookiehash] != $post->post_password) { // and it doesn't match the cookie 1059 $output = "There is no excerpt because this is a protected post."; 1060 return $output; 1061 } 1062 } 1063 //if we haven't got an excerpt, make one in the style of the rss ones 1064 if (($output == '') && $fakeit) { 1065 $output = get_the_content(); 1066 $output = strip_tags($output); 1067 $blah = explode(' ', $output); 1068 $excerpt_length = 120; 1069 if (count($blah) > $excerpt_length) { 1070 $k = $excerpt_length; 1071 $use_dotdotdot = 1; 1072 } else { 1073 $k = count($blah); 1074 $use_dotdotdot = 0; 1075 } 1076 $excerpt = ''; 1077 for ($i=0; $i<$k; $i++) { 1078 $excerpt .= $blah[$i].' '; 1079 } 1080 $excerpt .= ($use_dotdotdot) ? '...' : ''; 1081 $output = $excerpt; 1082 } // end if no excerpt 1083 if ($preview) { // preview fix for javascript bug with foreign languages 1084 $output = preg_replace('/\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10).';'", $output); 1085 } 1086 return $output; 1087 } 1088 1089 1090 function link_pages($before='<br />', $after='<br />', $next_or_number='number', $nextpagelink='next page', $previouspagelink='previous page', $pagelink='%', $more_file='') { 1091 global $id, $page, $numpages, $multipage, $more; 1092 global $pagenow; 1093 global $querystring_start, $querystring_equal, $querystring_separator; 1094 if ($more_file != '') { 1095 $file = $more_file; 1096 } else { 1097 $file = $pagenow; 1098 } 1099 if (($multipage)) { 1100 if ($next_or_number=='number') { 1101 echo $before; 1102 for ($i = 1; $i < ($numpages+1); $i = $i + 1) { 1103 $j=str_replace('%',"$i",$pagelink); 1104 echo " "; 1105 if (($i != $page) || ((!$more) && ($page==1))) { 1106 if ('' == get_settings('permalink_structure')) { 1107 echo '<a href="'.get_permalink().$querystring_separator.'page'.$querystring_equal.$i.'">'; 1108 } else { 1109 echo '<a href="'.get_permalink().$i.'/">'; 1110 } 1111 } 1112 echo $j; 1113 if (($i != $page) || ((!$more) && ($page==1))) 1114 echo '</a>'; 1115 } 1116 echo $after; 1117 } else { 1118 if ($more) { 1119 echo $before; 1120 $i=$page-1; 1121 if ($i && $more) { 1122 if ('' == get_settings('permalink_structure')) { 1123 echo '<a href="'.get_permalink().$querystring_separator.'page'.$querystring_equal.$i.'">'; 1124 } else { 1125 echo '<a href="'.get_permalink().$i.'/">'; 1126 } 1127 } 1128 $i=$page+1; 1129 if ($i<=$numpages && $more) { 1130 if ('' == get_settings('permalink_structure')) { 1131 echo '<a href="'.get_permalink().$querystring_separator.'page'.$querystring_equal.$i.'">'; 1132 } else { 1133 echo '<a href="'.get_permalink().$i.'/">'; 1134 } 1135 } 1136 echo $after; 1137 } 1138 } 1139 } 1140 } 1141 1142 1143 function previous_post($format='%', $previous='previous post: ', $title='yes', $in_same_cat='no', $limitprev=1, $excluded_categories='') { 1144 global $tableposts, $id, $post, $siteurl, $blogfilename, $wpdb; 1145 global $p, $posts, $posts_per_page, $s, $single; 1146 global $querystring_start, $querystring_equal, $querystring_separator; 1147 1148 if(($p) || ($posts_per_page == 1) || 1 == $single) { 1149 1150 $current_post_date = $post->post_date; 1151 $current_category = $post->post_category; 1152 1153 $sqlcat = ''; 1154 if ($in_same_cat != 'no') { 1155 $sqlcat = " AND post_category = '$current_category' "; 1156 } 1157 1158 $sql_exclude_cats = ''; 1159 if (!empty($excluded_categories)) { 1160 $blah = explode('and', $excluded_categories); 1161 foreach($blah as $category) { 1162 $category = intval($category); 1163 $sql_exclude_cats .= " AND post_category != $category"; 1164 } 1165 } 1166 1167 $limitprev--; 1168 $lastpost = @$wpdb->get_row("SELECT ID, post_title FROM $tableposts WHERE post_date < '$current_post_date' AND post_status = 'publish' $sqlcat $sql_exclude_cats ORDER BY post_date DESC LIMIT $limitprev, 1"); 1169 if ($lastpost) { 1170 $string = '<a href="'.get_permalink($lastpost->ID).'">'.$previous; 1171 if ($title == 'yes') { 1172 $string .= wptexturize(stripslashes($lastpost->post_title)); 1173 } 1174 $string .= '</a>'; 1175 $format = str_replace('%', $string, $format); 1176 echo $format; 1177 } 1178 } 1179 } 1180 1181 function next_post($format='%', $next='next post: ', $title='yes', $in_same_cat='no', $limitnext=1, $excluded_categories='') { 1182 global $tableposts, $p, $posts, $id, $post, $siteurl, $blogfilename, $wpdb; 1183 global $time_difference, $single; 1184 global $querystring_start, $querystring_equal, $querystring_separator; 1185 if(($p) || ($posts==1) || 1 == $single) { 1186 1187 $current_post_date = $post->post_date; 1188 $current_category = $post->post_category; 1189 1190 $sqlcat = ''; 1191 if ($in_same_cat != 'no') { 1192 $sqlcat = " AND post_category='$current_category' "; 1193 } 1194 1195 $sql_exclude_cats = ''; 1196 if (!empty($excluded_categories)) { 1197 $blah = explode('and', $excluded_categories); 1198 foreach($blah as $category) { 1199 $category = intval($category); 1200 $sql_exclude_cats .= " AND post_category != $category"; 1201 } 1202 } 1203 1204 $now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600))); 1205 1206 $limitnext--; 1207 1208 $nextpost = @$wpdb->get_row("SELECT ID,post_title FROM $tableposts WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_status = 'publish' $sqlcat $sql_exclude_cats ORDER BY post_date ASC LIMIT $limitnext,1"); 1209 if ($nextpost) { 1210 $string = '<a href="'.get_permalink($nextpost->ID).'">'.$next; 1211 if ($title=='yes') { 1212 $string .= wptexturize(stripslashes($nextpost->post_title)); 1213 } 1214 $string .= '</a>'; 1215 $format = str_replace('%', $string, $format); 1216 echo $format; 1217 } 1218 } 1219 } 1220 1221 function next_posts($max_page = 0) { // original by cfactor at cooltux.org 1222 global $HTTP_SERVER_VARS, $siteurl, $blogfilename, $p, $paged, $what_to_show, $pagenow; 1223 global $querystring_start, $querystring_equal, $querystring_separator; 1224 if (empty($p) && ($what_to_show == 'paged')) { 1225 $qstr = $HTTP_SERVER_VARS['QUERY_STRING']; 1226 if (!empty($qstr)) { 1227 $qstr = preg_replace("/&paged=\d{0,}/","",$qstr); 1228 $qstr = preg_replace("/paged=\d{0,}/","",$qstr); 1229 } elseif (stristr($HTTP_SERVER_VARS['REQUEST_URI'], $HTTP_SERVER_VARS['SCRIPT_NAME'] )) { 1230 if ('' != $qstr = str_replace($HTTP_SERVER_VARS['SCRIPT_NAME'], '', 1231 $HTTP_SERVER_VARS['REQUEST_URI']) ) { 1232 $qstr = preg_replace("/^\//", "", $qstr); 1233 $qstr = preg_replace("/paged\/\d{0,}\//", "", $qstr); 1234 $qstr = preg_replace("/paged\/\d{0,}/", "", $qstr); 1235 $qstr = preg_replace("/\/$/", "", $qstr); 1236 } 1237 } 1238 if (!$paged) $paged = 1; 1239 $nextpage = intval($paged) + 1; 1240 if (!$max_page || $max_page >= $nextpage) { 1241 echo $siteurl.'/'.$pagenow.$querystring_start. 1242 ($qstr == '' ? '' : $qstr.$querystring_separator) . 1243 'paged'.$querystring_equal.$nextpage; 1244 } 1245 } 1246 } 1247 1248 function next_posts_link($label='Next Page »', $max_page=0) { 1249 global $p, $paged, $result, $request, $posts_per_page, $what_to_show, $wpdb; 1250 if ($what_to_show == 'paged') { 1251 if (!$max_page) { 1252 $nxt_request = $request; 1253 //if the query includes a limit clause, call it again without that 1254 //limit clause! 1255 if ($pos = strpos(strtoupper($request), 'LIMIT')) { 1256 $nxt_request = substr($request, 0, $pos); 1257 } 1258 $nxt_result = $wpdb->query($nxt_request); 1259 $numposts = $wpdb->num_rows; 1260 $max_page = ceil($numposts / $posts_per_page); 1261 } 1262 if (!$paged) 1263 $paged = 1; 1264 $nextpage = intval($paged) + 1; 1265 if (empty($p) && (empty($paged) || $nextpage <= $max_page)) { 1266 echo '<a href="'; 1267 next_posts($max_page); 1268 echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>'; 1269 } 1270 } 1271 } 1272 1273 1274 function previous_posts() { // original by cfactor at cooltux.org 1275 global $HTTP_SERVER_VARS, $siteurl, $blogfilename, $p, $paged, $what_to_show, $pagenow; 1276 global $querystring_start, $querystring_equal, $querystring_separator; 1277 if (empty($p) && ($what_to_show == 'paged')) { 1278 $qstr = $HTTP_SERVER_VARS['QUERY_STRING']; 1279 if (!empty($qstr)) { 1280 $qstr = preg_replace("/&paged=\d{0,}/","",$qstr); 1281 $qstr = preg_replace("/paged=\d{0,}/","",$qstr); 1282 } elseif (stristr($HTTP_SERVER_VARS['REQUEST_URI'], $HTTP_SERVER_VARS['SCRIPT_NAME'] )) { 1283 if ('' != $qstr = str_replace($HTTP_SERVER_VARS['SCRIPT_NAME'], '', 1284 $HTTP_SERVER_VARS['REQUEST_URI']) ) { 1285 $qstr = preg_replace("/^\//", "", $qstr); 1286 $qstr = preg_replace("/paged\/\d{0,}\//", "", $qstr); 1287 $qstr = preg_replace("/paged\/\d{0,}/", "", $qstr); 1288 $qstr = preg_replace("/\/$/", "", $qstr); 1289 } 1290 } 1291 $nextpage = intval($paged) - 1; 1292 if ($nextpage < 1) $nextpage = 1; 1293 echo $siteurl.'/'.$pagenow.$querystring_start. 1294 ($qstr == '' ? '' : $qstr.$querystring_separator) . 1295 'paged'.$querystring_equal.$nextpage; 1296 } 1297 } 1298 1299 function previous_posts_link($label='« Previous Page') { 1300 global $p, $paged, $what_to_show; 1301 if (empty($p) && ($paged > 1) && ($what_to_show == 'paged')) { 1302 echo '<a href="'; 1303 previous_posts(); 1304 echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>'; 1305 } 1306 } 1307 1308 function posts_nav_link($sep=' :: ', $prelabel='<< Previous Page', $nxtlabel='Next Page >>') { 1309 global $p, $what_to_show, $request, $posts_per_page, $wpdb; 1310 if (empty($p) && ($what_to_show == 'paged')) { 1311 $nxt_request = $request; 1312 if ($pos = strpos(strtoupper($request), 'LIMIT')) { 1313 $nxt_request = substr($request, 0, $pos); 1314 } 1315 $nxt_result = $wpdb->query($nxt_request); 1316 $numposts = $wpdb->num_rows; 1317 $max_page = ceil($numposts / $posts_per_page); 1318 if ($max_page > 1) { 1319 previous_posts_link($prelabel); 1320 echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep); 1321 next_posts_link($nxtlabel, $max_page); 1322 } 1323 } 1324 } 1325 1326 /***** // Post tags *****/ 1327 1328 1329 17 require($curpath . 'template-functions-post.php'); 1330 18 1331 19 /***** Category tags *****/ 1332 1333 function get_the_category() { 1334 global $post, $tablecategories, $tablepost2cat, $wpdb, $category_cache; 1335 if ($category_cache[$post->ID]) { 1336 return $category_cache[$post->ID]; 1337 } else { 1338 $categories = $wpdb->get_results(" 1339 SELECT category_id, cat_name, category_nicename, category_description, category_parent 1340 FROM $tablecategories, $tablepost2cat 1341 WHERE $tablepost2cat.category_id = cat_ID AND $tablepost2cat.post_id = $post->ID 1342 "); 1343 1344 return $categories; 1345 } 1346 } 1347 1348 function get_category_link($echo = false, $category_id, $category_nicename) { 1349 global $wpdb, $tablecategories, $post, $querystring_start, $querystring_equal, $siteurl, $blogfilename, $cache_categories; 1350 $cat_ID = $category_id; 1351 $permalink_structure = get_settings('permalink_structure'); 1352 1353 if ('' == $permalink_structure) { 1354 $file = "$siteurl/$blogfilename"; 1355 $link = $file.$querystring_start.'cat'.$querystring_equal.$cat_ID; 1356 } else { 1357 if ('' == $category_nicename) $category_nicename = $cache_categories[$category_id]->category_nicename; 1358 // Get any static stuff from the front 1359 $front = substr($permalink_structure, 0, strpos($permalink_structure, '%')); 1360 $link = $siteurl . $front . 'category/'; 1361 if ($parent=$cache_categories[$category_id]->category_parent) $link .= get_category_parents($parent, FALSE, '/', TRUE); 1362 $link .= $category_nicename . '/'; 1363 } 1364 1365 if ($echo) echo $link; 1366 return $link; 1367 } 1368 1369 function the_category($seperator = '', $parents='') { 1370 $categories = get_the_category(); 1371 if ('' == $seperator) { 1372 echo '<ul class="post-categories">'; 1373 foreach ($categories as $category) { 1374 $category->cat_name = stripslashes($category->cat_name); 1375 echo "\n\t<li>"; 1376 switch(strtolower($parents)) { 1377 case 'multiple': 1378 if ($category->category_parent) echo get_category_parents($category->category_parent, TRUE); 1379 echo "<a href='" . get_category_link(0, $category->category_id, $category->category_nicename) . "' title='View all posts in $category->cat_name'>$category->cat_name</a></li>"; 1380 break; 1381 case 'single': 1382 echo "<a href='" . get_category_link(0, $category->category_id, $category->category_nicename) . "' title='View all posts in $category->cat_name'>"; 1383 if ($category->category_parent)echo get_category_parents($category->category_parent, FALSE); 1384 echo "$category->cat_name</a></li>"; 1385 break; 1386 case '': 1387 default: 1388 echo "<a href='" . get_category_link(0, $category->category_id, $category->category_nicename) . "' title='View all posts in $category->cat_name'>$category->cat_name</a></li>"; 1389 } 1390 } 1391 echo '</ul>'; 1392 } else { 1393 $i = 0; 1394 foreach ($categories as $category) { 1395 $category->cat_name = stripslashes($category->cat_name); 1396 if (0 < $i) echo $seperator . ' '; 1397 switch(strtolower($parents)) { 1398 case 'multiple': 1399 if ($category->category_parent) echo get_category_parents($category->category_parent, TRUE); 1400 echo "<a href='" . get_category_link(0, $category->category_id, $category->category_nicename) . "' title='View all posts in $category->cat_name'>$category->cat_name</a>"; 1401 case 'single': 1402 echo "<a href='" . get_category_link(0, $category->category_id, $category->category_nicename) . "' title='View all posts in $category->cat_name'>"; 1403 if ($category->category_parent)echo get_category_parents($category->category_parent, FALSE); 1404 echo "$category->cat_name</a>"; 1405 case '': 1406 default: 1407 echo "<a href='" . get_category_link(0, $category->category_id, $category->category_nicename) . "' title='View all posts in $category->cat_name'>$category->cat_name</a>"; 1408 } 1409 ++$i; 1410 } 1411 } 1412 } 1413 1414 function the_category_rss($type = 'rss') { 1415 $categories = get_the_category(); 1416 foreach ($categories as $category) { 1417 $category->cat_name = stripslashes(convert_chars($category->cat_name)); 1418 if ('rdf' == $type) { 1419 echo "\n<dc:subject>$category->cat_name</dc:subject>"; 1420 } else { 1421 echo "\n<category>$category->cat_name</category>"; 1422 } 1423 } 1424 1425 } 1426 function the_category_unicode() { 1427 $category = get_the_category(); 1428 $category = apply_filters('the_category_unicode', $category); 1429 echo convert_chars($category, 'unicode'); 1430 } 1431 1432 function get_the_category_by_ID($cat_ID) { 1433 global $tablecategories, $cache_categories, $use_cache, $wpdb; 1434 if ((!$cache_categories[$cat_ID]) OR (!$use_cache)) { 1435 $cat_name = $wpdb->get_var("SELECT cat_name FROM $tablecategories WHERE cat_ID = '$cat_ID'"); 1436 $cache_categories[$cat_ID]->cat_name = $cat_name; 1437 } else { 1438 $cat_name = $cache_categories[$cat_ID]->cat_name; 1439 } 1440 return(stripslashes($cat_name)); 1441 } 1442 1443 function get_category_parents($id, $link=FALSE, $separator=' / ', $nicename=FALSE){ 1444 global $tablecategories, $cache_categories; 1445 $chain = ""; 1446 $parent = $cache_categories[$id]; 1447 if ($nicename) { 1448 $name = $parent->category_nicename; 1449 } else { 1450 $name = $parent->cat_name; 1451 } 1452 if ($parent->category_parent) $chain .= get_category_parents($parent->category_parent, $link, $separator, $nicename); 1453 if ($link) { 1454 $chain .= "<a href='" . get_category_link(0, $parent->cat_ID, $parent->category_nicename) . "' title='View all posts in $parent->cat_name'>$name</a>" . $separator; 1455 } else { 1456 $chain .= $name.$separator; 1457 } 1458 return $chain; 1459 } 1460 1461 function get_category_children($id, $before=' / ', $after='') { 1462 global $tablecategories, $cache_categories; 1463 $c_cache=$cache_categories; // Can't do recursive foreach on a global, have to make a copy 1464 $chain = ""; 1465 foreach ($c_cache as $category){ 1466 if ($category->category_parent == $id){ 1467 $chain .= $before.$category->cat_ID.$after; 1468 $chain .= get_category_children($category->cat_ID, $before, $after); 1469 } 1470 } 1471 return $chain; 1472 } 1473 1474 function the_category_ID($echo=true) { 1475 global $post; 1476 if ($echo) 1477 echo $post->post_category; 1478 else 1479 return $post->post_category; 1480 } 1481 1482 function the_category_head($before='', $after='') { 1483 global $post, $currentcat, $previouscat, $dateformat, $newday; 1484 $currentcat = $post->post_category; 1485 if ($currentcat != $previouscat) { 1486 echo $before; 1487 echo get_the_category_by_ID($currentcat); 1488 echo $after; 1489 $previouscat = $currentcat; 1490 } 1491 } 1492 1493 function category_description($category = 0) { 1494 global $cat, $wpdb, $tablecategories, $cache_categories; 1495 if (!$category) $category = $cat; 1496 $category_description = $cache_categories[$category]->category_description; 1497 $category_description = apply_filters('category_description', $category_description); 1498 return $category_description; 1499 } 1500 1501 // out of the WordPress loop 1502 function dropdown_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', 1503 $optiondates = 0, $optioncount = 0, $hide_empty = 1, $optionnone=FALSE, 1504 $selected=0, $hide=0) { 1505 global $tablecategories, $tableposts, $tablepost2cat, $wpdb; 1506 global $pagenow, $siteurl, $blogfilename; 1507 global $querystring_start, $querystring_equal, $querystring_separator; 1508 if (($file == 'blah') || ($file == '')) $file = "$siteurl/$blogfilename"; 1509 if (!$selected) $selected=$cat; 1510 $sort_column = 'cat_'.$sort_column; 1511 1512 $query = " 1513 SELECT cat_ID, cat_name, category_nicename,category_parent, 1514 COUNT($tablepost2cat.post_id) AS cat_count, 1515 DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth 1516 FROM $tablecategories LEFT JOIN $tablepost2cat ON (cat_ID = category_id) 1517 LEFT JOIN $tableposts ON (ID = post_id) 1518 WHERE cat_ID > 0 1519 "; 1520 if ($hide) { 1521 $query .= " AND cat_ID != $hide"; 1522 $query .= get_category_children($hide, " AND cat_ID != "); 1523 } 1524 $query .=" GROUP BY cat_ID"; 1525 if (intval($hide_empty) == 1) $query .= " HAVING cat_count > 0"; 1526 $query .= " ORDER BY $sort_column $sort_order, post_date DESC"; 1527 1528 $categories = $wpdb->get_results($query); 1529 echo "<select name='cat' class='postform'>\n"; 1530 if (intval($optionall) == 1) { 1531 $all = apply_filters('list_cats', $all); 1532 echo "\t<option value='all'>$all</option>\n"; 1533 } 1534 if (intval($optionnone) == 1) echo "\t<option value='0'>None</option>\n"; 1535 if ($categories) { 1536 foreach ($categories as $category) { 1537 $cat_name = apply_filters('list_cats', $category->cat_name); 1538 echo "\t<option value=\"".$category->cat_ID."\""; 1539 if ($category->cat_ID == $selected) 1540 echo ' selected="selected"'; 1541 echo '>'; 1542 echo stripslashes($cat_name); 1543 if (intval($optioncount) == 1) echo ' ('.$category->cat_count.')'; 1544 if (intval($optiondates) == 1) echo ' '.$category->lastday.'/'.$category->lastmonth; 1545 echo "</option>\n"; 1546 } 1547 } 1548 echo "</select>\n"; 1549 } 1550 1551 // out of the WordPress loop 1552 function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = '', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1, $use_desc_for_title = 0, $children=FALSE, $child_of=0, $categories=0, $recurse=0) { 1553 global $tablecategories, $tableposts, $tablepost2cat, $wpdb; 1554 global $pagenow, $siteurl, $blogfilename; 1555 global $querystring_start, $querystring_equal, $querystring_separator; 1556 // Optiondates now works 1557 if ('' == $file) { 1558 $file = "$siteurl/$blogfilename"; 1559 } 1560 if (intval($categories)==0){ 1561 $sort_column = 'cat_'.$sort_column; 1562 1563 $query = " 1564 SELECT cat_ID, cat_name, category_nicename, category_description, category_parent 1565 FROM $tablecategories 1566 WHERE cat_ID > 0 1567 ORDER BY $sort_column $sort_order"; 1568 1569 $categories = $wpdb->get_results($query); 1570 } 1571 if (intval($hide_empty) == 1 || intval($optioncount) == 1) { 1572 $cat_counts = $wpdb->get_results(" SELECT cat_ID, 1573 COUNT($tablepost2cat.post_id) AS cat_count 1574 FROM $tablecategories LEFT JOIN $tablepost2cat ON (cat_ID = category_id) 1575 LEFT JOIN $tableposts ON (ID = post_id) 1576 GROUP BY category_id"); 1577 foreach ($cat_counts as $cat_count) { 1578 $category_posts["$cat_count->cat_ID"] = $cat_count->cat_count; 1579 } 1580 } 1581 1582 if (intval($optiondates) == 1) { 1583 $cat_dates = $wpdb->get_results(" SELECT cat_ID, 1584 DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth 1585 FROM $tablecategories LEFT JOIN $tablepost2cat ON (cat_ID = category_id) 1586 LEFT JOIN $tableposts ON (ID = post_id) 1587 GROUP BY category_id"); 1588 foreach ($cat_dates as $cat_date) { 1589 $category_lastday["$cat_date->cat_ID"] = $cat_date->lastday; 1590 $category_lastmonth["$cat_date->cat_ID"] = $cat_date->lastmonth; 1591 } 1592 } 1593 1594 if (intval($optionall) == 1 && !$child_of && $categories) { 1595 $all = apply_filters('list_cats', $all); 1596 $link = "<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.'all">'.$all."</a>"; 1597 if ($list) { 1598 echo "\n\t<li>$link</li>"; 1599 } else { 1600 echo "\t$link<br />\n"; 1601 } 1602 } 1603 1604 $num_found=0; 1605 $thelist = ""; 1606 1607 foreach ($categories as $category) { 1608 if ((intval($hide_empty) == 0 || $category_posts["$category->cat_ID"] > 0) && (!$children || $category->category_parent == $child_of)) { 1609 $num_found++; 1610 $link = '<a href="'.get_category_link(0, $category->cat_ID, $category->category_nicename).'" '; 1611 if ($use_desc_for_title == 0 || empty($category->category_description)) { 1612 $link .= 'title="View all posts filed under ' . htmlspecialchars($category->cat_name) . '"'; 1613 } else { 1614 $link .= 'title="' . htmlspecialchars($category->category_description) . '"'; 1615 } 1616 $link .= '>'; 1617 $link .= stripslashes($category->cat_name).'</a>'; 1618 if (intval($optioncount) == 1) { 1619 $link .= ' ('.intval($category_posts["$category->cat_ID"]).')'; 1620 } 1621 if (intval($optiondates) == 1) { 1622 $link .= ' '.$category_lastday["$category->cat_ID"].'/'.$category_lastmonth["$category->cat_ID"]; 1623 } 1624 if ($list) { 1625 $thelist .= "\t<li>$link\n"; 1626 } else { 1627 $thelist .= "\t$link<br />\n"; 1628 } 1629 if ($children) $thelist .= list_cats($optionall, $all, $sort_column, $sort_order, $file, $list, $optiondates, $optioncount, $hide_empty, $use_desc_for_title, $children, $category->cat_ID, $categories, 1); 1630 if ($list) $thelist .= "</li>\n"; 1631 } 1632 } 1633 if (!$num_found && !$child_of){ 1634 if ($list) { 1635 $before = '<li>'; 1636 $after = '</li>'; 1637 } 1638 echo $before . "No categories" . $after . "\n"; 1639 return; 1640 } 1641 if ($list && $child_of && $num_found && $recurse) { 1642 $pre = "\t\t<ul class='children'>"; 1643 $post = "\t\t</ul>\n"; 1644 } 1645 $thelist=$pre.$thelist.$post; 1646 if ($recurse) { 1647 return $thelist; 1648 } 1649 echo $thelist; 1650 } 1651 1652 /***** // Category tags *****/ 1653 1654 1655 1656 1657 /***** <Link> tags *****/ 1658 1659 1660 1661 /***** // <Link> tags *****/ 1662 1663 1664 20 require($curpath . 'template-functions-category.php'); 1665 21 1666 22 /***** Comment tags *****/ 1667 1668 // generic comments/trackbacks/pingbacks numbering 1669 1670 function comments_number($zero='No Comments', $one='1 Comment', $more='% Comments', $number='') { 1671 global $id, $comment, $tablecomments, $wpdb; 1672 if ('' == $number) $number = $wpdb->get_var("SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = $id AND comment_approved = '1'"); 1673 if ($number == 0) { 1674 $blah = $zero; 1675 } elseif ($number == 1) { 1676 $blah = $one; 1677 } elseif ($number > 1) { 1678 $blah = str_replace('%', $number, $more); 1679 } 1680 echo $blah; 1681 } 1682 1683 function comments_link($file='', $echo=true) { 1684 global $id, $pagenow; 1685 if ($file == '') $file = $pagenow; 1686 if ($file == '/') $file = ''; 1687 if (!$echo) return get_permalink() . '#comments'; 1688 else echo get_permalink() . '#comments'; 1689 } 1690 1691 function comments_popup_script($width=400, $height=400, $file='wp-comments-popup.php') { 1692 global $wpcommentspopupfile, $wptrackbackpopupfile, $wppingbackpopupfile, $wpcommentsjavascript; 1693 $wpcommentspopupfile = $file; 1694 $wpcommentsjavascript = 1; 1695 $javascript = "<script type='text/javascript'>\nfunction wpopen (macagna) {\n window.open(macagna, '_blank', 'width=$width,height=$height,scrollbars=yes,status=yes');\n}\n</script>\n"; 1696 echo $javascript; 1697 } 1698 1699 function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') { 1700 global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb, $tablecomments, $HTTP_COOKIE_VARS, $cookiehash; 1701 global $querystring_start, $querystring_equal, $querystring_separator, $siteurl; 1702 global $comment_count_cache; 1703 if ('' == $comment_count_cache["$id"]) { 1704 $number = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $tablecomments WHERE comment_post_ID = $id AND comment_approved = '1';"); 1705 } else { 1706 $number = $comment_count_cache["$id"]; 1707 } 1708 if (0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status) { 1709 echo $none; 1710 return; 1711 } else { 1712 if (!empty($post->post_password)) { // if there's a password 1713 if ($HTTP_COOKIE_VARS['wp-postpass_'.$cookiehash] != $post->post_password) { // and it doesn't match the cookie 1714 echo("Enter your password to view comments"); 1715 return; 1716 } 1717 } 1718 echo '<a href="'; 1719 if ($wpcommentsjavascript) { 1720 echo $siteurl.'/'.$wpcommentspopupfile.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'c'.$querystring_equal.'1'; 1721 //echo get_permalink(); 1722 echo '" onclick="wpopen(this.href); return false"'; 1723 } else { 1724 // if comments_popup_script() is not in the template, display simple comment link 1725 comments_link(); 1726 echo '"'; 1727 } 1728 if (!empty($CSSclass)) { 1729 echo ' class="'.$CSSclass.'"'; 1730 } 1731 echo '>'; 1732 comments_number($zero, $one, $more, $number); 1733 echo '</a>'; 1734 } 1735 } 1736 1737 function comment_ID() { 1738 global $comment; 1739 echo $comment->comment_ID; 1740 } 1741 1742 function comment_author() { 1743 global $comment; 1744 $author = stripslashes(stripslashes($comment->comment_author)); 1745 $author = apply_filters('comment_auther', $author); 1746 $author = convert_chars($author); 1747 if (!empty($author)) { 1748 echo $comment->comment_author; 1749 } 1750 else { 1751 echo "Anonymous"; 1752 } 1753 } 1754 1755 function comment_author_email() { 1756 global $comment; 1757 $email = stripslashes(stripslashes($comment->comment_author_email)); 1758 1759 echo antispambot(stripslashes($comment->comment_author_email)); 1760 } 1761 1762 function comment_author_link() { 1763 global $comment; 1764 $url = trim(stripslashes($comment->comment_author_url)); 1765 $email = stripslashes($comment->comment_author_email); 1766 $author = stripslashes($comment->comment_author); 1767 $author = convert_chars($author); 1768 $author = wptexturize($author); 1769 if (empty($author)) { 1770 $author = "Anonymous"; 1771 } 1772 1773 $url = str_replace('http://url', '', $url); 1774 $url = preg_replace('|[^a-z0-9-_.?#=&;,/:]|i', '', $url); 1775 if (empty($url) && empty($email)) { 1776 echo $author; 1777 return; 1778 } 1779 echo '<a href="'; 1780 if ($url) { 1781 $url = str_replace(';//', '://', $url); 1782 $url = (!strstr($url, '://')) ? 'http://'.$url : $url; 1783 $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&$1', $url); 1784 echo $url; 1785 } else { 1786 echo 'mailto:'.antispambot($email); 1787 } 1788 echo '" rel="external">' . $author . '</a>'; 1789 } 1790 1791 function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') { 1792 global $comment; 1793 if (preg_match('|<trackback />|', $comment->comment_content)) echo $trackbacktxt; 1794 elseif (preg_match('|<pingback />|', $comment->comment_content)) echo $pingbacktxt; 1795 else echo $commenttxt; 1796 } 1797 1798 function comment_author_url() { 1799 global $comment; 1800 $url = trim(stripslashes($comment->comment_author_url)); 1801 $url = str_replace(';//', '://', $url); 1802 $url = (!strstr($url, '://')) ? 'http://'.$url : $url; 1803 // convert & into & 1804 $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&$1', $url); 1805 $url = preg_replace('|[^a-z0-9-_.,/:]|i', '', $url); 1806 if ($url != 'http://url') { 1807 echo $url; 1808 } 1809 } 1810 1811 function comment_author_email_link($linktext='', $before='', $after='') { 1812 global $comment; 1813 $email = $comment->comment_author_email; 1814 if ((!empty($email)) && ($email != '@')) { 1815 $display = ($linktext != '') ? $linktext : antispambot(stripslashes($email)); 1816 echo $before; 1817 echo '<a href="mailto:'.antispambot(stripslashes($email)).'">'.$display.'</a>'; 1818 echo $after; 1819 } 1820 } 1821 1822 function comment_author_url_link($linktext='', $before='', $after='') { 1823 global $comment; 1824 $url = trim(stripslashes($comment->comment_author_url)); 1825 $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&$1', $url); 1826 $url = (!stristr($url, '://')) ? 'http://'.$url : $url; 1827 $url = preg_replace('|[^a-z0-9-_.,/:]|i', '', $url); 1828 if ((!empty($url)) && ($url != 'http://') && ($url != 'http://url')) { 1829 $display = ($linktext != '') ? $linktext : stripslashes($url); 1830 echo $before; 1831 echo '<a href="'.stripslashes($url).'" rel="external">'.$display.'</a>'; 1832 echo $after; 1833 } 1834 } 1835 1836 function comment_author_IP() { 1837 global $comment; 1838 echo stripslashes($comment->comment_author_IP); 1839 } 1840 1841 function comment_text() { 1842 global $comment; 1843 $comment_text = stripslashes($comment->comment_content); 1844 $comment_text = str_replace('<trackback />', '', $comment_text); 1845 $comment_text = str_replace('<pingback />', '', $comment_text); 1846 $comment_text = convert_chars($comment_text); 1847 $comment_text = convert_bbcode($comment_text); 1848 $comment_text = convert_gmcode($comment_text); 1849 $comment_text = make_clickable($comment_text); 1850 $comment_text = balanceTags($comment_text,1); 1851 $comment_text = apply_filters('comment_text', $comment_text); 1852 $comment_text = convert_smilies($comment_text); 1853 echo $comment_text; 1854 } 1855 1856 function comment_date($d='') { 1857 global $comment, $dateformat; 1858 if ($d == '') { 1859 echo mysql2date($dateformat, $comment->comment_date); 1860 } else { 1861 echo mysql2date($d, $comment->comment_date); 1862 } 1863 } 1864 1865 function comment_time($d='') { 1866 global $comment, $timeformat; 1867 if ($d == '') { 1868 echo mysql2date($timeformat, $comment->comment_date); 1869 } else { 1870 echo mysql2date($d, $comment->comment_date); 1871 } 1872 } 1873 1874 function comments_rss_link($link_text='Comments RSS', $commentsrssfilename = 'wp-commentsrss2.php') { 1875 global $id; 1876 global $querystring_start, $querystring_equal, $querystring_separator, $siteurl; 1877 $url = $siteurl.'/'.$commentsrssfilename.$querystring_start.'p'.$querystring_equal.$id; 1878 $url = '<a href="'.$url.'">'.$link_text.'</a>'; 1879 echo $url; 1880 } 1881 1882 function comment_author_rss() { 1883 global $comment; 1884 if (!empty($comment->comment_author)) { 1885 echo htmlspecialchars(strip_tags(stripslashes($comment->comment_author))); 1886 } 1887 else { 1888 echo "Anonymous"; 1889 } 1890 } 1891 1892 function comment_text_rss() { 1893 global $comment; 1894 $comment_text = stripslashes($comment->comment_content); 1895 $comment_text = str_replace('<trackback />', '', $comment_text); 1896 $comment_text = str_replace('<pingback />', '', $comment_text); 1897 $comment_text = convert_chars($comment_text); 1898 $comment_text = convert_bbcode($comment_text); 1899 $comment_text = convert_gmcode($comment_text); 1900 $comment_text = convert_smilies($comment_text); 1901 $comment_text = apply_filters('comment_text', $comment_text); 1902 $comment_text = strip_tags($comment_text); 1903 $comment_text = htmlspecialchars($comment_text); 1904 echo $comment_text; 1905 } 1906 1907 function comment_link_rss() { 1908 global $comment; 1909 echo get_permalink($comment->comment_post_ID).'#comments'; 1910 } 1911 1912 function permalink_comments_rss() { 1913 global $comment; 1914 echo get_permalink($comment->comment_post_ID); 1915 } 1916 1917 /***** // Comment tags *****/ 1918 1919 1920 1921 /***** TrackBack tags *****/ 1922 1923 function trackback_url($display = true) { 1924 global $siteurl, $id; 1925 $tb_url = $siteurl.'/wp-trackback.php/'.$id; 1926 if ($display) { 1927 echo $tb_url; 1928 } else { 1929 return $tb_url; 1930 } 1931 } 1932 1933 1934 function trackback_rdf($timezone = 0) { 1935 global $siteurl, $id, $HTTP_SERVER_VARS; 1936 if (!stristr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'W3C_Validator')) { 1937 echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" '."\n"; 1938 echo ' xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n"; 1939 echo ' xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">'."\n"; 1940 echo '<rdf:Description'."\n"; 1941 echo ' rdf:about="'; 1942 permalink_single(); 1943 echo '"'."\n"; 1944 echo ' dc:identifier="'; 1945 permalink_single(); 1946 echo '"'."\n"; 1947 echo ' dc:title="'.str_replace('--', '--', addslashes(strip_tags(get_the_title()))).'"'."\n"; 1948 echo ' trackback:ping="'.trackback_url(0).'"'." />\n"; 1949 echo '</rdf:RDF>'; 1950 } 1951 } 1952 1953 /***** // TrackBack tags *****/ 1954 1955 1956 /***** Permalink tags *****/ 1957 function permalink_anchor($mode = 'id') { 1958 global $id, $post; 1959 switch(strtolower($mode)) { 1960 case 'title': 1961 $title = sanitize_title($post->post_title) . '-' . $id; 1962 echo '<a id="'.$title.'"></a>'; 1963 break; 1964 case 'id': 1965 default: 1966 echo '<a id="post-'.$id.'"></a>'; 1967 break; 1968 } 1969 } 1970 1971 function permalink_link($file='', $mode = 'id') { 1972 global $post, $pagenow, $cacheweekly, $wpdb; 1973 $file = ($file=='') ? $pagenow : $file; 1974 switch(strtolower($mode)) { 1975 case 'title': 1976 $title = sanitize_title($post->post_title) . '-' . $post->ID; 1977 $anchor = $title; 1978 break; 1979 case 'id': 1980 default: 1981 $anchor = $id; 1982 break; 1983 } 1984 echo get_permalink(); 1985 } 1986 1987 function permalink_single($file = '') { 1988 echo get_permalink(); 1989 } 1990 1991 function permalink_single_rss($file = '') { 1992 global $siteurl; 1993 echo get_permalink(); 1994 } 1995 1996 /***** // Permalink tags *****/ 1997 1998 function allowed_tags() { 1999 global $allowedtags; 2000 foreach($allowedtags as $tag => $attributes) { 2001 $allowed .= "<$tag"; 2002 if (0 < count($attributes)) { 2003 foreach ($attributes as $attribute => $limits) { 2004 $allowed .= " $attribute=\"\""; 2005 } 2006 } 2007 $allowed .= "> "; 2008 } 2009 return htmlentities($allowed); 2010 } 23 require($curpath . 'template-functions-comment.php'); 2011 24 2012 25 ?>
Note: See TracChangeset
for help on using the changeset viewer.