BxBaseStudioFormView.php 8.1 KB

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