BxDevFunctions.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. * When the form is inited.
  17. *
  18. * @see BxDevFormsField
  19. */
  20. public static function changeFormField($aParams, $aInputs, $oDb)
  21. {
  22. $aInputs['module']['type'] = 'select';
  23. $aInputs['module']['values'] = array_merge(array('' => _t('_bx_dev_frm_txt_select_module')), BxDolStudioUtils::getModules());
  24. $aInputs['module']['value'] = $aParams['module'];
  25. $aInputs['object']['type'] = 'select';
  26. $aInputs['object']['value'] = $aParams['object'];
  27. $aInputs['object']['values'] = array();
  28. foreach(['caption_system', 'caption'] as $sField)
  29. if(isset($aInputs[$sField]))
  30. $aInputs[$sField]['caption'] = _t('_bx_dev_frm_txt_field_title_' . $sField);
  31. $aForms = array();
  32. $oDb->getForms(array('type' => 'by_module', 'value' => $aParams['module']), $aForms, false);
  33. if(!empty($aForms) && is_array($aForms)) {
  34. foreach($aForms as $aForm)
  35. $aInputs['object']['values'][$aForm['object']] = _t($aForm['title']);
  36. asort($aInputs['object']['values']);
  37. }
  38. $aInputs['object']['values'] = array_merge(array('' => _t('_bx_dev_frm_txt_select_object')), $aInputs['object']['values']);
  39. $aInputs['name']['type'] = 'text';
  40. $sTrlTypePostfix = '_translatable';
  41. $sTrlCheckFuncPostfix = 'Translatable';
  42. foreach($aInputs as $sName => $aInput)
  43. if(isset($aInput['type']) && stripos($aInput['type'], $sTrlTypePostfix) !== false) {
  44. $aInputs[$sName]['type'] = 'text';
  45. $aInputs[$sName]['html'] = 0;
  46. if(isset($aInput['checker']['func']) && stripos($aInput['checker']['func'], $sTrlCheckFuncPostfix) !== false)
  47. $aInputs[$sName]['checker']['func'] = str_ireplace($sTrlCheckFuncPostfix, '', $aInput['checker']['func']);
  48. }
  49. unset($aInputs['required']['attrs']['onchange']);
  50. unset($aInputs['checker_func']['attrs']['disabled'], $aInputs['checker_func']['tr_attrs']['style']);
  51. unset($aInputs['checker_error']['attrs']['disabled'], $aInputs['checker_error']['tr_attrs']['style']);
  52. $aFields = array(
  53. 'editable' => array(
  54. 'type' => 'switcher',
  55. 'name' => 'editable',
  56. 'caption' => _t('_bx_dev_frm_txt_field_title_editable'),
  57. 'info' => _t('_bx_dev_frm_txt_field_info_editable'),
  58. 'value' => '1',
  59. 'required' => '0',
  60. 'db' => array (
  61. 'pass' => 'Int',
  62. )
  63. ),
  64. 'deletable' => array(
  65. 'type' => 'switcher',
  66. 'name' => 'deletable',
  67. 'caption' => _t('_bx_dev_frm_txt_field_title_deletable'),
  68. 'info' => _t('_bx_dev_frm_txt_field_info_deletable'),
  69. 'value' => '1',
  70. 'required' => '0',
  71. 'db' => array (
  72. 'pass' => 'Int',
  73. )
  74. ),
  75. );
  76. $aInputs = BxDolStudioUtils::addInArray($aInputs, 'controls', $aFields, false);
  77. return $aInputs;
  78. }
  79. /*
  80. * Is needed to change form's array in "Form's Field" add/edit form.
  81. * It's called just before the form is displayed with "getCode" method.
  82. *
  83. * @see BxDevFormsField
  84. */
  85. public static function changeForm($sAction, $aForm, $oForm)
  86. {
  87. switch($sAction) {
  88. case 'add':
  89. break;
  90. case 'edit':
  91. if(isset($aForm['inputs']['checker_func'])) {
  92. if(isset($aForm['inputs']['checker_func']['attrs']['disabled']))
  93. unset($aForm['inputs']['checker_func']['attrs']['disabled']);
  94. $sCfValue = $aForm['inputs']['checker_func']['value'];
  95. if(!empty($sCfValue) && !in_array($sCfValue, $oForm->getCheckFunctions()))
  96. $aForm['inputs']['checker_func']['info'] = _t('_adm_form_txt_field_checker_func_info_custom');
  97. }
  98. break;
  99. }
  100. return $aForm;
  101. }
  102. public static function serializeString($sValue)
  103. {
  104. if(empty($sValue))
  105. return '';
  106. $aValue = array();
  107. @eval("\$aValue = " . $sValue . ";");
  108. if(empty($aValue) || !is_array($aValue))
  109. return '';
  110. return serialize($aValue);
  111. }
  112. public static function unserializeString($sValue)
  113. {
  114. if(empty($sValue))
  115. return '';
  116. $aValue = @unserialize($sValue);
  117. if(empty($aValue) || !is_array($aValue))
  118. return '';
  119. return var_export($aValue, true);
  120. }
  121. }
  122. /** @} */