[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/components/com_content/src/View/Featured/ -> FeedView.php (source)

   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\Categories\Categories;
  14  use Joomla\CMS\Document\Feed\FeedItem;
  15  use Joomla\CMS\Factory;
  16  use Joomla\CMS\HTML\HTMLHelper;
  17  use Joomla\CMS\Language\Text;
  18  use Joomla\CMS\MVC\View\AbstractView;
  19  use Joomla\CMS\Router\Route;
  20  use Joomla\Component\Content\Site\Helper\RouteHelper;
  21  
  22  // phpcs:disable PSR1.Files.SideEffects
  23  \defined('_JEXEC') or die;
  24  // phpcs:enable PSR1.Files.SideEffects
  25  
  26  /**
  27   * Frontpage View class
  28   *
  29   * @since  1.5
  30   */
  31  class FeedView extends AbstractView
  32  {
  33      /**
  34       * Execute and display a template script.
  35       *
  36       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  37       *
  38       * @return  mixed  A string if successful, otherwise an Error object.
  39       */
  40      public function display($tpl = null)
  41      {
  42          // Parameters
  43          $app       = Factory::getApplication();
  44          $params    = $app->getParams();
  45          $feedEmail = $app->get('feed_email', 'none');
  46          $siteEmail = $app->get('mailfrom');
  47  
  48          $this->document->link = Route::_('index.php?option=com_content&view=featured');
  49  
  50          // Get some data from the model
  51          $app->input->set('limit', $app->get('feed_limit'));
  52          $categories = Categories::getInstance('Content');
  53          $rows       = $this->get('Items');
  54  
  55          foreach ($rows as $row) {
  56              // Strip html from feed item title
  57              $title = htmlspecialchars($row->title, ENT_QUOTES, 'UTF-8');
  58              $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
  59  
  60              // Compute the article slug
  61              $row->slug = $row->alias ? ($row->id . ':' . $row->alias) : $row->id;
  62  
  63              // URL link to article
  64              $link = RouteHelper::getArticleRoute($row->slug, $row->catid, $row->language);
  65  
  66              $description = '';
  67              $obj = json_decode($row->images);
  68  
  69              if (!empty($obj->image_intro)) {
  70                  $description = '<p>' . HTMLHelper::_('image', $obj->image_intro, $obj->image_intro_alt) . '</p>';
  71              }
  72  
  73              $description .= ($params->get('feed_summary', 0) ? $row->introtext . $row->fulltext : $row->introtext);
  74              $author      = $row->created_by_alias ?: $row->author;
  75  
  76              // Load individual item creator class
  77              $item           = new FeedItem();
  78              $item->title    = $title;
  79              $item->link     = Route::_($link);
  80              $item->date     = $row->publish_up;
  81              $item->category = array();
  82  
  83              // All featured articles are categorized as "Featured"
  84              $item->category[] = Text::_('JFEATURED');
  85  
  86              for ($item_category = $categories->get($row->catid); $item_category !== null; $item_category = $item_category->getParent()) {
  87                  // Only add non-root categories
  88                  if ($item_category->id > 1) {
  89                      $item->category[] = $item_category->title;
  90                  }
  91              }
  92  
  93              $item->author = $author;
  94  
  95              if ($feedEmail === 'site') {
  96                  $item->authorEmail = $siteEmail;
  97              } elseif ($feedEmail === 'author') {
  98                  $item->authorEmail = $row->author_email;
  99              }
 100  
 101              // Add readmore link to description if introtext is shown, show_readmore is true and fulltext exists
 102              if (!$params->get('feed_summary', 0) && $params->get('feed_show_readmore', 0) && $row->fulltext) {
 103                  $link = Route::_($link, true, $app->get('force_ssl') == 2 ? Route::TLS_FORCE : Route::TLS_IGNORE, true);
 104                  $description .= '<p class="feed-readmore"><a target="_blank" href="' . $link . '" rel="noopener">'
 105                      . Text::_('COM_CONTENT_FEED_READMORE') . '</a></p>';
 106              }
 107  
 108              // Load item description and add div
 109              $item->description = '<div class="feed-description">' . $description . '</div>';
 110  
 111              // Loads item info into rss array
 112              $this->document->addItem($item);
 113          }
 114      }
 115  }


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