Пример #1
0
 /**
  * Creates a list of maps.
  *
  * @return  array  An array containing the maps that can be selected.
  *
  * @since   2.5
  */
 public static function mapslist()
 {
     $lang = JFactory::getLanguage();
     // Load the finder types.
     $db = JFactory::getDbo();
     $query = $db->getQuery(true)->select($db->quoteName('title', 'text'))->select($db->quoteName('id', 'value'))->from($db->quoteName('#__finder_taxonomy'))->where($db->quoteName('parent_id') . ' = 1');
     $db->setQuery($query);
     try {
         $branches = $db->loadObjectList();
     } catch (RuntimeException $e) {
         JError::raiseWarning(500, $db->getMessage());
     }
     // Translate.
     foreach ($branches as $branch) {
         $key = FinderHelperLanguage::branchPlural($branch->text);
         $branch->translatedText = $lang->hasKey($key) ? JText::_($key) : $branch->text;
     }
     // Order by title.
     $branches = ArrayHelper::sortObjects($branches, 'translatedText', 1, true, true);
     // Compile the options.
     $options = array();
     $options[] = JHtml::_('select.option', '', JText::_('COM_FINDER_MAPS_SELECT_BRANCH'));
     // Convert the values to options.
     foreach ($branches as $branch) {
         $options[] = JHtml::_('select.option', $branch->value, $branch->translatedText);
     }
     return $options;
 }
