1
0

BxBaseModGeneralModule.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 ($sMsg);
  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. /**
  146. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  147. */
  148. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  149. {
  150. // admin always has access
  151. if (isAdmin($this->_iProfileId))
  152. return CHECK_ACTION_RESULT_ALLOWED;
  153. // check ACL
  154. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  155. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  156. return $aCheck[CHECK_ACTION_MESSAGE];
  157. return CHECK_ACTION_RESULT_ALLOWED;
  158. }
  159. // ====== PROTECTED METHODS
  160. protected function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true)
  161. {
  162. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  163. return MsgBox($sMsg);
  164. bx_import('SearchResult', $this->_aModule);
  165. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  166. $o = new $sClass($sMode, $aParams);
  167. $o->setDesignBoxTemplateId($iDesignBox);
  168. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  169. $o->setAjaxPaginate($bAjaxPaginate);
  170. if ($o->isError)
  171. return '';
  172. if ($s = $o->processing())
  173. return $s;
  174. else
  175. return '';
  176. }
  177. protected function _isModerator ($isPerformAction = false)
  178. {
  179. // check moderator ACL
  180. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  181. return $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
  182. }
  183. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false)
  184. {
  185. if (!$iContentId)
  186. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  187. if (!$iContentId)
  188. return false;
  189. bx_import('FormsEntryHelper', $this->_aModule);
  190. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  191. $oFormsHelper = new $sClass($this);
  192. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay);
  193. }
  194. protected function _serviceTemplateFunc ($sFunc, $iContentId)
  195. {
  196. if (!$iContentId)
  197. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  198. if (!$iContentId)
  199. return false;
  200. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  201. if (!$aContentInfo)
  202. return false;
  203. return $this->_oTemplate->$sFunc($aContentInfo);
  204. }
  205. }
  206. /** @} */