Source for file templates.php

Documentation is available at templates.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_config
  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.  * Template style model.
  14.  *
  15.  * @package     Joomla.Site
  16.  * @subpackage  com_config
  17.  * @since       3.2
  18.  */
  19. {
  20.     /**
  21.      * Method to auto-populate the model state.
  22.      *
  23.      * Note. Calling getState in this method will result in recursion.
  24.      *
  25.      * @since   3.2
  26.      */
  27.     protected function populateState()
  28.     {
  29.         $state $this->loadState();
  30.  
  31.         // Load the parameters.
  32.         $params    JComponentHelper::getParams('com_templates');
  33.         $state->set('params'$params);
  34.  
  35.         $this->setState($state);
  36.     }
  37.  
  38.     /**
  39.      * Method to get the record form.
  40.      *
  41.      * @param   array    $data      An optional array of data for the form to interogate.
  42.      * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not.
  43.      *
  44.      * @return  JForm    A JForm object on success, false on failure
  45.      *
  46.      * @since   3.2
  47.      */
  48.     public function getForm($data array()$loadData true)
  49.     {
  50.         // Get the form.
  51.         $form $this->loadForm('com_config.templates''templates'array('control' => 'jform''load_data' => $loadData));
  52.  
  53.         try
  54.         {
  55.             $form new JForm('com_config.templates');
  56.             $data array();
  57.             $this->preprocessForm($form$data);
  58.  
  59.             // Load the data into the form
  60.             $form->bind($data);
  61.         }
  62.         catch (Exception $e)
  63.         {
  64.             JFactory::getApplication()->enqueueMessage($e->getMessage());
  65.  
  66.             return false;
  67.         }
  68.  
  69.         if (empty($form))
  70.         {
  71.             return false;
  72.         }
  73.  
  74.         return $form;
  75.     }
  76.  
  77.     /**
  78.      * Method to preprocess the form
  79.      *
  80.      * @param   JForm   $form   A form object.
  81.      * @param   mixed   $data   The data expected for the form.
  82.      * @param   string  $group  Plugin group to load
  83.      *
  84.      * @return  void 
  85.      *
  86.      * @since   3.2
  87.      * @throws    Exception if there is an error in the form event.
  88.      */
  89.     protected function preprocessForm(JForm $form$data$group 'content')
  90.     {
  91.         $lang JFactory::getLanguage();
  92.  
  93.         $template JFactory::getApplication()->getTemplate();
  94.  
  95.         jimport('joomla.filesystem.path');
  96.  
  97.         // Load the core and/or local language file(s).
  98.         $lang->load('tpl_' $templateJPATH_BASEnullfalsetrue)
  99.         ||    $lang->load('tpl_' $templateJPATH_BASE '/templates/' $templatenullfalsetrue);
  100.  
  101.         // Look for com_config.xml, which contains fileds to display
  102.         $formFile    JPath::clean(JPATH_BASE '/templates/' $template '/com_config.xml');
  103.  
  104.         if (!file_exists($formFile))
  105.         {
  106.             // If com_config.xml not found, fall back to templateDetails.xml
  107.             $formFile    JPath::clean(JPATH_BASE '/templates/' $template '/templateDetails.xml');
  108.         }
  109.  
  110.         if (file_exists($formFile))
  111.         {
  112.             // Get the template form.
  113.             if (!$form->loadFile($formFilefalse'//config'))
  114.             {
  115.                 throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
  116.             }
  117.         }
  118.  
  119.         // Attempt to load the xml file.
  120.         if (!$xml simplexml_load_file($formFile))
  121.         {
  122.             throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
  123.         }
  124.  
  125.         // Trigger the default form events.
  126.         parent::preprocessForm($form$data$group);
  127.     }
  128. }

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