/** * Method to get the field input. * * @return string The field input. */ protected function _getGroups() { $client = $this->_element->attributes('client'); $client_id = $client == 'administrator' ? 1 : 0; $db = JFactory::getDBO(); $query = new JQuery(); $query->select($db->nameQuote('id')); $query->select($db->nameQuote('title')); $query->select($db->nameQuote('template')); $query->from($db->nameQuote('#__template_styles')); $query->where($db->nameQuote('client_id') . '=' . (int) $client_id); $query->order($db->nameQuote('template')); $query->order($db->nameQuote('title')); $db->setQuery($query); $styles = $db->loadObjectList(); // Pre-process into groups. $last = null; $groups = array(); foreach ($styles as $style) { if ($style->template != $last) { $last = $style->template; $groups[$last] = array(); } $groups[$last][] = JHtml::_('select.option', $style->id, $style->title); } // Merge any additional options in the XML definition. $groups = array_merge(parent::_getGroups(), $groups); return $groups; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->from('`#__viewlevels` AS a'); // Add the level in the tree. $query->group('a.id'); // Filter the items over the search string if set. $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.title LIKE ' . $search); } } $query->group('a.id'); // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.lft')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Method to get a list of options for a list input. * * @return array An array of JHtml options. */ protected function _getOptions() { $db =& JFactory::getDbo(); $query = new JQuery(); $query->select('a.id AS value, a.title AS text, a.level'); $query->from('#__categories AS a'); $query->join('LEFT', '`#__categories` AS b ON a.lft > b.lft AND a.rgt < b.rgt'); // Filter by the type if ($extension = $this->_form->getValue('extension')) { $query->where('(a.extension = ' . $db->quote($extension) . ' OR a.parent_id = 0)'); } // Prevent parenting to children of this item. if ($id = $this->_form->getValue('id')) { $query->join('LEFT', '`#__categories` AS p ON p.id = ' . (int) $id); $query->where('NOT(a.lft >= p.lft AND a.rgt <= p.rgt)'); } $query->group('a.id'); $query->order('a.lft ASC'); // Get the options. $db->setQuery($query); $options = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseWarning(500, $db->getErrorMsg()); } // Pad the option text with spaces using depth level as a multiplier. for ($i = 0, $n = count($options); $i < $n; $i++) { $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text; } $options = array_merge(parent::_getOptions(), $options); return $options; }
/** * @param boolean True to join selected foreign information * * @return string */ function _getListQuery($resolveFKs = true) { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid, a.state, a.access, a.created, a.hits')); $query->from('#__content AS a'); // Join over the content table. $query->select('fp.ordering'); $query->join('INNER', '#__content_frontpage AS fp ON fp.content_id = a.id'); // Join over the users for the checked out user. $query->select('uc.name AS editor'); $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); // Join over the asset groups. $query->select('ag.title AS access_level'); $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); // Join over the categories. $query->select('c.title AS category_title'); $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); // Join over the users for the author. $query->select('ua.name AS author_name'); $query->join('LEFT', '#__users AS ua ON ua.id = a.created_by'); // Filter by access level. if ($access = $this->getState('filter.access')) { $query->where('a.access = ' . (int) $access); } // Filter by published state $published = $this->getState('filter.published'); if (is_numeric($published)) { $query->where('a.state = ' . (int) $published); } else { if ($published === '') { $query->where('(a.state = 0 OR a.state = 1)'); } } // Filter by search in title $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.title LIKE ' . $search . ' OR a.alias LIKE ' . $search); } } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.title')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query->toString())); return $query; }
function getUsers($params) { $db =& JFactory::getDbo(); $result = null; $query = new JQuery(); $query->select('a.id, a.name, a.username, a.activation'); $query->order('a.activation DESC'); $query->from('#__users AS a'); $db->setQuery($query, 0, $params->get('shownumber')); $result = $db->loadObjectList(); if ($db->getErrorNum()) { JError::raiseWarning(500, $db->stderr()); } return $result; }
/** * Get a list of the thread contexts * * @return mixed An array if successful, false otherwise and the internal error is set. */ function getContextOptions() { $db = JFactory::getDbo(); $query = new JQuery(); $query->select('DISTINCT(context) AS value, context AS text'); $query->from('#__social_threads'); $query->order('context'); $db->setQuery($query); $result = $db->loadObjectList(); if ($error = $db->getErrorMsg()) { $this->setError($error); return false; } return $result; }
/** * Returns an array of standard published state filter options. * * @return string The HTML code for the select tag */ public static function folderOptions() { jimport('joomla.database.query'); $db = JFactory::getDbo(); $query = new JQuery(); $query->select('DISTINCT(folder) AS value, folder AS text'); $query->from('#__extensions'); $query->where('`type` = ' . $db->quote('plugin')); $query->order('name'); $db->setQuery($query); $options = $db->loadObjectList(); if ($error = $db->getErrorMsg()) { JError::raiseWarning(500, $error); } return $options; }
/** * Method to get a list of options for a list input. * * @return array An array of JHtml options. */ protected function _getOptions() { $db = JFactory::getDbo(); $query = new JQuery(); $query->select('id As value, name As text'); $query->from('#__newsfeeds AS a'); $query->order('a.name'); // Get the options. $db->setQuery($query); $options = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseWarning(500, $db->getErrorMsg()); } $options = array_merge(parent::_getOptions(), $options); return $options; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.extension_id, a.name, a.element AS module')); $query->from('`#__extensions` AS a'); // Filter by module $query->where('a.type = ' . $this->_db->Quote('module')); // Filter by client. $clientId = $this->getState('filter.client_id'); $query->where('a.client_id = ' . (int) $clientId); // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.ordering')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Loads the entire menu table into memory. * * @return array */ public function load() { $cache =& JFactory::getCache('_system', 'output'); if (!($data = $cache->get('menu_items'))) { jimport('joomla.database.query'); // Initialise some variables. $db =& JFactory::getDbo(); $query = new JQuery(); $query->select('m.id, m.menutype, m.title, m.alias, m.path AS route, m.link, m.type, m.level'); $query->select('m.browserNav, m.access, m.params, m.home, m.img, m.template_style_id, m.component_id, m.parent_id'); $query->select('e.element as component'); $query->from('#__menu AS m'); $query->leftJoin('#__extensions AS e ON m.component_id = e.extension_id'); $query->where('m.published = 1'); $query->where('m.parent_id > 0'); $query->order('m.lft'); $db->setQuery($query); if (!($menus = $db->loadObjectList('id'))) { JError::raiseWarning(500, "Error loading Menus: " . $db->getErrorMsg()); return false; } foreach ($menus as &$menu) { // Get parent information. $parent_tree = array(); if (($parent = $menu->parent_id) && isset($menus[$parent]) && is_object($menus[$parent]) && isset($menus[$parent]->route) && isset($menus[$parent]->tree)) { $parent_tree = $menus[$parent]->tree; } // Create tree. array_push($parent_tree, $menu->id); $menu->tree = $parent_tree; // Create the query array. $url = str_replace('index.php?', '', $menu->link); if (strpos($url, '&') !== false) { $url = str_replace('&', '&', $url); } parse_str($url, $menu->query); } $cache->store(serialize($menus), 'menu_items'); $this->_items = $menus; } else { $this->_items = unserialize($data); } }
/** * Get the options for the element * * @param object $node * @return array */ protected function _getOptions(&$node) { $db =& JFactory::getDbo(); $query = new JQuery(); $query->select('a.lang_code AS value, a.title AS text, a.title_native'); $query->from('#__languages AS a'); $query->where('a.published >= 0'); $query->order('a.title'); // Get the options. $db->setQuery($query); $options = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseWarning(500, $db->getErrorMsg()); } // Merge any additional options in the XML definition. $options = array_merge(parent::_getOptions($node), $options); return $options; }
/** * Get a list of the most popular articles * * @param JObject The module parameters. * * @return array */ public static function getList($params) { jimport('joomla.database.query'); $db = JFactory::getDbo(); $limit = $params->get('limit', 10); $result = null; $query = new JQuery(); $query->select('a.hits, a.id, a.sectionid, a.title, a.created, u.name'); $query->from('#__content AS a'); $query->join('LEFT', '#__users AS u ON u.id=a.created_by'); $query->where('a.state <> -2'); $query->order('hits'); $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); if ($error = $db->getErrorMsg()) { JError::raiseWarning(500, $error); return false; } return $rows; }
/** * Returns an array of menu items groups by menu. * * @param array An array of configuration options. * * @return array */ public static function menuitems($config = array()) { if (empty(self::$items)) { $db =& JFactory::getDbo(); $db->setQuery('SELECT menutype As value, title As text' . ' FROM #__menu_types' . ' ORDER BY title'); $menus = $db->loadObjectList(); $query = new JQuery(); $query->select('a.id AS value, a.title As text, a.level, a.menutype'); $query->from('#__menu AS a'); $query->where('a.parent_id > 0'); $query->where('a.type <> ' . $db->quote('url')); // Filter on the published state if (isset($config['published'])) { $query->where('a.published = ' . (int) $config['published']); } $query->order('a.lft'); $db->setQuery($query); $items = $db->loadObjectList(); // Collate menu items based on menutype $lookup = array(); foreach ($items as &$item) { if (!isset($lookup[$item->menutype])) { $lookup[$item->menutype] = array(); } $lookup[$item->menutype][] =& $item; $item->text = str_repeat('- ', $item->level) . $item->text; } self::$items = array(); foreach ($menus as &$menu) { self::$items[] = JHtml::_('select.optgroup', $menu->text); self::$items[] = JHtml::_('select.option', $menu->value . '.0', JText::_('Menus_Add_to_this_menu')); if (isset($lookup[$menu->value])) { foreach ($lookup[$menu->value] as &$item) { self::$items[] = JHtml::_('select.option', $menu->value . '.' . $item->value, $item->text); } } } } return self::$items; }
/** * Method to build an SQL query to load the list data. * * @return string An SQL query */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select all fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->from('`#__menu_types` AS a'); // Self join to find the number of published menu items in the menu. $query->select('COUNT(DISTINCT m1.id) AS count_published'); $query->join('LEFT', '`#__menu` AS m1 ON m1.menutype = a.menutype AND m1.published = 1'); // Self join to find the number of unpublished menu items in the menu. $query->select('COUNT(DISTINCT m2.id) AS count_unpublished'); $query->join('LEFT', '`#__menu` AS m2 ON m2.menutype = a.menutype AND m2.published = 0'); // Self join to find the number of trashed menu items in the menu. $query->select('COUNT(DISTINCT m3.id) AS count_trashed'); $query->join('LEFT', '`#__menu` AS m3 ON m3.menutype = a.menutype AND m3.published = -2'); $query->group('a.id'); // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.id')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query->toString())).'<hr/>'; return $query; }
/** * Returns an array of categories for the given extension. * * @param string The extension option. * @param array An array of configuration options. By default, only published and unpulbished categories are returned. * * @return array */ public static function options($extension, $config = array('filter.published' => array(0, 1))) { $hash = md5($extension . '.' . serialize($config)); if (!isset(self::$items[$hash])) { $config = (array) $config; $db =& JFactory::getDbo(); jimport('joomla.database.query'); $query = new JQuery(); $query->select('a.id, a.title, a.level'); $query->from('#__categories AS a'); $query->where('a.parent_id > 0'); // Filter on extension. $query->where('extension = ' . $db->quote($extension)); // Filter on the published state if (isset($config['filter.published'])) { if (is_numeric($config['filter.published'])) { $query->where('a.published = ' . (int) $config['filter.published']); } else { if (is_array($config['filter.published'])) { JArrayHelper::toInteger($config['filter.published']); $query->where('a.published IN (' . implode(',', $config['filter.published']) . ')'); } } } $query->order('a.lft'); $db->setQuery($query); $items = $db->loadObjectList(); // Assemble the list options. self::$items[$hash] = array(); foreach ($items as &$item) { $item->title = str_repeat('- ', $item->level - 1) . $item->title; self::$items[$hash][] = JHtml::_('select.option', $item->id, $item->title); } } return self::$items[$hash]; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->from('`#__redirect_links` AS a'); // Filter by published state $state = $this->getState('filter.state'); if (is_numeric($state)) { $query->where('a.published = ' . (int) $state); } else { if ($state === '') { $query->where('(a.published IN (0,1,2))'); } } // Filter the items over the search string if set. $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('(`old_url` LIKE ' . $search . ' OR `new_url` LIKE ' . $search . ' OR `comment` LIKE ' . $search . ' OR `referer` LIKE ' . $search . ')'); } } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.old_url')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * @param boolean True to join selected foreign information * * @return string */ function _getListQuery($resolveFKs = true) { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.id, a.title, a.alias, a.access, a.published' . ', a.path AS route, a.parent_id, a.level, a.lft, a.rgt' . ', a.description')); $query->from('#__categories AS a'); // Filter by access level. if ($access = $this->getState('filter.access')) { $user =& JFactory::getUser(); $groups = implode(',', $user->authorisedLevels()); $query->where('a.access IN (' . $groups . ')'); } // Filter by published state. $published = $this->getState('filter.published'); if (is_numeric($published)) { $query->where('a.published = ' . (int) $published); } else { if (is_array($published)) { JArrayHelper::toInteger($published); $published = implode(',', $published); $query->where('a.published IN (' . $published . ')'); } } // Filter by extension. $query->where('a.extension = ' . $this->_db->quote($this->_extension)); // Retrieve a sub tree or lineage. if ($parentId = $this->getState('filter.parent_id')) { if ($levels = $this->getState('filter.get_children')) { // Optionally get all the child categories for given parent. $query->leftJoin('#__categories AS p ON p.id = ' . (int) $parentId); $query->where('a.lft > p.lft AND a.rgt < p.rgt'); if ((int) $levels > 0) { // Only go to a certain depth. $query->where('a.level <= p.level + ' . (int) $levels); } } else { if ($this->getState('filter.get_parents')) { // Optionally get all the parents to the category. $query->leftJoin('#__categories AS p ON p.id = ' . (int) $parentId); $query->where('a.lft < p.lft AND a.rgt > p.rgt'); } else { // Only looking for categories with this parent. $query->where('a.parent_id = ' . (int) $parentId); } } } // Inclusive/exclusive filters (-ve id's are to be excluded). $categoryId = $this->getState('filter.category_id'); if (is_numeric($categoryId)) { if ($categoryId > 0) { $query->where('a.id = ' . (int) $categoryId); } else { $query->where('a.id <> ' . -(int) $categoryId); } } else { if (is_array($categoryId)) { JArrayHelper::toInteger($categoryId); // Find the include/excludes $include = array(); $exclude = array(); foreach ($categoryId as $id) { if ($id > 0) { $include[] = $id; } else { $exclude[] = $id; } } if (!empty($include)) { $include = implode(',', $include); $query->where('a.id IN (' . $include . ')'); } else { $include = implode(',', $include); $query->where('a.id NOT IN (' . $include . ')'); } } } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.lft')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->from('`#__usergroups` AS a'); // Add the level in the tree. $query->select('COUNT(DISTINCT c2.id) AS level'); $query->join('LEFT OUTER', '`#__usergroups` AS c2 ON a.lft > c2.lft AND a.rgt < c2.rgt'); $query->group('a.id'); // Count the objects in the user group. $query->select('COUNT(DISTINCT map.user_id) AS user_count'); $query->join('LEFT', '`#__user_usergroup_map` AS map ON map.group_id = a.id'); $query->group('a.id'); // Filter the comments over the search string if set. $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.title LIKE ' . $search); } } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.lft')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Method to build an SQL query to load the list data. * * @access protected * @return string An SQL query * @since 1.0 */ function _getListQuery() { $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->from('`#__social_threads` AS a'); // Join on the comments table. $query->select('COUNT(c.id) AS comment_count'); $query->leftJoin('#__social_comments AS c ON c.thread_id = a.id'); // Join on the ratings table. $query->select('pscore_count'); $query->leftJoin('#__social_ratings AS r ON r.thread_id = a.id'); $query->group('a.id'); // Filter the items over the context if set. if ($context = $this->getState('filter.context')) { $query->where('a.context = ' . $this->_db->Quote($context)); } // Filter by search string. if ($search = $this->getState('filter.search')) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.page_title LIKE ' . $search); } } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.id') . ' ' . $this->getState('list.direction', 'asc'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->from('`#__users` AS a'); // Join over the group mapping table. $query->select('COUNT(map.group_id) AS group_count'); $query->join('LEFT', '#__user_usergroup_map AS map ON map.user_id = a.id'); $query->group('a.id'); // Join over the user groups table. $query->select('GROUP_CONCAT(g2.title SEPARATOR ' . $this->_db->Quote("\n") . ') AS group_names'); $query->join('LEFT', '#__usergroups AS g2 ON g2.id = map.group_id'); // If the model is set to check item state, add to the query. $state = $this->getState('filter.state'); if (is_numeric($state)) { $query->where('a.block = ' . (int) $state); } // If the model is set to check the activated state, add to the query. $active = $this->getState('filter.active'); if (is_numeric($active)) { if ($active == '0') { $query->where('a.activation = ""'); } else { if ($active == '1') { $query->where('LENGTH(a.activation) = 32'); } } } // Filter the items over the group id if set. if ($groupId = $this->getState('filter.group_id')) { $query->join('LEFT', '#__user_usergroup_map AS map2 ON map2.user_id = a.id'); $query->where('map2.group_id = ' . (int) $groupId); } // Filter the items over the search string if set. if ($this->getState('filter.search') !== '') { // Escape the search token. $token = $this->_db->Quote('%' . $this->_db->getEscaped($this->getState('filter.search')) . '%'); // Compile the different search clauses. $searches = array(); $searches[] = 'a.name LIKE ' . $token; $searches[] = 'a.username LIKE ' . $token; $searches[] = 'a.email LIKE ' . $token; // Add the clauses to the query. $query->where('(' . implode(' OR ', $searches) . ')'); } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.name')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Get a list of menu links for one or all menus. * * @param string An option menu to filter the list on, otherwise all menu links are returned as a grouped array. * @param int An optional parent ID to pivot results around. * @param int An optional mode. If parent ID is set and mode=2, the parent and children are excluded from the list. * @param array An optional array of states */ public static function getMenuLinks($menuType = null, $parentId = 0, $mode = 0, $published = array()) { $db = JFactory::getDbo(); $query = new JQuery(); $query->select('a.id AS value, a.title AS text, a.level, a.menutype, a.type'); $query->from('#__menu AS a'); $query->join('LEFT', '`#__menu` AS b ON a.lft > b.lft AND a.rgt < b.rgt'); // Filter by the type if ($menuType) { $query->where('(a.menutype = ' . $db->quote($menuType) . ' OR a.parent_id = 0)'); } if ($parentId) { if ($mode == 2) { // Prevent the parent and children from showing. $query->join('LEFT', '`#__menu` AS p ON p.id = ' . (int) $parentId); $query->where('(a.lft <= p.lft OR a.rgt >= p.rgt)'); } } if (!empty($published)) { if (is_array($published)) { $published = '(' . implode(',', $published) . ')'; } $query->where('a.published IN ' . $published); } $query->group('a.id'); $query->order('a.lft ASC'); // Get the options. $db->setQuery($query); $links = $db->loadObjectList(); // Check for a database error. if ($error = $db->getErrorMsg()) { JError::raiseWarning(500, $error); return false; } // Pad the option text with spaces using depth level as a multiplier. foreach ($links as &$link) { $link->text = str_repeat('- ', $link->level) . $link->text; } if (empty($menuType)) { // If the menutype is empty, group the items by menutype. $query = new JQuery(); $query->select('*'); $query->from('#__menu_types'); $query->where('menutype <> ' . $db->quote('')); $query->order('title, menutype'); $db->setQuery($query); $menuTypes = $db->loadObjectList(); // Check for a database error. if ($error = $db->getErrorMsg()) { JError::raiseWarning(500, $error); return false; } // Create a reverse lookup and aggregate the links. $rlu = array(); foreach ($menuTypes as &$type) { $rlu[$type->menutype] =& $type; $type->links = array(); } // Loop through the list of menu links. foreach ($links as &$link) { if (isset($rlu[$link->menutype])) { $rlu[$link->menutype]->links[] =& $link; // Cleanup garbage. unset($link->menutype); } } return $menuTypes; } else { return $links; } }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Get the application object $app =& JFactory::getApplication(); require_once JPATH_COMPONENT . '/helpers/banners.php'; // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select('a.track_date as track_date,' . 'a.track_type as track_type,' . 'a.`count` as `count`'); $query->from('`#__banner_tracks` AS a'); // Join with the banners $query->join('LEFT', '`#__banners` as b ON b.id=a.banner_id'); $query->select('b.name as name'); // Join with the client $query->join('LEFT', '`#__banner_clients` as cl ON cl.id=b.cid'); $query->select('cl.name as client_name'); // Join with the category $query->join('LEFT', '`#__categories` as cat ON cat.id=b.catid'); $query->select('cat.title as category_title'); // Filter by type $type = $this->getState('filter.type'); if (!empty($type)) { $query->where('a.track_type = ' . (int) $type); } // Filter by client $clientId = $this->getState('filter.client_id'); if (is_numeric($clientId)) { $query->where('b.cid = ' . (int) $clientId); } // Filter by category $catedoryId = $this->getState('filter.category_id'); if (is_numeric($catedoryId)) { $query->where('b.catid = ' . (int) $catedoryId); } // Filter by begin date $begin = $this->getState('filter.begin'); if (!empty($begin)) { $query->where('a.track_date >= ' . $this->_db->Quote($begin)); } // Filter by end date $end = $this->getState('filter.end'); if (!empty($end)) { $query->where('a.track_date <= ' . $this->_db->Quote($end)); } // Add the list ordering clause. $orderCol = $this->getState('list.ordering', 'name'); $query->order($this->_db->getEscaped($orderCol) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); return $query; }
/** * Get a list of the authorised, non-special components to display in the components menu. * * @param array An optional array of components to exclude from the list. * @param boolean 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 */ function getComponents($authCheck = true) { // Initialise variables. $lang =& JFactory::getLanguage(); $user =& JFactory::getUser(); $db =& JFactory::getDbo(); $query = new JQuery(); $result = array(); $langs = array(); // Prepare the query. $query->select('m.id, m.title, m.alias, m.link, m.parent_id, m.img, e.element'); $query->from('#__menu AS m'); // Filter on the enabled states. $query->leftJoin('#__extensions AS e ON m.component_id = e.extension_id'); $query->where('m.menutype = "_adminmenu"'); $query->where('e.enabled = 1'); $query->where('m.id > 1'); // Order by lft. $query->order('m.lft'); $db->setQuery($query); $components = $db->loadObjectList(); // component list // 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->authorize('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)) { $langs[$component->element . '.menu'] = true; } } } 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)) { $result[$component->parent_id]->submenu[] =& $component; } } } } // Load additional language files. foreach (array_keys($langs) as $langName) { // Load extension-local file. $lang->load('menu', JPATH_ADMINISTRATOR . '/components/' . str_replace('.menu', '', $langName)); // Load the core file. $lang->load($langName); } return $result; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.id, a.name, a.alias, a.checked_out, a.checked_out_time, a.catid,' . 'a.numarticles, a.cache_time, ' . ' a.published, a.access, a.ordering, a.language')); $query->from('`#__newsfeeds` AS a'); // Join over the users for the checked out user. $query->select('uc.name AS editor'); $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); // Join over the asset groups. $query->select('ag.title AS access_level'); $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); // Join over the categories. $query->select('c.title AS category_title'); $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); // Filter by access level. if ($access = $this->getState('filter.access')) { $query->where('a.access = ' . (int) $access); } // Filter by published state. $published = $this->getState('filter.state'); if (is_numeric($published)) { $query->where('a.published = ' . (int) $published); } else { if ($published === '') { $query->where('(a.published IN (0, 1))'); } } // Filter by category. $categoryId = $this->getState('filter.category_id'); if (is_numeric($categoryId)) { $query->where('a.catid = ' . (int) $categoryId); } // Filter by search in title $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.name LIKE ' . $search . ' OR a.alias LIKE ' . $search); } } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.name')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Gets a list of the asset groups as an array of JHtml compatible options. * * @param array $config An array of options for the options * * @return mixed An array or false if an error occurs */ public static function assetgroups($config = array()) { if (empty(JHtmlAccess::$asset_groups)) { $db =& JFactory::getDbo(); $query = new JQuery(); $query->select('a.id AS value, a.title AS text'); $query->from('#__viewlevels AS a'); $query->group('a.id'); $query->order('a.ordering ASC'); $db->setQuery($query); JHtmlAccess::$asset_groups = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseNotice(500, $db->getErrorMsg()); return false; } } return JHtmlAccess::$asset_groups; }
/** * Method to return the JRules object for an asset. The returned object can optionally hold * only the rules explicitly set for the asset or the summation of all inherited rules from * parent assets and explicit rules. * * @param mixed Integer asset id or the name of the asset as a string. * @param boolean True to return the rules object with inherited rules. * @return object JRules object for the asset. * @since 1.6 */ public static function getAssetRules($asset, $recursive = false) { // Get the database connection object. $db = JFactory::getDbo(); // Build the database query to get the rules for the asset. $query = new JQuery(); $query->select($recursive ? 'b.rules' : 'a.rules'); $query->from('#__assets AS a'); // If the asset identifier is numeric assume it is a primary key, else lookup by name. if (is_numeric($asset)) { $query->where('a.id = ' . (int) $asset); } else { $query->where('a.name = ' . $db->quote($asset)); } // If we want the rules cascading up to the global asset node we need a self-join. if ($recursive) { $query->leftJoin('#__assets AS b ON b.lft <= a.lft AND b.rgt >= a.rgt'); $query->order('b.lft'); } // Execute the query and load the rules from the result. $db->setQuery($query); $result = $db->loadResultArray(); // Instantiate and return the JRules object for the asset rules. $rules = new JRules(); $rules->mergeCollection($result); return $rules; }
/** * Gets a list of banners * @return array An array of banner objects */ function _getListQuery() { static $query; if (!isset($query)) { $query = new JQuery(); $ordering = $this->getState('filter.ordering'); $tagSearch = $this->getState('filter.tag_search'); $cid = $this->getState('filter.client_id'); $catid = $this->getState('filter.category_id'); $keywords = $this->getState('filter.keywords'); $randomise = $ordering == 'random'; $query->select('a.id as id,' . 'a.type as type,' . 'a.name as name,' . 'a.clickurl as clickurl,' . 'a.cid as cid,' . 'a.params as params,' . 'a.track_impressions as track_impressions'); $query->from('#__banners as a'); $query->where('a.state=1'); $query->where("(NOW() >= a.publish_up OR a.publish_up='0000-00-00 00:00:00')"); $query->where("(NOW() <= a.publish_down OR a.publish_down='0000-00-00 00:00:00')"); $query->where('(a.imptotal = 0 OR a.impmade = a.imptotal)'); if ($cid) { $query->where('a.cid = ' . (int) $cid); $query->join('LEFT', '#__banner_clients AS cl ON cl.id = a.cid'); $query->select('cl.track_impressions as client_track_impressions'); $query->where('cl.state = 1'); } if ($catid) { $query->where('a.catid = ' . (int) $catid); $query->join('LEFT', '#__categories AS cat ON cat.id = a.catid'); $query->where('cat.published = 1'); } if ($tagSearch) { if (count($keywords) == 0) { $query->where('0'); } else { $temp = array(); $config =& JComponentHelper::getParams('com_banners'); $prefix = $config->get('metakey_prefix'); foreach ($keywords as $keyword) { $keyword = trim($keyword); $condition1 = "a.own_prefix=1 AND a.metakey_prefix=SUBSTRING('" . $keyword . "',1,LENGTH( a.metakey_prefix)) OR a.own_prefix=0 AND cl.own_prefix=1 AND cl.metakey_prefix=SUBSTRING('" . $keyword . "',1,LENGTH(cl.metakey_prefix)) OR a.own_prefix=0 AND cl.own_prefix=0 AND " . ($prefix == substr($keyword, 0, strlen($prefix)) ? '1' : '0'); $condition2 = "a.metakey REGEXP '[[:<:]]" . $this->_db->getEscaped($keyword) . "[[:>:]]'"; if ($cid) { $condition2 .= " OR cl.metakey REGEXP '[[:<:]]" . $this->_db->getEscaped($keyword) . "[[:>:]]'"; } if ($catid) { $condition2 .= " OR cat.metakey REGEXP '[[:<:]]" . $this->_db->getEscaped($keyword) . "[[:>:]]'"; } $temp[] = "({$condition1}) AND ({$condition2})"; } $query->where('(' . implode(' OR ', $temp) . ')'); } } $query->order('a.sticky DESC,' . ($randomise ? 'RAND()' : 'a.ordering')); } return $query; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->from('`#__core_log_searches` AS a'); // Filter by access level. if ($access = $this->getState('filter.access')) { $query->where('a.access = ' . (int) $access); } // Filter by search in title $search = $this->getState('filter.search'); if (!empty($search)) { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.search_term LIKE ' . $search); } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.hits')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Get the application object $app =& JFactory::getApplication(); // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.id AS id, a.name AS name, a.alias AS alias,' . 'a.checked_out AS checked_out,' . 'a.checked_out_time AS checked_out_time, a.catid AS catid,' . 'a.clicks AS clicks, a.metakey AS metakey, a.sticky AS sticky,' . 'a.impmade AS impmade, a.imptotal AS imptotal,' . 'a.state AS state, a.ordering AS ordering,' . 'a.purchase_type as purchase_type')); $query->from('`#__banners` AS a'); // Join over the users for the checked out user. $query->select('uc.name AS editor'); $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); // Join over the categories. $query->select('c.title AS category_title'); $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); // Join over the clients. $query->select('cl.name AS client_name,cl.purchase_type as client_purchase_type'); $query->join('LEFT', '#__banner_clients AS cl ON cl.id = a.cid'); // Filter by published state $published = $this->getState('filter.state'); if (is_numeric($published)) { $query->where('a.state = ' . (int) $published); } else { if ($published === '') { $query->where('(a.state IN (0, 1))'); } } // Filter by category. $categoryId = $this->getState('filter.category_id'); if (is_numeric($categoryId)) { $query->where('a.catid = ' . (int) $categoryId); } // Filter by client. $clientId = $this->getState('filter.client_id'); if (is_numeric($clientId)) { $query->where('a.cid = ' . (int) $clientId); } // Filter by search in title $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('(a.name LIKE ' . $search . ' OR a.alias LIKE ' . $search . ')'); } } // Add the list ordering clause. $orderCol = $this->getState('list.ordering', 'ordering'); $app->setUserState($this->_context . '.' . $orderCol . '.orderdirn', $this->getState('list.direction', 'ASC')); if ($orderCol == 'ordering') { $query->order($this->_db->getEscaped('category_title') . ' ' . $this->_db->getEscaped($app->getUserState($this->_context . '.category_title.orderdirn', 'ASC'))); } $query->order($this->_db->getEscaped($orderCol) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); if ($orderCol == 'category_title') { $query->order($this->_db->getEscaped('ordering') . ' ' . $this->_db->getEscaped($app->getUserState($this->_context . '.ordering.orderdirn', 'ASC'))); } $query->order($this->_db->getEscaped('state') . ' ' . $this->_db->getEscaped($app->getUserState($this->_context . '.state.orderdirn', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Get the list of modules not in trash. * * @return mixed An array of module records (id, title, position), or false on error. */ public function getModules() { $query = new JQuery(); $query->select('a.id, a.title, a.position, a.published'); $query->from('#__modules AS a'); // Join on the module-to-menu mapping table. // We are only interested if the module is displayed on ALL or THIS menu item (or the inverse ID number). $query->select('map.menuid'); $query->join('LEFT', '#__modules_menu AS map ON map.moduleid = a.id AND (map.menuid = 0 OR ABS(map.menuid) = ' . (int) $this->getState('item.id') . ')'); // Join on the asset groups table. $query->select('ag.title AS access_title'); $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); $query->where('a.published >= 0'); $query->where('a.client_id = 0'); $query->order('a.position, a.ordering'); $this->_db->setQuery($query); $result = $this->_db->loadObjectList(); if ($error = $this->_db->getError()) { $this->setError($error); return false; } return $result; }