[ PHPXref.com ] [ Generated: Sun Jul 20 16:35:25 2008 ] [ bBlog 0.7.6 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/bblog/bBlog_plugins/ -> function.getrecentposts.php (source)

   1  <?php
   2  // function.getposts.php 
   3  //
   4  // Written by Reverend Jim <jim@revjim.net>
   5  //
   6  /*
   7  ** bBlog Weblog http://www.bblog.com/
   8  ** Copyright (C) 2003  Eaden McKee <email@eadz.co.nz>
   9  **
  10  ** This program is free software; you can redistribute it and/or modify
  11  ** it under the terms of the GNU General Public License as published by
  12  ** the Free Software Foundation; either version 2 of the License, or
  13  ** (at your option) any later version.
  14  **
  15  ** This program is distributed in the hope that it will be useful,
  16  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  17  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18  ** GNU General Public License for more details.
  19  **
  20  ** You should have received a copy of the GNU General Public License
  21  ** along with this program; if not, write to the Free Software
  22  ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23  */
  24  function identify_function_getrecentposts () {
  25  $help = '
  26  <p>the {getrecentposts} function is used to retrieve recent posts. It takes the following parameters:<br />
  27  <br />
  28  assign: variable to assign data to<br />
  29  archive: to get ascending sorted results<br />
  30  num: for number of entries to return<br />
  31  skip: number of entries to skip<br />
  32  section: to request recent items in a section<br />
  33  home=true : to only show posts that have not been hidden.<br />
  34  sectionid: to request recent items in a section, by specifing the sectionid';
  35  
  36    return array (
  37      'name'           =>'getrecentposts',
  38      'type'             =>'function',
  39      'nicename'     =>'GetRecentPosts',
  40      'description'   =>'Retrieves recent blog posts',
  41      'authors'        =>'Reverend Jim <jim@revjim.net>',
  42      'licence'         =>'GPL',
  43      'help'   => $help
  44    );
  45  }
  46  
  47  function smarty_function_getrecentposts($params, &$bBlog) {
  48    $ar = array();
  49    $opt = array();
  50  
  51      // If "assign" is not set... we'll establish a default.
  52      if($params['assign'] == '') {
  53          $params['assign'] = 'posts';
  54      }
  55      
  56      // If "archive" is set, order them ASCENDING by posttime.
  57      if($params['archive']=='TRUE') {
  58          $opt['order']=" ORDER BY posttime ";
  59      }
  60  
  61      // If num is set, we'll only get that many results in return
  62      if(is_numeric($params['num'])) {
  63          $opt['num'] = $params['num'];
  64      }
  65  
  66      // If skip is set, we'll skip that many results
  67      if(is_numeric($params['skip'])) {
  68          $opt['num'] = $params['skip'];
  69      }
  70       
  71      if ($params['section'] != '') {
  72            $opt['sectionid'] = $bBlog->sect_by_name[$params['section']];
  73      }
  74      
  75      if($bBlog->show_section) {
  76          $opt['sectionid'] = $bBlog->show_section;
  77      }
  78  
  79      $opt['home'] = $params['home'];
  80  
  81    $q = $bBlog->make_post_query($opt);
  82  
  83    $ar['posts'] = $bBlog->get_posts($q);
  84          
  85      // No posts.
  86    if(!is_array($ar['posts'])) {
  87      return '';
  88    }
  89  
  90    $lastmonth = 0;
  91    $lastdate = 0;
  92  
  93    foreach($ar['posts'] as $key => $value) {
  94          // It seems silly to do this. Especially since,
  95          // this kind of check can be done in Smarty template.
  96          // Additionally, since {newday} and {newmonth} require
  97          // the data to be in a variable named "post" it may not
  98          // function at all.
  99          //
 100          // We'll leave it here for now.
 101          
 102      /* check if new day  - used by block.newday.php */
 103      if(date('Ymd',$ar['posts'][$key]['posttime']) != $lastdate) {
 104        $ar['posts'][$key]['newday'] = TRUE;
 105      }
 106      $lastdate = date('Ymd',$ar['posts'][$key]['posttime']);
 107  
 108      /* check if new month - use by block.newmonth.php */
 109      if(date('Fy',$ar['posts'][$key]['posttime']) != $lastmonth) {
 110        $ar['posts'][$key]['newmonth'] = TRUE;
 111      }
 112      $lastmonth = date('Fy',$ar['posts'][$key]['posttime']);
 113    }
 114  
 115    $bBlog->assign($params['assign'],$ar['posts']);
 116  
 117    return '';
 118      
 119  }
 120  
 121  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]