[ 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_tags 6 * 7 * @copyright (C) 2013 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\Tags\Site\View\Tag; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\MVC\View\GenericDataException; 15 use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; 16 use Joomla\CMS\Plugin\PluginHelper; 17 use Joomla\CMS\Router\Route; 18 use Joomla\CMS\User\User; 19 use Joomla\Registry\Registry; 20 21 // phpcs:disable PSR1.Files.SideEffects 22 \defined('_JEXEC') or die; 23 // phpcs:enable PSR1.Files.SideEffects 24 25 /** 26 * HTML View class for the Tags component 27 * 28 * @since 3.1 29 */ 30 class HtmlView extends BaseHtmlView 31 { 32 /** 33 * The model state 34 * 35 * @var \Joomla\CMS\Object\CMSObject 36 * 37 * @since 3.1 38 */ 39 protected $state; 40 41 /** 42 * List of items associated with the tag 43 * 44 * @var \stdClass[]|false 45 * 46 * @since 3.1 47 */ 48 protected $items; 49 50 /** 51 * Tag data for the current tag or tags (on success, false on failure) 52 * 53 * @var \Joomla\CMS\Object\CMSObject|boolean 54 * 55 * @since 3.1 56 */ 57 protected $item; 58 59 /** 60 * UNUSED 61 * 62 * @var null 63 * 64 * @since 3.1 65 */ 66 protected $children; 67 68 /** 69 * UNUSED 70 * 71 * @var null 72 * 73 * @since 3.1 74 */ 75 protected $parent; 76 77 /** 78 * The pagination object 79 * 80 * @var \Joomla\CMS\Pagination\Pagination 81 * 82 * @since 3.1 83 */ 84 protected $pagination; 85 86 /** 87 * The page parameters 88 * 89 * @var \Joomla\Registry\Registry|null 90 * 91 * @since 3.1 92 */ 93 protected $params; 94 95 /** 96 * Array of tags title 97 * 98 * @var array 99 * 100 * @since 3.1 101 */ 102 protected $tags_title; 103 104 /** 105 * The page class suffix 106 * 107 * @var string 108 * 109 * @since 4.0.0 110 */ 111 protected $pageclass_sfx = ''; 112 113 /** 114 * The logged in user 115 * 116 * @var User|null 117 * 118 * @since 4.0.0 119 */ 120 protected $user = null; 121 122 /** 123 * Execute and display a template script. 124 * 125 * @param string $tpl The name of the template file to parse; automatically searches through the template paths. 126 * 127 * @return void 128 * 129 * @since 3.1 130 */ 131 public function display($tpl = null) 132 { 133 $app = Factory::getApplication(); 134 $params = $app->getParams(); 135 136 // Get some data from the models 137 $state = $this->get('State'); 138 $items = $this->get('Items'); 139 $item = $this->get('Item'); 140 $children = $this->get('Children'); 141 $parent = $this->get('Parent'); 142 $pagination = $this->get('Pagination'); 143 144 // Flag indicates to not add limitstart=0 to URL 145 $pagination->hideEmptyLimitstart = true; 146 147 if (count($errors = $this->get('Errors'))) { 148 throw new GenericDataException(implode("\n", $errors), 500); 149 } 150 151 // Check whether access level allows access. 152 // @TODO: Should already be computed in $item->params->get('access-view') 153 $user = $this->getCurrentUser(); 154 $groups = $user->getAuthorisedViewLevels(); 155 156 foreach ($item as $itemElement) { 157 if (!in_array($itemElement->access, $groups)) { 158 unset($itemElement); 159 } 160 161 // Prepare the data. 162 if (!empty($itemElement)) { 163 $temp = new Registry($itemElement->params); 164 $itemElement->params = clone $params; 165 $itemElement->params->merge($temp); 166 $itemElement->params = (array) json_decode($itemElement->params); 167 $itemElement->metadata = new Registry($itemElement->metadata); 168 } 169 } 170 171 if ($items !== false) { 172 PluginHelper::importPlugin('content'); 173 174 foreach ($items as $itemElement) { 175 $itemElement->event = new \stdClass(); 176 177 // For some plugins. 178 !empty($itemElement->core_body) ? $itemElement->text = $itemElement->core_body : $itemElement->text = null; 179 180 $itemElement->core_params = new Registry($itemElement->core_params); 181 182 Factory::getApplication()->triggerEvent('onContentPrepare', ['com_tags.tag', &$itemElement, &$itemElement->core_params, 0]); 183 184 $results = Factory::getApplication()->triggerEvent( 185 'onContentAfterTitle', 186 ['com_tags.tag', &$itemElement, &$itemElement->core_params, 0] 187 ); 188 $itemElement->event->afterDisplayTitle = trim(implode("\n", $results)); 189 190 $results = Factory::getApplication()->triggerEvent( 191 'onContentBeforeDisplay', 192 ['com_tags.tag', &$itemElement, &$itemElement->core_params, 0] 193 ); 194 $itemElement->event->beforeDisplayContent = trim(implode("\n", $results)); 195 196 $results = Factory::getApplication()->triggerEvent( 197 'onContentAfterDisplay', 198 ['com_tags.tag', &$itemElement, &$itemElement->core_params, 0] 199 ); 200 $itemElement->event->afterDisplayContent = trim(implode("\n", $results)); 201 202 // Write the results back into the body 203 if (!empty($itemElement->core_body)) { 204 $itemElement->core_body = $itemElement->text; 205 } 206 207 // Categories store the images differently so lets re-map it so the display is correct 208 if ($itemElement->type_alias === 'com_content.category') { 209 $itemElement->core_images = json_encode( 210 array( 211 'image_intro' => $itemElement->core_params->get('image', ''), 212 'image_intro_alt' => $itemElement->core_params->get('image_alt', '') 213 ) 214 ); 215 } 216 } 217 } 218 219 $this->state = $state; 220 $this->items = $items; 221 $this->children = $children; 222 $this->parent = $parent; 223 $this->pagination = $pagination; 224 $this->user = $user; 225 $this->item = $item; 226 227 // Escape strings for HTML output 228 $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', '')); 229 230 // Merge tag params. If this is single-tag view, menu params override tag params 231 // Otherwise, article params override menu item params 232 $this->params = $this->state->get('params'); 233 $active = $app->getMenu()->getActive(); 234 $temp = clone $this->params; 235 236 // Convert item params to a Registry object 237 $item[0]->params = new Registry($item[0]->params); 238 239 // Check to see which parameters should take priority 240 if ($active) { 241 $currentLink = $active->link; 242 243 // If the current view is the active item and a tag view for one tag, then the menu item params take priority 244 if (strpos($currentLink, 'view=tag') && strpos($currentLink, '&id[0]=' . (string) $item[0]->id)) { 245 // $item[0]->params are the tag params, $temp are the menu item params 246 // Merge so that the menu item params take priority 247 $item[0]->params->merge($temp); 248 249 // Load layout from active query (in case it is an alternative menu item) 250 if (isset($active->query['layout'])) { 251 $this->setLayout($active->query['layout']); 252 } 253 } else { 254 // Current menuitem is not a single tag view, so the tag params take priority. 255 // Merge the menu item params with the tag params so that the tag params take priority 256 $temp->merge($item[0]->params); 257 $item[0]->params = $temp; 258 259 // Check for alternative layouts (since we are not in a single-article menu item) 260 // Single-article menu item layout takes priority over alt layout for an article 261 if ($layout = $item[0]->params->get('tag_layout')) { 262 $this->setLayout($layout); 263 } 264 } 265 } else { 266 // Merge so that item params take priority 267 $temp->merge($item[0]->params); 268 $item[0]->params = $temp; 269 270 // Check for alternative layouts (since we are not in a single-tag menu item) 271 // Single-tag menu item layout takes priority over alt layout for an article 272 if ($layout = $item[0]->params->get('tag_layout')) { 273 $this->setLayout($layout); 274 } 275 } 276 277 // Increment the hit counter 278 $model = $this->getModel(); 279 $model->hit(); 280 281 $this->_prepareDocument(); 282 283 parent::display($tpl); 284 } 285 286 /** 287 * Prepares the document. 288 * 289 * @return void 290 */ 291 protected function _prepareDocument() 292 { 293 $app = Factory::getApplication(); 294 $menu = $app->getMenu()->getActive(); 295 $this->tags_title = $this->getTagsTitle(); 296 $pathway = $app->getPathway(); 297 $title = ''; 298 299 // Highest priority for "Browser Page Title". 300 if ($menu) { 301 $title = $menu->getParams()->get('page_title', ''); 302 } 303 304 if ($this->tags_title) { 305 $this->params->def('page_heading', $this->tags_title); 306 $title = $title ?: $this->tags_title; 307 } elseif ($menu) { 308 $this->params->def('page_heading', $this->params->get('page_title', $menu->title)); 309 $title = $title ?: $this->params->get('page_title', $menu->title); 310 } 311 312 $this->setDocumentTitle($title); 313 $pathway->addItem($title); 314 315 foreach ($this->item as $itemElement) { 316 if ($itemElement->metadesc) { 317 $this->document->setDescription($itemElement->metadesc); 318 } elseif ($this->params->get('menu-meta_description')) { 319 $this->document->setDescription($this->params->get('menu-meta_description')); 320 } 321 322 if ($this->params->get('robots')) { 323 $this->document->setMetaData('robots', $this->params->get('robots')); 324 } 325 } 326 327 if (count($this->item) === 1) { 328 foreach ($this->item[0]->metadata->toArray() as $k => $v) { 329 if ($v) { 330 $this->document->setMetaData($k, $v); 331 } 332 } 333 } 334 335 if ($this->params->get('show_feed_link', 1) == 1) { 336 $link = '&format=feed&limitstart='; 337 $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0'); 338 $this->document->addHeadLink(Route::_($link . '&type=rss'), 'alternate', 'rel', $attribs); 339 $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0'); 340 $this->document->addHeadLink(Route::_($link . '&type=atom'), 'alternate', 'rel', $attribs); 341 } 342 } 343 344 /** 345 * Creates the tags title for the output 346 * 347 * @return string 348 * 349 * @since 3.1 350 */ 351 protected function getTagsTitle() 352 { 353 $tags_title = array(); 354 355 if (!empty($this->item)) { 356 $user = $this->getCurrentUser(); 357 $groups = $user->getAuthorisedViewLevels(); 358 359 foreach ($this->item as $item) { 360 if (in_array($item->access, $groups)) { 361 $tags_title[] = $item->title; 362 } 363 } 364 } 365 366 return implode(' ', $tags_title); 367 } 368 }
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 |