diff --git a/components/com_content/models/article.php b/components/com_content/models/article.php index 7e748d60a7b65..7d7c94a81c0c1 100644 --- a/components/com_content/models/article.php +++ b/components/com_content/models/article.php @@ -27,7 +27,7 @@ class ContentModelArticle extends JModelItem * * @var string */ - protected $_context = 'com_content.item'; + protected $_context = 'com_content.article'; /** * Method to auto-populate the model state. diff --git a/components/com_content/models/articles.php b/components/com_content/models/articles.php new file mode 100644 index 0000000000000..e33767ff52bae --- /dev/null +++ b/components/com_content/models/articles.php @@ -0,0 +1,204 @@ +getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit')); + $limit = JRequest::getInt('limit', $app->getCfg('list_limit', 0)); + $this->setState('list.limit', $limit); + + //$limitstart = $app->getUserStateFromRequest($this->_context.'.limitstart', 'limitstart', 0); + $limitstart = JRequest::getInt('limitstart', 0); + $this->setState('list.limitstart', $limitstart); + + //$orderCol = $app->getUserStateFromRequest($this->_context.'.ordercol', 'filter_order', 'a.lft'); + $orderCol = JRequest::getCmd('filter_order', 'a.ordering'); + $this->setState('list.ordering', $orderCol); + + //$orderDirn = $app->getUserStateFromRequest($this->_context.'.orderdirn', 'filter_order_Dir', 'asc'); + $orderDirn = JRequest::getWord('filter_order_Dir', 'asc'); + $this->setState('list.direction', $orderDirn); + + $params = $app->getParams(); + $this->setState('params', $params); + + $this->setState('filter.published', 1); + $this->setState('filter.access', true); + } + + /** + * Method to get a store id based on model configuration state. + * + * This is necessary because the model is used by the component and + * different modules that might need different sets of data or different + * ordering requirements. + * + * @param string $id A prefix for the store id. + * + * @return string A store id. + */ + protected function _getStoreId($id = '') + { + // Compile the store id. + $id .= ':'.$this->getState('list.start'); + $id .= ':'.$this->getState('list.limit'); + $id .= ':'.$this->getState('list.ordering'); + $id .= ':'.$this->getState('list.direction'); + $id .= ':'.$this->getState('filter.published'); + $id .= ':'.$this->getState('filter.access'); + + return md5($id); + } + + /** + * @param boolean True to join selected foreign information + * + * @return string + */ + function _getListQuery() + { + // Create a new query object. + $query = new JQuery; + + // Select the required fields from the table. + $query->select($this->getState( + 'list.select', + 'a.id, a.title, a.alias, a.title_alias, a.introtext, a.state, a.catid, a.created, a.created_by, a.created_by_alias,' . + ' a.modified, a.modified_by,a.publish_up, a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access,' . + ' LENGTH(a.fulltext) AS readmore' + )); + $query->from('#__content AS a'); + + // Join over the categories. + $query->select('c.title AS category_title, c.path AS category_route, c.access AS category_access'); + $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); + + // Join over the users for the author. + $query->select('ua.name AS author_name'); + $query->join('LEFT', '#__users AS ua ON ua.id = a.created_by'); + + // Filter by access level. + if ($access = $this->getState('filter.access')) + { + $user = &JFactory::getUser(); + $groups = implode(',', $user->authorisedLevels()); + $query->where('a.access IN ('.$groups.')'); + } + + // Filter by published state + $published = $this->getState('filter.published'); + if (is_numeric($published)) { + $query->where('a.state = ' . (int) $published); + } + else if (is_array($published)) + { + JArrayHelper::toInteger($published); + $published = implode(',', $published); + $query->where('a.state IN ('.$published.')'); + } + + // Filter by a single or group of categories. + $categoryId = $this->getState('filter.category_id'); + if (is_numeric($categoryId)) { + $query->where('a.catid = ' . (int) $categoryId); + } + else if (is_array($categoryId)) + { + JArrayHelper::toInteger($categoryId); + $categoryId = implode(',', $categoryId); + $query->where('a.catid IN ('.$categoryId.')'); + } + + // Filter by start and end dates. + $nullDate = $this->_db->Quote($this->_db->getNullDate()); + $nowDate = $this->_db->Quote(JFactory::getDate()->toMySQL()); + + $query->where('(a.publish_up = '.$nullDate.' OR a.publish_up <= '.$nowDate.')'); + $query->where('(a.publish_down = '.$nullDate.' OR a.publish_down >= '.$nowDate.')'); + + // Add the list ordering clause. + $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.ordering')).' '.$this->_db->getEscaped($this->getState('list.direction', 'ASC'))); + + //echo nl2br(str_replace('#__','jos_',$query)); + return $query; + } + + + /** + * Method to get a list of articles. + * + * Overriden to inject convert the attribs field into a JParameter object. + * + * @return mixed An array of objects on success, false on failure. + */ + public function &getItems() + { + $items = &parent::getItems(); + $user = &JFactory::getUser(); + $groups = $user->authorisedLevels(); + + // Contvert the parameter fields into objects. + foreach ($items as &$item) + { + $registry = new JRegistry; + $registry->loadJSON($item->attribs); + $item->params = clone $this->getState('params'); + $item->params->merge($registry); + + // TODO: Embed the access controls in here + $item->params->set('access-edit', false); + + $access = $this->getState('filter.access'); + if ($access = $this->getState('filter.access')) + { + // If the access filter has been set, we already have only the articles this user can view. + $item->params->set('access-view', true); + } + else + { + // If no access filter is set, the layout takes some responsibility for display of limited information. + if ($item->catid == 0 || $item->category_access === null) { + $item->params->set('access-view', in_array($item->access, $groups)); + } + else { + $item->params->set('access-view', in_array($item->access, $groups) && in_array($item->category_access, $groups)); + } + } + } + + return $items; + } +} diff --git a/components/com_content/models/categories.php b/components/com_content/models/categories.php index 77bc15e85f645..4c2acb227a589 100644 --- a/components/com_content/models/categories.php +++ b/components/com_content/models/categories.php @@ -11,7 +11,7 @@ jimport('joomla.application.component.modellist'); /** - * Categories Component Categories Model + * This models supports retrieving lists of article categories. * * @package Joomla.Administrator * @subpackage com_content @@ -34,35 +34,35 @@ class ContentModelCategories extends JModelList protected $_extension = 'com_content'; /** - * Overridden method to lazy load data from the request/session as necessary + * Method to auto-populate the model state. * - * @access public - * @param string $key The key of the state item to return - * @param mixed $default The default value to return if it does not exist - * @return mixed The requested value by key - * @since 1.0 + * @since 1.6 */ - function _populateState() + protected function _populateState() { $app = &JFactory::getApplication(); $this->setState('filter.extension', $this->_extension); - // Get the parent id + // Get the parent id if defined. $parentId = JRequest::getInt('id'); - $this->setState('list.parentId', $parentId); + $this->setState('filter.parentId', $parentId); // List state information - $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit')); + //$limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit')); + $limit = JRequest::getInt('limit', $app->getCfg('list_limit', 0)); $this->setState('list.limit', $limit); - $limitstart = $app->getUserStateFromRequest($this->_context.'.limitstart', 'limitstart', 0); + //$limitstart = $app->getUserStateFromRequest($this->_context.'.limitstart', 'limitstart', 0); + $limitstart = JRequest::getInt('limitstart', 0); $this->setState('list.limitstart', $limitstart); - $orderCol = $app->getUserStateFromRequest($this->_context.'.ordercol', 'filter_order', 'a.lft'); + //$orderCol = $app->getUserStateFromRequest($this->_context.'.ordercol', 'filter_order', 'a.lft'); + $orderCol = JRequest::getCmd('filter_order', 'a.lft'); $this->setState('list.ordering', $orderCol); - $orderDirn = $app->getUserStateFromRequest($this->_context.'.orderdirn', 'filter_order_Dir', 'asc'); + //$orderDirn = $app->getUserStateFromRequest($this->_context.'.orderdirn', 'filter_order_Dir', 'asc'); + $orderDirn = JRequest::getWord('filter_order_Dir', 'asc'); $this->setState('list.direction', $orderDirn); $params = $app->getParams(); @@ -83,7 +83,7 @@ function _populateState() * * @return string A store id. */ - public function _getStoreId($id = '') + protected function _getStoreId($id = '') { // Compile the store id. $id .= ':'.$this->getState('list.start'); @@ -112,24 +112,12 @@ function _getListQuery($resolveFKs = true) $this->getState( 'list.select', 'a.id, a.title, a.alias, a.access, a.published, a.access' . - ', a.path, a.parent_id, a.level, a.lft, a.rgt' . + ', a.path AS route, a.parent_id, a.level, a.lft, a.rgt' . ', a.description' ) ); $query->from('#__categories AS a'); - // Retrieve a sub tree - if ($parentId = $this->getState('list.parentId')) - { - $query->join('LEFT', '#__categories AS p ON p.id = '.(int) $parentId); - $query->where('(a.lft > p.lft AND a.rgt < p.rgt)'); - } - - // Filter by extension - if ($extension = $this->getState('filter.extension')) { - $query->where('a.extension = '.$this->_db->quote($extension)); - } - // Filter by access level. if ($access = $this->getState('filter.access')) { @@ -138,7 +126,7 @@ function _getListQuery($resolveFKs = true) $query->where('a.access IN ('.$groups.')'); } - // Filter by published state + // Filter by published state. $published = $this->getState('filter.published'); if (is_numeric($published)) { $query->where('a.published = ' . (int) $published); @@ -146,11 +134,80 @@ function _getListQuery($resolveFKs = true) else if (is_array($published)) { JArrayHelper::toInteger($published); + $published = implode(',', $published); $query->where('a.published IN ('.$published.')'); } + // Filter by extension. + $query->where('a.extension = '.$this->_db->quote($this->_extension)); + + // Retrieve a sub tree or lineage. + if ($parentId = $this->getState('filter.parent_id')) + { + if ($levels = $this->getState('filter.get_children')) + { + // Optionally get all the child categories for given parent. + $query->leftJoin('#__categories AS p ON p.id = '.(int) $parentId); + $query->where('a.lft > p.lft AND a.rgt < p.rgt'); + if ((int) $levels > 0) + { + // Only go to a certain depth. + $query->where('a.level <= p.level + '.(int) $levels); + } + } + else if ($this->getState('filter.get_parents')) + { + // Optionally get all the parents to the category. + $query->leftJoin('#__categories AS p ON p.id = '.(int) $parentId); + $query->where('a.lft < p.lft AND a.rgt > p.rgt'); + } + else + { + // Only looking for categories with this parent. + $query->where('a.parent_id = '.(int) $parentId); + } + } + + // Inclusive/exclusive filters (-ve id's are to be excluded). + $categoryId = $this->getState('filter.category_id'); + if (is_numeric($categoryId)) + { + if ($categoryId > 0) { + $query->where('a.id = ' . (int) $categoryId); + } + else { + $query->where('a.id <> ' . -(int) $categoryId); + } + } + else if (is_array($categoryId)) + { + JArrayHelper::toInteger($categoryId); + // Find the include/excludes + $include = array(); + $exclude = array(); + foreach ($categoryId as $id) + { + if ($id > 0) { + $include[] = $id; + } + else { + $exclude[] = $id; + } + } + if (!empty($include)) + { + $include = implode(',', $include); + $query->where('a.id IN ('.$include.')'); + } + else + { + $include = implode(',', $include); + $query->where('a.id NOT IN ('.$include.')'); + } + } + // Add the list ordering clause. - $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.title')).' '.$this->_db->getEscaped($this->getState('list.direction', 'ASC'))); + $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.lft')).' '.$this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; diff --git a/components/com_content/models/category.php b/components/com_content/models/category.php index 7a2a8e5c94006..6403d6856f087 100644 --- a/components/com_content/models/category.php +++ b/components/com_content/models/category.php @@ -8,454 +8,295 @@ // No direct access defined('_JEXEC') or die; -jimport('joomla.application.component.model'); +jimport('joomla.application.component.modelitem'); +jimport('joomla.database.query'); /** - * Content Component Category Model + * This models supports retrieving a category, the articles associated with the category, + * sibling, child and parent categories. * * @package Joomla.Site * @subpackage com_content - * @since 1.5 + * @since 1.5 */ -class ContentModelCategory extends JModel +class ContentModelCategory extends JModelItem { - /** - * Category id - * - * @var int - */ - protected $_id = null; - /** * Category items data * * @var array */ - protected $_data = null; + protected $_item = null; - /** - * Category number items - * - * @var integer - */ - protected $_total = null; + protected $_articles = null; - /** - * Category data - * - * @var object - */ - protected $_category = null; + protected $_siblings = null; + + protected $_children = null; + + protected $_parents = null; /** - * Category data + * Model context string. * - * @var array + * @var string */ - protected $_siblings = null; - - protected $_content = null; - - protected $_category_tree = array(); + protected $_context = 'com_content.article'; /** - * Constructor + * Method to auto-populate the model state. * - * @since 1.5 + * @return void */ - public function __construct() + protected function _populateState() { - parent::__construct(); - $app = JFactory::getApplication(); + $app = &JFactory::getApplication('site'); + + // Load state from the request. + $pk = JRequest::getInt('id'); + $this->setState('category.id', $pk); - $id = JRequest::getVar('id', 0, '', 'int'); - $this->setId((int)$id); + // TODO: Add pagination for children , siblings and articles?? - // here we initialize defaults for category model - $params = &$app->getParams(); - $params->def('filter', 1); - $params->def('filter_type', 'title'); + // Load the parameters. + $params = $app->getParams(); + $this->setState('params', $params); + + // TODO: Tune these values based on other permissions. + $this->setState('filter.published', 1); + $this->setState('filter.access', true); } /** - * Method to set the category id + * Method to get a store id based on model configuration state. + * + * This is necessary because the model is used by the component and + * different modules that might need different sets of data or different + * ordering requirements. * - * @access public - * @param int Category ID number + * @param string $context A prefix for the store id. + * @return string A store id. */ - public function setId($id) + protected function _getStoreId($id = '') { - // Set category ID and wipe data - $this->_id = $id; - $this->_category = null; - $this->_siblings = null; - $this->_data = array(); - $this->_total = null; + // Compile the store id. + // TODO: Add uniqueness stuff + return md5($id); } /** - * Method to get content item data for the current category + * Method to get article data. * - * @param int $state The content state to pull from for the current - * category - * @since 1.5 + * @param integer The id of the category. + * + * @return mixed Menu item data object on success, false on failure. */ - public function getData($state = 1) + public function &getItem($pk = null) { - if (empty($this->_category)) - { - jimport('joomla.application.categorytree'); - $categoryTree = JCategories::getInstance('com_content'); - $this->_category = &$categoryTree->get($this->_id); + // Initialize variables. + $pk = (!empty($pk)) ? $pk : (int) $this->getState('category.id'); + + if ($this->_item === null) { + $this->_item = array(); } - // Load the Category data - if ($this->_loadData($state)) - { - // Initialize some variables - $user = &JFactory::getUser(); - // Make sure the category is published - if (!$this->_category->published) + if (!isset($this->_item[$pk])) + { + try { - JError::raiseError(404, JText::_("Resource Not Found")); - return false; - } + $query = new JQuery; + + $query->select($this->getState('item.select', 'a.*')); + $query->from('#__categories AS a'); + + $query->where('a.extension = '.$this->_db->quote('com_content')); + $query->where('a.id = '.(int) $pk); + + // Filter by published state. + $published = $this->getState('filter.published'); + if (is_numeric($published)) { + $query->where('a.published = '.(int) $published); + } + + // Filter by access level. + if ($access = $this->getState('filter.access')) + { + $user = &JFactory::getUser(); + $groups = implode(',', $user->authorisedLevels()); + $query->where('a.access IN ('.$groups.')'); + } + + $this->_db->setQuery($query); + + $data = $this->_db->loadObject(); + + if ($error = $this->_db->getErrorMsg()) { + throw new Exception($error); + } + + if (empty($data)) { + throw new Exception(JText::_('Content_Error_Category_not_found')); + } + + // Check for published state if filter set. + if (is_numeric($published) && $data->published != $published) { + throw new Exception(JText::_('Content_Error_Category_not_found')); + } + + // Convert parameter fields to objects. + $registry = new JRegistry; + $registry->loadJSON($data->params); + $data->params = clone $this->getState('params'); + $data->params->merge($registry); + + $registry = new JRegistry; + $registry->loadJSON($data->metadata); + $data->metadata = $registry; + + // Compute access permissions. + if ($access) + { + // If the access filter has been set, we already know this user can view. + // TODO + $data->params->set('access-view', true); + } + else + { + // If no access filter is set, the layout takes some responsibility for display of limited information. + $user = &JFactory::getUser(); + $groups = $user->authorisedLevels(); - // check whether category access level allows access - if (!in_array($this->_category->access, $user->authorisedLevels())) + $data->params->set('access-view', in_array($data->access, $groups) && in_array($data->category_access, $groups)); + } + // TODO: Type 2 permission checks? + + $this->_item[$pk] = $data; + } + catch (Exception $e) { - JError::raiseError(403, JText::_("ALERTNOTAUTH")); - return false; + $this->setError($e->getMessage()); + $this->_item[$pk] = false; } } - return $this->_data[$state]; + + return $this->_item[$pk]; } /** - * Method to get the total number of content items for the frontpage + * Get the articles in the category * - * @access public - * @return integer + * @return mixed An array of articles or false if an error occurs. */ - public function getTotal($state = 1, $recursive = false) + function &getArticles() { - // Lets load the content if it doesn't already exist - if (empty($this->_total)) + if ($this->_articles === null && $category = &$this->getItem()) { - if (empty($this->_category)) - { - jimport('joomla.application.categorytree'); - $categoryTree = JCategories::getInstance('com_content'); - $this->_category = &$categoryTree->get($this->_id); + $model = &JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true)); + $model->setState('params', JFactory::getApplication()->getParams()); + $model->setState('filter.category_id', $category->id); + $model->setState('filter.published', $this->getState('filter.published')); + $model->setState('filter.access', $this->getState('filter.access')); + // TODO: Set ordering + // TODO: Set limits + + $this->_articles = $model->getItems(); + + if ($this->_articles === false) { + $this->setError($model->getError()); } - $query = $this->_buildQuery($state, true); - $this->_db->setQuery($query); - $this->_total[$state] = $this->_db->loadResult(); } - return $this->_total[$state]; + return $this->_articles; } /** - * Method to get category data for the current category + * Get the sibling (adjacent) categories. * - * @since 1.5 + * @return mixed An array of categories or false if an error occurs. */ - public function getCategory() + function &getSiblings() { - // Load the Category data - if (empty($this->_category)) + if ($this->_siblings === null && $category = &$this->getItem()) { - jimport('joomla.application.categorytree'); - $categoryTree = JCategories::getInstance('com_content'); - $this->_category = &$categoryTree->get($this->_id); - } + $model = &JModel::getInstance('Categories', 'ContentModel', array('ignore_request' => true)); + $model->setState('params', JFactory::getApplication()->getParams()); + $model->setState('filter.parent_id', $category->parent_id); + $model->setState('filter.published', $this->getState('filter.published')); + $model->setState('filter.access', $this->getState('filter.access')); + // TODO: Set limits - if (empty($this->_category)) - { - JError::raiseError(404, JText::_("Resource Not Found")); - return false; - } - // Initialize some variables - $user = &JFactory::getUser(); + $this->_siblings = $model->getItems(); - // Make sure the category is published - if (!$this->_category->published) { - JError::raiseError(404, JText::_("Resource Not Found")); - return false; - } - // check whether category access level allows access - if (!in_array($this->_category->access, $user->authorisedLevels())) { - JError::raiseError(403, JText::_("ALERTNOTAUTH")); - return false; + if ($this->_siblings === false) { + $this->setError($model->getError()); + } } - return $this->_category; + + return $this->_siblings; } /** - * Method to get sibling category data for the current category + * Get the child categories. * - * @since 1.5 + * @param int An optional category id. If not supplied, the model state 'category.id' will be used. + * + * @return mixed An array of categories or false if an error occurs. */ - public function getSiblings() + function &getChildren($categoryId = 0) { - // Initialize some variables - $user = &JFactory::getUser(); + // Initialize variables. + $categoryId = (!empty($categoryId)) ? $categoryId : $this->getState('category.id'); - // Load the Category data - if ($this->_loadCategory() && $this->_loadSiblings()) + if ($this->_children === null) { - // Make sure the category is published - if (!$this->_category->published) - { - JError::raiseError(404, JText::_("Resource Not Found")); - return false; - } - - // check whether category access level allows access - if ($this->_category->access > $user->get('aid', 0)) - { - JError::raiseError(403, JText::_("ALERTNOTAUTH")); - return false; + $model = &JModel::getInstance('Categories', 'ContentModel', array('ignore_request' => true)); + $model->setState('params', JFactory::getApplication()->getParams()); + $model->setState('filter.parent_id', $categoryId); + $model->setState('filter.get_children', true); + $model->setState('filter.published', $this->getState('filter.published')); + $model->setState('filter.access', $this->getState('filter.access')); + // TODO: Set limits + + $this->_children = $model->getItems(); + + if ($this->_children === false) { + $this->setError($model->getError()); } } - return $this->_siblings; - } - - /** - * Method to get archived article data for the current category - * - * @param int $state The content state to pull from for the current section - * @since 1.5 - */ - public function getArchives($state = -1) - { - return $this->getContent(-1); - } - public function getChildren($recursive = 0) - { - return $this->_category->getChildren(); + return $this->_children; } /** - * Method to load content item data for items in the category if they don't - * exist. + * Get the child categories. * - * @access private - * @return boolean True on success + * @param int An optional category id. If not supplied, the model state 'category.id' will be used. + * + * @return mixed An array of categories or false if an error occurs. */ - protected function _loadData($state = 1) + function &getParents($categoryId = 0) { - if (empty($this->_category)) { - return false; // TODO: set error -- can't get siblings when we don't know the category - } + // Initialize variables. + $categoryId = (!empty($categoryId)) ? $categoryId : $this->getState('category.id'); - // Lets load the siblings if they don't already exist - if (empty($this->_content[$state])) + if ($this->_parents === null) { - // Get the pagination request variables - $limit = JRequest::getVar('limit', 0, '', 'int'); - $limitstart = JRequest::getVar('limitstart', 0, '', 'int'); - - $query = $this->_buildQuery(); - $Arows = $this->_getList($query, $limitstart, $limit); - // special handling required as Uncategorized content does not have a section / category id linkage - $i = $limitstart; - $rows = array(); - foreach ($Arows as $row) - { - // check to determine if section or category has proper access rights - $rows[$i] = $row; - $i ++; - } - $this->_data[$state] = $rows; - } - return true; - } - - protected function _buildQuery($state = 1, $countOnly = false) - { - $app = JFactory::getApplication(); - // Get the page/component configuration - $params = &$app->getParams(); - $user = &JFactory::getUser(); - $groups = implode(',', $user->authorisedLevels()); - - - // If voting is turned on, get voting data as well for the content items - $voting = ContentHelperQuery::buildVotingQuery($params); - - // Get the WHERE and ORDER BY clauses for the query - $where = $this->_buildContentWhere($state); - $orderby = $this->_buildContentOrderBy($state); - - if (!$countOnly) { - $query = 'SELECT cc.title AS category, a.id, a.title, a.title_alias, a.introtext, a.fulltext, a.state, a.catid, a.created, a.created_by, a.created_by_alias, a.modified, a.modified_by,' . - ' a.checked_out, a.checked_out_time, a.publish_up, a.publish_down, a.attribs, a.hits, a.images, a.urls, a.ordering, a.metakey, a.metadesc, a.access,' . - ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'; - if ($params->get('show_subcategory_content', 0)) - { - $query .= ' cc.catslug as catslug, '; - } else { - $query .= ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug,'; + $model = &JModel::getInstance('Categories', 'ContentModel', array('ignore_request' => true)); + $model->setState('params', JFactory::getApplication()->getParams()); + $model->setState('list.select', 'a.id, a.title, a.level, a.path AS route'); + $model->setState('filter.parent_id', $categoryId); + $model->setState('filter.get_parents', true); + $model->setState('filter.published', $this->getState('filter.published')); + $model->setState('filter.access', $this->getState('filter.access')); + // TODO: Set limits + + $this->_parents = $model->getItems(); + + if ($this->_parents === false) { + $this->setError($model->getError()); } - $query .= ' CHAR_LENGTH(a.`fulltext`) AS readmore, u.name AS author, u.usertype'.$voting['select']; - } else { - $query = 'SELECT count(*) '; - } - if ($params->get('show_subcategory_content', 0)) - { - $subquery = ' RIGHT JOIN (SELECT c.id as id, c.title as title, c.alias as alias,'. - ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(":", c.id, c.alias) ELSE c.id END as catslug'. - ' FROM #__categories AS c'. - ' JOIN #__categories AS cp ON cp.lft <= c.lft AND c.rgt <= cp.rgt'. - ' WHERE c.extension = \'com_content\''. - ' AND c.access IN ('.$groups.')'. - ' AND cp.id = '.$this->_id.') AS cc ON a.catid = cc.id'; - } else { - $subquery = ' LEFT JOIN #__categories AS cc ON a.catid = cc.id'; - } - $query .= - ' FROM #__content AS a' . - $subquery. - ' LEFT JOIN #__users AS u ON u.id = a.created_by' . - $voting['join']. - $where. - $orderby; - - return $query; - } - - protected function _buildContentOrderBy($state = 1) - { - $app = JFactory::getApplication(); - // Get the page/component configuration - $params = &$app->getParams(); - - $filter_order = JRequest::getCmd('filter_order'); - $filter_order_Dir = JRequest::getWord('filter_order_Dir'); - - $orderby = ' ORDER BY '; - if ($filter_order && $filter_order_Dir) - { - $orderby .= $filter_order .' '. $filter_order_Dir.', '; } - if ($filter_order == 'author') - { - $orderby .= 'created_by_alias '. $filter_order_Dir.', '; - } - switch ($state) - { - case -1: - // Special ordering for archive articles - $orderby_sec = $params->def('orderby', 'rdate'); - $secondary = ContentHelperQuery::orderbySecondary($orderby_sec).', '; - $primary = ''; - break; - - case 1: - default: - $orderby_sec = $params->def('orderby_sec', 'rdate'); - $orderby_sec = ($orderby_sec == 'front') ? '' : $orderby_sec; - $orderby_pri = $params->def('orderby_pri', ''); - $secondary = ContentHelperQuery::orderbySecondary($orderby_sec).', '; - $primary = ContentHelperQuery::orderbyPrimary($orderby_pri); - break; - } - $orderby .= $primary .' '. $secondary .' a.created DESC'; - - return $orderby; - } - - protected function _buildContentWhere($state = 1) - { - $app = JFactory::getApplication(); - // Get the page/component configuration - $params = &$app->getParams(); - - $user = &JFactory::getUser(); - $groups = implode(',', $user->authorisedLevels()); - - $jnow = &JFactory::getDate(); - $now = $jnow->toMySQL(); - - // Get the page/component configuration - $noauth = !$params->get('show_noauth'); - $nullDate = $this->_db->getNullDate(); - if ($params->get('show_subcategory_content', 0)) - { - $where = ' WHERE 1 '; - } else { - $where = ' WHERE a.catid = '.$this->_id; - } - // Does the user have access to view the items? - if ($noauth) { - $where .= ' AND a.access IN ('.$groups.')'; - } - - // Regular Published Content - switch ($state) - { - case 1: - if ($user->authorize('com_content', 'edit', 'content', 'all')) - { - $where .= ' AND a.state >= 0'; - } - else - { - $where .= ' AND a.state = 1' . - ' AND (publish_up = '.$this->_db->Quote($nullDate).' OR publish_up <= '.$this->_db->Quote($now).')' . - ' AND (publish_down = '.$this->_db->Quote($nullDate).' OR publish_down >= '.$this->_db->Quote($now).')'; - } - break; - - // Archive Content - case -1: - // Get some request vars specific to this state - $year = JRequest::getInt('year', date('Y')); - $month = JRequest::getInt('month', date('m')); - - $where .= ' AND a.state = -1'; - $where .= ' AND YEAR(a.created) = '.(int) $year; - $where .= ' AND MONTH(a.created) = '.(int) $month; - break; - - default: - $where .= ' AND a.state = '.(int) $state; - break; - } - - /* - * If we have a filter, and this is enabled... lets tack the AND clause - * for the filter onto the WHERE clause of the content item query. - */ - if ($params->get('filter')) - { - $filter = JRequest::getString('filter', '', 'request'); - if ($filter) - { - // clean filter variable - $filter = JString::strtolower($filter); - $filter = $this->_db->Quote('%'.$this->_db->getEscaped($filter, true).'%', false); - - switch ($params->get('filter_type')) - { - case 'title' : - $where .= ' AND LOWER(a.title) LIKE '.$filter; - break; - - case 'author' : - $where .= ' AND ((LOWER(u.name) LIKE '.$filter.') OR (LOWER(a.created_by_alias) LIKE '.$filter.'))'; - break; - - case 'hits' : - $where .= ' AND a.hits LIKE '.$filter; - break; - } - } - } - return $where; + return $this->_parents; } } diff --git a/components/com_content/models/frontpage.php b/components/com_content/models/frontpage.php index 851cedea7d8ca..1d94a7122d55a 100644 --- a/components/com_content/models/frontpage.php +++ b/components/com_content/models/frontpage.php @@ -10,7 +10,7 @@ // No direct access defined('_JEXEC') or die; -jimport('joomla.application.component.modellist'); +require_once dirname(__FILE__).DS.'articles.php'; /** * Frontpage Component Model @@ -19,50 +19,25 @@ * @subpackage com_content * @since 1.5 */ -class ContentModelFrontpage extends JModelList +class ContentModelFrontpage extends ContentModelArticles { /** * Model context string. * * @var string */ - public $_context = 'com_content.articles'; - + public $_context = 'com_content.frontpage'; /** - * Overridden method to lazy load data from the request/session as necessary + * Method to auto-populate the model state. * - * @access public - * @param string $key The key of the state item to return - * @param mixed $default The default value to return if it does not exist - * @return mixed The requested value by key - * @since 1.0 + * @since 1.6 */ - function _populateState() + protected function _populateState() { - $app = &JFactory::getApplication(); - - // List state information - $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit')); - $this->setState('list.limit', $limit); - - $limitstart = $app->getUserStateFromRequest($this->_context.'.limitstart', 'limitstart', 0); - $this->setState('list.limitstart', $limitstart); - - $orderCol = $app->getUserStateFromRequest($this->_context.'.ordercol', 'filter_order', 'a.title'); - $this->setState('list.ordering', $orderCol); - - $orderDirn = $app->getUserStateFromRequest($this->_context.'.orderdirn', 'filter_order_Dir', 'asc'); - $this->setState('list.direction', $orderDirn); - - $params = $app->getParams(); - $this->setState('params', $params); + parent::_populateState(); $this->setState('filter.frontpage', true); - - // TODO: Tune these values based on other permissions. - $this->setState('filter.published', 1); - $this->setState('filter.access', true); } /** @@ -76,161 +51,29 @@ function _populateState() * * @return string A store id. */ - public function _getStoreId($id = '') + protected function _getStoreId($id = '') { // Compile the store id. - $id .= ':'.$this->getState('list.start'); - $id .= ':'.$this->getState('list.limit'); - $id .= ':'.$this->getState('list.ordering'); - $id .= ':'.$this->getState('list.direction'); - $id .= ':'.$this->getState('filter.published'); + $id = parent::_getStoreId($id); $id .= ':'.$this->getState('filter.frontpage'); return md5($id); } /** - * @param boolean True to join selected foreign information - * - * @return string + * @return JQuery */ - function _getListQuery($resolveFKs = true) + function _getListQuery() { -/* - $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,' . - ' 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,' . - ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug,'. - ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug,'. - ' CHAR_LENGTH(a.`fulltext`) AS readmore,' . - ' u.name AS author, u.usertype, 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'. - $voting['select'] . - ' FROM #__content AS a' . - ' INNER JOIN #__content_frontpage AS f ON f.content_id = a.id' . - ' LEFT JOIN #__categories AS cc ON cc.id = a.catid'. - ' LEFT JOIN #__sections AS s ON s.id = a.sectionid'. - ' LEFT JOIN #__users AS u ON u.id = a.created_by' . - $voting['join']. - $where - .$orderby - ; - - global $mainframe; - // Get the page/component configuration - $params = &$mainframe->getParams(); - if (!is_object($params)) { - $params = &JComponentHelper::getParams('com_content'); - } - - $orderby_sec = $params->def('orderby_sec', ''); - $orderby_pri = $params->def('orderby_pri', ''); - $secondary = ContentHelperQuery::orderbySecondary($orderby_sec); - $primary = ContentHelperQuery::orderbyPrimary($orderby_pri); - - $orderby = ' ORDER BY '.$primary.' '.$secondary; - - return $orderby; -*/ // Create a new query object. - $query = new JQuery; - - // Select the required fields from the table. - $query->select($this->getState( - 'list.select', - 'a.id, a.title, a.alias, a.title_alias, a.introtext, a.state, a.catid, a.created, a.created_by, a.created_by_alias,' . - ' a.modified, a.modified_by,a.publish_up, a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access,' . - ' LENGTH(a.fulltext) AS readmore' - )); - $query->from('#__content AS a'); - - // Join over the categories. - $query->select('c.title AS category_title, c.alias AS category_alias, c.access AS category_access'); - $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); - - // Join over the users for the author. - $query->select('ua.name AS author_name'); - $query->join('LEFT', '#__users AS ua ON ua.id = a.created_by'); - - // Filter by access level. - if ($access = $this->getState('filter.access')) - { - $user = &JFactory::getUser(); - $groups = implode(',', $user->authorisedLevels()); - $query->where('a.access IN ('.$groups.')'); - $query->where('(c.access IS NULL OR c.access IN ('.$groups.'))'); - } - - // Filter by published state. - $published = $this->getState('filter.published'); - if (is_numeric($published)) { - $query->where('a.state = ' . (int) $published); - } - else if (is_array($published)) - { - JArrayHelper::toInteger($published); - $query->where('a.state IN ('.$published.')'); - } + $query = parent::_getListQuery(); // Filter by frontpage. if ($this->getState('filter.frontpage')) { $query->join('INNER', '#__content_frontpage AS fp ON fp.content_id = a.id'); } - // Filter by start and end dates. - $nullDate = $this->_db->Quote($this->_db->getNullDate()); - $nowDate = $this->_db->Quote(JFactory::getDate()->toMySQL()); - - $query->where('(a.publish_up = '.$nullDate.' OR a.publish_up <= '.$nowDate.')'); - $query->where('(a.publish_down = '.$nullDate.' OR a.publish_down >= '.$nowDate.')'); - - // Add the list ordering clause. - $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.title')).' '.$this->_db->getEscaped($this->getState('list.direction', 'ASC'))); - //echo nl2br(str_replace('#__','jos_',$query)); return $query; } - - /** - * Method to get a list of articles. - * - * Overriden to inject convert the attribs field into a JParameter object. - * - * @return mixed An array of objects on success, false on failure. - */ - public function &getItems() - { - $items = &parent::getItems(); - $user = &JFactory::getUser(); - $groups = $user->authorisedLevels(); - - // Contvert the parameter fields into objects. - foreach ($items as &$item) - { - $registry = new JRegistry; - $registry->loadJSON($item->attribs); - $item->params = clone $this->getState('params'); - $item->params->merge($registry); - - // TODO: Embed the access controls in here - $item->params->set('access-edit', false); - - $access = $this->getState('filter.access'); - if ($access = $this->getState('filter.access')) - { - // If the access filter has been set, we already have only the articles this user can view. - $item->params->set('access-view', true); - } - else - { - // If no access filter is set, the layout takes some responsibility for display of limited information. - if ($item->catid == 0 || $item->category_access === null) { - $item->params->set('access-view', in_array($item->access, $groups)); - } - else { - $item->params->set('access-view', in_array($item->access, $groups) && in_array($item->category_access, $groups)); - } - } - } - - return $items; - } } diff --git a/components/com_content/router.php b/components/com_content/router.php index d4f38c10b8d87..735fe440a606d 100644 --- a/components/com_content/router.php +++ b/components/com_content/router.php @@ -28,7 +28,7 @@ class ContentRoute public static function article($id, $categoryId = null) { $needles = array( - 'article' => (int) $id, + 'article' => (int) $id, 'category' => (int) $categoryId ); @@ -236,47 +236,56 @@ function ContentParseRoute($segments) { $vars = array(); - //Get the active menu item + //G et the active menu item. $menu = &JSite::getMenu(); $item = &$menu->getActive(); // Count route segments $count = count($segments); - //Standard routing for articles + // Standard routing for articles. if (!isset($item)) { - $vars['view'] = $segments[0]; - $vars['id'] = $segments[$count - 1]; + $vars['view'] = $segments[0]; + $vars['id'] = $segments[$count - 1]; return $vars; } - //Handle View and Identifier - switch($item->query['view']) + // Handle View and Identifier. + switch ($item->query['view']) { + case 'categories': + // From the categories view, we can only jump to a category. + // 123-path/to/category + $vars['id'] = $segments[0]; + $vars['view'] = 'category'; + break; + case 'category': - $vars['id'] = $segments[$count-1]; - $vars['view'] = 'article'; + $vars['id'] = $segments[$count-1]; + $vars['view'] = 'article'; break; case 'frontpage': - $vars['id'] = $segments[$count-1]; - $vars['view'] = 'article'; + $vars['id'] = $segments[$count-1]; + $vars['view'] = 'article'; break; case 'article': - $vars['id'] = $segments[$count-1]; - $vars['view'] = 'article'; + $vars['id'] = $segments[$count-1]; + $vars['view'] = 'article'; break; case 'archive': if ($count != 1) { - $vars['year'] = $count >= 2 ? $segments[$count-2] : null; + $vars['year'] = $count >= 2 ? $segments[$count-2] : null; $vars['month'] = $segments[$count-1]; - $vars['view'] = 'archive'; - } else { - $vars['id'] = $segments[$count-1]; + $vars['view'] = 'archive'; + } + else + { + $vars['id'] = $segments[$count-1]; $vars['view'] = 'article'; } break; diff --git a/components/com_content/views/categories/tmpl/default.php b/components/com_content/views/categories/tmpl/default.php index a1683a83b5e3a..1274662fa1829 100644 --- a/components/com_content/views/categories/tmpl/default.php +++ b/components/com_content/views/categories/tmpl/default.php @@ -29,9 +29,13 @@
    items as &$item) : ?>
  1. - + escape($item->title); ?>
