Guest User

93

a guest
Sep 6th, 2016
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. <?php
  2. /**
  3. * Main Plugin File
  4. *
  5. * @package Advanced Module Manager
  6. * @version 4.22.7
  7. *
  8. * @author Peter van Westen <[email protected]>
  9. * @link http://www.nonumber.nl
  10. * @copyright Copyright © 2015 NoNumber All Rights Reserved
  11. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
  12. */
  13.  
  14. defined('_JEXEC') or die;
  15.  
  16. jimport('joomla.filesystem.file');
  17.  
  18. /**
  19. * Plugin that shows active modules in menu item edit view
  20. */
  21. class plgSystemAdvancedModules extends JPlugin
  22. {
  23. private $_alias = 'advancedmodules';
  24. private $_title = 'ADVANCED_MODULE_MANAGER';
  25. private $_lang_prefix = 'AMM';
  26.  
  27. private $_init = false;
  28. private $_helper = null;
  29.  
  30. public function __construct(&$subject, $config)
  31. {
  32. parent::__construct($subject, $config);
  33.  
  34. if (!$this->getHelper())
  35. {
  36. return;
  37. }
  38.  
  39. if (!JFactory::getApplication()->isSite())
  40. {
  41. return;
  42. }
  43.  
  44. $this->_helper->loadModuleHelper();
  45. $this->_helper->registerEvents();
  46. }
  47.  
  48. /*
  49. * Replace links to com_modules with com_advancedmodules
  50. */
  51. public function onAfterRender()
  52. {
  53. if (!$this->getHelper())
  54. {
  55. return;
  56. }
  57.  
  58. // only in html
  59. if (JFactory::getDocument()->getType() != 'html')
  60. {
  61. return;
  62. }
  63.  
  64. $this->_helper->replaceLinks();
  65. }
  66.  
  67. /*
  68. * Below methods are general functions used in most of the NoNumber extensions
  69. * The reason these are not placed in the NoNumber Framework files is that they also
  70. * need to be used when the NoNumber Framework is not installed
  71. */
  72.  
  73. /**
  74. * Create the helper object
  75. *
  76. * @return object The plugins helper object
  77. */
  78. private function getHelper()
  79. {
  80. // Already initialized, so return
  81. if ($this->_init)
  82. {
  83. return $this->_helper;
  84. }
  85.  
  86. $this->_init = true;
  87.  
  88. if (!$this->isFrameworkEnabled())
  89. {
  90. return false;
  91. }
  92.  
  93. require_once JPATH_PLUGINS . '/system/nnframework/helpers/protect.php';
  94.  
  95. if (!nnProtect::isComponentInstalled($this->_alias))
  96. {
  97. return false;
  98. }
  99.  
  100. if (nnProtect::isProtectedPage($this->_alias))
  101. {
  102. return false;
  103. }
  104.  
  105. require_once JPATH_PLUGINS . '/system/nnframework/helpers/helper.php';
  106. $this->_helper = nnFrameworkHelper::getPluginHelper($this);
  107.  
  108. return $this->_helper;
  109. }
  110.  
  111. /**
  112. * Check if the NoNumber Framework is enabled
  113. *
  114. * @return bool
  115. */
  116. private function isFrameworkEnabled()
  117. {
  118. // Return false if NoNumber Framework is not installed
  119. if (!$this->isFrameworkInstalled())
  120. {
  121. return false;
  122. }
  123.  
  124. $nnframework = JPluginHelper::getPlugin('system', 'nnframework');
  125. if (!isset($nnframework->name))
  126. {
  127. $this->throwError($this->_lang_prefix . '_NONUMBER_FRAMEWORK_NOT_ENABLED');
  128.  
  129. return false;
  130. }
  131.  
  132. return true;
  133. }
  134.  
  135. /**
  136. * Check if the NoNumber Framework is installed
  137. *
  138. * @return bool
  139. */
  140. private function isFrameworkInstalled()
  141. {
  142. jimport('joomla.filesystem.file');
  143.  
  144. if (!JFile::exists(JPATH_PLUGINS . '/system/nnframework/nnframework.php'))
  145. {
  146. $this->throwError($this->_lang_prefix . '_NONUMBER_FRAMEWORK_NOT_INSTALLED');
  147.  
  148. return false;
  149. }
  150.  
  151. return true;
  152. }
  153.  
  154. /**
  155. * Place an error in the message queue
  156. */
  157. private function throwError($text)
  158. {
  159. // Return if page is not an admin page or the admin login page
  160. if (
  161. !JFactory::getApplication()->isAdmin()
  162. || JFactory::getUser()->get('guest')
  163. )
  164. {
  165. return;
  166. }
  167.  
  168. // load the admin language file
  169. JFactory::getLanguage()->load('plg_' . $this->_type . '_' . $this->_name, JPATH_ADMINISTRATOR);
  170.  
  171. $text = JText::_($text) . ' ' . JText::sprintf($this->_lang_prefix . '_EXTENSION_CAN_NOT_FUNCTION', JText::_($this->_title));
  172.  
  173. // Check if message is not already in queue
  174. $messagequeue = JFactory::getApplication()->getMessageQueue();
  175. foreach ($messagequeue as $message)
  176. {
  177. if ($message['message'] == $text)
  178. {
  179. return;
  180. }
  181. }
  182.  
  183. JFactory::getApplication()->enqueueMessage($text, 'error');
  184. }
  185. }
Advertisement
Add Comment
Please, Sign In to add comment