BxBaseModGeneralModule.php 8.9 KB

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