[ 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_newsfeeds 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\Newsfeeds\Site\View\Newsfeed; 12 13 use Joomla\CMS\Categories\Categories; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Feed\FeedFactory; 16 use Joomla\CMS\Helper\TagsHelper; 17 use Joomla\CMS\Language\Text; 18 use Joomla\CMS\MVC\View\GenericDataException; 19 use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; 20 use Joomla\Component\Newsfeeds\Site\Helper\RouteHelper; 21 22 // phpcs:disable PSR1.Files.SideEffects 23 \defined('_JEXEC') or die; 24 // phpcs:enable PSR1.Files.SideEffects 25 26 /** 27 * HTML View class for the Newsfeeds component 28 * 29 * @since 1.0 30 */ 31 class HtmlView extends BaseHtmlView 32 { 33 /** 34 * The model state 35 * 36 * @var object 37 * 38 * @since 1.6 39 */ 40 protected $state; 41 42 /** 43 * The newsfeed item 44 * 45 * @var object 46 * 47 * @since 1.6 48 */ 49 protected $item; 50 51 /** 52 * UNUSED? 53 * 54 * @var boolean 55 * 56 * @since 1.6 57 */ 58 protected $print; 59 60 /** 61 * The current user instance 62 * 63 * @var \Joomla\CMS\User\User|null 64 * 65 * @since 4.0.0 66 */ 67 protected $user = null; 68 69 /** 70 * The page class suffix 71 * 72 * @var string 73 * 74 * @since 4.0.0 75 */ 76 protected $pageclass_sfx = ''; 77 78 /** 79 * The page parameters 80 * 81 * @var \Joomla\Registry\Registry|null 82 * 83 * @since 4.0.0 84 */ 85 protected $params; 86 87 /** 88 * Execute and display a template script. 89 * 90 * @param string $tpl The name of the template file to parse; automatically searches through the template paths. 91 * 92 * @return void 93 * 94 * @since 1.6 95 */ 96 public function display($tpl = null) 97 { 98 $app = Factory::getApplication(); 99 $user = $this->getCurrentUser(); 100 101 // Get view related request variables. 102 $print = $app->input->getBool('print'); 103 104 // Get model data. 105 $state = $this->get('State'); 106 $item = $this->get('Item'); 107 108 // Check for errors. 109 // @TODO: Maybe this could go into ComponentHelper::raiseErrors($this->get('Errors')) 110 if (count($errors = $this->get('Errors'))) { 111 throw new GenericDataException(implode("\n", $errors), 500); 112 } 113 114 // Add router helpers. 115 $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; 116 $item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid; 117 $item->parent_slug = $item->category_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id; 118 119 // Merge newsfeed params. If this is single-newsfeed view, menu params override newsfeed params 120 // Otherwise, newsfeed params override menu item params 121 $params = $state->get('params'); 122 $newsfeed_params = clone $item->params; 123 $active = $app->getMenu()->getActive(); 124 $temp = clone $params; 125 126 // Check to see which parameters should take priority 127 if ($active) { 128 $currentLink = $active->link; 129 130 // If the current view is the active item and a newsfeed view for this feed, then the menu item params take priority 131 if (strpos($currentLink, 'view=newsfeed') && strpos($currentLink, '&id=' . (string) $item->id)) { 132 // $item->params are the newsfeed params, $temp are the menu item params 133 // Merge so that the menu item params take priority 134 $newsfeed_params->merge($temp); 135 $item->params = $newsfeed_params; 136 137 // Load layout from active query (in case it is an alternative menu item) 138 if (isset($active->query['layout'])) { 139 $this->setLayout($active->query['layout']); 140 } 141 } else { 142 // Current view is not a single newsfeed, so the newsfeed params take priority here 143 // Merge the menu item params with the newsfeed params so that the newsfeed params take priority 144 $temp->merge($newsfeed_params); 145 $item->params = $temp; 146 147 // Check for alternative layouts (since we are not in a single-newsfeed menu item) 148 if ($layout = $item->params->get('newsfeed_layout')) { 149 $this->setLayout($layout); 150 } 151 } 152 } else { 153 // Merge so that newsfeed params take priority 154 $temp->merge($newsfeed_params); 155 $item->params = $temp; 156 157 // Check for alternative layouts (since we are not in a single-newsfeed menu item) 158 if ($layout = $item->params->get('newsfeed_layout')) { 159 $this->setLayout($layout); 160 } 161 } 162 163 // Check the access to the newsfeed 164 $levels = $user->getAuthorisedViewLevels(); 165 166 if (!in_array($item->access, $levels) || (in_array($item->access, $levels) && (!in_array($item->category_access, $levels)))) { 167 $app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error'); 168 $app->setHeader('status', 403, true); 169 170 return; 171 } 172 173 // Get the current menu item 174 $params = $app->getParams(); 175 176 $params->merge($item->params); 177 178 try { 179 $feed = new FeedFactory(); 180 $this->rssDoc = $feed->getFeed($item->link); 181 } catch (\InvalidArgumentException $e) { 182 $msg = Text::_('COM_NEWSFEEDS_ERRORS_FEED_NOT_RETRIEVED'); 183 } catch (\RuntimeException $e) { 184 $msg = Text::_('COM_NEWSFEEDS_ERRORS_FEED_NOT_RETRIEVED'); 185 } 186 187 if (empty($this->rssDoc)) { 188 $msg = Text::_('COM_NEWSFEEDS_ERRORS_FEED_NOT_RETRIEVED'); 189 } 190 191 $feed_display_order = $params->get('feed_display_order', 'des'); 192 193 if ($feed_display_order === 'asc') { 194 $this->rssDoc->reverseItems(); 195 } 196 197 // Escape strings for HTML output 198 $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', '')); 199 200 $this->params = $params; 201 $this->state = $state; 202 $this->item = $item; 203 $this->user = $user; 204 205 if (!empty($msg)) { 206 $this->msg = $msg; 207 } 208 209 $this->print = $print; 210 211 $item->tags = new TagsHelper(); 212 $item->tags->getItemTags('com_newsfeeds.newsfeed', $item->id); 213 214 // Increment the hit counter of the newsfeed. 215 $model = $this->getModel(); 216 $model->hit(); 217 218 $this->_prepareDocument(); 219 220 parent::display($tpl); 221 } 222 223 /** 224 * Prepares the document 225 * 226 * @return void 227 * 228 * @since 1.6 229 */ 230 protected function _prepareDocument() 231 { 232 $app = Factory::getApplication(); 233 $pathway = $app->getPathway(); 234 235 // Because the application sets a default page title, 236 // we need to get it from the menu item itself 237 $menu = $app->getMenu()->getActive(); 238 239 if ($menu) { 240 $this->params->def('page_heading', $this->params->get('page_title', $menu->title)); 241 } else { 242 $this->params->def('page_heading', Text::_('COM_NEWSFEEDS_DEFAULT_PAGE_TITLE')); 243 } 244 245 $title = $this->params->get('page_title', ''); 246 247 $id = (int) @$menu->query['id']; 248 249 // If the menu item does not concern this newsfeed 250 if ( 251 $menu && (!isset($menu->query['option']) || $menu->query['option'] !== 'com_newsfeeds' || $menu->query['view'] !== 'newsfeed' 252 || $id != $this->item->id) 253 ) { 254 // If this is not a single newsfeed menu item, set the page title to the newsfeed title 255 if ($this->item->name) { 256 $title = $this->item->name; 257 } 258 259 $path = array(array('title' => $this->item->name, 'link' => '')); 260 $category = Categories::getInstance('Newsfeeds')->get($this->item->catid); 261 262 while ( 263 (!isset($menu->query['option']) || $menu->query['option'] !== 'com_newsfeeds' || $menu->query['view'] === 'newsfeed' 264 || $id != $category->id) && $category->id > 1 265 ) { 266 $path[] = array('title' => $category->title, 'link' => RouteHelper::getCategoryRoute($category->id)); 267 $category = $category->getParent(); 268 } 269 270 $path = array_reverse($path); 271 272 foreach ($path as $item) { 273 $pathway->addItem($item['title'], $item['link']); 274 } 275 } 276 277 if (empty($title)) { 278 $title = $this->item->name; 279 } 280 281 $this->setDocumentTitle($title); 282 283 if ($this->item->metadesc) { 284 $this->document->setDescription($this->item->metadesc); 285 } elseif ($this->params->get('menu-meta_description')) { 286 $this->document->setDescription($this->params->get('menu-meta_description')); 287 } 288 289 if ($this->params->get('robots')) { 290 $this->document->setMetaData('robots', $this->params->get('robots')); 291 } 292 293 if ($app->get('MetaAuthor') == '1') { 294 $this->document->setMetaData('author', $this->item->author); 295 } 296 297 $mdata = $this->item->metadata->toArray(); 298 299 foreach ($mdata as $k => $v) { 300 if ($v) { 301 $this->document->setMetaData($k, $v); 302 } 303 } 304 } 305 }
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 |