1
0

BxBaseModGeneralModule.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. * Delete content entry
  119. * @param $iContentId content id
  120. * @return error message or empty string on success
  121. */
  122. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  123. {
  124. bx_import('FormsEntryHelper', $this->_aModule);
  125. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  126. $oFormsHelper = new $sClass($this);
  127. return $oFormsHelper->$sFuncDelete($iContentId);
  128. }
  129. /**
  130. * Entry actions block
  131. */
  132. public function serviceEntityActions ($iContentId = 0)
  133. {
  134. if (!$iContentId)
  135. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  136. if (!$iContentId)
  137. return false;
  138. bx_import('BxTemplMenu');
  139. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  140. return $oMenu ? $oMenu->getCode() : false;
  141. }
  142. // ====== PERMISSION METHODS
  143. /**
  144. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  145. */
  146. public function checkAllowedBrowse ()
  147. {
  148. return CHECK_ACTION_RESULT_ALLOWED;
  149. }
  150. /**
  151. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  152. */
  153. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  154. {
  155. $CNF = &$this->_oConfig->CNF;
  156. // moderator and owner always have access
  157. if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  158. return CHECK_ACTION_RESULT_ALLOWED;
  159. // check ACL
  160. $aCheck = checkActionModule($this->_iProfileId, 'view entry', $this->getName(), $isPerformAction);
  161. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  162. return $aCheck[CHECK_ACTION_MESSAGE];
  163. // check privacy
  164. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  165. bx_import('BxDolPrivacy');
  166. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  167. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]))
  168. return _t('_sys_access_denied_to_private_content');
  169. }
  170. return CHECK_ACTION_RESULT_ALLOWED;
  171. }
  172. /**
  173. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  174. */
  175. public function checkAllowedAdd ($isPerformAction = false)
  176. {
  177. // check ACL
  178. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  179. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  180. return $aCheck[CHECK_ACTION_MESSAGE];
  181. return CHECK_ACTION_RESULT_ALLOWED;
  182. }
  183. /**
  184. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  185. */
  186. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  187. {
  188. // moderator and owner always have access
  189. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  190. return CHECK_ACTION_RESULT_ALLOWED;
  191. return _t('_sys_txt_access_denied');
  192. }
  193. /**
  194. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  195. */
  196. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  197. {
  198. // moderator always has access
  199. if ($this->_isModerator($isPerformAction))
  200. return CHECK_ACTION_RESULT_ALLOWED;
  201. // check ACL
  202. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  203. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  204. return CHECK_ACTION_RESULT_ALLOWED;
  205. return _t('_sys_txt_access_denied');
  206. }
  207. /**
  208. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  209. */
  210. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  211. {
  212. // admin always has access
  213. if (isAdmin($this->_iProfileId))
  214. return CHECK_ACTION_RESULT_ALLOWED;
  215. // check ACL
  216. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  217. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  218. return $aCheck[CHECK_ACTION_MESSAGE];
  219. return CHECK_ACTION_RESULT_ALLOWED;
  220. }
  221. // ====== PROTECTED METHODS
  222. protected function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  223. {
  224. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  225. return MsgBox($sMsg);
  226. bx_import($sClassSearchResult, $this->_aModule);
  227. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  228. $o = new $sClass($sMode, $aParams);
  229. $o->setDesignBoxTemplateId($iDesignBox);
  230. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  231. $o->setAjaxPaginate($bAjaxPaginate);
  232. $o->setUnitParams(array('context' => $sMode));
  233. if ($o->isError)
  234. return '';
  235. if ($s = $o->processing())
  236. return $s;
  237. else
  238. return '';
  239. }
  240. protected function _isModerator ($isPerformAction = false)
  241. {
  242. // check moderator ACL
  243. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  244. return $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
  245. }
  246. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false)
  247. {
  248. if (!$iContentId)
  249. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  250. if (!$iContentId)
  251. return false;
  252. bx_import('FormsEntryHelper', $this->_aModule);
  253. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  254. $oFormsHelper = new $sClass($this);
  255. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay);
  256. }
  257. protected function _serviceTemplateFunc ($sFunc, $iContentId)
  258. {
  259. if (!$iContentId)
  260. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  261. if (!$iContentId)
  262. return false;
  263. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  264. if (!$aContentInfo)
  265. return false;
  266. return $this->_oTemplate->$sFunc($aContentInfo);
  267. }
  268. }
  269. /** @} */