/** * Method to get the field input. * * @return string The field input. */ protected function getInput() { $attributes = ''; if ($v = (string) $this->element['onchange']) { $attributes .= ' onchange="' . $v . '"'; } if ($this->value == '_thirdparty') { $attributes .= ' class="' . (string) $this->element['class'] . ' iconlist-16-thirdparty"'; } elseif ($this->value == '_override') { $attributes .= ' class="' . (string) $this->element['class'] . ' iconlist-16-override"'; } else { $attributes .= ' class="' . (string) $this->element['class'] . '"'; } $options = array(); foreach ($this->element->children() as $option) { $options[] = JHtml::_('select.option', $option->attributes('value'), JText::_(trim($option)), array('option.attr' => 'attributes', 'attr' => '')); } $packages = LocaliseHelper::getPackages(); $packages_options = array(); foreach ($packages as $package) { $packages_options[] = JHtml::_('select.option', $package->name, JText::_($package->title), array('option.attr' => 'attributes', 'attr' => 'class="localise-icon" style="background-image: url(' . JURI::root(true) . $package->icon . ');"')); if ($this->value == $package->name) { $attributes .= ' style="background-image: url(' . JURI::root(true) . $package->icon . ');"'; } } $packages_options = JArrayHelper::sortObjects($packages_options, 'text'); $thirdparty = JHtml::_('select.option', '_thirdparty', JText::sprintf('COM_LOCALISE_OPTION_TRANSLATIONS_ORIGIN_THIRDPARTY'), array('option.attr' => 'attributes', 'attr' => 'class="iconlist-16-thirdparty"')); $override = JHtml::_('select.option', '_override', JText::sprintf('COM_LOCALISE_OPTION_TRANSLATIONS_ORIGIN_OVERRIDE'), array('option.attr' => 'attributes', 'attr' => 'class="iconlist-16-override"')); $return = JHtml::_('select.genericlist', array_merge($options, $packages_options, array($thirdparty), array($override)), $this->name, array('id' => $this->id, 'list.select' => $this->value, 'option.attr' => 'attributes', 'list.attr' => $attributes, 'group.items' => null)); return $return; }
/** * Method to get the field input. * * @return string The field input. */ protected function getInput() { $attributes = ''; if ($v = (string) $this->element['onchange']) { $attributes .= ' onchange="' . $v . '"'; } $params = JComponentHelper::getParams('com_localise'); $reference = $params->get('reference', 'en-GB'); $admin = JLanguage::getKnownLanguages(LOCALISEPATH_ADMINISTRATOR); $site = JLanguage::getKnownLanguages(LOCALISEPATH_SITE); if (JFolder::exists(LOCALISEPATH_INSTALLATION)) { $install = JLanguage::getKnownLanguages(LOCALISEPATH_INSTALLATION); } else { $install = array(); } $languages = array_merge($admin, $site, $install); $attributes .= ' class="' . (string) $this->element['class'] . ($this->value == $reference ? ' iconlist-16-reference"' : '"'); foreach ($languages as $i => $language) { $languages[$i] = JArrayHelper::toObject($language); } JArrayHelper::sortObjects($languages, 'name'); $options = array(); foreach ($this->element->children() as $option) { $options[] = JHtml::_('select.option', $option->attributes('value'), JText::_(trim($option)), array('option.attr' => 'attributes', 'attr' => '')); } foreach ($languages as $language) { $options[] = JHtml::_('select.option', $language->tag, $language->name, array('option.attr' => 'attributes', 'attr' => 'class="' . ($language->tag == $reference ? 'iconlist-16-reference" title="' . JText::_('COM_LOCALISE_TOOLTIP_FIELD_LANGUAGE_REFERENCE') . '"' : '"'))); } $return = JHtml::_('select.genericlist', $options, $this->name, array('id' => $this->id, 'list.select' => $this->value, 'option.attr' => 'attributes', 'list.attr' => $attributes)); return $return; }
public static function reasons($selected = null, $id = 'reason', $attribs = array()) { $reasons = array('other', 'adminpw', 'ipwl', 'ipbl', 'sqlishield', 'antispam', 'tpone', 'tmpl', 'template', 'muashield', 'csrfshield', 'badbehaviour', 'geoblocking', 'rfishield', 'dfishield', 'uploadshield', 'sessionshield', 'httpbl', 'loginfailure', 'securitycode', 'external', 'awayschedule', 'admindir'); $options = array(); foreach ($reasons as $reason) { $options[] = JHTML::_('select.option', $reason, JText::_('ATOOLS_LBL_REASON_' . strtoupper($reason))); } // Enable miscellaneous reasons, for use in email templates if (isset($attribs['misc'])) { $options[] = JHTML::_('select.option', 'user-reactivate', JText::_('ATOOLS_LBL_USER_REACTIVATE')); $options[] = JHTML::_('select.option', 'adminloginfail', JText::_('COM_ADMINTOOLS_EMAILTEMPLATE_REASON_ADMINLOGINFAIL')); $options[] = JHTML::_('select.option', 'adminloginsuccess', JText::_('COM_ADMINTOOLS_EMAILTEMPLATE_REASON_ADMINLOGINSUCCESS')); $options[] = JHTML::_('select.option', 'ipautoban', JText::_('COM_ADMINTOOLS_EMAILTEMPLATE_REASON_IPAUTOBAN')); unset($attribs['misc']); } // Let's sort the list alphabetically JArrayHelper::sortObjects($options, 'text'); if (isset($attribs['all'])) { array_unshift($options, JHTML::_('select.option', 'all', JText::_('ATOOLS_LBL_REASON_ALL'))); unset($attribs['all']); } if (!isset($attribs['hideEmpty'])) { array_unshift($options, JHTML::_('select.option', '', '- ' . JText::_('ATOOLS_LBL_REASON_SELECT') . ' -')); } else { unset($attribs['hideEmpty']); } return self::genericlist($options, $id, $attribs, $selected, $id); }
/** * Returns an object list * * @param string The query * @param int Offset * @param int The number of records * @return array */ protected function _getList($query, $limitstart = 0, $limit = 0) { $ordering = $this->getState('list.ordering'); $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(); $lang = JFactory::getLanguage(); $this->translate($result); if (!empty($search)) { foreach ($result as $i => $item) { if (!preg_match("/{$search}/i", $item->name)) { unset($result[$i]); } } } JArrayHelper::sortObjects($result, $this->getState('list.ordering'), $this->getState('list.direction') == 'desc' ? -1 : 1, true, $lang->getLocale()); $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 { $query->order($db->quoteName($ordering) . ' ' . $this->getState('list.direction')); $result = parent::_getList($query, $limitstart, $limit); $this->translate($result); return $result; } }
protected function _getList($query, $limitstart = 0, $limit = 0) { $ordering = $this->getState('list.ordering', 'ordering'); if (in_array($ordering, array('pages', 'name'))) { $this->_db->setQuery($query); $result = $this->_db->loadObjectList(); $this->translate($result); $lang = JFactory::getLanguage(); JArrayHelper::sortObjects($result, $ordering, $this->getState('list.direction') == 'desc' ? -1 : 1, true, $lang->getLocale()); $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('position ASC'); } $query->order($this->_db->quoteName($ordering) . ' ' . $this->getState('list.direction')); if ($ordering == 'position') { $query->order('ordering ASC'); } $result = parent::_getList($query, $limitstart, $limit); $this->translate($result); return $result; } }
/** * Method to get cache data * * @return array */ public function getData() { if (empty($this->_data)) { $cache = $this->getCache(); $data = $cache->getAll(); if ($data != false) { $this->_data = $data; $this->_total = count($data); if ($this->_total) { // Apply custom ordering $ordering = $this->getState('list.ordering'); $direction = $this->getState('list.direction') == 'asc' ? 1 : -1; jimport('joomla.utilities.arrayhelper'); $this->_data = JArrayHelper::sortObjects($data, $ordering, $direction); // Apply custom pagination if ($this->_total > $this->getState('list.limit') && $this->getState('list.limit')) { $this->_data = array_slice($this->_data, $this->getState('list.start'), $this->getState('list.limit')); } } } else { $this->_data = array(); } } return $this->_data; }
function fetchElement($name, $value, &$node, $control_name, $raw = false) { // Must load admin language files $lang =& JFactory::getLanguage(); $lang->load("com_jevents", JPATH_ADMINISTRATOR); $db =& JFactory::getDBO(); if (JVersion::isCompatible("1.6.0")) { $extension = $node->getAttribute('extension'); } else { $section = $node->attributes('section'); if (!isset($section)) { // alias for section $section = $node->attributes('scope'); if (!isset($section)) { $section = 'content'; } } } $class = $node->attributes('class'); if (!$class) { $class = "inputbox"; } $query = 'SELECT c.id, c.title as ctitle,p.title as ptitle, gp.title as gptitle, ggp.title as ggptitle, ' . ' CASE WHEN CHAR_LENGTH(p.title) THEN CONCAT_WS(" => ", p.title, c.title) ELSE c.title END as title' . ' FROM #__categories AS c' . ' LEFT JOIN #__categories AS p ON p.id=c.parent_id' . ' LEFT JOIN #__categories AS gp ON gp.id=p.parent_id ' . ' LEFT JOIN #__categories AS ggp ON ggp.id=gp.parent_id ' . ' WHERE c.published = 1 '; if (JVersion::isCompatible("1.6.0")) { $query .= ' AND c.extension = ' . $db->Quote($extension); } else { $query .= ' AND c.section = ' . $db->Quote($section); } $db->setQuery($query); $options = $db->loadObjectList(); echo $db->getErrorMsg(); foreach ($options as $key => $option) { $title = $option->ctitle; if (!is_null($option->ptitle)) { $title = $option->ptitle . "=>" . $title; } if (!is_null($option->gptitle)) { $title = $option->gptitle . "=>" . $title; } if (!is_null($option->ggptitle)) { $title = $option->ggptitle . "=>" . $title; } /* if (!is_null($option->gggptitle)){ $title = $option->gggptitle."=>".$title; } */ $options[$key]->title = $title; } JArrayHelper::sortObjects($options, "title"); if ($raw) { return $options; } else { array_unshift($options, JHTML::_('select.option', '0', '- ' . JText::_('JEV_SELECT_CATEGORY') . ' -', 'id', 'title')); return JHTML::_('select.genericlist', $options, '' . $control_name . '[' . $name . ']', 'class="' . $class . '"', 'id', 'title', $value, $control_name . $name); } }
protected function _getComponents() { $lang = JFactory::getLanguage(); // Get the list of components. $db = JFactory::getDBO(); $db->setQuery('SELECT extension_id, name, element ' . ' FROM #__extensions' . ' WHERE type = ' . $db->quote('component') . ' AND enabled = 1' . ' ORDER BY name'); $components = $db->loadObjectList(); $components = JArrayHelper::sortObjects($components, 'name', 1, true, $lang->getLocale()); return $components; }
/** * Get the table filter for the element * @param int counter * @param bol 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 */ function getFilter($counter = 0, $normal = true) { $element = $this->getElement(); $values = $this->getSubOptionValues(); $default = $this->getDefaultFilterVal($normal, $counter); $elName = $this->getFullName(false, true, false); $htmlid = $this->getHTMLId() . 'value'; $table =& $this->getlistModel()->getTable(); $params =& $this->getParams(); $v = 'fabrik___filter[list_' . $table->id . '][value]'; $v .= $normal ? '[' . $counter . ']' : '[]'; if (in_array($element->filter_type, array('range', 'dropdown', ''))) { $rows = $this->filterValueList($normal); JArrayHelper::sortObjects($rows, $params->get('filter_groupby', 'text')); if (!in_array('', $values)) { array_unshift($rows, JHTML::_('select.option', '', $this->filterSelectLabel())); } } $attribs = 'class="inputbox fabrik_filter" size="1" '; $size = $params->get('filter_length', 20); switch ($element->filter_type) { case "range": $default1 = is_array($default) ? $default[0] : ''; $return = JHTML::_('select.genericlist', $rows, $v . '[]', $attribs, 'value', 'text', $default1, $element->name . "_filter_range_0"); $default1 = is_array($default) ? $default[1] : ''; $return .= JHTML::_('select.genericlist', $rows, $v . '[]', $attribs, 'value', 'text', $default1, $element->name . "_filter_range_1"); break; case "dropdown": default: $return = JHTML::_('select.genericlist', $rows, $v, $attribs, 'value', 'text', $default, $htmlid); break; case "field": if (get_magic_quotes_gpc()) { $default = stripslashes($default); } $default = htmlspecialchars($default); $return = "<input type=\"text\" name=\"{$v}\" class=\"inputbox fabrik_filter\" size=\"{$size}\" value=\"{$default}\" id=\"{$htmlid}\" />"; break; case 'auto-complete': if (get_magic_quotes_gpc()) { $default = stripslashes($default); } $default = htmlspecialchars($default); $return = "<input type=\"hidden\" name=\"{$v}\" class=\"inputbox fabrik_filter\" value=\"{$default}\" id=\"{$htmlid}\" />"; $return .= "<input type=\"text\" name=\"{$v}-auto-complete\" class=\"inputbox fabrik_filter autocomplete-trigger\" size=\"{$size}\" value=\"{$default}\" id=\"{$htmlid}-auto-complete\" />"; FabrikHelperHTML::autoComplete($htmlid, $this->getElement()->id, $element->plugin); break; } if ($normal) { $return .= $this->getFilterHiddenFields($counter, $elName); } else { $return .= $this->getAdvancedFilterHiddenFields(); } return $return; }
protected function _getList($query, $limitstart = 0, $limit = 0) { $ordering = $this->getState('list.ordering', 'ordering'); $this->_db->setQuery($query); $result = $this->_db->loadObjectList(); JArrayHelper::sortObjects($result, $ordering, $this->getState('list.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); }
function jl_birthday_sort($array, $sort) { /** * 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 */ $res = JArrayHelper::sortObjects($array, 'age', $sort); return $res; }
public function getFilters($rows) { $filters = array(); $cats = array(); $options = array(); if ($rows) { foreach ($rows as $row) { if ($row->ostcat_id && !in_array($row->ostcat_id, $cats)) { $cats[] = $row->ostcat_id; $options[] = JHtml::_('select.option', $row->ostcat_id, $row->ostcat_name); } } } JArrayHelper::sortObjects($options, 'text'); array_unshift($options, JHtml::_('select.option', '', 'All')); $attributes = "class='inputbox' onchange='document.adminForm.submit();'"; $filters['category'] = JHtml::_('select.genericlist', $options, 'category', $attributes, 'value', 'text', $this->getState('category')); return $filters; }
/** * Method to get the field input. * * @return string The field input. */ protected function getOptions() { $admin = JLanguage::getKnownLanguages(LOCALISEPATH_ADMINISTRATOR); $site = JLanguage::getKnownLanguages(LOCALISEPATH_SITE); if (JFolder::exists(LOCALISEPATH_INSTALLATION)) { $installation = JLanguage::getKnownLanguages(LOCALISEPATH_INSTALLATION); $languages = array_intersect_key($admin, $site, $installation); } else { $languages = array_intersect_key($admin, $site); } foreach ($languages as $i => $language) { $languages[$i] = JArrayHelper::toObject($language); } JArrayHelper::sortObjects($languages, 'name'); $options = parent::getOptions(); foreach ($languages as $language) { $options[] = JHtml::_('select.option', $language->tag, $language->name); } return $options; }
/** * 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 JArrayHelper::sortObjects($items, 'text', 1, true, true); } return $items; }
function fetchElementOLD($name, $value, &$node, $control_name) { $options = array(); $menu =& JApplication::getMenu('site', $options); $items = $menu->getMenu(); $items2 = $menu->getItems("component", "com_joomleague"); JArrayHelper::sortObjects($items2, "menutype"); foreach ($items2 as &$item) { $item->title = $item->name . " (" . $item->menutype . " - " . $item->component . ")"; unset($item); } JArrayHelper::sortObjects($items, "menutype"); foreach ($items as &$item) { if ($item->component != "com_joomleague") { $item->title = $item->name . " (" . $item->menutype . " - " . $item->component . ")"; $items2[] = $item; unset($item); } } return JHTML::_('select.genericlist', $items2, '' . $control_name . '[' . $name . ']', '', 'id', 'title', $value, $control_name . $name); }
/** * Get infomation in file xml in the folder widgets (example : tile ,type, version ...) */ public function getItems() { $items = self::getFolder(); $client = JApplicationHelper::getClientInfo($this->getState('filter.client_id', 0)); $lang = JFactory::getLanguage(); foreach ($items as &$item) { $path = JPath::clean($client->path . '/administrator/components/com_bt_socialconnect/widgets/' . $item->wgtype . '/' . $item->wgtype . '.xml'); $item->type = $item->wgtype; if (file_exists($path)) { $item->xml = simplexml_load_file($path); } else { $item->xml = null; } $item->title = JText::_($item->xml->name); if (isset($item->xml) && ($text = trim($item->xml->description))) { $item->desc = JText::_($text); } else { $item->desc = JText::_('COM_MODULES_NODESCRIPTION'); } } $items = JArrayHelper::sortObjects($items, 'wgtype', 1, true, $lang->getLocale()); return $items; }
private function _getPackages() { if (!isset($this->packages)) { $search = $this->getState('filter.search'); $this->packages = array(); $path = JPATH_COMPONENT_ADMINISTRATOR . '/packages'; if (JFolder::exists($path)) { $files = JFolder::files($path, '\\.xml$'); foreach ($files as $file) { $model = JModelLegacy::getInstance('Package', 'LocaliseModel', array('ignore_request' => true)); $id = LocaliseHelper::getFileId("{$path}/{$file}"); $model->setState('package.id', $id); $package = $model->getItem(); if (empty($search) || preg_match("/{$search}/i", $package->title)) { $this->packages[] = $package; } } } $ordering = $this->getState('list.ordering') ? $this->getState('list.ordering') : 'title'; JArrayHelper::sortObjects($this->packages, $ordering, $this->getState('list.direction') == 'desc' ? -1 : 1); } return $this->packages; }
/** * Legacy function, deprecated * * @deprecated As of version 1.5 */ function MenuSelect($name = 'menuselect', $javascript = NULL) { $db =& JFactory::getDBO(); $query = 'SELECT params' . ' FROM #__modules' . ' WHERE module = "mod_mainmenu"'; $db->setQuery($query); $menus = $db->loadObjectList(); $total = count($menus); $menuselect = array(); $usedmenus = array(); for ($i = 0; $i < $total; $i++) { $registry = new JRegistry(); $registry->loadINI($menus[$i]->params); $params = $registry->toObject(); if (!in_array($params->menutype, $usedmenus)) { $menuselect[$i]->value = $params->menutype; $menuselect[$i]->text = $params->menutype; $usedmenus[] = $params->menutype; } } // sort array of objects JArrayHelper::sortObjects($menuselect, 'text', 1); $menus = JHTML::_('select.genericlist', $menuselect, $name, 'class="inputbox" size="10" ' . $javascript, 'value', 'text'); return $menus; }
/** * 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 array $expect The expected results * @param string $message The failure message * @param bool $defaults Use the defaults (true) or full argument list * * @return void * @dataProvider getTestSortObjectData */ public function testSortObjects( $input, $key, $direction, $casesensitive, $locale, $expect, $message, $defaults) { // Skip for MAC until PHP sort bug is fixed if (substr(php_uname(), 0, 6) != 'Darwin') { if ($defaults) { $output = JArrayHelper::sortObjects($input, $key); } else { $output = JArrayHelper::sortObjects($input, $key, $direction, $casesensitive, $locale); } $this->assertEquals( $expect, $output, $message ); } }
/** * Method to get the field options. * * Ordering is disabled by default. You can enable ordering by setting the * 'order' element in your form field. The other order values are optional. * * - order What to order. Possible values: 'name' or 'value' (default = false) * - order_dir Order direction. Possible values: 'asc' = Ascending or 'desc' = Descending (default = 'asc') * - order_case_sensitive Order case sensitive. Possible values: 'true' or 'false' (default = false) * * @return array The field option objects. * * @since Ordering is available since FOF 2.1.b2. */ protected function getOptions() { // Ordering is disabled by default for backward compatibility $order = false; // Set default order direction $order_dir = 'asc'; // Set default value for case sensitive sorting $order_case_sensitive = false; if ($this->element['order'] && $this->element['order'] !== 'false') { $order = $this->element['order']; } if ($this->element['order_dir']) { $order_dir = $this->element['order_dir']; } if ($this->element['order_case_sensitive']) { // Override default setting when the form element value is 'true' if ($this->element['order_case_sensitive'] == 'true') { $order_case_sensitive = true; } } // Create a $sortOptions array in order to apply sorting $i = 0; $sortOptions = array(); foreach ($this->element->children() as $option) { $name = JText::alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)); $sortOptions[$i] = new \stdClass(); $sortOptions[$i]->option = $option; $sortOptions[$i]->value = $option['value']; $sortOptions[$i]->name = $name; $i++; } // Only order if it's set if ($order) { jimport('joomla.utilities.arrayhelper'); \JArrayHelper::sortObjects($sortOptions, $order, $order_dir == 'asc' ? 1 : -1, $order_case_sensitive, false); } // Initialise the options $options = array(); // Get the field $options foreach ($sortOptions as $sortOption) { /** @var \SimpleXMLElement $option */ $option = $sortOption->option; $name = $sortOption->name; // Only add <option /> elements. if ($option->getName() != 'option') { continue; } $tmp = JHtml::_('select.option', (string) $option['value'], $name, '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; } // Do we have a class and method source for our options? $source_file = empty($this->element['source_file']) ? '' : (string) $this->element['source_file']; $source_class = empty($this->element['source_class']) ? '' : (string) $this->element['source_class']; $source_method = empty($this->element['source_method']) ? '' : (string) $this->element['source_method']; $source_key = empty($this->element['source_key']) ? '*' : (string) $this->element['source_key']; $source_value = empty($this->element['source_value']) ? '*' : (string) $this->element['source_value']; $source_translate = empty($this->element['source_translate']) ? 'true' : (string) $this->element['source_translate']; $source_translate = in_array(strtolower($source_translate), array('true', 'yes', '1', 'on')) ? true : false; $source_format = empty($this->element['source_format']) ? '' : (string) $this->element['source_format']; if ($source_class && $source_method) { // Maybe we have to load a file? if (!empty($source_file)) { $source_file = $this->form->getContainer()->template->parsePath($source_file, true); if ($this->form->getContainer()->filesystem->fileExists($source_file)) { include_once $source_file; } } // Make sure the class exists if (class_exists($source_class, true)) { // ...and so does the option if (in_array($source_method, get_class_methods($source_class))) { // Get the data from the class if ($source_format == 'optionsobject') { $options = array_merge($options, $source_class::$source_method()); } else { // Get the data from the class $source_data = $source_class::$source_method(); // Loop through the data and prime the $options array foreach ($source_data as $k => $v) { $key = empty($source_key) || $source_key == '*' ? $k : $v[$source_key]; $value = empty($source_value) || $source_value == '*' ? $v : $v[$source_value]; if ($source_translate) { $value = JText::_($value); } $options[] = JHtml::_('select.option', $key, $value, 'value', 'text'); } } } } } reset($options); return $options; }
function render(&$params) { $app = JFactory::getApplication(); // load the admin language file require_once JPATH_PLUGINS . '/system/nnframework/helpers/functions.php'; NNFrameworkFunctions::loadLanguage('plg_system_nnframework'); NNFrameworkFunctions::loadLanguage('plg_editors-xtd_modulesanywhere'); NNFrameworkFunctions::loadLanguage('plg_system_modulesanywhere'); NNFrameworkFunctions::loadLanguage('com_modules', JPATH_ADMINISTRATOR); JHtml::stylesheet('nnframework/style.min.css', false, true); // Initialize some variables $db = JFactory::getDbo(); $query = $db->getQuery(true); $option = 'modulesanywhere'; $filter_order = $app->getUserStateFromRequest($option . 'filter_order', 'filter_order', 'm.position', 'string'); $filter_order_Dir = $app->getUserStateFromRequest($option . 'filter_order_Dir', 'filter_order_Dir', '', 'string'); $filter_state = $app->getUserStateFromRequest($option . 'filter_state', 'filter_state', '', 'string'); $filter_position = $app->getUserStateFromRequest($option . 'filter_position', 'filter_position', '', 'string'); $filter_type = $app->getUserStateFromRequest($option . 'filter_type', 'filter_type', '', 'string'); $filter_search = $app->getUserStateFromRequest($option . 'filter_search', 'filter_search', '', 'string'); $filter_search = JString::strtolower($filter_search); $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'int'); $limitstart = $app->getUserStateFromRequest('modulesanywhere_limitstart', 'limitstart', 0, 'int'); $where[] = 'm.client_id = 0'; // used by filter if ($filter_position) { if ($filter_position == 'none') { $where[] = 'm.position = ""'; } else { $where[] = 'm.position = ' . $db->quote($filter_position); } } if ($filter_type) { $where[] = 'm.module = ' . $db->quote($filter_type); } if ($filter_search) { $where[] = 'LOWER( m.title ) LIKE ' . $db->quote('%' . $db->escape($filter_search, true) . '%', false); } if ($filter_state != '') { $where[] = 'm.published = ' . $filter_state; } $where = implode(' AND ', $where); if ($filter_order == 'm.ordering') { $orderby = 'm.position, m.ordering ' . $filter_order_Dir; } else { $orderby = $filter_order . ' ' . $filter_order_Dir . ', m.ordering ASC'; } // get the total number of records $query->clear()->select('COUNT(DISTINCT m.id)')->from('#__modules AS m')->join('LEFT', '#__users AS u ON u.id = m.checked_out')->join('LEFT', '#__viewlevels AS g ON g.id = m.access')->join('LEFT', '#__modules_menu AS mm ON mm.moduleid = m.id')->where($where); $db->setQuery($query); $total = $db->loadResult(); jimport('joomla.html.pagination'); $pageNav = new JPagination($total, $limitstart, $limit); $query->clear()->select('m.*, u.name AS editor, g.title AS groupname, MIN( mm.menuid ) AS pages')->from('#__modules AS m')->join('LEFT', '#__users AS u ON u.id = m.checked_out')->join('LEFT', '#__viewlevels AS g ON g.id = m.access')->join('LEFT', '#__modules_menu AS mm ON mm.moduleid = m.id')->where($where)->group('m.id')->order($orderby); $db->setQuery($query, $pageNav->limitstart, $pageNav->limit); $rows = $db->loadObjectList(); if ($db->getErrorNum()) { echo $db->stderr(); return false; } // get list of Positions for dropdown filter $query->clear()->select('m.position AS value, m.position AS text')->from('#__modules as m')->where('m.client_id = 0')->where('m.position != ""')->group('m.position')->order('m.position'); $db->setQuery($query); $positions = $db->loadObjectList(); array_unshift($positions, $options[] = JHtml::_('select.option', 'none', ':: ' . JText::_('JNONE') . ' ::')); array_unshift($positions, JHtml::_('select.option', '', JText::_('COM_MODULES_OPTION_SELECT_POSITION'))); $lists['position'] = JHtml::_('select.genericlist', $positions, 'filter_position', 'class="inputbox" size="1" onchange="this.form.submit()"', 'value', 'text', $filter_position); // get list of Types for dropdown filter $query->clear()->select('e.element AS value, e.name AS text')->from('#__extensions as e')->where('e.client_id = 0')->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('e.element, e.name'); $db->setQuery($query); $types = $db->loadObjectList(); foreach ($types as $i => $type) { $extension = $type->value; $source = JPATH_SITE . '/modules/' . $extension; NNFrameworkFunctions::loadLanguage($extension . '.sys', JPATH_SITE) || NNFrameworkFunctions::loadLanguage($extension . '.sys', $source); $types[$i]->text = JText::_($type->text); } JArrayHelper::sortObjects($types, 'text', 1, true, JFactory::getLanguage()->getLocale()); array_unshift($types, JHtml::_('select.option', '', JText::_('COM_MODULES_OPTION_SELECT_MODULE'))); $lists['type'] = JHtml::_('select.genericlist', $types, 'filter_type', 'class="inputbox" size="1" onchange="this.form.submit()"', 'value', 'text', $filter_type); // state filter $states = array(); $states[] = JHtml::_('select.option', '', JText::_('JOPTION_SELECT_PUBLISHED')); $states[] = JHtml::_('select.option', '1', JText::_('JPUBLISHED')); $states[] = JHtml::_('select.option', '0', JText::_('JUNPUBLISHED')); $states[] = JHtml::_('select.option', '-2', JText::_('JTRASHED')); $lists['state'] = JHtml::_('select.genericlist', $states, 'filter_state', 'class="inputbox" size="1" onchange="this.form.submit()"', 'value', 'text', $filter_state); // table ordering $lists['order_Dir'] = $filter_order_Dir; $lists['order'] = $filter_order; // search filter $lists['filter_search'] = $filter_search; $this->outputHTML($params, $rows, $pageNav, $lists); }
/** * Returns an object list * * @param string The query * @param int Offset * @param int 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 ($ordering == 'name' || !empty($search) && stripos($search, 'id:') !== 0) { $this->_db->setQuery($query); $result = $this->_db->loadObjectList(); $this->translate($result); if (!empty($search)) { foreach ($result as $i => $item) { if (!preg_match("/{$search}/i", $item->name)) { unset($result[$i]); } } } $direction = $this->getState('list.direction') == 'desc' ? -1 : 1; JArrayHelper::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; } }
* 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 = JArrayHelper::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);
/** * Get the child categories. * * @param integer An optional category id. If not supplied, the model state 'category.id' will be used. * * @return mixed An array of categories or false if an error occurs. * @since 1.6 */ 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') { jimport('joomla.utilities.arrayhelper'); JArrayHelper::sortObjects($this->_children, 'title', $params->get('orderby_pri') == 'alpha' ? 1 : -1); } } return $this->_children; }
/** * Get all languages (according to filters) * * @return array array of object items */ protected function getLanguages() { if (!isset($this->languages)) { $this->languages = array(); $client = $this->getState('filter.client'); $tag = $this->getState('filter.tag'); $search = $this->getState('filter.search'); if (empty($client)) { $clients = array('site', 'administrator'); if (LocaliseHelper::hasInstallation()) { $clients[] = 'installation'; } } else { $clients = array($client); } foreach ($clients as $client) { if (empty($tag)) { $folders = JFolder::folders(constant('LOCALISEPATH_' . strtoupper($client)) . '/language', '.', false, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'pdf_fonts', 'overrides')); } else { $folders = JFolder::folders(constant('LOCALISEPATH_' . strtoupper($client)) . '/language', '^' . $tag . '$', false, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'pdf_fonts', 'overrides')); } foreach ($folders as $folder) { //move to first $id = LocaliseHelper::getFileId(constant('LOCALISEPATH_' . strtoupper($client)) . "/language/{$folder}/{$folder}.xml"); //if it was not found a file. if ($id < 1) { continue; } $model = JModelLegacy::getInstance('Language', 'LocaliseModel', array('ignore_request' => true)); $model->setState('language.tag', $folder); $model->setState('language.client', $client); $model->setState('language.id', $id); $language = $model->getItem(); if (empty($search) || preg_match("/{$search}/i", $language->name)) { $this->languages[] = $language; } } } $ordering = $this->getState('list.ordering') ? $this->getState('list.ordering') : 'name'; JArrayHelper::sortObjects($this->languages, $ordering, $this->getState('list.direction') == 'desc' ? -1 : 1); } return $this->languages; }
/** * 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); $elName = $this->getFullName(true, false); $htmlid = $this->getHTMLId() . 'value'; $listModel = $this->getListModel(); $params = $this->getParams(); $class = $this->filterClass(); $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) { JArrayHelper::sortObjects($rows, $params->get('filter_groupby', 'text')); } if (!in_array('', $values) && !in_array($element->filter_type, array('checkbox', 'multiselect'))) { array_unshift($rows, JHTML::_('select.option', '', $this->filterSelectLabel())); } } $attribs = 'class="' . $class . '" size="1" '; $size = $params->get('filter_length', 20); $return = array(); switch ($element->filter_type) { case 'range': if (!is_array($default)) { $default = array('', ''); } $return[] = JHTML::_('select.genericlist', $rows, $v . '[]', $attribs, 'value', 'text', $default[0], $element->name . "_filter_range_0"); $return[] = JHTML::_('select.genericlist', $rows, $v . '[]', $attribs, 'value', 'text', $default[1], $element->name . "_filter_range_1"); break; case 'checkbox': $return[] = $this->checkboxFilter($rows, $default, $v); break; case 'dropdown': case 'multiselect': default: $size = $element->filter_type === 'multiselect' ? 'multiple="multiple" size="7"' : 'size="1"'; $attribs = 'class="' . $class . '" ' . $size; $v = $element->filter_type === 'multiselect' ? $v . '[]' : $v; $return[] = JHTML::_('select.genericlist', $rows, $v, $attribs, 'value', 'text', $default, $htmlid); break; case 'field': if (get_magic_quotes_gpc()) { $default = stripslashes($default); } $default = htmlspecialchars($default); $return[] = '<input type="text" name="' . $v . '" class="' . $class . '" size="' . $size . '" value="' . $default . '" id="' . $htmlid . '" />'; break; case 'hidden': if (get_magic_quotes_gpc()) { $default = stripslashes($default); } $default = htmlspecialchars($default); $return[] = '<input type="hidden" name="' . $v . '" class="' . $class . '" value="' . $default . '" id="' . $htmlid . '" />'; 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); }
/** * 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; } } } } $result = JArrayHelper::sortObjects($result, 'text', 1, false, true); return $result; }
/** * Get a list of the unique modules installed in the client application. * * @param int The client id. * * @return array */ public static function getModules($clientId) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('element AS value, name AS text'); $query->from('#__extensions as e'); $query->where('e.client_id = ' . (int) $clientId); $query->where('type = ' . $db->quote('module')); $query->leftJoin('#__modules as m ON m.module=e.element AND m.client_id=e.client_id'); $query->where('m.module IS NOT NULL'); $query->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, false) || $lang->load("{$extension}.sys", $source, null, false, false) || $lang->load("{$extension}.sys", $path, $lang->getDefault(), false, false) || $lang->load("{$extension}.sys", $source, $lang->getDefault(), false, false); $modules[$i]->text = JText::_($module->text); } JArrayHelper::sortObjects($modules, 'text', 1, true, $lang->getLocale()); return $modules; }
/** * 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 getTestSortObjectData * @covers JArrayHelper::sortObjects * @covers JArrayHelper::_sortObjects * @since 11.1 */ public function testSortObjects($input, $key, $direction, $casesensitive, $locale, $expect, $message, $defaults) { 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 = JArrayHelper::sortObjects($input, $key); } else { $output = JArrayHelper::sortObjects($input, $key, $direction, $casesensitive, $locale); } $this->assertEquals($expect, $output, $message); }
/** * 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) { $ordering = strtolower($this->getState('list.ordering', 'ordering')); $orderDirn = strtoupper($this->getState('list.direction', 'ASC')); if (in_array($ordering, array('pages', 'name'))) { $this->_db->setQuery($query); $result = $this->_db->loadObjectList(); $this->translate($result); JArrayHelper::sortObjects($result, $ordering, $orderDirn == '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); } if ($ordering != 'color') { if ($ordering == 'ordering') { $query->order('a.position ASC'); $ordering = 'a.ordering'; } if ($ordering == 'language_title') { $ordering = 'l.title'; } $query->order($this->_db->quoteName($ordering) . ' ' . $orderDirn); if ($ordering == 'position') { $query->order('a.ordering ASC'); } $result = parent::_getList($query, $limitstart, $limit); $this->translate($result); return $result; } $this->_db->setQuery($query); $result = $this->_db->loadObjectList(); $this->translate($result); $newresult = array(); foreach ($result as $i => $row) { $params = json_decode($row->advancedparams); if (is_null($params)) { $params = new stdClass(); } $color = isset($params->color) ? str_replace('#', '', $params->color) : 'none'; $color = empty($color) ? 'none' : $color; $newresult['_' . $color . '_' . ($i + 1) / 10000] = $row; } if ($orderDirn == 'DESC') { krsort($newresult); } else { ksort($newresult); } $newresult = array_values($newresult); $total = count($newresult); $this->cache[$this->getStoreId('getTotal')] = $total; if ($total < $limitstart) { $limitstart = 0; $this->setState('list.start', 0); } return array_slice($newresult, $limitstart, $limit ? $limit : null); }