1
0

BxBaseUploaderHTML5.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import ('BxDolUploader');
  10. /**
  11. * Upload files using AJAX uploader with multiple files selection support (without flash),
  12. * it works in Firefox and WebKit(Safari, Chrome) browsers only, but has fallback for other browsers (IE, Opera).
  13. * @see BxDolUploader
  14. */
  15. class BxBaseUploaderHTML5 extends BxDolUploader
  16. {
  17. protected $_sDivId; ///< div id where upload button will be placed
  18. function __construct ($aObject, $sStorageObject, $sUniqId)
  19. {
  20. parent::__construct($aObject, $sStorageObject, $sUniqId);
  21. $this->_sDivId = 'bx-form-input-files-' . $sUniqId . '-div-' . $this->_aObject['object'];
  22. $this->_sButtonTemplate = 'uploader_button_html5.html';
  23. }
  24. /**
  25. * Show uploader button.
  26. * @return HTML string
  27. */
  28. public function getUploaderButton($sGhostTemplate, $isMultiple = true, $aParams = array())
  29. {
  30. $s = parent::getUploaderButton($sGhostTemplate, $isMultiple, $aParams);
  31. $this->_oTemplate->addJs('fileuploader.js');
  32. return $s;
  33. }
  34. /**
  35. * Get uploader button title
  36. */
  37. public function getUploaderButtonTitle($mixed = false)
  38. {
  39. if (is_string($mixed))
  40. return $mixed;
  41. elseif (is_array($mixed) && isset($mixed['HTML5']))
  42. return $mixed['HTML5'];
  43. else
  44. return _t('_sys_uploader_html5_button_name');
  45. }
  46. /**
  47. * Show uploader form.
  48. * @return HTML string
  49. */
  50. public function getUploaderForm($isMultiple = true, $iContentId = false)
  51. {
  52. parent::getUploaderForm($isMultiple, $iContentId);
  53. $sForm = $this->_oTemplate->parseHtmlByName('uploader_form_html5.html', array(
  54. 'form_container_id' => $this->_sFormContainerId,
  55. 'errors_container_id' => $this->_sErrorsContainerId,
  56. 'uploader_instance_name' => $this->getNameJsInstanceUploader(),
  57. 'restrictions_text' => $this->getRestrictionsText(),
  58. 'div_id' => $this->_sDivId,
  59. 'content_id' => $iContentId,
  60. ));
  61. bx_import('BxTemplFunctions');
  62. return BxTemplFunctions::getInstance()->transBox('', $sForm);
  63. }
  64. /**
  65. * Handle uploads here.
  66. * @param $mixedFiles as usual $_FILES['some_name'] array, but maybe some other params depending on the uploader
  67. * @return nothing, but if some files failed to upload, the actual error message can be determined by calling BxDolUploader::getUploadErrorMessages()
  68. */
  69. public function handleUploads ($iProfileId, $mixedFiles, $isMultiple = true, $iContentId = false)
  70. {
  71. bx_import('BxDolStorage');
  72. $oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
  73. $iProfileId = bx_get_logged_profile_id();
  74. if (!$isMultiple)
  75. $this->cleanupGhostsForProfile($iProfileId, $iContentId);
  76. if (bx_get('qqfile'))
  77. $iId = $oStorage->storeFileFromXhr(bx_get('qqfile'), true, $iProfileId, $iContentId);
  78. else
  79. $iId = $oStorage->storeFileFromForm($_FILES['qqfile'], true, $iProfileId, $iContentId);
  80. if ($iId) {
  81. $aResponse = array ('success' => 1);
  82. } else {
  83. $this->appendUploadErrorMessage(_t('_sys_uploader_err_msg', isset($_FILES['qqfile']['name']) ? $_FILES['qqfile']['name'] : bx_get('qqfile'), $oStorage->getErrorString()));
  84. $aResponse = array ('error' => $this->getUploadErrorMessages());
  85. }
  86. echo htmlspecialchars(json_encode($aResponse), ENT_NOQUOTES);
  87. }
  88. }
  89. /** @} */