BxFroalaModule.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 serviceInjection()
  18. {
  19. return "
  20. <script>
  21. var fFroalaAddClass = function (s) {
  22. $('.bx-content-description,.cmt-body,.bx-base-text-entity-content,.bx-tl-content').addClass('fr-view');
  23. };
  24. if (typeof glOnProcessHtml === 'undefined')
  25. glOnProcessHtml = [];
  26. if (glOnProcessHtml instanceof Array)
  27. glOnProcessHtml.push(fFroalaAddClass);
  28. fFroalaAddClass();
  29. </script>";
  30. }
  31. public function actionUpload()
  32. {
  33. header('Content-Type: application/json; charset=utf-8');
  34. if (!($oStorage = BxDolStorage::getObjectInstance('bx_froala_files'))) {
  35. echo json_encode(array('error' => '1'));
  36. exit;
  37. }
  38. $iProfileId = bx_get_logged_profile_id();
  39. if (!($iId = $oStorage->storeFileFromForm($_FILES['file'], false, $iProfileId))) {
  40. echo json_encode(array('error' => '1'));
  41. exit;
  42. }
  43. $oStorage->afterUploadCleanup($iId, $iProfileId);
  44. $aFileInfo = $oStorage->getFile($iId);
  45. if ($aFileInfo && in_array($aFileInfo['ext'], array('jpg', 'jpeg', 'jpe', 'png'))) {
  46. $oTranscoder = BxDolTranscoderImage::getObjectInstance('bx_froala_image');
  47. $sUrl = $oTranscoder->getFileUrl($iId);
  48. }
  49. else {
  50. $sUrl = $oStorage->getFileUrlById($iId);
  51. }
  52. echo json_encode(array('link' => $sUrl));
  53. }
  54. }
  55. /** @} */