b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _class_blogstats.php

Documentation is available at _class_blogstats.php

  1. <?php
  2. /**
  3.  * b2evolution - http://b2evolution.net/
  4.  *
  5.  * Copyright (c)2003-2005 by Francois PLANQUE - http://fplanque.net/
  6.  * Released under GNU GPL License - http://b2evolution.net/about/license.html
  7.  *
  8.  *    Filename:    /b2evocore/_class_blogstats.php
  9.  *    Created on:    12/12/03
  10.  *    Created by:    Travis Swicegood <travis@domain51productions.com>
  11.  *    File Description
  12.  *        This file contains the code for the blogstats class.  The main purpose of this class
  13.  *        is to create information necessary for statistical information about the blog without
  14.  *        loading everything as the ItemList class does.
  15.  *
  16.  *    Practical Use
  17.  *        The first use of this class is to generate a total number of blog entries.  Searches
  18.  *        can be limited to specific blogs and/or categories.  This number would them be used to
  19.  *        create random number within a range to display a random blog entry.  Example: Blog
  20.  *        that contains a list of quotes with a random quote being displayed each time a page
  21.  *        is loaded.
  22.  *
  23.  *    Last Modified
  24.  *        12/12/03 - Travis Swicegood: Created file.
  25.  *
  26.  * @deprecated functionality will be moved to ItemList
  27.  * @package evocore
  28.  */
  29. if!defined('DB_USER') ) die'Please, do not access this page directly.' );
  30.  
  31. /**
  32.  * @deprecated deprecated
  33.  * @package evocore
  34.  */
  35. class BlogStats{
  36.     var $blog;                // Blog # (1 = all blogs)
  37.     var $request;            // SQL query string
  38.     var $total_posts;        // Number of total posts (loaded via $this->get_post_total())
  39.  
  40.     function BlogStats(
  41.         $blog 1,                             // What blog to display (def: all blogs)
  42.         $show_statuses array(),            // What status to display?
  43. //        $p = '',                            // Specific post number to display
  44.         $m '',                            // YearMonth(Day) to display
  45.         $w = -1,                            // Week number
  46.         $cat '',                            // Category(s): 1,2,3
  47.         $catsel array(),                    // Same as above except array
  48.         $author '',                        // List of authors to restrict to
  49.         $posts '',                         // # of posts to display on the page
  50.         $poststart '',                    // Start results at this position
  51.         $postend '',                        // End results at this position
  52.         $s '',                            // Search string
  53.         $sentence '',                        // Search for sentence or for words
  54.         $exact '',                        // Require exact match of title or contents
  55.         $init_what_to_show '',            // Type of display (example: "posts")
  56.         $timestamp_min '',                // Do not show posts before this timestamp
  57.         $timestamp_max 'now'  )            // Do not show posts after this timestamp
  58.     {
  59.     //////
  60.     //    Handle global calls
  61.         global $querycount;                                        // Total number of queries
  62.         global $tableposts$tablepostcats$tablecategories;    // ?
  63.         global $cache_categories;                // ?
  64.         global $cat_array;                                         // communication with recursive callback funcs
  65.         global $DB;
  66.         global $Settings;
  67.         
  68.     //////
  69.     //    Which blog is used?
  70.         $this->blog = $blog;
  71.  
  72.     ////////
  73.     // First let's clear some variables
  74.         $whichcat '';
  75.         $whichauthor '';
  76.         $result '';
  77.         $where '';
  78.         $limits '';
  79.         $distinct '';
  80.  
  81.         // WE ARE GOING TO CONSTRUCT THE "AND" CLOSE
  82.         // THIS IS GOING TO LAST FOR MANY MANY LINES...
  83.  
  84.         // if a month is specified in the querystring, load that month
  85.         if ($m != '')
  86.         {
  87.             $m ''.intval($m);
  88.             $where .= ' AND YEAR(post_issue_date)='substr($m,0,4);
  89.             if (strlen($m)>5)
  90.                 $where .= ' AND MONTH(post_issue_date)='substr($m,4,2);
  91.             if (strlen($m)>7)
  92.                 $where .= ' AND DAYOFMONTH(post_issue_date)='substr($m,6,2);
  93.             if (strlen($m)>9)
  94.                 $where .= ' AND HOUR(post_issue_date)='substr($m,8,2);
  95.             if (strlen($m)>11)
  96.                 $where .= ' AND MINUTE(post_issue_date)='substr($m,10,2);
  97.             if (strlen($m)>13)
  98.                 $where .= ' AND SECOND(post_issue_date)='substr($m,12,2);
  99.         }
  100.  
  101.         // If a week number is specified
  102.         if!empty($w&& ($w>=0) )
  103.         {
  104.             $where .= ' AND WEEK(post_issue_date,1)='.intval($w);
  105.         }
  106.  
  107.         /*
  108.          * ----------------------------------------------------
  109.          * Search stuff:
  110.          * ----------------------------------------------------
  111.          */
  112.         if(!empty($s))
  113.         {
  114.             $search ' AND (';
  115.             if ($exact)    // We want exact match of title or contents
  116.                 $n '';
  117.             else // The words/sentence are/is to be included in in the title or the contents
  118.                 $n '%';
  119.             if( ($sentence == '1'or ($sentence == 'sentence') )
  120.             // Sentence search
  121.                 $s trim($s);
  122.                 $search .= '(post_title LIKE \''.$n.$s.$n.'\') OR (post_content LIKE \''.$n.$s.$n.'\')';
  123.             }
  124.             else
  125.             {    // Word search
  126.                 ifstrtoupper$sentence == 'OR' )
  127.                     $swords 'OR';
  128.                 else
  129.                     $swords 'AND';
  130.  
  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.                 $s_array explode(' ',$s);
  137.                 $join '';
  138.                 for $i 0$i count($s_array)$i++)
  139.                 {
  140.                     $search .= ' '.$join.' ( (post_title LIKE \''.$n.$s_array[$i].$n.'\') OR (post_content LIKE \''.$n.$s_array[$i].$n.'\') ) ';
  141.                     $join $swords;
  142.                 }
  143.             }
  144.  
  145.             $search .= ')';
  146.  
  147.             //echo $search;
  148.         }
  149.         else
  150.         {
  151.             $search '';
  152.         }
  153.  
  154.         /*
  155.          * ----------------------------------------------------
  156.          * Category stuff:
  157.          * ----------------------------------------------------
  158.          */
  159.         $eq 'IN'// default
  160.  
  161.         $cat_array array();        // this is a global var
  162.  
  163.         // Check for cat string (which will be handled recursively)
  164.         if ((empty($cat)) || ($cat == 'all'|| ($cat == '0')) )
  165.         {    // specified a category string:
  166.             $cat str_replace(','' '$cat);
  167.             ifstrstr($cat,'-') )
  168.             {    // We want to exclude cats
  169.                 $eq 'NOT IN';
  170.                 $cats explode('-',$cat);
  171.                 $req_cat_array explode(' ',$cats[1]);
  172.             }
  173.             else
  174.             {    // We want to include cats
  175.                 $req_cat_array explode(' ',$cat);
  176.             }
  177.  
  178.             // Getting required sub-categories:
  179.             // and add everything to cat array
  180.             // ----------------- START RECURSIVE CAT LIST ----------------
  181.             cat_query();    // make sure the caches are loaded
  182.             foreach$req_cat_array as $cat_ID )
  183.             // run recursively through the cats
  184.                 settype$cat_ID'integer' )// make sure
  185.                 ifin_array$cat_ID$cat_array ) )
  186.                 {    // Not already in list
  187.                     $cat_array[$cat_ID;
  188.                     cat_children$cache_categories($blog==1)?0:$blog$cat_ID'cat_req_dummy''cat_req',
  189.                                                 'cat_req_dummy''cat_req_dummy');
  190.                 }
  191.             }
  192.             // ----------------- END RECURSIVE CAT LIST ----------------
  193.         }
  194.  
  195.         // Add explicit selections:
  196.         ifempty$catsel ))
  197.         {
  198.             // echo "Explicit selections!<br />";
  199.             $cat_array array_merge$cat_array$catsel );
  200.             array_unique$cat_array );
  201.         }
  202.  
  203.         ifempty($cat_array) )
  204.         {
  205.             $whichcat='';
  206.         }
  207.         else
  208.         {
  209.             $whichcat .= ' AND postcat_cat_ID '.$eq.' ('.implode(","$cat_array).') ';
  210.             // echo $whichcat;
  211.         }
  212.  
  213.  
  214.  
  215.         /*
  216.          * ----------------------------------------------------
  217.          * Author stuff:
  218.          * ----------------------------------------------------
  219.          */
  220.         if((empty($author)) || ($author == 'all'))
  221.         {
  222.             $whichauthor='';
  223.         }
  224.         elseif (intval($author))
  225.         {
  226.             $author intval($author);
  227.             if (stristr($author'-'))
  228.             {
  229.                 $eq '!=';
  230.                 $andor 'AND';
  231.                 $author explode('-'$author);
  232.                 $author $author[1];
  233.             else {
  234.                 $eq '=';
  235.                 $andor 'OR';
  236.             }
  237.             $author_array explode(' '$author);
  238.             $whichauthor .= ' AND post_author '.$eq.' '.$author_array[0];
  239.             for ($i 1$i (count($author_array))$i $i 1{
  240.                 $whichauthor .= ' '.$andor.' post_author '.$eq.' '.$author_array[$i];
  241.             }
  242.         }
  243.  
  244.         $where .= $search.$whichcat.$whichauthor;
  245.  
  246.  
  247.         /*
  248.          * ----------------------------------------------------
  249.          * Limits:
  250.          * ----------------------------------------------------
  251.          */
  252.         if!empty($poststart) )
  253.         // fp removed && (!$m) && (!$w) && (!$whichcat) && (!$s)
  254.         // fp added: when in backoffice: always page
  255.         {
  256.             // echo 'POSTSTART-POSTEND';
  257.             if$postend $poststart )
  258.             {
  259.                 $postend $poststart $Settings->get('posts_per_page'1;
  260.             }
  261.  
  262.             if ($Settings->get('what_to_show'== 'posts' || $Settings->get('what_to_show'== 'paged')
  263.             {
  264.                 $posts $postend $poststart 1;
  265.                 $limits ' LIMIT '.($poststart-1).','.$posts;
  266.             }
  267.             elseif ($Settings->get('what_to_show'== 'days')
  268.             {
  269.                 $posts $postend $poststart 1;
  270.                 $lastpostdate get_lastpostdate$blog$show_statuses );
  271.                 $lastpostdate mysql2date('Y-m-d 00:00:00',$lastpostdate);
  272.                 $lastpostdate mysql2date('U',$lastpostdate);
  273.                 $startdate date('Y-m-d H:i:s'($lastpostdate (($poststart -186400)));
  274.                 $otherdate date('Y-m-d H:i:s'($lastpostdate (($postend -186400)));
  275.                 $where .= ' AND post_issue_date > \''.$otherdate.'\' AND post_issue_date < \''.$startdate.'\'';
  276.             }
  277.         }
  278.         elseif( ($m|| ($p) ) // fp rem || ($w) || ($s) || ($whichcat) || ($author)
  279.         {    // (no restriction if we request a month... some permalinks may point to the archive!)
  280.             // echo 'ARCHIVE - no limits';
  281.             $limits '';
  282.         }
  283.         elseif ($Settings->get('what_to_show'== 'posts')
  284.         {
  285.             // echo 'LIMIT POSTS';
  286.             $limits ' LIMIT ' $Settings->get('posts_per_page');
  287.         }
  288.         elseif$Settings->get('what_to_show'== 'paged' )
  289.         {
  290.             // echo 'PAGED';
  291.             $pgstrt '';
  292.             if ($paged{
  293.                 $pgstrt (intval($paged-1$Settings->get('posts_per_page'', ';
  294.             }
  295.             $limits 'LIMIT '.$pgstrt.$Settings->get('posts_per_page');
  296.         }
  297.         elseif ($Settings->get('what_to_show'== 'days')
  298.         {
  299.             // echo 'LIMIT DAYS';
  300.             $lastpostdate get_lastpostdate$blog$show_statuses );
  301.             $lastpostdate mysql2date('Y-m-d 00:00:00',$lastpostdate);
  302.             $lastpostdate mysql2date('U',$lastpostdate);
  303.             $otherdate date('Y-m-d H:i:s'($lastpostdate (($Settings->get('posts_per_page')-186400)));
  304.             $where .= ' AND post_issue_date > \''.$otherdate.'\'';
  305.         }
  306.  
  307.  
  308.         /*
  309.          * ----------------------------------------------------
  310.          *  Restrict to the statuses we want to show:
  311.          * ----------------------------------------------------
  312.          */
  313.         $where .= ' AND '.statuses_where_clause$show_statuses );
  314.  
  315.         /*
  316.          * ----------------------------------------------------
  317.          * Time limits:
  318.          * ----------------------------------------------------
  319.          */
  320.         if$timestamp_min == 'now' )
  321.         {
  322.             // echo 'hide past';
  323.             $timestamp_min time();
  324.         }
  325.         if!empty($timestamp_min) )
  326.         {    // Hide posts before
  327.             // echo 'before';
  328.             $date_min date('Y-m-d H:i:s'$timestamp_min ($Settings->get('time_difference'3600) );
  329.             $where .= ' AND post_issue_date >= \''.$date_min.'\'';
  330.         }
  331.  
  332.         if$timestamp_max == 'now' )
  333.         {
  334.             // echo 'hide future';
  335.             $timestamp_max time();
  336.         }
  337.         if!empty($timestamp_max) )
  338.         {    // Hide posts after
  339.             // echo 'after';
  340.             $date_max date('Y-m-d H:i:s'$timestamp_max ($Settings->get('time_difference'3600) );
  341.             $where .= ' AND post_issue_date <= \''.$date_max.'\'';
  342.         }
  343.  
  344.  
  345.         $this->request = "SELECT COUNT( DISTINCT post_id ) as total_posts ";
  346.  
  347.         $this->request .= "FROM
  348.                 ($tableposts
  349.                     INNER JOIN $tablepostcats ON ID = postcat_post_ID)
  350.                     INNER JOIN $tablecategories ON postcat_cat_ID = cat_ID ";
  351.  
  352.         if$blog == )
  353.         {    // Special case: we aggregate all cats from all blogs
  354.             $this->request .= "WHERE 1 ";
  355.         }
  356.         else
  357.         {
  358.             $this->request .= "WHERE cat_blog_ID = $blog ";
  359.         }
  360.  
  361.  
  362.         if ($preview)
  363.         {
  364.             $this->request = 'SELECT 0 AS ID'// dummy mysql query for the preview
  365.         }
  366.  
  367.         //echo $this->request;
  368.         $querycount++;
  369.         $row $DB->get_row$this->request );
  370.     }
  371.  
  372. }
  373. ?>

Documentation generated on Tue, 20 May 2008 01:52:32 +0200 by phpDocumentor 1.4.2