[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/MVC/View/ -> CategoryFeedView.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\MVC\View;
  11  
  12  use Joomla\CMS\Document\Feed\FeedItem;
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Helper\RouteHelper;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\Router\Route;
  17  use Joomla\CMS\UCM\UCMType;
  18  
  19  // phpcs:disable PSR1.Files.SideEffects
  20  \defined('JPATH_PLATFORM') or die;
  21  // phpcs:enable PSR1.Files.SideEffects
  22  
  23  /**
  24   * Base feed View class for a category
  25   *
  26   * @since  3.2
  27   */
  28  class CategoryFeedView extends HtmlView
  29  {
  30      /**
  31       * Execute and display a template script.
  32       *
  33       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  34       *
  35       * @return  void
  36       *
  37       * @since   3.2
  38       * @throws  \Exception
  39       */
  40      public function display($tpl = null)
  41      {
  42          $app      = Factory::getApplication();
  43          $document = Factory::getDocument();
  44  
  45          $extension      = $app->input->getString('option');
  46          $contentType = $extension . '.' . $this->viewName;
  47  
  48          $ucmType = new UCMType();
  49          $ucmRow = $ucmType->getTypeByAlias($contentType);
  50          $ucmMapCommon = json_decode($ucmRow->field_mappings)->common;
  51          $createdField = null;
  52          $titleField = null;
  53  
  54          if (\is_object($ucmMapCommon)) {
  55              $createdField = $ucmMapCommon->core_created_time;
  56              $titleField = $ucmMapCommon->core_title;
  57          } elseif (\is_array($ucmMapCommon)) {
  58              $createdField = $ucmMapCommon[0]->core_created_time;
  59              $titleField = $ucmMapCommon[0]->core_title;
  60          }
  61  
  62          $document->link = Route::_(RouteHelper::getCategoryRoute($app->input->getInt('id'), $language = 0, $extension));
  63  
  64          $app->input->set('limit', $app->get('feed_limit'));
  65          $siteEmail        = $app->get('mailfrom');
  66          $fromName         = $app->get('fromname');
  67          $feedEmail        = $app->get('feed_email', 'none');
  68          $document->editor = $fromName;
  69  
  70          if ($feedEmail !== 'none') {
  71              $document->editorEmail = $siteEmail;
  72          }
  73  
  74          // Get some data from the model
  75          $items    = $this->get('Items');
  76          $category = $this->get('Category');
  77  
  78          // Don't display feed if category id missing or non existent
  79          if ($category == false || $category->alias === 'root') {
  80              throw new \Exception(Text::_('JGLOBAL_CATEGORY_NOT_FOUND'), 404);
  81          }
  82  
  83          foreach ($items as $item) {
  84              $this->reconcileNames($item);
  85  
  86              // Strip html from feed item title
  87              if ($titleField) {
  88                  $title = $this->escape($item->$titleField);
  89                  $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
  90              } else {
  91                  $title = '';
  92              }
  93  
  94              // URL link to article
  95              $router = new RouteHelper();
  96              $link   = Route::_($router->getRoute($item->id, $contentType, null, null, $item->catid));
  97  
  98              // Strip HTML from feed item description text.
  99              $description   = $item->description;
 100              $author        = $item->created_by_alias ?: $item->author;
 101              $categoryTitle = isset($item->category_title) ? $item->category_title : $category->title;
 102  
 103              if ($createdField) {
 104                  $date = isset($item->$createdField) ? date('r', strtotime($item->$createdField)) : '';
 105              } else {
 106                  $date = '';
 107              }
 108  
 109              // Load individual item creator class.
 110              $feeditem              = new FeedItem();
 111              $feeditem->title       = $title;
 112              $feeditem->link        = $link;
 113              $feeditem->description = $description;
 114              $feeditem->date        = $date;
 115              $feeditem->category    = $categoryTitle;
 116              $feeditem->author      = $author;
 117  
 118              // We don't have the author email so we have to use site in both cases.
 119              if ($feedEmail === 'site') {
 120                  $feeditem->authorEmail = $siteEmail;
 121              } elseif ($feedEmail === 'author') {
 122                  $feeditem->authorEmail = $item->author_email;
 123              }
 124  
 125              // Loads item information into RSS array
 126              $document->addItem($feeditem);
 127          }
 128      }
 129  
 130      /**
 131       * Method to reconcile non standard names from components to usage in this class.
 132       * Typically overridden in the component feed view class.
 133       *
 134       * @param   object  $item  The item for a feed, an element of the $items array.
 135       *
 136       * @return  void
 137       *
 138       * @since   3.2
 139       */
 140      protected function reconcileNames($item)
 141      {
 142          if (!property_exists($item, 'title') && property_exists($item, 'name')) {
 143              $item->title = $item->name;
 144          }
 145      }
 146  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer