2003-04-21 21:37:11 +00:00
< ? php
/* new and improved ! now with more querystring stuff ! */
if ( ! isset ( $querystring_start )) {
$querystring_start = '?' ;
$querystring_equal = '=' ;
$querystring_separator = '&' ;
}
/* template functions... */
// @@@ These are template tags, you can edit them if you know what you're doing...
/***** About-the-blog tags *****/
/* Note: these tags go anywhere in the template */
function bloginfo ( $show = '' ) {
$info = get_bloginfo ( $show );
$info = convert_bbcode ( $info );
$info = convert_gmcode ( $info );
$info = convert_smilies ( $info );
$info = apply_filters ( 'bloginfo' , $info );
echo convert_chars ( $info , 'html' );
}
function bloginfo_rss ( $show = '' ) {
$info = strip_tags ( get_bloginfo ( $show ));
echo convert_chars ( $info , 'unicode' );
}
function bloginfo_unicode ( $show = '' ) {
$info = get_bloginfo ( $show );
echo convert_chars ( $info , 'unicode' );
}
function get_bloginfo ( $show = '' ) {
2003-05-24 21:50:22 +00:00
global $siteurl , $blogfilename , $blogname , $blogdescription , $siteurl , $admin_email ;
2003-04-21 21:37:11 +00:00
switch ( $show ) {
case " url " :
$output = $siteurl . " / " . $blogfilename ;
break ;
case " description " :
$output = $blogdescription ;
break ;
case " rdf_url " :
2003-11-10 23:45:02 +00:00
$output = $siteurl . '/wp-rdf.php' ;
2003-04-21 21:37:11 +00:00
break ;
case " rss_url " :
2003-11-10 23:45:02 +00:00
$output = $siteurl . '/wp-rss.php' ;
2003-04-21 21:37:11 +00:00
break ;
case " rss2_url " :
2003-11-10 23:45:02 +00:00
$output = $siteurl . '/wp-rss2.php' ;
break ;
case " comments_rss2_url " :
$output = $siteurl . '/wp-commentsrss2.php' ;
2003-04-21 21:37:11 +00:00
break ;
case " pingback_url " :
2003-05-24 21:50:22 +00:00
$output = $siteurl . '/xmlrpc.php' ;
2003-04-21 21:37:11 +00:00
break ;
case " admin_email " :
$output = $admin_email ;
break ;
case " name " :
default :
$output = $blogname ;
break ;
}
2003-11-10 23:45:02 +00:00
return $output ;
2003-04-21 21:37:11 +00:00
}
2003-12-25 00:01:31 +00:00
function wp_title ( $sep = '»' , $display = true ) {
global $wpdb , $tableposts , $tablecategories ;
global $year , $monthnum , $day , $cat , $p , $name ;
// If there's a category
2003-12-27 18:37:30 +00:00
if ( ! empty ( $cat )) {
2003-12-25 00:01:31 +00:00
$title = stripslashes ( get_the_category_by_ID ( $cat ));
2003-12-27 18:37:30 +00:00
}
if ( ! empty ( $category_name )) {
2003-12-25 00:01:31 +00:00
$title = stripslashes ( $wpdb -> get_var ( " SELECT cat_name FROM $tablecategories WHERE category_nicename = ' $category_name ' " ));
}
// If there's a month
if ( ! empty ( $m )) {
$my_year = substr ( $m , 0 , 4 );
$my_month = $month [ substr ( $m , 4 , 2 )];
$title = " $my_year $sep $my_month " ;
}
if ( ! empty ( $year )) {
$title = $year ;
if ( ! empty ( $monthnum )) {
$title .= " $sep $monthnum " ;
}
if ( ! empty ( $day )) {
$title .= " $sep $day " ;
}
}
// If there's a post
if ( intval ( $p ) || '' != $name ) {
if ( ! $p ) {
if ( $year != '' ) {
$year = '' . intval ( $year );
$where .= ' AND YEAR(post_date)=' . $year ;
}
if ( $monthnum != '' ) {
$monthnum = '' . intval ( $monthnum );
$where .= ' AND MONTH(post_date)=' . $monthnum ;
}
if ( $day != '' ) {
$hay = '' . intval ( $day );
$where .= ' AND DAYOFMONTH(post_date)=' . $day ;
}
$p = $wpdb -> get_var ( " SELECT ID FROM $tableposts WHERE post_name = ' $name ' $where " );
}
$post_data = get_postdata ( $p );
$title = strip_tags ( stripslashes ( $post_data [ 'Title' ]));
$title = apply_filters ( 'single_post_title' , $title );
}
// Send it out
2003-12-27 18:37:30 +00:00
if ( $display && $title ) {
2003-12-25 00:01:31 +00:00
echo " $sep $title " ;
2003-12-27 18:37:30 +00:00
} elseif ( ! $display && $title ) {
2003-12-25 00:01:31 +00:00
return " $sep $title " ;
}
}
2003-05-29 14:04:30 +00:00
function single_post_title ( $prefix = '' , $display = true ) {
2003-12-13 17:53:42 +00:00
global $p , $name , $wpdb , $tableposts ;
if ( intval ( $p ) || '' != $name ) {
if ( ! $p ) {
$p = $wpdb -> get_var ( " SELECT ID FROM $tableposts WHERE post_name = ' $name ' " );
}
2003-04-21 21:37:11 +00:00
$post_data = get_postdata ( $p );
$title = $post_data [ 'Title' ];
$title = apply_filters ( 'single_post_title' , $title );
if ( $display ) {
echo $prefix . strip_tags ( stripslashes ( $title ));
} else {
return strip_tags ( stripslashes ( $title ));
}
}
}
2003-05-29 14:04:30 +00:00
function single_cat_title ( $prefix = '' , $display = true ) {
2003-04-21 21:37:11 +00:00
global $cat ;
if ( ! empty ( $cat ) && ! ( strtoupper ( $cat ) == 'ALL' )) {
$my_cat_name = get_the_category_by_ID ( $cat );
if ( ! empty ( $my_cat_name )) {
if ( $display )
echo $prefix . strip_tags ( stripslashes ( $my_cat_name ));
else
return strip_tags ( stripslashes ( $my_cat_name ));
}
}
}
2003-05-29 14:04:30 +00:00
function single_month_title ( $prefix = '' , $display = true ) {
2003-04-21 21:37:11 +00:00
global $m , $month ;
if ( ! empty ( $m )) {
$my_year = substr ( $m , 0 , 4 );
$my_month = $month [ substr ( $m , 4 , 2 )];
if ( $display )
echo $prefix . $my_month . $prefix . $my_year ;
else
return $m ;
}
}
2003-07-25 23:31:11 +00:00
/* link navigation hack by Orien http://icecode.com/ */
2003-09-02 23:23:04 +00:00
function get_archives_link ( $url , $text , $format = " html " , $before = " " , $after = " " ) {
2003-07-25 23:07:38 +00:00
if ( 'link' == $format ) {
2003-08-24 16:46:24 +00:00
return " \t " . '<link rel="archives" title="' . $text . '" href="' . $url . '" />' . " \n " ;
2003-08-04 21:55:10 +00:00
} else if ( 'option' == $format ) {
return '<option value="' . $url . '">' . $text . '</option>' . " \n " ;
2003-09-02 23:23:04 +00:00
} else if ( 'html' == $format ) {
2003-10-26 00:35:45 +00:00
return " \t " . '<li><a href="' . $url . '" title="' . $text . '">' . $text . '</a>' . $after . '</li>' . " \n " ;
2003-11-04 02:08:55 +00:00
} else { // custom
2003-09-02 23:23:04 +00:00
return " \t " . $before . '<a href="' . $url . '" title="' . $text . '">' . $text . '</a>' . $after . " \n " ;
2003-07-25 23:07:38 +00:00
}
}
2003-09-26 07:03:35 +00:00
function get_archives ( $type = '' , $limit = '' , $format = 'html' , $before = " " , $after = " " , $show_post_count = false ) {
2003-06-08 01:12:38 +00:00
global $tableposts , $dateformat , $time_difference , $siteurl , $blogfilename ;
2003-12-05 01:27:00 +00:00
global $querystring_start , $querystring_equal , $querystring_separator , $month , $wpdb , $start_of_week ;
2003-06-08 00:10:07 +00:00
2003-06-08 00:15:39 +00:00
if ( '' == $type ) {
$type = get_settings ( 'archive_mode' );
}
2003-05-21 11:17:09 +00:00
if ( '' != $limit ) {
2003-06-08 00:10:07 +00:00
$limit = ( int ) $limit ;
$limit = " LIMIT $limit " ;
2003-05-21 11:17:09 +00:00
}
// this is what will separate dates on weekly archive links
$archive_week_separator = '–' ;
2003-06-08 00:10:07 +00:00
2003-05-21 11:17:09 +00:00
// archive link url
2003-06-08 00:10:07 +00:00
$archive_link_m = $siteurl . '/' . $blogfilename . $querystring_start . 'm' . $querystring_equal ; # monthly archive;
$archive_link_w = $siteurl . '/' . $blogfilename . $querystring_start . 'w' . $querystring_equal ; # weekly archive;
$archive_link_p = $siteurl . '/' . $blogfilename . $querystring_start . 'p' . $querystring_equal ; # post-by-post archive;
2003-06-08 00:15:39 +00:00
2003-06-08 00:10:07 +00:00
// over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
$archive_date_format_over_ride = 0 ;
// options for daily archive (only if you over-ride the general date format)
$archive_day_date_format = 'Y/m/d' ;
// options for weekly archive (only if you over-ride the general date format)
$archive_week_start_date_format = 'Y/m/d' ;
$archive_week_end_date_format = 'Y/m/d' ;
if ( ! $archive_date_format_over_ride ) {
$archive_day_date_format = $dateformat ;
$archive_week_start_date_format = $dateformat ;
$archive_week_end_date_format = $dateformat ;
}
2003-06-08 00:15:39 +00:00
2003-05-21 11:17:09 +00:00
$now = date ( 'Y-m-d H:i:s' ,( time () + ( $time_difference * 3600 )));
2003-06-08 00:15:39 +00:00
2003-05-29 14:04:30 +00:00
if ( 'monthly' == $type ) {
2003-12-10 09:05:11 +00:00
$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 );
2003-08-04 22:33:27 +00:00
if ( $arcresults ) {
foreach ( $arcresults as $arcresult ) {
2003-11-03 17:45:57 +00:00
$url = get_month_link ( $arcresult -> year , $arcresult -> month );
2003-10-26 00:35:45 +00:00
if ( $show_post_count ) {
2003-09-26 07:03:35 +00:00
$text = sprintf ( " %s %d " , $month [ zeroise ( $arcresult -> month , 2 )], $arcresult -> year );
2003-10-26 00:35:45 +00:00
$after = " ( $arcresult->posts ) " ;
} else {
$text = sprintf ( " %s %d " , $month [ zeroise ( $arcresult -> month , 2 )], $arcresult -> year );
}
2003-09-02 23:23:04 +00:00
echo get_archives_link ( $url , $text , $format , $before , $after );
2003-08-04 22:33:27 +00:00
}
}
2003-05-29 14:04:30 +00:00
} elseif ( 'daily' == $type ) {
2003-12-10 09:05:11 +00:00
$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 );
2003-08-04 22:33:27 +00:00
if ( $arcresults ) {
foreach ( $arcresults as $arcresult ) {
2003-11-03 17:45:57 +00:00
$url = get_day_link ( $arcresult -> year , $arcresult -> month , $arcresult -> dayofmonth );
2003-08-04 22:33:27 +00:00
$date = sprintf ( " %d-%02d-%02d 00:00:00 " , $arcresult -> year , $arcresult -> month , $arcresult -> dayofmonth );
$text = mysql2date ( $archive_day_date_format , $date );
2003-09-02 23:23:04 +00:00
echo get_archives_link ( $url , $text , $format , $before , $after );
2003-08-04 22:33:27 +00:00
}
}
2003-05-29 14:04:30 +00:00
} elseif ( 'weekly' == $type ) {
2003-05-21 11:17:09 +00:00
if ( ! isset ( $start_of_week )) {
$start_of_week = 1 ;
}
2003-12-10 09:05:11 +00:00
$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 );
2003-05-21 11:17:09 +00:00
$arc_w_last = '' ;
2003-08-04 22:33:27 +00:00
if ( $arcresults ) {
foreach ( $arcresults as $arcresult ) {
if ( $arcresult -> week != $arc_w_last ) {
$arc_year = $arcresult -> yr ;
$arc_w_last = $arcresult -> week ;
$arc_week = get_weekstartend ( $arcresult -> yyyymmdd , $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' ]);
2003-11-04 02:08:55 +00:00
$url = sprintf ( " %s/%s%sm%s%s%sw%s%d " , $siteurl , $blogfilename , $querystring_start ,
$querystring_equal , $arc_year , $querystring_separator ,
2003-08-04 22:33:27 +00:00
$querystring_equal , $arcresult -> week );
$text = $arc_week_start . $archive_week_separator . $arc_week_end ;
2003-09-02 23:23:04 +00:00
echo get_archives_link ( $url , $text , $format , $before , $after );
2003-08-04 22:33:27 +00:00
}
}
}
2003-05-29 14:04:30 +00:00
} elseif ( 'postbypost' == $type ) {
2003-12-10 09:05:11 +00:00
$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 );
2003-08-04 22:33:27 +00:00
if ( $arcresults ) {
foreach ( $arcresults as $arcresult ) {
if ( $arcresult -> post_date != '0000-00-00 00:00:00' ) {
2003-10-27 07:00:42 +00:00
$url = get_permalink ( $arcresult -> ID );
2003-08-04 22:33:27 +00:00
$arc_title = stripslashes ( $arcresult -> post_title );
if ( $arc_title ) {
$text = strip_tags ( $arc_title );
} else {
$text = $arcresult -> ID ;
}
2003-09-02 23:23:04 +00:00
echo get_archives_link ( $url , $text , $format , $before , $after );
2003-08-04 22:33:27 +00:00
}
}
}
2003-05-21 11:17:09 +00:00
}
}
2003-11-03 07:30:04 +00:00
2003-11-03 17:22:01 +00:00
function get_calendar ( $daylength = 1 ) {
2003-12-05 01:27:00 +00:00
global $wpdb , $HTTP_GET_VARS , $m , $monthnum , $year , $timedifference , $month , $weekday , $tableposts , $posts ;
2003-11-03 07:30:04 +00:00
2003-11-04 02:08:55 +00:00
// Quick check. If we have no posts at all, abort!
if ( ! $posts ) {
2003-12-10 09:05:11 +00:00
$gotsome = $wpdb -> get_var ( " SELECT ID from $tableposts WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 1 " );
2003-11-04 02:08:55 +00:00
if ( ! $gotsome )
return ;
}
$w = '' . intval ( $HTTP_GET_VARS [ 'w' ]);
$time_difference = get_settings ( 'time_difference' );
// Let's figure out when we are
if ( ! empty ( $monthnum ) && ! empty ( $year )) {
$thismonth = '' . intval ( $monthnum );
$thisyear = '' . intval ( $year );
} elseif ( ! empty ( $w )) {
// We need to get the month from MySQL
$thisyear = '' . intval ( substr ( $m , 0 , 4 ));
$d = (( $w - 1 ) * 7 ) + 6 ; //it seems MySQL's weeks disagree with PHP's
$thismonth = $wpdb -> get_var ( " SELECT DATE_FORMAT((DATE_ADD(' ${ thisyear } 0101', INTERVAL $d DAY) ), '%m') " );
} elseif ( ! empty ( $m )) {
$calendar = substr ( $m , 0 , 6 );
$thisyear = '' . intval ( substr ( $m , 0 , 4 ));
if ( strlen ( $m ) < 6 ) {
$thismonth = '01' ;
} else {
$thismonth = '' . intval ( substr ( $m , 4 , 2 ));
}
2003-11-03 07:30:04 +00:00
} else {
2003-11-04 02:08:55 +00:00
$thisyear = intval ( date ( 'Y' , time () + ( $time_difference * 3600 )));
$thismonth = intval ( date ( 'm' , time () + ( $time_difference * 3600 )));
2003-11-03 07:30:04 +00:00
}
2003-11-04 02:08:55 +00:00
$unixmonth = mktime ( 0 , 0 , 0 , $thismonth , 1 , $thisyear );
// Get the next and previous month and year with at least one post
$previous = $wpdb -> get_row ( " SELECT DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year
FROM $tableposts
WHERE post_date < '$thisyear-$thismonth-01'
AND post_status = 'publish'
ORDER BY post_date DESC
LIMIT 1 " );
$next = $wpdb -> get_row ( " SELECT DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year
FROM $tableposts
WHERE post_date > '$thisyear-$thismonth-01'
AND MONTH ( post_date ) != MONTH ( '$thisyear-$thismonth-01' )
AND post_status = 'publish'
ORDER BY post_date ASC
LIMIT 1 " );
echo ' < table id = " wp-calendar " >
2003-11-03 07:30:04 +00:00
< caption > ' . $month[zeroise($thismonth, 2)] . ' ' . date(' Y ', $unixmonth) . ' </ caption >
2003-11-04 02:08:55 +00:00
< thead >
< tr > ' ;
foreach ( $weekday as $wd ) {
echo " \n \t \t <th abbr=' $wd ' scope='col' title=' $wd '> " . substr ( $wd , 0 , $daylength ) . '</th>' ;
2003-11-03 17:22:01 +00:00
}
2003-11-03 07:30:04 +00:00
2003-11-04 02:08:55 +00:00
echo '
</ tr >
</ thead >
< tfoot >
< tr > ' ;
2003-11-03 07:30:04 +00:00
2003-11-04 02:08:55 +00:00
if ( $previous ) {
echo " \n \t \t " . '<td abbr="' . $month [ zeroise ( $previous -> month , 2 )] . '" colspan="3" id="prev"><a href="' .
get_month_link ( $previous -> year , $previous -> month ) . '" title="View posts for ' . $month [ zeroise ( $previous -> month , 2 )] . ' ' .
date ( 'Y' , mktime ( 0 , 0 , 0 , $previous -> month , 1 , $previous -> year )) . '">« ' . substr ( $month [ zeroise ( $previous -> month , 2 )], 0 , 3 ) . '</a></td>' ;
} else {
2003-11-04 15:12:43 +00:00
echo " \n \t \t " . '<td colspan="3" id="prev" class="pad"> </td>' ;
2003-11-04 02:08:55 +00:00
}
2003-11-03 17:22:01 +00:00
2003-11-04 15:12:43 +00:00
echo " \n \t \t " . '<td class="pad"> </td>' ;
2003-11-03 16:14:54 +00:00
2003-11-04 02:08:55 +00:00
if ( $next ) {
echo " \n \t \t " . '<td abbr="' . $month [ zeroise ( $next -> month , 2 )] . '" colspan="3" id="next"><a href="' .
get_month_link ( $previous -> year , $next -> month ) . '" title="View posts for ' . $month [ zeroise ( $next -> month , 2 )] . ' ' .
date ( 'Y' , mktime ( 0 , 0 , 0 , $next -> month , 1 , $next -> year )) . '">' . substr ( $month [ zeroise ( $next -> month , 2 )], 0 , 3 ) . ' »</a></td>' ;
2003-11-03 16:14:54 +00:00
} else {
2003-11-04 15:12:43 +00:00
echo " \n \t \t " . '<td colspan="3" id="next" class="pad"> </td>' ;
2003-11-04 02:08:55 +00:00
}
echo '
</ tr >
</ tfoot >
< tbody >
< tr > ' ;
// Get days with posts
$dayswithposts = $wpdb -> get_results ( " SELECT DISTINCT DAYOFMONTH(post_date)
FROM $tableposts WHERE MONTH ( post_date ) = $thismonth
AND YEAR ( post_date ) = $thisyear
AND post_status = 'publish'
AND post_date < '" . date("Y-m-d H:i:s", (time() + ($time_difference * 3600)))."' " , ARRAY_N);
if ( $dayswithposts ) {
foreach ( $dayswithposts as $daywith ) {
$daywithpost [] = $daywith [ 0 ];
}
} else {
$daywithpost = array ();
2003-11-03 16:14:54 +00:00
}
2003-11-03 07:30:04 +00:00
2003-11-04 02:08:55 +00:00
2003-11-04 15:12:43 +00:00
if ( strstr ( $_SERVER [ " HTTP_USER_AGENT " ], " MSIE " ) ||
strstr ( strtolower ( $_SERVER [ " HTTP_USER_AGENT " ]), " camino " )) {
$ak_title_separator = " \n " ;
} else {
$ak_title_separator = " , " ;
}
$ak_titles_for_day = array ();
$ak_post_titles = $wpdb -> get_results ( " SELECT post_title, DAYOFMONTH(post_date) as dom "
. " FROM $tableposts "
. " WHERE YEAR(post_date) = ' $thisyear ' "
. " AND MONTH(post_date) = ' $thismonth ' "
. " AND post_date < ' " . date ( " Y-m-d H:i:s " , ( time () + ( $time_difference * 3600 ))) . " ' "
. " AND post_status = 'publish' "
);
if ( $ak_post_titles ) {
foreach ( $ak_post_titles as $ak_post_title ) {
if ( empty ( $ak_titles_for_day [ " $ak_post_title->dom " ])) { // first one
$ak_titles_for_day [ " $ak_post_title->dom " ] .= htmlspecialchars ( stripslashes ( $ak_post_title -> post_title ));
} else {
$ak_titles_for_day [ " $ak_post_title->dom " ] .= $ak_title_separator . htmlspecialchars ( stripslashes ( $ak_post_title -> post_title ));
2003-11-04 02:08:55 +00:00
}
}
}
2003-11-04 15:12:43 +00:00
2003-11-04 02:08:55 +00:00
// See how much we should pad in the beginning
$pad = intval ( date ( 'w' , $unixmonth ));
2003-11-04 15:12:43 +00:00
if ( 0 != $pad ) echo " \n \t \t <td colspan=' $pad ' class='pad'> </td> " ;
2003-11-04 02:08:55 +00:00
$daysinmonth = intval ( date ( 't' , $unixmonth ));
for ( $day = 1 ; $day <= $daysinmonth ; ++ $day ) {
if ( $newrow )
echo " \n \t </tr> \n \t <tr> \n \t \t " ;
$newrow = false ;
if ( $day == date ( 'j' , ( time () + ( $time_difference * 3600 ))) && $thismonth == date ( 'm' , time () + ( $time_difference * 3600 )))
echo '<td id="today">' ;
else
echo " <td> " ;
if ( in_array ( $day , $daywithpost )) { // any posts today?
2003-11-04 15:12:43 +00:00
echo '<a href="' . get_day_link ( $thisyear , $thismonth , $day ) . " \" title= \" $ak_titles_for_day[$day] \" > $day </a> " ;
2003-11-04 02:08:55 +00:00
} else {
echo $day ;
}
echo '</td>' ;
2003-11-04 15:12:43 +00:00
2003-11-04 02:08:55 +00:00
if ( 6 == date ( 'w' , mktime ( 0 , 0 , 0 , $thismonth , $day , $thisyear )))
$newrow = true ;
}
2003-11-04 15:12:43 +00:00
2003-11-04 02:08:55 +00:00
$pad = 7 - date ( 'w' , mktime ( 0 , 0 , 0 , $thismonth , $day , $thisyear ));
if ( 0 != $pad )
2003-11-04 15:12:43 +00:00
echo " \n \t \t <td class='pad' colspan=' $pad '> </td> " ;
2003-11-04 02:08:55 +00:00
echo " \n \t </tr> \n \t </tbody> \n \t </table> " ;
2003-11-03 07:30:04 +00:00
}
2003-04-21 21:37:11 +00:00
/***** // About-the-blog tags *****/
2003-11-02 00:50:48 +00:00
/***** Links *****/
function get_permalink ( $id = false ) {
global $post , $wpdb , $tableposts ;
2003-12-05 01:27:00 +00:00
global $siteurl , $blogfilename , $querystring_start , $querystring_equal ;
2003-11-25 00:46:52 +00:00
2003-11-02 00:50:48 +00:00
$rewritecode = array (
'%year%' ,
'%monthnum%' ,
'%day%' ,
2003-12-04 22:53:15 +00:00
'%postname%' ,
'%post_id%'
2003-11-02 00:50:48 +00:00
);
if ( ! $id ) {
if ( '' != get_settings ( 'permalink_structure' )) {
$unixtime = strtotime ( $post -> post_date );
$rewritereplace = array (
date ( 'Y' , $unixtime ),
date ( 'n' , $unixtime ),
date ( 'j' , $unixtime ),
2003-12-22 23:00:45 +00:00
$post -> post_name ,
$post -> ID
2003-11-02 00:50:48 +00:00
);
return $siteurl . str_replace ( $rewritecode , $rewritereplace , get_settings ( 'permalink_structure' ));
} else { // if they're not using the fancy permalink option
2003-11-11 20:49:00 +00:00
return $siteurl . '/' . $blogfilename . $querystring_start . 'p' . $querystring_equal . $post -> ID ;
2003-11-02 00:50:48 +00:00
}
} else { // if an ID is given
$idpost = $wpdb -> get_row ( " SELECT post_date, post_name FROM $tableposts WHERE ID = $id " );
if ( '' != get_settings ( 'permalink_structure' )) {
$unixtime = strtotime ( $idpost -> post_date );
$rewritereplace = array (
date ( 'Y' , $unixtime ),
date ( 'n' , $unixtime ),
date ( 'j' , $unixtime ),
2003-12-04 22:53:15 +00:00
$idpost -> post_name ,
$id
2003-11-02 00:50:48 +00:00
);
return $siteurl . str_replace ( $rewritecode , $rewritereplace , get_settings ( 'permalink_structure' ));
} else {
2003-11-24 08:24:00 +00:00
return $siteurl . '/' . $blogfilename . $querystring_start . 'p' . $querystring_equal . $id ;
2003-11-02 00:50:48 +00:00
}
}
}
2003-04-21 21:37:11 +00:00
2003-11-02 00:50:48 +00:00
function get_month_link ( $year , $month ) {
global $siteurl , $blogfilename , $querystring_start , $querystring_equal ;
if ( ! $year ) $year = date ( 'Y' , time () + ( $time_difference * 3600 ));
if ( ! $month ) $month = date ( 'm' , time () + ( $time_difference * 3600 ));
if ( '' != get_settings ( 'permalink_structure' )) {
$off = strpos ( get_settings ( 'permalink_structure' ), '%monthnum%' );
$offset = $off + 11 ;
$monthlink = substr ( get_settings ( 'permalink_structure' ), 0 , $offset );
if ( '/' != substr ( $monthlink , - 1 )) $monthlink = substr ( $monthlink , 0 , - 1 );
$monthlink = str_replace ( '%year%' , $year , $monthlink );
$monthlink = str_replace ( '%monthnum%' , intval ( $month ), $monthlink );
2003-12-28 21:45:18 +00:00
return $siteurl . $monthlink ;
2003-11-02 00:50:48 +00:00
} else {
2003-11-03 16:14:54 +00:00
return $siteurl . '/' . $blogfilename . $querystring_start . 'm' . $querystring_equal . $year . zeroise ( $month , 2 );
}
}
function get_day_link ( $year , $month , $day ) {
global $siteurl , $blogfilename , $querystring_start , $querystring_equal ;
if ( ! $year ) $year = date ( 'Y' , time () + ( $time_difference * 3600 ));
if ( ! $month ) $month = date ( 'm' , time () + ( $time_difference * 3600 ));
if ( ! $day ) $day = date ( 'j' , time () + ( $time_difference * 3600 ));
if ( '' != get_settings ( 'permalink_structure' )) {
$off = strpos ( get_settings ( 'permalink_structure' ), '%day%' );
$offset = $off + 6 ;
$daylink = substr ( get_settings ( 'permalink_structure' ), 0 , $offset );
if ( '/' != substr ( $daylink , - 1 )) $daylink = substr ( $daylink , 0 , - 1 );
$daylink = str_replace ( '%year%' , $year , $daylink );
$daylink = str_replace ( '%monthnum%' , intval ( $month ), $daylink );
$daylink = str_replace ( '%day%' , intval ( $day ), $daylink );
2003-12-28 21:45:18 +00:00
return $siteurl . $daylink ;
2003-11-03 16:14:54 +00:00
} else {
return $siteurl . '/' . $blogfilename . $querystring_start . 'm' . $querystring_equal . $year . zeroise ( $month , 2 ) . zeroise ( $day , 2 );
2003-11-02 00:50:48 +00:00
}
}
2003-04-21 21:37:11 +00:00
/***** Date/Time tags *****/
2003-08-05 22:44:38 +00:00
function the_date_xml () {
global $post ;
echo mysql2date ( " Y-m-d " , $post -> post_date );
//echo ""+$post->post_date;
}
2003-05-29 14:04:30 +00:00
function the_date ( $d = '' , $before = '' , $after = '' , $echo = true ) {
2003-12-30 08:34:57 +00:00
global $id , $post , $dateday , $previousday , $dateformat , $newday ;
2003-04-21 21:37:11 +00:00
$the_date = '' ;
2003-12-30 08:34:57 +00:00
$dateday = mysql2date ( 'Yd' , $post -> post_date );
if ( $dateday != $previousday ) {
2003-04-21 21:37:11 +00:00
$the_date .= $before ;
if ( $d == '' ) {
2003-05-29 15:51:10 +00:00
$the_date .= mysql2date ( $dateformat , $post -> post_date );
2003-04-21 21:37:11 +00:00
} else {
2003-05-29 15:51:10 +00:00
$the_date .= mysql2date ( $d , $post -> post_date );
2003-04-21 21:37:11 +00:00
}
$the_date .= $after ;
2003-12-30 08:34:57 +00:00
$previousday = $dateday ;
2003-04-21 21:37:11 +00:00
}
$the_date = apply_filters ( 'the_date' , $the_date );
if ( $echo ) {
echo $the_date ;
} else {
return $the_date ;
}
}
2003-05-29 14:04:30 +00:00
function the_time ( $d = '' , $echo = true ) {
2003-05-29 15:51:10 +00:00
global $id , $post , $timeformat ;
2003-04-21 21:37:11 +00:00
if ( $d == '' ) {
2003-05-29 15:51:10 +00:00
$the_time = mysql2date ( $timeformat , $post -> post_date );
2003-04-21 21:37:11 +00:00
} else {
2003-05-29 15:51:10 +00:00
$the_time = mysql2date ( $d , $post -> post_date );
2003-04-21 21:37:11 +00:00
}
$the_time = apply_filters ( 'the_time' , $the_time );
if ( $echo ) {
echo $the_time ;
} else {
return $the_time ;
}
}
function the_weekday () {
2003-05-29 15:51:10 +00:00
global $weekday , $id , $post ;
$the_weekday = $weekday [ mysql2date ( 'w' , $post -> post_date )];
2003-04-21 21:37:11 +00:00
$the_weekday = apply_filters ( 'the_weekday' , $the_weekday );
echo $the_weekday ;
}
function the_weekday_date ( $before = '' , $after = '' ) {
2003-05-29 15:51:10 +00:00
global $weekday , $id , $post , $day , $previousweekday ;
2003-04-21 21:37:11 +00:00
$the_weekday_date = '' ;
if ( $day != $previousweekday ) {
$the_weekday_date .= $before ;
2003-05-29 15:51:10 +00:00
$the_weekday_date .= $weekday [ mysql2date ( 'w' , $post -> post_date )];
2003-04-21 21:37:11 +00:00
$the_weekday_date .= $after ;
$previousweekday = $day ;
}
$the_weekday_date = apply_filters ( 'the_weekday_date' , $the_weekday_date );
echo $the_weekday_date ;
}
/***** // Date/Time tags *****/
2003-08-05 22:44:38 +00:00
/**** // Geo Tags ****/
function get_Lat () {
global $post ;
return $post -> post_lat ;
}
function get_Lon () {
global $post ;
return $post -> post_lon ;
}
function print_Lat () {
if ( get_settings ( 'use_geo_positions' )) {
if ( get_Lat () > 0 ) {
echo " " . get_Lat () . " N " ;
} else {
echo " " . get_Lat () . " S " ;
}
}
}
function print_Lon () {
global $id , $postdata ;
if ( get_settings ( 'use_geo_positions' )) {
if ( get_Lon () < 0 ) {
$temp = get_Lon () * - 1 ;
echo " " . $temp . " W " ;
} else {
echo " " . get_Lon () . " E " ;
}
}
}
function print_PopUpScript () {
echo "
2003-08-21 15:09:54 +00:00
< script type = 'text/javascript' >
2003-08-05 22:44:38 +00:00
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source !! http :// javascript . internet . com -->
function formHandler ( form ) {
var URL = form . site . options [ form . site . selectedIndex ] . value ;
if ( URL != \ " . \" ) {
popup = window . open ( URL , \ " MenuPopup \" );
}
}
</ script > " ;
}
function print_UrlPopNav () {
2003-11-04 02:08:55 +00:00
$sites = array (
2003-08-10 22:31:26 +00:00
array ( 'http://www.acme.com/mapper/?lat=' . get_Lat () . '&long=' . get_Lon () . '&scale=11&theme=Image&width=3&height=2&dot=Yes' ,
'Acme Mapper' ),
array ( 'http://geourl.org/near/?lat=' . get_Lat () . '&lon=' . get_Lon () . '&dist=500' ,
2003-08-22 23:09:43 +00:00
'GeoURLs near here' ),
2003-08-10 22:31:26 +00:00
array ( 'http://www.geocaching.com/seek/nearest.aspx?origin_lat=' . get_Lat () . '&origin_long=' . get_Lon () . '&dist=5' ,
'Geocaches Near Nere' ),
array ( 'http://www.mapquest.com/maps/map.adp?latlongtype=decimal&latitude=' . get_Lat () . '&longitude=' . get_Lon (),
'Mapquest map of this spot' ),
array ( 'http://www.sidebit.com/ProjectGeoURLMap.php?lat=' . get_Lat () . '&lon=' . get_Lon (),
'SideBit URL Map of this spot' ),
array ( 'http://confluence.org/confluence.php?lat=' . get_Lat () . '&lon=' . get_Lon (),
'Confluence.org near here' ),
array ( 'http://www.topozone.com/map.asp?lat=' . get_Lat () . '&lon=' . get_Lon (),
'Topozone near here' ),
array ( 'http://www.findu.com/cgi-bin/near.cgi?lat=' . get_Lat () . '&lon=' . get_Lon (),
'FindU near here' ),
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' ,
'Maptech near here' )
2003-08-05 22:44:38 +00:00
);
2003-08-23 06:03:38 +00:00
echo ' < form action = " " >< div >
2003-08-22 23:09:43 +00:00
< select name = " site " size = " 1 " onchange = " formHandler(this.form); " > ' . " \n " ;
2003-08-23 06:03:38 +00:00
echo '<option value=".">Sites referencing ' . get_Lat () . ' x ' . get_Lon () . " </option> \n " ;
2003-08-05 22:44:38 +00:00
foreach ( $sites as $site ) {
2003-08-22 23:11:03 +00:00
echo " \t " . '<option value="' . $site [ 0 ] . '">' . $site [ 1 ] . " </option> \n " ;
2003-08-05 22:44:38 +00:00
}
2003-08-23 06:03:38 +00:00
echo ' </ select ></ div >
2003-08-22 23:09:43 +00:00
</ form > ' . " \n " ;
2003-08-05 22:44:38 +00:00
}
function longitude_invalid () {
if ( get_Lon () == null ) return true ;
if ( get_Lon () > 360 ) return true ;
if ( get_Lon () < - 360 ) return true ;
}
function print_AcmeMap_Url () {
if ( ! get_settings ( 'use_geo_positions' )) return ;
if ( longitude_invalid ()) return ;
2003-08-10 22:31:26 +00:00
echo " http://www.acme.com/mapper/?lat= " . get_Lat () . " &long= " . get_Lon () . " &scale=11&theme=Image&width=3&height=2&dot=Yes " ;
2003-08-05 22:44:38 +00:00
}
function print_GeoURL_Url () {
if ( ! get_settings ( 'use_geo_positions' )) return ;
if ( longitude_invalid ()) return ;
2003-08-10 22:31:26 +00:00
echo " http://geourl.org/near/?lat= " . get_Lat () . " &lon= " . get_Lon () . " &dist=500 " ;
2003-08-05 22:44:38 +00:00
}
function print_GeoCache_Url () {
if ( ! get_settings ( 'use_geo_positions' )) return ;
if ( longitude_invalid ()) return ;
2003-08-10 22:31:26 +00:00
echo " http://www.geocaching.com/seek/nearest.aspx?origin_lat= " . get_Lat () . " &origin_long= " . get_Lon () . " &dist=5 " ;
2003-08-05 22:44:38 +00:00
}
function print_MapQuest_Url () {
if ( ! get_settings ( 'use_geo_positions' )) return ;
if ( longitude_invalid ()) return ;
2003-08-10 22:31:26 +00:00
echo " http://www.mapquest.com/maps/map.adp?latlongtype=decimal&latitude= " . get_Lat () . " &longitude= " . get_Lon ();
2003-08-05 22:44:38 +00:00
}
function print_SideBit_Url () {
if ( ! get_settings ( 'use_geo_positions' )) return ;
if ( longitude_invalid ()) return ;
2003-08-10 22:31:26 +00:00
echo " http://www.sidebit.com/ProjectGeoURLMap.php?lat= " . get_Lat () . " &lon= " . get_Lon ();
2003-08-05 22:44:38 +00:00
}
function print_DegreeConfluence_Url () {
if ( ! get_settings ( 'use_geo_positions' )) return ;
if ( longitude_invalid ()) return ;
2003-08-10 22:31:26 +00:00
echo " http://confluence.org/confluence.php?lat= " . get_Lat () . " &lon= " . get_Lon ();
2003-08-05 22:44:38 +00:00
}
2003-04-21 21:37:11 +00:00
/***** Author tags *****/
function the_author () {
2003-05-29 15:51:10 +00:00
global $id , $authordata ;
2003-06-01 11:57:50 +00:00
$i = $authordata -> user_idmode ;
if ( $i == 'nickname' ) echo $authordata -> user_nickname ;
if ( $i == 'login' ) echo $authordata -> user_login ;
if ( $i == 'firstname' ) echo $authordata -> user_firstname ;
if ( $i == 'lastname' ) echo $authordata -> user_lastname ;
if ( $i == 'namefl' ) echo $authordata -> user_firstname . ' ' . $authordata -> user_lastname ;
if ( $i == 'namelf' ) echo $authordata -> user_lastname . ' ' . $authordata -> user_firstname ;
if ( ! $i ) echo $authordata -> user_nickname ;
2003-04-21 21:37:11 +00:00
}
function the_author_login () {
2003-06-01 11:57:50 +00:00
global $id , $authordata ; echo $authordata -> user_login ;
2003-04-21 21:37:11 +00:00
}
function the_author_firstname () {
2003-06-01 11:57:50 +00:00
global $id , $authordata ; echo $authordata -> user_firstname ;
2003-04-21 21:37:11 +00:00
}
function the_author_lastname () {
2003-06-01 11:57:50 +00:00
global $id , $authordata ; echo $authordata -> user_lastname ;
2003-04-21 21:37:11 +00:00
}
function the_author_nickname () {
2003-06-01 11:57:50 +00:00
global $id , $authordata ; echo $authordata -> user_nickname ;
2003-04-21 21:37:11 +00:00
}
function the_author_ID () {
2003-06-01 11:57:50 +00:00
global $id , $authordata ; echo $authordata -> ID ;
2003-04-21 21:37:11 +00:00
}
function the_author_email () {
2003-06-01 11:57:50 +00:00
global $id , $authordata ; echo antispambot ( $authordata -> user_email );
2003-04-21 21:37:11 +00:00
}
function the_author_url () {
2003-06-01 11:57:50 +00:00
global $id , $authordata ; echo $authordata -> user_url ;
2003-04-21 21:37:11 +00:00
}
function the_author_icq () {
2003-06-01 11:57:50 +00:00
global $id , $authordata ; echo $authordata -> user_icq ;
2003-04-21 21:37:11 +00:00
}
function the_author_aim () {
2003-06-01 11:57:50 +00:00
global $id , $authordata ; echo str_replace ( ' ' , '+' , $authordata -> user_aim );
2003-04-21 21:37:11 +00:00
}
function the_author_yim () {
2003-06-01 11:57:50 +00:00
global $id , $authordata ; echo $authordata -> user_yim ;
2003-04-21 21:37:11 +00:00
}
function the_author_msn () {
2003-06-01 11:57:50 +00:00
global $id , $authordata ; echo $authordata -> user_msn ;
2003-04-21 21:37:11 +00:00
}
function the_author_posts () {
2003-05-29 15:51:10 +00:00
global $id , $postdata ; $posts = get_usernumposts ( $post -> post_author ); echo $posts ;
2003-04-21 21:37:11 +00:00
}
/***** // Author tags *****/
/***** Post tags *****/
2003-09-28 18:23:52 +00:00
function get_the_password_form () {
$output = " <form action=' " . get_settings ( 'siteurl' ) . " /wp-pass.php' method='post'>
< p > This post is password protected . To view it please enter your password below :</ p >
< p >< label > Password : < input name = 'post_password' type = 'text' size = '20' /></ label > < input type = 'submit' name = 'Submit' value = 'Submit' /></ p >
</ form >
" ;
return $output ;
}
2003-04-21 21:37:11 +00:00
function the_ID () {
global $id ;
echo $id ;
}
2003-09-09 22:33:47 +00:00
function the_title ( $before = '' , $after = '' , $echo = true ) {
2003-04-21 21:37:11 +00:00
$title = get_the_title ();
$title = convert_bbcode ( $title );
$title = convert_gmcode ( $title );
$title = convert_smilies ( $title );
if ( $title ) {
2003-08-12 22:23:33 +00:00
$title = convert_chars ( $before . $title . $after );
$title = apply_filters ( 'the_title' , $title );
2003-09-09 22:33:47 +00:00
if ( $echo )
echo $title ;
else
return $title ;
2003-04-21 21:37:11 +00:00
}
}
function the_title_rss () {
$title = get_the_title ();
$title = convert_bbcode ( $title );
$title = convert_gmcode ( $title );
$title = strip_tags ( $title );
if ( trim ( $title )) {
echo convert_chars ( $title , 'unicode' );
}
}
function the_title_unicode ( $before = '' , $after = '' ) {
$title = get_the_title ();
$title = convert_bbcode ( $title );
$title = convert_gmcode ( $title );
2003-08-12 22:23:33 +00:00
if ( $title ) {
$title = convert_chars ( $before . $title . $after );
$title = apply_filters ( 'the_title_unicode' , $title );
echo $title ;
2003-04-21 21:37:11 +00:00
}
}
function get_the_title () {
2003-05-29 15:51:10 +00:00
global $id , $post ;
$output = stripslashes ( $post -> post_title );
2003-08-20 22:59:20 +00:00
if ( ! empty ( $post -> post_password )) { // if there's a password
$output = 'Protected: ' . $output ;
}
return $output ;
2003-04-21 21:37:11 +00:00
}
function the_content ( $more_link_text = '(more...)' , $stripteaser = 0 , $more_file = '' ) {
2003-05-29 15:51:10 +00:00
$content = get_the_content ( $more_link_text , $stripteaser , $more_file );
2003-04-21 21:37:11 +00:00
$content = convert_bbcode ( $content );
$content = convert_gmcode ( $content );
$content = convert_smilies ( $content );
$content = convert_chars ( $content , 'html' );
$content = apply_filters ( 'the_content' , $content );
echo $content ;
}
2003-11-03 17:45:57 +00:00
2003-04-21 21:37:11 +00:00
function the_content_rss ( $more_link_text = '(more...)' , $stripteaser = 0 , $more_file = '' , $cut = 0 , $encode_html = 0 ) {
2003-05-29 15:51:10 +00:00
$content = get_the_content ( $more_link_text , $stripteaser , $more_file );
2003-04-21 21:37:11 +00:00
$content = convert_bbcode ( $content );
$content = convert_gmcode ( $content );
$content = convert_chars ( $content , 'unicode' );
if ( $cut && ! $encode_html ) {
$encode_html = 2 ;
}
if ( $encode_html == 1 ) {
$content = htmlspecialchars ( $content );
$cut = 0 ;
} elseif ( $encode_html == 0 ) {
$content = make_url_footnote ( $content );
} elseif ( $encode_html == 2 ) {
$content = strip_tags ( $content );
}
if ( $cut ) {
$blah = explode ( ' ' , $content );
if ( count ( $blah ) > $cut ) {
$k = $cut ;
$use_dotdotdot = 1 ;
} else {
$k = count ( $blah );
$use_dotdotdot = 0 ;
}
for ( $i = 0 ; $i < $k ; $i ++ ) {
$excerpt .= $blah [ $i ] . ' ' ;
}
$excerpt .= ( $use_dotdotdot ) ? '...' : '' ;
$content = $excerpt ;
}
echo $content ;
}
2003-05-29 15:51:10 +00:00
2003-04-21 21:37:11 +00:00
function the_content_unicode ( $more_link_text = '(more...)' , $stripteaser = 0 , $more_file = '' ) {
2003-05-29 15:51:10 +00:00
$content = get_the_content ( $more_link_text , $stripteaser , $more_file );
2003-04-21 21:37:11 +00:00
$content = convert_bbcode ( $content );
$content = convert_gmcode ( $content );
$content = convert_smilies ( $content );
$content = convert_chars ( $content , 'unicode' );
$content = apply_filters ( 'the_content_unicode' , $content );
echo $content ;
}
2003-05-29 15:51:10 +00:00
2003-04-21 21:37:11 +00:00
function get_the_content ( $more_link_text = '(more...)' , $stripteaser = 0 , $more_file = '' ) {
2003-05-29 15:51:10 +00:00
global $id , $post , $more , $c , $withcomments , $page , $pages , $multipage , $numpages ;
2003-10-20 20:53:13 +00:00
global $HTTP_SERVER_VARS , $HTTP_COOKIE_VARS , $preview , $cookiehash ;
2003-04-21 21:37:11 +00:00
global $querystring_start , $querystring_equal , $querystring_separator ;
global $pagenow ;
$output = '' ;
2003-11-04 02:08:55 +00:00
2003-08-20 22:59:20 +00:00
if ( ! empty ( $post -> post_password )) { // if there's a password
2003-10-20 20:53:13 +00:00
if ( $HTTP_COOKIE_VARS [ 'wp-postpass_' . $cookiehash ] != $post -> post_password ) { // and it doesn't match the cookie
2003-09-28 18:23:52 +00:00
$output = get_the_password_form ();
2003-08-20 22:59:20 +00:00
return $output ;
}
}
2003-04-21 21:37:11 +00:00
if ( $more_file != '' ) {
2003-05-29 15:51:10 +00:00
$file = $more_file ;
2003-04-21 21:37:11 +00:00
} else {
2003-05-29 15:51:10 +00:00
$file = $pagenow ; //$HTTP_SERVER_VARS['PHP_SELF'];
2003-04-21 21:37:11 +00:00
}
2003-05-29 15:51:10 +00:00
$content = $pages [ $page - 1 ];
$content = explode ( '<!--more-->' , $content );
if (( preg_match ( '/<!--noteaser-->/' , $post -> post_content ) && (( ! $multipage ) || ( $page == 1 ))))
$stripteaser = 1 ;
$teaser = $content [ 0 ];
2003-04-21 21:37:11 +00:00
if (( $more ) && ( $stripteaser ))
2003-05-29 15:51:10 +00:00
$teaser = '' ;
2003-04-21 21:37:11 +00:00
$output .= $teaser ;
if ( count ( $content ) > 1 ) {
if ( $more ) {
2003-12-10 19:06:28 +00:00
$output .= '<a id="more-' . $id . '"></a>' . $content [ 1 ];
2003-04-21 21:37:11 +00:00
} else {
2003-12-10 19:06:28 +00:00
$output .= " <a href=' " . get_permalink () . " #more- $id '> $more_link_text </a> " ;
2003-04-21 21:37:11 +00:00
}
}
if ( $preview ) { // preview fix for javascript bug with foreign languages
$output = preg_replace ( '/\%u([0-9A-F]{4,4})/e' , " '&#'.base_convert(' \\ 1',16,10).';' " , $output );
}
2003-11-10 23:45:02 +00:00
return $output ;
2003-04-21 21:37:11 +00:00
}
2003-04-24 01:04:42 +00:00
function the_excerpt () {
$excerpt = get_the_excerpt ();
$excerpt = convert_bbcode ( $excerpt );
$excerpt = convert_gmcode ( $excerpt );
$excerpt = convert_smilies ( $excerpt );
$excerpt = convert_chars ( $excerpt , 'html' );
$excerpt = apply_filters ( 'the_excerpt' , $excerpt );
echo $excerpt ;
}
function the_excerpt_rss ( $cut = 0 , $encode_html = 0 ) {
2003-05-24 23:44:19 +00:00
$output = get_the_excerpt ( true );
$output = convert_bbcode ( $output );
$output = convert_gmcode ( $output );
$output = convert_chars ( $output , 'unicode' );
2003-04-24 01:04:42 +00:00
if ( $cut && ! $encode_html ) {
$encode_html = 2 ;
}
if ( $encode_html == 1 ) {
2003-05-24 23:44:19 +00:00
$output = htmlspecialchars ( $output );
2003-04-24 01:04:42 +00:00
$cut = 0 ;
} elseif ( $encode_html == 0 ) {
2003-05-24 23:44:19 +00:00
$output = make_url_footnote ( $output );
2003-04-24 01:04:42 +00:00
} elseif ( $encode_html == 2 ) {
2003-05-24 23:44:19 +00:00
$output = strip_tags ( $output );
2003-04-24 01:04:42 +00:00
}
if ( $cut ) {
2003-11-30 00:55:19 +00:00
$excerpt = '' ;
2003-05-24 23:44:19 +00:00
$blah = explode ( ' ' , $output );
2003-04-24 01:04:42 +00:00
if ( count ( $blah ) > $cut ) {
$k = $cut ;
$use_dotdotdot = 1 ;
} else {
$k = count ( $blah );
$use_dotdotdot = 0 ;
}
for ( $i = 0 ; $i < $k ; $i ++ ) {
$excerpt .= $blah [ $i ] . ' ' ;
}
$excerpt .= ( $use_dotdotdot ) ? '...' : '' ;
2003-05-24 23:44:19 +00:00
$output = $excerpt ;
2003-04-24 01:04:42 +00:00
}
2003-05-24 23:44:19 +00:00
echo $output ;
2003-04-24 01:04:42 +00:00
}
2003-05-06 22:15:28 +00:00
2003-04-24 01:04:42 +00:00
function the_excerpt_unicode () {
$excerpt = get_the_excerpt ();
$excerpt = convert_bbcode ( $excerpt );
$excerpt = convert_gmcode ( $excerpt );
$excerpt = convert_smilies ( $excerpt );
$excerpt = convert_chars ( $excerpt , 'unicode' );
$excerpt = apply_filters ( 'the_excerpt_unicode' , $excerpt );
echo $excerpt ;
}
2003-05-06 22:15:28 +00:00
2003-05-24 23:14:04 +00:00
function get_the_excerpt ( $fakeit = false ) {
2003-05-29 15:51:10 +00:00
global $id , $post ;
2003-10-20 20:53:13 +00:00
global $HTTP_SERVER_VARS , $HTTP_COOKIE_VARS , $preview , $cookiehash ;
2003-04-24 01:04:42 +00:00
$output = '' ;
2003-09-22 22:57:41 +00:00
$output = stripslashes ( $post -> post_excerpt );
2003-08-20 22:59:20 +00:00
if ( ! empty ( $post -> post_password )) { // if there's a password
2003-10-20 20:53:13 +00:00
if ( $HTTP_COOKIE_VARS [ 'wp-postpass_' . $cookiehash ] != $post -> post_password ) { // and it doesn't match the cookie
2003-08-20 22:59:20 +00:00
$output = " There is no excerpt because this is a protected post. " ;
return $output ;
}
}
2003-05-06 22:15:28 +00:00
//if we haven't got an excerpt, make one in the style of the rss ones
2003-05-24 23:14:04 +00:00
if (( $output == '' ) && $fakeit ) {
2003-05-06 22:15:28 +00:00
$output = get_the_content ();
$output = strip_tags ( $output );
$blah = explode ( ' ' , $output );
$excerpt_length = 120 ;
if ( count ( $blah ) > $excerpt_length ) {
$k = $excerpt_length ;
$use_dotdotdot = 1 ;
} else {
$k = count ( $blah );
$use_dotdotdot = 0 ;
}
2003-11-30 00:55:19 +00:00
$excerpt = '' ;
2003-05-06 22:15:28 +00:00
for ( $i = 0 ; $i < $k ; $i ++ ) {
$excerpt .= $blah [ $i ] . ' ' ;
}
$excerpt .= ( $use_dotdotdot ) ? '...' : '' ;
$output = $excerpt ;
} // end if no excerpt
2003-04-24 01:04:42 +00:00
if ( $preview ) { // preview fix for javascript bug with foreign languages
$output = preg_replace ( '/\%u([0-9A-F]{4,4})/e' , " '&#'.base_convert(' \\ 1',16,10).';' " , $output );
}
2003-05-06 22:15:28 +00:00
return $output ;
2003-04-24 01:04:42 +00:00
}
2003-04-21 21:37:11 +00:00
function link_pages ( $before = '<br />' , $after = '<br />' , $next_or_number = 'number' , $nextpagelink = 'next page' , $previouspagelink = 'previous page' , $pagelink = '%' , $more_file = '' ) {
2003-05-29 15:51:10 +00:00
global $id , $page , $numpages , $multipage , $more ;
2003-04-21 21:37:11 +00:00
global $pagenow ;
global $querystring_start , $querystring_equal , $querystring_separator ;
if ( $more_file != '' ) {
$file = $more_file ;
} else {
$file = $pagenow ;
}
2003-12-10 19:06:28 +00:00
if (( $multipage )) {
2003-04-21 21:37:11 +00:00
if ( $next_or_number == 'number' ) {
echo $before ;
for ( $i = 1 ; $i < ( $numpages + 1 ); $i = $i + 1 ) {
$j = str_replace ( '%' , " $i " , $pagelink );
echo " " ;
2003-12-10 19:06:28 +00:00
if (( $i != $page ) || (( ! $more ) && ( $page == 1 ))) {
if ( '' == get_settings ( 'permalink_structure' )) {
echo '<a href="' . get_permalink () . $querystring_separator . 'page' . $querystring_equal . $i . '">' ;
} else {
echo '<a href="' . get_permalink () . $i . '/">' ;
}
}
2003-04-21 21:37:11 +00:00
echo $j ;
if (( $i != $page ) || (( ! $more ) && ( $page == 1 )))
echo '</a>' ;
}
echo $after ;
} else {
if ( $more ) {
echo $before ;
$i = $page - 1 ;
2003-12-10 19:06:28 +00:00
if ( $i && $more ) {
if ( '' == get_settings ( 'permalink_structure' )) {
echo '<a href="' . get_permalink () . $querystring_separator . 'page' . $querystring_equal . $i . '">' ;
} else {
echo '<a href="' . get_permalink () . $i . '/">' ;
}
}
2003-04-21 21:37:11 +00:00
$i = $page + 1 ;
2003-12-10 19:06:28 +00:00
if ( $i <= $numpages && $more ) {
if ( '' == get_settings ( 'permalink_structure' )) {
echo '<a href="' . get_permalink () . $querystring_separator . 'page' . $querystring_equal . $i . '">' ;
} else {
echo '<a href="' . get_permalink () . $i . '/">' ;
}
}
2003-04-21 21:37:11 +00:00
echo $after ;
}
}
}
}
function previous_post ( $format = '%' , $previous = 'previous post: ' , $title = 'yes' , $in_same_cat = 'no' , $limitprev = 1 , $excluded_categories = '' ) {
2003-12-05 01:27:00 +00:00
global $tableposts , $id , $post , $siteurl , $blogfilename , $wpdb ;
2003-10-27 20:27:38 +00:00
global $p , $posts , $posts_per_page , $s , $single ;
2003-04-21 21:37:11 +00:00
global $querystring_start , $querystring_equal , $querystring_separator ;
2003-10-27 20:27:38 +00:00
if (( $p ) || ( $posts_per_page == 1 ) || 1 == $single ) {
2003-06-08 00:15:39 +00:00
2003-05-29 15:51:10 +00:00
$current_post_date = $post -> post_date ;
$current_category = $post -> post_category ;
2003-04-21 21:37:11 +00:00
$sqlcat = '' ;
if ( $in_same_cat != 'no' ) {
2003-05-29 15:51:10 +00:00
$sqlcat = " AND post_category = ' $current_category ' " ;
2003-04-21 21:37:11 +00:00
}
$sql_exclude_cats = '' ;
if ( ! empty ( $excluded_categories )) {
$blah = explode ( 'and' , $excluded_categories );
foreach ( $blah as $category ) {
$category = intval ( $category );
$sql_exclude_cats .= " AND post_category != $category " ;
}
}
$limitprev -- ;
2003-12-10 09:05:11 +00:00
$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 " );
2003-05-29 15:51:10 +00:00
if ( $lastpost ) {
2003-10-27 07:00:42 +00:00
$string = '<a href="' . get_permalink ( $lastpost -> ID ) . '">' . $previous ;
2003-06-30 22:27:21 +00:00
if ( $title == 'yes' ) {
$string .= wptexturize ( stripslashes ( $lastpost -> post_title ));
}
2003-04-21 21:37:11 +00:00
$string .= '</a>' ;
2003-05-29 15:51:10 +00:00
$format = str_replace ( '%' , $string , $format );
2003-04-21 21:37:11 +00:00
echo $format ;
}
}
}
function next_post ( $format = '%' , $next = 'next post: ' , $title = 'yes' , $in_same_cat = 'no' , $limitnext = 1 , $excluded_categories = '' ) {
2003-12-05 01:27:00 +00:00
global $tableposts , $p , $posts , $id , $post , $siteurl , $blogfilename , $wpdb ;
2003-10-27 20:27:38 +00:00
global $time_difference , $single ;
2003-04-21 21:37:11 +00:00
global $querystring_start , $querystring_equal , $querystring_separator ;
2003-10-27 20:27:38 +00:00
if (( $p ) || ( $posts == 1 ) || 1 == $single ) {
2003-06-08 00:15:39 +00:00
2003-05-29 15:51:10 +00:00
$current_post_date = $post -> post_date ;
$current_category = $post -> post_category ;
2003-04-21 21:37:11 +00:00
$sqlcat = '' ;
if ( $in_same_cat != 'no' ) {
$sqlcat = " AND post_category=' $current_category ' " ;
}
$sql_exclude_cats = '' ;
if ( ! empty ( $excluded_categories )) {
$blah = explode ( 'and' , $excluded_categories );
foreach ( $blah as $category ) {
$category = intval ( $category );
$sql_exclude_cats .= " AND post_category != $category " ;
}
}
$now = date ( 'Y-m-d H:i:s' ,( time () + ( $time_difference * 3600 )));
$limitnext -- ;
2003-12-10 09:05:11 +00:00
$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 " );
2003-05-29 15:51:10 +00:00
if ( $nextpost ) {
2003-10-27 07:00:42 +00:00
$string = '<a href="' . get_permalink ( $nextpost -> ID ) . '">' . $next ;
2003-04-21 21:37:11 +00:00
if ( $title == 'yes' ) {
2003-05-29 15:51:10 +00:00
$string .= wptexturize ( stripslashes ( $nextpost -> post_title ));
2003-04-21 21:37:11 +00:00
}
$string .= '</a>' ;
2003-05-29 15:51:10 +00:00
$format = str_replace ( '%' , $string , $format );
2003-04-21 21:37:11 +00:00
echo $format ;
}
}
}
function next_posts ( $max_page = 0 ) { // original by cfactor at cooltux.org
global $HTTP_SERVER_VARS , $siteurl , $blogfilename , $p , $paged , $what_to_show , $pagenow ;
global $querystring_start , $querystring_equal , $querystring_separator ;
if ( empty ( $p ) && ( $what_to_show == 'paged' )) {
$qstr = $HTTP_SERVER_VARS [ 'QUERY_STRING' ];
if ( ! empty ( $qstr )) {
$qstr = preg_replace ( " /&paged= \ d { 0,}/ " , " " , $qstr );
$qstr = preg_replace ( " /paged= \ d { 0,}/ " , " " , $qstr );
} elseif ( stristr ( $HTTP_SERVER_VARS [ 'REQUEST_URI' ], $HTTP_SERVER_VARS [ 'SCRIPT_NAME' ] )) {
2003-06-08 00:15:39 +00:00
if ( '' != $qstr = str_replace ( $HTTP_SERVER_VARS [ 'SCRIPT_NAME' ], '' ,
2003-04-21 21:37:11 +00:00
$HTTP_SERVER_VARS [ 'REQUEST_URI' ]) ) {
$qstr = preg_replace ( " /^ \ // " , " " , $qstr );
2003-06-08 00:15:39 +00:00
$qstr = preg_replace ( " /paged \ / \ d { 0,} \ // " , " " , $qstr );
2003-04-21 21:37:11 +00:00
$qstr = preg_replace ( " /paged \ / \ d { 0,}/ " , " " , $qstr );
$qstr = preg_replace ( " / \ / $ / " , " " , $qstr );
}
}
if ( ! $paged ) $paged = 1 ;
$nextpage = intval ( $paged ) + 1 ;
if ( ! $max_page || $max_page >= $nextpage ) {
echo $pagenow . $querystring_start .
( $qstr == '' ? '' : $qstr . $querystring_separator ) .
'paged' . $querystring_equal . $nextpage ;
}
}
}
2003-10-27 07:00:42 +00:00
function next_posts_link ( $label = 'Next Page »' , $max_page = 0 ) {
2003-07-30 23:44:08 +00:00
global $p , $paged , $result , $request , $posts_per_page , $what_to_show , $wpdb ;
2003-04-21 21:37:11 +00:00
if ( $what_to_show == 'paged' ) {
if ( ! $max_page ) {
$nxt_request = $request ;
2003-07-30 23:44:08 +00:00
//if the query includes a limit clause, call it again without that
//limit clause!
2003-04-21 21:37:11 +00:00
if ( $pos = strpos ( strtoupper ( $request ), 'LIMIT' )) {
$nxt_request = substr ( $request , 0 , $pos );
}
2003-07-30 23:44:08 +00:00
$nxt_result = $wpdb -> query ( $nxt_request );
$numposts = $wpdb -> num_rows ;
2003-04-21 21:37:11 +00:00
$max_page = ceil ( $numposts / $posts_per_page );
}
2003-07-30 23:44:08 +00:00
if ( ! $paged )
$paged = 1 ;
2003-04-21 21:37:11 +00:00
$nextpage = intval ( $paged ) + 1 ;
if ( empty ( $p ) && ( empty ( $paged ) || $nextpage <= $max_page )) {
echo '<a href="' ;
echo next_posts ( $max_page );
echo '">' . htmlspecialchars ( $label ) . '</a>' ;
}
}
}
function previous_posts () { // original by cfactor at cooltux.org
global $HTTP_SERVER_VARS , $siteurl , $blogfilename , $p , $paged , $what_to_show , $pagenow ;
global $querystring_start , $querystring_equal , $querystring_separator ;
if ( empty ( $p ) && ( $what_to_show == 'paged' )) {
$qstr = $HTTP_SERVER_VARS [ 'QUERY_STRING' ];
if ( ! empty ( $qstr )) {
$qstr = preg_replace ( " /&paged= \ d { 0,}/ " , " " , $qstr );
$qstr = preg_replace ( " /paged= \ d { 0,}/ " , " " , $qstr );
} elseif ( stristr ( $HTTP_SERVER_VARS [ 'REQUEST_URI' ], $HTTP_SERVER_VARS [ 'SCRIPT_NAME' ] )) {
2003-06-08 00:15:39 +00:00
if ( '' != $qstr = str_replace ( $HTTP_SERVER_VARS [ 'SCRIPT_NAME' ], '' ,
2003-04-21 21:37:11 +00:00
$HTTP_SERVER_VARS [ 'REQUEST_URI' ]) ) {
$qstr = preg_replace ( " /^ \ // " , " " , $qstr );
2003-06-08 00:15:39 +00:00
$qstr = preg_replace ( " /paged \ / \ d { 0,} \ // " , " " , $qstr );
2003-04-21 21:37:11 +00:00
$qstr = preg_replace ( " /paged \ / \ d { 0,}/ " , " " , $qstr );
$qstr = preg_replace ( " / \ / $ / " , " " , $qstr );
}
}
$nextpage = intval ( $paged ) - 1 ;
if ( $nextpage < 1 ) $nextpage = 1 ;
echo $pagenow . $querystring_start .
( $qstr == '' ? '' : $qstr . $querystring_separator ) .
'paged' . $querystring_equal . $nextpage ;
}
2003-06-08 00:15:39 +00:00
}
2003-04-21 21:37:11 +00:00
2003-10-27 07:00:42 +00:00
function previous_posts_link ( $label = '« Previous Page' ) {
2003-04-21 21:37:11 +00:00
global $p , $paged , $what_to_show ;
if ( empty ( $p ) && ( $paged > 1 ) && ( $what_to_show == 'paged' )) {
echo '<a href="' ;
echo previous_posts ();
echo '">' . htmlspecialchars ( $label ) . '</a>' ;
}
}
function posts_nav_link ( $sep = ' :: ' , $prelabel = '<< Previous Page' , $nxtlabel = 'Next Page >>' ) {
2003-07-30 23:44:08 +00:00
global $p , $what_to_show , $request , $posts_per_page , $wpdb ;
2003-04-21 21:37:11 +00:00
if ( empty ( $p ) && ( $what_to_show == 'paged' )) {
$nxt_request = $request ;
if ( $pos = strpos ( strtoupper ( $request ), 'LIMIT' )) {
$nxt_request = substr ( $request , 0 , $pos );
}
2003-07-30 23:44:08 +00:00
$nxt_result = $wpdb -> query ( $nxt_request );
$numposts = $wpdb -> num_rows ;
2003-04-21 21:37:11 +00:00
$max_page = ceil ( $numposts / $posts_per_page );
if ( $max_page > 1 ) {
previous_posts_link ( $prelabel );
echo htmlspecialchars ( $sep );
next_posts_link ( $nxtlabel , $max_page );
}
}
}
/***** // Post tags *****/
/***** Category tags *****/
2003-12-04 22:53:15 +00:00
function get_the_category () {
global $post , $tablecategories , $tablepost2cat , $wpdb ;
$categories = $wpdb -> get_results ( "
2003-12-23 20:51:04 +00:00
SELECT category_id , cat_name , category_nicename , category_description
2003-12-04 22:53:15 +00:00
FROM $tablecategories , $tablepost2cat
WHERE $tablepost2cat . category_id = cat_ID AND $tablepost2cat . post_id = $post -> ID
" );
return $categories ;
}
function get_category_link ( $echo = false , $category_id ) {
global $wpdb , $tablecategories , $post , $querystring_start , $querystring_equal , $siteurl , $blogfilename ;
$cat_ID = $category_id ;
$permalink_structure = get_settings ( 'permalink_structure' );
if ( '' == $permalink_structure ) {
$file = " $siteurl / $blogfilename " ;
$link = $file . $querystring_start . 'cat' . $querystring_equal . $cat_ID ;
} else {
$category_nicename = $wpdb -> get_var ( " SELECT category_nicename FROM $tablecategories WHERE cat_ID = $category_id " );
// Get any static stuff from the front
$front = substr ( $permalink_structure , 0 , strpos ( $permalink_structure , '%' ));
2003-12-28 21:45:18 +00:00
$link = $siteurl . $front . 'category/' . $category_nicename ;
2003-12-04 22:53:15 +00:00
}
if ( $echo ) echo $link ;
return $link ;
2003-11-03 22:16:26 +00:00
}
2003-12-04 22:53:15 +00:00
function the_category ( $seperator = '' ) {
$categories = get_the_category ();
if ( '' == $seperator ) {
echo '<ul class="post-categories">' ;
foreach ( $categories as $category ) {
2003-12-05 09:41:27 +00:00
$category -> cat_name = stripslashes ( $category -> cat_name );
2003-12-04 22:53:15 +00:00
echo " \n \t <li><a href=' " . get_category_link ( 0 , $category -> category_id ) . " ' title='View all posts in $category->cat_name '> $category->cat_name </a></li> " ;
}
echo '</ul>' ;
} else {
$i = 0 ;
foreach ( $categories as $category ) {
2003-12-05 09:41:27 +00:00
$category -> cat_name = stripslashes ( $category -> cat_name );
2003-12-04 22:53:15 +00:00
if ( 0 < $i ) echo $seperator . ' ' ;
echo " <a href=' " . get_category_link ( 0 , $category -> category_id ) . " ' title='View all posts in $category->cat_name '> $category->cat_name </a> " ;
++ $i ;
}
}
2003-04-21 21:37:11 +00:00
}
2003-12-04 22:53:15 +00:00
2003-12-22 00:32:05 +00:00
function the_category_rss ( $type = 'rss' ) {
2003-12-18 08:58:07 +00:00
$categories = get_the_category ();
foreach ( $categories as $category ) {
$category -> cat_name = stripslashes ( convert_chars ( $category -> cat_name ));
2003-12-22 00:32:05 +00:00
if ( 'rdf' == $type ) {
echo " \n <dc:subject> $category->cat_name </dc:subject> " ;
} else {
echo " \n <category> $category->cat_name </category> " ;
}
2003-12-18 08:58:07 +00:00
}
2003-04-21 21:37:11 +00:00
}
function the_category_unicode () {
$category = get_the_category ();
$category = apply_filters ( 'the_category_unicode' , $category );
echo convert_chars ( $category , 'unicode' );
}
2003-05-29 15:51:10 +00:00
2003-12-04 22:53:15 +00:00
2003-04-21 21:37:11 +00:00
function get_the_category_by_ID ( $cat_ID ) {
2003-12-05 01:27:00 +00:00
global $tablecategories , $cache_categories , $use_cache , $wpdb ;
2003-04-21 21:37:11 +00:00
if (( ! $cache_categories [ $cat_ID ]) OR ( ! $use_cache )) {
2003-05-29 15:51:10 +00:00
$cat_name = $wpdb -> get_var ( " SELECT cat_name FROM $tablecategories WHERE cat_ID = ' $cat_ID ' " );
2003-08-06 22:40:11 +00:00
$cache_categories [ $cat_ID ] = $cat_name ;
2003-04-21 21:37:11 +00:00
} else {
$cat_name = $cache_categories [ $cat_ID ];
}
return ( stripslashes ( $cat_name ));
}
2003-09-09 22:33:47 +00:00
function the_category_ID ( $echo = true ) {
2003-05-29 15:51:10 +00:00
global $post ;
2003-09-09 22:33:47 +00:00
if ( $echo )
echo $post -> post_category ;
else
return $post -> post_category ;
2003-04-21 21:37:11 +00:00
}
2003-05-29 15:51:10 +00:00
function the_category_head ( $before = '' , $after = '' ) {
global $post , $currentcat , $previouscat , $dateformat , $newday ;
$currentcat = $post -> post_category ;
2003-04-21 21:37:11 +00:00
if ( $currentcat != $previouscat ) {
echo $before ;
echo get_the_category_by_ID ( $currentcat );
echo $after ;
$previouscat = $currentcat ;
}
}
2003-12-23 20:51:04 +00:00
function category_description ( $category = 0 ) {
global $cat , $wpdb , $tablecategories ;
if ( ! $category ) $category = $cat ;
$category_description = $wpdb -> get_var ( " SELECT category_description FROM $tablecategories WHERE cat_ID = $category " );
$category_description = apply_filters ( 'category_description' , $category_description );
return $category_description ;
}
2003-04-21 21:37:11 +00:00
// out of the b2 loop
2003-08-04 21:25:35 +00:00
function dropdown_cats ( $optionall = 1 , $all = 'All' , $sort_column = 'ID' , $sort_order = 'asc' ,
2003-08-04 21:55:10 +00:00
$optiondates = 0 , $optioncount = 0 , $hide_empty = 1 ) {
2003-12-05 01:27:00 +00:00
global $cat , $tablecategories , $tableposts , $wpdb ;
2003-08-04 21:25:35 +00:00
$sort_column = 'cat_' . $sort_column ;
$query = " SELECT cat_ID, cat_name, " ;
$query .= " COUNT( $tableposts .ID) AS cat_count, " ;
$query .= " DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth " ;
$query .= " FROM $tablecategories LEFT JOIN $tableposts ON cat_ID = post_category " ;
$query .= " WHERE cat_ID > 0 " ;
$query .= " GROUP BY post_category " ;
if ( intval ( $hide_empty ) == 1 ) {
$query .= " HAVING cat_count > 0 " ;
}
$query .= " ORDER BY $sort_column $sort_order , post_date DESC " ;
$categories = $wpdb -> get_results ( $query );
2003-05-29 15:51:10 +00:00
echo " <select name='cat' class='postform'> \n " ;
2003-04-21 21:37:11 +00:00
if ( intval ( $optionall ) == 1 ) {
2003-08-04 21:25:35 +00:00
$all = apply_filters ( 'list_cats' , $all );
2003-05-29 15:51:10 +00:00
echo " \t <option value='all'> $all </option> \n " ;
2003-04-21 21:37:11 +00:00
}
2003-10-07 21:48:32 +00:00
if ( $categories ) {
foreach ( $categories as $category ) {
$cat_name = apply_filters ( 'list_cats' , $category -> cat_name );
echo " \t <option value= \" " . $category -> cat_ID . " \" " ;
if ( $category -> cat_ID == $cat )
echo ' selected="selected"' ;
echo '>' . stripslashes ( $cat_name );
if ( intval ( $optioncount ) == 1 ) {
echo ' (' . $category -> cat_count . ')' ;
}
if ( intval ( $optiondates ) == 1 ) {
echo ' ' . $category -> lastday . '/' . $category -> lastmonth ;
}
echo " </option> \n " ;
}
2003-04-21 21:37:11 +00:00
}
echo " </select> \n " ;
}
// out of the b2 loop
2003-07-19 22:55:18 +00:00
function list_cats ( $optionall = 1 , $all = 'All' , $sort_column = 'ID' , $sort_order = 'asc' ,
$file = 'blah' , $list = true , $optiondates = 0 , $optioncount = 0 , $hide_empty = 1 ) {
2003-12-07 09:25:05 +00:00
global $tablecategories , $tableposts , $tablepost2cat , $wpdb ;
2003-11-03 22:16:26 +00:00
global $pagenow , $siteurl , $blogfilename ;
2003-04-21 21:37:11 +00:00
global $querystring_start , $querystring_equal , $querystring_separator ;
2003-07-19 22:55:18 +00:00
if (( $file == 'blah' ) || ( $file == '' )) {
2003-11-03 22:16:26 +00:00
$file = " $siteurl / $blogfilename " ;
2003-07-19 22:55:18 +00:00
}
2003-04-21 21:37:11 +00:00
$sort_column = 'cat_' . $sort_column ;
2003-07-19 22:55:18 +00:00
2003-12-07 09:25:05 +00:00
$query = "
SELECT cat_ID , cat_name ,
COUNT ( $tablepost2cat . post_id ) AS cat_count ,
DAYOFMONTH ( MAX ( post_date )) AS lastday , MONTH ( MAX ( post_date )) AS lastmonth
FROM $tablecategories LEFT JOIN $tablepost2cat ON ( cat_ID = category_id )
LEFT JOIN $tableposts ON ( ID = post_id )
WHERE cat_ID > 0
GROUP BY category_id
" ;
2003-07-19 22:55:18 +00:00
if ( intval ( $hide_empty ) == 1 ) {
$query .= " HAVING cat_count > 0 " ;
}
$query .= " ORDER BY $sort_column $sort_order , post_date DESC " ;
$categories = $wpdb -> get_results ( $query );
2003-10-07 21:48:32 +00:00
if ( ! $categories ) {
if ( $list ) {
$before = '<li>' ;
$after = '</li>' ;
}
echo $before . " No categories " . $after . " \n " ;
return ;
}
2003-04-21 21:37:11 +00:00
if ( intval ( $optionall ) == 1 ) {
$all = apply_filters ( 'list_cats' , $all );
2003-07-19 22:55:18 +00:00
$link = " <a href= \" " . $file . $querystring_start . 'cat' . $querystring_equal . 'all">' . $all . " </a> " ;
if ( $list ) echo " \n \t <li> $link </li> " ;
else echo " \t $link <br /> \n " ;
2003-04-21 21:37:11 +00:00
}
2003-10-07 21:48:32 +00:00
2003-05-29 15:51:10 +00:00
foreach ( $categories as $category ) {
$cat_name = apply_filters ( 'list_cats' , $category -> cat_name );
2003-12-07 09:25:05 +00:00
$link = '<a href="' . get_category_link ( 0 , $category -> cat_ID ) . '" title="View all posts filed under ' . $category -> cat_name . '">' ;
2003-07-24 00:59:07 +00:00
$link .= stripslashes ( $cat_name ) . '</a>' ;
2003-07-19 22:55:18 +00:00
if ( intval ( $optioncount ) == 1 ) {
2003-07-24 00:59:07 +00:00
$link .= ' (' . $category -> cat_count . ')' ;
2003-07-19 22:55:18 +00:00
}
if ( intval ( $optiondates ) == 1 ) {
2003-07-24 00:59:07 +00:00
$link .= ' ' . $category -> lastday . '/' . $category -> lastmonth ;
2003-07-19 22:55:18 +00:00
}
2003-05-06 08:06:57 +00:00
if ( $list ) {
2003-07-24 00:59:07 +00:00
echo " \t <li> $link </li> \n " ;
2003-05-06 08:06:57 +00:00
} else {
2003-07-19 22:55:18 +00:00
echo " \t $link <br /> \n " ;
2003-05-06 08:06:57 +00:00
}
2003-04-21 21:37:11 +00:00
}
}
/***** // Category tags *****/
/***** <Link> tags *****/
/***** // <Link> tags *****/
/***** Comment tags *****/
// generic comments/trackbacks/pingbacks numbering
2003-11-12 15:22:47 +00:00
function comments_number ( $zero = 'No Comments' , $one = '1 Comment' , $more = '% Comments' , $include_unapproved = false ) {
2003-12-05 01:27:00 +00:00
global $id , $comment , $tablecomments , $wpdb ;
2003-11-25 00:46:52 +00:00
$query = " SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = $id " ;
2003-11-12 15:22:47 +00:00
if ( false == $include_unapproved ) {
$query .= " AND comment_approved = '1' " ;
}
$number = $wpdb -> get_var ( $query );
2003-04-21 21:37:11 +00:00
if ( $number == 0 ) {
$blah = $zero ;
} elseif ( $number == 1 ) {
$blah = $one ;
} elseif ( $number > 1 ) {
2003-05-29 14:04:30 +00:00
$blah = str_replace ( '%' , $number , $more );
2003-04-21 21:37:11 +00:00
}
echo $blah ;
}
2003-05-29 14:04:30 +00:00
function comments_link ( $file = '' , $echo = true ) {
global $id , $pagenow ;
2003-04-21 21:37:11 +00:00
global $querystring_start , $querystring_equal , $querystring_separator ;
if ( $file == '' ) $file = $pagenow ;
if ( $file == '/' ) $file = '' ;
2003-10-26 05:28:58 +00:00
if ( ! $echo ) return get_permalink () . '#comments' ;
else echo get_permalink () . '#comments' ;
2003-04-21 21:37:11 +00:00
}
2003-12-11 00:22:36 +00:00
function comments_popup_script ( $width = 400 , $height = 400 , $file = 'wp-comments-popup.php' ) {
2003-12-18 09:36:13 +00:00
global $wpcommentspopupfile , $wptrackbackpopupfile , $wppingbackpopupfile , $wpcommentsjavascript ;
$wpcommentspopupfile = $file ;
$wpcommentsjavascript = 1 ;
2003-12-16 01:58:39 +00:00
$javascript = " <script type='text/javascript'> \n function wpopen (macagna) { \n window.open(macagna, '_blank', 'width= $width ,height= $height ,scrollbars=yes,status=yes'); \n } \n </script> \n " ;
2003-04-21 21:37:11 +00:00
echo $javascript ;
}
2003-06-04 19:36:35 +00:00
function comments_popup_link ( $zero = 'No Comments' , $one = '1 Comment' , $more = '% Comments' , $CSSclass = '' , $none = 'Comments Off' ) {
2003-12-18 09:36:13 +00:00
global $id , $wpcommentspopupfile , $wpcommentsjavascript , $post , $wpdb , $tablecomments , $HTTP_COOKIE_VARS , $cookiehash ;
2003-04-21 21:37:11 +00:00
global $querystring_start , $querystring_equal , $querystring_separator , $siteurl ;
2003-11-12 15:22:47 +00:00
$number = $wpdb -> get_var ( " SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = $id AND comment_approved = '1' " );
2003-12-28 21:45:18 +00:00
if ( 0 == $number && 'closed' == $post -> comment_status && 'closed' == $post -> ping_status ) {
2003-06-04 19:36:35 +00:00
echo $none ;
return ;
2003-04-21 21:37:11 +00:00
} else {
2003-09-20 00:03:21 +00:00
if ( ! empty ( $post -> post_password )) { // if there's a password
2003-10-20 20:53:13 +00:00
if ( $HTTP_COOKIE_VARS [ 'wp-postpass_' . $cookiehash ] != $post -> post_password ) { // and it doesn't match the cookie
2003-09-20 00:03:21 +00:00
echo ( " Enter your password to view comments " );
return ;
}
}
2003-11-04 00:22:15 +00:00
echo '<a href="' ;
2003-12-18 09:36:13 +00:00
if ( $wpcommentsjavascript ) {
echo $wpcommentspopupfile . $querystring_start . 'p' . $querystring_equal . $id . $querystring_separator . 'c' . $querystring_equal . '1' ;
2003-11-04 00:22:15 +00:00
//echo get_permalink();
2003-12-16 01:58:39 +00:00
echo '" onclick="wpopen(this.href); return false"' ;
2003-09-20 00:03:21 +00:00
} else {
// if comments_popup_script() is not in the template, display simple comment link
comments_link ();
echo '"' ;
}
if ( ! empty ( $CSSclass )) {
echo ' class="' . $CSSclass . '"' ;
}
echo '>' ;
comments_number ( $zero , $one , $more );
echo '</a>' ;
}
2003-04-21 21:37:11 +00:00
}
function comment_ID () {
2003-05-29 14:04:30 +00:00
global $comment ;
echo $comment -> comment_ID ;
2003-04-21 21:37:11 +00:00
}
function comment_author () {
2003-05-29 14:04:30 +00:00
global $comment ;
2003-12-24 20:43:04 +00:00
$author = stripslashes ( stripslashes ( $comment -> comment_author ));
$author = apply_filters ( 'comment_auther' , $author );
if ( ! empty ( $author )) {
echo htmlspecialchars ( $comment -> comment_author );
2003-12-09 17:16:28 +00:00
}
else {
echo " Anonymous " ;
}
2003-04-21 21:37:11 +00:00
}
function comment_author_email () {
2003-05-29 14:04:30 +00:00
global $comment ;
2003-12-24 20:43:04 +00:00
$email = stripslashes ( stripslashes ( $comment -> comment_author_email ));
2003-05-29 14:04:30 +00:00
echo antispambot ( stripslashes ( $comment -> comment_author_email ));
2003-04-21 21:37:11 +00:00
}
2003-05-29 14:04:30 +00:00
function comment_author_link () {
global $comment ;
2003-08-06 22:40:11 +00:00
$url = trim ( stripslashes ( $comment -> comment_author_url ));
2003-10-05 21:06:11 +00:00
$email = stripslashes ( $comment -> comment_author_email );
2003-12-09 17:16:28 +00:00
$author = htmlspecialchars ( stripslashes ( $comment -> comment_author ));
if ( empty ( $author )) {
$author = " Anonymous " ;
}
2003-05-29 14:04:30 +00:00
$url = str_replace ( 'http://url' , '' , $url );
2003-12-24 20:43:04 +00:00
$url = preg_replace ( '|[^a-z0-9-_.,/:]|i' , '' , $url );
2003-06-08 10:12:50 +00:00
if ( empty ( $url ) && empty ( $email )) {
echo $author ;
return ;
}
2003-05-29 14:04:30 +00:00
echo '<a href="' ;
if ( $url ) {
$url = str_replace ( ';//' , '://' , $url );
$url = ( ! strstr ( $url , '://' )) ? 'http://' . $url : $url ;
$url = preg_replace ( '/&([^#])(?![a-z]{2,8};)/' , '&$1' , $url );
2003-06-08 10:15:17 +00:00
echo $url ;
2003-05-29 14:04:30 +00:00
} else {
2003-10-05 21:06:11 +00:00
echo 'mailto:' . antispambot ( $email );
2003-05-29 14:04:30 +00:00
}
echo '" rel="external">' . $author . '</a>' ;
}
function comment_type ( $commenttxt = 'Comment' , $trackbacktxt = 'Trackback' , $pingbacktxt = 'Pingback' ) {
global $comment ;
if ( preg_match ( '|<trackback />|' , $comment -> comment_content )) echo $trackbacktxt ;
elseif ( preg_match ( '|<pingback />|' , $comment -> comment_content )) echo $pingbacktxt ;
else echo $commenttxt ;
}
2003-10-27 07:00:42 +00:00
2003-04-21 21:37:11 +00:00
function comment_author_url () {
2003-05-29 14:04:30 +00:00
global $comment ;
$url = trim ( stripslashes ( $comment -> comment_author_url ));
$url = str_replace ( ';//' , '://' , $url );
$url = ( ! strstr ( $url , '://' )) ? 'http://' . $url : $url ;
2003-04-21 21:37:11 +00:00
// convert & into &
2003-05-29 14:04:30 +00:00
$url = preg_replace ( '/&([^#])(?![a-z]{2,8};)/' , '&$1' , $url );
2003-12-24 20:43:04 +00:00
$url = preg_replace ( '|[^a-z0-9-_.,/:]|i' , '' , $url );
2003-04-21 21:37:11 +00:00
if ( $url != 'http://url' ) {
echo $url ;
}
}
function comment_author_email_link ( $linktext = '' , $before = '' , $after = '' ) {
2003-05-29 14:04:30 +00:00
global $comment ;
$email = $comment -> comment_author_email ;
2003-04-21 21:37:11 +00:00
if (( ! empty ( $email )) && ( $email != '@' )) {
$display = ( $linktext != '' ) ? $linktext : antispambot ( stripslashes ( $email ));
echo $before ;
echo '<a href="mailto:' . antispambot ( stripslashes ( $email )) . '">' . $display . '</a>' ;
echo $after ;
}
}
function comment_author_url_link ( $linktext = '' , $before = '' , $after = '' ) {
2003-05-29 14:04:30 +00:00
global $comment ;
$url = trim ( stripslashes ( $comment -> comment_author_url ));
$url = preg_replace ( '/&([^#])(?![a-z]{2,8};)/' , '&$1' , $url );
2003-04-21 21:37:11 +00:00
$url = ( ! stristr ( $url , '://' )) ? 'http://' . $url : $url ;
2003-12-24 20:43:04 +00:00
$url = preg_replace ( '|[^a-z0-9-_.,/:]|i' , '' , $url );
2003-04-21 21:37:11 +00:00
if (( ! empty ( $url )) && ( $url != 'http://' ) && ( $url != 'http://url' )) {
$display = ( $linktext != '' ) ? $linktext : stripslashes ( $url );
echo $before ;
2003-12-24 20:43:04 +00:00
echo '<a href="' . stripslashes ( $url ) . '" rel="external">' . $display . '</a>' ;
2003-04-21 21:37:11 +00:00
echo $after ;
}
}
function comment_author_IP () {
2003-05-29 14:04:30 +00:00
global $comment ;
echo stripslashes ( $comment -> comment_author_IP );
2003-04-21 21:37:11 +00:00
}
function comment_text () {
2003-05-29 14:04:30 +00:00
global $comment ;
$comment_text = stripslashes ( $comment -> comment_content );
$comment_text = str_replace ( '<trackback />' , '' , $comment_text );
$comment_text = str_replace ( '<pingback />' , '' , $comment_text );
$comment_text = convert_chars ( $comment_text );
$comment_text = convert_bbcode ( $comment_text );
$comment_text = convert_gmcode ( $comment_text );
$comment_text = make_clickable ( $comment_text );
2003-06-26 23:23:37 +00:00
$comment_text = balanceTags ( $comment_text , 1 );
2003-05-29 14:04:30 +00:00
$comment_text = apply_filters ( 'comment_text' , $comment_text );
2003-12-30 08:34:57 +00:00
$comment_text = convert_smilies ( $comment_text );
2003-05-29 14:04:30 +00:00
echo $comment_text ;
2003-04-21 21:37:11 +00:00
}
function comment_date ( $d = '' ) {
2003-05-29 14:04:30 +00:00
global $comment , $dateformat ;
2003-04-21 21:37:11 +00:00
if ( $d == '' ) {
2003-05-29 14:04:30 +00:00
echo mysql2date ( $dateformat , $comment -> comment_date );
2003-04-21 21:37:11 +00:00
} else {
2003-05-29 14:04:30 +00:00
echo mysql2date ( $d , $comment -> comment_date );
2003-04-21 21:37:11 +00:00
}
}
function comment_time ( $d = '' ) {
2003-05-29 14:04:30 +00:00
global $comment , $timeformat ;
2003-04-21 21:37:11 +00:00
if ( $d == '' ) {
2003-05-29 14:04:30 +00:00
echo mysql2date ( $timeformat , $comment -> comment_date );
2003-04-21 21:37:11 +00:00
} else {
2003-05-29 14:04:30 +00:00
echo mysql2date ( $d , $comment -> comment_date );
2003-04-21 21:37:11 +00:00
}
}
2003-09-28 18:23:52 +00:00
function comments_rss_link ( $link_text = 'Comments RSS' , $commentsrssfilename = 'wp-commentsrss2.php' ) {
global $id ;
global $querystring_start , $querystring_equal , $querystring_separator ;
$url = $commentsrssfilename . $querystring_start . 'p' . $querystring_equal . $id ;
$url = '<a href="' . $url . '">' . $link_text . '</a>' ;
echo $url ;
}
function comment_author_rss () {
global $comment ;
2003-12-09 17:16:28 +00:00
if ( ! empty ( $comment -> comment_author )) {
echo htmlspecialchars ( strip_tags ( stripslashes ( $comment -> comment_author )));
}
else {
echo " Anonymous " ;
}
2003-09-28 18:23:52 +00:00
}
function comment_text_rss () {
global $comment ;
$comment_text = stripslashes ( $comment -> comment_content );
$comment_text = str_replace ( '<trackback />' , '' , $comment_text );
$comment_text = str_replace ( '<pingback />' , '' , $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 = apply_filters ( 'comment_text' , $comment_text );
$comment_text = strip_tags ( $comment_text );
$comment_text = htmlspecialchars ( $comment_text );
echo $comment_text ;
}
function comment_link_rss () {
2003-12-24 20:43:04 +00:00
global $comment ;
2003-11-04 00:22:15 +00:00
echo get_permalink ( $comment -> comment_post_ID ) . '#comments' ;
2003-09-28 18:23:52 +00:00
}
function permalink_comments_rss () {
2003-12-24 20:43:04 +00:00
global $comment ;
2003-11-04 00:22:15 +00:00
echo get_permalink ( $comment -> comment_post_ID );
2003-09-28 18:23:52 +00:00
}
2003-04-21 21:37:11 +00:00
/***** // Comment tags *****/
/***** TrackBack tags *****/
2003-05-29 14:04:30 +00:00
function trackback_url ( $display = true ) {
2003-05-24 21:50:22 +00:00
global $siteurl , $id ;
2003-12-11 00:22:36 +00:00
$tb_url = $siteurl . '/wp-trackback.php/' . $id ;
2003-04-21 21:37:11 +00:00
if ( $display ) {
echo $tb_url ;
} else {
return $tb_url ;
}
}
2003-05-29 15:51:10 +00:00
function trackback_rdf ( $timezone = 0 ) {
2003-05-24 21:50:22 +00:00
global $siteurl , $id , $HTTP_SERVER_VARS ;
2003-04-21 21:37:11 +00:00
if ( ! stristr ( $HTTP_SERVER_VARS [ 'HTTP_USER_AGENT' ], 'W3C_Validator' )) {
echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" ' . " \n " ;
echo ' xmlns:dc="http://purl.org/dc/elements/1.1/"' . " \n " ;
echo ' xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">' . " \n " ;
echo '<rdf:Description' . " \n " ;
echo ' rdf:about="' ;
permalink_single ();
echo '"' . " \n " ;
echo ' dc:identifier="' ;
permalink_single ();
echo '"' . " \n " ;
2003-09-09 22:33:47 +00:00
echo ' dc:title="' . str_replace ( '--' , '--' , addslashes ( strip_tags ( get_the_title ()))) . '"' . " \n " ;
2003-04-21 21:37:11 +00:00
echo ' trackback:ping="' . trackback_url ( 0 ) . '"' . " /> \n " ;
echo '</rdf:RDF>' ;
}
}
/***** // TrackBack tags *****/
/***** Permalink tags *****/
function permalink_anchor ( $mode = 'id' ) {
2003-05-29 15:51:10 +00:00
global $id , $post ;
2003-04-21 21:37:11 +00:00
switch ( strtolower ( $mode )) {
case 'title' :
2003-10-27 07:00:42 +00:00
$title = sanitize_title ( $post -> post_title ) . '-' . $id ;
echo '<a id="' . $title . '"></a>' ;
2003-04-21 21:37:11 +00:00
break ;
case 'id' :
default :
2003-10-27 07:00:42 +00:00
echo '<a id="post-' . $id . '"></a>' ;
2003-04-21 21:37:11 +00:00
break ;
}
}
function permalink_link ( $file = '' , $mode = 'id' ) {
2003-10-27 07:00:42 +00:00
global $post , $pagenow , $cacheweekly , $wpdb ;
2003-04-21 21:37:11 +00:00
$file = ( $file == '' ) ? $pagenow : $file ;
switch ( strtolower ( $mode )) {
case 'title' :
2003-10-27 07:00:42 +00:00
$title = sanitize_title ( $post -> post_title ) . '-' . $post -> ID ;
2003-04-21 21:37:11 +00:00
$anchor = $title ;
break ;
case 'id' :
default :
$anchor = $id ;
break ;
}
2003-10-26 05:25:26 +00:00
echo get_permalink ();
2003-04-21 21:37:11 +00:00
}
2003-10-27 07:00:42 +00:00
function permalink_single ( $file = '' ) {
echo get_permalink ();
2003-04-21 21:37:11 +00:00
}
2003-10-27 07:00:42 +00:00
function permalink_single_rss ( $file = '' ) {
global $siteurl ;
2003-11-04 00:22:15 +00:00
echo get_permalink ();
2003-04-21 21:37:11 +00:00
}
/***** // Permalink tags *****/
2003-12-07 20:48:06 +00:00
?>