BxBaseUploaderHTML5.php 3.9 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. var $_sDivId; ///< div id where upload button will be placed
  17. function __construct ($aObject, $sStorageObject, $sUniqId) {
  18. parent::__construct($aObject, $sStorageObject, $sUniqId);
  19. $this->_sDivId = 'bx-form-input-files-' . $sUniqId . '-div-' . $this->_aObject['object'];
  20. $this->_sButtonTemplate = 'uploader_button_html5.html';
  21. }
  22. /**
  23. * Show uploader button.
  24. * @return HTML string
  25. */
  26. public function getUploaderButton($sGhostTemplate, $isMultiple = true, $aParams = array()) {
  27. $s = parent::getUploaderButton($sGhostTemplate, $isMultiple, $aParams);
  28. $oTemplate = BxDolTemplate::getInstance();
  29. $oTemplate->addJs(BX_DOL_URL_PLUGINS . 'fileuploader.js');
  30. return $s;
  31. }
  32. /**
  33. * Get uploader button title
  34. */
  35. public function getUploaderButtonTitle($mixed = false) {
  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) {
  48. parent::getUploaderForm($isMultiple, $iContentId);
  49. $oTemplate = BxDolTemplate::getInstance();
  50. $sForm = $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. bx_import('BxTemplFunctions');
  59. return BxTemplFunctions::getInstance()->transBox($sForm);
  60. }
  61. /**
  62. * Handle uploads here.
  63. * @param $mixedFiles as usual $_FILES['some_name'] array, but maybe some other params depending on the uploader
  64. * @return nothing, but if some files failed to upload, the actual error message can be determined by calling BxDolUploader::getUploadErrorMessages()
  65. */
  66. public function handleUploads ($iProfileId, $mixedFiles, $isMultiple = true, $iContentId = false) {
  67. bx_import('BxDolStorage');
  68. $oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
  69. $iProfileId = bx_get_logged_profile_id();
  70. if (!$isMultiple)
  71. $this->cleanupGhostsForProfile($iProfileId, $iContentId);
  72. if (bx_get('qqfile'))
  73. $iId = $oStorage->storeFileFromXhr(bx_get('qqfile'), true, $iProfileId, $iContentId);
  74. else
  75. $iId = $oStorage->storeFileFromForm($_FILES['qqfile'], true, $iProfileId, $iContentId);
  76. if ($iId) {
  77. $aResponse = array ('success' => 1);
  78. } else {
  79. $this->appendUploadErrorMessage(_t('_sys_uploader_err_msg', isset($_FILES['qqfile']['name']) ? $_FILES['qqfile']['name'] : bx_get('qqfile'), $oStorage->getErrorString()));
  80. $aResponse = array ('error' => $this->getUploadErrorMessages());
  81. }
  82. require_once(BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php');
  83. $oParser = new Services_JSON();
  84. echo htmlspecialchars($oParser->encode($aResponse), ENT_NOQUOTES);
  85. }
  86. }
  87. /** @} */