BxDolModule.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentCore Trident Core
  7. * @{
  8. */
  9. /**
  10. * Base class for Module classes in modules engine.
  11. *
  12. * The object of the class contains major objects of the whole module. They are:
  13. * a. An object of config class
  14. * @see BxDolModuleConfig
  15. *
  16. * b. An object of database class.
  17. * @see BxDolModuleQuery
  18. *
  19. * c. An object of template class.
  20. * @see BxDolTemplate
  21. *
  22. *
  23. * Example of usage:
  24. * refer to any BoonEx module
  25. *
  26. *
  27. * Static Methods:
  28. *
  29. * Get an instance of a module's class.
  30. * @see BxDolModule::getInstance($sClassName)
  31. *
  32. *
  33. * Memberships/ACL:
  34. * Doesn't depend on user's membership.
  35. *
  36. *
  37. * Alerts:
  38. * no alerts available
  39. *
  40. */
  41. class BxDolModule extends BxDol
  42. {
  43. public $_aModule;
  44. public $_oDb;
  45. public $_oTemplate;
  46. public $_oConfig;
  47. /**
  48. * constructor
  49. */
  50. function __construct($aModule)
  51. {
  52. parent::__construct();
  53. $this->_aModule = $aModule;
  54. $sClassPrefix = $aModule['class_prefix'];
  55. $sClassPath = BX_DIRECTORY_PATH_MODULES . $aModule['path'] . 'classes/';
  56. $sClassName = $sClassPrefix . 'Config';
  57. require_once($sClassPath . $sClassName . '.php');
  58. $this->_oConfig = new $sClassName($aModule);
  59. $sClassName = $sClassPrefix . 'Db';
  60. require_once($sClassPath . $sClassName . '.php');
  61. $this->_oDb = new $sClassName($this->_oConfig);
  62. $sClassName = $sClassPrefix . 'Template';
  63. require_once($sClassPath . $sClassName . '.php');
  64. $this->_oTemplate = new $sClassName($this->_oConfig, $this->_oDb);
  65. $this->_oTemplate->loadTemplates();
  66. }
  67. /**
  68. * Static method to get an instance of a module's class.
  69. *
  70. * @param $sName module name.
  71. */
  72. public static function getInstance($sName)
  73. {
  74. if (empty($sName))
  75. return null;
  76. $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sName);
  77. if (empty($aModule) || !is_array($aModule))
  78. return null;
  79. $sClassName = $aModule['class_prefix'] . 'Module';
  80. if ('system' != $sName) {
  81. if (isset($GLOBALS['bxDolClasses'][$sClassName]))
  82. return $GLOBALS['bxDolClasses'][$sClassName];
  83. $sClassPath = BX_DIRECTORY_PATH_MODULES . $aModule['path'] . '/classes/' . $sClassName . '.php';
  84. if (!file_exists($sClassPath))
  85. return null;
  86. require_once($sClassPath);
  87. $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName($aModule);
  88. return $GLOBALS['bxDolClasses'][$sClassName];
  89. } else {
  90. $sClassName = 'BxTemplServices';
  91. return bx_instance($sClassName, array($aModule));
  92. }
  93. }
  94. public static function getTitle($sUri)
  95. {
  96. return _t(self::getTitleKey($sUri));
  97. }
  98. public static function getTitleKey($sUri)
  99. {
  100. return '_sys_module_' . strtolower(str_replace(' ', '_', $sUri));
  101. }
  102. /**
  103. * is module enabled
  104. */
  105. function isEnabled()
  106. {
  107. return (int)$this->_aModule['enabled'] == 1;
  108. }
  109. /**
  110. * get module name
  111. */
  112. function getName()
  113. {
  114. return $this->_aModule['name'];
  115. }
  116. /**
  117. * Check whether user logged in or not.
  118. *
  119. * @return boolean result of operation.
  120. */
  121. public function isLogged()
  122. {
  123. return isLogged();
  124. }
  125. /**
  126. * Get currently logged in user ID.
  127. *
  128. * @return integer user ID.
  129. */
  130. public function getUserId()
  131. {
  132. return getLoggedId();
  133. }
  134. /**
  135. * Get currently logged in user password.
  136. *
  137. * @return string user password.
  138. */
  139. public function getUserPassword ()
  140. {
  141. return getLoggedPassword();
  142. }
  143. }
  144. /** @} */