2003-04-01 09:12:34 -05:00
< ? php
$use_cache = 1 ;
$use_gzipcompression = 1 ;
2003-05-25 17:20:59 -04:00
/* Including config and functions files */
$curpath = dirname ( __FILE__ ) . '/' ;
2003-05-25 08:43:31 -04:00
2003-06-12 18:42:48 -04:00
require_once ( $curpath . '/wp-config.php' );
2003-05-25 17:20:59 -04:00
require_once ( $curpath . $b2inc . '/b2template.functions.php' );
require_once ( $curpath . $b2inc . '/b2vars.php' );
require_once ( $curpath . $b2inc . '/b2functions.php' );
require_once ( $curpath . $b2inc . '/xmlrpc.inc' );
require_once ( $curpath . $b2inc . '/xmlrpcs.inc' );
2003-04-01 09:12:34 -05:00
2003-12-07 03:59:05 -05:00
$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' , 'year' , 'monthnum' , 'day' , 'name' , 'category_name' );
2003-04-01 09:12:34 -05:00
for ( $i = 0 ; $i < count ( $b2varstoreset ); $i += 1 ) {
$b2var = $b2varstoreset [ $i ];
if ( ! isset ( $$b2var )) {
if ( empty ( $HTTP_POST_VARS [ $b2var ])) {
if ( empty ( $HTTP_GET_VARS [ $b2var ])) {
$$b2var = '' ;
} else {
$$b2var = $HTTP_GET_VARS [ $b2var ];
}
} else {
$$b2var = $HTTP_POST_VARS [ $b2var ];
}
}
}
2003-05-25 19:38:03 -04:00
/* Sending HTTP headers */
2003-05-23 08:39:05 -04:00
// It is presumptious to think that WP is the only thing that might change on the page.
2003-05-25 19:38:03 -04:00
@ header ( " Expires: Mon, 26 Jul 1997 05:00:00 GMT " ); // Date in the past
@ header ( " Last-Modified: " . gmdate ( " D, d M Y H:i:s " ) . " GMT " ); // always modified
@ header ( " Cache-Control: no-store, no-cache, must-revalidate " ); // HTTP/1.1
@ header ( " Cache-Control: post-check=0, pre-check=0 " , false );
@ header ( " Pragma: no-cache " ); // HTTP/1.0
2003-06-03 20:14:49 -04:00
@ header ( " X-Pingback: $siteurl /xmlrpc.php " );
2003-04-01 09:12:34 -05:00
/* Getting settings from db */
2003-11-29 19:55:19 -05:00
if ( isset ( $doing_rss ) && $doing_rss == 1 )
2003-08-08 19:07:25 -04:00
$posts_per_page = get_settings ( 'posts_per_rss' );
2003-11-29 19:55:19 -05:00
if ( ! isset ( $posts_per_page ) || $posts_per_page == 0 )
2003-08-08 19:07:25 -04:00
$posts_per_page = get_settings ( 'posts_per_page' );
2003-04-01 09:12:34 -05:00
$what_to_show = get_settings ( 'what_to_show' );
$archive_mode = get_settings ( 'archive_mode' );
$dateformat = stripslashes ( get_settings ( 'date_format' ));
$timeformat = stripslashes ( get_settings ( 'time_format' ));
$time_difference = get_settings ( 'time_difference' );
/* First let's clear some variables */
$whichcat = '' ;
$whichauthor = '' ;
$result = '' ;
$where = '' ;
$limits = '' ;
$distinct = '' ;
2003-12-07 03:59:05 -05:00
$join = '' ;
2003-04-01 09:12:34 -05:00
2003-11-03 17:11:42 -05:00
if ( $pagenow != 'wp-post.php' ) { timer_start (); }
2003-04-01 09:12:34 -05:00
2003-11-29 19:55:19 -05:00
if ( isset ( $showposts ) && $showposts ) {
2003-06-07 00:23:09 -04:00
$showposts = ( int ) $showposts ;
$posts_per_page = $showposts ;
2003-06-03 20:14:49 -04:00
}
2003-04-01 09:12:34 -05:00
// if a month is specified in the querystring, load that month
if ( $m != '' ) {
$m = '' . intval ( $m );
$where .= ' AND YEAR(post_date)=' . substr ( $m , 0 , 4 );
if ( strlen ( $m ) > 5 )
$where .= ' AND MONTH(post_date)=' . substr ( $m , 4 , 2 );
if ( strlen ( $m ) > 7 )
$where .= ' AND DAYOFMONTH(post_date)=' . substr ( $m , 6 , 2 );
if ( strlen ( $m ) > 9 )
$where .= ' AND HOUR(post_date)=' . substr ( $m , 8 , 2 );
if ( strlen ( $m ) > 11 )
$where .= ' AND MINUTE(post_date)=' . substr ( $m , 10 , 2 );
if ( strlen ( $m ) > 13 )
$where .= ' AND SECOND(post_date)=' . substr ( $m , 12 , 2 );
}
2003-10-26 01:25:26 -04:00
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 ;
}
if ( $name != '' ) {
$name = preg_replace ( '/[^a-z0-9-]/' , '' , $name );
$where .= " AND post_name = ' $name ' " ;
}
2003-04-01 09:12:34 -05:00
if ( $w != '' ) {
$w = '' . intval ( $w );
2003-10-26 01:25:26 -04:00
$where .= ' AND WEEK(post_date, 1)=' . $w ;
2003-04-01 09:12:34 -05:00
}
// if a post number is specified, load that post
if (( $p != '' ) && ( $p != 'all' )) {
$p = intval ( $p );
$where = ' AND ID = ' . $p ;
}
// if a search pattern is specified, load the posts that match
if ( ! empty ( $s )) {
$s = addslashes_gpc ( $s );
$search = ' AND (' ;
// puts spaces instead of commas
$s = preg_replace ( '/, +/' , '' , $s );
$s = str_replace ( ',' , ' ' , $s );
$s = str_replace ( '"' , ' ' , $s );
$s = trim ( $s );
if ( $exact ) {
$n = '' ;
} else {
$n = '%' ;
}
if ( ! $sentence ) {
$s_array = explode ( ' ' , $s );
2003-09-11 14:26:49 -04:00
$search .= '((post_title LIKE \'' . $n . $s_array [ 0 ] . $n . '\') OR (post_content LIKE \'' . $s_array [ 0 ] . '\'))' ;
2003-04-01 09:12:34 -05:00
for ( $i = 1 ; $i < count ( $s_array ); $i = $i + 1 ) {
2003-09-11 14:26:49 -04:00
$search .= ' AND ((post_title LIKE \'' . $n . $s_array [ $i ] . $n . '\') OR (post_content LIKE \'' . $n . $s_array [ $i ] . $n . '\'))' ;
2003-04-01 09:12:34 -05:00
}
$search .= ' OR (post_title LIKE \'' . $n . $s . $n . '\') OR (post_content LIKE \'' . $n . $s . $n . '\')' ;
$search .= ')' ;
} else {
$search = ' AND ((post_title LIKE \'' . $n . $s . $n . '\') OR (post_content LIKE \'' . $n . $s . $n . '\'))' ;
}
}
// category stuff
if (( empty ( $cat )) || ( $cat == 'all' ) || ( $cat == '0' )) {
$whichcat = '' ;
} else {
$cat = '' . urldecode ( $cat ) . '' ;
$cat = addslashes_gpc ( $cat );
if ( stristr ( $cat , '-' )) {
$eq = '!=' ;
$andor = 'AND' ;
$cat = explode ( '-' , $cat );
2003-10-01 10:35:49 -04:00
$cat = intval ( $cat [ 1 ]);
2003-04-01 09:12:34 -05:00
} else {
$eq = '=' ;
$andor = 'OR' ;
}
2003-12-07 03:59:05 -05:00
$join = " LEFT JOIN $tablepost2cat ON ( $tableposts .ID = $tablepost2cat .post_id) " ;
2003-04-01 09:12:34 -05:00
$cat_array = explode ( ' ' , $cat );
2003-12-07 03:59:05 -05:00
$whichcat .= ' AND (category_id ' . $eq . ' ' . intval ( $cat_array [ 0 ]);
2003-04-01 09:12:34 -05:00
for ( $i = 1 ; $i < ( count ( $cat_array )); $i = $i + 1 ) {
2003-10-01 10:35:49 -04:00
$whichcat .= ' ' . $andor . ' post_category ' . $eq . ' ' . intval ( $cat_array [ $i ]);
2003-04-01 09:12:34 -05:00
}
$whichcat .= ')' ;
2003-12-07 03:59:05 -05:00
}
// Category stuff for nice URIs
if ( '' != $category_name ) {
$category_name = preg_replace ( '|[^a-z0-9-/]|' , '' , $category_name );
$join = " LEFT JOIN $tablepost2cat ON ( $tableposts .ID = $tablepost2cat .post_id) LEFT JOIN $tablecategories ON ( $tablepost2cat .category_id = $tablecategories .cat_ID) " ;
$whichcat = " AND (category_nicename = ' $category_name ') " ;
}
2003-04-01 09:12:34 -05:00
// author stuff
2003-10-01 16:58:44 -04:00
if (( empty ( $author )) || ( $author == 'all' ) || ( $author == '0' )) {
2003-04-01 09:12:34 -05:00
$whichauthor = '' ;
2003-10-01 16:58:44 -04:00
} else {
$author = '' . urldecode ( $author ) . '' ;
$author = addslashes_gpc ( $author );
2003-04-01 09:12:34 -05:00
if ( stristr ( $author , '-' )) {
$eq = '!=' ;
$andor = 'AND' ;
$author = explode ( '-' , $author );
2003-10-01 10:35:49 -04:00
$author = '' . intval ( $author [ 1 ]);
2003-04-01 09:12:34 -05:00
} else {
$eq = '=' ;
$andor = 'OR' ;
}
$author_array = explode ( ' ' , $author );
2003-10-02 09:56:14 -04:00
$whichauthor .= ' AND (post_author ' . $eq . ' ' . intval ( $author_array [ 0 ]);
2003-04-01 09:12:34 -05:00
for ( $i = 1 ; $i < ( count ( $author_array )); $i = $i + 1 ) {
2003-10-01 10:35:49 -04:00
$whichauthor .= ' ' . $andor . ' post_author ' . $eq . ' ' . intval ( $author_array [ $i ]);
2003-04-01 09:12:34 -05:00
}
2003-10-02 09:56:14 -04:00
$whichauthor .= ')' ;
2003-04-01 09:12:34 -05:00
}
$where .= $search . $whichcat . $whichauthor ;
if (( empty ( $order )) || (( strtoupper ( $order ) != 'ASC' ) && ( strtoupper ( $order ) != 'DESC' ))) {
$order = 'DESC' ;
}
// order by stuff
if ( empty ( $orderby )) {
$orderby = 'date ' . $order ;
} else {
2003-10-01 10:35:49 -04:00
// used to filter values
$allowed_keys = array ( 'author' , 'date' , 'category' , 'title' );
2003-04-01 09:12:34 -05:00
$orderby = urldecode ( $orderby );
$orderby = addslashes_gpc ( $orderby );
$orderby_array = explode ( ' ' , $orderby );
2003-10-01 10:38:10 -04:00
if ( ! in_array ( $orderby_array [ 0 ], $allowed_keys )) {
2003-10-01 10:35:49 -04:00
$orderby_array [ 0 ] = 'date' ;
}
2003-04-01 09:12:34 -05:00
$orderby = $orderby_array [ 0 ] . ' ' . $order ;
if ( count ( $orderby_array ) > 1 ) {
for ( $i = 1 ; $i < ( count ( $orderby_array )); $i = $i + 1 ) {
2003-10-01 10:35:49 -04:00
// Only allow certain values for safety
2003-10-01 10:38:10 -04:00
if ( in_array ( $orderby_array [ $i ], $allowed_keys )) {
2003-10-01 10:35:49 -04:00
$orderby .= ',post_' . $orderby_array [ $i ] . ' ' . $order ;
}
2003-04-01 09:12:34 -05:00
}
}
}
if (( ! $whichcat ) && ( ! $m ) && ( ! $p ) && ( ! $w ) && ( ! $s ) && empty ( $poststart ) && empty ( $postend )) {
if ( $what_to_show == 'posts' ) {
$limits = ' LIMIT ' . $posts_per_page ;
} elseif ( $what_to_show == 'days' ) {
$lastpostdate = get_lastpostdate ();
$lastpostdate = mysql2date ( 'Y-m-d 00:00:00' , $lastpostdate );
$lastpostdate = mysql2date ( 'U' , $lastpostdate );
$otherdate = date ( 'Y-m-d H:i:s' , ( $lastpostdate - (( $posts_per_page - 1 ) * 86400 )));
$where .= ' AND post_date > \'' . $otherdate . '\'' ;
}
}
2003-10-26 14:21:04 -05:00
if ( ! empty ( $postend ) && ( $postend > $poststart ) && ( ! $m ) && empty ( $monthnum ) && empty ( $year ) && empty ( $day ) && ( ! $w ) && ( ! $whichcat ) && ( ! $s ) && ( ! $p )) {
2003-04-01 09:12:34 -05:00
if ( $what_to_show == 'posts' || ( $what_to_show == 'paged' && ( ! $paged ))) {
$poststart = intval ( $poststart );
$postend = intval ( $postend );
2003-06-07 00:23:09 -04:00
$limposts = $postend - $poststart ;
$limits = ' LIMIT ' . $poststart . ',' . $limposts ;
2003-04-01 09:12:34 -05:00
} elseif ( $what_to_show == 'days' ) {
$poststart = intval ( $poststart );
$postend = intval ( $postend );
2003-06-07 00:23:09 -04:00
$limposts = $postend - $poststart ;
2003-04-01 09:12:34 -05:00
$lastpostdate = get_lastpostdate ();
$lastpostdate = mysql2date ( 'Y-m-d 00:00:00' , $lastpostdate );
$lastpostdate = mysql2date ( 'U' , $lastpostdate );
$startdate = date ( 'Y-m-d H:i:s' , ( $lastpostdate - (( $poststart - 1 ) * 86400 )));
$otherdate = date ( 'Y-m-d H:i:s' , ( $lastpostdate - (( $postend - 1 ) * 86400 )));
$where .= ' AND post_date > \'' . $otherdate . '\' AND post_date < \'' . $startdate . '\'' ;
}
} else {
if (( $what_to_show == 'paged' ) && ( ! $p ) && ( ! $more )) {
2003-11-03 17:11:42 -05:00
if ( $pagenow != 'wp-post.php' ) {
2003-04-01 09:12:34 -05:00
$pgstrt = '' ;
if ( $paged ) {
$pgstrt = ( intval ( $paged ) - 1 ) * $posts_per_page . ', ' ;
}
$limits = 'LIMIT ' . $pgstrt . $posts_per_page ;
} else {
if (( $m ) || ( $p ) || ( $w ) || ( $s ) || ( $whichcat )) {
$limits = '' ;
} else {
$pgstrt = '' ;
if ( $paged ) {
$pgstrt = ( intval ( $paged ) - 1 ) * $posts_per_page . ', ' ;
}
$limits = 'LIMIT ' . $pgstrt . $posts_per_page ;
}
}
}
2003-11-23 04:07:31 -05:00
elseif (( $m ) || ( $p ) || ( $w ) || ( $s ) || ( $whichcat ) || ( $author ) || $monthnum || $year || $day ) {
2003-04-01 09:12:34 -05:00
$limits = '' ;
}
}
if ( $p == 'all' ) {
$where = '' ;
}
$now = date ( 'Y-m-d H:i:s' ,( time () + ( $time_difference * 3600 )));
2003-11-03 17:11:42 -05:00
if ( $pagenow != 'wp-post.php' ) {
2003-04-01 09:12:34 -05:00
if (( empty ( $poststart )) || ( empty ( $postend )) || ! ( $postend > $poststart )) {
$where .= ' AND post_date <= \'' . $now . '\'' ;
}
2003-12-05 04:41:27 -05:00
2003-04-01 09:12:34 -05:00
$distinct = 'DISTINCT' ;
2003-12-05 04:41:27 -05:00
2003-04-01 09:12:34 -05:00
if ( $use_gzipcompression ) {
// gzipping the output of the script
gzip_compression ();
}
}
2003-06-07 13:21:08 -04:00
$where .= ' AND (post_status = "publish"' ;
2003-04-01 09:12:34 -05:00
2003-06-01 10:49:04 -04:00
// Get private posts
2003-11-29 19:55:19 -05:00
if ( isset ( $user_ID ) && ( '' != intval ( $user_ID )))
2003-12-04 20:44:42 -05:00
$where .= " OR post_author = $user_ID AND post_status != 'draft') " ;
2003-11-29 19:55:19 -05:00
else
$where .= ')' ;
2003-12-07 03:59:05 -05:00
$request = " SELECT $distinct * FROM $tableposts $join WHERE 1=1 " . $where . " ORDER BY post_ $orderby $limits " ;
2003-04-01 09:12:34 -05:00
2003-06-01 10:49:04 -04:00
2003-04-01 09:12:34 -05:00
if ( $preview ) {
$request = 'SELECT 1-1' ; // dummy mysql query for the preview
// little funky fix for IEwin, rawk on that code
$is_winIE = (( preg_match ( '/MSIE/' , $HTTP_USER_AGENT )) && ( preg_match ( '/Win/' , $HTTP_USER_AGENT )));
if (( $is_winIE ) && ( ! isset ( $IEWin_bookmarklet_fix ))) {
$preview_content = preg_replace ( '/\%u([0-9A-F]{4,4})/e' , " '&#'.base_convert(' \\ 1',16,10).';' " , $preview_content );
}
}
2003-10-26 01:25:26 -04:00
// error_log("$request");
// echo $request;
2003-05-29 10:04:30 -04:00
$posts = $wpdb -> get_results ( $request );
2003-12-04 20:44:42 -05:00
2003-10-26 01:25:26 -04:00
if ( 1 == count ( $posts )) {
2003-11-23 04:07:31 -05:00
if ( $p || $name ) {
2003-11-23 03:41:40 -05:00
$more = 1 ;
$c = 1 ;
$single = 1 ;
}
2003-10-27 18:00:39 -05:00
if ( $s ) { // If they were doing a search and got one result
header ( 'Location: ' . get_permalink ( $posts [ 0 ] -> ID ));
}
2003-10-26 01:25:26 -04:00
}
2003-04-01 09:12:34 -05:00
?>