BxDevFunctions.php 3.0 KB

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