b2evolution

Multilingual multiuser multiblog engine

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

Source for file _class_itemlist.php

Documentation is available at _class_itemlist.php

  1. <?php
  2. /**
  3.  * This file implements item/post/article 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_oncedirname(__FILE__)'/_class_dataobjectlist.php' );
  17. require_oncedirname(__FILE__)'/_class_item.php' );
  18.  
  19. function cat_req$parent_cat_ID$level )
  20. {
  21.     global $cat_array;
  22.     // echo "[$parent_cat_ID] ";
  23.     ifin_array$parent_cat_ID$cat_array ) )
  24.     // Not already visited
  25.         $cat_array[$parent_cat_ID;
  26.     }
  27.     else
  28.     {
  29.         // echo "STOP! ALREADY VISITED THIS ONE!";
  30.         return -1;        // STOP going through that branch
  31.     }
  32. }
  33.  
  34. function cat_req_dummy({}
  35.  
  36. /**
  37.  * Item List Class
  38.  *
  39.  * @package evocore
  40.  */
  41. class ItemList extends DataObjectList
  42. {
  43.     var $preview;
  44.     var $blog;
  45.     var $p;
  46.     var $what_to_show;
  47.     var $result_num_rows;            // Number of rows in result set
  48.     var $postIDlist;
  49.     var $postIDarray;
  50.  
  51.     var $total_num_posts;            // Total number of posts
  52.     var $max_paged;                        // Max page number for paged display
  53.  
  54.     var $group_by_cat;
  55.  
  56.     var $limitdate_start;     // UNIX timestamp
  57.     var $limitdate_end;       // UNIX timestamp
  58.  
  59.     // Used in looping
  60.     var $row_num;                            // Current row
  61.     var $row;                                    // Current row
  62.     var $main_cat;                        // Current main category
  63.     var $previous_main_cat;        // Previous one
  64.     /**
  65.      * @access private
  66.      */
  67.     var $last_Item;
  68.  
  69.     /**
  70.      * @access private
  71.      */
  72.     var $last_displayed_date '';
  73.  
  74.     /**
  75.      * Constructor
  76.      *
  77.      * {@internal ItemList::ItemList(-)}}
  78.      *
  79.      * @param integer Blog ID
  80.      * @param array show_statuses
  81.      * @param mixed Specific post number to display
  82.      * @param mixed YearMonth(Day) to display
  83.      * @param mixed Week number. Note: uses mySQL's week numbering and mySQL default if applicable.
  84.    *  In mySQL < 4.0, WEEK() uses mode 0: Week starts on Sunday;
  85.    *  Value range is 0 to 53; week 1 is the first week that starts in this year
  86.      * @param mixed List of cats to restrict to
  87.      * @param array Array of cats to restrict to
  88.      * @param mixed List of authors to restrict to
  89.      * @param string sort order can be either ASC or DESC
  90.      * @param string space separated list of fields to order by. Possible list elements are:
  91.      *                author issue_date mod_date status locale content title urltitle url ctageory
  92.      *                wordcount comments
  93.      * @param mixed # of posts to display on the page
  94.      * @param mixed List page number in paged display
  95.      * @param mixed Start results at this position
  96.      * @param mixed End results at this position
  97.      * @param string Search string
  98.      * @param mixed Search for sentence or for words
  99.      * @param mixed Require exact match of title or contents
  100.      * @param boolean Is this preview
  101.      * @param mixed 
  102.      * @param mixed 
  103.      * @param mixed Do not show posts before this timestamp, can be 'now'
  104.      * @param mixed Do not show posts after this timestamp, can be 'now'
  105.      * @param string urltitle of post to display
  106.      */
  107.     function ItemList(
  108.         $blog 1,
  109.         $show_statuses array(),
  110.         $p '',                                                            // Specific post number to display
  111.         $m '',                                                            // YearMonth(Day) to display
  112.         $w = -1,                                                            // Week number
  113.         $cat '',                                                        // List of cats to restrict to
  114.         $catsel array(),                                        // Array of cats to restrict to
  115.         $author '',                                                    // List of authors to restrict to
  116.         $order '',                                                    // ASC or DESC
  117.         $orderby '',                                                // list of fields to order by
  118.         $posts '',                                                    // # of posts to display on the page
  119.         $paged '',                                                    // List page number in paged display
  120.         $poststart '',                                            // Start results at this position
  121.         $postend '',                                                // End results at this position
  122.         $s '',                                                            // Search string
  123.         $sentence '',                                                // Search for sentence or for words
  124.         $exact '',                                                    // Require exact match of title or contents
  125.         $preview 0,                                                    // Is this preview
  126.         $default_posts_per_page '',
  127.         $init_what_to_show '',
  128.         $timestamp_min '',                                    // Do not show posts before this timestamp
  129.         $timestamp_max 'now',                                // Do not show posts after this timestamp
  130.         $title '' )                                                    // urltitle of post to display
  131.     {
  132.         global $DB;
  133.         global $tableposts$tablepostcats$tablecategories;
  134.         global $cache_categories;
  135.         global $cat_array// communication with recursive callback funcs
  136.         global $Settings;
  137.  
  138.         // Call parent constructor:
  139.         parent::DataObjectList$tableposts'post_''ID' );
  140.  
  141.         $this->preview = $preview;
  142.         $this->blog = $blog;
  143.         $this->p = $p;
  144.  
  145.         if!empty($posts) )
  146.             $posts_per_page $posts;
  147.         elseif!empty($default_posts_per_page) )
  148.             $posts_per_page $default_posts_per_page;
  149.         else
  150.             $posts_per_page $Settings->get('posts_per_page');
  151.         $this->posts_per_page $posts_per_page;
  152.  
  153.         $what_to_show (empty($init_what_to_show)) $Settings->get('what_to_show'$init_what_to_show;
  154.         $this->what_to_show = $what_to_show;
  155.  
  156.         // First let's clear some variables
  157.         $whichcat '';
  158.         $whichauthor '';
  159.         $result '';
  160.         $where '';
  161.         $limits '';
  162.         $distinct '';
  163.  
  164.         // WE ARE GOING TO CONSTRUCT THE "AND" CLOSE
  165.         // THIS IS GOING TO LAST FOR MANY MANY LINES...
  166.  
  167.         // if a month is specified in the querystring, load that month
  168.         if$m != '' )
  169.         {
  170.             $m '' intval($m);
  171.             $where .= ' AND YEAR(post_issue_date)=' substr($m,0,4);
  172.             ifstrlen($m)
  173.                 $where .= ' AND MONTH(post_issue_date)=' substr($m,4,2);
  174.             ifstrlen($m)
  175.                 $where .= ' AND DAYOFMONTH(post_issue_date)=' substr($m,6,2);
  176.             ifstrlen($m)
  177.                 $where .= ' AND HOUR(post_issue_date)=' substr($m,8,2);
  178.             ifstrlen($m11 )
  179.                 $where .= ' AND MINUTE(post_issue_date)=' substr($m,10,2);
  180.             ifstrlen($m13 )
  181.                 $where .= ' AND SECOND(post_issue_date)=' substr($m,12,2);
  182.         }
  183.  
  184.         // If a week number is specified
  185.         if!empty($w&& ($w>=0) ) // Note: week # can be 0
  186.         {
  187.             $where .= ' AND WEEK(post_issue_date)='.intval($w);
  188.         }
  189.  
  190.         // if a post number is specified, load that post
  191.         if( ($p != ''&& ($p != 'all') )
  192.         {
  193.             $p intval($p);
  194.             $where .= ' AND ID = '$p;
  195.         }
  196.  
  197.         // if a post urltitle is specified, load that post
  198.         if!empty$title ) )
  199.         {
  200.             $where .= ' AND post_urltitle = '.$DB->quote($title);
  201.         }
  202.  
  203.         /*
  204.          * ----------------------------------------------------
  205.          * Search stuff:
  206.          * ----------------------------------------------------
  207.          */
  208.         if!empty($s) )
  209.         {
  210.             $search ' AND (';
  211.             if$exact // We want exact match of title or contents
  212.                 $n '';
  213.             else // The words/sentence are/is to be included in in the title or the contents
  214.                 $n '%';
  215.             if( ($sentence == '1'or ($sentence == 'sentence') )
  216.             // Sentence search
  217.                 $s $DB->escape(trim($s));
  218.                 $search .= '(post_title LIKE \''$n$s$n'\') OR (post_content LIKE \''$n$s$n.'\')';
  219.             }
  220.             else
  221.             // Word search
  222.                 ifstrtoupper$sentence == 'OR' )
  223.                     $swords 'OR';
  224.                 else
  225.                     $swords 'AND';
  226.  
  227.                 // puts spaces instead of commas
  228.                 $s preg_replace('/, +/'''$s);
  229.                 $s str_replace(','' '$s);
  230.                 $s str_replace('"'' '$s);
  231.                 $s trim($s);
  232.                 $s_array explode(' ',$s);
  233.                 $join '';
  234.                 for $i 0$i count($s_array)$i++)
  235.                 {
  236.                     $search .= ' '$join' ( (post_title LIKE \''$n$DB->escape($s_array[$i])$n'\') OR (post_content LIKE \''$n$DB->escape($s_array[$i])$n.'\') ) ';
  237.                     $join $swords;
  238.                 }
  239.             }
  240.  
  241.             $search .= ')';
  242.  
  243.             //echo $search;
  244.         }
  245.         else
  246.         {
  247.             $search '';
  248.         }
  249.  
  250.         /*
  251.          * ----------------------------------------------------
  252.          * Category stuff:
  253.          * ----------------------------------------------------
  254.          */
  255.         $eq 'IN'// default
  256.  
  257.         $cat_array array();        // this is a global var
  258.  
  259.         // Check for cat string (which will be handled recursively)
  260.         if((empty($cat)) || ($cat == 'all'|| ($cat == '0')) )
  261.         // specified a category string:
  262.             $cat str_replace(','' '$cat);
  263.             ifstrstr($cat'-') )
  264.             // We want to exclude cats
  265.                 $eq 'NOT IN';
  266.                 $cats explode('-'$cat);
  267.                 $req_cat_array explode(' '$cats[1]);
  268.             }
  269.             else
  270.             // We want to include cats
  271.                 $req_cat_array explode(' '$cat);
  272.             }
  273.  
  274.             // Getting required sub-categories:
  275.             // and add everything to cat array
  276.             // ----------------- START RECURSIVE CAT LIST ----------------
  277.             cat_query();    // make sure the caches are loaded
  278.             foreach$req_cat_array as $cat_ID )
  279.             // run recursively through the cats
  280.                 settype$cat_ID'integer' )// make sure
  281.                 ifin_array$cat_ID$cat_array ) )
  282.                 // Not already in list
  283.                     $cat_array[$cat_ID;
  284.                     cat_children$cache_categories($blog==1)?0:$blog$cat_ID'cat_req_dummy''cat_req',
  285.                                                 'cat_req_dummy''cat_req_dummy');
  286.                 }
  287.             }
  288.             // ----------------- END RECURSIVE CAT LIST ----------------
  289.         }
  290.  
  291.         // Add explicit selections:
  292.         ifempty$catsel ))
  293.         {
  294.             // echo "Explicit selections!<br />";
  295.             $cat_array array_merge$cat_array$catsel );
  296.             array_unique$cat_array );
  297.         }
  298.  
  299.         ifempty($cat_array) )
  300.         {
  301.             $whichcat='';
  302.         }
  303.         else
  304.         {
  305.             $whichcat .= ' AND postcat_cat_ID '$eq.' ('.implode(","$cat_array)') ';
  306.             // echo $whichcat;
  307.         }
  308.  
  309.         /*
  310.          * ----------------------------------------------------
  311.          * Author stuff:
  312.          * ----------------------------------------------------
  313.          */
  314.         if((empty($author)) || ($author == 'all'))
  315.         {
  316.             $whichauthor='';
  317.         }
  318.         elseif (intval($author))
  319.         {
  320.             $author intval($author);
  321.             if (stristr($author'-'))
  322.             {
  323.                 $eq '!=';
  324.                 $andor 'AND';
  325.                 $author explode('-'$author);
  326.                 $author $author[1];
  327.             else {
  328.                 $eq '=';
  329.                 $andor 'OR';
  330.             }
  331.             $author_array explode(' '$author);
  332.             $whichauthor .= ' AND post_author '$eq.' '$author_array[0];
  333.             for ($i 1$i (count($author_array))$i $i 1{
  334.                 $whichauthor .= ' '$andor.' post_author '$eq.' '$author_array[$i];
  335.             }
  336.         }
  337.  
  338.         $where .= $search$whichcat $whichauthor;
  339.  
  340.  
  341.         /*
  342.          * ----------------------------------------------------
  343.          * order by stuff
  344.          * ----------------------------------------------------
  345.          */
  346.         if( (!empty($order)) && ((strtoupper($order!= 'ASC'&& (strtoupper($order!= 'DESC')))
  347.         {
  348.             $order='DESC';
  349.         }
  350.  
  351.         if(empty($orderby))
  352.         {
  353.             $orderby 'issue_date '$order;
  354.         }
  355.         else
  356.         {
  357.             $orderby_array explode(' ',$orderby);
  358.             $orderby $orderby_array[0]' '$order;
  359.             if (count($orderby_array)>1)
  360.             {
  361.                 for($i 1$i (count($orderby_array))$i++)
  362.                 {
  363.                     $orderby .= ', post_'$orderby_array[$i]' '$order;
  364.                 }
  365.             }
  366.         }
  367.  
  368.  
  369.         /*
  370.          * ----------------------------------------------------
  371.          * Limits:
  372.          * ----------------------------------------------------
  373.          */
  374.         if!empty($poststart) )
  375.         // When in backoffice: always paged
  376.             // echo 'POSTSTART-POSTEND ';
  377.             if$postend $poststart )
  378.             {
  379.                 $postend $poststart $posts_per_page 1;
  380.             }
  381.             if ($what_to_show == 'posts' || $what_to_show == 'paged')
  382.             {
  383.                 $posts $postend $poststart 1;
  384.                 $limits ' LIMIT '($poststart-1)','$posts;
  385.             }
  386.             elseif ($what_to_show == 'days')
  387.             {
  388.                 $posts $postend $poststart 1;
  389.                 // echo 'days=',$posts;
  390.                 $lastpostdate get_lastpostdate$blog$show_statuses$cat$catsel,    $timestamp_min$timestamp_max );
  391.                 $lastpostdate mysql2date('Y-m-d 23:59:59',$lastpostdate);
  392.                 // echo $lastpostdate;
  393.                 $lastpostdate mysql2date('U',$lastpostdate);
  394.                 $this->limitdate_end = $lastpostdate (($poststart -186400);
  395.                 $this->limitdate_start = $lastpostdate+(($postend86400);
  396.                 $where .= ' AND post_issue_date >= \''date'Y-m-d H:i:s'$this->limitdate_start 
  397.                                     .'\' AND post_issue_date <= \''date('Y-m-d H:i:s'$this->limitdate_end'\'';
  398.                 
  399.             }
  400.         }
  401.         elseif!empty($m) ) 
  402.         // no restriction if we request a month... some permalinks may point to the archive!
  403.             // echo 'ARCHIVE - no limits';
  404.             $limits '';
  405.         }
  406.         elseif ($what_to_show == 'posts')
  407.         {
  408.             // echo 'LIMIT POSTS!';
  409.             $limits ' LIMIT '$posts_per_page;
  410.         }
  411.         elseif$what_to_show == 'paged' )
  412.         {
  413.             // echo 'PAGED';
  414.             $pgstrt '';
  415.             if ($paged
  416.             {
  417.                 $pgstrt (intval($paged-1$posts_per_page', ';
  418.             }
  419.             $limits 'LIMIT '$pgstrt.$posts_per_page;
  420.         }
  421.         elseif$what_to_show == 'days' )
  422.         {
  423.             // echo 'LIMIT DAYS ';
  424.             if!empty($p|| !empty($title|| !empty($s|| !empty($cat|| !empty($author) )
  425.             // We are in DAYS mode but we can't restrict on these!
  426.                 $limits '';
  427.             }
  428.             else
  429.             {
  430.                 $lastpostdate get_lastpostdate$blog$show_statuses$cat$catsel,    $timestamp_min$timestamp_max );
  431.                 $lastpostdate mysql2date('Y-m-d 00:00:00',$lastpostdate);
  432.                 $lastpostdate mysql2date('U',$lastpostdate);
  433.                 $otherdate date('Y-m-d H:i:s'($lastpostdate (($posts_per_page-186400)));
  434.                 $where .= ' AND post_issue_date > \''$otherdate.'\'';
  435.             }
  436.         }
  437.         /* else
  438.         {
  439.             echo 'DEFAULT - NO LIMIT';
  440.         }*/
  441.  
  442.         /*
  443.          * ----------------------------------------------------
  444.          *    Restrict to the statuses we want to show:
  445.          * ----------------------------------------------------
  446.          */
  447.         $where .= ' AND ' statuses_where_clause$show_statuses );
  448.  
  449.         /*
  450.          * ----------------------------------------------------
  451.          * Time limits:
  452.          * ----------------------------------------------------
  453.          */
  454.         if$timestamp_min == 'now' )
  455.         {
  456.             // echo 'hide past';
  457.             $timestamp_min time();
  458.         }
  459.         if!empty($timestamp_min) )
  460.         // Hide posts before
  461.             // echo 'hide before '.$timestamp_min;
  462.             $date_min date('Y-m-d H:i:s'$timestamp_min ($Settings->get('time_difference'3600) );
  463.             $where .= ' AND post_issue_date >= \''$date_min.'\'';
  464.         }
  465.  
  466.         if$timestamp_max == 'now' )
  467.         {
  468.             // echo 'hide future';
  469.             $timestamp_max time();
  470.         }
  471.         if!empty($timestamp_max) )
  472.         // Hide posts after
  473.             // echo 'after';
  474.             $date_max date('Y-m-d H:i:s'$timestamp_max ($Settings->get('time_difference'3600) );
  475.             $where .= ' AND post_issue_date <= \''$date_max.'\'';
  476.         }
  477.  
  478.         // LIMIT TO SPECIFIC BLOG?
  479.         if$blog == )
  480.         // Special case: we aggregate all cats from all blogs
  481.             $where 'WHERE 1 '.$where;
  482.         }
  483.         else
  484.         {
  485.             $where 'WHERE cat_blog_ID = '.$blog.$where;
  486.         }
  487.  
  488.  
  489.         /*
  490.          * RUN QUERY NOW:
  491.          */
  492.         if ($preview)
  493.         {    // PREVIEW MODE:
  494.             $this->request $this->preview_request();
  495.         }
  496.         else
  497.         {    // NORMAL MODE:
  498.  
  499.             // We are going to proceed in two steps (we simulate a subquery)
  500.             // 1) we get the IDs we need
  501.             // 2) we get all the other fields matching these IDs
  502.             // This is more efficient than manipulating all fields at once.
  503.             $step1_sql "SELECT DISTINCT ID
  504.                                             FROM ($tableposts INNER JOIN $tablepostcats ON ID = postcat_post_ID)
  505.                                                         INNER JOIN $tablecategories ON postcat_cat_ID = cat_ID ";
  506.             $step1_sql .= $where;
  507.             $step1_sql .= ' ORDER BY post_'.$orderby;
  508.             $step1_sql .= ' '.$limits;
  509.  
  510.             // Get list of the IDs we need:
  511.             $ID_list $DB->get_list$step1_sql0'Get ID list for Item List (Main|Lastpostdate) Query' );
  512.  
  513.             $this->request 'SELECT ID, post_author, post_issue_date,     post_mod_date,
  514.                                                                 post_status, post_locale, post_content, post_title,
  515.                                                                 post_urltitle, post_url, post_category,
  516.                                                                 post_autobr, post_flags, post_wordcount, post_comments,
  517.                                                                 post_renderers, post_karma
  518.                                                     FROM '.$tableposts;
  519.             if!empty($ID_list) )
  520.             {
  521.                 $this->request .= ' WHERE ID IN ('.$ID_list.')
  522.                                                     ORDER BY post_'.$orderby;
  523.             }
  524.             else
  525.             {
  526.                 $this->request .= ' WHERE 0';
  527.             }
  528.  
  529.             $this->count_request "SELECT COUNT(ID)
  530.                                                                 FROM ($tableposts INNER JOIN $tablepostcats ON ID = postcat_post_ID)
  531.                                                                             INNER JOIN $tablecategories ON postcat_cat_ID = cat_ID
  532.                                                             ".$where;
  533.  
  534.         }
  535.  
  536.         //echo $this->request;
  537.         $this->result_rows $DB->get_results$this->requestOBJECT'Get data for Item List (Main|Lastpostdate) Query' );
  538.  
  539.         $this->result_num_rows = $DB->num_rows;
  540.         // echo $this->result_num_rows, ' items';
  541.  
  542.         // Make a list of posts for future queries!
  543.         // Also make arrays...
  544.         $this->postIDlist = "";
  545.         $this->postIDarray = array();
  546.         ifcount$this->result_rows ) ) foreach$this->result_rows as $myrow )
  547.         {
  548.             array_unshift$this->postIDarray$myrow->ID );    // new row at beginning
  549.         }
  550.         if!empty($this->postIDarray) )
  551.         {
  552.             $this->postIDlist = implode','$this->postIDarray );
  553.         }
  554.         // echo "postlist:". $this->postIDlist;
  555.  
  556.         // Initialize loop stuff:
  557.         $this->restart();
  558.     }
  559.  
  560.  
  561.     // dummy mysql query for the preview
  562.     function preview_request()
  563.     {
  564.         // we need globals for the param function
  565.         global $preview_userid$preview_date$post_status$post_locale$content,
  566.                         $post_title$post_url$post_category$post_autobr$edit_date,
  567.                         $aa$mm$jj$hh$mn$ss$renderers;
  568.         global $DB$localtimenow;
  569.  
  570.         $id 0;
  571.         param'preview_userid''integer'true );
  572.         param'post_status''string'true );
  573.         param'post_locale''string'true );
  574.         param'content''html'true );
  575.         param'post_title''html'true );
  576.         param'post_url''string'true );
  577.         param'post_category''integer'true );
  578.         param'post_autobr''integer');
  579.         param'renderers''array'array() );
  580.  
  581.         $post_title format_to_post$post_title);
  582.         $content format_to_post$content$post_autobr );
  583.         $post_renderers implode'.'$renderers );
  584.  
  585.         param'aa''integer'2000 );
  586.         param'mm''integer');
  587.         param'jj''integer');
  588.         param'hh''integer'20 );
  589.         param'mn''integer'30 );
  590.         param'ss''integer');
  591.         $jj ($jj 3131 $jj;
  592.         $hh ($hh 23$hh 24 $hh;
  593.         $mn ($mn 59$mn 60 $mn;
  594.         $ss ($ss 59$ss 60 $ss;
  595.         $post_date date('Y-m-d H:i:s'mktime$hh$mn$ss$mm$jj$aa ) );
  596.  
  597.  
  598.         if$errcontent errors_displayT_('Invalid post, please correct these errors:')''false ) )
  599.         {
  600.             $content $errcontent;
  601.         }
  602.  
  603.         // little funky fix for IEwin, rawk on that code
  604.         global $is_winIE;
  605.         if (($is_winIE&& (!isset($IEWin_bookmarklet_fix)))
  606.         {
  607.             $content =    preg_replace('/\%u([0-9A-F]{4,4})/e',     "'&#'.base_convert('\\1',16,10). ';'"$content);
  608.         }
  609.  
  610.         return "SELECT    
  611.                                         0 AS ID, 
  612.                                         $preview_userid AS post_author, 
  613.                                         '$post_date' AS post_issue_date,
  614.                                         '$post_date' AS post_mod_date,
  615.                                         '".$DB->escape($post_status)."' AS post_status,
  616.                                         '".$DB->escape($post_locale)."' AS post_locale, 
  617.                                         '".$DB->escape($content)."' AS post_content, 
  618.                                         '".$DB->escape($post_title)."' AS post_title,
  619.                                         NULL AS post_urltitle, 
  620.                                         '".$DB->escape($post_url)."' AS post_url, 
  621.                                         $post_category AS post_category,
  622.                                         $post_autobr AS post_autobr, 
  623.                                         '' AS post_flags, 
  624.                                         ".bpost_count_words$content )." AS post_wordcount, 
  625.                                         'open' AS post_comments,
  626.                                         '".$DB->escape$post_renderers )."' AS post_renderers, 
  627.                                         0 AS post_karma";
  628.     }
  629.  
  630.     /*
  631.      * ItemList->restart(-)
  632.      */
  633.     function restart()
  634.     {
  635.         // Set variables for future:
  636.         global $previousday;        // Should be a member var
  637.         $previousday '';
  638.         $this->row_num = 0;
  639.         $this->main_cat = '';
  640.         $this->group_by_cat = false;
  641.     }
  642.  
  643.  
  644.     /*
  645.      * ItemList->get_max_paged(-)
  646.      *
  647.      * return maximum page number for paged display
  648.      */
  649.     function get_max_paged()
  650.     {
  651.         ifempty($this->max_paged) )
  652.         // Not already cached:
  653.             $this->calc_max();
  654.         }
  655.         //echo 'max paged= ', $this->max_paged;
  656.         return $this->max_paged;
  657.     }
  658.  
  659.  
  660.     /**
  661.      * Template function: display last mod date (datetime) of Item
  662.      *
  663.      * {@internal ItemList::mod_date(-) }}
  664.      *
  665.      * @param string date/time format: leave empty to use locale default date format
  666.      * @param boolean true if you want GMT
  667.      */
  668.     function mod_date$format ''$useGM false )
  669.     {
  670.         $mod_date_timestamp 0;
  671.         foreach$this->result_rows as $loop_row )
  672.         // Go through whole list
  673.             $m $loop_row->post_mod_date;
  674.             $loop_mod_date mktime(substr($m,11,2),substr($m,14,2),substr($m,17,2),substr($m,5,2),substr($m,8,2),substr($m,0,4));
  675.             if$loop_mod_date $mod_date_timestamp )
  676.                 $mod_date_timestamp $loop_mod_date;
  677.         }
  678.  
  679.         ifempty($format) )
  680.             echo date_i18nlocale_datefmt()$mod_date_timestamp$useGM );
  681.         else
  682.             echo date_i18n$format$mod_date_timestamp$useGM );
  683.     }
  684.  
  685.  
  686.     /*
  687.      * ItemList->get_total_num_posts(-)
  688.      *
  689.      * return total number of posts
  690.      */
  691.     function get_total_num_posts()
  692.     {
  693.         ifempty($this->total_num_posts) )
  694.         // Not already cached:
  695.             $this->calc_max();
  696.         }
  697.         return $this->total_num_posts;
  698.     }
  699.  
  700.  
  701.     /*
  702.      * Private ItemList->calc_max(-)
  703.      */
  704.     function calc_max()
  705.     {
  706.         global $DB;
  707.  
  708.         if$this->preview )
  709.             return 1;    // 1 row in preview mode
  710.  
  711.         $this->total_num_posts = $DB->get_var$this->count_request00'Get result count' );
  712.  
  713.         $this->max_paged = intval( ($this->total_num_posts-1max($this->posts_per_page$this->result_num_rows)) 1;
  714.         if$this->max_paged < )
  715.             $this->max_paged =1;
  716.     }
  717.  
  718.  
  719.     /**
  720.      * {@internal ItemList::get_category_group()}}
  721.      */
  722.     function get_category_group()
  723.     {
  724.         global $row;
  725.  
  726.         $this->group_by_cat = true;
  727.  
  728.         if( ($this->row_num > $this->result_num_rows|| ($this->result_num_rows == 0) )
  729.         // We are at the the end!
  730.             // echo 'END';
  731.             return false;
  732.         }
  733.  
  734.         if$this->row_num == )
  735.         // We need to initialize
  736.             $this->row = $this->result_rows[0];
  737.             $row $this->row;
  738.             $this->row_num = 1;
  739.             $this->get_postdata();
  740.         }
  741.  
  742.         // Memorize main cat
  743.         $this->main_cat = $this->row->post_category;
  744.  
  745.         // Go back now so that the fetch row doesn't skip one!
  746.         $this->row_num --;
  747.  
  748.         $this->last_Item new Item$this->row )// COPY !
  749.         return $this->last_Item;
  750.     }
  751.  
  752.  
  753.     /**
  754.      * {@internal ItemList::get_item()}}
  755.      */
  756.     function get_item)
  757.     {
  758.         global $row;
  759.         if$this->row_num >= $this->result_num_rows )
  760.         // We would pass the end!
  761.             $this->row_num++;
  762.             return false;
  763.         }
  764.         $this->row = $this->result_rows[$this->row_num];
  765.         $row $this->row;
  766.         // echo '<p>accessing row['. $this->row_num. ']:',$this->row->post_title,'</p>';
  767.         $this->row_num++;
  768.         $this->get_postdata();
  769.  
  770.  
  771.         if$this->group_by_cat && ($this->main_cat != $this->row->post_category) )
  772.         // Category change
  773.             // echo '<p>CAT CHANGE!</p>';
  774.             return false;
  775.         }
  776.  
  777.         $this->last_Item new Item$this->row )// COPY !
  778.         return $this->last_Item;
  779.     }
  780.  
  781.  
  782.     /**
  783.      * {@internal ItemList::get_postdata(-)}}
  784.      *
  785.      * Init postdata
  786.      */
  787.     function get_postdata()
  788.     {
  789.         global $id$postdata$authordata$day$page$pages$multipage$more$numpages;
  790.         global $pagenow$current_User;
  791.  
  792.         $row $this->row;
  793.         ifempty($row->post_issue_date) )
  794.         {
  795.             die('ItemList::get_postdata(-) => No post data available!');
  796.         }
  797.         $id $row->ID;
  798.         // echo 'starting ',$row->post_title;
  799.         $postdata array (
  800.             'ID' => $row->ID,
  801.             'Author_ID' => $row->post_author,
  802.             'Date' => $row->post_issue_date,
  803.             'Status' => $row->post_status,
  804.             'Locale' =>     $row->post_locale,
  805.             'Content' => $row->post_content,
  806.             'Title' => $row->post_title,
  807.             'Url' => $row->post_url,
  808.             'Category' => $row->post_category,
  809.             'AutoBR' => $row->post_autobr,
  810.             'Flags' => explode','$row->post_flags ),
  811.             'Wordcount' => $row->post_wordcount,
  812.             'comments' => $row->post_comments,
  813.             'Karma' => $row->post_karma // this isn't used yet
  814.             );
  815.  
  816.         // echo ' title: ',$postdata['Title'];
  817.         $authordata get_userdata($postdata['Author_ID']);
  818.         $day mysql2date('d.m.y',$postdata['Date']);
  819.         $currentmonth mysql2date('m',$postdata['Date']);
  820.         $numpages 1;
  821.         if!$page )
  822.             $page 1;
  823.         ifisset($p) )
  824.             $more 1;
  825.         $content $postdata['Content'];
  826.         ifpreg_match('/<!--nextpage-->/'$postdata['Content']) )
  827.         {
  828.             if$page )
  829.                 $more 1;
  830.             $multipage 1;
  831.             $content $postdata['Content'];
  832.             $content str_replace("\n<!--nextpage-->\n"'<!--nextpage-->'$content);
  833.             $content str_replace("\n<!--nextpage-->"'<!--nextpage-->'$content);
  834.             $content str_replace("<!--nextpage-->\n"'<!--nextpage-->'$content);
  835.             $pages explode('<!--nextpage-->'$content);
  836.             $numpages count($pages);
  837.         }
  838.         else
  839.         {
  840.             $pages[0$postdata['Content'];
  841.             $multipage 0;
  842.         }
  843.     }
  844.  
  845.  
  846.     /**
  847.      * Template function: Display the date if it has changed since last call
  848.      *
  849.      * {@internal ItemList::date_if_changed(-) }}
  850.      *
  851.      * @param string string to display before the date (if changed)
  852.      * @param string string to display after the date (if changed)
  853.      * @param string date/time format: leave empty to use locale default time format
  854.      */
  855.     function date_if_changed$before='<h2>'$after='</h2>'$format='' )
  856.     {
  857.         $current_item_date $this->last_Item->get'issue_date' );
  858.         if($format=='')
  859.         {
  860.             $current_item_date mysql2datelocale_datefmt()$current_item_date );
  861.         }
  862.         else
  863.         {
  864.             $current_item_date mysql2date$format$current_item_date );
  865.         }
  866.  
  867.         if$current_item_date != $this->last_displayed_date )
  868.         {
  869.             $this->last_displayed_date $current_item_date;
  870.  
  871.             echo $before;
  872.             echo $current_item_date;
  873.             echo $after;
  874.         }
  875.     }
  876.  
  877.     /**
  878.      * Template function: display message if list is empty
  879.      *
  880.      * {@internal ItemList::display_if_empty(-) }}
  881.      *
  882.      * @param string String to display if list is empty
  883.    * @return true if empty
  884.      */
  885.     function display_if_empty$message '' )
  886.     {
  887.         ifempty($message) ) 
  888.         {    // Default message:
  889.             $message T_('Sorry, there is no post to display...');
  890.         }
  891.  
  892.         return parent::display_if_empty$message );
  893.     }
  894. }
  895. ?>

Documentation generated on Tue, 20 May 2008 01:53:15 +0200 by phpDocumentor 1.4.2