Пример #2
0
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  *
  * @since   3.6.0
  */
 public function getOptions()
 {
     $lang = JFactory::getLanguage();
     $options = array();
     $db = JFactory::getDbo();
     $query = $db->getQuery(true)->select($db->quoteName('id', 'value'))->select($db->quoteName('title', 'text'))->from($db->quoteName('#__finder_types'));
     // Get the options.
     $db->setQuery($query);
     try {
         $contentTypes = $db->loadObjectList();
     } catch (RuntimeException $e) {
         JError::raiseWarning(500, $db->getMessage());
     }
     // Translate.
     foreach ($contentTypes as $contentType) {
         $key = FinderHelperLanguage::branchSingular($contentType->text);
         $contentType->translatedText = $lang->hasKey($key) ? JText::_($key) : $contentType->text;
     }
     // Order by title.
     $contentTypes = ArrayHelper::sortObjects($contentTypes, 'translatedText', 1, true, true);
     // Convert the values to options.
     foreach ($contentTypes as $contentType) {
         $options[] = JHtml::_('select.option', $contentType->value, $contentType->translatedText);
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Пример #3
0
 /**
  * Returns an object list
  *
  * @param   string  $query       The query
  * @param   int     $limitstart  Offset
  * @param   int     $limit       The number of records
  *
  * @return  array
  */
 protected function _getList($query, $limitstart = 0, $limit = 0)
 {
     $listOrder = $this->getState('list.ordering', 'name');
     $listDirn = $this->getState('list.direction', 'asc');
     // Replace slashes so preg_match will work
     $search = $this->getState('filter.search');
     $search = str_replace('/', ' ', $search);
     $db = $this->getDbo();
     // Define which fields have to be processed in a custom way because of translation.
     $customOrderFields = array('name', 'client_translated', 'type_translated', 'folder_translated');
     // Process searching, ordering and pagination for fields that need to be translated.
     if (in_array($listOrder, $customOrderFields) || !empty($search) && stripos($search, 'id:') !== 0) {
         // Get results from database and translate them.
         $db->setQuery($query);
         $result = $db->loadObjectList();
         $this->translate($result);
         // Process searching.
         if (!empty($search) && stripos($search, 'id:') !== 0) {
             $escapedSearchString = $this->refineSearchStringToRegex($search, '/');
             // By default search only the extension name field.
             $searchFields = array('name');
             // If in update sites view search also in the update site name field.
             if ($this instanceof InstallerModelUpdatesites) {
                 $searchFields[] = 'update_site_name';
             }
             foreach ($result as $i => $item) {
                 // Check if search string exists in any of the fields to be searched.
                 $found = 0;
                 foreach ($searchFields as $key => $field) {
                     if (!$found && preg_match('/' . $escapedSearchString . '/i', $item->{$field})) {
                         $found = 1;
                     }
                 }
                 // If search string was not found in any of the fields searched remove it from results array.
                 if (!$found) {
                     unset($result[$i]);
                 }
             }
         }
         // Process ordering.
         // Sort array object by selected ordering and selected direction. Sort is case insensative and using locale sorting.
         $result = ArrayHelper::sortObjects($result, $listOrder, strtolower($listDirn) == 'desc' ? -1 : 1, false, true);
         // Process pagination.
         $total = count($result);
         $this->cache[$this->getStoreId('getTotal')] = $total;
         if ($total < $limitstart) {
             $limitstart = 0;
             $this->setState('list.start', 0);
         }
         return array_slice($result, $limitstart, $limit ? $limit : null);
     }
     // Process searching, ordering and pagination for regular database fields.
     $query->order($db->quoteName($listOrder) . ' ' . $db->escape($listDirn));
     $result = parent::_getList($query, $limitstart, $limit);
     $this->translate($result);
     return $result;
 }
Пример #4
0
 /**
  * Get a list of the components.
  *
  * @return  array
  *
  * @since   1.6
  */
 public static function getComponents()
 {
     // Initialise variable.
     $db = JFactory::getDbo();
     $query = $db->getQuery(true)->select('name AS text, element AS value')->from('#__extensions')->where('enabled >= 1')->where('type =' . $db->quote('component'));
     $items = $db->setQuery($query)->loadObjectList();
     if (count($items)) {
         $lang = JFactory::getLanguage();
         foreach ($items as &$item) {
             // Load language
             $extension = $item->value;
             $source = JPATH_ADMINISTRATOR . '/components/' . $extension;
             $lang->load("{$extension}.sys", JPATH_ADMINISTRATOR, null, false, true) || $lang->load("{$extension}.sys", $source, null, false, true);
             // Translate component name
             $item->text = JText::_($item->text);
         }
         // Sort by component name
         $items = ArrayHelper::sortObjects($items, 'text', 1, true, true);
     }
     return $items;
 }
Пример #5
0
 /**
  * Returns an object list
  *
  * @param   string  $query       The query
  * @param   int     $limitstart  Offset
  * @param   int     $limit       The number of records
  *
  * @return  array
  */
 protected function _getList($query, $limitstart = 0, $limit = 0)
 {
     $listOrder = $this->getState('list.ordering', 'name');
     $listDirn = $this->getState('list.direction', 'asc');
     // Replace slashes so preg_match will work
     $search = $this->getState('filter.search');
     $search = str_replace('/', ' ', $search);
     $db = $this->getDbo();
     // Process ordering and pagination.
     if (in_array($listOrder, array('name', 'client_translated', 'type_translated', 'folder_translated')) || !empty($search) && stripos($search, 'id:') !== 0) {
         $db->setQuery($query);
         $result = $db->loadObjectList();
         $this->translate($result);
         // Search in the name.
         if (!empty($search)) {
             $escapedSearchString = $this->refineSearchStringToRegex($search, '/');
             foreach ($result as $i => $item) {
                 if (!preg_match("/{$escapedSearchString}/i", $item->name)) {
                     unset($result[$i]);
                 }
             }
         }
         // Sort array object by selected ordering and selected direction. Sort is case insensative and using locale sorting.
         $result = ArrayHelper::sortObjects($result, $listOrder, strtolower($listDirn) == 'desc' ? -1 : 1, false, true);
         $total = count($result);
         $this->cache[$this->getStoreId('getTotal')] = $total;
         if ($total < $limitstart) {
             $limitstart = 0;
             $this->setState('list.start', 0);
         }
         return array_slice($result, $limitstart, $limit ? $limit : null);
     }
     $query->order($db->quoteName($listOrder) . ' ' . $db->escape($listDirn));
     $result = parent::_getList($query, $limitstart, $limit);
     $this->translate($result);
     return $result;
 }
Пример #6
0
 /**
  * Method to get a list of items.
  *
  * @return  mixed  An array of objects on success, false on failure.
  */
 public function getItems()
 {
     // Get the list of items from the database.
     $items = parent::getItems();
     $client = JApplicationHelper::getClientInfo($this->getState('client_id', 0));
     $lang = JFactory::getLanguage();
     // Loop through the results to add the XML metadata,
     // and load language support.
     foreach ($items as &$item) {
         $path = JPath::clean($client->path . '/modules/' . $item->module . '/' . $item->module . '.xml');
         if (file_exists($path)) {
             $item->xml = simplexml_load_file($path);
         } else {
             $item->xml = null;
         }
         // 1.5 Format; Core files or language packs then
         // 1.6 3PD Extension Support
         $lang->load($item->module . '.sys', $client->path, null, false, true) || $lang->load($item->module . '.sys', $client->path . '/modules/' . $item->module, null, false, true);
         $item->name = JText::_($item->name);
         if (isset($item->xml) && ($text = trim($item->xml->description))) {
             $item->desc = JText::_($text);
         } else {
             $item->desc = JText::_('COM_MODULES_NODESCRIPTION');
         }
     }
     $items = ArrayHelper::sortObjects($items, 'name', 1, true, true);
     // TODO: Use the cached XML from the extensions table?
     return $items;
 }
Пример #7
0
 /**
  * Returns an object list
  *
  * @param   string  $query       The query
  * @param   int     $limitstart  Offset
  * @param   int     $limit       The number of records
  *
  * @return  array
  */
 protected function _getList($query, $limitstart = 0, $limit = 0)
 {
     $listOrder = $this->getState('list.ordering', 'a.position');
     $listDirn = $this->getState('list.direction', 'asc');
     // If ordering by fields that need translate we need to sort the array of objects after translating them.
     if (in_array($listOrder, array('pages', 'name'))) {
         // Fetch the results.
         $this->_db->setQuery($query);
         $result = $this->_db->loadObjectList();
         // Translate the results.
         $this->translate($result);
         // Sort the array of translated objects.
         $result = ArrayHelper::sortObjects($result, $listOrder, strtolower($listDirn) == 'desc' ? -1 : 1, true, true);
         // Process pagination.
         $total = count($result);
         $this->cache[$this->getStoreId('getTotal')] = $total;
         if ($total < $limitstart) {
             $limitstart = 0;
             $this->setState('list.start', 0);
         }
         return array_slice($result, $limitstart, $limit ? $limit : null);
     }
     // If ordering by fields that doesn't need translate just order the query.
     if ($listOrder === 'a.ordering') {
         $query->order($this->_db->quoteName('a.position') . ' ASC')->order($this->_db->quoteName($listOrder) . ' ' . $this->_db->escape($listDirn));
     } elseif ($listOrder === 'a.position') {
         $query->order($this->_db->quoteName($listOrder) . ' ' . $this->_db->escape($listDirn))->order($this->_db->quoteName('a.ordering') . ' ASC');
     } else {
         $query->order($this->_db->quoteName($listOrder) . ' ' . $this->_db->escape($listDirn));
     }
     // Process pagination.
     $result = parent::_getList($query, $limitstart, $limit);
     // Translate the results.
     $this->translate($result);
     return $result;
 }
Пример #8
0
 /**
  * Method to get Languages item data.
  *
  * @return  array
  *
  * @since   1.6
  */
 public function getData()
 {
     // Fetch language data if not fetched yet.
     if (is_null($this->data)) {
         $this->data = array();
         // Get information.
         $db = $this->getDbo();
         $query = $db->getQuery(true);
         // Select languages installed from the extensions table.
         $query->select($db->quoteName(array('a.element', 'a.client_id', 'a.extension_id')))->from($db->quoteName('#__extensions', 'a'))->where($db->quoteName('a.type') . ' = ' . $db->quote('language'))->where($db->quoteName('state') . ' = 0')->where($db->quoteName('enabled') . ' = 1');
         // For client_id = 1 do we need to check language table also?
         $db->setQuery($query);
         $langlist = $db->loadObjectList();
         // Compute all the languages.
         foreach ($langlist as $lang) {
             $client = JApplicationHelper::getClientInfo($lang->client_id);
             $clientPath = $lang->client_id === 0 ? JPATH_SITE : JPATH_ADMINISTRATOR;
             $info = JApplicationHelper::parseXMLLangMetaFile($clientPath . '/language/' . $lang->element . '/' . $lang->element . '.xml');
             $row = new StdClass();
             $row->language = $lang->element;
             $row->client_id = (int) $lang->client_id;
             $row->extension_id = (int) $lang->extension_id;
             if (!is_array($info)) {
                 continue;
             }
             foreach ($info as $key => $value) {
                 $row->{$key} = $value;
             }
             // Fix wrongly set parentheses in RTL languages
             if (JFactory::getLanguage()->isRtl()) {
                 $row->name = html_entity_decode($row->name . '&#x200E;', ENT_QUOTES, 'UTF-8');
             }
             // If current than set published.
             $params = JComponentHelper::getParams('com_languages');
             if ($params->get($client->name, 'en-GB') == $row->language) {
                 $row->published = 1;
             } else {
                 $row->published = 0;
             }
             $row->checked_out = 0;
             $this->data[] = $row;
         }
     }
     $installedLanguages = array_merge($this->data);
     // Process filters.
     $clientId = (int) $this->getState('client_id');
     $search = $this->getState('filter.search');
     foreach ($installedLanguages as $key => $installedLanguage) {
         // Filter by client id.
         if (in_array($clientId, array(0, 1))) {
             if ($installedLanguage->client_id !== $clientId) {
                 unset($installedLanguages[$key]);
                 continue;
             }
         }
         // Filter by search term.
         if (!empty($search)) {
             if (stripos($installedLanguage->name, $search) === false && stripos($installedLanguage->language, $search) === false) {
                 unset($installedLanguages[$key]);
                 continue;
             }
         }
     }
     // Process ordering.
     $listOrder = $this->getState('list.ordering', 'name');
     $listDirn = $this->getState('list.direction', 'ASC');
     $installedLanguages = ArrayHelper::sortObjects($installedLanguages, $listOrder, strtolower($listDirn) === 'desc' ? -1 : 1, true, true);
     // Process pagination.
     $limit = (int) $this->getState('list.limit', 25);
     // Sets the total for pagination.
     $this->total = count($installedLanguages);
     if ($limit !== 0) {
         $start = (int) $this->getState('list.start', 0);
         return array_slice($installedLanguages, $start, $limit);
     }
     return $installedLanguages;
 }
Пример #9
0
 /**
  * Method to get cache data
  *
  * @return array
  */
 public function getData()
 {
     if (empty($this->_data)) {
         $cache = $this->getCache();
         $data = $cache->getAll();
         if ($data && count($data) > 0) {
             // Process filter by search term.
             if ($search = $this->getState('filter.search')) {
                 foreach ($data as $key => $cacheItem) {
                     if (stripos($cacheItem->group, $search) === false) {
                         unset($data[$key]);
                         continue;
                     }
                 }
             }
             // Process ordering.
             $listOrder = $this->getState('list.ordering', 'group');
             $listDirn = $this->getState('list.direction', 'ASC');
             $this->_data = ArrayHelper::sortObjects($data, $listOrder, strtolower($listDirn) === 'desc' ? -1 : 1, true, true);
             // Process pagination.
             $limit = (int) $this->getState('list.limit', 25);
             if ($limit !== 0) {
                 $start = (int) $this->getState('list.start', 0);
                 return array_slice($this->_data, $start, $limit);
             }
         } else {
             $this->_data = array();
         }
     }
     return $this->_data;
 }
Пример #10
0
 /**
  * Get a list of the unique modules installed in the client application.
  *
  * @param   int  $clientId  The client id.
  *
  * @return  array  Array of unique modules
  */
 public static function getModules($clientId)
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true)->select('element AS value, name AS text')->from('#__extensions as e')->where('e.client_id = ' . (int) $clientId)->where('type = ' . $db->quote('module'))->join('LEFT', '#__modules as m ON m.module=e.element AND m.client_id=e.client_id')->where('m.module IS NOT NULL')->group('element,name');
     $db->setQuery($query);
     $modules = $db->loadObjectList();
     $lang = JFactory::getLanguage();
     foreach ($modules as $i => $module) {
         $extension = $module->value;
         $path = $clientId ? JPATH_ADMINISTRATOR : JPATH_SITE;
         $source = $path . "/modules/{$extension}";
         $lang->load("{$extension}.sys", $path, null, false, true) || $lang->load("{$extension}.sys", $source, null, false, true);
         $modules[$i]->text = JText::_($module->text);
     }
     $modules = ArrayHelper::sortObjects($modules, 'text', 1, true, true);
     return $modules;
 }
