1
0

BxBaseModGeneralFormsEntryHelper.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Entry forms helper functions
  13. */
  14. class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
  15. {
  16. protected $_oModule;
  17. /**
  18. * 'Ajax Mode' determines the format of response. If it's TRUE the response
  19. * (a form or an error appeared during form creation) should be returned
  20. * as text during initial loading, while all other responses appeared after
  21. * form submit should be arrays, which are ready to path to echoJson.
  22. */
  23. protected $_bAjaxMode;
  24. /**
  25. * Use absolute Action URL in generated form object.
  26. * It's needed in Ajax Mode.
  27. */
  28. protected $_bAbsoluteActionUrl;
  29. protected $_bDynamicMode;
  30. public function __construct($oModule)
  31. {
  32. parent::__construct();
  33. $this->_oModule = $oModule;
  34. $this->_bDynamicMode = false;
  35. $this->_bAjaxMode = false;
  36. $mixedAjaxMode = bx_get('ajax_mode');
  37. if($mixedAjaxMode !== false)
  38. $this->setAjaxMode($mixedAjaxMode);
  39. $this->_bAbsoluteActionUrl = false;
  40. $mixedAbsoluteActionUrl = bx_get('absolute_action_url');
  41. if($mixedAbsoluteActionUrl !== false)
  42. $this->setAbsoluteActionUrl($mixedAbsoluteActionUrl);
  43. }
  44. public function setAjaxMode($bAjaxMode)
  45. {
  46. $this->_bAjaxMode = (bool)$bAjaxMode;
  47. if($this->_bAjaxMode)
  48. $this->setDynamicMode(true);
  49. }
  50. public function setAbsoluteActionUrl($bAbsoluteActionUrl)
  51. {
  52. $this->_bAbsoluteActionUrl = (bool)$bAbsoluteActionUrl;
  53. }
  54. public function setDynamicMode($bDynamicMode)
  55. {
  56. $this->_bDynamicMode = (bool)$bDynamicMode;
  57. }
  58. public function getObjectStorage()
  59. {
  60. return BxDolStorage::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_STORAGE']);
  61. }
  62. public function getObjectFormAdd ($sDisplay = false)
  63. {
  64. $CNF = &$this->_oModule->_oConfig->CNF;
  65. if(false === $sDisplay)
  66. $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'];
  67. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
  68. if($this->_bAjaxMode)
  69. $oForm->setAjaxMode($this->_bAjaxMode);
  70. if($this->_bAbsoluteActionUrl)
  71. $this->_setAbsoluteActionUrl('add', $oForm);
  72. return $oForm;
  73. }
  74. public function getObjectFormEdit ($sDisplay = false)
  75. {
  76. $CNF = &$this->_oModule->_oConfig->CNF;
  77. if(false === $sDisplay)
  78. $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'];
  79. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
  80. if($this->_bAjaxMode)
  81. $oForm->setAjaxMode($this->_bAjaxMode);
  82. if($this->_bAbsoluteActionUrl)
  83. $this->_setAbsoluteActionUrl('edit', $oForm);
  84. return $oForm;
  85. }
  86. public function getObjectFormView ($sDisplay = false)
  87. {
  88. $CNF = &$this->_oModule->_oConfig->CNF;
  89. if (false === $sDisplay)
  90. $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW'];
  91. return BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
  92. }
  93. public function getObjectFormDelete ($sDisplay = false)
  94. {
  95. $CNF = &$this->_oModule->_oConfig->CNF;
  96. if (false === $sDisplay)
  97. $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_DELETE'];
  98. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
  99. if($this->_bAjaxMode)
  100. $oForm->setAjaxMode($this->_bAjaxMode);
  101. if($this->_bAbsoluteActionUrl)
  102. $this->_setAbsoluteActionUrl('delete', $oForm);
  103. return $oForm;
  104. }
  105. public function viewDataEntry ($iContentId)
  106. {
  107. // get content data and profile info
  108. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  109. if (!$aContentInfo)
  110. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  111. // check access
  112. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
  113. return MsgBox($sMsg);
  114. return $this->_oModule->_oTemplate->entryText($aContentInfo);
  115. }
  116. public function addData ($iProfile, $aValues, $sDisplay = false)
  117. {
  118. $CNF = &$this->_oModule->_oConfig->CNF;
  119. // check and display form
  120. $oForm = $this->getObjectFormAdd($sDisplay);
  121. if (!$oForm)
  122. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  123. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  124. $oForm->aParams['csrf']['disable'] = true;
  125. if(!empty($oForm->aParams['db']['submit_name'])) {
  126. $sSubmitName = false;
  127. if (is_array($oForm->aParams['db']['submit_name'])) {
  128. foreach ($oForm->aParams['db']['submit_name'] as $sVal) {
  129. if (isset($oForm->aInputs[$sVal])) {
  130. $sSubmitName = $sVal;
  131. break;
  132. }
  133. }
  134. }
  135. else {
  136. $sSubmitName = $oForm->aParams['db']['submit_name'];
  137. }
  138. if ($sSubmitName && isset($oForm->aInputs[$sSubmitName]))
  139. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  140. }
  141. $oForm->initChecker(array(), $aValues);
  142. if (!$oForm->isSubmittedAndValid())
  143. return array('code' => 2, 'message' => '_sys_txt_error_occured');
  144. // insert data into database
  145. $aValsToAdd = array ();
  146. if(isset($CNF['FIELD_AUTHOR']))
  147. $aValsToAdd[$CNF['FIELD_AUTHOR']] = $iProfile;
  148. $iContentId = $oForm->insert($aValsToAdd);
  149. if (!$iContentId) {
  150. if (!$oForm->isValid())
  151. return array('code' => 2, 'message' => '_sys_txt_error_occured');
  152. else
  153. return array('code' => 3, 'message' => '_sys_txt_error_entry_creation');
  154. }
  155. $sResult = $this->onDataAddAfter(BxDolProfile::getInstance($iProfile)->getAccountId(), $iContentId);
  156. if($sResult)
  157. return array('code' => 4, 'message' => $sResult);
  158. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  159. /*
  160. * Process metas.
  161. * Note. It's essential to process metas a the very end,
  162. * because all data related to an entry should be already
  163. * processed and are ready to be passed to alert.
  164. */
  165. $this->_oModule->processMetasAdd($iContentId);
  166. /*
  167. * Create alert about the completed action.
  168. */
  169. $this->_oModule->alertAfterAdd($aContentInfo);
  170. return array('code' => 0, 'message' => '', 'content' => $aContentInfo);
  171. }
  172. public function addDataForm ($sDisplay = false, $sCheckFunction = false)
  173. {
  174. if (!$sCheckFunction)
  175. $sCheckFunction = 'checkAllowedAdd';
  176. $CNF = &$this->_oModule->_oConfig->CNF;
  177. $bAsJson = false;
  178. // get form object
  179. $oForm = $this->getObjectFormAdd($sDisplay);
  180. if (!$oForm)
  181. return $this->prepareResponse(MsgBox(_t('_sys_txt_error_occured')), $bAsJson, 'msg');
  182. $bAsJson = $this->_bAjaxMode && $oForm->isSubmitted();
  183. // check access
  184. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->$sCheckFunction())) {
  185. $oProfile = BxDolProfile::getInstance();
  186. if ($oProfile && ($aProfileInfo = $oProfile->getInfo()) && $aProfileInfo['type'] == 'system' && is_subclass_of($this->_oModule, 'BxBaseModProfileModule') && $this->_oModule->serviceActAsProfile()) // special check for system profile is needed, because of incorrect error message
  187. return $this->prepareResponse(MsgBox(_t('_sys_txt_access_denied')), $bAsJson, 'msg');
  188. else
  189. return $this->prepareResponse(MsgBox($sMsg), $bAsJson, 'msg');
  190. }
  191. // check and display form
  192. $oForm->initChecker();
  193. if (!$oForm->isSubmittedAndValid())
  194. return $this->prepareResponse($oForm->getCode($this->_bDynamicMode), $bAsJson, 'form', array(
  195. 'form_id' => $oForm->getId()
  196. ));
  197. // insert data into database
  198. $aValsToAdd = array ();
  199. $iContentId = $oForm->insert ($aValsToAdd);
  200. if (!$iContentId) {
  201. if (!$oForm->isValid())
  202. return $this->prepareResponse($oForm->getCode($this->_bDynamicMode), $bAsJson, 'form', array(
  203. 'form_id' => $oForm->getId()
  204. ));
  205. else
  206. return $this->prepareResponse(MsgBox(_t('_sys_txt_error_entry_creation')), $bAsJson, 'msg');
  207. }
  208. $sResult = $this->onDataAddAfter (getLoggedId(), $iContentId);
  209. if ($sResult)
  210. return $this->prepareResponse($sResult, $bAsJson, 'msg');
  211. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  212. /*
  213. * Process metas.
  214. * Note. It's essential to process metas a the very end,
  215. * because all data related to an entry should be already
  216. * processed and are ready to be passed to alert.
  217. */
  218. $this->_oModule->processMetasAdd($iContentId);
  219. // Perform ACL action
  220. $this->_oModule->$sCheckFunction(true);
  221. // Create alert about the completed action.
  222. $this->_oModule->alertAfterAdd($aContentInfo);
  223. // Redirect
  224. $this->redirectAfterAdd($aContentInfo);
  225. }
  226. public function redirectAfterAdd($aContentInfo)
  227. {
  228. $CNF = &$this->_oModule->_oConfig->CNF;
  229. $sUrl = 'page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']];
  230. if($this->_bAjaxMode) {
  231. echoJson($this->prepareResponse($sUrl, $this->_bAjaxMode, 'redirect'));
  232. exit;
  233. }
  234. else
  235. $this->_redirectAndExit($sUrl);
  236. }
  237. public function editDataForm ($iContentId, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  238. {
  239. if (!$sCheckFunction)
  240. $sCheckFunction = 'checkAllowedEdit';
  241. $CNF = &$this->_oModule->_oConfig->CNF;
  242. // get content data and profile info
  243. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  244. if (!$aContentInfo)
  245. return $bErrorMsg ? MsgBox(_t('_sys_txt_error_entry_is_not_defined')) : '';
  246. // check access
  247. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->$sCheckFunction($aContentInfo)))
  248. return $bErrorMsg ? MsgBox($sMsg) : '';
  249. // check and display form
  250. $oForm = $this->getObjectFormEdit($sDisplay);
  251. if (!$oForm)
  252. return $bErrorMsg ? MsgBox(_t('_sys_txt_error_occured')) : '';
  253. $aSpecificValues = array();
  254. if (!empty($CNF['OBJECT_METATAGS'])) {
  255. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  256. if ($oMetatags->locationsIsEnabled())
  257. $aSpecificValues = $oMetatags->locationGet($iContentId, empty($CNF['FIELD_LOCATION_PREFIX']) ? '' : $CNF['FIELD_LOCATION_PREFIX']);
  258. }
  259. $oForm->initChecker($aContentInfo, $aSpecificValues);
  260. if (!$oForm->isSubmittedAndValid())
  261. return $oForm->getCode();
  262. // update data in the DB
  263. $aTrackTextFieldsChanges = null;
  264. $this->onDataEditBefore ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm);
  265. if (!$oForm->update ($aContentInfo[$CNF['FIELD_ID']], array(), $aTrackTextFieldsChanges)) {
  266. if (!$oForm->isValid())
  267. return $oForm->getCode();
  268. else
  269. return MsgBox(_t('_sys_txt_error_entry_update'));
  270. }
  271. $sResult = $this->onDataEditAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm);
  272. if ($sResult)
  273. return $sResult;
  274. /*
  275. * Process metas.
  276. * Note. It's essential to process metas a the very end,
  277. * because all data related to an entry should be already
  278. * processed and are ready to be passed to alert.
  279. */
  280. $this->_oModule->processMetasEdit($iContentId, $oForm);
  281. // Perform ACL action
  282. $this->_oModule->$sCheckFunction($aContentInfo, true);
  283. // Create alert about the completed action.
  284. $this->_oModule->alertAfterEdit($aContentInfo);
  285. // Redirect
  286. $this->redirectAfterEdit($aContentInfo);
  287. }
  288. protected function redirectAfterEdit($aContentInfo)
  289. {
  290. $CNF = &$this->_oModule->_oConfig->CNF;
  291. $this->_redirectAndExit('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  292. }
  293. public function deleteDataForm ($iContentId, $sDisplay = false, $sCheckFunction = false)
  294. {
  295. if (!$sCheckFunction)
  296. $sCheckFunction = 'checkAllowedDelete';
  297. $CNF = &$this->_oModule->_oConfig->CNF;
  298. // get content data and profile info
  299. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  300. if (!$aContentInfo)
  301. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  302. // check access
  303. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->$sCheckFunction($aContentInfo)))
  304. return MsgBox($sMsg);
  305. // check and display form
  306. $oForm = $this->getObjectFormDelete($sDisplay);
  307. if (!$oForm)
  308. return MsgBox(_t('_sys_txt_error_occured'));
  309. $oForm->initChecker($aContentInfo);
  310. if (!$oForm->isSubmittedAndValid())
  311. return $oForm->getCode();
  312. if ($sError = $this->deleteData($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $oProfile, $oForm))
  313. return MsgBox($sError);
  314. // perform action
  315. $this->_oModule->$sCheckFunction($aContentInfo, true);
  316. // redirect
  317. $this->redirectAfterDelete($aContentInfo);
  318. }
  319. protected function redirectAfterDelete($aContentInfo)
  320. {
  321. $CNF = &$this->_oModule->_oConfig->CNF;
  322. $this->_redirectAndExit($CNF['URL_HOME'], true, array(
  323. 'account_id' => getLoggedId(),
  324. 'profile_id' => bx_get_logged_profile_id(),
  325. ));
  326. }
  327. /**
  328. * Delete data entry
  329. * @param $iContentId entry id
  330. * @param $oForm optional content info array
  331. * @param $aContentInfo optional content info array
  332. * @param $oProfile optional content author profile
  333. * @return error string on error or empty string on success
  334. */
  335. public function deleteData ($iContentId, $aContentInfo = false, $oProfile = null, $oForm = null)
  336. {
  337. $CNF = &$this->_oModule->_oConfig->CNF;
  338. if (!$aContentInfo || !$oProfile)
  339. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  340. if (!$aContentInfo)
  341. return _t('_sys_txt_error_entry_is_not_defined');
  342. if (!$oForm)
  343. $oForm = $this->getObjectFormDelete();
  344. if (!$oForm->delete ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo))
  345. return _t('_sys_txt_error_entry_delete');
  346. if ($sResult = $this->onDataDeleteAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $oProfile))
  347. return $sResult;
  348. // create an alert
  349. bx_alert($this->_oModule->getName(), 'deleted', $aContentInfo[$CNF['FIELD_ID']]);
  350. return '';
  351. }
  352. public function viewDataForm ($iContentId, $sDisplay = false)
  353. {
  354. $CNF = &$this->_oModule->_oConfig->CNF;
  355. // get content data and profile info
  356. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  357. if (!$aContentInfo)
  358. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  359. // check access
  360. if ($sMsg = $this->_processPermissionsCheckForViewDataForm ($aContentInfo, $oProfile))
  361. return MsgBox($sMsg);
  362. // get form
  363. $oForm = $this->getObjectFormView($sDisplay);
  364. if (!$oForm)
  365. return MsgBox(_t('_sys_txt_error_occured'));
  366. // process metatags
  367. if (!empty($CNF['OBJECT_METATAGS'])) {
  368. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  369. if ($oMetatags->keywordsIsEnabled()) {
  370. $aFields = $oMetatags->metaFields($aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW']);
  371. $oForm->setMetatagsKeywordsData($iContentId, $aFields, $oMetatags);
  372. }
  373. }
  374. // display profile
  375. $oForm->initChecker($aContentInfo);
  376. return $oForm->getCode();
  377. }
  378. protected function _processPermissionsCheckForViewDataForm ($aContentInfo, $oProfile)
  379. {
  380. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
  381. return $sMsg;
  382. return '';
  383. }
  384. public function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
  385. {
  386. $CNF = &$this->_oModule->_oConfig->CNF;
  387. if(($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  388. $oPrivacy->deleteGroupCustomByContentId($iContentId);
  389. bx_audit(
  390. $iContentId,
  391. $this->_oModule->getName(),
  392. '_sys_audit_action_detete',
  393. $this->_prepareAuditParams($aContentInfo)
  394. );
  395. return '';
  396. }
  397. public function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges, &$oProfile, &$oForm)
  398. {
  399. $CNF = &$this->_oModule->_oConfig->CNF;
  400. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == 'failed')
  401. $oForm->addTrackFields($CNF['FIELD_STATUS'], $aContentInfo);
  402. }
  403. public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm)
  404. {
  405. $CNF = &$this->_oModule->_oConfig->CNF;
  406. /*
  407. * Load update data.
  408. */
  409. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  410. if(isset($CNF['FIELD_PHOTO']))
  411. $oForm->processFiles ($CNF['FIELD_PHOTO'], $iContentId, false);
  412. if(isset($CNF['FIELD_STATUS']) && ($aTrackResult = $oForm->isTrackFieldChanged($CNF['FIELD_STATUS'], true)) !== false)
  413. if($aTrackResult['old'] == 'failed' && $aTrackResult['new'] == 'active')
  414. $this->_oModule->alertAfterAdd($aContentInfo);
  415. if(isset($CNF['FIELD_ALLOW_VIEW_TO']) && !empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  416. $oPrivacy->reassociateGroupCustomWithContent($oProfile->id(), $iContentId, (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  417. bx_audit(
  418. $iContentId,
  419. $this->_oModule->getName(),
  420. '_sys_audit_action_edit',
  421. $this->_prepareAuditParams($aContentInfo)
  422. );
  423. return '';
  424. }
  425. public function onDataAddAfter ($iAccountId, $iContentId)
  426. {
  427. $CNF = &$this->_oModule->_oConfig->CNF;
  428. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  429. if(($oForm = $this->getObjectFormAdd()) !== false) {
  430. if(isset($CNF['FIELD_PHOTO']))
  431. $oForm->processFiles($CNF['FIELD_PHOTO'], $iContentId, true);
  432. }
  433. if(isset($CNF['FIELD_ALLOW_VIEW_TO']) && !empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  434. $oPrivacy->associateGroupCustomWithContent($oProfile->id(), $iContentId, (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  435. bx_audit(
  436. $iContentId,
  437. $this->_oModule->getName(),
  438. '_sys_audit_action_add',
  439. $this->_prepareAuditParams($aContentInfo)
  440. );
  441. return '';
  442. }
  443. protected function prepareCustomRedirectUrl($s, $aContentInfo)
  444. {
  445. $CNF = &$this->_oModule->_oConfig->CNF;
  446. $oProfile = BxDolProfile::getInstanceByContentAndType($aContentInfo[$CNF['FIELD_ID']], $this->_oModule->getName());
  447. $aMarkers = array(
  448. '{profile_id}',
  449. '{content_id}',
  450. '{module}',
  451. );
  452. $aReplacements = array(
  453. $oProfile ? $oProfile->id() : 0,
  454. $aContentInfo[$CNF['FIELD_ID']],
  455. $this->_oModule->getName(),
  456. );
  457. $s = str_replace($aMarkers, $aReplacements, $s);
  458. $s = BxDolPermalinks::getInstance()->permalink($s);
  459. if (false === strpos($s, 'http://') && false === strpos($s, 'https://'))
  460. $s = BX_DOL_URL_ROOT . $s;
  461. return $s;
  462. }
  463. private function _prepareAuditParams($aContentInfo)
  464. {
  465. $CNF = &$this->_oModule->_oConfig->CNF;
  466. $iContextId = isset($CNF['FIELD_ALLOW_VIEW_TO']) && (!empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) ? - $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] : 0;
  467. $AuditParams = array(
  468. 'content_title' => isset($CNF['FIELD_TITLE']) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  469. 'context_profile_id' => $iContextId,
  470. 'content_info_object' => isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
  471. 'data' => $aContentInfo
  472. );
  473. if ($iContextId > 0)
  474. $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
  475. return $AuditParams;
  476. }
  477. protected function prepareResponse($mixedResponse, $bAsJson = false, $sKey = 'msg', $aAdditional = array())
  478. {
  479. if(!$bAsJson)
  480. return $mixedResponse;
  481. $aResponse = array(
  482. $sKey => $mixedResponse,
  483. '_dt' => 'json'
  484. );
  485. if(!empty($aAdditional) && is_array($aAdditional))
  486. $aResponse = array_merge($aResponse, $aAdditional);
  487. return $aResponse;
  488. }
  489. protected function _setAbsoluteActionUrl($sType, &$oForm)
  490. {
  491. $CNF = &$this->_oModule->_oConfig->CNF;
  492. $sKeyUri = 'URI_' . strtoupper($sType) . '_ENTRY';
  493. if(empty($CNF[$sKeyUri]))
  494. return;
  495. $oForm->setAbsoluteActionUrl(BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF[$sKeyUri]));
  496. }
  497. }
  498. /** @} */