BxEditorModule.php 2.4 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 Editor integration
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxEditorModule extends BxDolModule
  12. {
  13. public $_aButtons = [];
  14. function __construct(&$aModule)
  15. {
  16. parent::__construct($aModule);
  17. $this->_aButtons = [
  18. 'bold' => ['icon' => 'bold', 'text' => _t('_bx_editor_toolbar_action_bold')],
  19. 'italic' => ['icon' => 'italic', 'text' => _t('_bx_editor_toolbar_action_italic')],
  20. 'link' => ['icon' => 'link', 'text' => _t('_bx_editor_toolbar_action_link')],
  21. 'marker' => ['icon' => 'marker', 'text' => _t('_bx_editor_toolbar_action_marker')],
  22. 'inlineCode' => ['icon' => 'inlineCode', 'text' => _t('_bx_editor_toolbar_action_inlineCode')],
  23. 'header' => ['icon' => 'header', 'text' => _t('_bx_editor_toolbar_action_header')],
  24. 'list' => ['icon' => 'list-ul', 'text' => _t('_bx_editor_toolbar_action_list')],
  25. 'code' => ['icon' => 'code', 'text' => _t('_bx_editor_toolbar_action_code')],
  26. 'delimiter' => ['icon' => 'delimiter', 'text' => _t('_bx_editor_toolbar_action_delimiter')],
  27. 'link' => ['icon' => 'link', 'text' => _t('_bx_editor_toolbar_action_link')],
  28. 'image' => ['icon' => 'image', 'text' => _t('_bx_editor_toolbar_action_image')],
  29. 'embed' => ['icon' => 'share-alt', 'text' => _t('_bx_editor_toolbar_action_embed')],
  30. ];
  31. }
  32. public function actionUpload()
  33. {
  34. header('Content-Type: application/json; charset=utf-8');
  35. if (!($oStorage = BxDolStorage::getObjectInstance('bx_editor_files'))) {
  36. echo json_encode(array('error' => '1'));
  37. exit;
  38. }
  39. $iProfileId = bx_get_logged_profile_id();
  40. if (!($iId = $oStorage->storeFileFromForm($_FILES['file'], false, $iProfileId))) {
  41. echo json_encode(array('error' => '1'));
  42. exit;
  43. }
  44. $oStorage->afterUploadCleanup($iId, $iProfileId);
  45. $aFileInfo = $oStorage->getFile($iId);
  46. if ($aFileInfo && in_array($aFileInfo['ext'], array('jpg', 'jpeg', 'jpe', 'png'))) {
  47. $oTranscoder = BxDolTranscoderImage::getObjectInstance('bx_editor_image');
  48. $sUrl = $oTranscoder->getFileUrl($iId);
  49. }
  50. else {
  51. $sUrl = $oStorage->getFileUrlById($iId);
  52. }
  53. echo json_encode(array('link' => $sUrl));
  54. }
  55. }
  56. /** @} */