10 defined(
'JPATH_PLATFORM') or die;
12 jimport('joomla.filesystem.folder');
30 protected $type =
'ComponentLayout';
39 protected function getInput()
42 $clientId = $this->element[
'client_id'];
44 if (is_null($clientId) && $this->form instanceof
JForm)
46 $clientId = $this->form->getValue(
'client_id');
48 $clientId = (int) $clientId;
50 $client = JApplicationHelper::getClientInfo($clientId);
53 $extn = (string) $this->element[
'extension'];
55 if (empty($extn) && ($this->form instanceof JForm))
57 $extn = $this->form->getValue(
'extension');
60 $extn = preg_replace(
'#\W#',
'', $extn);
63 $template = (string) $this->element[
'template'];
64 $template = preg_replace(
'#\W#',
'', $template);
67 if ($this->form instanceof JForm)
69 $template_style_id = $this->form->getValue(
'template_style_id');
72 $template_style_id = preg_replace(
'#\W#',
'', $template_style_id);
75 $view = (string) $this->element[
'view'];
76 $view = preg_replace(
'#\W#',
'', $view);
79 if ($extn && $view && $client)
84 $lang->load($extn .
'.sys', JPATH_ADMINISTRATOR, null,
false,
false)
85 || $lang->load($extn .
'.sys', JPATH_ADMINISTRATOR .
'/components/' . $extn, null,
false,
false)
86 || $lang->load($extn .
'.sys', JPATH_ADMINISTRATOR, $lang->getDefault(),
false,
false)
87 || $lang->load($extn .
'.sys', JPATH_ADMINISTRATOR .
'/components/' . $extn, $lang->getDefault(),
false,
false);
91 $query = $db->getQuery(
true);
94 $query->select(
'e.element, e.name')
95 ->from(
'#__extensions as e')
96 ->where(
'e.client_id = ' . (
int) $clientId)
97 ->where(
'e.type = ' . $db->quote(
'template'))
98 ->where(
'e.enabled = 1');
102 $query->where(
'e.element = ' . $db->quote($template));
105 if ($template_style_id)
107 $query->join(
'LEFT',
'#__template_styles as s on s.template=e.element')
108 ->where(
's.id=' . (
int) $template_style_id);
112 $db->setQuery($query);
113 $templates = $db->loadObjectList(
'element');
116 $component_path =
JPath::clean($client->path .
'/components/' . $extn .
'/views/' . $view .
'/tmpl');
119 $component_layouts = array();
125 if ($this->element[
'useglobal'] ==
'true')
127 $groups[
JText::_(
'JOPTION_FROM_STANDARD')][
'items'][] = JHtml::_(
'select.option',
'',
JText::_(
'JGLOBAL_USE_GLOBAL'));
131 if (is_dir($component_path) && ($component_layouts =
JFolder::files($component_path,
'^[^_]*\.xml$',
false,
true)))
134 $groups[
'_'] = array();
135 $groups[
'_'][
'id'] = $this->
id .
'__';
137 $groups[
'_'][
'items'] = array();
139 foreach ($component_layouts as $i => $file)
142 if (!$xml = simplexml_load_file($file))
144 unset($component_layouts[$i]);
150 if (!$menu = $xml->xpath(
'layout[1]'))
152 unset($component_layouts[$i]);
160 $value = basename($file,
'.xml');
161 $component_layouts[$i] = $value;
162 $text = isset($menu[
'option']) ?
JText::_($menu[
'option']) : (isset($menu[
'title']) ?
JText::_($menu[
'title']) : $value);
163 $groups[
'_'][
'items'][] = JHtml::_(
'select.option',
'_:' . $value, $text);
170 foreach ($templates as $template)
173 $lang->load(
'tpl_' . $template->element .
'.sys', $client->path, null,
false,
false)
174 || $lang->load(
'tpl_' . $template->element .
'.sys', $client->path .
'/templates/' . $template->element, null,
false,
false)
175 || $lang->load(
'tpl_' . $template->element .
'.sys', $client->path, $lang->getDefault(),
false,
false)
177 'tpl_' . $template->element .
'.sys', $client->path .
'/templates/' . $template->element, $lang->getDefault(),
false, false
180 $template_path =
JPath::clean($client->path .
'/templates/' . $template->element .
'/html/' . $extn .
'/' . $view);
183 if (is_dir($template_path) && ($files =
JFolder::files($template_path,
'^[^_]*\.php$',
false,
true)))
187 $xml_files =
JFolder::files($template_path,
'^[^_]*\.xml$',
false,
true);
188 for ($j = 0, $count = count($xml_files); $j < $count; $j++)
190 $xml_files[$j] = basename($xml_files[$j],
'.xml');
192 foreach ($files as $i => $file)
195 if ((in_array(basename($file,
'.php'), $component_layouts))
196 || (in_array(basename($file,
'.php'), $xml_files)))
204 $groups[$template->name] = array();
205 $groups[$template->name][
'id'] = $this->
id .
'_' . $template->element;
206 $groups[$template->name][
'text'] =
JText::sprintf(
'JOPTION_FROM_TEMPLATE', $template->name);
207 $groups[$template->name][
'items'] = array();
209 foreach ($files as $file)
212 $value = basename($file,
'.php');
214 ->hasKey($key = strtoupper(
'TPL_' . $template->name .
'_' . $extn .
'_' . $view .
'_LAYOUT_' . $value))
216 $groups[$template->name][
'items'][] = JHtml::_(
'select.option', $template->element .
':' . $value, $text);
224 $attr = $this->element[
'size'] ?
' size="' . (int) $this->element[
'size'] .
'"' :
'';
230 $selected = array($this->value);
234 'select.groupedlist', $groups, $this->name,
235 array(
'id' => $this->
id,
'group.id' =>
'id',
'list.attr' => $attr,
'list.select' => $selected)
238 return implode($html);