BxDevFunctions.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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'] = 'text';
  41. $aInputs[$sName]['html'] = 0;
  42. if(isset($aInput['checker']['func']) && stripos($aInput['checker']['func'], $sTrlCheckFuncPostfix) !== false)
  43. $aInputs[$sName]['checker']['func'] = str_ireplace($sTrlCheckFuncPostfix, '', $aInput['checker']['func']);
  44. }
  45. unset($aInputs['required']['attrs']['onchange']);
  46. unset($aInputs['checker_func']['attrs']['disabled'], $aInputs['checker_func']['tr_attrs']['style']);
  47. unset($aInputs['checker_error']['attrs']['disabled'], $aInputs['checker_error']['tr_attrs']['style']);
  48. $aFields = array(
  49. 'editable' => array(
  50. 'type' => 'switcher',
  51. 'name' => 'editable',
  52. 'caption' => _t('_bx_dev_frm_txt_field_title_editable'),
  53. 'info' => _t('_bx_dev_frm_txt_field_info_editable'),
  54. 'value' => '1',
  55. 'required' => '0',
  56. 'db' => array (
  57. 'pass' => 'Int',
  58. )
  59. ),
  60. 'deletable' => array(
  61. 'type' => 'switcher',
  62. 'name' => 'deletable',
  63. 'caption' => _t('_bx_dev_frm_txt_field_title_deletable'),
  64. 'info' => _t('_bx_dev_frm_txt_field_info_deletable'),
  65. 'value' => '1',
  66. 'required' => '0',
  67. 'db' => array (
  68. 'pass' => 'Int',
  69. )
  70. ),
  71. );
  72. $aInputs = BxDolStudioUtils::addInArray($aInputs, 'controls', $aFields, false);
  73. }
  74. public static function serializeString($sValue)
  75. {
  76. if(empty($sValue))
  77. return '';
  78. $aValue = array();
  79. @eval("\$aValue = " . $sValue . ";");
  80. if(empty($aValue) || !is_array($aValue))
  81. return '';
  82. return serialize($aValue);
  83. }
  84. public static function unserializeString($sValue)
  85. {
  86. if(empty($sValue))
  87. return '';
  88. $aValue = @unserialize($sValue);
  89. if(empty($aValue) || !is_array($aValue))
  90. return '';
  91. return var_export($aValue, true);
  92. }
  93. }
  94. /** @} */