BxBaseModGeneralFormsEntryHelper.php 21 KB

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