[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/components/com_content/src/View/Form/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Site
   5   * @subpackage  com_content
   6   *
   7   * @copyright   (C) 2009 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\Form;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Helper\TagsHelper;
  15  use Joomla\CMS\Language\Multilanguage;
  16  use Joomla\CMS\Language\Text;
  17  use Joomla\CMS\MVC\View\GenericDataException;
  18  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  19  use Joomla\CMS\Plugin\PluginHelper;
  20  
  21  // phpcs:disable PSR1.Files.SideEffects
  22  \defined('_JEXEC') or die;
  23  // phpcs:enable PSR1.Files.SideEffects
  24  
  25  /**
  26   * HTML Article View class for the Content component
  27   *
  28   * @since  1.5
  29   */
  30  class HtmlView extends BaseHtmlView
  31  {
  32      /**
  33       * The Form object
  34       *
  35       * @var  \Joomla\CMS\Form\Form
  36       */
  37      protected $form;
  38  
  39      /**
  40       * The item being created
  41       *
  42       * @var  \stdClass
  43       */
  44      protected $item;
  45  
  46      /**
  47       * The page to return to after the article is submitted
  48       *
  49       * @var  string
  50       */
  51      protected $return_page = '';
  52  
  53      /**
  54       * The model state
  55       *
  56       * @var  \Joomla\CMS\Object\CMSObject
  57       */
  58      protected $state;
  59  
  60      /**
  61       * The page parameters
  62       *
  63       * @var    \Joomla\Registry\Registry|null
  64       *
  65       * @since  4.0.0
  66       */
  67      protected $params = null;
  68  
  69      /**
  70       * The page class suffix
  71       *
  72       * @var    string
  73       *
  74       * @since  4.0.0
  75       */
  76      protected $pageclass_sfx = '';
  77  
  78      /**
  79       * The user object
  80       *
  81       * @var \Joomla\CMS\User\User
  82       *
  83       * @since  4.0.0
  84       */
  85      protected $user = null;
  86  
  87      /**
  88       * Should we show a captcha form for the submission of the article?
  89       *
  90       * @var    boolean
  91       *
  92       * @since  3.7.0
  93       */
  94      protected $captchaEnabled = false;
  95  
  96      /**
  97       * Should we show Save As Copy button?
  98       *
  99       * @var    boolean
 100       * @since  4.1.0
 101       */
 102      protected $showSaveAsCopy = false;
 103  
 104      /**
 105       * Execute and display a template script.
 106       *
 107       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
 108       *
 109       * @return  void|boolean
 110       */
 111      public function display($tpl = null)
 112      {
 113          $app  = Factory::getApplication();
 114          $user = $app->getIdentity();
 115  
 116          // Get model data.
 117          $this->state       = $this->get('State');
 118          $this->item        = $this->get('Item');
 119          $this->form        = $this->get('Form');
 120          $this->return_page = $this->get('ReturnPage');
 121  
 122          if (empty($this->item->id)) {
 123              $catid = $this->state->params->get('catid');
 124  
 125              if ($this->state->params->get('enable_category') == 1 && $catid) {
 126                  $authorised = $user->authorise('core.create', 'com_content.category.' . $catid);
 127              } else {
 128                  $authorised = $user->authorise('core.create', 'com_content') || count($user->getAuthorisedCategories('com_content', 'core.create'));
 129              }
 130          } else {
 131              $authorised = $this->item->params->get('access-edit');
 132          }
 133  
 134          if ($authorised !== true) {
 135              $app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error');
 136              $app->setHeader('status', 403, true);
 137  
 138              return false;
 139          }
 140  
 141          $this->item->tags = new TagsHelper();
 142  
 143          if (!empty($this->item->id)) {
 144              $this->item->tags->getItemTags('com_content.article', $this->item->id);
 145  
 146              $this->item->images = json_decode($this->item->images);
 147              $this->item->urls = json_decode($this->item->urls);
 148  
 149              $tmp = new \stdClass();
 150              $tmp->images = $this->item->images;
 151              $tmp->urls = $this->item->urls;
 152              $this->form->bind($tmp);
 153          }
 154  
 155          // Check for errors.
 156          if (count($errors = $this->get('Errors'))) {
 157              throw new GenericDataException(implode("\n", $errors), 500);
 158          }
 159  
 160          // Create a shortcut to the parameters.
 161          $params = &$this->state->params;
 162  
 163          // Escape strings for HTML output
 164          $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', ''));
 165  
 166          $this->params = $params;
 167  
 168          // Override global params with article specific params
 169          $this->params->merge($this->item->params);
 170          $this->user   = $user;
 171  
 172          // Propose current language as default when creating new article
 173          if (empty($this->item->id) && Multilanguage::isEnabled() && $params->get('enable_category') != 1) {
 174              $lang = Factory::getLanguage()->getTag();
 175              $this->form->setFieldAttribute('language', 'default', $lang);
 176          }
 177  
 178          $captchaSet = $params->get('captcha', Factory::getApplication()->get('captcha', '0'));
 179  
 180          foreach (PluginHelper::getPlugin('captcha') as $plugin) {
 181              if ($captchaSet === $plugin->name) {
 182                  $this->captchaEnabled = true;
 183                  break;
 184              }
 185          }
 186  
 187          // If the article is being edited and the current user has permission to create article
 188          if (
 189              $this->item->id
 190              && ($user->authorise('core.create', 'com_content') || \count($user->getAuthorisedCategories('com_content', 'core.create')))
 191          ) {
 192              $this->showSaveAsCopy = true;
 193          }
 194  
 195          $this->_prepareDocument();
 196  
 197          parent::display($tpl);
 198      }
 199  
 200      /**
 201       * Prepares the document
 202       *
 203       * @return  void
 204       */
 205      protected function _prepareDocument()
 206      {
 207          $app   = Factory::getApplication();
 208  
 209          // Because the application sets a default page title,
 210          // we need to get it from the menu item itself
 211          $menu = $app->getMenu()->getActive();
 212  
 213          if ($menu) {
 214              $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
 215          } else {
 216              $this->params->def('page_heading', Text::_('COM_CONTENT_FORM_EDIT_ARTICLE'));
 217          }
 218  
 219          $title = $this->params->def('page_title', Text::_('COM_CONTENT_FORM_EDIT_ARTICLE'));
 220  
 221          $this->setDocumentTitle($title);
 222  
 223          $app->getPathway()->addItem($title);
 224  
 225          if ($this->params->get('menu-meta_description')) {
 226              $this->document->setDescription($this->params->get('menu-meta_description'));
 227          }
 228  
 229          if ($this->params->get('robots')) {
 230              $this->document->setMetaData('robots', $this->params->get('robots'));
 231          }
 232      }
 233  }


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