Пример #11
0
 /**
  * Utility function to sort an array of objects on a given field
  *
  * @param   array  &$a             An array of objects
  * @param   mixed  $k              The key (string) or a array of key to sort on
  * @param   mixed  $direction      Direction (integer) or an array of direction to sort in [1 = Ascending] [-1 = Descending]
  * @param   mixed  $caseSensitive  Boolean or array of booleans to let sort occur case sensitive or insensitive
  * @param   mixed  $locale         Boolean or array of booleans to let sort occur using the locale language or not
  *
  * @return  array  The sorted array of objects
  *
  * @since   11.1
  * @deprecated  4.0 Use Joomla\Utilities\ArrayHelper::sortObjects instead
  */
 public static function sortObjects(&$a, $k, $direction = 1, $caseSensitive = true, $locale = false)
 {
     if (is_array($a)) {
         $a = ArrayHelper::sortObjects($a, $k, $direction, $caseSensitive, $locale);
     } else {
         JLog::add('This method is typehinted to be an array in \\Joomla\\Utilities\\ArrayHelper::sortObjects.', JLog::WARNING, 'deprecated');
     }
     return $a;
 }
Пример #12
0
 /**
  * Returns an object list
  *
  * @param   string  $query       The query
  * @param   int     $limitstart  Offset
  * @param   int     $limit       The number of records
  *
  * @return  array
  *
  * @since   3.5
  */
 protected function _getList($query, $limitstart = 0, $limit = 0)
 {
     $db = $this->getDbo();
     $listOrder = $this->getState('list.ordering', 'u.name');
     $listDirn = $this->getState('list.direction', 'asc');
     // Process ordering.
     if (in_array($listOrder, array('client_translated', 'folder_translated', 'type_translated'))) {
         $db->setQuery($query);
         $result = $db->loadObjectList();
         $this->translate($result);
         $result = ArrayHelper::sortObjects($result, $listOrder, strtolower($listDirn) === 'desc' ? -1 : 1, true, true);
         $total = count($result);
         if ($total < $limitstart) {
             $limitstart = 0;
             $this->setState('list.start', 0);
         }
         return array_slice($result, $limitstart, $limit ? $limit : null);
     } else {
         $query->order($db->quoteName($listOrder) . ' ' . $db->escape($listDirn));
         $result = parent::_getList($query, $limitstart, $limit);
         $this->translate($result);
         return $result;
     }
 }
