BxBaseStudioStoragesImages.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioStoragesImages extends BxDolStudioStoragesImages
  11. {
  12. function __construct($aOptions, $oTemplate = false)
  13. {
  14. parent::__construct($aOptions, $oTemplate);
  15. }
  16. public function performActionResize()
  17. {
  18. $sAction = 'resize';
  19. $aIds = bx_get('ids');
  20. if(!$aIds || !is_array($aIds)) {
  21. $iId = (int)bx_get('id');
  22. if(!$iId) {
  23. echoJson(array());
  24. exit;
  25. }
  26. $aIds = array($iId);
  27. }
  28. $iId = $aIds[0];
  29. $oForm = $this->_getFormObjectResize($iId);
  30. $oForm->initChecker();
  31. if($oForm->isSubmittedAndValid()) {
  32. $iWidth = $oForm->getCleanValue('width');
  33. $iHeight = $oForm->getCleanValue('height');
  34. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_sTranscoderResize);
  35. if(!$oTranscoder)
  36. return echoJson(array('msg' => _t($this->_aT['err_files_resize'])));
  37. $sFileUrl = bx_append_url_params($oTranscoder->getFileUrlNotReady($iId), array(
  38. 'x' => $iWidth,
  39. 'y' => $iHeight
  40. ));
  41. $sPopup = $this->_oTemplate->parseHtmlByName('strg_resize_' . $this->_sType . '_result.html', array(
  42. 'url' => $sFileUrl
  43. ));
  44. $aPopupOptions = array();
  45. }
  46. else {
  47. $sPopup = $this->_oTemplate->parseHtmlByName('strg_resize_' . $this->_sType . '_form.html', array(
  48. 'form_id' => $oForm->aFormAttrs['id'],
  49. 'form' => $oForm->getCode(true),
  50. 'object' => $this->_sObject,
  51. 'action' => $sAction
  52. ));
  53. $aPopupOptions = array('closeOnOuterClick' => false);
  54. }
  55. echoJson(array('popup' => array(
  56. 'html' => BxTemplStudioFunctions::getInstance()->popupBox('adm-strg-' . $this->_sType . '-resize-popup', _t($this->_aT['txt_files_resize_popup']), $sPopup),
  57. 'options' => $aPopupOptions
  58. )));
  59. }
  60. protected function _getCellMimeType($mixedValue, $sKey, $aField, $aRow)
  61. {
  62. $iWidth = $iHeight = 0;
  63. $sFileUrl = $this->_oStorage->getFileUrlById($aRow['id']);
  64. if(!empty($sFileUrl) && ($aSize = @getimagesize($sFileUrl)))
  65. list($iWidth, $iHeight) = $aSize;
  66. return parent::_getCellDefault(_t('_adm_strg_txt_size_mime_type', (int)$iWidth, (int)$iHeight, $mixedValue), $sKey, $aField, $aRow);
  67. }
  68. protected function _getFormObjectResize($iId)
  69. {
  70. bx_import('BxTemplStudioFormView');
  71. $aForm = array(
  72. 'form_attrs' => array(
  73. 'id' => 'adm-strg-' . $this->_sType . '-resize',
  74. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=resize',
  75. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  76. ),
  77. 'params' => array (
  78. 'db' => array(
  79. 'table' => '',
  80. 'key' => '',
  81. 'uri' => '',
  82. 'uri_title' => '',
  83. 'submit_name' => 'do_submit'
  84. ),
  85. ),
  86. 'inputs' => array (
  87. 'id' => array(
  88. 'type' => 'hidden',
  89. 'name' => 'id',
  90. 'value' => $iId,
  91. 'db' => array (
  92. 'pass' => 'Int',
  93. ),
  94. ),
  95. 'width' => array(
  96. 'type' => 'text',
  97. 'name' => 'width',
  98. 'caption' => _t('_adm_strg_txt_width'),
  99. 'value' => '',
  100. 'required' => '1',
  101. 'db' => array (
  102. 'pass' => 'Int',
  103. ),
  104. 'checker' => array (
  105. 'func' => 'Avail',
  106. 'params' => array(),
  107. 'error' => _t('_adm_strg_err_width'),
  108. ),
  109. ),
  110. 'height' => array(
  111. 'type' => 'text',
  112. 'name' => 'height',
  113. 'caption' => _t('_adm_strg_txt_height'),
  114. 'value' => '',
  115. 'required' => '1',
  116. 'db' => array (
  117. 'pass' => 'Int',
  118. ),
  119. 'checker' => array (
  120. 'func' => 'Avail',
  121. 'params' => array(),
  122. 'error' => _t('_adm_strg_err_height'),
  123. ),
  124. ),
  125. 'controls' => array(
  126. 'name' => 'controls',
  127. 'type' => 'input_set',
  128. array(
  129. 'type' => 'submit',
  130. 'name' => 'do_submit',
  131. 'value' => _t('_adm_strg_btn_resize'),
  132. ),
  133. array (
  134. 'type' => 'reset',
  135. 'name' => 'close',
  136. 'value' => _t('_adm_strg_btn_cancel'),
  137. 'attrs' => array(
  138. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  139. 'class' => 'bx-def-margin-sec-left',
  140. ),
  141. )
  142. )
  143. )
  144. );
  145. return new BxTemplStudioFormView($aForm);
  146. }
  147. }
  148. /** @} */