[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_templates/src/Service/HTML/ -> Templates.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_templates
   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\Templates\Administrator\Service\HTML;
  12  
  13  use Joomla\CMS\Application\ApplicationHelper;
  14  use Joomla\CMS\HTML\HTMLHelper;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\Uri\Uri;
  17  use Joomla\Component\Templates\Administrator\Helper\TemplatesHelper;
  18  
  19  // phpcs:disable PSR1.Files.SideEffects
  20  \defined('_JEXEC') or die;
  21  // phpcs:enable PSR1.Files.SideEffects
  22  
  23  /**
  24   * Html helper class.
  25   *
  26   * @since  1.6
  27   */
  28  class Templates
  29  {
  30      /**
  31       * Display the thumb for the template.
  32       *
  33       * @param   string|object  $template  The name of the template or the template object.
  34       * @param   integer        $clientId  The application client ID the template applies to
  35       *
  36       * @return  string  The html string
  37       *
  38       * @since   1.6
  39       *
  40       * @deprecated  5.0  The argument $template should be object and $clientId will be removed
  41       */
  42      public function thumb($template, $clientId = 0)
  43      {
  44          if (is_string($template)) {
  45              return HTMLHelper::_('image', 'template_thumbnail.png', Text::_('COM_TEMPLATES_PREVIEW'), [], true, -1);
  46          }
  47  
  48          $client = ApplicationHelper::getClientInfo($template->client_id);
  49  
  50          if (!isset($template->xmldata)) {
  51              $template->xmldata = TemplatesHelper::parseXMLTemplateFile($client->id === 0 ? JPATH_ROOT : JPATH_ROOT . '/administrator', $template->name);
  52          }
  53  
  54          if ((isset($template->xmldata->inheritable) && (bool) $template->xmldata->inheritable) || isset($template->xmldata->parent)) {
  55              if (isset($template->xmldata->parent) && (string) $template->xmldata->parent !== '' && file_exists(JPATH_ROOT . '/media/templates/' . $client->name . '/' . (string) $template->xmldata->parent . '/images/template_thumbnail.png')) {
  56                  if (file_exists(JPATH_ROOT . '/media/templates/' . $client->name . '/' . $template->element . '/images/template_preview.png')) {
  57                      $html = HTMLHelper::_('image', 'media/templates/' . $client->name . '/' . $template->element . '/images/template_thumbnail.png', Text::_('COM_TEMPLATES_PREVIEW'));
  58                      $html = '<button type="button" data-bs-target="#' . $template->element . '-Modal" class="thumbnail" data-bs-toggle="modal" title="' . Text::_('COM_TEMPLATES_CLICK_TO_ENLARGE') . '">' . $html . '</button>';
  59                  } elseif ((file_exists(JPATH_ROOT . '/media/templates/' . $client->name . '/' . (string) $template->xmldata->parent . '/images/template_preview.png'))) {
  60                      $html = HTMLHelper::_('image', 'media/templates/' . $client->name . '/' . (string) $template->xmldata->parent . '/images/template_thumbnail.png', Text::_('COM_TEMPLATES_PREVIEW'));
  61                      $html = '<button type="button" data-bs-target="#' . $template->element . '-Modal" class="thumbnail" data-bs-toggle="modal" title="' . Text::_('COM_TEMPLATES_CLICK_TO_ENLARGE') . '">' . $html . '</button>';
  62                  } else {
  63                      $html = HTMLHelper::_('image', 'template_thumb.svg', Text::_('COM_TEMPLATES_PREVIEW'), ['style' => 'width:200px; height:120px;']);
  64                  }
  65              } elseif (file_exists(JPATH_ROOT . '/media/templates/' . $client->name . '/' . $template->element . '/images/template_thumbnail.png')) {
  66                  $html = HTMLHelper::_('image', 'media/templates/' . $client->name . '/' . $template->element . '/images/template_thumbnail.png', Text::_('COM_TEMPLATES_PREVIEW'));
  67  
  68                  if (file_exists(JPATH_ROOT . '/media/templates/' . $client->name . '/' . $template->element . '/images/template_preview.png')) {
  69                      $html = '<button type="button" data-bs-target="#' . $template->element . '-Modal" class="thumbnail" data-bs-toggle="modal" title="' . Text::_('COM_TEMPLATES_CLICK_TO_ENLARGE') . '">' . $html . '</button>';
  70                  }
  71              } else {
  72                  $html = HTMLHelper::_('image', 'template_thumb.svg', Text::_('COM_TEMPLATES_PREVIEW'), ['style' => 'width:200px; height:120px;']);
  73              }
  74          } elseif (file_exists($client->path . '/templates/' . $template->element . '/template_thumbnail.png')) {
  75              $html = HTMLHelper::_('image', (($template->client_id == 0) ? Uri::root(true) : Uri::root(true) . '/administrator/') . '/templates/' . $template->element . '/template_thumbnail.png', Text::_('COM_TEMPLATES_PREVIEW'), [], false, -1);
  76  
  77              if (file_exists($client->path . '/templates/' . $template->element . '/template_preview.png')) {
  78                  $html = '<button type="button" data-bs-target="#' . $template->element . '-Modal" class="thumbnail" data-bs-toggle="modal" title="' . Text::_('COM_TEMPLATES_CLICK_TO_ENLARGE') . '">' . $html . '</button>';
  79              }
  80          } else {
  81              $html = HTMLHelper::_('image', 'template_thumb.svg', Text::_('COM_TEMPLATES_PREVIEW'), ['style' => 'width:200px; height:120px;']);
  82          }
  83  
  84          return $html;
  85      }
  86  
  87      /**
  88       * Renders the html for the modal linked to thumb.
  89       *
  90       * @param   string|object  $template  The name of the template or the template object.
  91       * @param   integer        $clientId  The application client ID the template applies to
  92       *
  93       * @return  string  The html string
  94       *
  95       * @since   3.4
  96       *
  97       * @deprecated  5.0  The argument $template should be object and $clientId will be removed
  98       */
  99      public function thumbModal($template, $clientId = 0)
 100      {
 101          if (is_string($template)) {
 102              return HTMLHelper::_('image', 'template_thumbnail.png', Text::_('COM_TEMPLATES_PREVIEW'), [], true, -1);
 103          }
 104  
 105          $html    = '';
 106          $thumb   = '';
 107          $preview = '';
 108          $client  = ApplicationHelper::getClientInfo($template->client_id);
 109  
 110          if (!isset($template->xmldata)) {
 111              $template->xmldata = TemplatesHelper::parseXMLTemplateFile($client->id === 0 ? JPATH_ROOT : JPATH_ROOT . '/administrator', $template->name);
 112          }
 113  
 114          if ((isset($template->xmldata->inheritable) && (bool) $template->xmldata->inheritable) || isset($template->xmldata->parent)) {
 115              if (isset($template->xmldata->parent) && (string) $template->xmldata->parent !== '') {
 116                  if (file_exists(JPATH_ROOT . '/media/templates/' . $client->name . '/' . $template->element . '/images/template_thumbnail.png')) {
 117                      $thumb = ($template->client_id == 0 ? Uri::root(true) : Uri::root(true) . 'administrator') . 'media/templates/' . $client->name . '/' . $template->element . '/images/template_thumbnail.png';
 118  
 119                      if (file_exists(JPATH_ROOT . '/media/templates/' . $client->name . '/' . $template->element . '/images/template_preview.png')) {
 120                          $preview = ($template->client_id == 0 ? Uri::root(true) : Uri::root(true) . '/administrator') . '/media/templates/' . $client->name . '/' . $template->element . '/images/template_preview.png';
 121                      }
 122                  } else {
 123                      $thumb = ($template->client_id == 0 ? Uri::root(true) : Uri::root(true) . 'administrator') . 'media/templates/' . $client->name . '/' . (string) $template->xmldata->parent . '/images/template_thumbnail.png';
 124  
 125                      if (file_exists(JPATH_ROOT . '/media/templates/' . $client->name . '/' . (string) $template->xmldata->parent . '/images/template_preview.png')) {
 126                          $preview = ($template->client_id == 0 ? Uri::root(true) : Uri::root(true) . '/administrator') . '/media/templates/' . $client->name . '/' . (string) $template->xmldata->parent . '/images/template_preview.png';
 127                      }
 128                  }
 129              } elseif (file_exists(JPATH_ROOT . '/media/templates/' . $client->name . '/' . $template->element . '/images/template_thumbnail.png')) {
 130                  $thumb = ($template->client_id == 0 ? Uri::root(true) : Uri::root(true) . '/administrator') . '/media/templates/' . $client->name . '/' . $template->element . '/images/template_thumbnail.png';
 131  
 132                  if (file_exists(JPATH_ROOT . '/media/templates/' . $client->name . '/' . $template->element . '/images/template_preview.png')) {
 133                      $preview = Uri::root(true) . '/media/templates/' . $client->name . '/' . $template->element . '/images/template_preview.png';
 134                  }
 135              }
 136          } elseif (file_exists($client->path . '/templates/' . $template->element . '/template_thumbnail.png')) {
 137              $thumb = (($template->client_id == 0) ? Uri::root(true) : Uri::root(true) . 'administrator') . '/templates/' . $template->element . '/template_thumbnail.png';
 138  
 139              if (file_exists($client->path . '/templates/' . $template->element . '/template_preview.png')) {
 140                  $preview = (($template->client_id == 0) ? Uri::root(true) : Uri::root(true) . '/administrator') . '/templates/' . $template->element . '/template_preview.png';
 141              }
 142          }
 143  
 144          if ($thumb !== '' && $preview !== '') {
 145              $footer = '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">'
 146              . Text::_('JTOOLBAR_CLOSE') . '</button>';
 147  
 148              $html .= HTMLHelper::_(
 149                  'bootstrap.renderModal',
 150                  $template->name . '-Modal',
 151                  array(
 152                      'title'  => Text::sprintf('COM_TEMPLATES_SCREENSHOT', ucfirst($template->name)),
 153                      'height' => '500px',
 154                      'width'  => '800px',
 155                      'footer' => $footer,
 156                  ),
 157                  '<div><img src="' . $preview . '" class="mw-100" alt="' . $template->name . '"></div>'
 158              );
 159          }
 160  
 161          return $html;
 162      }
 163  }


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