/** * 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; }
/** * 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); } }
/** * @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; }
/** * Method to build menu database entries for a component * * @access private * @return boolean True if successful * @since 1.5 */ protected function _buildAdminMenus() { // Initialise variables. $db =& $this->parent->getDbo(); $table =& JTable::getInstance('menu'); $option = $this->get('element'); // If a component exists with this option in the table then we don't need to add menus $query = new JQuery(); $query->select('m.id, e.extension_id'); $query->from('#__menu AS m'); $query->leftJoin('#__extensions AS e ON m.component_id = e.extension_id'); $query->where('m.parent_id = 1'); $query->where('e.element = ' . $db->quote($option)); $db->setQuery($query); $componentrow = $db->loadObject(); // Check if menu items exist if ($componentrow) { // Don't do anything if overwrite has not been enabled if (!$this->parent->getOverwrite()) { return true; } // Remove existing menu items if overwrite has been enabled if ($option) { $this->_removeAdminMenus($componentrow); // If something goes wrong, theres no way to rollback TODO: Search for better solution } } else { // Lets Find the extension id $query = new JQuery(); $query->select('e.extension_id'); $query->from('#__extensions AS e'); $query->where('e.element = ' . $db->quote($option)); $db->setQuery($query); $component_id = $db->loadResult(); // TODO Find Some better way to discover the component_id } // Ok, now its time to handle the menus. Start with the component root menu, then handle submenus. $menuElement = $this->manifest->administration->menu; if ($menuElement) { $data = array(); $data['menutype'] = '_adminmenu'; $data['title'] = $option; $data['alias'] = (string) $menuElement; $data['link'] = 'index.php?option=' . $option; $data['type'] = 'component'; $data['published'] = 0; $data['parent_id'] = 1; $data['component_id'] = $component_id; $data['img'] = (string) $menuElement->attributes()->img ? (string) $menuElement->attributes()->img : 'class:component'; $data['home'] = 0; if (!$table->setLocation(1, 'last-child') || !$table->bind($data) || !$table->check() || !$table->store()) { // Install failed, rollback changes $this->parent->abort(JText::_('Component') . ' ' . JText::_('Install') . ': ' . $db->stderr(true)); return false; } /* * Since we have created a menu item, we add it to the installation step stack * so that if we have to rollback the changes we can undo it. */ $this->parent->pushStep(array('type' => 'menu')); } else { // No menu element was specified, Let's make a generic menu item $data = array(); $data['menutype'] = '_adminmenu'; $data['title'] = $option; $data['alias'] = $option; $data['link'] = 'index.php?option=' . $option; $data['type'] = 'component'; $data['published'] = 0; $data['parent_id'] = 1; $data['component_id'] = $component_id; $data['img'] = 'class:component'; $data['home'] = 0; if (!$table->bind($data) || !$table->check() || !$table->store()) { // Install failed, rollback changes $this->parent->abort(JText::_('Component') . ' ' . JText::_('Install') . ': ' . $db->stderr(true)); return false; } /* * Since we have created a menu item, we add it to the installation step stack * so that if we have to rollback the changes we can undo it. */ $this->parent->pushStep(array('type' => 'menu')); } /* * Process SubMenus */ if (!$this->manifest->administration->submenu) { return true; } foreach ($this->manifest->administration->submenu->menu as $child) { $data = array(); $data['menutype'] = '_adminmenu'; $data['title'] = (string) $child->attributes()->view ? $option . '_' . $child->attributes()->view : $option; $data['alias'] = (string) $child; $data['type'] = 'component'; $data['published'] = 0; $data['parent_id'] = 1; $data['component_id'] = $component_id; $data['img'] = (string) $child->attributes()->img ? (string) $child->attributes()->img : 'class:component'; $data['home'] = 0; // Set the sub menu link if ((string) $child->attributes()->link) { $data['link'] = (string) $child->attributes()->link; } else { $request = array(); if ((string) $child->attributes()->act) { $request[] = 'act=' . $child->attributes()->act; } if ((string) $child->attributes()->task) { $request[] = 'task=' . $child->attributes()->task; } if ((string) $child->attributes()->controller) { $request[] = 'controller=' . $child->attributes()->controller; } if ((string) $child->attributes()->view) { $request[] = 'view=' . $child->attributes()->view; } if ((string) $child->attributes()->layout) { $request[] = 'layout=' . $child->attributes()->layout; } if ((string) $child->attributes()->sub) { $request[] = 'sub=' . $child->attributes()->sub; } $qstring = count($request) ? '&' . implode('&', $request) : ''; $data['link'] = "index.php?option=" . $option . $qstring; } if (!$table->bind($data) || !$table->check() || !$table->store()) { // Install failed, rollback changes $this->parent->abort(JText::_('Component') . ' ' . JText::_('Install') . ': ' . $db->stderr(true)); return false; } /* * Since we have created a menu item, we add it to the installation step stack * so that if we have to rollback the changes we can undo it. */ $this->parent->pushStep(array('type' => 'menu')); } }
/** * 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; }
/** * Method to return a list of user groups mapped to a user. The returned list can optionally hold * only the groups explicitly mapped to the user or all groups both explicitly mapped and inherited * by the user. * * @param integer Id of the user for which to get the list of groups. * @param boolean True to include inherited user groups. * @return array List of user group ids to which the user is mapped. * @since 1.6 */ public static function getGroupsByUser($userId, $recursive = true) { // 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.id' : 'a.id'); $query->from('#__user_usergroup_map AS map'); $query->where('map.user_id = ' . (int) $userId); $query->leftJoin('#__usergroups AS a ON a.id = map.group_id'); // If we want the rules cascading up to the global asset node we need a self-join. if ($recursive) { $query->leftJoin('#__usergroups AS b ON b.lft <= a.lft AND b.rgt >= a.rgt'); } // Execute the query and load the rules from the result. $db->setQuery($query); $result = $db->loadResultArray(); // Clean up any NULL or duplicate values, just in case JArrayHelper::toInteger($result); if (empty($result)) { $result = array('1'); } else { $result = array_unique($result); } return $result; }