BxBaseUploaderHTML5.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. 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. * add necessary js, css files and js translations
  26. */
  27. public function addCssJs ()
  28. {
  29. parent::addCssJs ();
  30. $this->_oTemplate->addJs('fileuploader.js');
  31. }
  32. /**
  33. * Get uploader button title
  34. */
  35. public function getUploaderButtonTitle($mixed = false)
  36. {
  37. if (is_string($mixed))
  38. return $mixed;
  39. elseif (is_array($mixed) && isset($mixed['HTML5']))
  40. return $mixed['HTML5'];
  41. else
  42. return _t('_sys_uploader_html5_button_name');
  43. }
  44. /**
  45. * Show uploader form.
  46. * @return HTML string
  47. */
  48. public function getUploaderForm($isMultiple = true, $iContentId = false)
  49. {
  50. return $this->_oTemplate->parseHtmlByName('uploader_form_html5.html', array(
  51. 'form_container_id' => $this->_sFormContainerId,
  52. 'errors_container_id' => $this->_sErrorsContainerId,
  53. 'uploader_instance_name' => $this->getNameJsInstanceUploader(),
  54. 'restrictions_text' => $this->getRestrictionsText(),
  55. 'div_id' => $this->_sDivId,
  56. 'content_id' => $iContentId,
  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)
  65. {
  66. bx_import('BxDolStorage');
  67. $oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
  68. $iProfileId = bx_get_logged_profile_id();
  69. if (!$isMultiple)
  70. $this->cleanupGhostsForProfile($iProfileId, $iContentId);
  71. if (bx_get('qqfile'))
  72. $iId = $oStorage->storeFileFromXhr(bx_get('qqfile'), true, $iProfileId, $iContentId);
  73. else
  74. $iId = $oStorage->storeFileFromForm($_FILES['qqfile'], true, $iProfileId, $iContentId);
  75. if ($iId) {
  76. $aResponse = array ('success' => 1);
  77. } else {
  78. $this->appendUploadErrorMessage(_t('_sys_uploader_err_msg', isset($_FILES['qqfile']['name']) ? $_FILES['qqfile']['name'] : bx_get('qqfile'), $oStorage->getErrorString()));
  79. $aResponse = array ('error' => $this->getUploadErrorMessages());
  80. }
  81. echo htmlspecialchars(json_encode($aResponse), ENT_NOQUOTES);
  82. }
  83. }
  84. /** @} */