1
0

BxBaseModGeneralModule.php 12 KB

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