BxFroalaModule.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Froala Froala editor integration
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxFroalaModule extends BxDolModule
  12. {
  13. function __construct(&$aModule)
  14. {
  15. parent::__construct($aModule);
  16. }
  17. public function actionUpload()
  18. {
  19. header('Content-Type: application/json; charset=utf-8');
  20. if (!($oStorage = BxDolStorage::getObjectInstance('bx_froala_files'))) {
  21. echo json_encode(array('error' => '1'));
  22. exit;
  23. }
  24. $iProfileId = bx_get_logged_profile_id();
  25. if (!($iId = $oStorage->storeFileFromForm($_FILES['file'], false, $iProfileId))) {
  26. echo json_encode(array('error' => '1'));
  27. exit;
  28. }
  29. $oStorage->afterUploadCleanup($iId, $iProfileId);
  30. $aFileInfo = $oStorage->getFile($iId);
  31. if ($aFileInfo && in_array($aFileInfo['ext'], array('jpg', 'jpeg', 'jpe', 'png'))) {
  32. $oTranscoder = BxDolTranscoderImage::getObjectInstance('bx_froala_image');
  33. $sUrl = $oTranscoder->getFileUrl($iId);
  34. }
  35. else {
  36. $sUrl = $oStorage->getFileUrlById($iId);
  37. }
  38. echo json_encode(array('link' => $sUrl));
  39. }
  40. }
  41. /** @} */