1
0

BxBaseModGeneralModule.php 11 KB

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