BxBaseModGeneralModule.php 11 KB

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