/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

  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. defined('_JEXEC') or die;
  10. /**
  11. * Components helper for com_config
  12. *
  13. * @package Joomla.Administrator
  14. * @subpackage com_config
  15. * @since 3.0
  16. */
  17. class ConfigHelperComponent
  18. {
  19. /**
  20. * Get an array of all enabled components.
  21. *
  22. * @return array
  23. *
  24. * @since 3.0
  25. */
  26. public static function getAllComponents()
  27. {
  28. $db = JFactory::getDBO();
  29. $query = $db->getQuery(true);
  30. $query->select('name');
  31. $query->from('#__extensions');
  32. $query->where('type = ' . $db->quote('component'));
  33. $query->where('enabled = 1');
  34. $db->setQuery($query);
  35. $result = $db->loadColumn();
  36. return $result;
  37. }
  38. /**
  39. * Returns true if the component has configuration options.
  40. *
  41. * @param string $components
  42. *
  43. * @return boolean
  44. *
  45. * @since 3.0
  46. */
  47. public static function hasComponentConfig($component)
  48. {
  49. return is_file(JPATH_ADMINISTRATOR . '/components/' . $component . '/config.xml');
  50. }
  51. /**
  52. * Returns an array of all components with configuration options. By only
  53. * components for which the current user has 'core.manage' rights are returned.
  54. *
  55. * @param boolean $authCheck
  56. *
  57. * @return array
  58. *
  59. * @since 3.0
  60. */
  61. public static function getComponentsWithConfig($authCheck = true)
  62. {
  63. $result = array();
  64. $components = self::getAllComponents();
  65. $user = JFactory::getUser();
  66. // Remove com_config from the array as that may have weird side effects
  67. $components = array_diff($components, array('com_config'));
  68. foreach ($components as $component)
  69. {
  70. if (self::hasComponentConfig($component) && (!$authCheck || $user->authorise('core.manage', $component)))
  71. {
  72. $result[] = $component;
  73. }
  74. }
  75. return $result;
  76. }
  77. /**
  78. * Load the sys language for the given component.
  79. *
  80. * @param string $components
  81. *
  82. * @return void
  83. *
  84. * @since 3.0
  85. */
  86. public static function loadLanguageForComponents($components)
  87. {
  88. $lang = JFactory::getLanguage();
  89. foreach ($components as $component)
  90. {
  91. if (!empty($component)) {
  92. // Load the core file then
  93. // Load extension-local file.
  94. $lang->load($component . '.sys', JPATH_BASE, null, false, false)
  95. || $lang->load($component . '.sys', JPATH_ADMINISTRATOR . '/components/' . $component, null, false, false)
  96. || $lang->load($component . '.sys', JPATH_BASE, $lang->getDefault(), false, false)
  97. || $lang->load($component . '.sys', JPATH_ADMINISTRATOR . '/components/' . $component, $lang->getDefault(), false, false);
  98. }
  99. }
  100. }
  101. }