[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Site 5 * @subpackage com_content 6 * 7 * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Content\Site\View\Category; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\MVC\View\CategoryView; 15 use Joomla\CMS\Plugin\PluginHelper; 16 use Joomla\Component\Content\Site\Helper\RouteHelper; 17 use Joomla\Registry\Registry; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('_JEXEC') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * HTML View class for the Content component 25 * 26 * @since 1.5 27 */ 28 class HtmlView extends CategoryView 29 { 30 /** 31 * @var array Array of leading items for blog display 32 * @since 3.2 33 */ 34 protected $lead_items = array(); 35 36 /** 37 * @var array Array of intro items for blog display 38 * @since 3.2 39 */ 40 protected $intro_items = array(); 41 42 /** 43 * @var array Array of links in blog display 44 * @since 3.2 45 */ 46 protected $link_items = array(); 47 48 /** 49 * @var string The name of the extension for the category 50 * @since 3.2 51 */ 52 protected $extension = 'com_content'; 53 54 /** 55 * @var string Default title to use for page title 56 * @since 3.2 57 */ 58 protected $defaultPageTitle = 'JGLOBAL_ARTICLES'; 59 60 /** 61 * @var string The name of the view to link individual items to 62 * @since 3.2 63 */ 64 protected $viewName = 'article'; 65 66 /** 67 * Execute and display a template script. 68 * 69 * @param string $tpl The name of the template file to parse; automatically searches through the template paths. 70 * 71 * @return void 72 */ 73 public function display($tpl = null) 74 { 75 parent::commonCategoryDisplay(); 76 77 // Flag indicates to not add limitstart=0 to URL 78 $this->pagination->hideEmptyLimitstart = true; 79 80 // Prepare the data 81 // Get the metrics for the structural page layout. 82 $params = $this->params; 83 $numLeading = $params->def('num_leading_articles', 1); 84 $numIntro = $params->def('num_intro_articles', 4); 85 $numLinks = $params->def('num_links', 4); 86 $this->vote = PluginHelper::isEnabled('content', 'vote'); 87 88 PluginHelper::importPlugin('content'); 89 90 $app = Factory::getApplication(); 91 92 // Compute the article slugs and prepare introtext (runs content plugins). 93 foreach ($this->items as $item) { 94 $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; 95 96 // No link for ROOT category 97 if ($item->parent_alias === 'root') { 98 $item->parent_id = null; 99 } 100 101 $item->event = new \stdClass(); 102 103 // Old plugins: Ensure that text property is available 104 if (!isset($item->text)) { 105 $item->text = $item->introtext; 106 } 107 108 $app->triggerEvent('onContentPrepare', array('com_content.category', &$item, &$item->params, 0)); 109 110 // Old plugins: Use processed text as introtext 111 $item->introtext = $item->text; 112 113 $results = $app->triggerEvent('onContentAfterTitle', array('com_content.category', &$item, &$item->params, 0)); 114 $item->event->afterDisplayTitle = trim(implode("\n", $results)); 115 116 $results = $app->triggerEvent('onContentBeforeDisplay', array('com_content.category', &$item, &$item->params, 0)); 117 $item->event->beforeDisplayContent = trim(implode("\n", $results)); 118 119 $results = $app->triggerEvent('onContentAfterDisplay', array('com_content.category', &$item, &$item->params, 0)); 120 $item->event->afterDisplayContent = trim(implode("\n", $results)); 121 } 122 123 // For blog layouts, preprocess the breakdown of leading, intro and linked articles. 124 // This makes it much easier for the designer to just interrogate the arrays. 125 if ($params->get('layout_type') === 'blog' || $this->getLayout() === 'blog') { 126 foreach ($this->items as $i => $item) { 127 if ($i < $numLeading) { 128 $this->lead_items[] = $item; 129 } elseif ($i >= $numLeading && $i < $numLeading + $numIntro) { 130 $this->intro_items[] = $item; 131 } elseif ($i < $numLeading + $numIntro + $numLinks) { 132 $this->link_items[] = $item; 133 } 134 } 135 } 136 137 // Because the application sets a default page title, 138 // we need to get it from the menu item itself 139 $active = $app->getMenu()->getActive(); 140 141 if ($this->menuItemMatchCategory) { 142 $this->params->def('page_heading', $this->params->get('page_title', $active->title)); 143 $title = $this->params->get('page_title', $active->title); 144 } else { 145 $this->params->def('page_heading', $this->category->title); 146 $title = $this->category->title; 147 $this->params->set('page_title', $title); 148 } 149 150 if (empty($title)) { 151 $title = $this->category->title; 152 } 153 154 $this->setDocumentTitle($title); 155 156 if ($this->category->metadesc) { 157 $this->document->setDescription($this->category->metadesc); 158 } elseif ($this->params->get('menu-meta_description')) { 159 $this->document->setDescription($this->params->get('menu-meta_description')); 160 } 161 162 if ($this->params->get('robots')) { 163 $this->document->setMetaData('robots', $this->params->get('robots')); 164 } 165 166 if (!is_object($this->category->metadata)) { 167 $this->category->metadata = new Registry($this->category->metadata); 168 } 169 170 if (($app->get('MetaAuthor') == '1') && $this->category->get('author', '')) { 171 $this->document->setMetaData('author', $this->category->get('author', '')); 172 } 173 174 $mdata = $this->category->metadata->toArray(); 175 176 foreach ($mdata as $k => $v) { 177 if ($v) { 178 $this->document->setMetaData($k, $v); 179 } 180 } 181 182 parent::display($tpl); 183 } 184 185 /** 186 * Prepares the document 187 * 188 * @return void 189 */ 190 protected function prepareDocument() 191 { 192 parent::prepareDocument(); 193 194 parent::addFeed(); 195 196 if ($this->menuItemMatchCategory) { 197 // If the active menu item is linked directly to the category being displayed, no further process is needed 198 return; 199 } 200 201 // Get ID of the category from active menu item 202 $menu = $this->menu; 203 204 if ( 205 $menu && $menu->component == 'com_content' && isset($menu->query['view']) 206 && in_array($menu->query['view'], ['categories', 'category']) 207 ) { 208 $id = $menu->query['id']; 209 } else { 210 $id = 0; 211 } 212 213 $path = [['title' => $this->category->title, 'link' => '']]; 214 $category = $this->category->getParent(); 215 216 while ($category !== null && $category->id !== 'root' && $category->id != $id) { 217 $path[] = ['title' => $category->title, 'link' => RouteHelper::getCategoryRoute($category->id, $category->language)]; 218 $category = $category->getParent(); 219 } 220 221 $path = array_reverse($path); 222 223 foreach ($path as $item) { 224 $this->pathway->addItem($item['title'], $item['link']); 225 } 226 } 227 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |