[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/components/com_content/models/ -> frontpage.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: frontpage.php 14401 2010-01-26 14:10:00Z louis $
   4   * @package        Joomla
   5   * @subpackage    Content
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant to the
   9   * GNU General Public License, and as distributed it includes or is derivative
  10   * of works licensed under the GNU General Public License or other free or open
  11   * source software licenses. See COPYRIGHT.php for copyright notices and
  12   * details.
  13   */
  14  
  15  // Check to ensure this file is included in Joomla!
  16  defined('_JEXEC') or die( 'Restricted access' );
  17  
  18  jimport('joomla.application.component.model');
  19  
  20  /**
  21   * Frontpage Component Model
  22   *
  23   * @package        Joomla
  24   * @subpackage    Content
  25   * @since 1.5
  26   */
  27  class ContentModelFrontpage extends JModel
  28  {
  29      /**
  30       * Frontpage data array
  31       *
  32       * @var array
  33       */
  34      var $_data = null;
  35  
  36      /**
  37       * Frontpage total
  38       *
  39       * @var integer
  40       */
  41      var $_total = null;
  42  
  43  
  44      /**
  45       * Method to get content item data for the frontpage
  46       *
  47       * @access public
  48       * @return array
  49       */
  50  	function getData()
  51      {
  52          // Load the Category data
  53          if ($this->_loadData())
  54          {
  55              // Initialize some variables
  56              $user    =& JFactory::getUser();
  57  
  58              // raise errors
  59          }
  60  
  61          return $this->_data;
  62      }
  63  
  64      /**
  65       * Method to get the total number of content items for the frontpage
  66       *
  67       * @access public
  68       * @return integer
  69       */
  70  	function getTotal()
  71      {
  72          // Lets load the content if it doesn't already exist
  73          if (empty($this->_total))
  74          {
  75              $query = $this->_buildQuery();
  76              $this->_total = $this->_getListCount($query);
  77          }
  78  
  79          return $this->_total;
  80      }
  81  
  82      /**
  83       * Method to load content item data for items in the frontpage
  84       * exist.
  85       *
  86       * @access    private
  87       * @return    boolean    True on success
  88       */
  89  	function _loadData()
  90      {
  91          // Lets load the content if it doesn't already exist
  92          if (empty($this->_data))
  93          {
  94              // Get the pagination request variables
  95              $limit        = JRequest::getVar('limit', 0, '', 'int');
  96              $limitstart    = JRequest::getVar('limitstart', 0, '', 'int');
  97  
  98              $query = $this->_buildQuery();
  99              $Arows = $this->_getList($query, $limitstart, $limit);
 100  
 101              // special handling required as Uncategorized content does not have a section / category id linkage
 102              $i = $limitstart;
 103              $rows = array();
 104              foreach ($Arows as $row)
 105              {
 106                  // check to determine if section or category has proper access rights
 107                  $rows[$i] = $row;
 108                  $i ++;
 109              }
 110              $this->_data = $rows;
 111          }
 112          return true;
 113      }
 114  
 115  	function _buildQuery()
 116      {
 117          global $mainframe;
 118          // Get the page/component configuration
 119          $params = &$mainframe->getParams();
 120  
 121          // Voting is turned on, get voting data as well for the content items
 122          $voting    = ContentHelperQuery::buildVotingQuery($params);
 123  
 124          // Get the WHERE and ORDER BY clauses for the query
 125          $where    = $this->_buildContentWhere();
 126          $orderby             = $this->_buildContentOrderBy();
 127  
 128          $query = ' SELECT a.id, a.title, a.alias, a.title_alias, a.introtext, a.fulltext, a.sectionid, a.state, a.catid, a.created, a.created_by, a.created_by_alias, a.modified, a.modified_by,' .
 129              ' a.checked_out, a.checked_out_time, a.publish_up, a.publish_down, a.images, a.attribs, a.urls, a.metakey, a.metadesc, a.access,' .
 130              ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug,'.
 131              ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug,'.
 132              ' CHAR_LENGTH( a.`fulltext` ) AS readmore,' .
 133              ' u.name AS author, u.usertype, g.name AS groups, u.email as author_email, cc.title AS category, s.title AS section, s.ordering AS s_ordering, cc.ordering AS cc_ordering, a.ordering AS a_ordering, f.ordering AS f_ordering'.
 134              $voting['select'] .
 135              ' FROM #__content AS a' .
 136              ' INNER JOIN #__content_frontpage AS f ON f.content_id = a.id' .
 137              ' LEFT JOIN #__categories AS cc ON cc.id = a.catid'.
 138              ' LEFT JOIN #__sections AS s ON s.id = a.sectionid'.
 139              ' LEFT JOIN #__users AS u ON u.id = a.created_by' .
 140              ' LEFT JOIN #__groups AS g ON a.access = g.id'.
 141              $voting['join'].
 142              $where
 143              .$orderby
 144              ;
 145  
 146          return $query;
 147      }
 148  
 149  	function _buildContentOrderBy()
 150      {
 151          global $mainframe;
 152          // Get the page/component configuration
 153          $params = &$mainframe->getParams();
 154          if (!is_object($params)) {
 155              $params = &JComponentHelper::getParams('com_content');
 156          }
 157  
 158          $orderby_sec    = $params->def('orderby_sec', '');
 159          $orderby_pri    = $params->def('orderby_pri', '');
 160          $secondary        = ContentHelperQuery::orderbySecondary($orderby_sec);
 161          $primary        = ContentHelperQuery::orderbyPrimary($orderby_pri);
 162  
 163          $orderby = ' ORDER BY '.$primary.' '.$secondary;
 164  
 165          return $orderby;
 166      }
 167  
 168  	function _buildContentWhere()
 169      {
 170          global $mainframe;
 171  
 172          $user        =& JFactory::getUser();
 173          $gid        = $user->get('aid', 0);
 174          // TODO: Should we be using requestTime here? or is JDate ok?
 175          // $now        = $mainframe->get('requestTime');
 176  
 177          $jnow        =& JFactory::getDate();
 178          $now        = $jnow->toMySQL();
 179  
 180          // Get the page/component configuration
 181          $params = &$mainframe->getParams();
 182  
 183          $noauth        = !$params->get('show_noauth');
 184          $nullDate    = $this->_db->getNullDate();
 185  
 186          //First thing we need to do is assert that the articles are in the current category
 187          $where = ' WHERE 1';
 188  
 189          // Does the user have access to view the items?
 190          if ($noauth) {
 191              $where .= ' AND a.access <= '.(int) $gid;
 192          }
 193  
 194          if ($user->authorize('com_content', 'edit', 'content', 'all')) {
 195              $where .= ' AND a.state >= 0';
 196          } else {
 197              $where .= ' AND a.state = 1'.
 198                      ' AND (( cc.published = 1'.
 199                      ' AND s.published = 1 )'.
 200                      ' OR ( a.catid = 0 AND a.sectionid = 0 ) )';
 201  
 202              $where .= ' AND ( a.publish_up = '.$this->_db->Quote($nullDate).' OR a.publish_up <= '.$this->_db->Quote($now).' )' .
 203                        ' AND ( a.publish_down = '.$this->_db->Quote($nullDate).' OR a.publish_down >= '.$this->_db->Quote($now).' )';
 204          }
 205  
 206          return $where;
 207      }
 208  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1