BxDevFunctions.php 4.1 KB

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