+ + + + diff --git a/components/com_content/views/categories/view.html.php b/components/com_content/views/categories/view.html.php index a7cd43c42104b..5036ead6d5ef2 100644 --- a/components/com_content/views/categories/view.html.php +++ b/components/com_content/views/categories/view.html.php @@ -52,9 +52,8 @@ function display($tpl = null) // Compute the weblink slug and prepare description (runs content plugins). foreach ($items as $i => &$item) { - $item->slug = $item->path ? ($item->id.':'.$item->path) : $item->id; - - $item->description = JHtml::_('content.prepare', $item->description); + $item->slug = $item->route ? ($item->id.':'.$item->route) : $item->id; + $item->description = JHtml::_('content.prepare', $item->description); } $this->assignRef('params', $params); diff --git a/components/com_content/views/category/tmpl/default.php b/components/com_content/views/category/tmpl/default.php index a9bb607665a67..795d2784a9491 100644 --- a/components/com_content/views/category/tmpl/default.php +++ b/components/com_content/views/category/tmpl/default.php @@ -10,44 +10,35 @@ // no direct access defined('_JEXEC') or die; -$cparams =& JComponentHelper::getParams('com_media'); +JHtml::addIncludePath(JPATH_COMPONENT.DS.'helpers'); + +// If the page class is defined, wrap the whole output in a div. +$pageClass = $this->params->get('pageclass_sfx'); ?> + +
+ + params->get('show_page_title', 1)) : ?> -
+

