BxBaseModGeneralModule.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. public function serviceManageTools($sType)
  45. {
  46. bx_import('BxDolGrid');
  47. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
  48. if(!$oGrid)
  49. return '';
  50. $this->_oTemplate->addCss(array('manage_tools.css'));
  51. $this->_oTemplate->addJs(array('manage_tools.js'));
  52. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  53. return $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode();
  54. }
  55. /**
  56. * Add entry form
  57. * @return HTML string
  58. */
  59. public function serviceEntityCreate ()
  60. {
  61. bx_import('FormsEntryHelper', $this->_aModule);
  62. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  63. $oFormsHelper = new $sClass($this);
  64. return $oFormsHelper->addDataForm();
  65. }
  66. public function serviceEntityEdit ($iContentId = 0)
  67. {
  68. return $this->_serviceEntityForm ('editDataForm', $iContentId);
  69. }
  70. public function serviceEntityDelete ($iContentId = 0)
  71. {
  72. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  73. }
  74. public function serviceEntityInfo ($iContentId = 0)
  75. {
  76. return $this->_serviceEntityForm ('viewDataForm', $iContentId);
  77. }
  78. /**
  79. * Entry actions block
  80. */
  81. public function serviceEntityActions ($iContentId = 0)
  82. {
  83. if (!$iContentId)
  84. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  85. if (!$iContentId)
  86. return false;
  87. bx_import('BxTemplMenu');
  88. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  89. return $oMenu ? $oMenu->getCode() : false;
  90. }
  91. // ====== PERMISSION METHODS
  92. /**
  93. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  94. */
  95. public function checkAllowedBrowse ()
  96. {
  97. return CHECK_ACTION_RESULT_ALLOWED;
  98. }
  99. /**
  100. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  101. */
  102. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  103. {
  104. $CNF = &$this->_oConfig->CNF;
  105. // moderator and owner always have access
  106. if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  107. return CHECK_ACTION_RESULT_ALLOWED;
  108. // check ACL
  109. $aCheck = checkActionModule($this->_iProfileId, 'view entry', $this->getName(), $isPerformAction);
  110. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  111. return $aCheck[CHECK_ACTION_MESSAGE];
  112. // check privacy
  113. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  114. bx_import('BxDolPrivacy');
  115. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  116. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]))
  117. return _t('_sys_access_denied_to_private_content');
  118. }
  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 checkAllowedAdd ($isPerformAction = false)
  125. {
  126. // check ACL
  127. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  128. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  129. return $aCheck[CHECK_ACTION_MESSAGE];
  130. return CHECK_ACTION_RESULT_ALLOWED;
  131. }
  132. /**
  133. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  134. */
  135. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  136. {
  137. // moderator and owner always have access
  138. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  139. return CHECK_ACTION_RESULT_ALLOWED;
  140. return _t('_sys_txt_access_denied');
  141. }
  142. /**
  143. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  144. */
  145. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  146. {
  147. // moderator always has access
  148. if ($this->_isModerator($isPerformAction))
  149. return CHECK_ACTION_RESULT_ALLOWED;
  150. // check ACL
  151. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  152. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  153. return CHECK_ACTION_RESULT_ALLOWED;
  154. return _t('_sys_txt_access_denied');
  155. }
  156. /**
  157. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  158. */
  159. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  160. {
  161. // admin always has access
  162. if (isAdmin($this->_iProfileId))
  163. return CHECK_ACTION_RESULT_ALLOWED;
  164. // check ACL
  165. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  166. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  167. return $aCheck[CHECK_ACTION_MESSAGE];
  168. return CHECK_ACTION_RESULT_ALLOWED;
  169. }
  170. // ====== PROTECTED METHODS
  171. protected function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true)
  172. {
  173. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  174. return MsgBox($sMsg);
  175. bx_import('SearchResult', $this->_aModule);
  176. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  177. $o = new $sClass($sMode, $aParams);
  178. $o->setDesignBoxTemplateId($iDesignBox);
  179. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  180. $o->setAjaxPaginate($bAjaxPaginate);
  181. if ($o->isError)
  182. return '';
  183. if ($s = $o->processing())
  184. return $s;
  185. else
  186. return '';
  187. }
  188. protected function _isModerator ($isPerformAction = false)
  189. {
  190. // check moderator ACL
  191. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  192. return $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
  193. }
  194. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false)
  195. {
  196. if (!$iContentId)
  197. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  198. if (!$iContentId)
  199. return false;
  200. bx_import('FormsEntryHelper', $this->_aModule);
  201. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  202. $oFormsHelper = new $sClass($this);
  203. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay);
  204. }
  205. protected function _serviceTemplateFunc ($sFunc, $iContentId)
  206. {
  207. if (!$iContentId)
  208. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  209. if (!$iContentId)
  210. return false;
  211. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  212. if (!$aContentInfo)
  213. return false;
  214. return $this->_oTemplate->$sFunc($aContentInfo);
  215. }
  216. }
  217. /** @} */