b2evolution

Multilingual multiuser multiblog engine

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

Source for file _class_archivelist.php

Documentation is available at _class_archivelist.php

  1. <?php
  2. /**
  3.  * This file implements archive lists
  4.  *
  5.  * b2evolution - {@link http://b2evolution.net/}
  6.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  7.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  *
  9.  * @package evocore
  10.  */
  11. if!defined('DB_USER') ) die'Please, do not access this page directly.' );
  12.  
  13. /**
  14.  * Includes:
  15.  */
  16. require_once dirname(__FILE__).'/_class_dataobjectlist.php';
  17.  
  18. /**
  19.  * Archive List Class
  20.  *
  21.  * @package evocore
  22.  */
  23. class ArchiveList extends DataObjectList
  24. {
  25.     var $blog;
  26.     var $archive_mode;
  27.     var $arc_w_last;
  28.     
  29.     /**
  30.      * Constructor
  31.    *
  32.    * Note: Weekly archives use mySQL's week numbering and mySQL default if applicable.
  33.    * In mySQL < 4.0, WEEK() uses mode 0: Week starts on Sunday;
  34.    * Value range is 0 to 53; week 1 is the first week that starts in this year
  35.    *
  36.      * {@internal ArchiveList::ArchiveList(-)}}
  37.      *
  38.    * @param integer 
  39.    * @param string 
  40.    * @param array 
  41.    * @param mixed 
  42.    * @param mixed 
  43.    * @param integer 
  44.      */
  45.     function ArchiveList
  46.         $blog 1
  47.         $archive_mode 'monthly',
  48.         $show_statuses array(),                    
  49.         $timestamp_min '',                                    // Do not show posts before this timestamp
  50.         $timestamp_max 'now',                                // Do not show posts after this timestamp
  51.         $limit '' )
  52.     {
  53.         global $DB;
  54.         global $tableposts$tablepostcats$tablecategories;
  55.         global $Settings;
  56.         
  57.         $this->blog = $blog;
  58.         $this->archive_mode = $archive_mode;
  59.  
  60.         // CONSTRUCT THE WHERE CLAUSE:
  61.  
  62.         /*
  63.          * ----------------------------------------------------
  64.          *  Restrict to the statuses we want to show:
  65.          * ----------------------------------------------------
  66.          */
  67.         $where ' WHERE '.statuses_where_clause$show_statuses );
  68.         $where_link ' AND ';
  69.         
  70.  
  71.         // Restrict to timestamp limits:
  72.         if$timestamp_min == 'now' $timestamp_min time();
  73.         if!empty($timestamp_min) ) 
  74.         {    // Hide posts before
  75.             $date_min date('Y-m-d H:i:s'$timestamp_min ($Settings->get('time_difference'3600) );
  76.             $where .= $where_link.' post_issue_date >= \''.$date_min.'\'';
  77.             $where_link ' AND ';
  78.         }
  79.         if$timestamp_max == 'now' $timestamp_max time();
  80.         if!empty($timestamp_max) ) 
  81.         {    // Hide posts after
  82.             $date_max date('Y-m-d H:i:s'$timestamp_max ($Settings->get('time_difference'3600) );
  83.             $where .= $where_link.' post_issue_date <= \''.$date_max.'\'';
  84.             $where_link ' AND ';
  85.         }
  86.     
  87.         // Do we need to restrict categories:
  88.         if$blog 
  89.         {    // Blog #1 aggregates all
  90.             $where .= $where_link.' cat_blog_ID = '.$blog;
  91.             $where_link ' AND ';
  92.         }
  93.         
  94.         if!empty($limit) )
  95.         {
  96.             $limit ' LIMIT 0,'.$limit;
  97.         }
  98.  
  99.  
  100.         switch$archive_mode )
  101.         {
  102.             case 'monthly':
  103.                 // ------------------------------ MONTHLY ARCHIVES ------------------------------------
  104.                 $this->request 'SELECT YEAR(post_issue_date) AS year, MONTH(post_issue_date) AS month,
  105.                                                                     COUNT(DISTINCT postcat_post_ID) AS count
  106.                                                     FROM (T_posts INNER JOIN T_postcats ON ID = postcat_post_ID)
  107.                                                                 INNER JOIN T_categories ON postcat_cat_ID = cat_ID
  108.                                                     '.$where.'
  109.                                                     GROUP BY year, month
  110.                                                     ORDER BY year DESC, month DESC
  111.                                                     '.$limit;
  112.                 break;
  113.  
  114.             case 'daily':
  115.                 // ------------------------------- DAILY ARCHIVES -------------------------------------
  116.                 $this->request 'SELECT YEAR(post_issue_date) AS year, MONTH(post_issue_date) AS month,
  117.                                                                     DAYOFMONTH(post_issue_date) AS day,
  118.                                                                     COUNT(DISTINCT postcat_post_ID) AS count
  119.                                                     FROM (T_posts INNER JOIN T_postcats ON ID = postcat_post_ID)
  120.                                                                 INNER JOIN T_categories ON postcat_cat_ID = cat_ID
  121.                                                     '.$where.'
  122.                                                     GROUP BY year, month, day
  123.                                                     ORDER BY year DESC, month DESC, day DESC
  124.                                                     '.$limit;
  125.                 break;
  126.  
  127.             case 'weekly':
  128.                 // ------------------------------- WEEKLY ARCHIVES -------------------------------------
  129.                 $this->request 'SELECT YEAR(post_issue_date) AS year, WEEK(post_issue_date) AS week,
  130.                                                                     COUNT(DISTINCT postcat_post_ID) AS count
  131.                                                     FROM (T_posts INNER JOIN T_postcats ON ID = postcat_post_ID)
  132.                                                                 INNER JOIN T_categories ON postcat_cat_ID = cat_ID
  133.                                                     '.$where.'
  134.                                                     GROUP BY year, week
  135.                                                     ORDER BY year DESC, week DESC
  136.                                                     '.$limit;
  137.                 break;
  138.  
  139.             case 'postbypost':
  140.             default:
  141.                 // ----------------------------- POSY BY POST ARCHIVES --------------------------------
  142.                 $this->request 'SELECT DISTINCT ID, post_issue_date, post_title
  143.                                                     FROM (T_posts INNER JOIN T_postcats ON ID = postcat_post_ID)
  144.                                                                 INNER JOIN T_categories ON postcat_cat_ID = cat_ID
  145.                                                     '.$where.'
  146.                                                     ORDER BY post_issue_date DESC
  147.                                                     '.$limit;
  148.         }
  149.  
  150.         // echo $this->request.'<br/>';
  151.  
  152.         $this->result $DB->get_results$this->requestARRAY_A );;
  153.     
  154.         $this->result_num_rows $DB->num_rows;
  155.         // echo 'rows='.$this->result_num_rows.'<br/>';
  156.         
  157.         $this->arc_w_last = '';
  158.     }
  159.  
  160.     /**
  161.      * Getting next item in archive list
  162.      *
  163.      * {@internal ArchiveList->get_item(-)}}
  164.      */
  165.     function get_item$arc_year$arc_month$arc_dayofmonth$arc_w$arc_count$post_ID$post_title )
  166.     {
  167.         // echo 'getting next item<br />';
  168.  
  169.          if$this->current_idx >= $this->result_num_rows )
  170.         {    // No more entry
  171.             return false;
  172.         }
  173.  
  174.         $arc_row $this->result$this->current_idx++ ];
  175.  
  176.         switch$this->archive_mode )
  177.         {
  178.             case 'monthly':
  179.                 $arc_year  $arc_row['year'];
  180.                 $arc_month $arc_row['month'];
  181.                 $arc_count $arc_row['count'];
  182.                 return true;
  183.  
  184.             case 'daily':
  185.                 $arc_year  $arc_row['year'];
  186.                 $arc_month $arc_row['month'];
  187.                 $arc_dayofmonth $arc_row['day'];
  188.                 $arc_count $arc_row['count'];
  189.                 return true;
  190.  
  191.             case 'weekly':
  192.                 $arc_year  $arc_row['year'];
  193.                 $arc_w $arc_row['week'];
  194.                 $arc_count $arc_row['count'];
  195.                 return true;
  196.  
  197.             case 'postbypost':
  198.             default:
  199.                 $post_ID $arc_row['ID'];
  200.                 $post_title $arc_row['post_title'];
  201.                 return true;
  202.         }
  203.     }
  204. }
  205.  
  206. ?>

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