[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/components/com_contact/src/View/Featured/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Site
   5   * @subpackage  com_contact
   6   *
   7   * @copyright   (C) 2010 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\Contact\Site\View\Featured;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\HTML\HTMLHelper;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\Mail\MailHelper;
  17  use Joomla\CMS\MVC\View\GenericDataException;
  18  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('_JEXEC') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * Featured View class
  26   *
  27   * @since  1.6
  28   */
  29  class HtmlView extends BaseHtmlView
  30  {
  31      /**
  32       * The item model state
  33       *
  34       * @var    \Joomla\Registry\Registry
  35       *
  36       * @since  1.6.0
  37       */
  38      protected $state;
  39  
  40      /**
  41       * The item details
  42       *
  43       * @var    \Joomla\CMS\Object\CMSObject
  44       *
  45       * @since  1.6.0
  46       */
  47      protected $items;
  48  
  49      /**
  50       * The pagination object
  51       *
  52       * @var    \Joomla\CMS\Pagination\Pagination
  53       *
  54       * @since  1.6.0
  55       */
  56      protected $pagination;
  57  
  58      /**
  59       * The page parameters
  60       *
  61       * @var    \Joomla\Registry\Registry|null
  62       *
  63       * @since  4.0.0
  64       */
  65      protected $params = null;
  66  
  67      /**
  68       * The page class suffix
  69       *
  70       * @var    string
  71       *
  72       * @since  4.0.0
  73       */
  74      protected $pageclass_sfx = '';
  75  
  76      /**
  77       * Method to display the view.
  78       *
  79       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  80       *
  81       * @return  void
  82       *
  83       * @since   1.6
  84       */
  85      public function display($tpl = null)
  86      {
  87          $app    = Factory::getApplication();
  88          $params = $app->getParams();
  89  
  90          // Get some data from the models
  91          $state      = $this->get('State');
  92          $items      = $this->get('Items');
  93          $category   = $this->get('Category');
  94          $children   = $this->get('Children');
  95          $parent     = $this->get('Parent');
  96          $pagination = $this->get('Pagination');
  97  
  98          // Flag indicates to not add limitstart=0 to URL
  99          $pagination->hideEmptyLimitstart = true;
 100  
 101          // Check for errors.
 102          if (count($errors = $this->get('Errors'))) {
 103              throw new GenericDataException(implode("\n", $errors), 500);
 104          }
 105  
 106          // Prepare the data.
 107          // Compute the contact slug.
 108          for ($i = 0, $n = count($items); $i < $n; $i++) {
 109              $item       = &$items[$i];
 110              $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
 111              $temp       = $item->params;
 112              $item->params = clone $params;
 113              $item->params->merge($temp);
 114  
 115              if ($item->params->get('show_email', 0) == 1) {
 116                  $item->email_to = trim($item->email_to);
 117  
 118                  if (!empty($item->email_to) && MailHelper::isEmailAddress($item->email_to)) {
 119                      $item->email_to = HTMLHelper::_('email.cloak', $item->email_to);
 120                  } else {
 121                      $item->email_to = '';
 122                  }
 123              }
 124          }
 125  
 126          // Escape strings for HTML output
 127          $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', ''), ENT_COMPAT, 'UTF-8');
 128  
 129          $maxLevel         = $params->get('maxLevel', -1);
 130          $this->maxLevel   = &$maxLevel;
 131          $this->state      = &$state;
 132          $this->items      = &$items;
 133          $this->category   = &$category;
 134          $this->children   = &$children;
 135          $this->params     = &$params;
 136          $this->parent     = &$parent;
 137          $this->pagination = &$pagination;
 138  
 139          $this->_prepareDocument();
 140  
 141          parent::display($tpl);
 142      }
 143  
 144      /**
 145       * Prepares the document
 146       *
 147       * @return  void
 148       *
 149       * @since   1.6
 150       */
 151      protected function _prepareDocument()
 152      {
 153          // Because the application sets a default page title,
 154          // we need to get it from the menu item itself
 155          $menu = Factory::getApplication()->getMenu()->getActive();
 156  
 157          if ($menu) {
 158              $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
 159          } else {
 160              $this->params->def('page_heading', Text::_('COM_CONTACT_DEFAULT_PAGE_TITLE'));
 161          }
 162  
 163          $this->setDocumentTitle($this->params->get('page_title', ''));
 164  
 165          if ($this->params->get('menu-meta_description')) {
 166              $this->document->setDescription($this->params->get('menu-meta_description'));
 167          }
 168  
 169          if ($this->params->get('robots')) {
 170              $this->document->setMetaData('robots', $this->params->get('robots'));
 171          }
 172      }
 173  }


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