BxBaseModGeneralModule.php 10 KB

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