BxBaseModGeneralModule.php 11 KB

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