Fix media manager access (#4305)

This commit is contained in:
Marc Jauvin 2019-05-10 13:59:57 -04:00 committed by Denis Denisov
parent a1e6849a71
commit 8448d4b972
7 changed files with 23 additions and 2 deletions

View File

@ -1,5 +1,6 @@
<?php namespace Backend\FormWidgets;
use BackendAuth;
use Markdown;
use Backend\Classes\FormWidgetBase;
@ -65,6 +66,7 @@ class MarkdownEditor extends FormWidgetBase
$this->vars['size'] = $this->formField->size;
$this->vars['name'] = $this->getFieldName();
$this->vars['value'] = $this->getLoadValue();
$this->vars['useMediaManager'] = BackendAuth::getUser()->hasAccess('media.manage_media');
}
/**

View File

@ -5,6 +5,7 @@ use File;
use Event;
use Lang;
use Request;
use BackendAuth;
use Backend\Classes\FormWidgetBase;
use Backend\Models\EditorSetting;
@ -84,6 +85,7 @@ class RichEditor extends FormWidgetBase
$this->vars['name'] = $this->getFieldName();
$this->vars['value'] = $this->getLoadValue();
$this->vars['toolbarButtons'] = $this->evalToolbarButtons();
$this->vars['useMediaManager'] = BackendAuth::getUser()->hasAccess('media.manage_media');
$this->vars['globalToolbarButtons'] = EditorSetting::getConfigured('html_toolbar_buttons');
$this->vars['allowEmptyTags'] = EditorSetting::getConfigured('html_allow_empty_tags');

View File

@ -234,6 +234,10 @@
}
MarkdownEditor.prototype.makeToolbarButton = function(code, button) {
if (!this.options.useMediaManager && (code == 'medialink' || code == 'mediaimage')) {
return
}
var $button = $('<button />').attr({
'type': "button",
'class': 'btn',
@ -674,7 +678,8 @@
vendorPath: '/',
refreshHandler: null,
buttons: ['formatting', 'bold', 'italic', 'unorderedlist', 'orderedlist', 'link', 'horizontalrule'],
viewMode: 'tab'
viewMode: 'tab',
useMediaManager: false
}
// PLUGIN DEFINITION

View File

@ -7,6 +7,7 @@
data-control="markdowneditor"
data-refresh-handler="<?= $this->getEventHandler('onRefresh') ?>"
data-view-mode="<?= $mode ?>"
<?php if ($useMediaManager): ?>data-use-media-manager="true"<?php endif ?>
data-vendor-path="<?= Url::asset('/modules/backend/formwidgets/codeeditor/assets/vendor/ace') ?>">
<div class="control-toolbar editor-toolbar"></div>

View File

@ -157,7 +157,7 @@ Base.call(this)
this.init()}
RichEditor.prototype=Object.create(BaseProto)
RichEditor.prototype.constructor=RichEditor
RichEditor.DEFAULTS={linksHandler:null,stylesheet:null,fullpage:false,editorLang:'en',toolbarButtons:null,allowEmptyTags:null,allowTags:null,noWrapTags:null,removeTags:null,lineBreakerTags:null,imageStyles:null,linkStyles:null,paragraphStyles:null,tableStyles:null,tableCellStyles:null,aceVendorPath:'/',readOnly:false}
RichEditor.DEFAULTS={linksHandler:null,stylesheet:null,fullpage:false,editorLang:'en',useMediaManager:false,toolbarButtons:null,allowEmptyTags:null,allowTags:null,noWrapTags:null,removeTags:null,lineBreakerTags:null,imageStyles:null,linkStyles:null,paragraphStyles:null,tableStyles:null,tableCellStyles:null,aceVendorPath:'/',readOnly:false}
RichEditor.prototype.init=function(){var self=this;this.$el.one('dispose-control',this.proxy(this.dispose))
if(!this.$textarea.attr('id')){this.$textarea.attr('id','element-'+Math.random().toString(36).substring(7))}
this.initFroala()}
@ -184,6 +184,9 @@ froalaOptions.imageUploadParams=froalaOptions.fileUploadParams={X_OCTOBER_MEDIA_
var placeholder=this.$textarea.attr('placeholder')
froalaOptions.placeholderText=placeholder?placeholder:''
froalaOptions.height=this.$el.hasClass('stretch')?Infinity:$('.height-indicator',this.$el).height()
var enabledPlugins=['align','audio','codeBeautifier','codeView','colors','draggable','emoticons','entities','file','fontFamily','fontSize','fullscreen','image','lineBreaker','link','lists','paragraphFormat','paragraphStyle','quote','table','url','video','pageLinks','figures']
if(this.options.useMediaManager){enabledPlugins.push('mediaManager')}
froalaOptions.pluginsEnabled=enabledPlugins
$.FroalaEditor.ICON_TEMPLATES={font_awesome:'<i class="icon-[NAME]"></i>',text:'<span style="text-align: center;">[NAME]</span>',image:'<img src=[SRC] alt=[ALT] />'}
this.$textarea.on('froalaEditor.initialized',this.proxy(this.build))
this.$textarea.on('froalaEditor.contentChanged',this.proxy(this.onChange))

View File

@ -39,6 +39,7 @@
stylesheet: null,
fullpage: false,
editorLang: 'en',
useMediaManager: false,
toolbarButtons: null,
allowEmptyTags: null,
allowTags: null,
@ -167,6 +168,12 @@
? Infinity
: $('.height-indicator', this.$el).height()
var enabledPlugins = ['align', 'audio', 'codeBeautifier', 'codeView', 'colors', 'draggable', 'emoticons', 'entities', 'file', 'fontFamily', 'fontSize', 'fullscreen', 'image', 'lineBreaker', 'link', 'lists', 'paragraphFormat', 'paragraphStyle', 'quote', 'table', 'url', 'video', 'pageLinks', 'figures']
if (this.options.useMediaManager) {
enabledPlugins.push('mediaManager')
}
froalaOptions.pluginsEnabled = enabledPlugins
$.FroalaEditor.ICON_TEMPLATES = {
font_awesome: '<i class="icon-[NAME]"></i>',
text: '<span style="text-align: center;">[NAME]</span>',

View File

@ -7,6 +7,7 @@
class="field-richeditor size-<?= $size ?> <?= $stretch?'layout-relative stretch':'' ?>"
<?php if ($fullPage): ?>data-fullpage="true"<?php endif ?>
<?php if ($readOnly): ?>data-read-only="true"<?php endif ?>
<?php if ($useMediaManager): ?>data-use-media-manager="true"<?php endif ?>
<?php if ($editorLang): ?>data-editor-lang="<?= $editorLang ?>"<?php endif ?>
<?php if ($toolbarButtons): ?>data-toolbar-buttons="<?= implode(',', $toolbarButtons) ?>"
<?php elseif ($globalToolbarButtons): ?>data-toolbar-buttons="<?= str_replace(" ", "", $globalToolbarButtons) ?>"<?php endif ?>