escape($this->params->get('page_title')); ?> -

+ - - - - - - - - - - -
- category->description; ?> -
-
    - children as $child) - { - echo '
  • '.$child->title.' ('.$child->numitems.')
  • '; - } - ?> -
-
- items = &$this->getItems(); - if (count($this->items)) - { - echo $this->loadTemplate('items'); - } - ?> - - access->canEdit || $this->access->canEditOwn) : - echo JHtml::_('icon.create', $this->category , $this->params, $this->access); - endif; ?> -
+ +

+ escape($this->item->title); ?> +

+ +item->description; ?> + +loadTemplate('articles'); ?> + +loadTemplate('siblings'); ?> + +loadTemplate('children'); ?> + +loadTemplate('parents'); ?> + + +
+ \ No newline at end of file diff --git a/components/com_content/views/category/tmpl/default_articles.php b/components/com_content/views/category/tmpl/default_articles.php new file mode 100644 index 0000000000000..9b3b1070ce948 --- /dev/null +++ b/components/com_content/views/category/tmpl/default_articles.php @@ -0,0 +1,28 @@ + +articles)) : ?> + no articles + + + + articles as &$item) : ?> + + + + +
+ + title; ?> +
+ + diff --git a/components/com_content/views/category/tmpl/default_children.php b/components/com_content/views/category/tmpl/default_children.php new file mode 100644 index 0000000000000..bebee5d1fa669 --- /dev/null +++ b/components/com_content/views/category/tmpl/default_children.php @@ -0,0 +1,26 @@ + +children)) : ?> + no children + +
Children
+
    + children as &$item) : ?> +
  1. + + escape($item->title); ?> +
  2. + +
