1
0

BxBaseModGeneralFormsEntryHelper.php 21 KB

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