Пример #13
0
 /**
  * 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 = '')
 {
     JLoader::register('TemplatesHelper', 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;
                 }
             }
             $options = ArrayHelper::sortObjects($options, 'text');
         }
         $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;
 }
Пример #14
0
 /**
  * Returns an object list
  *
  * @param   string  $query       The query
  * @param   int     $limitstart  Offset
  * @param   int     $limit       The number of records
  *
  * @return  array
  *
  * @since   3.4
  */
 protected function _getList($query, $limitstart = 0, $limit = 0)
 {
     $ordering = $this->getState('list.ordering', 'name');
     $direction = $this->getState('list.direction', 'asc');
     $search = $this->getState('filter.search');
     // Replace slashes so preg_match will work
     $search = str_replace('/', ' ', $search);
     $db = $this->getDbo();
     if ($ordering == 'name' || !empty($search) && stripos($search, 'id:') !== 0) {
         $db->setQuery($query);
         $result = $db->loadObjectList();
         $this->translate($result);
         if (!empty($search) && stripos($search, 'id:') !== 0) {
             foreach ($result as $i => $item) {
                 if (!preg_match("/{$search}/i", $item->name) && !preg_match("/{$search}/i", $item->update_site_name)) {
                     unset($result[$i]);
                 }
             }
         }
         $result = ArrayHelper::sortObjects($result, $ordering, strtolower($direction) === 'desc' ? -1 : 1, true, true);
         $total = count($result);
         $this->cache[$this->getStoreId('getTotal')] = $total;
         if ($total < $limitstart) {
             $limitstart = 0;
             $this->setState('list.start', 0);
         }
         return array_slice($result, $limitstart, $limit ? $limit : null);
     }
     $query->order($db->quoteName($ordering) . ' ' . $direction);
     $result = parent::_getList($query, $limitstart, $limit);
     $this->translate($result);
     return $result;
 }
