BxBaseModGeneralFormsEntryHelper.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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. $CNF = &$this->_oModule->_oConfig->CNF;
  108. // get content data and profile info
  109. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  110. if (!$aContentInfo)
  111. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  112. // check access
  113. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
  114. return MsgBox($sMsg);
  115. $oForm = $this->getObjectFormView();
  116. $oForm->initChecker($aContentInfo);
  117. if(!empty($CNF['FIELD_TEXT']) && !$oForm->isInputVisible($CNF['FIELD_TEXT']))
  118. return '';
  119. return $this->_oModule->_oTemplate->entryText($aContentInfo);
  120. }
  121. public function addData ($iProfile, $aValues, $sDisplay = false)
  122. {
  123. $CNF = &$this->_oModule->_oConfig->CNF;
  124. // check and display form
  125. $oForm = $this->getObjectFormAdd($sDisplay);
  126. if (!$oForm)
  127. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  128. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  129. $oForm->aParams['csrf']['disable'] = true;
  130. if(!empty($oForm->aParams['db']['submit_name'])) {
  131. $sSubmitName = false;
  132. if (is_array($oForm->aParams['db']['submit_name'])) {
  133. foreach ($oForm->aParams['db']['submit_name'] as $sVal) {
  134. if (isset($oForm->aInputs[$sVal])) {
  135. $sSubmitName = $sVal;
  136. break;
  137. }
  138. }
  139. }
  140. else {
  141. $sSubmitName = $oForm->aParams['db']['submit_name'];
  142. }
  143. if ($sSubmitName && isset($oForm->aInputs[$sSubmitName]))
  144. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  145. }
  146. $oForm->initChecker(array(), $aValues);
  147. if (!$oForm->isSubmittedAndValid())
  148. return array('code' => 2, 'message' => '_sys_txt_error_occured');
  149. // insert data into database
  150. $aValsToAdd = array ();
  151. if(isset($CNF['FIELD_AUTHOR']))
  152. $aValsToAdd[$CNF['FIELD_AUTHOR']] = $iProfile;
  153. $iContentId = $oForm->insert($aValsToAdd);
  154. if (!$iContentId) {
  155. if (!$oForm->isValid())
  156. return array('code' => 2, 'message' => '_sys_txt_error_occured');
  157. else
  158. return array('code' => 3, 'message' => '_sys_txt_error_entry_creation');
  159. }
  160. $sResult = $this->onDataAddAfter(BxDolProfile::getInstance($iProfile)->getAccountId(), $iContentId);
  161. if($sResult)
  162. return array('code' => 4, 'message' => $sResult);
  163. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  164. /*
  165. * Process metas.
  166. * Note. It's essential to process metas a the very end,
  167. * because all data related to an entry should be already
  168. * processed and are ready to be passed to alert.
  169. */
  170. $this->_oModule->processMetasAdd($iContentId);
  171. /*
  172. * Create alert about the completed action.
  173. */
  174. $this->_oModule->alertAfterAdd($aContentInfo);
  175. return array('code' => 0, 'message' => '', 'content' => $aContentInfo);
  176. }
  177. public function addDataForm ($sDisplay = false, $sCheckFunction = false)
  178. {
  179. if (!$sCheckFunction)
  180. $sCheckFunction = 'checkAllowedAdd';
  181. $CNF = &$this->_oModule->_oConfig->CNF;
  182. $bAsJson = false;
  183. // get form object
  184. $oForm = $this->getObjectFormAdd($sDisplay);
  185. if (!$oForm)
  186. return $this->prepareResponse(MsgBox(_t('_sys_txt_error_occured')), $bAsJson, 'msg');
  187. $bAsJson = $this->_bAjaxMode && $oForm->isSubmitted();
  188. // check access
  189. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->$sCheckFunction())) {
  190. $oProfile = BxDolProfile::getInstance();
  191. 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
  192. return $this->prepareResponse(MsgBox(_t('_sys_txt_access_denied')), $bAsJson, 'msg');
  193. else
  194. return $this->prepareResponse(MsgBox($sMsg), $bAsJson, 'msg');
  195. }
  196. // check and display form
  197. $oForm->initChecker();
  198. if (!$oForm->isSubmittedAndValid())
  199. return $this->prepareResponse($oForm->getCode($this->_bDynamicMode), $bAsJson, 'form', array(
  200. 'form_id' => $oForm->getId()
  201. ));
  202. // insert data into database
  203. $aValsToAdd = array ();
  204. $iContentId = $oForm->insert ($aValsToAdd);
  205. if (!$iContentId) {
  206. if (!$oForm->isValid())
  207. return $this->prepareResponse($oForm->getCode($this->_bDynamicMode), $bAsJson, 'form', array(
  208. 'form_id' => $oForm->getId()
  209. ));
  210. else
  211. return $this->prepareResponse(MsgBox(_t('_sys_txt_error_entry_creation')), $bAsJson, 'msg');
  212. }
  213. $sResult = $this->onDataAddAfter (getLoggedId(), $iContentId);
  214. if ($sResult)
  215. return $this->prepareResponse($sResult, $bAsJson, 'msg');
  216. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  217. /*
  218. * Process metas.
  219. * Note. It's essential to process metas a the very end,
  220. * because all data related to an entry should be already
  221. * processed and are ready to be passed to alert.
  222. */
  223. $this->_oModule->processMetasAdd($iContentId);
  224. // Perform ACL action
  225. $this->_oModule->$sCheckFunction(true);
  226. // Create alert about the completed action.
  227. $this->_oModule->alertAfterAdd($aContentInfo);
  228. // Redirect
  229. $this->redirectAfterAdd($aContentInfo);
  230. }
  231. public function redirectAfterAdd($aContentInfo)
  232. {
  233. $CNF = &$this->_oModule->_oConfig->CNF;
  234. $sUrl = 'page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']];
  235. if($this->_bAjaxMode) {
  236. echoJson($this->prepareResponse($sUrl, $this->_bAjaxMode, 'redirect'));
  237. exit;
  238. }
  239. else
  240. $this->_redirectAndExit($sUrl);
  241. }
  242. public function editDataForm ($iContentId, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  243. {
  244. if (!$sCheckFunction)
  245. $sCheckFunction = 'checkAllowedEdit';
  246. $CNF = &$this->_oModule->_oConfig->CNF;
  247. // get content data and profile info
  248. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  249. if (!$aContentInfo)
  250. return $bErrorMsg ? MsgBox(_t('_sys_txt_error_entry_is_not_defined')) : '';
  251. // check access
  252. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->$sCheckFunction($aContentInfo)))
  253. return $bErrorMsg ? MsgBox($sMsg) : '';
  254. // check and display form
  255. $oForm = $this->getObjectFormEdit($sDisplay);
  256. if (!$oForm)
  257. return $bErrorMsg ? MsgBox(_t('_sys_txt_error_occured')) : '';
  258. $aSpecificValues = array();
  259. if (!empty($CNF['OBJECT_METATAGS'])) {
  260. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  261. if ($oMetatags->locationsIsEnabled())
  262. $aSpecificValues = $oMetatags->locationGet($iContentId, empty($CNF['FIELD_LOCATION_PREFIX']) ? '' : $CNF['FIELD_LOCATION_PREFIX']);
  263. }
  264. $oForm->initChecker($aContentInfo, $aSpecificValues);
  265. if (!$oForm->isSubmittedAndValid())
  266. return $oForm->getCode();
  267. // update data in the DB
  268. $aTrackTextFieldsChanges = null;
  269. $this->onDataEditBefore ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm);
  270. if (!$oForm->update ($aContentInfo[$CNF['FIELD_ID']], array(), $aTrackTextFieldsChanges)) {
  271. if (!$oForm->isValid())
  272. return $oForm->getCode();
  273. else
  274. return MsgBox(_t('_sys_txt_error_entry_update'));
  275. }
  276. $sResult = $this->onDataEditAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm);
  277. if ($sResult)
  278. return $sResult;
  279. /*
  280. * Process metas.
  281. * Note. It's essential to process metas a the very end,
  282. * because all data related to an entry should be already
  283. * processed and are ready to be passed to alert.
  284. */
  285. $this->_oModule->processMetasEdit($iContentId, $oForm);
  286. // Perform ACL action
  287. $this->_oModule->$sCheckFunction($aContentInfo, true);
  288. // Create alert about the completed action.
  289. $this->_oModule->alertAfterEdit($aContentInfo);
  290. // Redirect
  291. $this->redirectAfterEdit($aContentInfo);
  292. }
  293. protected function redirectAfterEdit($aContentInfo)
  294. {
  295. $CNF = &$this->_oModule->_oConfig->CNF;
  296. $this->_redirectAndExit('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  297. }
  298. public function deleteDataForm ($iContentId, $sDisplay = false, $sCheckFunction = false)
  299. {
  300. if (!$sCheckFunction)
  301. $sCheckFunction = 'checkAllowedDelete';
  302. $CNF = &$this->_oModule->_oConfig->CNF;
  303. // get content data and profile info
  304. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  305. if (!$aContentInfo)
  306. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  307. // check access
  308. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->$sCheckFunction($aContentInfo)))
  309. return MsgBox($sMsg);
  310. // check and display form
  311. $oForm = $this->getObjectFormDelete($sDisplay);
  312. if (!$oForm)
  313. return MsgBox(_t('_sys_txt_error_occured'));
  314. $oForm->initChecker($aContentInfo);
  315. if (!$oForm->isSubmittedAndValid())
  316. return $oForm->getCode();
  317. if ($sError = $this->deleteData($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $oProfile, $oForm))
  318. return MsgBox($sError);
  319. // perform action
  320. $this->_oModule->$sCheckFunction($aContentInfo, true);
  321. // redirect
  322. $this->redirectAfterDelete($aContentInfo);
  323. }
  324. protected function redirectAfterDelete($aContentInfo)
  325. {
  326. $CNF = &$this->_oModule->_oConfig->CNF;
  327. $this->_redirectAndExit($CNF['URL_HOME'], true, array(
  328. 'account_id' => getLoggedId(),
  329. 'profile_id' => bx_get_logged_profile_id(),
  330. ));
  331. }
  332. /**
  333. * Delete data entry
  334. * @param $iContentId entry id
  335. * @param $oForm optional content info array
  336. * @param $aContentInfo optional content info array
  337. * @param $oProfile optional content author profile
  338. * @return error string on error or empty string on success
  339. */
  340. public function deleteData ($iContentId, $aContentInfo = false, $oProfile = null, $oForm = null)
  341. {
  342. $CNF = &$this->_oModule->_oConfig->CNF;
  343. if (!$aContentInfo || !$oProfile)
  344. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  345. if (!$aContentInfo)
  346. return _t('_sys_txt_error_entry_is_not_defined');
  347. if (!$oForm)
  348. $oForm = $this->getObjectFormDelete();
  349. if (!$oForm->delete ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo))
  350. return _t('_sys_txt_error_entry_delete');
  351. if ($sResult = $this->onDataDeleteAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $oProfile))
  352. return $sResult;
  353. // create an alert
  354. bx_alert($this->_oModule->getName(), 'deleted', $aContentInfo[$CNF['FIELD_ID']], false, array(
  355. 'content' => &$aContentInfo
  356. ));
  357. return '';
  358. }
  359. public function viewDataForm ($iContentId, $sDisplay = false)
  360. {
  361. $CNF = &$this->_oModule->_oConfig->CNF;
  362. // get content data and profile info
  363. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  364. if (!$aContentInfo)
  365. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  366. // check access
  367. if ($sMsg = $this->_processPermissionsCheckForViewDataForm ($aContentInfo, $oProfile))
  368. return MsgBox($sMsg);
  369. // get form
  370. $oForm = $this->getObjectFormView($sDisplay);
  371. if (!$oForm)
  372. return MsgBox(_t('_sys_txt_error_occured'));
  373. // process metatags
  374. if (!empty($CNF['OBJECT_METATAGS'])) {
  375. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  376. if ($oMetatags->keywordsIsEnabled()) {
  377. $aFields = $oMetatags->metaFields($aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW']);
  378. $oForm->setMetatagsKeywordsData($iContentId, $aFields, $oMetatags);
  379. }
  380. }
  381. // display profile
  382. $oForm->initChecker($aContentInfo);
  383. return $oForm->getCode();
  384. }
  385. protected function _processPermissionsCheckForViewDataForm ($aContentInfo, $oProfile)
  386. {
  387. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
  388. return $sMsg;
  389. return '';
  390. }
  391. public function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
  392. {
  393. $CNF = &$this->_oModule->_oConfig->CNF;
  394. if(($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  395. $oPrivacy->deleteGroupCustomByContentId($iContentId);
  396. bx_audit(
  397. $iContentId,
  398. $this->_oModule->getName(),
  399. '_sys_audit_action_detete_content',
  400. $this->_oModule->_prepareAuditParams($aContentInfo)
  401. );
  402. return '';
  403. }
  404. public function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges, &$oProfile, &$oForm)
  405. {
  406. $CNF = &$this->_oModule->_oConfig->CNF;
  407. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == 'failed')
  408. $oForm->addTrackFields($CNF['FIELD_STATUS'], $aContentInfo);
  409. }
  410. public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm)
  411. {
  412. $CNF = &$this->_oModule->_oConfig->CNF;
  413. /*
  414. * Load update data.
  415. */
  416. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  417. if(isset($CNF['FIELD_PHOTO']))
  418. $oForm->processFiles ($CNF['FIELD_PHOTO'], $iContentId, false);
  419. if(isset($CNF['FIELD_STATUS']) && ($aTrackResult = $oForm->isTrackFieldChanged($CNF['FIELD_STATUS'], true)) !== false)
  420. if($aTrackResult['old'] == 'failed' && $aTrackResult['new'] == 'active')
  421. $this->_oModule->alertAfterAdd($aContentInfo);
  422. if(isset($CNF['FIELD_ALLOW_VIEW_TO']) && !empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  423. $oPrivacy->reassociateGroupCustomWithContent($oProfile->id(), $iContentId, (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  424. bx_audit(
  425. $iContentId,
  426. $this->_oModule->getName(),
  427. '_sys_audit_action_edit_content',
  428. $this->_oModule->_prepareAuditParams($aContentInfo)
  429. );
  430. return '';
  431. }
  432. public function onDataAddAfter ($iAccountId, $iContentId)
  433. {
  434. $CNF = &$this->_oModule->_oConfig->CNF;
  435. list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  436. if(($oForm = $this->getObjectFormAdd()) !== false) {
  437. if(isset($CNF['FIELD_PHOTO']))
  438. $oForm->processFiles($CNF['FIELD_PHOTO'], $iContentId, true);
  439. }
  440. if(isset($CNF['FIELD_ALLOW_VIEW_TO']) && !empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  441. $oPrivacy->associateGroupCustomWithContent($oProfile->id(), $iContentId, (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  442. bx_audit(
  443. $iContentId,
  444. $this->_oModule->getName(),
  445. '_sys_audit_action_add_content',
  446. $this->_oModule->_prepareAuditParams($aContentInfo)
  447. );
  448. return '';
  449. }
  450. protected function prepareCustomRedirectUrl($s, $aContentInfo)
  451. {
  452. $CNF = &$this->_oModule->_oConfig->CNF;
  453. $oProfile = BxDolProfile::getInstanceByContentAndType($aContentInfo[$CNF['FIELD_ID']], $this->_oModule->getName());
  454. $aMarkers = array(
  455. '{profile_id}',
  456. '{content_id}',
  457. '{module}',
  458. );
  459. $aReplacements = array(
  460. $oProfile ? $oProfile->id() : 0,
  461. $aContentInfo[$CNF['FIELD_ID']],
  462. $this->_oModule->getName(),
  463. );
  464. $s = str_replace($aMarkers, $aReplacements, $s);
  465. $s = BxDolPermalinks::getInstance()->permalink($s);
  466. if (false === strpos($s, 'http://') && false === strpos($s, 'https://'))
  467. $s = BX_DOL_URL_ROOT . $s;
  468. return $s;
  469. }
  470. protected function prepareResponse($mixedResponse, $bAsJson = false, $sKey = 'msg', $aAdditional = array())
  471. {
  472. if(!$bAsJson)
  473. return $mixedResponse;
  474. $aResponse = array(
  475. $sKey => $mixedResponse,
  476. '_dt' => 'json'
  477. );
  478. if(!empty($aAdditional) && is_array($aAdditional))
  479. $aResponse = array_merge($aResponse, $aAdditional);
  480. return $aResponse;
  481. }
  482. protected function _setAbsoluteActionUrl($sType, &$oForm)
  483. {
  484. $CNF = &$this->_oModule->_oConfig->CNF;
  485. $sKeyUri = 'URI_' . strtoupper($sType) . '_ENTRY';
  486. if(empty($CNF[$sKeyUri]))
  487. return;
  488. $oForm->setAbsoluteActionUrl(BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF[$sKeyUri]));
  489. }
  490. }
  491. /** @} */