+ + \ No newline at end of file diff --git a/components/com_content/views/category/tmpl/default_items.php b/components/com_content/views/category/tmpl/default_items.php deleted file mode 100644 index cdfdd385a90aa..0000000000000 --- a/components/com_content/views/category/tmpl/default_items.php +++ /dev/null @@ -1,138 +0,0 @@ - - -
- -params->get('filter') || $this->params->get('show_pagination_limit')) : ?> - - - - -params->get('show_headings')) : ?> - - - params->get('show_title')) : ?> - - - params->get('show_date')) : ?> - - - params->get('show_author')) : ?> - - - params->get('show_hits')) : ?> - - - - -items as $item) : ?> - - - params->get('show_title')) : ?> - readmore_register) : ?> - - - - - - params->get('show_date')) : ?> - - - params->get('show_author')) : ?> - - - params->get('show_hits')) : ?> - - - - -params->get('show_pagination')) : ?> - - - - - - - - - - -
- - - params->get('filter')) : ?> - - - params->get('show_pagination_limit')) : ?> - - - -
- - - - pagination->getLimitBox(); - ?> -
-
- - - lists['order_Dir'], $this->lists['order']); ?> - - lists['order_Dir'], $this->lists['order']); ?> - - lists['order_Dir'], $this->lists['order']); ?> - - lists['order_Dir'], $this->lists['order']); ?> -
- pagination->getRowOffset($item->count); ?> - - - title; ?> - item = $item; echo JHtml::_('icon.edit', $item, $this->params, $this->access) ?> - - escape($item->title).' : '; - $link = JRoute::_('index.php?option=com_user&task=register'); - ?> - - - - created; ?> - - created_by_alias ? $item->created_by_alias : $item->author; ?> - - hits ? $item->hits : '-'; ?> -
 
