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