Esempio n. 1
0
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     // Initialize variables.
     $options = array();
     // Initialize some field attributes.
     $first = (int) $this->element['first'];
     $last = (int) $this->element['last'];
     $step = (int) $this->element['step'];
     // Sanity checks.
     if ($step == 0) {
         // Step of 0 will create an endless loop.
         return $options;
     } elseif ($first < $last && $step < 0) {
         // A negative step will never reach the last number.
         return $options;
     } elseif ($first > $last && $step > 0) {
         // A position step will never reach the last number.
         return $options;
     }
     // Build the options array.
     for ($i = $first; $i <= $last; $i += $step) {
         $options[] = RokCommon_HTML_SelectList::option($i);
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Esempio n. 2
0
 /**
  * Method to get the field options for the list of installed editors.
  *
  * @return  array  The field option objects.
  * @since   11.1
  */
 protected function getOptions()
 {
     $container = RokCommon_Service::getContainer();
     $fieldname = $this->element['name'];
     $provider = (string) $this->element['provider'];
     $populator = (string) $this->element['populator'];
     $options = array();
     /** @var $provider RokSprocket_IProvider */
     $provider_class = $container[sprintf('roksprocket.providers.registered.%s.class', $provider)];
     $available = call_user_func(array($provider_class, 'isAvailable'));
     if ($available) {
         if (method_exists($provider_class, $populator)) {
             $provider_options = call_user_func(array($provider_class, $populator));
             foreach ($provider_options as $provider_option_value => $provider_option_label) {
                 //if ($this->value == $provider_option_value) $selected = ' selected="selected"'; else $selected = "";
                 $tmp = RokCommon_HTML_SelectList::option($provider_option_value, $provider_option_label);
                 // Set some option attributes.
                 $tmp->attr = array('rel' => $fieldname . '_' . $provider_option_value);
                 //$tmp->icon = 'provider ' . $provider_id;
                 $options[] = $tmp;
             }
         }
     }
     reset($options);
     return $options;
 }
Esempio n. 3
0
 /**
  * Method to get the field options for the list of installed editors.
  *
  * @return  array  The field option objects.
  * @since   11.1
  */
 protected function getOptions()
 {
     $container = RokCommon_Service::getContainer();
     $fieldname = $this->element['name'];
     $options = array();
     if (isset($this->element['configkey'])) {
         $configkey = (string) $this->element['configkey'];
         $params = $container[$configkey];
         foreach ($params as $id => $info) {
             if ($this->value == $id) {
                 $selected = ' selected="selected"';
             } else {
                 $selected = "";
             }
             $tmp = RokCommon_HTML_SelectList::option($id, $info->displayname);
             $options[] = $tmp;
         }
     }
     $options = array_merge(parent::getOptions(), $options);
     foreach ($options as &$option) {
         // Set some option attributes.
         $option->attr = array('class' => $option->value, 'rel' => $fieldname . '_' . $option->value);
     }
     reset($options);
     return $options;
 }
Esempio n. 4
0
 /**
  * Method to get the custom field options.
  * Use the query attribute to supply a query to generate the list.
  *
  * @return  array  The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     // Initialize variables.
     $options = array();
     // Initialize some field attributes.
     $key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value';
     $value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name'];
     $translate = $this->element['translate'] ? (string) $this->element['translate'] : false;
     $query = (string) $this->element['query'];
     // Get the database object.
     $db = JFactory::getDBO();
     // Set the query and get the result list.
     $db->setQuery($query);
     $items = $db->loadObjectlist();
     // Check for an error.
     if ($db->getErrorNum()) {
         JError::raiseWarning(500, $db->getErrorMsg());
         return $options;
     }
     // Build the field options.
     if (!empty($items)) {
         foreach ($items as $item) {
             if ($translate == true) {
                 $options[] = RokCommon_HTML_SelectList::option($item->{$key}, rc__($item->{$value}));
             } else {
                 $options[] = RokCommon_HTML_SelectList::option($item->{$key}, $item->{$value});
             }
         }
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
 /**
  * Method to get the field options for the list of installed editors.
  *
  * @return  array  The field option objects.
  * @since   11.1
  */
 protected function getOptions()
 {
     $container = RokCommon_Service::getContainer();
     /** @var $model RokSprocket_Model_Widgets */
     $model = $container->getService('roksprocket.widgets.model');
     $widgets = $model->getAvailableInstances();
     $fieldname = $this->element['name'];
     $options = array();
     $options[] = RokCommon_HTML_SelectList::option('', rc__('- Select RokSprocket Widget -'));
     foreach ($widgets as $info) {
         if ($this->value == $info['id']) {
             $selected = ' selected="selected"';
         } else {
             $selected = "";
         }
         $tmp = RokCommon_HTML_SelectList::option($info['id'], $info['title']);
         $options[] = $tmp;
     }
     $options = array_merge(parent::getOptions(), $options);
     foreach ($options as &$option) {
         // Set some option attributes.
         $option->attr = array('class' => $option->value, 'rel' => $fieldname . '_' . $option->value);
     }
     reset($options);
     return $options;
 }
Esempio n. 6
0
 /**
  * Method to get the field option groups.
  *
  * @return  array  The field option objects as a nested array in groups.
  *
  * @since   11.1
  */
 protected function getGroups()
 {
     // Initialize variables.
     $groups = array();
     // Initialize some field attributes.
     $menuType = (string) $this->element['menu_type'];
     $published = $this->element['published'] ? explode(',', (string) $this->element['published']) : array();
     $disable = $this->element['disable'] ? explode(',', (string) $this->element['disable']) : array();
     $language = $this->element['language'] ? explode(',', (string) $this->element['language']) : array();
     // Get the menu items.
     $items = MenusHelper::getMenuLinks($menuType, 0, 0, $published, $language);
     // Build group for a specific menu type.
     if ($menuType) {
         // Initialize the group.
         $groups[$menuType] = array();
         // Build the options array.
         foreach ($items as $link) {
             $groups[$menuType][] = RokCommon_HTML_SelectList::option($link->value, $link->text, 'value', 'text', in_array($link->type, $disable));
         }
     } else {
         // Build the groups arrays.
         foreach ($items as $menu) {
             // Initialize the group.
             $groups[$menu->menutype] = array();
             // Build the options array.
             foreach ($menu->links as $link) {
                 $groups[$menu->menutype][] = RokCommon_HTML_SelectList::option($link->value, $link->text, 'value', 'text', in_array($link->type, $disable));
             }
         }
     }
     // Merge any additional groups in the XML definition.
     $groups = array_merge(parent::getGroups(), $groups);
     return $groups;
 }
 /**
  * Method to get the field options.
  *
  * @return    array    The field option objects.
  * @since    1.6
  */
 protected function getOptions()
 {
     $options = parent::getOptions();
     $choices = array("linear", "Quad.easeOut", "Quad.easeIn", "Quad.easeInOut", "Cubic.easeOut", "Cubic.easeIn", "Cubic.easeInOut", "Quart.easeOut", "Quart.easeIn", "Quart.easeInOut", "Quint.easeOut", "Quint.easeIn", "Quint.easeInOut", "Expo.easeOut", "Expo.easeIn", "Expo.easeInOut", "Circ.easeOut", "Circ.easeIn", "Circ.easeInOut", "Sine.easeOut", "Sine.easeIn", "Sine.easeInOut", "Back.easeOut", "Back.easeIn", "Back.easeInOut", "Bounce.easeOut", "Bounce.easeIn", "Bounce.easeInOut", "Elastic.easeOut", "Elastic.easeIn", "Elastic.easeInOut");
     foreach ($choices as $choice) {
         // Create a new option object based on the <option /> element.
         $tmp = RokCommon_HTML_SelectList::option($choice, $choice, 'value', 'text', false);
         $options[] = $tmp;
     }
     return $options;
 }
Esempio n. 8
0
 /**
  * Method to get the field options.
  *
  * @return  array    The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     // Initialize variables.
     $options = array();
     // Convert to name => name array.
     foreach (JCache::getStores() as $store) {
         $options[] = RokCommon_HTML_SelectList::option($store, rc__('JLIB_FORM_VALUE_CACHE_' . $store), 'value', 'text');
     }
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Esempio n. 9
0
 /**
  * Method to get the session handler field options.
  *
  * @return  array  The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     // Initialize variables.
     $options = array();
     // Get the options from JSession.
     foreach (JSession::getStores() as $store) {
         $options[] = RokCommon_HTML_SelectList::option($store, rc__('JLIB_FORM_VALUE_SESSION_' . $store), 'value', 'text');
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Esempio n. 10
0
 protected function getOptions()
 {
     $options = array();
     foreach ($this->element->children() as $option) {
         if ($option->getName() != 'option') {
             continue;
         }
         $tmp = RokCommon_HTML_SelectList::option((string) $option['value'], rc_alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)), 'value', 'text', (string) $option['disabled'] == 'true');
         $tmp->class = (string) $option['class'];
         $options[] = $tmp;
     }
     reset($options);
     return $options;
 }
Esempio n. 11
0
 /**
  * Method to get the list of template style options
  * grouped by template.
  * Use the client attribute to specify a specific client.
  * Use the template attribute to specify a specific template
  *
  * @return  array  The field option objects as a nested array in groups.
  *
  * @since   11.1
  */
 protected function getGroups()
 {
     // Initialize variables.
     $groups = array();
     $lang = JFactory::getLanguage();
     // Get the client and client_id.
     $clientName = $this->element['client'] ? (string) $this->element['client'] : 'site';
     $client = JApplicationHelper::getClientInfo($clientName, true);
     // Get the template.
     $template = (string) $this->element['template'];
     // Get the database object and a new query object.
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     // Build the query.
     $query->select('s.id, s.title, e.name as name, s.template');
     $query->from('#__template_styles as s');
     $query->where('s.client_id = ' . (int) $client->id);
     $query->order('template');
     $query->order('title');
     if ($template) {
         $query->where('s.template = ' . $db->quote($template));
     }
     $query->join('LEFT', '#__extensions as e on e.element=s.template');
     $query->where('e.enabled=1');
     // Set the query and load the styles.
     $db->setQuery($query);
     $styles = $db->loadObjectList();
     // Build the grouped list array.
     if ($styles) {
         foreach ($styles as $style) {
             $template = $style->template;
             $lang->load('tpl_' . $template . '.sys', $client->path, null, false, false) || $lang->load('tpl_' . $template . '.sys', $client->path . '/templates/' . $template, null, false, false) || $lang->load('tpl_' . $template . '.sys', $client->path, $lang->getDefault(), false, false) || $lang->load('tpl_' . $template . '.sys', $client->path . '/templates/' . $template, $lang->getDefault(), false, false);
             $name = rc__($style->name);
             // Initialize the group if necessary.
             if (!isset($groups[$name])) {
                 $groups[$name] = array();
             }
             $groups[$name][] = RokCommon_HTML_SelectList::option($style->id, $style->title);
         }
     }
     // Merge any additional groups in the XML definition.
     $groups = array_merge(parent::getGroups(), $groups);
     return $groups;
 }
Esempio n. 12
0
 /**
  * Method to get the list of files for the field options.
  * Specify the target directory with a directory attribute
  * Attributes allow an exclude mask and stripping of extensions from file name.
  * Default attribute may optionally be set to null (no file) or -1 (use a default).
  *
  * @return  array  The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     // Initialize variables.
     $options = array();
     // Initialize some field attributes.
     $filter = (string) $this->element['filter'];
     $exclude = (string) $this->element['exclude'];
     $stripExt = (string) $this->element['stripext'];
     $hideNone = (string) $this->element['hide_none'];
     $hideDefault = (string) $this->element['hide_default'];
     // Get the path in which to search for file options.
     $path = (string) $this->element['directory'];
     if (!is_dir($path)) {
         $path = JPATH_ROOT . '/' . $path;
     }
     // Prepend some default options based on field attributes.
     if (!$hideNone) {
         $options[] = RokCommon_HTML_SelectList::option('-1', rc_alt('JOPTION_DO_NOT_USE', preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)));
     }
     if (!$hideDefault) {
         $options[] = RokCommon_HTML_SelectList::option('', rc_alt('JOPTION_USE_DEFAULT', preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)));
     }
     // Get a list of files in the search path with the given filter.
     $files = JFolder::files($path, $filter);
     // Build the options list from the list of files.
     if (is_array($files)) {
         foreach ($files as $file) {
             // Check to see if the file is in the exclude mask.
             if ($exclude) {
                 if (preg_match(chr(1) . $exclude . chr(1), $file)) {
                     continue;
                 }
             }
             // If the extension is to be stripped, do it.
             if ($stripExt) {
                 $file = JFile::stripExt($file);
             }
             $options[] = RokCommon_HTML_SelectList::option($file, $file);
         }
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Esempio n. 13
0
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     // Initialize variables.
     $options = array();
     foreach ($this->element->children() as $option) {
         // Only add <option /> elements.
         if ($option->getName() != 'option') {
             continue;
         }
         // Create a new option object based on the <option /> element.
         $tmp = RokCommon_HTML_SelectList::option((string) $option['value'], rc_alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)), 'value', 'text', (string) $option['disabled'] == 'true');
         // Set some option attributes.
         $tmp->class = (string) $option['class'];
         // Set some JavaScript option attributes.
         $tmp->onclick = (string) $option['onclick'];
         // Add the option object to the result set.
         $options[] = $tmp;
     }
     reset($options);
     return $options;
 }
Esempio n. 14
0
 /**
  * Method to get the field options for category
  * Use the extension attribute in a form to specify the.specific extension for
  * which categories should be displayed.
  * Use the show_root attribute to specify whether to show the global category root in the list.
  *
  * @return  array    The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     // Initialise variables.
     $options = array();
     $extension = $this->element['extension'] ? (string) $this->element['extension'] : (string) $this->element['scope'];
     $published = (string) $this->element['published'];
     // Load the category options for a given extension.
     if (!empty($extension)) {
         // Filter over published state or not depending upon if it is present.
         if ($published) {
             $options = JHtml::_('category.options', $extension, array('filter.published' => explode(',', $published)));
         } else {
             $options = JHtml::_('category.options', $extension);
         }
         // Verify permissions.  If the action attribute is set, then we scan the options.
         if ((string) $this->element['action']) {
             // Get the current user object.
             $user = JFactory::getUser();
             foreach ($options as $i => $option) {
                 // To take save or create in a category you need to have create rights for that category
                 // unless the item is already in that category.
                 // Unset the option if the user isn't authorised for it. In this field assets are always categories.
                 if ($user->authorise('core.create', $extension . '.category.' . $option->value) != true) {
                     unset($options[$i]);
                 }
             }
         }
         if (isset($this->element['show_root'])) {
             array_unshift($options, RokCommon_HTML_SelectList::option('0', rc__('JGLOBAL_ROOT')));
         }
     } else {
         JError::raiseWarning(500, rc__('JLIB_FORM_ERROR_FIELDS_CATEGORY_ERROR_EXTENSION_EMPTY'));
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Esempio n. 15
0
 /**
  * Method to get the field input markup fora grouped list.
  * Multiselect is enabled by using the multiple attribute.
  *
  * @return  string  The field input markup.
  *
  * @since   11.1
  */
 public function getInput()
 {
     // Initialize variables.
     $html = array();
     $attr = '';
     // Initialize some field attributes.
     $attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
     $attr .= (string) $this->element['disabled'] == 'true' ? ' disabled="disabled"' : '';
     $attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
     $attr .= $this->multiple ? ' multiple="multiple"' : '';
     // Initialize JavaScript field attributes.
     $attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
     // Get the field groups.
     $groups = (array) $this->getGroups();
     // Create a read-only list (no name) with a hidden input to store the value.
     if ((string) $this->element['readonly'] == 'true') {
         $html[] = RokCommon_HTML_SelectList::groupedlist($groups, null, array('list.attr' => $attr, 'id' => $this->id, 'list.select' => $this->value, 'group.items' => null, 'option.key.toHtml' => false, 'option.text.toHtml' => false));
         $html[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>';
     } else {
         $html[] = RokCommon_HTML_SelectList::groupedlist($groups, $this->name, array('list.attr' => $attr, 'id' => $this->id, 'list.select' => $this->value, 'group.items' => null, 'option.key.toHtml' => false, 'option.text.toHtml' => false));
     }
     return implode($html);
 }
Esempio n. 16
0
 /**
  * Method to get the field input for module layouts.
  *
  * @return  string  The field input.
  *
  * @since   11.1
  */
 public function getInput()
 {
     // Get the client id.
     $clientId = $this->element['client_id'];
     if (is_null($clientId) && $this->form instanceof RokCommon_Form) {
         $clientId = $this->form->getValue('client_id');
     }
     $clientId = (int) $clientId;
     $client = JApplicationHelper::getClientInfo($clientId);
     // Get the module.
     $module = (string) $this->element['module'];
     if (empty($module) && $this->form instanceof RokCommon_Form) {
         $module = $this->form->getValue('module');
     }
     $module = preg_replace('#\\W#', '', $module);
     // Get the template.
     $template = (string) $this->element['template'];
     $template = preg_replace('#\\W#', '', $template);
     // Get the style.
     if ($this->form instanceof RokCommon_Form) {
         $template_style_id = $this->form->getValue('template_style_id');
     }
     $template_style_id = preg_replace('#\\W#', '', $template_style_id);
     // If an extension and view are present build the options.
     if ($module && $client) {
         // Load language file
         $lang = JFactory::getLanguage();
         $lang->load($module . '.sys', $client->path, null, false, false) || $lang->load($module . '.sys', $client->path . '/modules/' . $module, null, false, false) || $lang->load($module . '.sys', $client->path, $lang->getDefault(), false, false) || $lang->load($module . '.sys', $client->path . '/modules/' . $module, $lang->getDefault(), false, false);
         // Get the database object and a new query object.
         $db = JFactory::getDBO();
         $query = $db->getQuery(true);
         // Build the query.
         $query->select('element, name');
         $query->from('#__extensions as e');
         $query->where('e.client_id = ' . (int) $clientId);
         $query->where('e.type = ' . $db->quote('template'));
         $query->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');
             $query->where('s.id=' . (int) $template_style_id);
         }
         // Set the query and load the templates.
         $db->setQuery($query);
         $templates = $db->loadObjectList('element');
         // Check for a database error.
         if ($db->getErrorNum()) {
             JError::raiseWarning(500, $db->getErrorMsg());
         }
         // Build the search paths for module layouts.
         $module_path = JPath::clean($client->path . '/modules/' . $module . '/tmpl');
         // Prepare array of component layouts
         $module_layouts = array();
         // Prepare the grouped list
         $groups = array();
         // Add the layout options from the module path.
         if (is_dir($module_path) && ($module_layouts = JFolder::files($module_path, '^[^_]*\\.php$'))) {
             // Create the group for the module
             $groups['_'] = array();
             $groups['_']['id'] = $this->id . '__';
             $groups['_']['text'] = rc__('JOPTION_FROM_MODULE');
             $groups['_']['items'] = array();
             foreach ($module_layouts as $file) {
                 // Add an option to the module group
                 $value = JFile::stripExt($file);
                 $text = $lang->hasKey($key = strtoupper($module . '_LAYOUT_' . $value)) ? rc__($key) : $value;
                 $groups['_']['items'][] = RokCommon_HTML_SelectList::option('_:' . $value, $text);
             }
         }
         // Loop on all templates
         if ($templates) {
             foreach ($templates as $template) {
                 // Load language file
                 $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/' . $module);
                 // Add the layout options from the template path.
                 if (is_dir($template_path) && ($files = JFolder::files($template_path, '^[^_]*\\.php$'))) {
                     foreach ($files as $i => $file) {
                         // Remove layout that already exist in component ones
                         if (in_array($file, $module_layouts)) {
                             unset($files[$i]);
                         }
                     }
                     if (count($files)) {
                         // Create the group for the template
                         $groups[$template->element] = array();
                         $groups[$template->element]['id'] = $this->id . '_' . $template->element;
                         $groups[$template->element]['text'] = rc__('JOPTION_FROM_TEMPLATE', $template->name);
                         $groups[$template->element]['items'] = array();
                         foreach ($files as $file) {
                             // Add an option to the template group
                             $value = JFile::stripExt($file);
                             $text = $lang->hasKey($key = strtoupper('TPL_' . $template->element . '_' . $module . '_LAYOUT_' . $value)) ? rc__($key) : $value;
                             $groups[$template->element]['items'][] = RokCommon_HTML_SelectList::option($template->element . ':' . $value, $text);
                         }
                     }
                 }
             }
         }
         // Compute attributes for the grouped list
         $attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
         // Prepare HTML code
         $html = array();
         // Compute the current selected values
         $selected = array($this->value);
         // Add a grouped list
         $html[] = RokCommon_HTML_SelectList::groupedlist($groups, $this->name, array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected));
         return implode($html);
     } else {
         return '';
     }
 }