Пример #15
0
 /**
  * Get a list of the authorised, non-special components to display in the components menu.
  *
  * @param   boolean  $authCheck	  An optional switch to turn off the auth check (to support custom layouts 'grey out' behaviour).
  *
  * @return  array  A nest array of component objects and submenus
  *
  * @since   1.6
  */
 public static function getComponents($authCheck = true)
 {
     $lang = JFactory::getLanguage();
     $user = JFactory::getUser();
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $result = array();
     // Prepare the query.
     $query->select('m.id, m.title, m.alias, m.link, m.parent_id, m.img, e.element')->from('#__menu AS m');
     // Filter on the enabled states.
     $query->join('LEFT', '#__extensions AS e ON m.component_id = e.extension_id')->where('m.client_id = 1')->where('e.enabled = 1')->where('m.id > 1');
     // Order by lft.
     $query->order('m.lft');
     $db->setQuery($query);
     // Component list
     try {
         $components = $db->loadObjectList();
     } catch (RuntimeException $e) {
         $components = array();
         JFactory::getApplication()->enqueueMessage(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
     }
     // Parse the list of extensions.
     foreach ($components as &$component) {
         // Trim the menu link.
         $component->link = trim($component->link);
         if ($component->parent_id == 1) {
             // Only add this top level if it is authorised and enabled.
             if ($authCheck == false || $authCheck && $user->authorise('core.manage', $component->element)) {
                 // Root level.
                 $result[$component->id] = $component;
                 if (!isset($result[$component->id]->submenu)) {
                     $result[$component->id]->submenu = array();
                 }
                 // If the root menu link is empty, add it in.
                 if (empty($component->link)) {
                     $component->link = 'index.php?option=' . $component->element;
                 }
                 if (!empty($component->element)) {
                     // Load the core file then
                     // Load extension-local file.
                     $lang->load($component->element . '.sys', JPATH_BASE, null, false, true) || $lang->load($component->element . '.sys', JPATH_ADMINISTRATOR . '/components/' . $component->element, null, false, true);
                 }
                 $component->text = $lang->hasKey($component->title) ? JText::_($component->title) : $component->alias;
             }
         } else {
             // Sub-menu level.
             if (isset($result[$component->parent_id])) {
                 // Add the submenu link if it is defined.
                 if (isset($result[$component->parent_id]->submenu) && !empty($component->link)) {
                     $component->text = $lang->hasKey($component->title) ? JText::_($component->title) : $component->alias;
                     $result[$component->parent_id]->submenu[] =& $component;
                 }
             }
         }
     }
     return ArrayHelper::sortObjects($result, 'text', 1, false, true);
 }
Пример #16
0
 /**
  * Get the table filter for the element
  *
  * @param   int   $counter  Filter order
  * @param   bool  $normal   Do we render as a normal filter or as an advanced search filter
  * if normal include the hidden fields as well (default true, use false for advanced filter rendering)
  *
  * @return  string	Filter HTML
  */
 public function getFilter($counter = 0, $normal = true)
 {
     $element = $this->getElement();
     $values = $this->getSubOptionValues();
     $default = $this->getDefaultFilterVal($normal, $counter);
     $this->filterDisplayValues = array($default);
     $elName = $this->getFullName(true, false);
     $params = $this->getParams();
     $v = $this->filterName($counter, $normal);
     if (in_array($element->filter_type, array('range', 'dropdown', '', 'checkbox', 'multiselect'))) {
         $rows = $this->filterValueList($normal);
         if ($params->get('filter_groupby') != -1) {
             ArrayHelper::sortObjects($rows, $params->get('filter_groupby', 'text'));
         }
         $this->getFilterDisplayValues($default, $rows);
         if (!in_array('', $values) && !in_array($element->filter_type, array('checkbox', 'multiselect'))) {
             array_unshift($rows, JHTML::_('select.option', '', $this->filterSelectLabel()));
         }
     }
     $return = array();
     switch ($element->filter_type) {
         case 'range':
             if (!is_array($default)) {
                 $default = array('', '');
             }
             $this->rangedFilterFields($default, $return, $rows, $v, 'list');
             break;
         case 'checkbox':
             $return[] = $this->checkboxFilter($rows, $default, $v);
             break;
         case 'dropdown':
         case 'multiselect':
         default:
             $return[] = $this->selectFilter($rows, $default, $v);
             break;
         case 'field':
             $return[] = $this->singleFilter($default, $v);
             break;
         case 'hidden':
             $return[] = $this->singleFilter($default, $v, 'hidden');
             break;
         case 'auto-complete':
             $defaultLabel = $this->getLabelForValue($default);
             $autoComplete = $this->autoCompleteFilter($default, $v, $defaultLabel, $normal);
             $return = array_merge($return, $autoComplete);
             break;
     }
     $return[] = $normal ? $this->getFilterHiddenFields($counter, $elName, false, $normal) : $this->getAdvancedFilterHiddenFields();
     return implode("\n", $return);
 }
 * Menus Submenu
 */
if ($user->authorise('core.manage', 'com_menus')) {
    $menu->addChild(new JMenuNode(JText::_('MOD_MENU_MENUS'), '#'), true);
    $createMenu = $shownew && $user->authorise('core.create', 'com_menus');
    $menu->addChild(new JMenuNode(JText::_('MOD_MENU_MENU_MANAGER'), 'index.php?option=com_menus&view=menus', 'class:menumgr'), $createMenu);
    if ($createMenu) {
        $menu->addChild(new JMenuNode(JText::_('MOD_MENU_MENU_MANAGER_NEW_MENU'), 'index.php?option=com_menus&view=menu&layout=edit', 'class:newarticle'));
        $menu->getParent();
    }
    $menu->addSeparator();
    $menu->addChild(new JMenuNode(JText::_('MOD_MENU_MENUS_ALL_ITEMS'), 'index.php?option=com_menus&view=items&menutype=', 'class:allmenu'));
    $menu->addSeparator();
    // Menu Types
    $menuTypes = ModMenuHelper::getMenus();
    $menuTypes = ArrayHelper::sortObjects($menuTypes, 'title', 1, false);
    foreach ($menuTypes as $menuType) {
        if (!$user->authorise('core.manage', 'com_menus.menu.' . (int) $menuType->id)) {
            continue;
        }
        $alt = '*' . $menuType->sef . '*';
        if ($menuType->home == 0) {
            $titleicon = '';
        } elseif ($menuType->home == 1 && $menuType->language == '*') {
            $titleicon = ' <span class="icon-home"></span>';
        } elseif ($menuType->home > 1) {
            $titleicon = ' <span>' . JHtml::_('image', 'mod_languages/icon-16-language.png', $menuType->home, array('title' => JText::_('MOD_MENU_HOME_MULTIPLE')), true) . '</span>';
        } else {
            $image = JHtml::_('image', 'mod_languages/' . $menuType->image . '.gif', null, null, true, true);
            if (!$image) {
                $image = JHtml::_('image', 'mod_languages/icon-16-language.png', $alt, array('title' => $menuType->title_native), true);
Пример #18
0
 /**
  * Test sorting an array of objects.
  *
  * @param   array    $input          Input array of objects
  * @param   mixed    $key            Key to sort on
  * @param   mixed    $direction      Ascending (1) or Descending(-1)
  * @param   string   $casesensitive  @todo
  * @param   string   $locale         @todo
  * @param   array    $expect         The expected results
  * @param   string   $message        The failure message
  * @param   boolean  $defaults       Use the defaults (true) or full argument list
  *
  * @return  void
  *
  * @dataProvider  seedTestSortObject
  * @covers        Joomla\Utilities\ArrayHelper::sortObjects
  * @since         1.0
  */
 public function testSortObjects($input, $key, $direction, $casesensitive, $locale, $expect, $message, $defaults, $swappable_keys = array())
 {
     // Convert the $locale param to a string if it is an array
     if (is_array($locale)) {
         $locale = "'" . implode("', '", $locale) . "'";
     }
     if (empty($input)) {
         $this->markTestSkipped('Skip for MAC until PHP sort bug is fixed');
         return;
     } elseif ($locale != false && !setlocale(LC_COLLATE, $locale)) {
         // If the locale is not available, we can't have to transcode the string and can't reliably compare it.
         $this->markTestSkipped("Locale {$locale} is not available.");
         return;
     }
     if ($defaults) {
         $output = ArrayHelper::sortObjects($input, $key);
     } else {
         $output = ArrayHelper::sortObjects($input, $key, $direction, $casesensitive, $locale);
     }
     // The ordering of elements that compare equal according to
     // $key is undefined (implementation dependent).
     if ($expect != $output && $swappable_keys) {
         list($k1, $k2) = $swappable_keys;
         $e1 = $output[$k1];
         $e2 = $output[$k2];
         $output[$k1] = $e2;
         $output[$k2] = $e1;
     }
     $this->assertEquals($expect, $output, $message);
 }
Пример #19
0
 /**
  * Returns an object list.
  *
  * @param   JDatabaseQuery  $query       A database query object.
  * @param   integer         $limitstart  Offset.
  * @param   integer         $limit       The number of records.
  *
  * @return  array
  */
 protected function _getList($query, $limitstart = 0, $limit = 0)
 {
     $search = $this->getState('filter.search');
     $ordering = $this->getState('list.ordering', 'ordering');
     // If "Sort Table By:" is not set, set ordering to name
     if ($ordering == '') {
         $ordering = "name";
     }
     if ($ordering == 'name' || !empty($search) && stripos($search, 'id:') !== 0) {
         $this->_db->setQuery($query);
         $result = $this->_db->loadObjectList();
         $this->translate($result);
         if (!empty($search)) {
             $escapedSearchString = $this->refineSearchStringToRegex($search, '/');
             foreach ($result as $i => $item) {
                 if (!preg_match("/{$escapedSearchString}/i", $item->name)) {
                     unset($result[$i]);
                 }
             }
         }
         $orderingDirection = strtolower($this->getState('list.direction'));
         $direction = $orderingDirection == 'desc' ? -1 : 1;
         $result = ArrayHelper::sortObjects($result, $ordering, $direction, true, true);
         $total = count($result);
         $this->cache[$this->getStoreId('getTotal')] = $total;
         if ($total < $limitstart) {
             $limitstart = 0;
             $this->setState('list.start', 0);
         }
         return array_slice($result, $limitstart, $limit ? $limit : null);
     } else {
         if ($ordering == 'ordering') {
             $query->order('a.folder ASC');
             $ordering = 'a.ordering';
         }
         $query->order($this->_db->quoteName($ordering) . ' ' . $this->getState('list.direction'));
         if ($ordering == 'folder') {
             $query->order('a.ordering ASC');
         }
         $result = parent::_getList($query, $limitstart, $limit);
         $this->translate($result);
         return $result;
     }
 }
Пример #20
0
 /**
  * Get the child categories.
  *
  * @return  mixed  An array of categories or false if an error occurs.
  *
  * @since   1.6
  */
 public function &getChildren()
 {
     if (!is_object($this->_item)) {
         $this->getCategory();
     }
     // Order subcategories
     if (count($this->_children)) {
         $params = $this->getState()->get('params');
         if ($params->get('orderby_pri') == 'alpha' || $params->get('orderby_pri') == 'ralpha') {
             $this->_children = ArrayHelper::sortObjects($this->_children, 'title', $params->get('orderby_pri') == 'alpha' ? 1 : -1);
         }
     }
     return $this->_children;
 }