BxDolProfileForms.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. /**
  10. * Functions to automate profile creation/editing/deletion forms.
  11. */
  12. class BxDolProfileForms extends BxDol {
  13. /**
  14. * Constructor
  15. */
  16. protected function __construct () {
  17. parent::__construct ();
  18. }
  19. // TODO: remake all calls and include markers with content and profile id at least
  20. protected function _redirectAndExit ($sUrl, $isPermalink = true, $aMarkers = false) {
  21. if ($isPermalink) {
  22. bx_import('BxDolPermalinks');
  23. $sUrl = BxDolPermalinks::getInstance()->permalink($sUrl);
  24. }
  25. header('Location: ' . BX_DOL_URL_ROOT . $this->_replaceMarkers($sUrl, $aMarkers));
  26. exit;
  27. }
  28. /**
  29. * Replace provided markers in a string, markers are surrounded by '{' and '}' signs, for example: a.php?x={id}
  30. * @param $mixed string or array to replace markers in
  31. * @param $aMarkers araay or markers for replacement, for example: array ('num' => 123, 'name' => 'Ivan');
  32. * @return string where all markers are replaced
  33. */
  34. protected function _replaceMarkers ($mixed, $aMarkers) {
  35. if (empty($aMarkers))
  36. return $mixed;
  37. if (is_array($mixed)) {
  38. foreach ($mixed as $sKey => $sValue)
  39. $mixed[$sKey] = $this->_replaceMarkers ($sValue);
  40. } else {
  41. foreach ($aMarkers as $sKey => $sValue)
  42. $mixed = str_replace('{' . $sKey . '}', $sValue, $mixed);
  43. }
  44. return $mixed;
  45. }
  46. }
  47. /** @} */