File:  [mozdev] / cdn / www / b2-include / b2template.functions.php
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Thu Mar 6 11:26:20 2003 UTC (16 years, 4 months ago) by cdn
Branches: MAIN
CVS tags: HEAD
o

    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 = '&amp;';
    9: }
   10: 
   11: 
   12: 
   13: /* template functions... */
   14: 
   15: 
   16: // @@@ These are template tags, you can edit them if you know what you're doing...
   17: 
   18: 
   19: 
   20: /***** About-the-blog tags *****/
   21: /* Note: these tags go anywhere in the template */
   22: 
   23: function bloginfo($show='') {
   24: 	$info = get_bloginfo($show);
   25: 	$info = convert_bbcode($info);
   26: 	$info = convert_gmcode($info);
   27: 	$info = convert_smilies($info);
   28: 	$info = apply_filters('bloginfo', $info);
   29: 	echo convert_chars($info, 'html');
   30: }
   31: 
   32: function bloginfo_rss($show='') {
   33: 	$info = strip_tags(get_bloginfo($show));
   34: 	echo convert_chars($info, 'unicode');
   35: }
   36: 
   37: function bloginfo_unicode($show='') {
   38: 	$info = get_bloginfo($show);
   39: 	echo convert_chars($info, 'unicode');
   40: }
   41: 
   42: function get_bloginfo($show='') {
   43: 	global $siteurl, $blogfilename, $blogname, $blogdescription, $pathserver, $admin_email;
   44: 	switch($show) {
   45: 		case "url":
   46: 			$output = $siteurl."/".$blogfilename;
   47: 			break;
   48: 		case "description":
   49: 			$output = $blogdescription;
   50: 			break;
   51: 		case "rdf_url":
   52: 			$output = $siteurl.'/b2rdf.php';
   53: 			break;
   54: 		case "rss_url":
   55: 			$output = $siteurl.'/b2rss.php';
   56: 			break;
   57: 		case "rss2_url":
   58: 			$output = $siteurl.'/b2rss2.php';
   59: 			break;
   60: 		case "pingback_url":
   61: 			$output = $pathserver.'/xmlrpc.php';
   62: 			break;
   63: 		case "admin_email":
   64: 			$output = $admin_email;
   65: 			break;
   66: 		case "name":
   67: 		default:
   68: 			$output = $blogname;
   69: 			break;
   70: 	}
   71: 	return($output);
   72: }
   73: 
   74: function single_post_title($prefix = '', $display = 1) {
   75: 	global $p;
   76: 	if (intval($p)) {
   77: 		$post_data = get_postdata($p);
   78: 		$title = $post_data['Title'];
   79: 		$title = apply_filters('single_post_title', $title);
   80: 		if ($display) {
   81: 			echo $prefix.strip_tags(stripslashes($title));
   82: 		} else {
   83: 			return strip_tags(stripslashes($title));
   84: 		}
   85: 	}
   86: }
   87: 
   88: function single_cat_title($prefix = '', $display = 1 ) {
   89: 	global $cat;
   90: 	if(!empty($cat) && !(strtoupper($cat) == 'ALL')) {
   91: 		$my_cat_name = get_the_category_by_ID($cat);
   92: 		if(!empty($my_cat_name)) {
   93: 			if ($display)
   94: 				echo $prefix.strip_tags(stripslashes($my_cat_name));
   95: 			else
   96: 				return strip_tags(stripslashes($my_cat_name));
   97: 		}
   98: 	}
   99: }
  100: 
  101: function single_month_title($prefix = '', $display = 1 ) {
  102: 	global $m, $month;
  103: 	if(!empty($m)) {
  104: 		$my_year = substr($m,0,4);
  105: 		$my_month = $month[substr($m,4,2)];
  106: 		if ($display)
  107: 			echo $prefix.$my_month.$prefix.$my_year;
  108: 		else
  109: 			return $m;
  110: 	}
  111: }
  112: 
  113: /***** // About-the-blog tags *****/
  114: 
  115: 
  116: 
  117: 
  118: /***** Date/Time tags *****/
  119: 
  120: function the_date($d='', $before='', $after='', $echo = 1) {
  121: 	global $id, $postdata, $day, $previousday,$dateformat,$newday;
  122: 	$the_date = '';
  123: 	if ($day != $previousday) {
  124: 		$the_date .= $before;
  125: 		if ($d=='') {
  126: 			$the_date .= mysql2date($dateformat, $postdata['Date']);
  127: 		} else {
  128: 			$the_date .= mysql2date($d, $postdata['Date']);
  129: 		}
  130: 		$the_date .= $after;
  131: 		$previousday = $day;
  132: 	}
  133: 	$the_date = apply_filters('the_date', $the_date);
  134: 	if ($echo) {
  135: 		echo $the_date;
  136: 	} else {
  137: 		return $the_date;
  138: 	}
  139: }
  140: 
  141: function the_time($d='', $echo = 1) {
  142: 	global $id,$postdata,$timeformat;
  143: 	if ($d=='') {
  144: 		$the_time = mysql2date($timeformat, $postdata['Date']);
  145: 	} else {
  146: 		$the_time = mysql2date($d, $postdata['Date']);
  147: 	}
  148: 	$the_time = apply_filters('the_time', $the_time);
  149: 	if ($echo) {
  150: 		echo $the_time;
  151: 	} else {
  152: 		return $the_time;
  153: 	}
  154: }
  155: 
  156: function the_weekday() {
  157: 	global $weekday,$id,$postdata;
  158: 	$the_weekday = $weekday[mysql2date('w', $postdata['Date'])];
  159: 	$the_weekday = apply_filters('the_weekday', $the_weekday);
  160: 	echo $the_weekday;
  161: }
  162: 
  163: function the_weekday_date($before='',$after='') {
  164: 	global $weekday,$id,$postdata,$day,$previousweekday;
  165: 	$the_weekday_date = '';
  166: 	if ($day != $previousweekday) {
  167: 		$the_weekday_date .= $before;
  168: 		$the_weekday_date .= $weekday[mysql2date('w', $postdata['Date'])];
  169: 		$the_weekday_date .= $after;
  170: 		$previousweekday = $day;
  171: 	}
  172: 	$the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date);
  173: 	echo $the_weekday_date;
  174: }
  175: 
  176: /***** // Date/Time tags *****/
  177: 
  178: 
  179: 
  180: 
  181: /***** Author tags *****/
  182: 
  183: function the_author() {
  184: 	global $id,$authordata;
  185: 	$i = $authordata['user_idmode'];
  186: 	if ($i == 'nickname')	echo $authordata['user_nickname'];
  187: 	if ($i == 'login')	echo $authordata['user_login'];
  188: 	if ($i == 'firstname')	echo $authordata['user_firstname'];
  189: 	if ($i == 'lastname')	echo $authordata['user_lastname'];
  190: 	if ($i == 'namefl')	echo $authordata['user_firstname'].' '.$authordata['user_lastname'];
  191: 	if ($i == 'namelf')	echo $authordata['user_lastname'].' '.$authordata['user_firstname'];
  192: 	if (!$i) echo $authordata['user_nickname'];
  193: }
  194: 
  195: function the_author_login() {
  196: 	global $id,$authordata;	echo $authordata['user_login'];
  197: }
  198: 
  199: function the_author_firstname() {
  200: 	global $id,$authordata;	echo $authordata['user_firstname'];
  201: }
  202: 
  203: function the_author_lastname() {
  204: 	global $id,$authordata;	echo $authordata['user_lastname'];
  205: }
  206: 
  207: function the_author_nickname() {
  208: 	global $id,$authordata;	echo $authordata['user_nickname'];
  209: }
  210: 
  211: function the_author_ID() {
  212: 	global $id,$authordata;	echo $authordata['ID'];
  213: }
  214: 
  215: function the_author_email() {
  216: 	global $id,$authordata;	echo antispambot($authordata['user_email']);
  217: }
  218: 
  219: function the_author_url() {
  220: 	global $id,$authordata;	echo $authordata['user_url'];
  221: }
  222: 
  223: function the_author_icq() {
  224: 	global $id,$authordata;	echo $authordata['user_icq'];
  225: }
  226: 
  227: function the_author_aim() {
  228: 	global $id,$authordata;	echo str_replace(' ', '+', $authordata['user_aim']);
  229: }
  230: 
  231: function the_author_yim() {
  232: 	global $id,$authordata;	echo $authordata['user_yim'];
  233: }
  234: 
  235: function the_author_msn() {
  236: 	global $id,$authordata;	echo $authordata['user_msn'];
  237: }
  238: 
  239: function the_author_posts() {
  240: 	global $id,$postdata;	$posts=get_usernumposts($postdata['Author_ID']);	echo $posts;
  241: }
  242: 
  243: /***** // Author tags *****/
  244: 
  245: 
  246: 
  247: 
  248: /***** Post tags *****/
  249: 
  250: function the_ID() {
  251: 	global $id;
  252: 	echo $id;
  253: }
  254: 
  255: function the_title($before='',$after='') {
  256: 	$title = get_the_title();
  257: 	$title = convert_bbcode($title);
  258: 	$title = convert_gmcode($title);
  259: 	$title = convert_smilies($title);
  260: 	$title = apply_filters('the_title', $title);
  261: 	if ($title) {
  262: 		echo convert_chars($before.$title.$after, 'html');
  263: 	}
  264: }
  265: function the_title_rss() {
  266: 	$title = get_the_title();
  267: 	$title = convert_bbcode($title);
  268: 	$title = convert_gmcode($title);
  269: 	$title = strip_tags($title);
  270: 	if (trim($title)) {
  271: 		echo convert_chars($title, 'unicode');
  272: 	}
  273: }
  274: function the_title_unicode($before='',$after='') {
  275: 	$title = get_the_title();
  276: 	$title = convert_bbcode($title);
  277: 	$title = convert_gmcode($title);
  278: 	$title = apply_filters('the_title_unicode', $title);
  279: 	if (trim($title)) {
  280: 		echo convert_chars($before.$title.$after, 'unicode');
  281: 	}
  282: }
  283: function get_the_title() {
  284: 	global $id,$postdata;
  285: 	$output = stripslashes($postdata['Title']);
  286: 	$output = apply_filters('the_title', $output);
  287: 	return($output);
  288: }
  289: 
  290: function the_content($more_link_text='(more...)', $stripteaser=0, $more_file='') {
  291: 	$content = get_the_content($more_link_text,$stripteaser,$more_file);
  292: 	$content = convert_bbcode($content);
  293: 	$content = convert_gmcode($content);
  294: 	$content = convert_smilies($content);
  295: 	$content = convert_chars($content, 'html');
  296: 	$content = apply_filters('the_content', $content);
  297: 	echo $content;
  298: }
  299: function the_content_rss($more_link_text='(more...)', $stripteaser=0, $more_file='', $cut = 0, $encode_html = 0) {
  300: 	$content = get_the_content($more_link_text,$stripteaser,$more_file);
  301: 	$content = convert_bbcode($content);
  302: 	$content = convert_gmcode($content);
  303: 	$content = convert_chars($content, 'unicode');
  304: 	if ($cut && !$encode_html) {
  305: 		$encode_html = 2;
  306: 	}
  307: 	if ($encode_html == 1) {
  308: 		$content = htmlspecialchars($content);
  309: 		$cut = 0;
  310: 	} elseif ($encode_html == 0) {
  311: 		$content = make_url_footnote($content);
  312: 	} elseif ($encode_html == 2) {
  313: 		$content = strip_tags($content);
  314: 	}
  315: 	if ($cut) {
  316: 		$blah = explode(' ', $content);
  317: 		if (count($blah) > $cut) {
  318: 			$k = $cut;
  319: 			$use_dotdotdot = 1;
  320: 		} else {
  321: 			$k = count($blah);
  322: 			$use_dotdotdot = 0;
  323: 		}
  324: 		for ($i=0; $i<$k; $i++) {
  325: 			$excerpt .= $blah[$i].' ';
  326: 		}
  327: 		$excerpt .= ($use_dotdotdot) ? '...' : '';
  328: 		$content = $excerpt;
  329: 	}
  330: 	echo $content;
  331: }
  332: function the_content_unicode($more_link_text='(more...)', $stripteaser=0, $more_file='') {
  333: 	$content = get_the_content($more_link_text,$stripteaser,$more_file);
  334: 	$content = convert_bbcode($content);
  335: 	$content = convert_gmcode($content);
  336: 	$content = convert_smilies($content);
  337: 	$content = convert_chars($content, 'unicode');
  338: 	$content = apply_filters('the_content_unicode', $content);
  339: 	echo $content;
  340: }
  341: function get_the_content($more_link_text='(more...)', $stripteaser=0, $more_file='') {
  342: 	global $id,$postdata,$more,$c,$withcomments,$b2page,$pages,$multipage,$numpages;
  343: 	global $HTTP_SERVER_VARS, $preview;
  344: 	global $querystring_start, $querystring_equal, $querystring_separator;
  345: 	$output = '';
  346: 	if ($more_file != '') {
  347: 		$file=$more_file;
  348: 	} else {
  349: 		$file=PAGE; //$HTTP_SERVER_VARS['PHP_SELF'];
  350: 	}
  351: 	$content=$pages[$b2page-1];
  352: 	$content=explode('<!--more-->', $content);
  353: 	if ((preg_match('/<!--noteaser-->/', $postdata['Content']) && ((!$multipage) || ($b2page==1))))
  354: 		$stripteaser=1;
  355: 	$teaser=$content[0];
  356: 	if (($more) && ($stripteaser))
  357: 		$teaser='';
  358: 	$output .= $teaser;
  359: 	if (count($content)>1) {
  360: 		if ($more) {
  361: 			$output .= '<a name="more'.$id.'"></a>'.$content[1];
  362: 		} else {
  363: 			$output .= ' <a href="'.$file.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'more'.$querystring_equal.'1#more'.$id.'">'.$more_link_text.'</a>';
  364: 		}
  365: 	}
  366: 	if ($preview) { // preview fix for javascript bug with foreign languages
  367: 		$output =  preg_replace('/\%u([0-9A-F]{4,4})/e',  "'&#'.base_convert('\\1',16,10).';'", $output);
  368: 	}
  369: 	return($output);
  370: }
  371: 
  372: function link_pages($before='<br />', $after='<br />', $next_or_number='number', $nextpagelink='next page', $previouspagelink='previous page', $pagelink='%', $more_file='') {
  373: 	global $id,$b2page,$numpages,$multipage,$more;
  374: 	global $blogfilename;
  375: 	global $querystring_start, $querystring_equal, $querystring_separator;
  376: 	if ($more_file != '') {
  377: 		$file = $more_file;
  378: 	} else {
  379: 		$file = $blogfilename;
  380: 	}
  381: 	if (($multipage)) { // && ($more)) {
  382: 		echo $before;
  383: 		if ($next_or_number=='number') {
  384: 			for ($i = 1; $i < ($numpages+1); $i = $i + 1) {
  385: 				$j=str_replace('%',"$i",$pagelink);
  386: 				echo " ";
  387: 				if (($i != $b2page) || ((!$more) && ($b2page==1)))
  388: 					echo '<a href="'.$file.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'more'.$querystring_equal.'1'.$querystring_separator.'page'.$querystring_equal.$i.'">';
  389: 				echo $j;
  390: 				if (($i != $b2page) || ((!$more) && ($b2page==1)))
  391: 					echo '</a>';
  392: 			}
  393: 		} else {
  394: 			$i=$b2page-1;
  395: 			if ($i)
  396: 				echo ' <a href="'.$file.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'page'.$querystring_equal.$i.'">'.$previouspagelink.'</a>';
  397: 			$i=$b2page+1;
  398: 			if ($i<=$numpages)
  399: 				echo ' <a href="'.$file.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'page'.$querystring_equal.$i.'">'.$nextpagelink.'</a>';
  400: 		}
  401: 		echo $after;
  402: 	}
  403: }
  404: 
  405: 
  406: function previous_post($format='%', $previous='previous post: ', $title='yes', $in_same_cat='no', $limitprev=1, $excluded_categories='') {
  407: 	global $tableposts, $id, $postdata, $siteurl, $blogfilename, $querycount;
  408: 	global $p, $posts, $posts_per_page, $s;
  409: 	global $querystring_start, $querystring_equal, $querystring_separator;
  410: 
  411: 	if(($p) || ($posts_per_page==1)) {
  412: 		
  413: 		$current_post_date = $postdata['Date'];
  414: 		$current_category = $postdata['Category'];
  415: 
  416: 		$sqlcat = '';
  417: 		if ($in_same_cat != 'no') {
  418: 			$sqlcat = " AND post_category='$current_category' ";
  419: 		}
  420: 
  421: 		$sql_exclude_cats = '';
  422: 		if (!empty($excluded_categories)) {
  423: 			$blah = explode('and', $excluded_categories);
  424: 			foreach($blah as $category) {
  425: 				$category = intval($category);
  426: 				$sql_exclude_cats .= " AND post_category != $category";
  427: 			}
  428: 		}
  429: 
  430: 		$limitprev--;
  431: 		$sql = "SELECT ID,post_title FROM $tableposts WHERE post_date < '$current_post_date' AND post_category > 0 $sqlcat $sql_exclude_cats ORDER BY post_date DESC LIMIT $limitprev,1";
  432: 
  433: 		$query = @mysql_query($sql);
  434: 		$querycount++;
  435: 		if (($query) && (mysql_num_rows($query))) {
  436: 			$p_info = mysql_fetch_object($query);
  437: 			$p_title = $p_info->post_title;
  438: 			$p_id = $p_info->ID;
  439: 			$string = '<a href="'.$blogfilename.$querystring_start.'p'.$querystring_equal.$p_id.$querystring_separator.'more'.$querystring_equal.'1'.$querystring_separator.'c'.$querystring_equal.'1">'.$previous;
  440: 			if (!($title!='yes')) {
  441: 				$string .= stripslashes($p_title);
  442: 			}
  443: 			$string .= '</a>';
  444: 			$format = str_replace('%',$string,$format);
  445: 			echo $format;
  446: 		}
  447: 	}
  448: }
  449: 
  450: function next_post($format='%', $next='next post: ', $title='yes', $in_same_cat='no', $limitnext=1, $excluded_categories='') {
  451: 	global $tableposts, $p, $posts, $id, $postdata, $siteurl, $blogfilename, $querycount;
  452: 	global $time_difference;
  453: 	global $querystring_start, $querystring_equal, $querystring_separator;
  454: 	if(($p) || ($posts==1)) {
  455: 		
  456: 		$current_post_date = $postdata['Date'];
  457: 		$current_category = $postdata['Category'];
  458: 
  459: 		$sqlcat = '';
  460: 		if ($in_same_cat != 'no') {
  461: 			$sqlcat = " AND post_category='$current_category' ";
  462: 		}
  463: 
  464: 		$sql_exclude_cats = '';
  465: 		if (!empty($excluded_categories)) {
  466: 			$blah = explode('and', $excluded_categories);
  467: 			foreach($blah as $category) {
  468: 				$category = intval($category);
  469: 				$sql_exclude_cats .= " AND post_category != $category";
  470: 			}
  471: 		}
  472: 
  473: 		$now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600)));
  474: 
  475: 		$limitnext--;
  476: 		$sql = "SELECT ID,post_title FROM $tableposts WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_category > 0 $sqlcat $sql_exclude_cats ORDER BY post_date ASC LIMIT $limitnext,1";
  477: 
  478: 		$query = @mysql_query($sql);
  479: 		$querycount++;
  480: 		if (($query) && (mysql_num_rows($query))) {
  481: 			$p_info = mysql_fetch_object($query);
  482: 			$p_title = $p_info->post_title;
  483: 			$p_id = $p_info->ID;
  484: 			$string = '<a href="'.$blogfilename.$querystring_start.'p'.$querystring_equal.$p_id.$querystring_separator.'more'.$querystring_equal.'1'.$querystring_separator.'c'.$querystring_equal.'1">'.$next;
  485: 			if ($title=='yes') {
  486: 				$string .= stripslashes($p_title);
  487: 			}
  488: 			$string .= '</a>';
  489: 			$format = str_replace('%',$string,$format);
  490: 			echo $format;
  491: 		}
  492: 	}
  493: }
  494: 
  495: 
  496: 
  497: 
  498: 
  499: function next_posts($max_page = 0) { // original by cfactor at cooltux.org
  500: 	global $HTTP_SERVER_VARS, $siteurl, $blogfilename, $p, $paged, $what_to_show;
  501: 	global $querystring_start, $querystring_equal, $querystring_separator;
  502: 	if (empty($p) && ($what_to_show == 'paged')) {
  503: 		$qstr = $HTTP_SERVER_VARS['QUERY_STRING'];
  504: 		if (!empty($qstr)) {
  505: 			$qstr = preg_replace("/&paged=\d{0,}/","",$qstr);
  506: 			$qstr = preg_replace("/paged=\d{0,}/","",$qstr);
  507: 		} elseif ('' != $qstr = str_replace($HTTP_SERVER_VARS['SCRIPT_NAME'], '', 
  508: 											$HTTP_SERVER_VARS['REQUEST_URI']) ) {
  509: 			$qstr = preg_replace("/^\//", "", $qstr);
  510: 			$qstr = preg_replace("/paged\/\d{0,}\//", "", $qstr);		
  511: 			$qstr = preg_replace("/paged\/\d{0,}/", "", $qstr);
  512: 			$qstr = preg_replace("/\/$/", "", $qstr);
  513: 		}
  514: 		if (!$paged) $paged = 1;
  515: 		$nextpage = intval($paged) + 1;
  516: 		if (!$max_page || $max_page >= $nextpage) {
  517: 			echo  $siteurl.'/'.$blogfilename.$querystring_start.
  518: 				($qstr == '' ? '' : $qstr.$querystring_separator) .
  519: 				'paged'.$querystring_equal.$nextpage;
  520: 		}
  521: 	}
  522: }
  523: 
  524: function next_posts_link($label='Next Page >>', $max_page=0) {
  525: 	global $p, $paged, $result, $request, $posts_per_page, $what_to_show;
  526: 	if ($what_to_show == 'paged') {
  527: 		if (!$max_page) {
  528: 			$nxt_request = $request;
  529: 			if ($pos = strpos(strtoupper($request), 'LIMIT')) {
  530: 				$nxt_request = substr($request, 0, $pos);
  531: 			}
  532: 			$nxt_result = mysql_query($nxt_request);
  533: 			$numposts = mysql_num_rows($nxt_result);
  534: 			$max_page = intval($numposts / $posts_per_page) +1;
  535: 		}
  536: 		if (!$paged) $paged = 1;
  537: 		$nextpage = intval($paged) + 1;
  538: 		if (empty($p) && (empty($paged) || $nextpage <= $max_page)) {
  539: 			echo '<a href="';
  540: 			echo next_posts($max_page);
  541: 			echo '">'. htmlspecialchars($label) .'</a>';
  542: 		}
  543: 	}
  544: }
  545: 
  546: 
  547: function previous_posts() { // original by cfactor at cooltux.org
  548: 	global $HTTP_SERVER_VARS, $siteurl, $blogfilename, $p, $paged, $what_to_show;
  549: 	global $querystring_start, $querystring_equal, $querystring_separator;
  550: 	if (empty($p) && ($what_to_show == 'paged')) {
  551: 		$qstr = $HTTP_SERVER_VARS['QUERY_STRING'];
  552: 		if (!empty($qstr)) {
  553: 			$qstr = preg_replace("/&paged=\d{0,}/","",$qstr);
  554: 			$qstr = preg_replace("/paged=\d{0,}/","",$qstr);
  555: 		} elseif ('' != $qstr = str_replace($HTTP_SERVER_VARS['SCRIPT_NAME'], '', 
  556: 											$HTTP_SERVER_VARS['REQUEST_URI']) ) {
  557: 			$qstr = preg_replace("/^\//", "", $qstr);
  558: 			$qstr = preg_replace("/paged\/\d{0,}\//", "", $qstr);		
  559: 			$qstr = preg_replace("/paged\/\d{0,}/", "", $qstr);
  560: 			$qstr = preg_replace("/\/$/", "", $qstr);
  561: 		}
  562: 		$nextpage = intval($paged) - 1;
  563: 		if ($nextpage < 1) $nextpage = 1;
  564: 		echo $siteurl.'/'.$blogfilename.$querystring_start.
  565: 			($qstr == '' ? '' : $qstr.$querystring_separator) .
  566: 			'paged'.$querystring_equal.$nextpage;
  567: 	}
  568: } 
  569: 
  570: function previous_posts_link($label='<< Previous Page') {
  571: 	global $p, $paged, $what_to_show;
  572: 	if (empty($p)  && ($paged > 1) && ($what_to_show == 'paged')) {
  573: 		echo '<a href="';
  574: 		echo previous_posts();
  575: 		echo '">'.  htmlspecialchars($label) .'</a>';
  576: 	}
  577: }
  578: 
  579: function posts_nav_link($sep=' :: ', $prelabel='<< Previous Page', $nxtlabel='Next Page >>') {
  580: 	global $p, $what_to_show, $request, $posts_per_page;
  581: 	if (empty($p) && ($what_to_show == 'paged')) {
  582: 		$nxt_request = $request;
  583: 		if ($pos = strpos(strtoupper($request), 'LIMIT')) {
  584: 			$nxt_request = substr($request, 0, $pos);
  585: 		}
  586: 		$nxt_result = mysql_query($nxt_request);
  587: 		$numposts = mysql_num_rows($nxt_result);
  588: 		$max_page = intval($numposts / $posts_per_page) +1;
  589: 		if ($max_page > 1) {
  590: 			previous_posts_link($prelabel);
  591: 			echo htmlspecialchars($sep);
  592: 			next_posts_link($nxtlabel, $max_page);
  593: 		}
  594: 	}
  595: }
  596: 
  597: /***** // Post tags *****/
  598: 
  599: 
  600: 
  601: 
  602: /***** Category tags *****/
  603: 
  604: function the_category() {
  605: 	$category = get_the_category();
  606: 	$category = apply_filters('the_category', $category);
  607: 	echo convert_chars($category, 'html');
  608: }
  609: function the_category_rss() {
  610: 	echo convert_chars(strip_tags(get_the_category()), 'xml');
  611: }
  612: function the_category_unicode() {
  613: 	$category = get_the_category();
  614: 	$category = apply_filters('the_category_unicode', $category);
  615: 	echo convert_chars($category, 'unicode');
  616: }
  617: function get_the_category() {
  618: 	global $id,$postdata,$tablecategories,$querycount,$cache_categories,$use_cache;
  619: 	$cat_ID = $postdata['Category'];
  620: 	if ((empty($cache_categories[$cat_ID])) OR (!$use_cache)) {
  621: 		$query="SELECT cat_name FROM $tablecategories WHERE cat_ID = '$cat_ID'";
  622: 		$result=mysql_query($query);
  623: 		$querycount++;
  624: 		$myrow = mysql_fetch_array($result);
  625: 		$cat_name = $myrow[0];
  626: 		$cache_categories[$cat_ID] = $cat_name;
  627: 	} else {
  628: 		$cat_name = $cache_categories[$cat_ID];
  629: 	}
  630: 	return(stripslashes($cat_name));
  631: }
  632: 
  633: function get_the_category_by_ID($cat_ID) {
  634: 	global $id,$tablecategories,$querycount,$cache_categories,$use_cache;
  635: 	if ((!$cache_categories[$cat_ID]) OR (!$use_cache)) {
  636: 		$query="SELECT cat_name FROM $tablecategories WHERE cat_ID = '$cat_ID'";
  637: 		$result=mysql_query($query);
  638: 		$querycount++;
  639: 		$myrow = mysql_fetch_array($result);
  640: 		$cat_name = $myrow[0];
  641: 		$cache_categories[$cat_ID] = $cat_name;
  642: 	} else {
  643: 		$cat_name = $cache_categories[$cat_ID];
  644: 	}
  645: 	return(stripslashes($cat_name));
  646: }
  647: 
  648: function the_category_ID() {
  649: 	global $id,$postdata;	echo $postdata['Category'];
  650: }
  651: 
  652: function the_category_head($before='',$after='') {
  653: 	global $id, $postdata, $currentcat, $previouscat,$dateformat,$newday;
  654: 	$currentcat = $postdata['Category'];
  655: 	if ($currentcat != $previouscat) {
  656: 		echo $before;
  657: 		echo get_the_category_by_ID($currentcat);
  658: 		echo $after;
  659: 		$previouscat = $currentcat;
  660: 	}
  661: }
  662: 
  663: // out of the b2 loop
  664: function dropdown_cats($optionall = 1, $all = 'All') {
  665: 	global $cat, $tablecategories, $querycount;
  666: 	$query="SELECT * FROM $tablecategories";
  667: 	$result=mysql_query($query);
  668: 	$querycount++;
  669: 	echo "<select name=\"cat\" class=\"postform\">\n";
  670: 	if (intval($optionall) == 1) {
  671: 		echo "\t<option value=\"all\">$all</option>\n";
  672: 	}
  673: 	while($row = mysql_fetch_object($result)) {
  674: 		echo "\t<option value=\"".$row->cat_ID."\"";
  675: 		if ($row->cat_ID == $cat)
  676: 			echo ' selected="selected"';
  677: 		echo '>'.stripslashes($row->cat_name)."</option>\n";
  678: 	}
  679: 	echo "</select>\n";
  680: }
  681: 
  682: // out of the b2 loop
  683: function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = 'blah') {
  684: 	global $tablecategories,$querycount;
  685: 	global $pagenow;
  686: 	global $querystring_start, $querystring_equal, $querystring_separator;
  687: 	$file = ($file == 'blah') ? $pagenow : $file;
  688: 	$sort_column = 'cat_'.$sort_column;
  689: 	$query="SELECT * FROM $tablecategories WHERE cat_ID > 0 ORDER BY $sort_column $sort_order";
  690: 	$result=mysql_query($query);
  691: 	$querycount++;
  692: 	if (intval($optionall) == 1) {
  693: 		$all = apply_filters('list_cats', $all);
  694: 		echo "\t<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.'all">'.$all."</a><br />\n";
  695: 	}
  696: 	while($row = mysql_fetch_object($result)) {
  697: 		$cat_name = $row->cat_name;
  698: 		$cat_name = apply_filters('list_cats', $cat_name);
  699: 		echo "\t<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.$row->cat_ID.'">';
  700: 		echo stripslashes($cat_name)."</a><br />\n";
  701: 	}
  702: }
  703: 
  704: /***** // Category tags *****/
  705: 
  706: 
  707: 
  708: 
  709: /***** <Link> tags *****/
  710: 
  711: 
  712: 
  713: /***** // <Link> tags *****/
  714: 
  715: 
  716: 
  717: 
  718: /***** Comment tags *****/
  719: 
  720: // generic comments/trackbacks/pingbacks numbering
  721: function generic_ctp_number($post_id, $mode = 'comments') {
  722: 	global $postdata, $tablecomments, $querycount, $cache_ctp_number, $use_cache;
  723: 	if (!isset($cache_ctp_number[$post_id]) || (!$use_cache)) {
  724: 		$post_id = intval($post_id);
  725: 		$query = "SELECT * FROM $tablecomments WHERE comment_post_ID = $post_id";
  726: 		$result = mysql_query($query) or die('SQL query: '.$query.'<br />MySQL Error: '.mysql_error());
  727: 		$querycount++;
  728: 		$ctp_number = array();
  729: 		while($row = mysql_fetch_object($result)) {
  730: 			if (substr($row->comment_content, 0, 13) == '<trackback />') {
  731: 				$ctp_number['trackbacks']++;
  732: 			} elseif (substr($row->comment_content, 0, 12) == '<pingback />') {
  733: 				$ctp_number['pingbacks']++;
  734: 			} else {
  735: 				$ctp_number['comments']++;
  736: 			}
  737: 			$ctp_number['ctp']++;
  738: 		}
  739: 		$cache_ctp_number[$post_id] = $ctp_number;
  740: 	} else {
  741: 		$ctp_number = $cache_ctp_number[$post_id];
  742: 	}
  743: 	if (($mode != 'comments') && ($mode != 'trackbacks') && ($mode != 'pingbacks') && ($mode != 'ctp')) {
  744: 		$mode = 'ctp';
  745: 	}
  746: 	return $ctp_number[$mode];
  747: }
  748: 
  749: function comments_number($zero='no comment', $one='1 comment', $more='% comments') {
  750: 	// original hack by dodo@regretless.com
  751: 	global $id,$postdata,$tablecomments,$c,$querycount,$cache_commentsnumber,$use_cache;
  752: 	$number = generic_ctp_number($id, 'comments');
  753: 	if ($number == 0) {
  754: 		$blah = $zero;
  755: 	} elseif ($number == 1) {
  756: 		$blah = $one;
  757: 	} elseif ($number  > 1) {
  758: 		$n = $number;
  759: 		$more=str_replace('%', $n, $more);
  760: 		$blah = $more;
  761: 	}
  762: 	echo $blah;
  763: }
  764: 
  765: function comments_link($file='') {
  766: 	global $id,$pagenow;
  767: 	global $querystring_start, $querystring_equal, $querystring_separator;
  768: 	if ($file == '')	$file = $pagenow;
  769: 	if ($file == '/')	$file = '';
  770: 	echo $file.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'c'.$querystring_equal.'1#comments';
  771: }
  772: 
  773: function comments_popup_script($width=400, $height=400, $file='b2commentspopup.php', $trackbackfile='b2trackbackpopup.php', $pingbackfile='b2pingbackspopup.php') {
  774: 	global $b2commentspopupfile, $b2trackbackpopupfile, $b2pingbackpopupfile, $b2commentsjavascript;
  775: 	$b2commentspopupfile = $file;
  776: 	$b2trackbackpopupfile = $trackbackfile;
  777: 	$b2pingbackpopupfile = $pingbackfile;
  778: 	$b2commentsjavascript = 1;
  779: 	$javascript = "<script language=\"javascript\" type=\"text/javascript\">\n<!--\nfunction b2open (macagna) {\n    window.open(macagna, '_blank', 'width=$width,height=$height,scrollbars=yes,status=yes');\n}\n//-->\n</script>\n";
  780: 	echo $javascript;
  781: }
  782: 
  783: function comments_popup_link($zero='no comment', $one='1 comment', $more='% comments', $CSSclass='') {
  784: 	global $id, $b2commentspopupfile, $b2commentsjavascript;
  785: 	global $querystring_start, $querystring_equal, $querystring_separator;
  786: 	echo '<a href="';
  787: 	if ($b2commentsjavascript) {
  788: 		echo $b2commentspopupfile.'?p='.$id.'&amp;c=1';
  789: 		echo '" onclick="b2open(this.href); return false"';
  790: 	} else {
  791: 		// if comments_popup_script() is not in the template, display simple comment link
  792: 		comments_link();
  793: 		echo '"';
  794: 	}
  795: 	if (!empty($CSSclass)) {
  796: 		echo ' class="'.$CSSclass.'"';
  797: 	}
  798: 	echo '>';
  799: 	comments_number($zero, $one, $more);
  800: 	echo '</a>';
  801: }
  802: 
  803: function comment_ID() {
  804: 	global $commentdata;	echo $commentdata['comment_ID'];
  805: }
  806: 
  807: function comment_author() {
  808: 	global $commentdata;	echo stripslashes($commentdata['comment_author']);
  809: }
  810: 
  811: function comment_author_email() {
  812: 	global $commentdata;	echo antispambot(stripslashes($commentdata['comment_author_email']));
  813: }
  814: 
  815: function comment_author_url() {
  816: 	global $commentdata;
  817: 	$url = trim(stripslashes($commentdata['comment_author_url']));
  818: 	$url = (!stristr($url, '://')) ? 'http://'.$url : $url;
  819: 	// convert & into &amp;
  820: 	$url = preg_replace('#&([^amp\;])#is', '&amp;$1', $url);
  821: 	if ($url != 'http://url') {
  822: 		echo $url;
  823: 	}
  824: }
  825: 
  826: function comment_author_email_link($linktext='', $before='', $after='') {
  827: 	global $commentdata;
  828: 	$email=$commentdata['comment_author_email'];
  829: 	if ((!empty($email)) && ($email != '@')) {
  830: 		$display = ($linktext != '') ? $linktext : antispambot(stripslashes($email));
  831: 		echo $before;
  832: 		echo '<a href="mailto:'.antispambot(stripslashes($email)).'">'.$display.'</a>';
  833: 		echo $after;
  834: 	}
  835: }
  836: 
  837: function comment_author_url_link($linktext='', $before='', $after='') {
  838: 	global $commentdata;
  839: 	$url = trim(stripslashes($commentdata['comment_author_url']));
  840: 	$url = preg_replace('#&([^amp\;])#is', '&amp;$1', $url);
  841: 	$url = (!stristr($url, '://')) ? 'http://'.$url : $url;
  842: 	if ((!empty($url)) && ($url != 'http://') && ($url != 'http://url')) {
  843: 		$display = ($linktext != '') ? $linktext : stripslashes($url);
  844: 		echo $before;
  845: 		echo '<a href="'.stripslashes($url).'" target="_blank">'.$display.'</a>';
  846: 		echo $after;
  847: 	}
  848: }
  849: 
  850: function comment_author_IP() {
  851: 	global $commentdata;	echo stripslashes($commentdata['comment_author_IP']);
  852: }
  853: 
  854: function comment_text() {
  855: 	global $commentdata;
  856: 	$comment = stripslashes($commentdata['comment_content']);
  857: 	$comment = str_replace('<trackback />', '', $comment);
  858: 	$comment = str_replace('<pingback />', '', $comment);
  859: 	$comment = convert_chars($comment);
  860: 	$comment = convert_bbcode($comment);
  861: 	$comment = convert_gmcode($comment);
  862: 	$comment = convert_smilies($comment);
  863: 	$comment = make_clickable($comment);
  864: 	$comment = balanceTags($comment);
  865: 	$comment = apply_filters('comment_text', $comment);
  866: 	echo $comment;
  867: }
  868: 
  869: function comment_date($d='') {
  870: 	global $commentdata,$dateformat;
  871: 	if ($d == '') {
  872: 		echo mysql2date($dateformat, $commentdata['comment_date']);
  873: 	} else {
  874: 		echo mysql2date($d, $commentdata['comment_date']);
  875: 	}
  876: }
  877: 
  878: function comment_time($d='') {
  879: 	global $commentdata,$timeformat;
  880: 	if ($d == '') {
  881: 		echo mysql2date($timeformat, $commentdata['comment_date']);
  882: 	} else {
  883: 		echo mysql2date($d, $commentdata['comment_date']);
  884: 	}
  885: }
  886: 
  887: /***** // Comment tags *****/
  888: 
  889: 
  890: 
  891: /***** TrackBack tags *****/
  892: 
  893: function trackback_url($display = 1) {
  894: 	global $pathserver, $id;
  895: 	$tb_url = $pathserver.'/b2trackback.php/'.$id;
  896: 	if ($display) {
  897: 		echo $tb_url;
  898: 	} else {
  899: 		return $tb_url;
  900: 	}
  901: }
  902: 
  903: function trackback_number($zero='no trackback', $one='1 trackback', $more='% trackbacks') {
  904: 	global $id, $tablecomments, $tb, $querycount, $cache_trackbacknumber, $use_cache;
  905: 	$number = generic_ctp_number($id, 'trackbacks');
  906: 	if ($number == 0) {
  907: 		$blah = $zero;
  908: 	} elseif ($number == 1) {
  909: 		$blah = $one;
  910: 	} elseif ($number  > 1) {
  911: 		$n = $number;
  912: 		$more=str_replace('%', $n, $more);
  913: 		$blah = $more;
  914: 	}
  915: 	echo $blah;
  916: }
  917: 
  918: function trackback_link($file='') {
  919: 	global $id,$pagenow;
  920: 	global $querystring_start, $querystring_equal, $querystring_separator;
  921: 	if ($file == '')	$file = $pagenow;
  922: 	if ($file == '/')	$file = '';
  923: 	echo $file.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'tb'.$querystring_equal.'1#trackback';
  924: }
  925: 
  926: function trackback_popup_link($zero='no trackback', $one='1 trackback', $more='% trackbacks', $CSSclass='') {
  927: 	global $id, $b2trackbackpopupfile, $b2commentsjavascript;
  928: 	global $querystring_start, $querystring_equal, $querystring_separator;
  929: 	echo '<a href="';
  930: 	if ($b2commentsjavascript) {
  931: 		echo $b2trackbackpopupfile.'?p='.$id.'&amp;tb=1';
  932: 		echo '" onclick="b2open(this.href); return false"';
  933: 	} else {
  934: 		// if comments_popup_script() is not in the template, display simple comment link
  935: 		trackback_link();
  936: 		echo '"';
  937: 	}
  938: 	if (!empty($CSSclass)) {
  939: 		echo ' class="'.$CSSclass.'"';
  940: 	}
  941: 	echo '>';
  942: 	trackback_number($zero, $one, $more);
  943: 	echo '</a>';
  944: }
  945: 
  946: function trackback_rdf($timezone=0) {
  947: 	global $pathserver, $id, $HTTP_SERVER_VARS;
  948: 	if (!stristr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'W3C_Validator')) {
  949: 		echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" '."\n";
  950: 		echo '    xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
  951: 		echo '    xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">'."\n";
  952: 		echo '<rdf:Description'."\n";
  953: 		echo '    rdf:about="';
  954: 		permalink_single();
  955: 		echo '"'."\n";
  956: 		echo '    dc:identifier="';
  957: 		permalink_single();
  958: 		echo '"'."\n";
  959: 		echo '    dc:title="'.addslashes(get_the_title()).'"'."\n";
  960: 		echo '    trackback:ping="'.trackback_url(0).'"'."\n";
  961: 		echo '</rdf:RDF>';
  962: 	}
  963: }
  964: 
  965: /***** // TrackBack tags *****/
  966: 
  967: 
  968: 
  969: /***** PingBack tags *****/
  970: 
  971: function pingback_number($zero='no pingback', $one='1 pingback', $more='% pingbacks') {
  972: 	global $id, $tablecomments, $tb, $querycount, $cache_pingbacknumber, $use_cache;
  973: 	$number = generic_ctp_number($id, 'pingbacks');
  974: 	if ($number == 0) {
  975: 		$blah = $zero;
  976: 	} elseif ($number == 1) {
  977: 		$blah = $one;
  978: 	} elseif ($number  > 1) {
  979: 		$n = $number;
  980: 		$more=str_replace('%', $n, $more);
  981: 		$blah = $more;
  982: 	}
  983: 	echo $blah;
  984: }
  985: 
  986: function pingback_link($file='') {
  987: 	global $id,$pagenow;
  988: 	global $querystring_start, $querystring_equal, $querystring_separator;
  989: 	if ($file == '')	$file = $pagenow;
  990: 	if ($file == '/')	$file = '';
  991: 	echo $file.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'pb'.$querystring_equal.'1#pingbacks';
  992: }
  993: 
  994: function pingback_popup_link($zero='no pingback', $one='1 pingback', $more='% pingbacks', $CSSclass='') {
  995: 	global $id, $b2pingbackpopupfile, $b2commentsjavascript;
  996: 	global $querystring_start, $querystring_equal, $querystring_separator;
  997: 	echo '<a href="';
  998: 	if ($b2commentsjavascript) {
  999: 		echo $b2pingbackpopupfile.'?p='.$id.'&amp;pb=1';
 1000: 		echo '" onclick="b2open(this.href); return false"';
 1001: 	} else {
 1002: 		// if comments_popup_script() is not in the template, display simple comment link
 1003: 		pingback_link();
 1004: 		echo '"';
 1005: 	}
 1006: 	if (!empty($CSSclass)) {
 1007: 		echo ' class="'.$CSSclass.'"';
 1008: 	}
 1009: 	echo '>';
 1010: 	pingback_number($zero, $one, $more);
 1011: 	echo '</a>';
 1012: }
 1013: 
 1014: 
 1015: 
 1016: /***** // PingBack tags *****/
 1017: 
 1018: 
 1019: 
 1020: /***** Permalink tags *****/
 1021: 
 1022: function permalink_anchor($mode = 'id') {
 1023: 	global $id, $postdata;
 1024: 	switch(strtolower($mode)) {
 1025: 		case 'title':
 1026: 			$title = preg_replace('/[^a-zA-Z0-9_\.-]/', '_', $postdata['Title']);
 1027: 			echo '<a name="'.$title.'"></a>';
 1028: 			break;
 1029: 		case 'id':
 1030: 		default:
 1031: 			echo '<a name="'.$id.'"></a>';
 1032: 			break;
 1033: 	}
 1034: }
 1035: 
 1036: function permalink_link($file='', $mode = 'id') {
 1037: 	global $id, $postdata, $pagenow, $cacheweekly;
 1038: 	global $querystring_start, $querystring_equal, $querystring_separator;
 1039: 	$file = ($file=='') ? $pagenow : $file;
 1040: 	switch(strtolower($mode)) {
 1041: 		case 'title':
 1042: 			$title = preg_replace('/[^a-zA-Z0-9_\.-]/', '_', $postdata['Title']);
 1043: 			$anchor = $title;
 1044: 			break;
 1045: 		case 'id':
 1046: 		default:
 1047: 			$anchor = $id;
 1048: 			break;
 1049: 	}
 1050: 	$archive_mode = get_settings('archive_mode');
 1051: 	switch($archive_mode) {
 1052: 		case 'daily':
 1053: 			echo $file.$querystring_start.'m'.$querystring_equal.substr($postdata['Date'],0,4).substr($postdata['Date'],5,2).substr($postdata['Date'],8,2).'#'.$anchor;
 1054: 			break;
 1055: 		case 'monthly':
 1056: 			echo $file.$querystring_start.'m'.$querystring_equal.substr($postdata['Date'],0,4).substr($postdata['Date'],5,2).'#'.$anchor;
 1057: 			break;
 1058: 		case 'weekly':
 1059: 			if((!isset($cacheweekly)) || (empty($cacheweekly[$postdata['Date']]))) {
 1060: 				$sql = "SELECT WEEK('".$postdata['Date']."')";
 1061: 				$result = mysql_query($sql);
 1062: 				$row = mysql_fetch_row($result);
 1063: 				$cacheweekly[$postdata['Date']] = $row[0];
 1064: 			}
 1065: 			echo $file.$querystring_start.'m'.$querystring_equal.substr($postdata['Date'],0,4).$querystring_separator.'w'.$querystring_equal.$cacheweekly[$postdata['Date']].'#'.$anchor;
 1066: 			break;
 1067: 		case 'postbypost':
 1068: 			echo $file.$querystring_start.'p'.$querystring_equal.$id;
 1069: 			break;
 1070: 	}
 1071: }
 1072: 
 1073: function permalink_single($file='') {
 1074: 	global $id,$postdata,$pagenow;
 1075: 	global $querystring_start, $querystring_equal, $querystring_separator;
 1076: 	if ($file=='')
 1077: 		$file=$pagenow;
 1078: 	echo $file.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'more'.$querystring_equal.'1'.$querystring_separator.'c'.$querystring_equal.'1';
 1079: }
 1080: 
 1081: function permalink_single_rss($file='b2rss.xml') {
 1082: 	global $id,$postdata,$pagenow,$siteurl,$blogfilename;
 1083: 	global $querystring_start, $querystring_equal, $querystring_separator;
 1084: 		echo $siteurl.'/'.$blogfilename.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'c'.$querystring_equal.'1';
 1085: }
 1086: 
 1087: /***** // Permalink tags *****/
 1088: 
 1089: 
 1090: 
 1091: 
 1092: // @@@ These aren't template tags, do not edit them
 1093: 
 1094: function start_b2() {
 1095: 	global $row, $id, $postdata, $authordata, $day, $preview, $b2page, $pages, $multipage, $more, $numpages;
 1096: 	global $preview_userid,$preview_date,$preview_content,$preview_title,$preview_category,$preview_notify,$preview_make_clickable,$preview_autobr;
 1097: 	global $pagenow;
 1098: 	global $HTTP_GET_VARS;
 1099: 	if (!$preview) {
 1100: 		$id = $row->ID;
 1101: 		$postdata=get_postdata2($id);
 1102: 	} else {
 1103: 		$id = 0;
 1104: 		$postdata = array (
 1105: 			'ID' => 0, 
 1106: 			'Author_ID' => $HTTP_GET_VARS['preview_userid'],
 1107: 			'Date' => $HTTP_GET_VARS['preview_date'],
 1108: 			'Content' => $HTTP_GET_VARS['preview_content'],
 1109: 			'Title' => $HTTP_GET_VARS['preview_title'],
 1110: 			'Category' => $HTTP_GET_VARS['preview_category'],
 1111: 			'Notify' => 1,
 1112: 			'Clickable' => 1,
 1113: 			'Karma' => 0 // this isn't used yet
 1114: 			);
 1115: 		if (!empty($HTTP_GET_VARS['preview_autobr'])) {
 1116: 			$postdata['Content'] = autobrize($postdata['Content']);
 1117: 		}
 1118: 	}
 1119: 	$authordata = get_userdata($postdata['Author_ID']);
 1120: 	$day = mysql2date('d.m.y',$postdata['Date']);
 1121: 	$currentmonth = mysql2date('m',$postdata['Date']);
 1122: 	$numpages=1;
 1123: 	if (!$b2page)
 1124: 		$b2page=1;
 1125: 	if (isset($p))
 1126: 		$more=1;
 1127: 	$content = $postdata['Content'];
 1128: 	if (preg_match('/<!--nextpage-->/', $postdata['Content'])) {
 1129: 		if ($b2page > 1)
 1130: 			$more=1;
 1131: 		$multipage=1;
 1132: 		$content=stripslashes($postdata['Content']);
 1133: 		$content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);
 1134: 		$content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content);
 1135: 		$content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content);
 1136: 		$pages=explode('<!--nextpage-->', $content);
 1137: 		$numpages=count($pages);
 1138: 	} else {
 1139: 		$pages[0]=stripslashes($postdata['Content']);
 1140: 		$multipage=0;
 1141: 	}
 1142: 	return true;
 1143: }
 1144: 
 1145: function is_new_day() {
 1146: 	global $day, $previousday;
 1147: 	if ($day != $previousday) {
 1148: 		return(1);
 1149: 	} else {
 1150: 		return(0);
 1151: 	}
 1152: }
 1153: 
 1154: function apply_filters($tag, $string) {
 1155: 	global $b2_filter;
 1156: 	if (isset($b2_filter['all'])) {
 1157: 		$b2_filter['all'] = (is_string($b2_filter['all'])) ? array($b2_filter['all']) : $b2_filter['all'];
 1158: 		$b2_filter[$tag] = array_merge($b2_filter['all'], $b2_filter[$tag]);
 1159: 		$b2_filter[$tag] = array_unique($b2_filter[$tag]);
 1160: 	}
 1161: 	if (isset($b2_filter[$tag])) {
 1162: 		$b2_filter[$tags] = (is_string($b2_filter[$tag])) ? array($b2_filter[$tag]) : $b2_filter[$tag];
 1163: 		$functions = $b2_filter[$tag];
 1164: 		foreach($functions as $function) {
 1165: 			$string = $function($string);
 1166: 		}
 1167: 	}
 1168: 	return $string;
 1169: }
 1170: 
 1171: function add_filter($tag, $function_to_add) {
 1172: 	global $b2_filter;
 1173: 	if (isset($b2_filter[$tag])) {
 1174: 		$functions = $b2_filter[$tag];
 1175: 		if (is_array($functions)) {
 1176: 			foreach($functions as $function) {
 1177: 				$new_functions[] = $function;
 1178: 			}
 1179: 		} elseif (is_string($functions)) {
 1180: 			$new_functions[] = $functions;
 1181: 		}
 1182: /* this is commented out because it just makes PHP die silently
 1183:    for no apparent reason
 1184: 		if (is_array($function_to_add)) {
 1185: 			foreach($function_to_add as $function) {
 1186: 				if (!in_array($function, $b2_filter[$tag])) {
 1187: 					$new_functions[] = $function;
 1188: 				}
 1189: 			}
 1190: 		} else */if (is_string($function_to_add)) {
 1191: 			if (!@in_array($function_to_add, $b2_filter[$tag])) {
 1192: 				$new_functions[] = $function_to_add;
 1193: 			}
 1194: 		}
 1195: 		$b2_filter[$tag] = $new_functions;
 1196: 	} else {
 1197: 		$b2_filter[$tag] = array($function_to_add);
 1198: 	}
 1199: 	return true;
 1200: }
 1201: 
 1202: ?>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>