- md5
- d803af7cf1de9e772161019ee63976ca
- sha1
- 6ded9309d81442bf6f305723390f51b9e36f33a8
- sha256
- 929b892201e0a8b0cefe7c228f2a3e26869fb38c8aca60f16ba41dffe177fc36
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\MVC\View;
use Joomla\CMS\Categories\CategoryNode;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Base HTML View class for the a Category list
*
* @since 3.2
*/
class CategoryView extends HtmlView
{
/**
* State data
*
* @var \Joomla\Registry\Registry
* @since 3.2
*/
protected $state;
/**
* The page parameters
*
* @var \Joomla\Registry\Registry
*
* @since 5.2.0
*/
public $params;
/**
* Category items data
*
* @var array
* @since 3.2
*/
protected $items;
/**
* The category model object for this category
*
* @var CategoryNode
* @since 3.2
*/
protected $category;
/**
* The list of other categories for this extension.
*
* @var array
* @since 3.2
*/
protected $categories;
/**
* Pagination object
*
* @var \Joomla\CMS\Pagination\Pagination
* @since 3.2
*/
protected $pagination;
/**
* Child objects
*
* @var array
* @since 3.2
*/
protected $children;
/**
* The name of the extension for the category
*
* @var string
* @since 3.2
*/
protected $extension;
/**
* The name of the view to link individual items to
*
* @var string
* @since 3.2
*/
protected $viewName;
/**
* Default title to use for page title
*
* @var string
* @since 3.2
*/
protected $defaultPageTitle;
/**
* Whether to run the standard Joomla plugin events.
* Off by default for b/c
*
* @var boolean
* @since 3.5
*/
protected $runPlugins = false;
/**
* The flag to mark if the active menu item is linked to the category being displayed
*
* @var bool
* @since 4.0.0
*/
protected $menuItemMatchCategory = false;
/**
* Method with common display elements used in category list displays
*
* @return void
*
* @since 3.2
*/
public function commonCategoryDisplay()
{
$app = Factory::getApplication();
$user = $this->getCurrentUser();
$params = $app->getParams();
// Get some data from the models
$model = $this->getModel();
$paramsModel = $model->getState('params');
$paramsModel->set('check_access_rights', 0);
$model->setState('params', $paramsModel);
$state = $this->get('State');
$category = $this->get('Category');
$children = $this->get('Children');
$parent = $this->get('Parent');
if (!$category) {
throw new \InvalidArgumentException(Text::_('JGLOBAL_CATEGORY_NOT_FOUND'), 404);
}
if (!$parent) {
throw new \InvalidArgumentException(Text::_('JGLOBAL_CATEGORY_NOT_FOUND'), 404);
}
// Check whether category access level allows access.
$groups = $user->getAuthorisedViewLevels();
if (!\in_array($category->access, $groups)) {
throw new \RuntimeException(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
$items = $this->get('Items');
$pagination = $this->get('Pagination');
// Check for errors.
if (\count($errors = $this->get('Errors'))) {
throw new GenericDataException(implode("\n", $errors), 500);
}
// Setup the category parameters.
$cparams = $category->getParams();
$category->params = clone $params;
$category->params->merge($cparams);
$children = [$category->id => $children];
// Escape strings for HTML output
$this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', ''));
if ($this->runPlugins) {
PluginHelper::importPlugin('content');
foreach ($items as $itemElement) {
$itemElement = (object) $itemElement;
$itemElement->event = new \stdClass();
// For some plugins.
!empty($itemElement->description) ? $itemElement->text = $itemElement->description : $itemElement->text = '';
Factory::getApplication()->triggerEvent('onContentPrepare', [$this->extension . '.category', $itemElement, $itemElement->params, 0]);
$results = Factory::getApplication()->triggerEvent(
'onContentAfterTitle',
[$this->extension . '.category', $itemElement, $itemElement->core_params ?? $itemElement->params, 0]
);
$itemElement->event->afterDisplayTitle = trim(implode("\n", $results));
$results = Factory::getApplication()->triggerEvent(
'onContentBeforeDisplay',
[$this->extension . '.category', $itemElement, $itemElement->core_params ?? $itemElement->params, 0]
);
$itemElement->event->beforeDisplayContent = trim(implode("\n", $results));
$results = Factory::getApplication()->triggerEvent(
'onContentAfterDisplay',
[$this->extension . '.category', $itemElement, $itemElement->core_params ?? $itemElement->params, 0]
);
$itemElement->event->afterDisplayContent = trim(implode("\n", $results));
if ($itemElement->text) {
$itemElement->description = $itemElement->text;
}
}
}
$maxLevel = $params->get('maxLevel', -1) < 0 ? PHP_INT_MAX : $params->get('maxLevel', PHP_INT_MAX);
$this->maxLevel = &$maxLevel;
$this->state = &$state;
$this->items = &$items;
$this->category = &$category;
$this->children = &$children;
$this->params = &$params;
$this->parent = &$parent;
$this->pagination = &$pagination;
$this->user = &$user;
// Check for layout override only if this is not the active menu item
// If it is the active menu item, then the view and category id will match
$active = $app->getMenu()->getActive();
if (
$active
&& $active->component == $this->extension
&& isset($active->query['view'], $active->query['id'])
&& $active->query['view'] === 'category'
&& $active->query['id'] == $this->category->id
) {
if (isset($active->query['layout'])) {
$this->setLayout($active->query['layout']);
}
$this->menuItemMatchCategory = true;
} elseif ($layout = $category->params->get('category_layout')) {
$this->setLayout($layout);
}
$this->category->tags = new TagsHelper();
$this->category->tags->getItemTags($this->extension . '.category', $this->category->id);
}
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*
* @since 3.2
* @throws \Exception
*/
public function display($tpl = null)
{
$this->prepareDocument();
parent::display($tpl);
}
/**
* Method to prepares the document
*
* @return void
*
* @since 3.2
*/
protected function prepareDocument()
{
$app = Factory::getApplication();
$this->pathway = $app->getPathway();
// Because the application sets a default page title, we need to get it from the menu item itself
$this->menu = $app->getMenu()->getActive();
if ($this->menu) {
$this->params->def('page_heading', $this->params->get('page_title', $this->menu->title));
} else {
$this->params->def('page_heading', Text::_($this->defaultPageTitle));
}
$this->setDocumentTitle($this->params->get('page_title', ''));
if ($this->params->get('menu-meta_description')) {
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
}
if ($this->params->get('robots')) {
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
}
}
/**
* Method to add an alternative feed link to a category layout.
*
* @return void
*
* @since 3.2
*/
protected function addFeed()
{
if ($this->params->get('show_feed_link', 1) == 1) {
$link = '&format=feed&limitstart=';
$attribs = ['type' => 'application/rss+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
$this->getDocument()->addHeadLink(Route::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
$attribs = ['type' => 'application/atom+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
$this->getDocument()->addHeadLink(Route::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
}
}
}
The same content is in 68 releases, Joomla 5.4.0-alpha1 to 6.2.0-alpha1. See them all, or every version of this file.