Source for file _class_blogstats.php
Documentation is available at _class_blogstats.php
* b2evolution - http://b2evolution.net/
* Copyright (c)2003-2005 by Francois PLANQUE - http://fplanque.net/
* Released under GNU GPL License - http://b2evolution.net/about/license.html
* Filename: /b2evocore/_class_blogstats.php
* Created by: Travis Swicegood <travis@domain51productions.com>
* This file contains the code for the blogstats class. The main purpose of this class
* is to create information necessary for statistical information about the blog without
* loading everything as the ItemList class does.
* The first use of this class is to generate a total number of blog entries. Searches
* can be limited to specific blogs and/or categories. This number would them be used to
* create random number within a range to display a random blog entry. Example: Blog
* that contains a list of quotes with a random quote being displayed each time a page
* 12/12/03 - Travis Swicegood: Created file.
* @deprecated functionality will be moved to ItemList
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
var $blog; // Blog # (1 = all blogs)
var $total_posts; // Number of total posts (loaded via $this->get_post_total())
$blog =
1, // What blog to display (def: all blogs)
$show_statuses =
array(), // What status to display?
// $p = '', // Specific post number to display
$m =
'', // YearMonth(Day) to display
$cat =
'', // Category(s): 1,2,3
$catsel =
array(), // Same as above except array
$author =
'', // List of authors to restrict to
$posts =
'', // # of posts to display on the page
$poststart =
'', // Start results at this position
$postend =
'', // End results at this position
$s =
'', // Search string
$sentence =
'', // Search for sentence or for words
$exact =
'', // Require exact match of title or contents
$init_what_to_show =
'', // Type of display (example: "posts")
$timestamp_min =
'', // Do not show posts before this timestamp
$timestamp_max =
'now' ) // Do not show posts after this timestamp
global $querycount; // Total number of queries
global $tableposts, $tablepostcats, $tablecategories; // ?
global $cache_categories; // ?
global $cat_array; // communication with recursive callback funcs
// First let's clear some variables
// WE ARE GOING TO CONSTRUCT THE "AND" CLOSE
// THIS IS GOING TO LAST FOR MANY MANY LINES...
// if a month is specified in the querystring, load that month
$where .=
' AND YEAR(post_issue_date)='.
substr($m,0,4);
$where .=
' AND MONTH(post_issue_date)='.
substr($m,4,2);
$where .=
' AND DAYOFMONTH(post_issue_date)='.
substr($m,6,2);
$where .=
' AND HOUR(post_issue_date)='.
substr($m,8,2);
$where .=
' AND MINUTE(post_issue_date)='.
substr($m,10,2);
$where .=
' AND SECOND(post_issue_date)='.
substr($m,12,2);
// If a week number is specified
if( !empty($w) &&
($w>=
0) )
$where .=
' AND WEEK(post_issue_date,1)='.
intval($w);
* ----------------------------------------------------
* ----------------------------------------------------
if ($exact) // We want exact match of title or contents
else // The words/sentence are/is to be included in in the title or the contents
if( ($sentence ==
'1') or ($sentence ==
'sentence') )
$search .=
'(post_title LIKE \''.
$n.
$s.
$n.
'\') OR (post_content LIKE \''.
$n.
$s.
$n.
'\')';
// puts spaces instead of commas
for ( $i =
0; $i <
count($s_array); $i++
)
$search .=
' '.
$join.
' ( (post_title LIKE \''.
$n.
$s_array[$i].
$n.
'\') OR (post_content LIKE \''.
$n.
$s_array[$i].
$n.
'\') ) ';
* ----------------------------------------------------
* ----------------------------------------------------
$cat_array =
array(); // this is a global var
// Check for cat string (which will be handled recursively)
if ( ! ((empty($cat)) ||
($cat ==
'all') ||
($cat ==
'0')) )
{ // specified a category string:
{ // We want to exclude cats
$req_cat_array =
explode(' ',$cats[1]);
{ // We want to include cats
$req_cat_array =
explode(' ',$cat);
// Getting required sub-categories:
// and add everything to cat array
// ----------------- START RECURSIVE CAT LIST ----------------
cat_query(); // make sure the caches are loaded
foreach( $req_cat_array as $cat_ID )
{ // run recursively through the cats
settype( $cat_ID, 'integer' ); // make sure
cat_children( $cache_categories, ($blog==
1)?
0:
$blog, $cat_ID, 'cat_req_dummy', 'cat_req',
'cat_req_dummy', 'cat_req_dummy', 1 );
// ----------------- END RECURSIVE CAT LIST ----------------
// Add explicit selections:
// echo "Explicit selections!<br />";
$whichcat .=
' AND postcat_cat_ID '.
$eq.
' ('.
implode(",", $cat_array).
') ';
* ----------------------------------------------------
* ----------------------------------------------------
if((empty($author)) ||
($author ==
'all'))
$author_array =
explode(' ', $author);
$whichauthor .=
' AND post_author '.
$eq.
' '.
$author_array[0];
for ($i =
1; $i <
(count($author_array)); $i =
$i +
1) {
$whichauthor .=
' '.
$andor.
' post_author '.
$eq.
' '.
$author_array[$i];
$where .=
$search.
$whichcat.
$whichauthor;
* ----------------------------------------------------
* ----------------------------------------------------
// fp removed && (!$m) && (!$w) && (!$whichcat) && (!$s)
// fp added: when in backoffice: always page
// echo 'POSTSTART-POSTEND';
if( $postend <
$poststart )
$postend =
$poststart +
$Settings->get('posts_per_page') -
1;
if ($Settings->get('what_to_show') ==
'posts' ||
$Settings->get('what_to_show') ==
'paged')
$posts =
$postend -
$poststart +
1;
$limits =
' LIMIT '.
($poststart-
1).
','.
$posts;
elseif ($Settings->get('what_to_show') ==
'days')
$posts =
$postend -
$poststart +
1;
$lastpostdate =
mysql2date('Y-m-d 00:00:00',$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_issue_date > \''.
$otherdate.
'\' AND post_issue_date < \''.
$startdate.
'\'';
elseif( ($m) ||
($p) ) // fp rem || ($w) || ($s) || ($whichcat) || ($author)
{ // (no restriction if we request a month... some permalinks may point to the archive!)
// echo 'ARCHIVE - no limits';
elseif ($Settings->get('what_to_show') ==
'posts')
$limits =
' LIMIT ' .
$Settings->get('posts_per_page');
elseif( $Settings->get('what_to_show') ==
'paged' )
$pgstrt =
(intval($paged) -
1) *
$Settings->get('posts_per_page') .
', ';
$limits =
'LIMIT '.
$pgstrt.
$Settings->get('posts_per_page');
elseif ($Settings->get('what_to_show') ==
'days')
$lastpostdate =
mysql2date('Y-m-d 00:00:00',$lastpostdate);
$otherdate =
date('Y-m-d H:i:s', ($lastpostdate -
(($Settings->get('posts_per_page')-
1) *
86400)));
$where .=
' AND post_issue_date > \''.
$otherdate.
'\'';
* ----------------------------------------------------
* Restrict to the statuses we want to show:
* ----------------------------------------------------
* ----------------------------------------------------
* ----------------------------------------------------
if( $timestamp_min ==
'now' )
if( !empty($timestamp_min) )
$date_min =
date('Y-m-d H:i:s', $timestamp_min +
($Settings->get('time_difference') *
3600) );
$where .=
' AND post_issue_date >= \''.
$date_min.
'\'';
if( $timestamp_max ==
'now' )
if( !empty($timestamp_max) )
$date_max =
date('Y-m-d H:i:s', $timestamp_max +
($Settings->get('time_difference') *
3600) );
$where .=
' AND post_issue_date <= \''.
$date_max.
'\'';
$this->request =
"SELECT COUNT( DISTINCT post_id ) as total_posts ";
INNER JOIN $tablepostcats ON ID = postcat_post_ID)
INNER JOIN $tablecategories ON postcat_cat_ID = cat_ID ";
{ // Special case: we aggregate all cats from all blogs
$this->request .=
"WHERE cat_blog_ID = $blog ";
$this->request =
'SELECT 0 AS ID'; // dummy mysql query for the preview
$row =
$DB->get_row( $this->request );