BxBaseModGeneralModule.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 BaseGeneral Base classes for modules
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import ('BxDolModule');
  12. /**
  13. * Base module class.
  14. */
  15. class BxBaseModGeneralModule extends BxDolModule
  16. {
  17. protected $_iProfileId;
  18. function __construct(&$aModule)
  19. {
  20. parent::__construct($aModule);
  21. $this->_iProfileId = bx_get_logged_profile_id();
  22. }
  23. // ====== ACTIONS METHODS
  24. public function actionRss ($sMode = '')
  25. {
  26. $aArgs = func_get_args();
  27. $sMode = array_shift($aArgs);
  28. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  29. $this->_oTemplate->displayAccessDenied ();
  30. exit;
  31. }
  32. $aParams = $this->_buildRssParams($sMode, $aArgs);
  33. bx_import ('SearchResult', $this->_aModule);
  34. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  35. $o = new $sClass($sMode, $aParams);
  36. if ($o->isError) {
  37. $this->_oTemplate->displayPageNotFound ();
  38. exit;
  39. }
  40. $o->outputRSS();
  41. exit;
  42. }
  43. // ====== SERVICE METHODS
  44. /**
  45. * Add entry form
  46. * @return HTML string
  47. */
  48. public function serviceEntityCreate ()
  49. {
  50. bx_import('FormsEntryHelper', $this->_aModule);
  51. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  52. $oFormsHelper = new $sClass($this);
  53. return $oFormsHelper->addDataForm();
  54. }
  55. public function serviceEntityEdit ($iContentId = 0)
  56. {
  57. return $this->_serviceEntityForm ('editDataForm', $iContentId);
  58. }
  59. public function serviceEntityDelete ($iContentId = 0)
  60. {
  61. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  62. }
  63. public function serviceEntityInfo ($iContentId = 0)
  64. {
  65. return $this->_serviceEntityForm ('viewDataForm', $iContentId);
  66. }
  67. /**
  68. * Entry actions block
  69. */
  70. public function serviceEntityActions ($iContentId = 0)
  71. {
  72. if (!$iContentId)
  73. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  74. if (!$iContentId)
  75. return false;
  76. bx_import('BxTemplMenu');
  77. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  78. return $oMenu ? $oMenu->getCode() : false;
  79. }
  80. // ====== PERMISSION METHODS
  81. /**
  82. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  83. */
  84. public function checkAllowedBrowse ()
  85. {
  86. return CHECK_ACTION_RESULT_ALLOWED;
  87. }
  88. /**
  89. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  90. */
  91. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  92. {
  93. $CNF = &$this->_oConfig->CNF;
  94. // moderator and owner always have access
  95. if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  96. return CHECK_ACTION_RESULT_ALLOWED;
  97. // check ACL
  98. $aCheck = checkActionModule($this->_iProfileId, 'view entry', $this->getName(), $isPerformAction);
  99. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  100. return $aCheck[CHECK_ACTION_MESSAGE];
  101. // check privacy
  102. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  103. bx_import('BxDolPrivacy');
  104. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  105. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]))
  106. return _t('_sys_access_denied_to_private_content');
  107. }
  108. return CHECK_ACTION_RESULT_ALLOWED;
  109. }
  110. /**
  111. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  112. */
  113. public function checkAllowedAdd ($isPerformAction = false)
  114. {
  115. // check ACL
  116. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  117. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  118. return $aCheck[CHECK_ACTION_MESSAGE];
  119. return CHECK_ACTION_RESULT_ALLOWED;
  120. }
  121. /**
  122. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  123. */
  124. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  125. {
  126. // moderator and owner always have access
  127. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  128. return CHECK_ACTION_RESULT_ALLOWED;
  129. return _t('_sys_txt_access_denied');
  130. }
  131. /**
  132. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  133. */
  134. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  135. {
  136. // moderator always has access
  137. if ($this->_isModerator($isPerformAction))
  138. return CHECK_ACTION_RESULT_ALLOWED;
  139. // check ACL
  140. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  141. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  142. return CHECK_ACTION_RESULT_ALLOWED;
  143. return _t('_sys_txt_access_denied');
  144. }
  145. // ====== PROTECTED METHODS
  146. protected function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false)
  147. {
  148. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  149. return MsgBox($sMsg);
  150. bx_import('SearchResult', $this->_aModule);
  151. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  152. $o = new $sClass($sMode, $aParams);
  153. $o->setDesignBoxTemplateId($iDesignBox);
  154. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  155. if ($o->isError)
  156. return '';
  157. if ($s = $o->processing())
  158. return $s;
  159. else
  160. return '';
  161. }
  162. protected function _isModerator ($isPerformAction = false)
  163. {
  164. // check moderator ACL
  165. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  166. return $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
  167. }
  168. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false)
  169. {
  170. if (!$iContentId)
  171. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  172. if (!$iContentId)
  173. return false;
  174. bx_import('FormsEntryHelper', $this->_aModule);
  175. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  176. $oFormsHelper = new $sClass($this);
  177. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay);
  178. }
  179. protected function _serviceTemplateFunc ($sFunc, $iContentId)
  180. {
  181. if (!$iContentId)
  182. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  183. if (!$iContentId)
  184. return false;
  185. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  186. if (!$aContentInfo)
  187. return false;
  188. return $this->_oTemplate->$sFunc($aContentInfo);
  189. }
  190. }
  191. /** @} */