| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Site 4 * @subpackage com_newsfeeds 5 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE.txt 7 * 8 */ 9 10 // Check to ensure this file is included in Joomla! 11 defined('_JEXEC') or die; 12 13 jimport('joomla.application.component.view'); 14 15 /** 16 * HTML View class for the Newsfeeds component 17 * 18 * @static 19 * @package Joomla.Site 20 * @subpackage com_newsfeeds 21 * @since 1.0 22 */ 23 class NewsfeedsViewNewsfeed extends JView 24 { 25 /** 26 * @var object 27 * @since 1.6 28 */ 29 protected $state; 30 31 /** 32 * @var object 33 * @since 1.6 34 */ 35 protected $item; 36 37 /** 38 * @var boolean 39 * @since 1.6 40 */ 41 protected $print; 42 43 /** 44 * @since 1.6 45 */ 46 function display($tpl = null) 47 { 48 // Initialise variables. 49 $app = JFactory::getApplication(); 50 $user = JFactory::getUser(); 51 $dispatcher = JDispatcher::getInstance(); 52 53 // Get view related request variables. 54 $print = JRequest::getBool('print'); 55 56 // Get model data. 57 $state = $this->get('State'); 58 $item = $this->get('Item'); 59 60 if ($item) { 61 // Get Category Model data 62 $categoryModel = JModel::getInstance('Category', 'NewsfeedsModel', array('ignore_request' => true)); 63 $categoryModel->setState('category.id', $item->catid); 64 $categoryModel->setState('list.ordering', 'a.name'); 65 $categoryModel->setState('list.direction', 'asc'); 66 $items = $categoryModel->getItems(); 67 } 68 69 // Check for errors. 70 // @TODO Maybe this could go into JComponentHelper::raiseErrors($this->get('Errors')) 71 if (count($errors = $this->get('Errors'))) { 72 JError::raiseWarning(500, implode("\n", $errors)); 73 74 return false; 75 } 76 77 // Add router helpers. 78 $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; 79 $item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid; 80 $item->parent_slug = $item->category_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id; 81 82 // check if cache directory is writeable 83 $cacheDir = JPATH_CACHE . '/'; 84 85 if (!is_writable($cacheDir)) { 86 JError::raiseNotice('0', JText::_('COM_NEWSFEEDS_CACHE_DIRECTORY_UNWRITABLE')); 87 return; 88 } 89 90 // Merge newsfeed params. If this is single-newsfeed view, menu params override newsfeed params 91 // Otherwise, newsfeed params override menu item params 92 $params = $state->get('params'); 93 $newsfeed_params = clone $item->params; 94 $active = $app->getMenu()->getActive(); 95 $temp = clone ($params); 96 97 // Check to see which parameters should take priority 98 if ($active) 99 { 100 $currentLink = $active->link; 101 // If the current view is the active item and an newsfeed view for this feed, then the menu item params take priority 102 if (strpos($currentLink, 'view=newsfeed') && (strpos($currentLink, '&id='.(string) $item->id))) 103 { 104 // $item->params are the newsfeed params, $temp are the menu item params 105 // Merge so that the menu item params take priority 106 $newsfeed_params->merge($temp); 107 $item->params = $newsfeed_params; 108 // Load layout from active query (in case it is an alternative menu item) 109 if (isset($active->query['layout'])) 110 { 111 $this->setLayout($active->query['layout']); 112 } 113 } 114 else 115 { 116 // Current view is not a single newsfeed, so the newsfeed params take priority here 117 // Merge the menu item params with the newsfeed params so that the newsfeed params take priority 118 $temp->merge($newsfeed_params); 119 $item->params = $temp; 120 // Check for alternative layouts (since we are not in a single-newsfeed menu item) 121 if ($layout = $item->params->get('newsfeed_layout')) 122 { 123 $this->setLayout($layout); 124 } 125 } 126 } 127 else 128 { 129 // Merge so that newsfeed params take priority 130 $temp->merge($newsfeed_params); 131 $item->params = $temp; 132 // Check for alternative layouts (since we are not in a single-newsfeed menu item) 133 if ($layout = $item->params->get('newsfeed_layout')) 134 { 135 $this->setLayout($layout); 136 } 137 } 138 139 $offset = $state->get('list.offset'); 140 141 // Check the access to the newsfeed 142 $levels = $user->getAuthorisedViewLevels(); 143 144 if (!in_array($item->access, $levels) or ((in_array($item->access, $levels) and (!in_array($item->category_access, $levels))))) { 145 JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR')); 146 return; 147 } 148 149 // Get the current menu item 150 $menus = $app->getMenu(); 151 $menu = $menus->getActive(); 152 $params = $app->getParams(); 153 154 // Get the newsfeed 155 $newsfeed = $item; 156 157 $temp = new JRegistry(); 158 $temp->loadString($item->params); 159 $params->merge($temp); 160 161 // get RSS parsed object 162 $rssDoc = JFactory::getFeedParser($newsfeed->link, $newsfeed->cache_time); 163 164 if ($rssDoc == false) { 165 $msg = JText::_('COM_NEWSFEEDS_ERRORS_FEED_NOT_RETRIEVED'); 166 $app->redirect(NewsFeedsHelperRoute::getCategoryRoute($newsfeed->catslug), $msg); 167 return; 168 } 169 $lists = array(); 170 171 // channel header and link 172 $newsfeed->channel['title'] = $rssDoc->get_title(); 173 $newsfeed->channel['link'] = $rssDoc->get_link(); 174 $newsfeed->channel['description'] = $rssDoc->get_description(); 175 $newsfeed->channel['language'] = $rssDoc->get_language(); 176 177 // channel image if exists 178 $newsfeed->image['url'] = $rssDoc->get_image_url(); 179 $newsfeed->image['title'] = $rssDoc->get_image_title(); 180 $newsfeed->image['link'] = $rssDoc->get_image_link(); 181 $newsfeed->image['height'] = $rssDoc->get_image_height(); 182 $newsfeed->image['width'] = $rssDoc->get_image_width(); 183 184 // items 185 $newsfeed->items = $rssDoc->get_items(); 186 187 // feed elements 188 $newsfeed->items = array_slice($newsfeed->items, 0, $newsfeed->numarticles); 189 190 // feed display order 191 $feed_display_order = $params->get('feed_display_order', 'des'); 192 if ($feed_display_order == 'asc') { 193 $newsfeed->items = array_reverse($newsfeed->items); 194 } 195 196 //Escape strings for HTML output 197 $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); 198 199 $this->assignRef('params' , $params ); 200 $this->assignRef('newsfeed', $newsfeed); 201 $this->assignRef('state', $state); 202 $this->assignRef('item', $item); 203 $this->assignRef('user', $user); 204 $this->assign('print', $print); 205 206 $this->_prepareDocument(); 207 208 parent::display($tpl); 209 } 210 211 /** 212 * Prepares the document 213 * 214 * @return void 215 * @since 1.6 216 */ 217 protected function _prepareDocument() 218 { 219 $app = JFactory::getApplication(); 220 $menus = $app->getMenu(); 221 $pathway = $app->getPathway(); 222 $title = null; 223 224 // Because the application sets a default page title, 225 // we need to get it from the menu item itself 226 $menu = $menus->getActive(); 227 if ($menu) { 228 $this->params->def('page_heading', $this->params->get('page_title', $menu->title)); 229 } 230 else { 231 $this->params->def('page_heading', JText::_('COM_NEWSFEEDS_DEFAULT_PAGE_TITLE')); 232 } 233 234 $title = $this->params->get('page_title', ''); 235 236 $id = (int) @$menu->query['id']; 237 238 // if the menu item does not concern this newsfeed 239 if ($menu && ($menu->query['option'] != 'com_newsfeeds' || $menu->query['view'] != 'newsfeed' || $id != $this->item->id)) 240 { 241 // If this is not a single newsfeed menu item, set the page title to the newsfeed title 242 if ($this->item->name) { 243 $title = $this->item->name; 244 } 245 246 $path = array(array('title' => $this->item->name, 'link' => '')); 247 $category = JCategories::getInstance('Newsfeeds')->get($this->item->catid); 248 while (($menu->query['option'] != 'com_newsfeeds' || $menu->query['view'] == 'newsfeed' || $id != $category->id) && $category->id > 1) 249 { 250 $path[] = array('title' => $category->title, 'link' => NewsfeedsHelperRoute::getCategoryRoute($category->id)); 251 $category = $category->getParent(); 252 } 253 $path = array_reverse($path); 254 foreach($path as $item) 255 { 256 $pathway->addItem($item['title'], $item['link']); 257 } 258 } 259 260 if (empty($title)) { 261 $title = $app->getCfg('sitename'); 262 } 263 elseif ($app->getCfg('sitename_pagetitles', 0) == 1) { 264 $title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title); 265 } 266 elseif ($app->getCfg('sitename_pagetitles', 0) == 2) { 267 $title = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename')); 268 } 269 if (empty($title)) { 270 $title = $this->item->name; 271 } 272 $this->document->setTitle($title); 273 274 if ($this->item->metadesc) 275 { 276 $this->document->setDescription($this->item->metadesc); 277 } 278 elseif (!$this->item->metadesc && $this->params->get('menu-meta_description')) 279 { 280 $this->document->setDescription($this->params->get('menu-meta_description')); 281 } 282 283 if ($this->item->metakey) 284 { 285 $this->document->setMetadata('keywords', $this->item->metakey); 286 } 287 elseif (!$this->item->metakey && $this->params->get('menu-meta_keywords')) 288 { 289 $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords')); 290 } 291 292 if ($this->params->get('robots')) 293 { 294 $this->document->setMetadata('robots', $this->params->get('robots')); 295 } 296 297 if ($app->getCfg('MetaTitle') == '1') { 298 $this->document->setMetaData('title', $this->item->name); 299 } 300 301 if ($app->getCfg('MetaAuthor') == '1') { 302 $this->document->setMetaData('author', $this->item->author); 303 } 304 305 $mdata = $this->item->metadata->toArray(); 306 foreach ($mdata as $k => $v) 307 { 308 if ($v) { 309 $this->document->setMetadata($k, $v); 310 } 311 } 312 } 313 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |