Source for file templates.php

Documentation is available at templates.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_templates
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Templates component helper.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_templates
  17.  * @since       1.6
  18.  */
  19. {
  20.     /**
  21.      * Configure the Linkbar.
  22.      *
  23.      * @param   string  $vName  The name of the active view.
  24.      *
  25.      * @return  void 
  26.      */
  27.     public static function addSubmenu($vName)
  28.     {
  29.         JHtmlSidebar::addEntry(
  30.             JText::_('COM_TEMPLATES_SUBMENU_STYLES'),
  31.             'index.php?option=com_templates&view=styles',
  32.             $vName == 'styles'
  33.         );
  34.         JHtmlSidebar::addEntry(
  35.             JText::_('COM_TEMPLATES_SUBMENU_TEMPLATES'),
  36.             'index.php?option=com_templates&view=templates',
  37.             $vName == 'templates'
  38.         );
  39.     }
  40.  
  41.     /**
  42.      * Gets a list of the actions that can be performed.
  43.      *
  44.      * @return  JObject 
  45.      */
  46.     public static function getActions()
  47.     {
  48.         $user JFactory::getUser();
  49.         $result new JObject;
  50.  
  51.         $actions JAccess::getActions('com_templates');
  52.  
  53.         foreach ($actions as $action)
  54.         {
  55.             $result->set($action->name$user->authorise($action->name'com_templates'));
  56.         }
  57.  
  58.         return $result;
  59.     }
  60.  
  61.     /**
  62.      * Get a list of filter options for the application clients.
  63.      *
  64.      * @return  array  An array of JHtmlOption elements.
  65.      */
  66.     public static function getClientOptions()
  67.     {
  68.         // Build the filter options.
  69.         $options array();
  70.         $options[JHtml::_('select.option''0'JText::_('JSITE'));
  71.         $options[JHtml::_('select.option''1'JText::_('JADMINISTRATOR'));
  72.  
  73.         return $options;
  74.     }
  75.  
  76.     /**
  77.      * Get a list of filter options for the templates with styles.
  78.      *
  79.      * @param   mixed  $clientId  The CMS client id (0:site | 1:administrator) or '*' for all.
  80.      *
  81.      * @return  array  An array of JHtmlOption elements.
  82.      */
  83.     public static function getTemplateOptions($clientId '*')
  84.     {
  85.         // Build the filter options.
  86.         $db JFactory::getDbo();
  87.         $query $db->getQuery(true);
  88.  
  89.         if ($clientId != '*')
  90.         {
  91.             $query->where('client_id=' . (int) $clientId);
  92.         }
  93.  
  94.         $query->select('element as value, name as text, extension_id as e_id')
  95.             ->from('#__extensions')
  96.             ->where('type = ' $db->quote('template'))
  97.             ->where('enabled = 1')
  98.             ->order('client_id')
  99.             ->order('name');
  100.         $db->setQuery($query);
  101.         $options $db->loadObjectList();
  102.  
  103.         return $options;
  104.     }
  105.  
  106.     /**
  107.      * TODO
  108.      *
  109.      * @param   string  $templateBaseDir  TODO
  110.      * @param   string  $templateDir      TODO
  111.      *
  112.      * @return  boolean|JObject
  113.      */
  114.     public static function parseXMLTemplateFile($templateBaseDir$templateDir)
  115.     {
  116.         $data new JObject;
  117.  
  118.         // Check of the xml file exists
  119.         $filePath JPath::clean($templateBaseDir '/templates/' $templateDir '/templateDetails.xml');
  120.  
  121.         if (is_file($filePath))
  122.         {
  123.             $xml JInstaller::parseXMLInstallFile($filePath);
  124.  
  125.             if ($xml['type'!= 'template')
  126.             {
  127.                 return false;
  128.             }
  129.  
  130.             foreach ($xml as $key => $value)
  131.             {
  132.                 $data->set($key$value);
  133.             }
  134.         }
  135.  
  136.         return $data;
  137.     }
  138.  
  139.     /**
  140.      * TODO
  141.      *
  142.      * @param   integer  $clientId     TODO
  143.      * @param   string   $templateDir  TODO
  144.      *
  145.      * @return  boolean|array
  146.      *
  147.      * @since   3.0
  148.      */
  149.     public static function getPositions($clientId$templateDir)
  150.     {
  151.         $positions array();
  152.  
  153.         $templateBaseDir $clientId JPATH_ADMINISTRATOR JPATH_SITE;
  154.         $filePath JPath::clean($templateBaseDir '/templates/' $templateDir '/templateDetails.xml');
  155.  
  156.         if (is_file($filePath))
  157.         {
  158.             // Read the file to see if it's a valid component XML file
  159.             $xml simplexml_load_file($filePath);
  160.  
  161.             if (!$xml)
  162.             {
  163.                 return false;
  164.             }
  165.  
  166.             // Check for a valid XML root tag.
  167.  
  168.             // Extensions use 'extension' as the root tag.  Languages use 'metafile' instead
  169.  
  170.             if ($xml->getName(!= 'extension' && $xml->getName(!= 'metafile')
  171.             {
  172.                 unset($xml);
  173.  
  174.                 return false;
  175.             }
  176.  
  177.             $positions = (array) $xml->positions;
  178.  
  179.             if (isset($positions['position']))
  180.             {
  181.                 $positions $positions['position'];
  182.             }
  183.             else
  184.             {
  185.                 $positions array();
  186.             }
  187.         }
  188.  
  189.         return $positions;
  190.     }
  191. }

Documentation generated on Tue, 19 Nov 2013 15:15:36 +0100 by phpDocumentor 1.4.3