BxDevFunctions.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 Developer Developer
  7. * @ingroup UnaModules
  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. unset($aInputs['required']['attrs']['onchange']);
  45. unset($aInputs['checker_func']['attrs']['disabled'], $aInputs['checker_func']['tr_attrs']['style']);
  46. unset($aInputs['checker_error']['attrs']['disabled'], $aInputs['checker_error']['tr_attrs']['style']);
  47. $aFields = array(
  48. 'editable' => array(
  49. 'type' => 'switcher',
  50. 'name' => 'editable',
  51. 'caption' => _t('_bx_dev_frm_txt_field_title_editable'),
  52. 'info' => _t('_bx_dev_frm_txt_field_info_editable'),
  53. 'value' => '1',
  54. 'required' => '0',
  55. 'db' => array (
  56. 'pass' => 'Int',
  57. )
  58. ),
  59. 'deletable' => array(
  60. 'type' => 'switcher',
  61. 'name' => 'deletable',
  62. 'caption' => _t('_bx_dev_frm_txt_field_title_deletable'),
  63. 'info' => _t('_bx_dev_frm_txt_field_info_deletable'),
  64. 'value' => '1',
  65. 'required' => '0',
  66. 'db' => array (
  67. 'pass' => 'Int',
  68. )
  69. ),
  70. );
  71. $aInputs = BxDolStudioUtils::addInArray($aInputs, 'controls', $aFields, false);
  72. }
  73. public static function serializeString($sValue)
  74. {
  75. if(empty($sValue))
  76. return '';
  77. $aValue = array();
  78. @eval("\$aValue = " . $sValue . ";");
  79. if(empty($aValue) || !is_array($aValue))
  80. return '';
  81. return serialize($aValue);
  82. }
  83. public static function unserializeString($sValue)
  84. {
  85. if(empty($sValue))
  86. return '';
  87. $aValue = @unserialize($sValue);
  88. if(empty($aValue) || !is_array($aValue))
  89. return '';
  90. return var_export($aValue, true);
  91. }
  92. /**
  93. * Add slashes before "'" and "\" characters that the value containing them can be used in export feature.
  94. *
  95. * @param string $sString - the input string to add slashes
  96. * @param boolean $bDoubleEscape - whether the string needs to be two more escaped or not
  97. * @return string the slashed string
  98. */
  99. public static function dbAddSlashes($sString = '', $bDoubleEscape = false)
  100. {
  101. if ($bDoubleEscape)
  102. $sString = str_replace('\\', '\\\\\\\\', $sString);
  103. else
  104. $sString = str_replace('\\', '\\\\', $sString);
  105. return str_replace('\'', '\\\'', $sString);
  106. }
  107. }
  108. /** @} */