[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Document/ -> FeedDocument.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2006 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\Document;
  11  
  12  use Joomla\CMS\Document\Feed\FeedImage;
  13  use Joomla\CMS\Document\Feed\FeedItem;
  14  use Joomla\CMS\Factory as CmsFactory;
  15  use Joomla\CMS\Language\Text;
  16  
  17  // phpcs:disable PSR1.Files.SideEffects
  18  \defined('JPATH_PLATFORM') or die;
  19  // phpcs:enable PSR1.Files.SideEffects
  20  
  21  /**
  22   * FeedDocument class, provides an easy interface to parse and display any feed document
  23   *
  24   * @since  1.7.0
  25   */
  26  class FeedDocument extends Document
  27  {
  28      /**
  29       * Syndication URL feed element
  30       *
  31       * optional
  32       *
  33       * @var    string
  34       * @since  1.7.0
  35       */
  36      public $syndicationURL = '';
  37  
  38      /**
  39       * Image feed element
  40       *
  41       * optional
  42       *
  43       * @var    FeedImage
  44       * @since  1.7.0
  45       */
  46      public $image = null;
  47  
  48      /**
  49       * Copyright feed element
  50       *
  51       * optional
  52       *
  53       * @var    string
  54       * @since  1.7.0
  55       */
  56      public $copyright = '';
  57  
  58      /**
  59       * Published date feed element
  60       *
  61       * optional
  62       *
  63       * @var    string
  64       * @since  1.7.0
  65       */
  66      public $pubDate = '';
  67  
  68      /**
  69       * Lastbuild date feed element
  70       *
  71       * @var    \Joomla\CMS\Date\Date
  72       * @since  1.7.0
  73       */
  74      public $lastBuildDate;
  75  
  76      /**
  77       * Editor feed element
  78       *
  79       * optional
  80       *
  81       * @var    string
  82       * @since  1.7.0
  83       */
  84      public $editor = '';
  85  
  86      /**
  87       * Docs feed element
  88       *
  89       * @var    string
  90       * @since  1.7.0
  91       */
  92      public $docs = '';
  93  
  94      /**
  95       * Editor email feed element
  96       *
  97       * optional
  98       *
  99       * @var    string
 100       * @since  1.7.0
 101       */
 102      public $editorEmail = '';
 103  
 104      /**
 105       * Webmaster email feed element
 106       *
 107       * optional
 108       *
 109       * @var    string
 110       * @since  1.7.0
 111       */
 112      public $webmaster = '';
 113  
 114      /**
 115       * Category feed element
 116       *
 117       * optional
 118       *
 119       * @var    string
 120       * @since  1.7.0
 121       */
 122      public $category = '';
 123  
 124      /**
 125       * TTL feed attribute
 126       *
 127       * optional
 128       *
 129       * @var    string
 130       * @since  1.7.0
 131       */
 132      public $ttl = '';
 133  
 134      /**
 135       * Rating feed element
 136       *
 137       * optional
 138       *
 139       * @var    string
 140       * @since  1.7.0
 141       */
 142      public $rating = '';
 143  
 144      /**
 145       * Skiphours feed element
 146       *
 147       * optional
 148       *
 149       * @var    string
 150       * @since  1.7.0
 151       */
 152      public $skipHours = '';
 153  
 154      /**
 155       * Skipdays feed element
 156       *
 157       * optional
 158       *
 159       * @var    string
 160       * @since  1.7.0
 161       */
 162      public $skipDays = '';
 163  
 164      /**
 165       * The feed items collection
 166       *
 167       * @var    FeedItem[]
 168       * @since  1.7.0
 169       */
 170      public $items = array();
 171  
 172      /**
 173       * Class constructor
 174       *
 175       * @param   array  $options  Associative array of options
 176       *
 177       * @since  1.7.0
 178       */
 179      public function __construct($options = array())
 180      {
 181          parent::__construct($options);
 182  
 183          // Set document type
 184          $this->_type = 'feed';
 185  
 186          // Gets and sets timezone offset from site configuration
 187          $this->lastBuildDate = CmsFactory::getDate();
 188          $this->lastBuildDate->setTimezone(new \DateTimeZone(CmsFactory::getApplication()->get('offset', 'UTC')));
 189      }
 190  
 191      /**
 192       * Render the document
 193       *
 194       * @param   boolean  $cache   If true, cache the output
 195       * @param   array    $params  Associative array of attributes
 196       *
 197       * @return  string The rendered data
 198       *
 199       * @since   1.7.0
 200       * @throws  \Exception
 201       * @todo    Make this cacheable
 202       */
 203      public function render($cache = false, $params = array())
 204      {
 205          // Get the feed type
 206          $type = CmsFactory::getApplication()->input->get('type', 'rss');
 207  
 208          // Instantiate feed renderer and set the mime encoding
 209          $renderer = $this->loadRenderer($type ?: 'rss');
 210  
 211          if (!($renderer instanceof DocumentRenderer)) {
 212              throw new \Exception(Text::_('JGLOBAL_RESOURCE_NOT_FOUND'), 404);
 213          }
 214  
 215          $this->setMimeEncoding($renderer->getContentType());
 216  
 217          // Output
 218          // Generate prolog
 219          $data = "<?xml version=\"1.0\" encoding=\"" . $this->_charset . "\"?>\n";
 220          $data .= "<!-- generator=\"" . $this->getGenerator() . "\" -->\n";
 221  
 222          // Generate stylesheet links
 223          foreach ($this->_styleSheets as $src => $attr) {
 224              $data .= "<?xml-stylesheet href=\"$src\" type=\"" . $attr['type'] . "\"?>\n";
 225          }
 226  
 227          // Render the feed
 228          $data .= $renderer->render();
 229  
 230          parent::render($cache, $params);
 231  
 232          return $data;
 233      }
 234  
 235      /**
 236       * Adds a FeedItem to the feed.
 237       *
 238       * @param   FeedItem  $item  The feeditem to add to the feed.
 239       *
 240       * @return  FeedDocument  instance of $this to allow chaining
 241       *
 242       * @since   1.7.0
 243       */
 244      public function addItem(FeedItem $item)
 245      {
 246          $item->source = $this->link;
 247          $this->items[] = $item;
 248  
 249          return $this;
 250      }
 251  }


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