[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_templates/src/View/Template/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_templates
   6   *
   7   * @copyright   (C) 2008 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\Templates\Administrator\View\Template;
  12  
  13  use Joomla\CMS\Component\ComponentHelper;
  14  use Joomla\CMS\Factory;
  15  use Joomla\CMS\Filter\InputFilter;
  16  use Joomla\CMS\Form\Form;
  17  use Joomla\CMS\HTML\HTMLHelper;
  18  use Joomla\CMS\Language\Text;
  19  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  20  use Joomla\CMS\Object\CMSObject;
  21  use Joomla\CMS\Plugin\PluginHelper;
  22  use Joomla\CMS\Toolbar\Toolbar;
  23  use Joomla\CMS\Toolbar\ToolbarHelper;
  24  use Joomla\CMS\Uri\Uri;
  25  
  26  // phpcs:disable PSR1.Files.SideEffects
  27  \defined('_JEXEC') or die;
  28  // phpcs:enable PSR1.Files.SideEffects
  29  
  30  /**
  31   * View to edit a template style.
  32   *
  33   * @since  1.6
  34   */
  35  class HtmlView extends BaseHtmlView
  36  {
  37      /**
  38       * The Model state
  39       *
  40       * @var  CMSObject
  41       */
  42      protected $state;
  43  
  44      /**
  45       * The template details
  46       *
  47       * @var  \stdClass|false
  48       */
  49      protected $template;
  50  
  51      /**
  52       * For loading the source form
  53       *
  54       * @var  Form
  55       */
  56      protected $form;
  57  
  58      /**
  59       * For loading source file contents
  60       *
  61       * @var  array
  62       */
  63      protected $source;
  64  
  65      /**
  66       * Extension id
  67       *
  68       * @var  integer
  69       */
  70      protected $id;
  71  
  72      /**
  73       * Encrypted file path
  74       *
  75       * @var  string
  76       */
  77      protected $file;
  78  
  79      /**
  80       * List of available overrides
  81       *
  82       * @var   array
  83       */
  84      protected $overridesList;
  85  
  86      /**
  87       * Name of the present file
  88       *
  89       * @var  string
  90       */
  91      protected $fileName;
  92  
  93      /**
  94       * Type of the file - image, source, font
  95       *
  96       * @var  string
  97       */
  98      protected $type;
  99  
 100      /**
 101       * For loading image information
 102       *
 103       * @var  array
 104       */
 105      protected $image;
 106  
 107      /**
 108       * Template id for showing preview button
 109       *
 110       * @var  \stdClass
 111       */
 112      protected $preview;
 113  
 114      /**
 115       * For loading font information
 116       *
 117       * @var  array
 118       */
 119      protected $font;
 120  
 121      /**
 122       * A nested array containing list of files and folders
 123       *
 124       * @var  array
 125       */
 126      protected $files;
 127  
 128      /**
 129       * An array containing a list of compressed files
 130       *
 131       * @var  array
 132       */
 133      protected $archive;
 134  
 135      /**
 136       * The state of installer override plugin.
 137       *
 138       * @var  array
 139       *
 140       * @since  4.0.0
 141       */
 142      protected $pluginState;
 143  
 144      /**
 145       * A nested array containing list of files and folders in the media folder
 146       *
 147       * @var  array
 148       *
 149       * @since  4.1.0
 150       */
 151      protected $mediaFiles;
 152  
 153      /**
 154       * Execute and display a template script.
 155       *
 156       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
 157       *
 158       * @return  void|boolean
 159       */
 160      public function display($tpl = null)
 161      {
 162          $app               = Factory::getApplication();
 163          $this->file        = $app->input->get('file', '');
 164          $this->fileName    = InputFilter::getInstance()->clean(base64_decode($this->file), 'string');
 165          $explodeArray      = explode('.', $this->fileName);
 166          $ext               = end($explodeArray);
 167          $this->files       = $this->get('Files');
 168          $this->mediaFiles  = $this->get('MediaFiles');
 169          $this->state       = $this->get('State');
 170          $this->template    = $this->get('Template');
 171          $this->preview     = $this->get('Preview');
 172          $this->pluginState = PluginHelper::isEnabled('installer', 'override');
 173          $this->updatedList = $this->get('UpdatedList');
 174          $this->styles      = $this->get('AllTemplateStyles');
 175          $this->stylesHTML  = '';
 176  
 177          $params       = ComponentHelper::getParams('com_templates');
 178          $imageTypes   = explode(',', $params->get('image_formats'));
 179          $sourceTypes  = explode(',', $params->get('source_formats'));
 180          $fontTypes    = explode(',', $params->get('font_formats'));
 181          $archiveTypes = explode(',', $params->get('compressed_formats'));
 182  
 183          if (in_array($ext, $sourceTypes)) {
 184              $this->form   = $this->get('Form');
 185              $this->form->setFieldAttribute('source', 'syntax', $ext);
 186              $this->source = $this->get('Source');
 187              $this->type   = 'file';
 188          } elseif (in_array($ext, $imageTypes)) {
 189              try {
 190                  $this->image = $this->get('Image');
 191                  $this->type  = 'image';
 192              } catch (\RuntimeException $exception) {
 193                  $app->enqueueMessage(Text::_('COM_TEMPLATES_GD_EXTENSION_NOT_AVAILABLE'));
 194                  $this->type = 'home';
 195              }
 196          } elseif (in_array($ext, $fontTypes)) {
 197              $this->font = $this->get('Font');
 198              $this->type = 'font';
 199          } elseif (in_array($ext, $archiveTypes)) {
 200              $this->archive = $this->get('Archive');
 201              $this->type    = 'archive';
 202          } else {
 203              $this->type = 'home';
 204          }
 205  
 206          $this->overridesList = $this->get('OverridesList');
 207          $this->id            = $this->state->get('extension.id');
 208  
 209          // Check for errors.
 210          if (count($errors = $this->get('Errors'))) {
 211              $app->enqueueMessage(implode("\n", $errors));
 212  
 213              return false;
 214          }
 215  
 216          $this->addToolbar();
 217  
 218          if (!$this->getCurrentUser()->authorise('core.admin')) {
 219              $this->setLayout('readonly');
 220          }
 221  
 222          parent::display($tpl);
 223      }
 224  
 225      /**
 226       * Add the page title and toolbar.
 227       *
 228       * @since   1.6
 229       *
 230       * @return  void
 231       */
 232      protected function addToolbar()
 233      {
 234          $app   = Factory::getApplication();
 235          $user  = $this->getCurrentUser();
 236          $app->input->set('hidemainmenu', true);
 237  
 238          // User is global SuperUser
 239          $isSuperUser = $user->authorise('core.admin');
 240  
 241          // Get the toolbar object instance
 242          $bar = Toolbar::getInstance('toolbar');
 243          $explodeArray = explode('.', $this->fileName);
 244          $ext = end($explodeArray);
 245  
 246          ToolbarHelper::title(Text::sprintf('COM_TEMPLATES_MANAGER_VIEW_TEMPLATE', ucfirst($this->template->name)), 'icon-code thememanager');
 247  
 248          // Only show file edit buttons for global SuperUser
 249          if ($isSuperUser) {
 250              // Add an Apply and save button
 251              if ($this->type === 'file') {
 252                  ToolbarHelper::apply('template.apply');
 253                  ToolbarHelper::save('template.save');
 254              } elseif ($this->type === 'image') {
 255                  // Add a Crop and Resize button
 256                  ToolbarHelper::custom('template.cropImage', 'icon-crop', '', 'COM_TEMPLATES_BUTTON_CROP', false);
 257                  ToolbarHelper::modal('resizeModal', 'icon-expand', 'COM_TEMPLATES_BUTTON_RESIZE');
 258              } elseif ($this->type === 'archive') {
 259                  // Add an extract button
 260                  ToolbarHelper::custom('template.extractArchive', 'chevron-down', '', 'COM_TEMPLATES_BUTTON_EXTRACT_ARCHIVE', false);
 261              } elseif ($this->type === 'home') {
 262                  // Add a copy/child template button
 263                  if (isset($this->template->xmldata->inheritable) && (string) $this->template->xmldata->inheritable === '1') {
 264                      ToolbarHelper::modal('childModal', 'icon-copy', 'COM_TEMPLATES_BUTTON_TEMPLATE_CHILD', false);
 265                  } elseif (!isset($this->template->xmldata->parent) || $this->template->xmldata->parent == '') {
 266                      ToolbarHelper::modal('copyModal', 'icon-copy', 'COM_TEMPLATES_BUTTON_COPY_TEMPLATE', false);
 267                  }
 268              }
 269          }
 270  
 271          // Add a Template preview button
 272          if ($this->type === 'home') {
 273              $client = (int) $this->preview->client_id === 1 ? 'administrator/' : '';
 274              $bar->linkButton('preview')
 275                  ->icon('icon-image')
 276                  ->text('COM_TEMPLATES_BUTTON_PREVIEW')
 277                  ->url(Uri::root() . $client . 'index.php?tp=1&templateStyle=' . $this->preview->id)
 278                  ->attributes(['target' => '_new']);
 279          }
 280  
 281          // Only show file manage buttons for global SuperUser
 282          if ($isSuperUser) {
 283              if ($this->type === 'home') {
 284                  // Add Manage folders button
 285                  ToolbarHelper::modal('folderModal', 'icon-folder icon white', 'COM_TEMPLATES_BUTTON_FOLDERS');
 286  
 287                  // Add a new file button
 288                  ToolbarHelper::modal('fileModal', 'icon-file', 'COM_TEMPLATES_BUTTON_FILE');
 289              } else {
 290                  // Add a Rename file Button
 291                  ToolbarHelper::modal('renameModal', 'icon-sync', 'COM_TEMPLATES_BUTTON_RENAME_FILE');
 292  
 293                  // Add a Delete file Button
 294                  ToolbarHelper::modal('deleteModal', 'icon-times', 'COM_TEMPLATES_BUTTON_DELETE_FILE', 'btn-danger');
 295              }
 296          }
 297  
 298          if (count($this->updatedList) !== 0 && $this->pluginState) {
 299              $dropdown = $bar->dropdownButton('override-group')
 300                  ->text('COM_TEMPLATES_BUTTON_CHECK')
 301                  ->toggleSplit(false)
 302                  ->icon('icon-ellipsis-h')
 303                  ->buttonClass('btn btn-action')
 304                  ->form('updateForm')
 305                  ->listCheck(true);
 306  
 307              $childBar = $dropdown->getChildToolbar();
 308  
 309              $childBar->publish('template.publish')
 310                  ->text('COM_TEMPLATES_BUTTON_CHECK_LIST_ENTRY')
 311                  ->form('updateForm')
 312                  ->listCheck(true);
 313              $childBar->unpublish('template.unpublish')
 314                  ->text('COM_TEMPLATES_BUTTON_UNCHECK_LIST_ENTRY')
 315                  ->form('updateForm')
 316                  ->listCheck(true);
 317              $childBar->unpublish('template.deleteOverrideHistory')
 318                  ->text('COM_TEMPLATES_BUTTON_DELETE_LIST_ENTRY')
 319                  ->form('updateForm')
 320                  ->listCheck(true);
 321          }
 322  
 323          if ($this->type === 'home') {
 324              ToolbarHelper::cancel('template.cancel', 'JTOOLBAR_CLOSE');
 325          } else {
 326              ToolbarHelper::cancel('template.close', 'COM_TEMPLATES_BUTTON_CLOSE_FILE');
 327          }
 328  
 329          ToolbarHelper::divider();
 330          ToolbarHelper::help('Templates:_Customise');
 331      }
 332  
 333      /**
 334       * Method for creating the collapsible tree.
 335       *
 336       * @param   array  $array  The value of the present node for recursion
 337       *
 338       * @return  string
 339       *
 340       * @note    Uses recursion
 341       * @since   3.2
 342       */
 343      protected function directoryTree($array)
 344      {
 345          $temp        = $this->files;
 346          $this->files = $array;
 347          $txt         = $this->loadTemplate('tree');
 348          $this->files = $temp;
 349  
 350          return $txt;
 351      }
 352  
 353      /**
 354       * Method for listing the folder tree in modals.
 355       *
 356       * @param   array  $array  The value of the present node for recursion
 357       *
 358       * @return  string
 359       *
 360       * @note    Uses recursion
 361       * @since   3.2
 362       */
 363      protected function folderTree($array)
 364      {
 365          $temp        = $this->files;
 366          $this->files = $array;
 367          $txt         = $this->loadTemplate('folders');
 368          $this->files = $temp;
 369  
 370          return $txt;
 371      }
 372  
 373      /**
 374       * Method for creating the collapsible tree.
 375       *
 376       * @param   array  $array  The value of the present node for recursion
 377       *
 378       * @return  string
 379       *
 380       * @note    Uses recursion
 381       * @since   4.1.0
 382       */
 383      protected function mediaTree($array)
 384      {
 385          $temp             = $this->mediaFiles;
 386          $this->mediaFiles = $array;
 387          $txt              = $this->loadTemplate('tree_media');
 388          $this->mediaFiles = $temp;
 389  
 390          return $txt;
 391      }
 392  
 393      /**
 394       * Method for listing the folder tree in modals.
 395       *
 396       * @param   array  $array  The value of the present node for recursion
 397       *
 398       * @return  string
 399       *
 400       * @note    Uses recursion
 401       * @since   4.1.0
 402       */
 403      protected function mediaFolderTree($array)
 404      {
 405          $temp             = $this->mediaFiles;
 406          $this->mediaFiles = $array;
 407          $txt              = $this->loadTemplate('media_folders');
 408          $this->mediaFiles = $temp;
 409  
 410          return $txt;
 411      }
 412  }


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