Source for file modulelayout.php

Documentation is available at modulelayout.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Legacy
  4.  * @subpackage  Form
  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
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. jimport('joomla.filesystem.folder');
  13.  
  14. /**
  15.  * Form Field to display a list of the layouts for module display from the module or template overrides.
  16.  *
  17.  * @package     Joomla.Legacy
  18.  * @subpackage  Form
  19.  * @since       11.1
  20.  */
  21. {
  22.     /**
  23.      * The form field type.
  24.      *
  25.      * @var    string 
  26.      * @since  11.1
  27.      */
  28.     protected $type = 'ModuleLayout';
  29.  
  30.     /**
  31.      * Method to get the field input for module layouts.
  32.      *
  33.      * @return  string  The field input.
  34.      *
  35.      * @since   11.1
  36.      */
  37.     protected function getInput()
  38.     {
  39.         // Get the client id.
  40.         $clientId $this->element['client_id'];
  41.  
  42.         if (is_null($clientId&& $this->form instanceof JForm)
  43.         {
  44.             $clientId $this->form->getValue('client_id');
  45.         }
  46.         $clientId = (int) $clientId;
  47.  
  48.         $client JApplicationHelper::getClientInfo($clientId);
  49.  
  50.         // Get the module.
  51.         $module = (string) $this->element['module'];
  52.  
  53.         if (empty($module&& ($this->form instanceof JForm))
  54.         {
  55.             $module $this->form->getValue('module');
  56.         }
  57.  
  58.         $module preg_replace('#\W#'''$module);
  59.  
  60.         // Get the template.
  61.         $template = (string) $this->element['template'];
  62.         $template preg_replace('#\W#'''$template);
  63.  
  64.         // Get the style.
  65.         if ($this->form instanceof JForm)
  66.         {
  67.             $template_style_id $this->form->getValue('template_style_id');
  68.         }
  69.  
  70.         $template_style_id preg_replace('#\W#'''$template_style_id);
  71.  
  72.         // If an extension and view are present build the options.
  73.         if ($module && $client)
  74.         {
  75.  
  76.             // Load language file
  77.             $lang JFactory::getLanguage();
  78.             $lang->load($module '.sys'$client->pathnullfalsetrue)
  79.                 || $lang->load($module '.sys'$client->path '/modules/' $modulenullfalsetrue);
  80.  
  81.             // Get the database object and a new query object.
  82.             $db JFactory::getDbo();
  83.             $query $db->getQuery(true);
  84.  
  85.             // Build the query.
  86.             $query->select('element, name')
  87.                 ->from('#__extensions as e')
  88.                 ->where('e.client_id = ' . (int) $clientId)
  89.                 ->where('e.type = ' $db->quote('template'))
  90.                 ->where('e.enabled = 1');
  91.  
  92.             if ($template)
  93.             {
  94.                 $query->where('e.element = ' $db->quote($template));
  95.             }
  96.  
  97.             if ($template_style_id)
  98.             {
  99.                 $query->join('LEFT''#__template_styles as s on s.template=e.element')
  100.                     ->where('s.id=' . (int) $template_style_id);
  101.             }
  102.  
  103.             // Set the query and load the templates.
  104.             $db->setQuery($query);
  105.             $templates $db->loadObjectList('element');
  106.  
  107.             // Build the search paths for module layouts.
  108.             $module_path JPath::clean($client->path '/modules/' $module '/tmpl');
  109.  
  110.             // Prepare array of component layouts
  111.             $module_layouts array();
  112.  
  113.             // Prepare the grouped list
  114.             $groups array();
  115.  
  116.             // Add the layout options from the module path.
  117.             if (is_dir($module_path&& ($module_layouts JFolder::files($module_path'^[^_]*\.php$')))
  118.             {
  119.                 // Create the group for the module
  120.                 $groups['_'array();
  121.                 $groups['_']['id'$this->id . '__';
  122.                 $groups['_']['text'JText::sprintf('JOPTION_FROM_MODULE');
  123.                 $groups['_']['items'array();
  124.  
  125.                 foreach ($module_layouts as $file)
  126.                 {
  127.                     // Add an option to the module group
  128.                     $value basename($file'.php');
  129.                     $text $lang->hasKey($key strtoupper($module '_LAYOUT_' $value)) JText::_($key$value;
  130.                     $groups['_']['items'][JHtml::_('select.option''_:' $value$text);
  131.                 }
  132.             }
  133.  
  134.             // Loop on all templates
  135.             if ($templates)
  136.             {
  137.                 foreach ($templates as $template)
  138.                 {
  139.                     // Load language file
  140.                     $lang->load('tpl_' $template->element '.sys'$client->pathnullfalsetrue)
  141.                         || $lang->load('tpl_' $template->element '.sys'$client->path '/templates/' $template->elementnullfalsetrue);
  142.  
  143.                     $template_path JPath::clean($client->path '/templates/' $template->element '/html/' $module);
  144.  
  145.                     // Add the layout options from the template path.
  146.                     if (is_dir($template_path&& ($files JFolder::files($template_path'^[^_]*\.php$')))
  147.                     {
  148.                         foreach ($files as $i => $file)
  149.                         {
  150.                             // Remove layout that already exist in component ones
  151.                             if (in_array($file$module_layouts))
  152.                             {
  153.                                 unset($files[$i]);
  154.                             }
  155.                         }
  156.  
  157.                         if (count($files))
  158.                         {
  159.                             // Create the group for the template
  160.                             $groups[$template->elementarray();
  161.                             $groups[$template->element]['id'$this->id . '_' $template->element;
  162.                             $groups[$template->element]['text'JText::sprintf('JOPTION_FROM_TEMPLATE'$template->name);
  163.                             $groups[$template->element]['items'array();
  164.  
  165.                             foreach ($files as $file)
  166.                             {
  167.                                 // Add an option to the template group
  168.                                 $value basename($file'.php');
  169.                                 $text $lang->hasKey($key strtoupper('TPL_' $template->element '_' $module '_LAYOUT_' $value))
  170.                                     ? JText::_($key$value;
  171.                                 $groups[$template->element]['items'][JHtml::_('select.option'$template->element ':' $value$text);
  172.                             }
  173.                         }
  174.                     }
  175.                 }
  176.             }
  177.             // Compute attributes for the grouped list
  178.             $attr $this->element['size'' size="' . (int) $this->element['size''"' '';
  179.  
  180.             // Prepare HTML code
  181.             $html array();
  182.  
  183.             // Compute the current selected values
  184.             $selected array($this->value);
  185.  
  186.             // Add a grouped list
  187.             $html[JHtml::_(
  188.                 'select.groupedlist'$groups$this->name,
  189.                 array('id' => $this->id'group.id' => 'id''list.attr' => $attr'list.select' => $selected)
  190.             );
  191.  
  192.             return implode($html);
  193.         }
  194.         else
  195.         {
  196.  
  197.             return '';
  198.         }
  199.     }
  200. }

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