1
0

BxBaseModGeneralModule.php 11 KB

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