BxDevFunctions.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 Developer Developer
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolStudioUtils');
  12. class BxDevFunctions
  13. {
  14. function __construct() {}
  15. /*
  16. * Is needed to change fields in "Form's Field" creation form.
  17. *
  18. * @see BxDevFormsField
  19. */
  20. public static function changeFormField($aParams, &$aInputs, &$oDb)
  21. {
  22. $aInputs['module']['type'] = 'select';
  23. $aInputs['module']['values'] = array_merge(array('' => _t('_bx_dev_frm_txt_select_module')), BxDolStudioUtils::getModules());
  24. $aInputs['module']['value'] = $aParams['module'];
  25. $aForms = array();
  26. $oDb->getForms(array('type' => 'by_module', 'value' => $aParams['module']), $aForms, false);
  27. foreach($aForms as $aForm)
  28. $aInputs['object']['values'][$aForm['object']] = _t($aForm['title']);
  29. asort($aInputs['object']['values']);
  30. $aInputs['object']['type'] = 'select';
  31. $aInputs['object']['values'] = array_merge(array('' => _t('_bx_dev_frm_txt_select_object')), $aInputs['object']['values']);
  32. $aInputs['object']['value'] = $aParams['object'];
  33. $sTrlTypePostfix = '_translatable';
  34. $sTrlCheckFuncPostfix = 'Translatable';
  35. foreach($aInputs as $sName => $aInput)
  36. if(isset($aInput['type']) && stripos($aInput['type'], $sTrlTypePostfix) !== false) {
  37. $aInputs[$sName]['type'] = str_ireplace($sTrlTypePostfix, '', $aInput['type']);
  38. if(isset($aInput['checker']['func']) && stripos($aInput['checker']['func'], $sTrlCheckFuncPostfix) !== false)
  39. $aInputs[$sName]['checker']['func'] = str_ireplace($sTrlCheckFuncPostfix, '', $aInput['checker']['func']);
  40. }
  41. }
  42. public static function serializeString($sValue)
  43. {
  44. if(empty($sValue))
  45. return '';
  46. $aValue = array();
  47. @eval("\$aValue = " . $sValue . ";");
  48. if(empty($aValue) || !is_array($aValue))
  49. return '';
  50. return serialize($aValue);
  51. }
  52. public static function unserializeString($sValue)
  53. {
  54. if(empty($sValue))
  55. return '';
  56. $aValue = @unserialize($sValue);
  57. if(empty($aValue) || !is_array($aValue))
  58. return '';
  59. return var_export($aValue, true);
  60. }
  61. /**
  62. * Add slashes before "'" and "\" characters that the value containing them can be used in export feature.
  63. *
  64. * @param string $sString - the input string to add slashes
  65. * @param boolean $bDoubleEscape - whether the string needs to be two more escaped or not
  66. * @return string the slashed string
  67. */
  68. public static function dbAddSlashes($sString = '', $bDoubleEscape = false)
  69. {
  70. if ($bDoubleEscape)
  71. $sString = str_replace('\\', '\\\\\\\\', $sString);
  72. else
  73. $sString = str_replace('\\', '\\\\', $sString);
  74. return str_replace('\'', '\\\'', $sString);
  75. }
  76. }
  77. /** @} */