1
0

BxBaseStudioFormView.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 TridentView Trident Studio Representation classes
  7. * @ingroup TridentStudio
  8. * @{
  9. */
  10. class BxBaseStudioFormView extends BxDolStudioForm
  11. {
  12. function __construct($aInfo, $oTemplate)
  13. {
  14. parent::__construct($aInfo, $oTemplate);
  15. }
  16. function addCssJs()
  17. {
  18. parent::addCssJs();
  19. $this->oTemplate->addJs(array(
  20. 'forms.js'
  21. ));
  22. }
  23. function genRow(&$aInput)
  24. {
  25. $sRow = '';
  26. switch($aInput['type']) {
  27. case 'image_uploader':
  28. $sRow = $this->genRowImageUploader($aInput);
  29. break;
  30. default:
  31. $sRow = parent::genRow($aInput);
  32. }
  33. return $sRow;
  34. }
  35. function genInput(&$aInput)
  36. {
  37. $sInput = '';
  38. switch($aInput['type']) {
  39. case 'text_translatable':
  40. $sInput = $this->genInputTranslatable($aInput, 'text');
  41. break;
  42. case 'textarea_translatable':
  43. $aInput['html'] = 0;
  44. $sInput = $this->genInputTranslatable($aInput, 'textarea');
  45. break;
  46. default:
  47. $sInput = parent::genInput($aInput);
  48. }
  49. return $sInput;
  50. }
  51. function genRowImageUploader(&$aInput)
  52. {
  53. $aTmplVarsPreview = array(
  54. 'bx_if:show_empty' => array(
  55. 'condition' => true,
  56. 'content' => array()
  57. ),
  58. 'bx_if:show_image' => array(
  59. 'condition' => false,
  60. 'content' => array()
  61. )
  62. );
  63. if(($iId = (int)$aInput['value']) != 0) {
  64. $sFileUrl = false;
  65. if (!empty($aInput['transcoder_object'])) {
  66. $oTranscoder = BxDolTranscoderImage::getObjectInstance($aInput['transcoder_object']);
  67. $sFileUrl = $oTranscoder->getFileUrlNotReady($iId);
  68. if (isset($aInput['transcoder_image_width']) && $aInput['transcoder_image_width'] > 0)
  69. $sFileUrl = bx_append_url_params($sFileUrl, array('x' => $aInput['transcoder_image_width']));
  70. if (isset($aInput['transcoder_image_height']) && $aInput['transcoder_image_height'] > 0)
  71. $sFileUrl = bx_append_url_params($sFileUrl, array('y' => $aInput['transcoder_image_height']));
  72. }
  73. else {
  74. $sStorage = isset($aInput['storage_object']) && $aInput['storage_object'] != '' ? $aInput['storage_object'] : BX_DOL_STORAGE_OBJ_IMAGES;
  75. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  76. $sFileUrl = $oStorage->getFileUrlById($iId);
  77. }
  78. if($sFileUrl !== false) {
  79. $aTmplVarsPreview['bx_if:show_empty']['condition'] = false;
  80. $aTmplVarsPreview['bx_if:show_image'] = array(
  81. 'condition' => true,
  82. 'content' => array(
  83. 'url' => $sFileUrl,
  84. 'bx_if:show_action_delete' => array(
  85. 'condition' => isset($aInput['ajax_action_delete']) && $aInput['ajax_action_delete'] != "",
  86. 'content' => array(
  87. 'action' => $aInput['ajax_action_delete']
  88. )
  89. )
  90. )
  91. );
  92. }
  93. }
  94. $sRow = '';
  95. $aInputPreview = array(
  96. 'type' => 'custom',
  97. 'name' => 'preview',
  98. 'caption' => isset($aInput['caption_preview']) ? $aInput['caption_preview'] : _t('_adm_txt_form_view_iu_preview'),
  99. 'content' => $this->oTemplate->parseHtmlByName('form_view_iu_preview.html', $aTmplVarsPreview)
  100. );
  101. $sRow .= $this->genRow($aInputPreview);
  102. $aInput['type'] = 'file';
  103. $sRow .= $this->genRow($aInput);
  104. return $sRow;
  105. }
  106. function genInputTranslatable(&$aInput, $sType = 'text')
  107. {
  108. $iValueLength = 20;
  109. $sInputIdPrefix = 'bx-form-input-';
  110. $aInputMethod = array('text' => 'genInputStandard', 'textarea' => 'genInputTextarea');
  111. $sInput = '';
  112. $sInputName = $aInput['name'];
  113. $aInputAttrs = isset($aInput['attrs']) && is_array($aInput['attrs']) ? $aInput['attrs'] : array();
  114. $oFunctions = BxTemplStudioFunctions::getInstance();
  115. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  116. $sLanguage = $oLanguage->getCurrentLangName(false);
  117. $aLanguages = $oLanguage->getLanguagesInfo();
  118. $aStrings = $oLanguage->getLanguageString($aInput['value']);
  119. $aInput['type'] = 'hidden';
  120. $aInput['attrs'] = array_merge($aInputAttrs, array(
  121. 'id' => $sInputIdPrefix . $aInput['name']
  122. ));
  123. $sInput .= $this->genInputStandard($aInput);
  124. $aTmplVars = array();
  125. foreach($aLanguages as $aLanguage) {
  126. $bLanguage = $aLanguage['name'] == $sLanguage;
  127. $sValue = '';
  128. if(($bValue = key_exists($aLanguage['id'], $aStrings)) === true)
  129. $sValue = $aStrings[$aLanguage['id']]['string'];
  130. else if(isset($aInput['values'][$aLanguage['name']]))
  131. $sValue = $aInput['values'][$aLanguage['name']];
  132. $aInput['type'] = $sType;
  133. $aInput['name'] = $sInputName . '-' . $aLanguage['name'];
  134. $aInput['value'] = $sValue;
  135. $aInput['attrs'] = array_merge($aInputAttrs, array(
  136. 'id' => $sInputIdPrefix . $aInput['name'],
  137. 'style' => !$bLanguage ? 'display:none;' : ''
  138. ));
  139. $sInput .= $this->$aInputMethod[$sType]($aInput);
  140. $aTmplVarValue = array(
  141. 'condition' => $bValue,
  142. 'content' => array(
  143. 'value' => strmaxtextlen($sValue, $iValueLength)
  144. )
  145. );
  146. $aTmplVarMissing = array(
  147. 'condition' => !$bValue || empty($sValue),
  148. 'content' => array()
  149. );
  150. $aTmplVars[] = array(
  151. 'name' => $sInputName,
  152. 'lang_name' => $aLanguage['name'],
  153. 'lang_flag' => $aLanguage['icon'],
  154. 'lang_title' => $aLanguage['title'],
  155. 'bx_if:hide_active' => array(
  156. 'condition' => !$bLanguage,
  157. 'content' => array()
  158. ),
  159. 'bx_if:act_value' => $aTmplVarValue,
  160. 'bx_if:act_missing' => $aTmplVarMissing,
  161. 'bx_if:hide_passive' => array(
  162. 'condition' => $bLanguage,
  163. 'content' => array()
  164. ),
  165. 'bx_if:pas_value' => $aTmplVarValue,
  166. 'bx_if:pas_missing' => $aTmplVarMissing,
  167. );
  168. }
  169. $sPopup = $this->oTemplate->parseHtmlByName('form_view_translator.html', array('bx_repeat:languages' => $aTmplVars));
  170. $sPopup = $oFunctions->transBox('bx-form-field-translator-popup-' . $sInputName, $sPopup, true);
  171. $aLanguage = $oLanguage->getLanguageInfo($sLanguage);
  172. $sControl = $this->oTemplate->parseHtmlByName('form_view_translatable.html', array(
  173. 'flag' => $aLanguage['icon'],
  174. 'title' => $aLanguage['title'],
  175. 'name' => $sInputName,
  176. 'popup' => $sPopup
  177. ));
  178. return $sInput . $sControl;
  179. }
  180. /**
  181. * Generate Reverse Checkbox Set Element
  182. *
  183. * @param array $aInput
  184. * @return string
  185. */
  186. function genInputCheckboxSet(&$aInput)
  187. {
  188. $aInput['value'] = isset($aInput['value']) && $aInput['value'] && is_array($aInput['value']) ? $aInput['value'] : array();
  189. if(!empty($aInput['reverse']))
  190. $aInput['value'] = array_diff(array_keys($aInput['values']), $aInput['value']);
  191. return parent::genInputCheckboxSet($aInput);
  192. }
  193. }
  194. /** @} */