- pagination->getPagesLinks(); ?> -
- pagination->getPagesCounter(); ?> -
- - - - - -
diff --git a/components/com_content/views/category/tmpl/default_parents.php b/components/com_content/views/category/tmpl/default_parents.php new file mode 100644 index 0000000000000..0c4427522cbd7 --- /dev/null +++ b/components/com_content/views/category/tmpl/default_parents.php @@ -0,0 +1,26 @@ + +parents)) : ?> + no parents + +
Parents
+
    + parents as &$item) : ?> +
  1. + + escape($item->title); ?> +
  2. + +
+ + diff --git a/components/com_content/views/category/tmpl/default_siblings.php b/components/com_content/views/category/tmpl/default_siblings.php new file mode 100644 index 0000000000000..167159f263134 --- /dev/null +++ b/components/com_content/views/category/tmpl/default_siblings.php @@ -0,0 +1,30 @@ + +siblings)) : ?> + no siblings + +
Siblings
+
    + siblings as &$item) : ?> +
  1. + id != $this->item->id) : ?> + + escape($item->title); ?> + + escape($item->title); ?> + +
  2. + +
+ + diff --git a/components/com_content/views/category/view.html.php b/components/com_content/views/category/view.html.php index 659a4ea285ca3..d6bee22407f52 100644 --- a/components/com_content/views/category/view.html.php +++ b/components/com_content/views/category/view.html.php @@ -8,7 +8,7 @@ // No direct access defined('_JEXEC') or die; -require_once JPATH_COMPONENT.DS.'view.php'; +jimport('joomla.application.component.view'); /** * HTML View class for the Content component @@ -17,294 +17,155 @@ * @subpackage com_content * @since 1.5 */ -class ContentViewCategory extends ContentView +class ContentViewCategory extends JView { - protected $_params = null; - public $total = null; - public $access = null; - public $action = null; - public $items = null; - public $item = null; - public $params = null; - public $category = null; - public $user = null; - public $pagination = null; - public $lists = null; - public $links = array(); + protected $state = null; + protected $item = null; + protected $articles = null; + protected $pagination = null; function display($tpl = null) { - $mainframe = JFactory::getApplication(); - $option = JRequest::getCmd('option'); - - // Initialize some variables + // Initialize variables $user = &JFactory::getUser(); - $uri = &JFactory::getURI(); - $document = &JFactory::getDocument(); - $pathway = &$mainframe->getPathway(); - - // Get the menu item object - $menus = &JSite::getMenu(); - $menu = $menus->getActive(); - - // Get the page/component configuration - $params = clone($mainframe->getParams('com_content')); + $app = &JFactory::getApplication(); + + $state = $this->get('State'); + $item = $this->get('Item'); + $articles = $this->get('Articles'); + $siblings = $this->get('Siblings'); + $children = $this->get('Children'); + $parents = $this->get('Parents'); + //$pagination = $this->get('Pagination'); + + // Check for errors. + if (count($errors = $this->get('Errors'))) { + JError::raiseWarning(500, implode("\n", $errors)); + return false; + } - // Request variables - $layout = JRequest::getCmd('layout'); - $task = JRequest::getCmd('task'); + $params = &$state->params; - // Parameters - $params->def('num_leading_articles', 1); - $params->def('num_intro_articles', 4); - $params->def('num_columns', 2); - $params->def('num_links', 4); - $params->def('show_headings', 1); - $params->def('show_pagination', 2); - $params->def('show_pagination_results', 1); - $params->def('show_pagination_limit', 1); - $params->def('filter', 1); + // PREPARE THE DATA - $intro = $params->get('num_intro_articles'); - $leading = $params->get('num_leading_articles'); - $links = $params->get('num_links'); + // Compute the category slug and prepare description (runs content plugins). + $item->slug = $item->path ? ($item->id.':'.$item->path) : $item->id; + $item->description = JHtml::_('content.prepare', $item->description); - $limitstart = JRequest::getVar('limitstart', 0, '', 'int'); + // Compute the article slugs and prepare introtext (runs content plugins). + foreach ($articles as $i => &$article) + { + $article->slug = $article->alias ? ($article->id.':'.$article->alias) : $article->id; + $article->catslug = $article->category_route ? ($article->catid.':'.$article->category_route) : $article->catid; + $article->event = new stdClass(); - if ($layout == 'blog') { - $default_limit = $intro + $leading + $links; - } else { - $params->def('display_num', $mainframe->getCfg('list_limit')); - $default_limit = $params->get('display_num'); - } - $limit = $mainframe->getUserStateFromRequest('com_content.'.$this->getLayout().'.limit', 'limit', $default_limit, 'int'); + $dispatcher = &JDispatcher::getInstance(); - JRequest::setVar('limit', (int) $limit); + // Ignore content plugins on links. + //if ($i < $numLeading + $numIntro) + //{ + $article->introtext = JHtml::_('content.prepare', $article->introtext); - $contentConfig = &JComponentHelper::getParams('com_content'); - $params->def('show_page_title', $contentConfig->get('show_title')); + $results = $dispatcher->trigger('onAfterDisplayTitle', array (&$article, &$article->params, 0)); + $article->event->afterDisplayTitle = trim(implode("\n", $results)); - // Get some data from the model - $items = & $this->get('Data'); - $total = & $this->get('Total'); - $category = & $this->get('Category'); + $results = $dispatcher->trigger('onBeforeDisplayContent', array (&$article, &$article->params, 0)); + $article->event->beforeDisplayContent = trim(implode("\n", $results)); - //add alternate feed link - if ($params->get('show_feed_link', 1) == 1) - { - $link = '&format=feed&limitstart='; - $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0'); - $document->addHeadLink(JRoute::_($link.'&type=rss'), 'alternate', 'rel', $attribs); - $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0'); - $document->addHeadLink(JRoute::_($link.'&type=atom'), 'alternate', 'rel', $attribs); + $results = $dispatcher->trigger('onAfterDisplayContent', array (&$article, &$article->params, 0)); + $article->event->afterDisplayContent = trim(implode("\n", $results)); + //} } - // Create a user access object for the user - $access = new stdClass(); - $access->canEdit = $user->authorize('com_content.article.edit_article'); - $access->canEditOwn = $user->authorize('com_content.article.edit_own'); - $access->canPublish = $user->authorize('com_content.article.publish'); - - // Set page title per category - // because the application sets a default page title, we need to get it - // right from the menu item itself - if (is_object($menu)) { - $menu_params = new JParameter($menu->params); - if (!$menu_params->get('page_title')) { - $params->set('page_title', $category->title); - } - } else { - $params->set('page_title', $category->title); + // Compute the sibling category slugs and prepare description (runs content plugins). + foreach ($siblings as $i => &$sibling) + { + $sibling->slug = $sibling->route ? ($sibling->id.':'.$sibling->route) : $item->id; + $sibling->description = JHtml::_('content.prepare', $sibling->description); } - $document->setTitle($params->get('page_title')); - //set breadcrumbs - $pathwaycat = $category; - $path = array(); - if (is_object($menu) && $menu->query['id'] != $category->id) + // Compute the sibling category slugs and prepare description (runs content plugins). + foreach ($children as $i => &$child) { - $path[] = array($pathwaycat->title); - $pathwaycat = $pathwaycat->getParent(); - while($pathwaycat->id != $menu->query['id']) - { - $path[] = array($pathwaycat->title, $pathwaycat->slug); - $pathwaycat = $pathwaycat->getParent(); - } - $path = array_reverse($path); - foreach($path as $element) - { - if (isset($element[1])) - { - $pathway->addItem($element[0], 'index.php?option=com_content&view=category&id='.$element[1]); - } else { - $pathway->addItem($element[0], ''); - } - } + $child->slug = $child->route ? ($child->id.':'.$child->route) : $child->id; + $child->description = JHtml::_('content.prepare', $child->description); } - // Prepare category description - $category->description = JHtml::_('content.prepare', $category->description); - - $params->def('date_format', JText::_('DATE_FORMAT_LC1')); - // Keep a copy for safe keeping this is soooooo dirty -- must deal with in a later version - // @todo -- oh my god we need to find this reference issue in 1.6 :) - $this->_params = $params->toArray(); - - jimport('joomla.html.pagination'); - //In case we are in a blog view set the limit - if ($layout == 'blog') { - $pagination = new JPagination($total, $limitstart, $limit - $links); - } else { - $pagination = new JPagination($total, $limitstart, $limit); + // Compute the parent category slugs. + foreach ($parents as $i => &$parent) + { + $parent->slug = $parent->route ? ($parent->id.':'.$parent->route) : $parent->id; } - $children = $this->get('Children'); - - $this->assign('total', $total); - $this->assign('action', $uri->toString()); - - $this->assignRef('items', $items); $this->assignRef('params', $params); - $this->assignRef('category', $category); - $this->assignRef('children', $children); + $this->assignRef('item', $item); + $this->assignRef('articles', $articles); + $this->assignRef('siblings', $siblings); + $this->assignRef('children', $children); + $this->assignRef('parents', $parents); + //$this->assignRef('pagination', $pagination); $this->assignRef('user', $user); - $this->assignRef('access', $access); - $this->assignRef('pagination', $pagination); + + $this->_prepareDocument(); + parent::display($tpl); } - function &getItems() + /** + * Prepares the document + */ + protected function _prepareDocument() { - $mainframe = JFactory::getApplication(); - - //create select lists - $user = &JFactory::getUser(); - $groups = $user->authorisedLevels(); - $lists = $this->_buildSortLists(); - - if (!count($this->items)) + $app = &JFactory::getApplication(); + $menus = &JSite::getMenu(); + $pathway = &$app->getPathway(); + $title = $this->item->title; + + // Because the application sets a default page title, + // we need to get it from the menu item itself. + if ($menu = $menus->getActive()) { - $this->assign('lists', $lists); - $return = array(); - return $return; + $menuParams = new JObject(json_decode($menu->params, true)); + if ($pageTitle = $menuParams->get('page_title')) { + $title = $pageTitle; + } } - - //create paginatiion - if ($lists['filter']) { - $this->data->link .= '&filter='.$lists['filter']; + if (empty($title)) { + $title = htmlspecialchars_decode($app->getCfg('sitename')); } + $this->document->setTitle($title); - $k = 0; - $i = 0; - foreach($this->items as $key => $item) + // Add feed links. + if ($this->params->get('show_feed_link', 1)) { - // checks if the item is a public or registered/special item - if (in_array($item->access, $groups)) - { - $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug)); - $item->readmore_register = false; - } - else - { - $item->link = JRoute::_('index.php?option=com_user&task=register'); - $item->readmore_register = true; - } - if ($user->authorize('com_content.article.edit_article')) - { - $item->edit = $user->authorize('com_content.article.edit', 'article.'.$item->id); - } else { - $item->edit = false; - } - $item->created = JHtml::_('date', $item->created, $this->params->get('date_format')); + $link = '&format=feed&limitstart='; - $item->odd = $k; - $item->count = $i; + $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0'); + $this->document->addHeadLink(JRoute::_($link.'&type=rss'), 'alternate', 'rel', $attribs); - $this->items[$key] = $item; - $k = 1 - $k; - $i++; + $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0'); + $this->document->addHeadLink(JRoute::_($link.'&type=atom'), 'alternate', 'rel', $attribs); } - $this->assign('lists', $lists); - - return $this->items; - } - - function &getItem($index = 0, &$params) - { - $mainframe = JFactory::getApplication(); - - // Initialize some variables - $user = &JFactory::getUser(); - $dispatcher = &JDispatcher::getInstance(); - - $SiteName = $mainframe->getCfg('sitename'); + // Set the pathway. + $path = array(); - $item = &$this->items[$index]; - $item->text = $item->introtext; - if ($user->authorize('com_content.article.edit_article')) + if ($menu && isset($menu->query)) { - $item->edit = $user->authorize('com_content.article.edit', 'article.'.$item->id); - } else { - $item->edit = false; - } - $category = & $this->get('Category'); - $item->category = $category->title; - - // Get the page/component configuration and article parameters - $item->params = clone($params); - $aparams = new JParameter($item->attribs); + $view = JArrayHelper::getValue($menu->query, 'view'); + $id = JArrayHelper::getValue($menu->query, 'id'); - // Merge article parameters into the page configuration - $item->params->merge($aparams); - - // Process the content preparation plugins - JPluginHelper::importPlugin('content'); - $results = $dispatcher->trigger('onPrepareContent', array (& $item, & $item->params, 0)); - - // Build the link and text of the readmore button - if (($item->params->get('show_readmore') && @ $item->readmore) || $item->params->get('link_titles')) - { - // checks if the item is a public or registered/special item - if (in_array($item->access, $user->authorisedLevels())) - { - //$item->readmore_link = JRoute::_('index.php?view=article&catid='.$this->category->slug.'&id='.$item->slug); - $item->readmore_link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug)); - $item->readmore_register = false; - } - else + if ($view != 'category' || ($view == 'category' && $id != $this->item->id)) { - $item->readmore_link = JRoute::_("index.php?option=com_user&task=register"); - $item->readmore_register = true; + foreach($this->parents as $parent) + { + $pathway->addItem( + $parent->title, + ContentRoute::category($parent->slug) + ); + } + $pathway->addItem($this->item->title); } } - - $item->event = new stdClass(); - $results = $dispatcher->trigger('onAfterDisplayTitle', array (& $item, & $item->params,0)); - $item->event->afterDisplayTitle = trim(implode("\n", $results)); - - $results = $dispatcher->trigger('onBeforeDisplayContent', array (& $item, & $item->params, 0)); - $item->event->beforeDisplayContent = trim(implode("\n", $results)); - - $results = $dispatcher->trigger('onAfterDisplayContent', array (& $item, & $item->params, 0)); - $item->event->afterDisplayContent = trim(implode("\n", $results)); - - return $item; - } - - function _buildSortLists() - { - // Table ordering values - $filter = JRequest::getString('filter'); - $filter_order = JRequest::getCmd('filter_order'); - $filter_order_Dir = JRequest::getCmd('filter_order_Dir'); - - $lists['task'] = 'category'; - $lists['filter'] = $filter; - $lists['order'] = $filter_order; - $lists['order_Dir'] = $filter_order_Dir; - - return $lists; } } -?> diff --git a/components/com_content/views/frontpage/tmpl/default_item.php b/components/com_content/views/frontpage/tmpl/default_item.php index 8e1d9806e2a68..9b414915ccff3 100644 --- a/components/com_content/views/frontpage/tmpl/default_item.php +++ b/components/com_content/views/frontpage/tmpl/default_item.php @@ -54,7 +54,7 @@ get('show_category')) : ?> get('link_category')) : ?> - item->catslug, $this->item->sectionid)).'">'; ?> + item->catslug)).'">'; ?> escape($this->item->category); ?> escape($this->item->category); ?> diff --git a/components/com_content/views/frontpage/tmpl/default_links.php b/components/com_content/views/frontpage/tmpl/default_links.php index 597cb0aaf5496..5e4a1aad80a98 100644 --- a/components/com_content/views/frontpage/tmpl/default_links.php +++ b/components/com_content/views/frontpage/tmpl/default_links.php @@ -15,7 +15,7 @@