PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_modules/helpers/modules.php

https://github.com/ot2sen/Molajo
PHP | 191 lines | 114 code | 23 blank | 54 comment | 5 complexity | 8f8c6065eea877be683f67f2d64fa3b1 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: modules.php 21670 2011-06-24 08:11:47Z chdemko $
  4. * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
  5. * @license GNU General Public License version 2 or later; see LICENSE.txt
  6. */
  7. // No direct access.
  8. defined('_JEXEC') or die;
  9. /**
  10. * Modules component helper.
  11. *
  12. * @package Joomla.Administrator
  13. * @subpackage com_modules
  14. * * * @since 1.0
  15. */
  16. abstract class ModulesHelper
  17. {
  18. /**
  19. * Configure the Linkbar.
  20. *
  21. * @param string The name of the active view.
  22. */
  23. public static function addSubmenu($vName)
  24. {
  25. // Not used in this component.
  26. }
  27. /**
  28. * Gets a list of the actions that can be performed.
  29. *
  30. * @return JObject
  31. */
  32. public static function getActions()
  33. {
  34. $user = MolajoFactory::getUser();
  35. $result = new JObject;
  36. $actions = array(
  37. 'core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.state', 'core.delete'
  38. );
  39. foreach ($actions as $action) {
  40. $result->set($action, $user->authorise($action, 'com_modules'));
  41. }
  42. return $result;
  43. }
  44. /**
  45. * Get a list of filter options for the state of a module.
  46. *
  47. * @return array An array of JHtmlOption elements.
  48. */
  49. public static function getStateOptions()
  50. {
  51. // Build the filter options.
  52. $options = array();
  53. $options[] = JHtml::_('select.option', '1', JText::_('JPUBLISHED'));
  54. $options[] = JHtml::_('select.option', '0', JText::_('JUNPUBLISHED'));
  55. $options[] = JHtml::_('select.option', '-2', JText::_('JTRASHED'));
  56. return $options;
  57. }
  58. /**
  59. * Get a list of filter options for the application applications.
  60. *
  61. * @return array An array of JHtmlOption elements.
  62. */
  63. public static function getApplicationOptions()
  64. {
  65. // Build the filter options.
  66. $options = array();
  67. $options[] = JHtml::_('select.option', '0', JText::_('JSITE'));
  68. $options[] = JHtml::_('select.option', '1', JText::_('JADMINISTRATOR'));
  69. return $options;
  70. }
  71. static function getPositions($applicationId)
  72. {
  73. jimport('joomla.filesystem.folder');
  74. $db = MolajoFactory::getDbo();
  75. $query = $db->getQuery(true);
  76. $query->select('DISTINCT(position)');
  77. $query->from('#__modules');
  78. $query->where('`application_id` = '.(int) $applicationId);
  79. $query->order('position');
  80. $db->setQuery($query);
  81. $positions = $db->loadResultArray();
  82. $positions = (is_array($positions)) ? $positions : array();
  83. if ($error = $db->getErrorMsg()) {
  84. JError::raiseWarning(500, $error);
  85. return;
  86. }
  87. // Build the list
  88. $options = array();
  89. foreach ($positions as $position) {
  90. $options[] = JHtml::_('select.option', $position, $position);
  91. }
  92. return $options;
  93. }
  94. public static function getTemplates($applicationId = 0, $state = '', $template='')
  95. {
  96. $db = MolajoFactory::getDbo();
  97. // Get the database object and a new query object.
  98. $query = $db->getQuery(true);
  99. // Build the query.
  100. $query->select('element, name, enabled');
  101. $query->from('#__extensions');
  102. $query->where('application_id = '.(int) $applicationId);
  103. $query->where('type = '.$db->quote('template'));
  104. if ($state!='') {
  105. $query->where('enabled = '.$db->quote($state));
  106. }
  107. if ($template!='') {
  108. $query->where('element = '.$db->quote($template));
  109. }
  110. // Set the query and load the templates.
  111. $db->setQuery($query);
  112. $templates = $db->loadObjectList('element');
  113. return $templates;
  114. }
  115. /**
  116. * Get a list of the unique modules installed in the application application.
  117. *
  118. * @param int The application id.
  119. *
  120. * @return array
  121. */
  122. public static function getModules($applicationId)
  123. {
  124. $db = MolajoFactory::getDbo();
  125. $query = $db->getQuery(true);
  126. $query->select('element AS value, name AS text');
  127. $query->from('#__extensions as e');
  128. $query->where('e.`application_id` = '.(int)$applicationId);
  129. $query->where('`type` = '.$db->quote('module'));
  130. $query->where('`enabled` = 1');
  131. $query->leftJoin('#__modules as m ON m.module=e.element AND m.application_id=e.application_id');
  132. $query->where('m.module IS NOT NULL');
  133. $query->group('element');
  134. $db->setQuery($query);
  135. $modules = $db->loadObjectList();
  136. $lang = MolajoFactory::getLanguage();
  137. foreach ($modules as $i=>$module) {
  138. $extension = $module->value;
  139. $path = $applicationId ? JPATH_ADMINISTRATOR : JPATH_SITE;
  140. $source = $path . "/modules/$extension";
  141. $lang->load("$extension.sys", $path, null, false, false)
  142. || $lang->load("$extension.sys", $source, null, false, false)
  143. || $lang->load("$extension.sys", $path, $lang->getDefault(), false, false)
  144. || $lang->load("$extension.sys", $source, $lang->getDefault(), false, false);
  145. $modules[$i]->text = JText::_($module->text);
  146. }
  147. JArrayHelper::sortObjects($modules, 'text', 1, true, $lang->getLocale());
  148. return $modules;
  149. }
  150. /**
  151. * Get a list of the assignment options for modules to menus.
  152. *
  153. * @param int The application id.
  154. *
  155. * @return array
  156. */
  157. public static function getAssignmentOptions($applicationId)
  158. {
  159. $options = array();
  160. $options[] = JHtml::_('select.option', '0', 'COM_MODULES_OPTION_MENU_ALL');
  161. $options[] = JHtml::_('select.option', '-', 'COM_MODULES_OPTION_MENU_NONE');
  162. if ($applicationId == 0) {
  163. $options[] = JHtml::_('select.option', '1', 'COM_MODULES_OPTION_MENU_INCLUDE');
  164. $options[] = JHtml::_('select.option', '-1', 'COM_MODULES_OPTION_MENU_EXCLUDE');
  165. }
  166. return $options;
  167. }
  168. }