1
0

BxBaseModGeneralFormsEntryHelper.php 22 KB

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