[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_templates/src/Helper/ -> TemplatesHelper.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_templates
   6   *
   7   * @copyright   (C) 2017 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\Helper;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Filesystem\Path;
  15  use Joomla\CMS\HTML\HTMLHelper;
  16  use Joomla\CMS\Installer\Installer;
  17  use Joomla\CMS\Language\Text;
  18  use Joomla\CMS\Object\CMSObject;
  19  use Joomla\Database\ParameterType;
  20  
  21  // phpcs:disable PSR1.Files.SideEffects
  22  \defined('_JEXEC') or die;
  23  // phpcs:enable PSR1.Files.SideEffects
  24  
  25  /**
  26   * Templates component helper.
  27   *
  28   * @since  1.6
  29   */
  30  class TemplatesHelper
  31  {
  32      /**
  33       * Get a list of filter options for the application clients.
  34       *
  35       * @return  array  An array of HtmlOption elements.
  36       */
  37      public static function getClientOptions()
  38      {
  39          // Build the filter options.
  40          $options = array();
  41          $options[] = HTMLHelper::_('select.option', '0', Text::_('JSITE'));
  42          $options[] = HTMLHelper::_('select.option', '1', Text::_('JADMINISTRATOR'));
  43  
  44          return $options;
  45      }
  46  
  47      /**
  48       * Get a list of filter options for the templates with styles.
  49       *
  50       * @param   mixed  $clientId  The CMS client id (0:site | 1:administrator) or '*' for all.
  51       *
  52       * @return  array
  53       */
  54      public static function getTemplateOptions($clientId = '*')
  55      {
  56          // Build the filter options.
  57          $db = Factory::getDbo();
  58          $query = $db->getQuery(true);
  59  
  60          $query->select($db->quoteName('element', 'value'))
  61              ->select($db->quoteName('name', 'text'))
  62              ->select($db->quoteName('extension_id', 'e_id'))
  63              ->from($db->quoteName('#__extensions'))
  64              ->where($db->quoteName('type') . ' = ' . $db->quote('template'))
  65              ->where($db->quoteName('enabled') . ' = 1')
  66              ->order($db->quoteName('client_id') . ' ASC')
  67              ->order($db->quoteName('name') . ' ASC');
  68  
  69          if ($clientId != '*') {
  70              $clientId = (int) $clientId;
  71              $query->where($db->quoteName('client_id') . ' = :clientid')
  72                  ->bind(':clientid', $clientId, ParameterType::INTEGER);
  73          }
  74  
  75          $db->setQuery($query);
  76          $options = $db->loadObjectList();
  77  
  78          return $options;
  79      }
  80  
  81      /**
  82       * @param   string  $templateBaseDir
  83       * @param   string  $templateDir
  84       *
  85       * @return boolean|CMSObject
  86       */
  87      public static function parseXMLTemplateFile($templateBaseDir, $templateDir)
  88      {
  89          $data = new CMSObject();
  90  
  91          // Check of the xml file exists
  92          $filePath = Path::clean($templateBaseDir . '/templates/' . $templateDir . '/templateDetails.xml');
  93  
  94          if (is_file($filePath)) {
  95              $xml = Installer::parseXMLInstallFile($filePath);
  96  
  97              if ($xml['type'] != 'template') {
  98                  return false;
  99              }
 100  
 101              foreach ($xml as $key => $value) {
 102                  $data->set($key, $value);
 103              }
 104          }
 105  
 106          return $data;
 107      }
 108  
 109      /**
 110       * @param   integer  $clientId
 111       * @param   string   $templateDir
 112       *
 113       * @return  boolean|array
 114       *
 115       * @since   3.0
 116       */
 117      public static function getPositions($clientId, $templateDir)
 118      {
 119          $positions = array();
 120  
 121          $templateBaseDir = $clientId ? JPATH_ADMINISTRATOR : JPATH_SITE;
 122          $filePath = Path::clean($templateBaseDir . '/templates/' . $templateDir . '/templateDetails.xml');
 123  
 124          if (is_file($filePath)) {
 125              // Read the file to see if it's a valid component XML file
 126              $xml = simplexml_load_file($filePath);
 127  
 128              if (!$xml) {
 129                  return false;
 130              }
 131  
 132              // Check for a valid XML root tag.
 133  
 134              // Extensions use 'extension' as the root tag.  Languages use 'metafile' instead
 135  
 136              if ($xml->getName() != 'extension' && $xml->getName() != 'metafile') {
 137                  unset($xml);
 138  
 139                  return false;
 140              }
 141  
 142              $positions = (array) $xml->positions;
 143  
 144              if (isset($positions['position'])) {
 145                  $positions = (array) $positions['position'];
 146              } else {
 147                  $positions = array();
 148              }
 149          }
 150  
 151          return $positions;
 152      }
 153  }


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