/** * Construct method * * @param JDocumentHTML $template Template object * * @throws Exception */ public function __construct(JDocumentHTML $template) { if (!$template instanceof JDocumentHTML) { return; } $this->tmpl_params = $template->params; $menu = JFactory::getApplication()->getMenu(); $activeMenu = $menu->getActive(); // Merge menu params with template params jimport('joomla.utilities.arrayhelper'); $params = array_merge($activeMenu->params->toArray(), $this->tmpl_params->toArray()); $this->params = JArrayHelper::toObject($params, 'JRegistry'); require_once JPATH_ADMINISTRATOR . '/components/com_templates/helpers/templates.php'; $positions = TemplatesHelper::getPositions(false, 'blank_j3'); // Check for positions foreach ($positions as $position) { $this->{'show_' . $position} = $template->countModules($position); } $this->show_msg = $template->countModules('message'); }
/** * Display a batch widget for the module position selector. * * @param integer $clientId The client ID. * @param integer $state The state of the module (enabled, unenabled, trashed). * @param string $selectedPosition The currently selected position for the module. * * @return string The necessary positions for the widget. * * @since 2.5 */ public static function positions($clientId, $state = 1, $selectedPosition = '') { require_once JPATH_ADMINISTRATOR . '/components/com_templates/helpers/templates.php'; $templates = array_keys(ModulesHelper::getTemplates($clientId, $state)); $templateGroups = array(); // Add an empty value to be able to deselect a module position $option = ModulesHelper::createOption(); $templateGroups[''] = ModulesHelper::createOptionGroup('', array($option)); // Add positions from templates $isTemplatePosition = false; foreach ($templates as $template) { $options = array(); $positions = TemplatesHelper::getPositions($clientId, $template); if (is_array($positions)) { foreach ($positions as $position) { $text = ModulesHelper::getTranslatedModulePosition($clientId, $template, $position) . ' [' . $position . ']'; $options[] = ModulesHelper::createOption($position, $text); if (!$isTemplatePosition && $selectedPosition === $position) { $isTemplatePosition = true; } } } $templateGroups[$template] = ModulesHelper::createOptionGroup(ucfirst($template), $options); } // Add custom position to options $customGroupText = JText::_('COM_MODULES_CUSTOM_POSITION'); $editPositions = true; $customPositions = ModulesHelper::getPositions($clientId, $editPositions); $templateGroups[$customGroupText] = ModulesHelper::createOptionGroup($customGroupText, $customPositions); return $templateGroups; }
protected function getPositions($active) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('element, name, enabled'); $query->from('#__extensions'); $query->where('client_id = 0'); $query->where('type = ' . $db->quote('template')); $query->where('enabled = 1'); $db->setQuery($query); $templates = $db->loadObjectList(); require_once JPATH_ADMINISTRATOR . '/components/com_templates/helpers/templates.php'; $options = array(); $group = array(); $group['value'] = ''; $group['text'] = ''; $group['items'] = array(); $option = new stdClass(); $option->value = ''; $option->text = JText::_('COM_SIGPRO___NONE_SELECTED__'); $group['items'][] = $option; $options[] = $group; foreach ($templates as $template) { $group = array(); $group['value'] = $template->name; $group['text'] = $template->name; $group['items'] = array(); $positions = TemplatesHelper::getPositions(0, $template->element); foreach ($positions as $position) { $option = new stdClass(); $option->value = $position; $option->text = $position; $group['items'][] = $option; } $options[] = $group; } // Build field $attributes = array('list.select' => $active, 'list.attr' => 'class="chzn-custom-value input-xlarge"'); return JHtml::_('select.groupedlist', $options, $this->name, $attributes); }
*/ defined('_JEXEC') or die; require_once JPATH_ADMINISTRATOR . '/components/com_templates/helpers/templates.php'; JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); $clientId = $this->item->client_id; $state = $this->state->get('filter.state'); $templates = array_keys(ModulesHelper::getTemplates($clientId, $state)); $templateGroups = array(); // Add an empty value to be able to deselect a module position $option = ModulesHelper::createOption(); $templateGroups[''] = ModulesHelper::createOptionGroup('', array($option)); // Add positions from templates $isTemplatePosition = false; foreach ($templates as $template) { $options = array(); $positions = TemplatesHelper::getPositions($clientId, $template); foreach ($positions as $position) { $text = ModulesHelper::getTranslatedModulePosition($clientId, $template, $position) . ' [' . $position . ']'; $options[] = ModulesHelper::createOption($position, $text); if (!$isTemplatePosition && $this->item->position === $position) { $isTemplatePosition = true; } } $templateGroups[$template] = ModulesHelper::createOptionGroup(ucfirst($template), $options); } // Add custom position to options $customGroupText = JText::_('COM_MODULES_CUSTOM_POSITION'); $editPositions = true; $customPositions = ModulesHelper::getPositions($clientId, $editPositions); $templateGroups[$customGroupText] = ModulesHelper::createOptionGroup($customGroupText, $customPositions); // Build field