Method to get the field input for a component layout field.
{
$clientId = $this->element['client_id'];
if (is_null($clientId) && $this->form instanceof
JForm)
{
$clientId = $this->form->getValue('client_id');
}
$clientId = (int) $clientId;
$client = JApplicationHelper::getClientInfo($clientId);
$extn = (string) $this->element['extension'];
if (empty($extn) && ($this->form instanceof JForm))
{
$extn = $this->form->getValue('extension');
}
$extn = preg_replace('#\W#', '', $extn);
$template = (string) $this->element['template'];
$template = preg_replace('#\W#', '', $template);
if ($this->form instanceof JForm)
{
$template_style_id = $this->form->getValue('template_style_id');
}
$template_style_id = preg_replace('#\W#', '', $template_style_id);
$view = (string) $this->element['view'];
$view = preg_replace('#\W#', '', $view);
if ($extn && $view && $client)
{
$lang->load($extn . '.sys', JPATH_ADMINISTRATOR, null, false, false)
|| $lang->load($extn . '.sys', JPATH_ADMINISTRATOR . '/components/' . $extn, null, false, false)
|| $lang->load($extn . '.sys', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false)
|| $lang->load($extn . '.sys', JPATH_ADMINISTRATOR . '/components/' . $extn, $lang->getDefault(), false, false);
$query = $db->getQuery(true);
$query->select('e.element, e.name')
->from('#__extensions as e')
->where('e.client_id = ' . (int) $clientId)
->where('e.type = ' . $db->quote('template'))
->where('e.enabled = 1');
if ($template)
{
$query->where('e.element = ' . $db->quote($template));
}
if ($template_style_id)
{
$query->join('LEFT', '#__template_styles as s on s.template=e.element')
->where('s.id=' . (int) $template_style_id);
}
$db->setQuery($query);
$templates = $db->loadObjectList('element');
$component_path =
JPath::clean($client->path .
'/components/' . $extn .
'/views/' . $view .
'/tmpl');
$component_layouts = array();
$groups = array();
if ($this->element['useglobal'] == 'true')
{
$groups[
JText::_(
'JOPTION_FROM_STANDARD')][
'items'][] = JHtml::_(
'select.option',
'',
JText::_(
'JGLOBAL_USE_GLOBAL'));
}
if (is_dir($component_path) && ($component_layouts =
JFolder::files($component_path,
'^[^_]*\.xml$',
false,
true)))
{
$groups['_'] = array();
$groups['_']['id'] = $this->id . '__';
$groups['_']['items'] = array();
foreach ($component_layouts as $i => $file)
{
if (!$xml = simplexml_load_file($file))
{
unset($component_layouts[$i]);
continue;
}
if (!$menu = $xml->xpath('layout[1]'))
{
unset($component_layouts[$i]);
continue;
}
$menu = $menu[0];
$value = basename($file,
'.xml');
$component_layouts[$i] =
$value;
$text = isset($menu[
'option']) ?
JText::_($menu[
'option']) : (isset($menu[
'title']) ?
JText::_($menu[
'title']) :
$value);
$groups[
'_'][
'items'][] = JHtml::_(
'select.option',
'_:' .
$value, $text);
}
}
if ($templates)
{
foreach ($templates as $template)
{
$lang->load('tpl_' . $template->element . '.sys', $client->path, null, false, false)
|| $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, false)
|| $lang->load('tpl_' . $template->element . '.sys', $client->path, $lang->getDefault(), false, false)
|| $lang->load(
'tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, $lang->getDefault(), false, false
);
$template_path =
JPath::clean($client->path .
'/templates/' . $template->element .
'/html/' . $extn .
'/' . $view);
if (is_dir($template_path) && ($files =
JFolder::files($template_path,
'^[^_]*\.php$',
false,
true)))
{
$xml_files =
JFolder::files($template_path,
'^[^_]*\.xml$',
false,
true);
{
$xml_files[$j] = basename($xml_files[$j], '.xml');
}
foreach ($files as $i => $file)
{
if ((in_array(basename($file, '.php'), $component_layouts))
|| (in_array(basename($file, '.php'), $xml_files)))
{
unset($files[$i]);
}
}
if (count($files))
{
$groups[$template->name] = array();
$groups[$template->name]['id'] = $this->id . '_' . $template->element;
$groups[$template->name][
'text'] =
JText::sprintf(
'JOPTION_FROM_TEMPLATE', $template->name);
$groups[$template->name]['items'] = array();
foreach ($files as $file)
{
$value = basename($file,
'.php');
$text = $lang
->hasKey($key = strtoupper(
'TPL_' . $template->name .
'_' . $extn .
'_' . $view .
'_LAYOUT_' .
$value))
$groups[$template->name][
'items'][] = JHtml::_(
'select.option', $template->element .
':' .
$value, $text);
}
}
}
}
}
$attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$html = array();
$selected = array($this->value);
$html[] = JHtml::_(
'select.groupedlist', $groups, $this->name,
array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected)
);
return implode($html);
}
else
{
return '';
}
}