1
0

BxBaseUploaderHTML5.php 3.4 KB

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