[ 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.getposts.php (source)

   1  <?php
   2  // function.getposts.php 
   3  //
   4  // Written by Eaden McKee & Reverend Jim
   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_getposts () {
  25  $help = '
  26  <p>the {getposts} function is used to retrieve a blog post or posts. <br />
  27  It takes the following parameters:<br />
  28  <br />
  29  <ul>
  30  <li>assign: variable to assign data to ( defaults to "posts", or "post" if postid is given) e.g. assign="posts"</li>
  31  <li>postid: to get one post e.g. postid=1</li>
  32  <li>archive: to get ascending sorted results ( older posts first )</li>
  33  <li>num: for number of entries to return, e.g. num=10</li>
  34  <li>section: to request recent items in a section, e.g. section="news"</li>
  35  <li>sectionid: to request recent items in a section, by specifing the sectionid instead of the name</li>
  36  <li>skip: number of entries to skip, e.g. {getposts section=news num=10 skip=10} will return 10 posts, but not the first ten but the second ten. for use with paging</li>
  37  <li>home : if this is set with home=true, posts that have the "do not show on homepage" option set will not show</li>
  38  <li>year: year of posts, e.g. year=2003 will only show posts for year 2003</li>
  39  <li>month: month of posts</li>
  40  <li>day: day of posts</li>
  41  <li>hour: hour of posts</li>
  42  <li>minute: minute of posts</li>
  43  <li>second: second of posts</li>
  44  </ul>
  45  <p>For more detailed help, see the bBlog template manual</p>
  46  ';
  47  
  48    return array (
  49      'name'           =>'getposts',
  50      'type'             =>'function',
  51      'nicename'     =>'Get Posts',
  52      'description'   =>'Retrieves blog posts',
  53      'authors'        =>'Eaden McKee, Reverend Jim',
  54      'licence'         =>'GPL',
  55      'help'   => $help
  56    );
  57  }
  58  
  59  function smarty_function_getposts($params, &$bBlog) {
  60    $ar = array();
  61    $opt = array();
  62          if(is_numeric($params['postid']) && $params['postid'] > 0) {
  63              $postid = $params['postid'];
  64      } else {
  65              $postid = FALSE;
  66      }
  67      // If "assign" is not set... we'll establish a default.
  68      if($params['assign'] == '') {
  69              if($postid) $params['assign'] = 'post';
  70          else $params['assign'] = 'posts';
  71      }
  72  
  73          if($postid) {   //we've been given a post id so we'll just get it and get outta here.
  74              $q = $bBlog->make_post_query(array("postid"=>$params['postid']));
  75                  $ar['posts'] = $bBlog->get_posts($q);
  76                  // No post.
  77                  if(!is_array($ar['posts'])) {
  78                  return false;
  79              }
  80              $ar['posts'][0]['newday'] = 'yes';
  81              $ar['posts'][0]['newmonth'] = 'yes';
  82              $bBlog->assign($params['assign'],$ar['posts'][0]);
  83              return ''; // so if postid is given this is the last line processed
  84      }
  85  
  86      // If "archive" is set, order them ASCENDING by posttime.
  87      if($params['archive']) {
  88          $opt['order']=" ORDER BY posttime ";
  89      }
  90  
  91  
  92      // If num is set, we'll only get that many results in return
  93      if(is_numeric($params['num'])) {
  94          $opt['num'] = $params['num'];
  95      }
  96  
  97      // If skip is set, we'll skip that many results
  98      if(is_numeric($params['skip'])) {
  99          $opt['skip'] = $params['skip'];
 100      }
 101       
 102      if ($params['section'] != '') {
 103            $opt['sectionid'] = $bBlog->sect_by_name[$params['section']];
 104      }
 105      
 106      if($bBlog->show_section) {
 107          $opt['sectionid'] = $bBlog->show_section;
 108      }
 109  
 110      if(is_numeric($params['year'])) {
 111          if(strlen($params['year']) != 4) {
 112              $bBlog->trigger_error('getposts: year parameter requires a 4 digit month');
 113              return '';
 114          }
 115          $opt['year'] = $params['year'];
 116      }
 117  
 118      if(is_numeric($params['month'])) {
 119          if(strlen($params['month']) != 2) {
 120              $bBlog->trigger_error('getposts: month parameter requires a 2 digit month');
 121              return '';
 122          }
 123          $opt['month'] = $params['month'];
 124      }
 125  
 126      if(is_numeric($params['day'])) {
 127          if(strlen($params['day']) != 2) {
 128              $bBlog->trigger_error('getposts: day parameter requires a 2 digit day');
 129              return '';
 130          }
 131          $opt['day'] = $params['day'];
 132      }
 133  
 134      if(is_numeric($params['hour'])) {
 135          if(strlen($params['hour']) != 2) {
 136              $bBlog->trigger_error('getposts: hour parameter requires a 2 digit hour');
 137              return '';
 138          }
 139          $opt['hour'] = $params['hour'];
 140      }
 141  
 142      if(is_numeric($params['minute'])) {
 143          if(strlen($params['minute']) != 2) {
 144              $bBlog->trigger_error('getposts: minute parameter requires a 2 digit minute');
 145              return '';
 146          }
 147          $opt['minute'] = $params['minute'];
 148      }
 149  
 150      if(is_numeric($params['second'])) {
 151          if(strlen($params['second']) != 2) {
 152              $bBlog->trigger_error('getposts: second parameter requires a 2 digit second');
 153              return '';
 154          }
 155          $opt['second'] = $params['second'];
 156      }
 157  
 158      $opt['home'] = $params['home'];
 159  
 160    $q = $bBlog->make_post_query($opt);
 161  
 162    $ar['posts'] = $bBlog->get_posts($q);
 163          
 164      // No posts.
 165    if(!is_array($ar['posts'])) {
 166      return '';
 167    }
 168  
 169    $lastmonth = 0;
 170    $lastdate = 0;
 171  
 172    foreach($ar['posts'] as $key => $value) {
 173  
 174      /* check if new day  - used by block.newday.php */
 175      if(date('Ymd',$ar['posts'][$key]['posttime']) != $lastdate) {
 176        $ar['posts'][$key]['newday'] = TRUE;
 177      }
 178      $lastdate = date('Ymd',$ar['posts'][$key]['posttime']);
 179  
 180      /* check if new month - use by block.newmonth.php */
 181      if(date('Fy',$ar['posts'][$key]['posttime']) != $lastmonth) {
 182        $ar['posts'][$key]['newmonth'] = TRUE;
 183      }
 184      $lastmonth = date('Fy',$ar['posts'][$key]['posttime']);
 185    }
 186  
 187    $bBlog->assign($params['assign'],$ar['posts']);
 188  
 189    return '';
 190      
 191  }
 192  
 193  ?>


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