BxBaseUploaderHTML5.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * @package Dolphin Core
  4. * @copyright Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  5. * @license CC-BY - http://creativecommons.org/licenses/by/3.0/
  6. */
  7. defined('BX_DOL') or die('hack attempt');
  8. bx_import ('BxDolUploader');
  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. var $_sDivId; ///< div id where upload button will be placed
  16. function BxBaseUploaderHTML5 ($aObject, $sStorageObject, $sUniqId) {
  17. parent::BxDolUploader($aObject, $sStorageObject, $sUniqId);
  18. $this->_sDivId = 'bx-form-input-files-' . $sUniqId . '-div-' . $this->_aObject['engine'];
  19. $this->_sButtonTemplate = 'uploader_button_html5.html';
  20. }
  21. /**
  22. * Show uploader button.
  23. * @return HTML string
  24. */
  25. public function getUploaderButton($sGhostTemplate, $isMultiple = true, $aParams = array()) {
  26. $s = parent::getUploaderButton($sGhostTemplate, $isMultiple, $aParams);
  27. $oTemplate = BxDolTemplate::getInstance();
  28. $oTemplate->addJs(BX_DOL_URL_PLUGINS . 'fileuploader.js');
  29. return $s;
  30. }
  31. /**
  32. * Get uploader button title
  33. */
  34. public function getUploaderButtonTitle($mixed = false) {
  35. if (is_string($mixed))
  36. return $mixed;
  37. elseif (is_array($mixed) && isset($mixed['HTML5']))
  38. return $mixed['HTML5'];
  39. else
  40. return _t('_sys_uploader_html5_button_name');
  41. }
  42. /**
  43. * Show uploader form.
  44. * @return HTML string
  45. */
  46. public function getUploaderForm($isMultiple = true, $iContentId = false) {
  47. parent::getUploaderForm($isMultiple, $iContentId);
  48. $oTemplate = BxDolTemplate::getInstance();
  49. $sForm = $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. ));
  57. bx_import('BxTemplFunctions');
  58. return BxTemplFunctions::getInstance()->transBox($sForm);
  59. }
  60. /**
  61. * Handle uploads here.
  62. * @param $mixedFiles as usual $_FILES['some_name'] array, but maybe some other params depending on the uploader
  63. * @return nothing, but if some files failed to upload, the actual error message can be determined by calling BxDolUploader::getUploadErrorMessages()
  64. */
  65. public function handleUploads ($mixedFiles, $isMultiple = true, $iContentId = false) {
  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. require_once(BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php');
  82. $oParser = new Services_JSON();
  83. echo htmlspecialchars($oParser->encode($aResponse), ENT_NOQUOTES);
  84. }
  85. }