/** * @param int $clientId The client id * @param string $state The state of the template */ public static function templates($clientId = 0, $state = '') { $templates = ModulesHelper::getTemplates($clientId, $state); foreach ($templates as $template) { $options[] = JHtml::_('select.option', $template->element, $template->name); } return $options; }
/** * Method to get the templates module styles. * * @return array The array of styles, grouped by templates. * * @since 3.0 */ protected function getTemplateModuleStyles() { $moduleStyles = array(); $templates = array($this->getSystemTemplate()); $templates = array_merge($templates, ModulesHelper::getTemplates('site')); foreach ($templates as $template) { $modulesFilePath = JPATH_SITE . '/templates/' . $template->element . '/html/modules.php'; // Is there modules.php for that template? if (file_exists($modulesFilePath)) { $modulesFileData = file_get_contents($modulesFilePath); preg_match_all('/function[\\s\\t]*modChrome\\_([a-z0-9\\-\\_]*)[\\s\\t]*\\(/i', $modulesFileData, $styles); if (!array_key_exists($template->element, $moduleStyles)) { $moduleStyles[$template->element] = array(); } $moduleStyles[$template->element] = $styles[1]; } } return $moduleStyles; }
/** * Method to get an array of data items. * * @return mixed An array of data items on success, false on failure. * * @since 1.6 */ public function getItems() { if (!isset($this->items)) { $lang = JFactory::getLanguage(); $search = trim($this->getState('filter.search')); $state = $this->getState('filter.state'); $clientId = $this->getState('filter.client_id'); $filter_template = $this->getState('filter.template'); $type = $this->getState('filter.type'); $ordering = $this->getState('list.ordering'); $direction = $this->getState('list.direction'); $limitstart = $this->getState('list.start'); $limit = $this->getState('list.limit'); $client = JApplicationHelper::getClientInfo($clientId); if ($type != 'template') { // Get the database object and a new query object. $query = $this->_db->getQuery(true)->select('DISTINCT(m.position) as value')->from('#__modules as m')->where('m.client_id = ' . (int) $clientId); if ($search) { $search = $this->_db->quote('%' . str_replace(' ', '%', $this->_db->escape(trim($search), true) . '%')); $query->where('m.position LIKE ' . $search); } $this->_db->setQuery($query); try { $positions = $this->_db->loadObjectList('value'); } catch (RuntimeException $e) { $this->setError($e->getMessage()); return false; } foreach ($positions as $value => $position) { $positions[$value] = array(); } } else { $positions = array(); } // Load the positions from the installed templates. foreach (ModulesHelper::getTemplates($clientId) as $template) { $path = JPath::clean($client->path . '/templates/' . $template->element . '/templateDetails.xml'); if (file_exists($path)) { $xml = simplexml_load_file($path); if (isset($xml->positions[0])) { $lang->load('tpl_' . $template->element . '.sys', $client->path, null, false, true) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, true); foreach ($xml->positions[0] as $position) { $value = (string) $position['value']; $label = (string) $position; if (!$value) { $value = $label; $label = preg_replace('/[^a-zA-Z0-9_\\-]/', '_', 'TPL_' . $template->element . '_POSITION_' . $value); $altlabel = preg_replace('/[^a-zA-Z0-9_\\-]/', '_', 'COM_MODULES_POSITION_' . $value); if (!$lang->hasKey($label) && $lang->hasKey($altlabel)) { $label = $altlabel; } } if ($type == 'user' || $state != '' && $state != $template->enabled) { unset($positions[$value]); } elseif (preg_match(chr(1) . $search . chr(1) . 'i', $value) && ($filter_template == '' || $filter_template == $template->element)) { if (!isset($positions[$value])) { $positions[$value] = array(); } $positions[$value][$template->name] = $label; } } } } } $this->total = count($positions); if ($limitstart >= $this->total) { $limitstart = $limitstart < $limit ? 0 : $limitstart - $limit; $this->setState('list.start', $limitstart); } if ($ordering == 'value') { if ($direction == 'asc') { ksort($positions); } else { krsort($positions); } } else { if ($direction == 'asc') { asort($positions); } else { arsort($positions); } } $this->items = array_slice($positions, $limitstart, $limit ? $limit : null); } return $this->items; }
/** * 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; }
<?php /** * @package Joomla.Administrator * @subpackage com_modules * * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ 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; } }