1
0

BxBaseModGeneralModule.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. public function serviceFormsHelper ()
  77. {
  78. bx_import('FormsEntryHelper', $this->_aModule);
  79. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  80. return new $sClass($this);
  81. }
  82. /**
  83. * Add entry form
  84. * @return HTML string
  85. */
  86. public function serviceEntityCreate ()
  87. {
  88. bx_import('FormsEntryHelper', $this->_aModule);
  89. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  90. $oFormsHelper = new $sClass($this);
  91. return $oFormsHelper->addDataForm();
  92. }
  93. public function serviceEntityEdit ($iContentId = 0)
  94. {
  95. return $this->_serviceEntityForm ('editDataForm', $iContentId);
  96. }
  97. public function serviceEntityDelete ($iContentId = 0)
  98. {
  99. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  100. }
  101. public function serviceEntityInfo ($iContentId = 0)
  102. {
  103. return $this->_serviceEntityForm ('viewDataForm', $iContentId);
  104. }
  105. /**
  106. * Delete content entry
  107. * @param $iContentId content id
  108. * @return error message or empty string on success
  109. */
  110. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  111. {
  112. bx_import('FormsEntryHelper', $this->_aModule);
  113. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  114. $oFormsHelper = new $sClass($this);
  115. return $oFormsHelper->$sFuncDelete($iContentId);
  116. }
  117. /**
  118. * Entry actions block
  119. */
  120. public function serviceEntityActions ($iContentId = 0)
  121. {
  122. if (!$iContentId)
  123. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  124. if (!$iContentId)
  125. return false;
  126. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  127. return $oMenu ? $oMenu->getCode() : false;
  128. }
  129. // ====== PERMISSION METHODS
  130. /**
  131. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  132. */
  133. public function checkAllowedBrowse ()
  134. {
  135. return CHECK_ACTION_RESULT_ALLOWED;
  136. }
  137. /**
  138. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  139. */
  140. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  141. {
  142. $CNF = &$this->_oConfig->CNF;
  143. // moderator and owner always have access
  144. if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  145. return CHECK_ACTION_RESULT_ALLOWED;
  146. // check ACL
  147. $aCheck = checkActionModule($this->_iProfileId, 'view entry', $this->getName(), $isPerformAction);
  148. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  149. return $aCheck[CHECK_ACTION_MESSAGE];
  150. // check privacy
  151. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  152. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  153. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]))
  154. return _t('_sys_access_denied_to_private_content');
  155. }
  156. return CHECK_ACTION_RESULT_ALLOWED;
  157. }
  158. /**
  159. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  160. */
  161. public function checkAllowedAdd ($isPerformAction = false)
  162. {
  163. // check ACL
  164. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  165. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  166. return $aCheck[CHECK_ACTION_MESSAGE];
  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 checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  173. {
  174. // moderator and owner always have access
  175. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  176. return CHECK_ACTION_RESULT_ALLOWED;
  177. return _t('_sys_txt_access_denied');
  178. }
  179. /**
  180. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  181. */
  182. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  183. {
  184. // moderator always has access
  185. if ($this->_isModerator($isPerformAction))
  186. return CHECK_ACTION_RESULT_ALLOWED;
  187. // check ACL
  188. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  189. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  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 checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  197. {
  198. // admin always has access
  199. if (isAdmin())
  200. return CHECK_ACTION_RESULT_ALLOWED;
  201. // check ACL
  202. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  203. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  204. return $aCheck[CHECK_ACTION_MESSAGE];
  205. return CHECK_ACTION_RESULT_ALLOWED;
  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 checkAllowedEditAnyEntry ($isPerformAction = false)
  211. {
  212. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  213. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  214. return CHECK_ACTION_RESULT_ALLOWED;
  215. return _t('_sys_txt_access_denied');
  216. }
  217. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  218. {
  219. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  220. return MsgBox($sMsg);
  221. bx_import($sClassSearchResult, $this->_aModule);
  222. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  223. $o = new $sClass($sMode, $aParams);
  224. $o->setDesignBoxTemplateId($iDesignBox);
  225. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  226. $o->setAjaxPaginate($bAjaxPaginate);
  227. $o->setUnitParams(array('context' => $sMode));
  228. if ($o->isError)
  229. return '';
  230. if ($s = $o->processing())
  231. return $s;
  232. else
  233. return '';
  234. }
  235. // ====== PROTECTED METHODS
  236. protected function _isModerator ($isPerformAction = false)
  237. {
  238. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
  239. }
  240. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false)
  241. {
  242. if (!$iContentId)
  243. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  244. if (!$iContentId)
  245. return false;
  246. bx_import('FormsEntryHelper', $this->_aModule);
  247. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  248. $oFormsHelper = new $sClass($this);
  249. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay);
  250. }
  251. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  252. {
  253. if (!$iContentId)
  254. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  255. if (!$iContentId)
  256. return false;
  257. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  258. if (!$aContentInfo)
  259. return false;
  260. return $this->_oTemplate->$sFunc($aContentInfo);
  261. }
  262. protected function _rss ($aArgs, $sClass = 'SearchResult')
  263. {
  264. $sMode = array_shift($aArgs);
  265. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  266. $this->_oTemplate->displayAccessDenied ($sMsg);
  267. exit;
  268. }
  269. $aParams = $this->_buildRssParams($sMode, $aArgs);
  270. bx_import ($sClass, $this->_aModule);
  271. $sClass = $this->_aModule['class_prefix'] . $sClass;
  272. $o = new $sClass($sMode, $aParams);
  273. if ($o->isError)
  274. $this->_oTemplate->displayPageNotFound ();
  275. else
  276. $o->outputRSS();
  277. exit;
  278. }
  279. }
  280. /** @} */