Esempio n. 17
0
 /**
  * Method to get the field input for a component layout field.
  *
  * @return  string   The field input.
  *
  * @since   11.1
  */
 public function getInput()
 {
     // Initialize variables.
     // Get the client id.
     $clientId = $this->element['client_id'];
     if (is_null($clientId) && $this->form instanceof RokCommon_Form) {
         $clientId = $this->form->getValue('client_id');
     }
     $clientId = (int) $clientId;
     $client = JApplicationHelper::getClientInfo($clientId);
     // Get the extension.
     $extn = (string) $this->element['extension'];
     if (empty($extn) && $this->form instanceof RokCommon_Form) {
         $extn = $this->form->getValue('extension');
     }
     $extn = preg_replace('#\\W#', '', $extn);
     // Get the template.
     $template = (string) $this->element['template'];
     $template = preg_replace('#\\W#', '', $template);
     // Get the style.
     if ($this->form instanceof RokCommon_Form) {
         $template_style_id = $this->form->getValue('template_style_id');
     }
     $template_style_id = preg_replace('#\\W#', '', $template_style_id);
     // Get the view.
     $view = (string) $this->element['view'];
     $view = preg_replace('#\\W#', '', $view);
     // If a template, extension and view are present build the options.
     if ($extn && $view && $client) {
         // Load language file
         $lang = JFactory::getLanguage();
         $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);
         // Get the database object and a new query object.
         $db = JFactory::getDBO();
         $query = $db->getQuery(true);
         // Build the query.
         $query->select('e.element, e.name');
         $query->from('#__extensions as e');
         $query->where('e.client_id = ' . (int) $clientId);
         $query->where('e.type = ' . $db->quote('template'));
         $query->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');
             $query->where('s.id=' . (int) $template_style_id);
         }
         // Set the query and load the templates.
         $db->setQuery($query);
         $templates = $db->loadObjectList('element');
         // Check for a database error.
         if ($db->getErrorNum()) {
             JError::raiseWarning(500, $db->getErrorMsg());
         }
         // Build the search paths for component layouts.
         $component_path = JPath::clean($client->path . '/components/' . $extn . '/views/' . $view . '/tmpl');
         // Prepare array of component layouts
         $component_layouts = array();
         // Prepare the grouped list
         $groups = array();
         // Add a Use Global option if useglobal="true" in XML file
         if ($this->element['useglobal'] == 'true') {
             $groups[rc__('JOPTION_FROM_STANDARD')]['items'][] = RokCommon_HTML_SelectList::option('', rc__('JGLOBAL_USE_GLOBAL'));
         }
         // Add the layout options from the component path.
         if (is_dir($component_path) && ($component_layouts = JFolder::files($component_path, '^[^_]*\\.xml$', false, true))) {
             // Create the group for the component
             $groups['_'] = array();
             $groups['_']['id'] = $this->id . '__';
             $groups['_']['text'] = rc__('JOPTION_FROM_COMPONENT');
             $groups['_']['items'] = array();
             foreach ($component_layouts as $i => $file) {
                 // Attempt to load the XML file.
                 if (!($xml = simplexml_load_file($file))) {
                     unset($component_layouts[$i]);
                     continue;
                 }
                 // Get the help data from the XML file if present.
                 if (!($menu = $xml->xpath('layout[1]'))) {
                     unset($component_layouts[$i]);
                     continue;
                 }
                 $menu = $menu[0];
                 // Add an option to the component group
                 $value = JFile::stripext(JFile::getName($file));
                 $component_layouts[$i] = $value;
                 $text = isset($menu['option']) ? rc__($menu['option']) : (isset($menu['title']) ? rc__($menu['title']) : $value);
                 $groups['_']['items'][] = RokCommon_HTML_SelectList::option('_:' . $value, $text);
             }
         }
         // Loop on all templates
         if ($templates) {
             foreach ($templates as $template) {
                 // Load language file
                 $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);
                 // Add the layout options from the template path.
                 if (is_dir($template_path) && ($files = JFolder::files($template_path, '^[^_]*\\.php$', false, true))) {
                     // Files with corresponding XML files are alternate menu items, not alternate layout files
                     // so we need to exclude these files from the list.
                     $xml_files = JFolder::files($template_path, '^[^_]*\\.xml$', false, true);
                     for ($j = 0, $count = count($xml_files); $j < $count; $j++) {
                         $xml_files[$j] = JFile::stripext(JFile::getName($xml_files[$j]));
                     }
                     foreach ($files as $i => $file) {
                         // Remove layout files that exist in the component folder or that have XML files
                         if (in_array(JFile::stripext(JFile::getName($file)), $component_layouts) || in_array(JFile::stripext(JFile::getName($file)), $xml_files)) {
                             unset($files[$i]);
                         }
                     }
                     if (count($files)) {
                         // Create the group for the template
                         $groups[$template->name] = array();
                         $groups[$template->name]['id'] = $this->id . '_' . $template->element;
                         $groups[$template->name]['text'] = rc__('JOPTION_FROM_TEMPLATE', $template->name);
                         $groups[$template->name]['items'] = array();
                         foreach ($files as $file) {
                             // Add an option to the template group
                             $value = JFile::stripext(JFile::getName($file));
                             $text = $lang->hasKey($key = strtoupper('TPL_' . $template->name . '_' . $extn . '_' . $view . '_LAYOUT_' . $value)) ? rc__($key) : $value;
                             $groups[$template->name]['items'][] = RokCommon_HTML_SelectList::option($template->element . ':' . $value, $text);
                         }
                     }
                 }
             }
         }
         // Compute attributes for the grouped list
         $attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
         // Prepare HTML code
         $html = array();
         // Compute the current selected values
         $selected = array($this->value);
         // Add a grouped list
         $html[] = RokCommon_HTML_SelectList::groupedlist($groups, $this->name, array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected));
         return implode($html);
     } else {
         return '';
     }
 }