PageRenderTime 12ms CodeModel.GetById 7ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_config/helper/component.php

https://bitbucket.org/eternaware/joomus
PHP | 112 lines | 49 code | 11 blank | 52 comment | 4 complexity | bcb12974262e565489582db25db103c9 MD5 | raw file
Possible License(s): LGPL-2.1
  1<?php
  2/**
  3 * @package     Joomla.Administrator
  4 * @subpackage  com_config
  5 *
  6 * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7 * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8 */
  9
 10defined('_JEXEC') or die;
 11
 12/**
 13 * Components helper for com_config
 14 *
 15 * @package     Joomla.Administrator
 16 * @subpackage  com_config
 17 * @since       3.0
 18 */
 19class ConfigHelperComponent
 20{
 21	/**
 22	 * Get an array of all enabled components.
 23	 *
 24	 * @return  array
 25	 *
 26	 * @since   3.0
 27	 */
 28	public static function getAllComponents()
 29	{
 30		$db = JFactory::getDBO();
 31		$query = $db->getQuery(true);
 32		$query->select('name');
 33		$query->from('#__extensions');
 34		$query->where('type = ' . $db->quote('component'));
 35		$query->where('enabled = 1');
 36		$db->setQuery($query);
 37		$result = $db->loadColumn();
 38
 39		return $result;
 40	}
 41
 42	/**
 43	 * Returns true if the component has configuration options.
 44	 *
 45	 * @param   string  $components
 46	 *
 47	 * @return  boolean
 48	 *
 49	 * @since   3.0
 50	 */
 51	public static function hasComponentConfig($component)
 52	{
 53		return is_file(JPATH_ADMINISTRATOR . '/components/' . $component . '/config.xml');
 54	}
 55
 56	/**
 57	 * Returns an array of all components with configuration options. By only
 58	 * components for which the current user has 'core.manage' rights are returned.
 59	 *
 60	 * @param   boolean  $authCheck
 61	 *
 62	 * @return  array
 63	 *
 64	 * @since   3.0
 65	 */
 66	public static function getComponentsWithConfig($authCheck = true)
 67	{
 68		$result = array();
 69		$components = self::getAllComponents();
 70		$user = JFactory::getUser();
 71
 72		// Remove com_config from the array as that may have weird side effects
 73		$components = array_diff($components, array('com_config'));
 74
 75		foreach ($components as $component)
 76		{
 77			if (self::hasComponentConfig($component) && (!$authCheck || $user->authorise('core.manage', $component)))
 78			{
 79				$result[] = $component;
 80			}
 81		}
 82
 83		return $result;
 84	}
 85
 86	/**
 87	 * Load the sys language for the given component.
 88	 *
 89	 * @param   string  $components
 90	 *
 91	 * @return  void
 92	 *
 93	 * @since   3.0
 94	 */
 95	public static function loadLanguageForComponents($components)
 96	{
 97		$lang = JFactory::getLanguage();
 98
 99		foreach ($components as $component)
100		{
101			if (!empty($component)) {
102					// Load the core file then
103					// Load extension-local file.
104					$lang->load($component . '.sys', JPATH_BASE, null, false, false)
105				||	$lang->load($component . '.sys', JPATH_ADMINISTRATOR . '/components/' . $component, null, false, false)
106				||	$lang->load($component . '.sys', JPATH_BASE, $lang->getDefault(), false, false)
107				||	$lang->load($component . '.sys', JPATH_ADMINISTRATOR . '/components/' . $component, $lang->getDefault(), false, false);
108			}
109		}
110	}
111
112}