[ 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\Featured; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Language\Text; 15 use Joomla\CMS\MVC\View\GenericDataException; 16 use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; 17 use Joomla\CMS\Plugin\PluginHelper; 18 use Joomla\CMS\Router\Route; 19 20 // phpcs:disable PSR1.Files.SideEffects 21 \defined('_JEXEC') or die; 22 // phpcs:enable PSR1.Files.SideEffects 23 24 /** 25 * Frontpage View class 26 * 27 * @since 1.5 28 */ 29 class HtmlView extends BaseHtmlView 30 { 31 /** 32 * The model state 33 * 34 * @var \Joomla\CMS\Object\CMSObject 35 */ 36 protected $state = null; 37 38 /** 39 * The featured articles array 40 * 41 * @var \stdClass[] 42 */ 43 protected $items = null; 44 45 /** 46 * The pagination object. 47 * 48 * @var \Joomla\CMS\Pagination\Pagination 49 */ 50 protected $pagination = null; 51 52 /** 53 * The featured articles to be displayed as lead items. 54 * 55 * @var \stdClass[] 56 */ 57 protected $lead_items = array(); 58 59 /** 60 * The featured articles to be displayed as intro items. 61 * 62 * @var \stdClass[] 63 */ 64 protected $intro_items = array(); 65 66 /** 67 * The featured articles to be displayed as link items. 68 * 69 * @var \stdClass[] 70 */ 71 protected $link_items = array(); 72 73 /** 74 * @var \Joomla\Database\DatabaseDriver 75 * 76 * @since 3.6.3 77 * 78 * @deprecated 5.0 Will be removed without replacement 79 */ 80 protected $db; 81 82 /** 83 * The user object 84 * 85 * @var \Joomla\CMS\User\User|null 86 */ 87 protected $user = null; 88 89 /** 90 * The page class suffix 91 * 92 * @var string 93 * 94 * @since 4.0.0 95 */ 96 protected $pageclass_sfx = ''; 97 98 /** 99 * The page parameters 100 * 101 * @var \Joomla\Registry\Registry|null 102 * 103 * @since 4.0.0 104 */ 105 protected $params = null; 106 107 /** 108 * Execute and display a template script. 109 * 110 * @param string $tpl The name of the template file to parse; automatically searches through the template paths. 111 * 112 * @return void 113 */ 114 public function display($tpl = null) 115 { 116 $user = $this->getCurrentUser(); 117 118 $state = $this->get('State'); 119 $items = $this->get('Items'); 120 $pagination = $this->get('Pagination'); 121 122 // Flag indicates to not add limitstart=0 to URL 123 $pagination->hideEmptyLimitstart = true; 124 125 // Check for errors. 126 if (count($errors = $this->get('Errors'))) { 127 throw new GenericDataException(implode("\n", $errors), 500); 128 } 129 130 /** @var \Joomla\Registry\Registry $params */ 131 $params = &$state->params; 132 133 // PREPARE THE DATA 134 135 // Get the metrics for the structural page layout. 136 $numLeading = (int) $params->def('num_leading_articles', 1); 137 $numIntro = (int) $params->def('num_intro_articles', 4); 138 139 PluginHelper::importPlugin('content'); 140 141 // Compute the article slugs and prepare introtext (runs content plugins). 142 foreach ($items as &$item) { 143 $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; 144 145 // No link for ROOT category 146 if ($item->parent_alias === 'root') { 147 $item->parent_id = null; 148 } 149 150 $item->event = new \stdClass(); 151 152 // Old plugins: Ensure that text property is available 153 if (!isset($item->text)) { 154 $item->text = $item->introtext; 155 } 156 157 Factory::getApplication()->triggerEvent('onContentPrepare', array('com_content.featured', &$item, &$item->params, 0)); 158 159 // Old plugins: Use processed text as introtext 160 $item->introtext = $item->text; 161 162 $results = Factory::getApplication()->triggerEvent('onContentAfterTitle', array('com_content.featured', &$item, &$item->params, 0)); 163 $item->event->afterDisplayTitle = trim(implode("\n", $results)); 164 165 $results = Factory::getApplication()->triggerEvent('onContentBeforeDisplay', array('com_content.featured', &$item, &$item->params, 0)); 166 $item->event->beforeDisplayContent = trim(implode("\n", $results)); 167 168 $results = Factory::getApplication()->triggerEvent('onContentAfterDisplay', array('com_content.featured', &$item, &$item->params, 0)); 169 $item->event->afterDisplayContent = trim(implode("\n", $results)); 170 } 171 172 // Preprocess the breakdown of leading, intro and linked articles. 173 // This makes it much easier for the designer to just integrate the arrays. 174 $max = count($items); 175 176 // The first group is the leading articles. 177 $limit = $numLeading; 178 179 for ($i = 0; $i < $limit && $i < $max; $i++) { 180 $this->lead_items[$i] = &$items[$i]; 181 } 182 183 // The second group is the intro articles. 184 $limit = $numLeading + $numIntro; 185 186 // Order articles across, then down (or single column mode) 187 for ($i = $numLeading; $i < $limit && $i < $max; $i++) { 188 $this->intro_items[$i] = &$items[$i]; 189 } 190 191 // The remainder are the links. 192 for ($i = $numLeading + $numIntro; $i < $max; $i++) { 193 $this->link_items[$i] = &$items[$i]; 194 } 195 196 // Escape strings for HTML output 197 $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', '')); 198 199 $this->params = &$params; 200 $this->items = &$items; 201 $this->pagination = &$pagination; 202 $this->user = &$user; 203 $this->db = Factory::getDbo(); 204 205 $this->_prepareDocument(); 206 207 parent::display($tpl); 208 } 209 210 /** 211 * Prepares the document. 212 * 213 * @return void 214 */ 215 protected function _prepareDocument() 216 { 217 // Because the application sets a default page title, 218 // we need to get it from the menu item itself 219 $menu = Factory::getApplication()->getMenu()->getActive(); 220 221 if ($menu) { 222 $this->params->def('page_heading', $this->params->get('page_title', $menu->title)); 223 } else { 224 $this->params->def('page_heading', Text::_('JGLOBAL_ARTICLES')); 225 } 226 227 $this->setDocumentTitle($this->params->get('page_title', '')); 228 229 if ($this->params->get('menu-meta_description')) { 230 $this->document->setDescription($this->params->get('menu-meta_description')); 231 } 232 233 if ($this->params->get('robots')) { 234 $this->document->setMetaData('robots', $this->params->get('robots')); 235 } 236 237 // Add feed links 238 if ($this->params->get('show_feed_link', 1)) { 239 $link = '&format=feed&limitstart='; 240 $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0'); 241 $this->document->addHeadLink(Route::_($link . '&type=rss'), 'alternate', 'rel', $attribs); 242 $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0'); 243 $this->document->addHeadLink(Route::_($link . '&type=atom'), 'alternate', 'rel', $attribs); 244 } 245 } 246 }
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 |