[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/components/com_content/src/View/Archive/ -> HtmlView.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\Archive;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\HTML\HTMLHelper;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\MVC\View\GenericDataException;
  17  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  18  use Joomla\CMS\Plugin\PluginHelper;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('_JEXEC') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * HTML View class for the Content component
  26   *
  27   * @since  1.5
  28   */
  29  class HtmlView extends BaseHtmlView
  30  {
  31      /**
  32       * The model state
  33       *
  34       * @var   \Joomla\CMS\Object\CMSObject
  35       */
  36      protected $state = null;
  37  
  38      /**
  39       * An array containing archived articles
  40       *
  41       * @var   \stdClass[]
  42       */
  43      protected $items = array();
  44  
  45      /**
  46       * The pagination object
  47       *
  48       * @var   \Joomla\CMS\Pagination\Pagination|null
  49       */
  50      protected $pagination = null;
  51  
  52      /**
  53       * The years that are available to filter on.
  54       *
  55       * @var   array
  56       *
  57       * @since 3.6.0
  58       */
  59      protected $years = array();
  60  
  61      /**
  62       * Object containing the year, month and limit field to be displayed
  63       *
  64       * @var    \stdClass|null
  65       *
  66       * @since  4.0.0
  67       */
  68      protected $form = null;
  69  
  70      /**
  71       * The page parameters
  72       *
  73       * @var    \Joomla\Registry\Registry|null
  74       *
  75       * @since  4.0.0
  76       */
  77      protected $params = null;
  78  
  79      /**
  80       * The search query used on any archived articles (note this may not be displayed depending on the value of the
  81       * filter_field component parameter)
  82       *
  83       * @var    string
  84       *
  85       * @since  4.0.0
  86       */
  87      protected $filter = '';
  88  
  89      /**
  90       * The user object
  91       *
  92       * @var    \Joomla\CMS\User\User
  93       *
  94       * @since  4.0.0
  95       */
  96      protected $user = null;
  97  
  98      /**
  99       * The page class suffix
 100       *
 101       * @var    string
 102       *
 103       * @since  4.0.0
 104       */
 105      protected $pageclass_sfx = '';
 106  
 107      /**
 108       * Execute and display a template script.
 109       *
 110       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
 111       *
 112       * @return  void
 113       *
 114       * @throws  GenericDataException
 115       */
 116      public function display($tpl = null)
 117      {
 118          $user       = $this->getCurrentUser();
 119          $state      = $this->get('State');
 120          $items      = $this->get('Items');
 121          $pagination = $this->get('Pagination');
 122  
 123          if ($errors = $this->getModel()->getErrors()) {
 124              throw new GenericDataException(implode("\n", $errors), 500);
 125          }
 126  
 127          // Flag indicates to not add limitstart=0 to URL
 128          $pagination->hideEmptyLimitstart = true;
 129  
 130          // Get the page/component configuration
 131          $params = &$state->params;
 132  
 133          PluginHelper::importPlugin('content');
 134  
 135          foreach ($items as $item) {
 136              $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
 137  
 138              // No link for ROOT category
 139              if ($item->parent_alias === 'root') {
 140                  $item->parent_id = null;
 141              }
 142  
 143              $item->event = new \stdClass();
 144  
 145              // Old plugins: Ensure that text property is available
 146              if (!isset($item->text)) {
 147                  $item->text = $item->introtext;
 148              }
 149  
 150              Factory::getApplication()->triggerEvent('onContentPrepare', array('com_content.archive', &$item, &$item->params, 0));
 151  
 152              // Old plugins: Use processed text as introtext
 153              $item->introtext = $item->text;
 154  
 155              $results = Factory::getApplication()->triggerEvent('onContentAfterTitle', array('com_content.archive', &$item, &$item->params, 0));
 156              $item->event->afterDisplayTitle = trim(implode("\n", $results));
 157  
 158              $results = Factory::getApplication()->triggerEvent('onContentBeforeDisplay', array('com_content.archive', &$item, &$item->params, 0));
 159              $item->event->beforeDisplayContent = trim(implode("\n", $results));
 160  
 161              $results = Factory::getApplication()->triggerEvent('onContentAfterDisplay', array('com_content.archive', &$item, &$item->params, 0));
 162              $item->event->afterDisplayContent = trim(implode("\n", $results));
 163          }
 164  
 165          $form = new \stdClass();
 166  
 167          // Month Field
 168          $months = array(
 169              ''   => Text::_('COM_CONTENT_MONTH'),
 170              '1'  => Text::_('JANUARY_SHORT'),
 171              '2'  => Text::_('FEBRUARY_SHORT'),
 172              '3'  => Text::_('MARCH_SHORT'),
 173              '4'  => Text::_('APRIL_SHORT'),
 174              '5'  => Text::_('MAY_SHORT'),
 175              '6'  => Text::_('JUNE_SHORT'),
 176              '7'  => Text::_('JULY_SHORT'),
 177              '8'  => Text::_('AUGUST_SHORT'),
 178              '9'  => Text::_('SEPTEMBER_SHORT'),
 179              '10' => Text::_('OCTOBER_SHORT'),
 180              '11' => Text::_('NOVEMBER_SHORT'),
 181              '12' => Text::_('DECEMBER_SHORT')
 182          );
 183          $form->monthField = HTMLHelper::_(
 184              'select.genericlist',
 185              $months,
 186              'month',
 187              array(
 188                  'list.attr' => 'class="form-select"',
 189                  'list.select' => $state->get('filter.month'),
 190                  'option.key' => null
 191              )
 192          );
 193  
 194          // Year Field
 195          $this->years = $this->getModel()->getYears();
 196          $years = array();
 197          $years[] = HTMLHelper::_('select.option', null, Text::_('JYEAR'));
 198  
 199          for ($i = 0, $iMax = count($this->years); $i < $iMax; $i++) {
 200              $years[] = HTMLHelper::_('select.option', $this->years[$i], $this->years[$i]);
 201          }
 202  
 203          $form->yearField = HTMLHelper::_(
 204              'select.genericlist',
 205              $years,
 206              'year',
 207              array('list.attr' => 'class="form-select"', 'list.select' => $state->get('filter.year'))
 208          );
 209          $form->limitField = $pagination->getLimitBox();
 210  
 211          // Escape strings for HTML output
 212          $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', ''));
 213  
 214          $this->filter     = $state->get('list.filter');
 215          $this->form       = &$form;
 216          $this->items      = &$items;
 217          $this->params     = &$params;
 218          $this->user       = &$user;
 219          $this->pagination = &$pagination;
 220          $this->pagination->setAdditionalUrlParam('month', $state->get('filter.month'));
 221          $this->pagination->setAdditionalUrlParam('year', $state->get('filter.year'));
 222  
 223          $this->_prepareDocument();
 224  
 225          parent::display($tpl);
 226      }
 227  
 228      /**
 229       * Prepares the document
 230       *
 231       * @return  void
 232       */
 233      protected function _prepareDocument()
 234      {
 235          // Because the application sets a default page title,
 236          // we need to get it from the menu item itself
 237          $menu = Factory::getApplication()->getMenu()->getActive();
 238  
 239          if ($menu) {
 240              $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
 241          } else {
 242              $this->params->def('page_heading', Text::_('JGLOBAL_ARTICLES'));
 243          }
 244  
 245          $this->setDocumentTitle($this->params->get('page_title', ''));
 246  
 247          if ($this->params->get('menu-meta_description')) {
 248              $this->document->setDescription($this->params->get('menu-meta_description'));
 249          }
 250  
 251          if ($this->params->get('robots')) {
 252              $this->document->setMetaData('robots', $this->params->get('robots'));
 253          }
 254      }
 255  }


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