1
0

BxBaseModGeneralModule.php 11 KB

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