BxDevFunctions.php 3.2 KB

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