Source for file view.html.php

Documentation is available at view.html.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_newsfeeds
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * HTML View class for the Newsfeeds component
  14.  *
  15.  * @package     Joomla.Site
  16.  * @subpackage  com_newsfeeds
  17.  * @since       1.0
  18.  */
  19. {
  20.     /**
  21.      * @var        object 
  22.      * @since   1.6
  23.      */
  24.     protected $state;
  25.  
  26.     /**
  27.      * @var        object 
  28.      * @since   1.6
  29.      */
  30.     protected $item;
  31.  
  32.     /**
  33.      * @var        boolean 
  34.      * @since   1.6
  35.      */
  36.     protected $print;
  37.  
  38.     /**
  39.      * Execute and display a template script.
  40.      *
  41.      * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  42.      *
  43.      * @return  mixed  A string if successful, otherwise a Error object.
  44.      *
  45.      * @since   1.6
  46.      */
  47.     public function display($tpl null)
  48.     {
  49.         $app        JFactory::getApplication();
  50.         $user        JFactory::getUser();
  51.  
  52.         // Get view related request variables.
  53.         $print $app->input->getBool('print');
  54.  
  55.         // Get model data.
  56.         $state $this->get('State');
  57.         $item $this->get('Item');
  58.  
  59.         if ($item)
  60.         {
  61.             // Get Category Model data
  62.             $categoryModel JModelLegacy::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.             // TODO: $items is not used. Remove this line?
  67.             $items $categoryModel->getItems();
  68.         }
  69.  
  70.         // Check for errors.
  71.         // @TODO Maybe this could go into JComponentHelper::raiseErrors($this->get('Errors'))
  72.         if (count($errors $this->get('Errors')))
  73.         {
  74.             JError::raiseWarning(500implode("\n"$errors));
  75.  
  76.             return false;
  77.         }
  78.  
  79.         // Add router helpers.
  80.         $item->slug $item->alias ($item->id ':' $item->alias$item->id;
  81.         $item->catslug $item->category_alias ($item->catid ':' $item->category_alias$item->catid;
  82.         $item->parent_slug $item->category_alias ($item->parent_id ':' $item->parent_alias$item->parent_id;
  83.  
  84.         // check if cache directory is writeable
  85.         $cacheDir JPATH_CACHE '/';
  86.  
  87.         if (!is_writable($cacheDir))
  88.         {
  89.             JError::raiseNotice('0'JText::_('COM_NEWSFEEDS_CACHE_DIRECTORY_UNWRITABLE'));
  90.             return;
  91.         }
  92.  
  93.         // Merge newsfeed params. If this is single-newsfeed view, menu params override newsfeed params
  94.         // Otherwise, newsfeed params override menu item params
  95.         $params $state->get('params');
  96.         $newsfeed_params clone $item->params;
  97.         $active $app->getMenu()->getActive();
  98.         $temp clone ($params);
  99.  
  100.         // Check to see which parameters should take priority
  101.         if ($active)
  102.         {
  103.             $currentLink $active->link;
  104.             // If the current view is the active item and an newsfeed view for this feed, then the menu item params take priority
  105.             if (strpos($currentLink'view=newsfeed'&& (strpos($currentLink'&id='.(string) $item->id)))
  106.             {
  107.                 // $item->params are the newsfeed params, $temp are the menu item params
  108.                 // Merge so that the menu item params take priority
  109.                 $newsfeed_params->merge($temp);
  110.                 $item->params $newsfeed_params;
  111.                 // Load layout from active query (in case it is an alternative menu item)
  112.                 if (isset($active->query['layout']))
  113.                 {
  114.                     $this->setLayout($active->query['layout']);
  115.                 }
  116.             }
  117.             else
  118.             {
  119.                 // Current view is not a single newsfeed, so the newsfeed params take priority here
  120.                 // Merge the menu item params with the newsfeed params so that the newsfeed params take priority
  121.                 $temp->merge($newsfeed_params);
  122.                 $item->params $temp;
  123.                 // Check for alternative layouts (since we are not in a single-newsfeed menu item)
  124.                 if ($layout $item->params->get('newsfeed_layout'))
  125.                 {
  126.                     $this->setLayout($layout);
  127.                 }
  128.             }
  129.         }
  130.         else
  131.         {
  132.             // Merge so that newsfeed params take priority
  133.             $temp->merge($newsfeed_params);
  134.             $item->params $temp;
  135.             // Check for alternative layouts (since we are not in a single-newsfeed menu item)
  136.             if ($layout $item->params->get('newsfeed_layout'))
  137.             {
  138.                 $this->setLayout($layout);
  139.             }
  140.         }
  141.  
  142.         // Check the access to the newsfeed
  143.         $levels $user->getAuthorisedViewLevels();
  144.  
  145.         if (!in_array($item->access$levelsor ((in_array($item->access$levelsand (!in_array($item->category_access$levels)))))
  146.         {
  147.             JError::raiseWarning(403JText::_('JERROR_ALERTNOAUTHOR'));
  148.             return;
  149.         }
  150.  
  151.         // Get the current menu item
  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.         try
  162.         {
  163.             $feed new JFeedFactory;
  164.             $this->rssDoc $feed->getFeed($newsfeed->link);
  165.         }
  166.         catch (InvalidArgumentException $e)
  167.         {
  168.             $msg JText::_('COM_NEWSFEEDS_ERRORS_FEED_NOT_RETRIEVED');
  169.         }
  170.         catch (RunTimeException $e)
  171.         {
  172.             $msg JText::_('COM_NEWSFEEDS_ERRORS_FEED_NOT_RETRIEVED');
  173.         }
  174.         if (empty($this->rssDoc))
  175.         {
  176.             $msg JText::_('COM_NEWSFEEDS_ERRORS_FEED_NOT_RETRIEVED');
  177.         }
  178.  
  179.         $feed_display_order $params->get('feed_display_order''des');
  180.         if ($feed_display_order == 'asc')
  181.         {
  182.             $newsfeed->items array_reverse($newsfeed->items);
  183.         }
  184.  
  185.         //Escape strings for HTML output
  186.         $this->pageclass_sfx htmlspecialchars($params->get('pageclass_sfx'));
  187.  
  188.         $this->assignRef('params'$params);
  189.         $this->assignRef('newsfeed'$newsfeed);
  190.         $this->assignRef('state'$state);
  191.         $this->assignRef('item'$item);
  192.         $this->assignRef('user'$user);
  193.         if (!empty($msg))
  194.         {
  195.             $this->assignRef('msg'$msg);
  196.         }
  197.         $this->print = $print;
  198.  
  199.         $item->tags new JHelperTags;
  200.         $item->tags->getItemTags('com_newsfeeds.newsfeed'$item->id);
  201.  
  202.         // Increment the hit counter of the newsfeed.
  203.         $model $this->getModel();
  204.         $model->hit();
  205.  
  206.         $this->_prepareDocument();
  207.  
  208.         return 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.  
  228.         if ($menu)
  229.         {
  230.             $this->params->def('page_heading'$this->params->get('page_title'$menu->title));
  231.         }
  232.         else
  233.         {
  234.             $this->params->def('page_heading'JText::_('COM_NEWSFEEDS_DEFAULT_PAGE_TITLE'));
  235.         }
  236.  
  237.         $title $this->params->get('page_title''');
  238.  
  239.         $id = (int) @$menu->query['id'];
  240.  
  241.         // if the menu item does not concern this newsfeed
  242.         if ($menu && ($menu->query['option'!= 'com_newsfeeds' || $menu->query['view'!= 'newsfeed' || $id != $this->item->id))
  243.         {
  244.             // If this is not a single newsfeed menu item, set the page title to the newsfeed title
  245.             if ($this->item->name)
  246.             {
  247.                 $title $this->item->name;
  248.             }
  249.  
  250.             $path array(array('title' => $this->item->name'link' => ''));
  251.             $category JCategories::getInstance('Newsfeeds')->get($this->item->catid);
  252.             while (($menu->query['option'!= 'com_newsfeeds' || $menu->query['view'== 'newsfeed' || $id != $category->id&& $category->id 1)
  253.             {
  254.                 $path[array('title' => $category->title'link' => NewsfeedsHelperRoute::getCategoryRoute($category->id));
  255.                 $category $category->getParent();
  256.             }
  257.             $path array_reverse($path);
  258.             foreach ($path as $item)
  259.             {
  260.                 $pathway->addItem($item['title']$item['link']);
  261.             }
  262.         }
  263.  
  264.         if (empty($title))
  265.         {
  266.             $title $app->getCfg('sitename');
  267.         }
  268.         elseif ($app->getCfg('sitename_pagetitles'0== 1)
  269.         {
  270.             $title JText::sprintf('JPAGETITLE'$app->getCfg('sitename')$title);
  271.         }
  272.         elseif ($app->getCfg('sitename_pagetitles'0== 2)
  273.         {
  274.             $title JText::sprintf('JPAGETITLE'$title$app->getCfg('sitename'));
  275.         }
  276.         if (empty($title))
  277.         {
  278.             $title $this->item->name;
  279.         }
  280.         $this->document->setTitle($title);
  281.  
  282.         if ($this->item->metadesc)
  283.         {
  284.             $this->document->setDescription($this->item->metadesc);
  285.         }
  286.         elseif (!$this->item->metadesc && $this->params->get('menu-meta_description'))
  287.         {
  288.             $this->document->setDescription($this->params->get('menu-meta_description'));
  289.         }
  290.  
  291.         if ($this->item->metakey)
  292.         {
  293.             $this->document->setMetadata('keywords'$this->item->metakey);
  294.         }
  295.         elseif (!$this->item->metakey && $this->params->get('menu-meta_keywords'))
  296.         {
  297.             $this->document->setMetadata('keywords'$this->params->get('menu-meta_keywords'));
  298.         }
  299.  
  300.         if ($this->params->get('robots'))
  301.         {
  302.             $this->document->setMetadata('robots'$this->params->get('robots'));
  303.         }
  304.  
  305.         if ($app->getCfg('MetaTitle'== '1')
  306.         {
  307.             $this->document->setMetaData('title'$this->item->name);
  308.         }
  309.  
  310.         if ($app->getCfg('MetaAuthor'== '1')
  311.         {
  312.             $this->document->setMetaData('author'$this->item->author);
  313.         }
  314.  
  315.         $mdata $this->item->metadata->toArray();
  316.         foreach ($mdata as $k => $v)
  317.         {
  318.             if ($v)
  319.             {
  320.                 $this->document->setMetadata($k$v);
  321.             }
  322.         }
  323.     }
  324. }

Documentation generated on Tue, 19 Nov 2013 15:17:20 +0100 by phpDocumentor 1.4.3