File:  [mozdev] / cdn / www / blog.header.php
Revision 1.17: download - view: text, annotated - select for diffs - revision graph
Sun Dec 28 22:31:41 2003 UTC (15 years, 7 months ago) by cdn
Branches: MAIN
CVS tags: HEAD
*** empty log message ***

    1: <?php
    2: 
    3: // echo 'blog<p />';
    4: 
    5: require_once('/usr/local/sandbox/php/include/globals.h');
    6: 
    7: // echo 'glob';
    8: 
    9: $use_cache = 1;
   10: $use_gzipcompression = 0;
   11: 
   12: /* Including config and functions files */
   13: require_once (dirname(__FILE__).'/b2config.php');
   14: //echo '<p>b2config</p>';
   15: $b2blah = dirname(__FILE__).'/';
   16: if ( (substr($b2inc,0,1)=='/') || (substr($b2inc,1,1)==':') ) {
   17: 	$b2blah='./';
   18: }
   19: 
   20: if ( !isset($b2inc) )
   21:   $b2inc = 'b2-include';
   22: 
   23: require_once ($b2blah.$b2inc.'/b2template.functions.php');
   24: //echo '<p>b2tmpfunk</p>';
   25: require_once ($b2blah.$b2inc.'/b2vars.php');
   26: //echo '<p>b2var</p>';
   27: require_once ($b2blah.$b2inc.'/b2functions.php');
   28: //echo '<p>b2func</p>';
   29: require_once ($b2blah.$b2inc.'/xmlrpc.php');
   30: require_once ($b2blah.$b2inc.'/xmlrpcs.php');
   31: //echo '<p>b2rpc[2]</p>';
   32: 
   33: $b2varstoreset = array('m','p','posts','w','c', 'cat','withcomments','s','search','exact', 'sentence','poststart','postend','preview','debug', 'calendar','page','paged','more','tb', 'pb','author','order','orderby');
   34: 
   35: //this doesn't work [under mozdev] : )
   36: // $_SERVER["REQUEST_URI"]; => /blog.html?p=1&c=1
   37: 
   38: 	for ($i=0; $i<count($b2varstoreset); $i += 1) {
   39: 		$b2var = $b2varstoreset[$i];
   40: 		if (!isset($$b2var)) {
   41: 			if (empty($HTTP_POST_VARS[$b2var])) {
   42: 				if (empty($HTTP_GET_VARS[$b2var])) {
   43: 					$$b2var = '';
   44: 				} else {
   45: 					$$b2var = $HTTP_GET_VARS[$b2var];
   46: 				}
   47: 			} else {
   48: 				$$b2var = $HTTP_POST_VARS[$b2var];
   49: 			}
   50: 		}
   51: 	}
   52: 
   53: // my own thing - again ... I'm quite sure some of my other 'bull in a chinashop' coding can be improved
   54: 
   55: $gfdsa = parse_url ($_SERVER['REQUEST_URI']);
   56: 
   57: $varsz = explode('&', $gfdsa['query']);
   58: 
   59: foreach( $varsz as $vrsz )
   60: {
   61:   $zrav = explode($querystring_equal, $vrsz);
   62:   ${$zrav[0]} = $zrav[1];
   63:   $HTTP_GET_VARS[$zrav[0]] = $zrav[1];
   64: }
   65: 
   66: // /me
   67: 
   68: /* Connecting to the db */
   69: dbconnect();
   70: 
   71: /* Sending HTTP headers */
   72: $last_modified_header = mysql2date('D, d M Y H:i:s', get_lastpostdate());
   73: @header ("X-Pingback: $pathserver/xmlrpc.php");
   74: @header ("Last-Modified: $last_modified_header");
   75: @header ('ETag: "'.md5($last_modified_header.$pagenow).'"');
   76: 
   77: /* Getting settings from db */
   78: $posts_per_page = get_settings('posts_per_page');
   79: $what_to_show = get_settings('what_to_show');
   80: $archive_mode = get_settings('archive_mode');
   81: $dateformat = stripslashes(get_settings('date_format'));
   82: $timeformat = stripslashes(get_settings('time_format'));
   83: $autobr = get_settings('AutoBR');
   84: $time_difference = get_settings('time_difference');
   85: 
   86: /* First let's clear some variables */
   87: $whichcat = '';
   88: $whichauthor = '';
   89: $result = '';
   90: $where = '';
   91: $limits = '';
   92: $distinct = '';
   93: 
   94: if ($pagenow != 'b2edit.php') { timer_start(); }
   95: 
   96: if ($posts)
   97: 	$posts_per_page=$posts;
   98: 
   99: // if a month is specified in the querystring, load that month
  100: if ($m != '') {
  101: 	$m = ''.intval($m);
  102: 	$where .= ' AND YEAR(post_date)='.substr($m,0,4);
  103: 	if (strlen($m)>5)
  104: 		$where .= ' AND MONTH(post_date)='.substr($m,4,2);
  105: 	if (strlen($m)>7)
  106: 		$where .= ' AND DAYOFMONTH(post_date)='.substr($m,6,2);
  107: 	if (strlen($m)>9)
  108: 		$where .= ' AND HOUR(post_date)='.substr($m,8,2);
  109: 	if (strlen($m)>11)
  110: 		$where .= ' AND MINUTE(post_date)='.substr($m,10,2);
  111: 	if (strlen($m)>13)
  112: 		$where .= ' AND SECOND(post_date)='.substr($m,12,2);
  113: 
  114: }
  115: 
  116: if ($w != '') {
  117: 	$w = ''.intval($w);
  118: 	$where .= ' AND WEEK(post_date,1)='.$w;
  119: }
  120: 
  121: // if a post number is specified, load that post
  122: if (($p != '') && ($p != 'all')) {
  123: 	$p = intval($p);
  124: 	$where = ' AND ID = '.$p;
  125: }
  126: 
  127: // if a search pattern is specified, load the posts that match
  128: if (!empty($s)) {
  129: 	$s = addslashes_gpc($s);
  130: 	$search = ' AND (';
  131: 	// puts spaces instead of commas
  132: 	$s = preg_replace('/, +/', '', $s);
  133: 	$s = str_replace(',', ' ', $s);
  134: 	$s = str_replace('"', ' ', $s);
  135: 	$s = trim($s);
  136: 	if ($exact) {
  137: 		$n = '';
  138: 	} else {
  139: 		$n = '%';
  140: 	}
  141: 	if (!$sentence) {
  142: 		$s_array = explode(' ',$s);
  143: 		$search .= '(post_title LIKE \''.$n.$s_array[0].$n.'\') OR (post_content LIKE \''.$s_array[0].'\')';
  144: 		for ( $i = 1; $i < count($s_array); $i = $i + 1) {
  145: 			$search .= ' OR (post_title LIKE \''.$n.$s_array[$i].$n.'\') OR (post_content LIKE \''.$n.$s_array[$i].$n.'\')';
  146: 		}
  147: 		$search .= ' OR (post_title LIKE \''.$n.$s.$n.'\') OR (post_content LIKE \''.$n.$s.$n.'\')';
  148: 		$search .= ')';
  149: 	} else {
  150: 		$search = ' AND ((post_title LIKE \''.$n.$s.$n.'\') OR (post_content LIKE \''.$n.$s.$n.'\'))';
  151: 	}
  152: }
  153: 
  154: // category stuff
  155: if ((empty($cat)) || ($cat == 'all') || ($cat == '0')) {
  156: 	$whichcat='';
  157: } else {
  158: 	$cat = ''.urldecode($cat).'';
  159: 	$cat = addslashes_gpc($cat);
  160: 	if (stristr($cat,'-')) {
  161: 		$eq = '!=';
  162: 		$andor = 'AND';
  163: 		$cat = explode('-',$cat);
  164: 		$cat = $cat[1];
  165: 	} else {
  166: 		$eq = '=';
  167: 		$andor = 'OR';
  168: 	}
  169: 	$cat_array = explode(' ',$cat);
  170:     $whichcat .= ' AND (post_category '.$eq.' '.$cat_array[0];
  171:     for ($i = 1; $i < (count($cat_array)); $i = $i + 1) {
  172:         $whichcat .= ' '.$andor.' post_category '.$eq.' '.$cat_array[$i];
  173:     }
  174:     $whichcat .= ')';
  175: } 
  176: // author stuff
  177: if ((!empty($author)) || ($author == 'all') || ($cat == '0')) {
  178: 	$whichauthor='';
  179: } elseif (intval($author)) {
  180: 	$author = intval($author);
  181: 	if (stristr($author, '-')) {
  182: 		$eq = '!=';
  183: 		$andor = 'AND';
  184: 		$author = explode('-', $author);
  185: 		$author = $author[1];
  186: 	} else {
  187: 		$eq = '=';
  188: 		$andor = 'OR';
  189: 	}
  190: 	$author_array = explode(' ', $author);
  191: 	$whichauthor .= ' AND post_author '.$eq.' '.$author_array[0];
  192: 	for ($i = 1; $i < (count($author_array)); $i = $i + 1) {
  193: 		$whichauthor .= ' '.$andor.' post_author '.$eq.' '.$author_array[$i];
  194: 	}
  195: }
  196: 
  197: $where .= $search.$whichcat.$whichauthor;
  198: 
  199: if ((empty($order)) || ((strtoupper($order) != 'ASC') && (strtoupper($order) != 'DESC'))) {
  200: 	$order='DESC';
  201: }
  202: 
  203: // order by stuff
  204: if (empty($orderby)) {
  205: 	$orderby='date '.$order;
  206: } else {
  207: 	$orderby = urldecode($orderby);
  208: 	$orderby = addslashes_gpc($orderby);
  209: 	$orderby_array = explode(' ',$orderby);
  210: 	$orderby = $orderby_array[0].' '.$order;
  211: 	if (count($orderby_array)>1) {
  212: 		for ($i = 1; $i < (count($orderby_array)); $i = $i + 1) {
  213: 			$orderby .= ',post_'.$orderby_array[$i].' '.$order;
  214: 		}
  215: 	}
  216: }
  217: 
  218: if ((!$whichcat) && (!$m) && (!$p) && (!$w) && (!$s) && empty($poststart) && empty($postend)) {
  219: 	if ($what_to_show == 'posts') {
  220: 		$limits = ' LIMIT '.$posts_per_page;
  221: 	} elseif ($what_to_show == 'days') {
  222: 		$lastpostdate = get_lastpostdate();
  223: 		$lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate);
  224: 		$lastpostdate = mysql2date('U',$lastpostdate);
  225: 		$otherdate = date('Y-m-d H:i:s', ($lastpostdate - (($posts_per_page-1) * 86400)));
  226: 		$where .= ' AND post_date > \''.$otherdate.'\'';
  227: 	}
  228: }
  229: 
  230: if ( !empty($postend) && ($postend > $poststart) && (!$m) &&(!$w) && (!$whichcat) && (!$s) && (!$p)) {
  231: 	if ($what_to_show == 'posts' || ($what_to_show == 'paged' && (!$paged))) {
  232: 		$poststart = intval($poststart);
  233: 		$postend = intval($postend);
  234: 		$posts = $postend - $poststart;
  235: 		$limits = ' LIMIT '.$poststart.','.$posts;
  236: 	} elseif ($what_to_show == 'days') {
  237: 		$poststart = intval($poststart);
  238: 		$postend = intval($postend);
  239: 		$posts = $postend - $poststart;
  240: 		$lastpostdate = get_lastpostdate();
  241: 		$lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate);
  242: 		$lastpostdate = mysql2date('U',$lastpostdate);
  243: 		$startdate = date('Y-m-d H:i:s', ($lastpostdate - (($poststart -1) * 86400)));
  244: 		$otherdate = date('Y-m-d H:i:s', ($lastpostdate - (($postend -1) * 86400)));
  245: 		$where .= ' AND post_date > \''.$otherdate.'\' AND post_date < \''.$startdate.'\'';
  246: 	}
  247: } else {
  248: 	if (($what_to_show == 'paged') && (!$p) && (!$more)) {
  249: 		if ($pagenow != 'b2edit.php') {
  250: 			$pgstrt = '';
  251: 			if ($paged) {
  252: 				$pgstrt = (intval($paged) -1) * $posts_per_page . ', ';
  253: 			}
  254: 			$limits = 'LIMIT '.$pgstrt.$posts_per_page;
  255: 		} else {
  256: 			if (($m) || ($p) || ($w) || ($s) || ($whichcat)) {
  257: 				$limits = '';
  258: 			} else {
  259: 				$pgstrt = '';
  260: 				if ($paged) {
  261: 					$pgstrt = (intval($paged) -1) * $posts_per_page . ', ';
  262: 				}
  263: 				$limits = 'LIMIT '.$pgstrt.$posts_per_page;
  264: 			}
  265: 		}
  266: 	}
  267: 	elseif (($m) || ($p) || ($w) || ($s) || ($whichcat) || ($author)) {
  268: 		$limits = '';
  269: 	}
  270: }
  271: 
  272: if ($p == 'all') {
  273: 	$where = '';
  274: }
  275: 
  276: $now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600)));
  277: 
  278: if ($pagenow != 'b2edit.php') {
  279: 	if ((empty($poststart)) || (empty($postend)) || !($postend > $poststart)) {
  280: 		$where .= ' AND post_date < \''.$now.'\'';
  281: 	}
  282: 	$where .= ' AND post_category > 0';
  283: 	$distinct = 'DISTINCT';
  284: 	if ($use_gzipcompression) {
  285: 		// gzipping the output of the script
  286: 		gzip_compression();
  287: 	}
  288: }
  289: 
  290: $request = " SELECT $distinct * FROM $tableposts WHERE 1=1".$where." ORDER BY post_$orderby $limits";
  291: 
  292: if ($preview) {
  293: 	$request = 'SELECT 1-1'; // dummy mysql query for the preview
  294: 	// little funky fix for IEwin, rawk on that code
  295: 	$is_winIE = ((preg_match('/MSIE/',$HTTP_USER_AGENT)) && (preg_match('/Win/',$HTTP_USER_AGENT)));
  296: 	if (($is_winIE) && (!isset($IEWin_bookmarklet_fix))) {
  297: 		$preview_content =  preg_replace('/\%u([0-9A-F]{4,4})/e',  "'&#'.base_convert('\\1',16,10).';'", $preview_content);
  298: 	}
  299: }
  300: 
  301: //echo $request;
  302: $result = mysql_query($request);
  303: 
  304: ?>

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