Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable uploading file into RTE (CKEditor) field with drag&drop in CP and Channel Form #4171

Open
wants to merge 19 commits into
base: 7.dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions cp-styles/app/styles/components/_rte.scss
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,52 @@ a.ck.ck-button.ck-on {
border-color: var(--ee-button-secondary-hover-border) !important;
}

.ck.ck-dialog {
background: var(--ee-button-default-bg) !important;
color: var(--ee-button-default-color) !important;
border-color: var(--ee-list-item-border) !important;
}

.ck.ck-dialog h2 {
color: var(--ee-button-default-color) !important;
}

.ck.ck-find-and-replace-form__actions {
margin-top: 10px !important;
}

.ck.ck-labeled-field-view .ck-labeled-field-view__status.ck-labeled-field-view__status_error {
color: var(--ee-error) !important;
}

// STYLES FOR CKEDITOR LABEL
.ck.ck-labeled-field-view .ck-labeled-field-view__status.ck-labeled-field-view__status_error {
color: var(--ee-error) !important;
}

.ck.ck-balloon-panel.ck-powered-by-balloon .ck-powered-by:hover {
filter: grayscale(1);
}

.ck.ck-balloon-panel.ck-powered-by-balloon .ck.ck-powered-by a {
padding: 1px;
}

.ck.ck-balloon-panel.ck-powered-by-balloon .ck.ck-powered-by .ck-powered-by__label {
color: var(--ee-text-secondary);
opacity: 0.5;
font-size: 6px;
}

.ck.ck-balloon-panel.ck-powered-by-balloon .ck.ck-powered-by .ck-icon {
color: var(--ee-text-secondary);
opacity: 0.3;
}

.ck.ck-widget__resizer {
background: transparent !important;
}

// REDACTORX STYLES
.rx-toolbar,
.rx-topbar {
Expand Down
51 changes: 47 additions & 4 deletions system/ee/ExpressionEngine/Addons/rte/Service/CkeditorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,41 @@ protected function insertConfigJsById()
'Rte.configs.' . $configHandle => $config
]);

// some config values are regular expressions, re-decleare those as such
$configRegex = [];
if (isset($config['htmlSupport']) && isset($config['htmlSupport']->allow)) {
foreach ($config['htmlSupport'] as $property => $htmlSupport) {
foreach ($htmlSupport as $i => $allowDisallow) {
foreach ($allowDisallow as $key => $value) {
if (is_string($value) && strpos($value, '/') === 0 && strrpos($value, '/') === strlen($value) - 1) {
$configRegex[] = 'EE.Rte.configs.' . $configHandle . '.htmlSupport.' . $property . '[' . $i . '].' . $key . ' = new RegExp(' . $value . ');';
} elseif (is_array($value)) {
foreach ($value as $j => $v) {
if (is_string($v) && strpos($v, '/') === 0 && strrpos($v, '/') === strlen($v) - 1) {
$configRegex[] = 'EE.Rte.configs.' . $configHandle . '.htmlSupport.' . $property . '[' . $i . '].' . $key . '[' . $j . '] = new RegExp(' . $v . ');';
}
}
}
}
}
}
}
if (isset($config['typing']) && isset($config['typing']->transformations) && isset($config['typing']->transformations->extra)) {
foreach ($config['typing']->transformations->extra as $i => $extra) {
foreach ($extra as $key => $value) {
if (is_string($value) && strpos($value, '/') === 0 && strrpos($value, '/') === strlen($value) - 1) {
$configRegex[] = 'EE.Rte.configs.typing.transformations.extra[' . $i . '].' . $key . ' = new RegExp(' . $value . ');';
}
}
}
}

if (!empty($configRegex)) {
ee()->cp->add_to_foot('<script type="text/javascript">
' . implode("\n", $configRegex) . '
</script>');
}

static::$_includedConfigs[] = $configHandle;

if (isset($config['height']) && !empty($config['height'])) {
Expand Down Expand Up @@ -259,13 +294,21 @@ public function buildToolbarConfig($config)
$toolbarConfig['htmlEmbed'] = new \stdClass();
$toolbarConfig['htmlEmbed']->showPreviews = true;

// By default, we allow some block elements & span with any data-attribute and any class
// Plus the elements that have corresponding plugin or button - such as table, link, image, etc.
// We also allow classes, but not styles
// If the mode "do anything when in source editing" needs to be enable, set up advanaced config like this:
// https://ckeditor.com/docs/ckeditor5/latest/features/html/general-html-support.html#enabling-all-html-features
// However this is ponetially dangerous and also will break "paste from Word" filters
$allowedHtml = new \stdClass();
$allowedHtml->name = '/.*/';
$allowedHtml->attributes = true;
$allowedHtml->name = '/^(div|section|article|span)$/';
$allowedHtml->attributes = '/data-[\w-]+/';
$allowedHtml->classes = true;
$allowedHtml->styles = true;
$allowedHtml->styles = false;
$toolbarConfig['htmlSupport'] = new \stdClass();
$toolbarConfig['htmlSupport']->allow = [$allowedHtml];
$toolbarConfig['htmlSupport']->allow = [
$allowedHtml
];

if (in_array('heading', $toolbarConfig['toolbar']->items)) {
$toolbarConfig['heading'] = new \stdClass();
Expand Down

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions themes/ee/cp/css/common.min.css
Original file line number Diff line number Diff line change
Expand Up @@ -47497,6 +47497,51 @@ a.ck.ck-button.ck-on {
border-color: var(--ee-button-secondary-hover-border) !important;
}

.ck.ck-dialog {
background: var(--ee-button-default-bg) !important;
color: var(--ee-button-default-color) !important;
border-color: var(--ee-list-item-border) !important;
}

.ck.ck-dialog h2 {
color: var(--ee-button-default-color) !important;
}

.ck.ck-find-and-replace-form__actions {
margin-top: 10px !important;
}

.ck.ck-labeled-field-view .ck-labeled-field-view__status.ck-labeled-field-view__status_error {
color: var(--ee-error) !important;
}

.ck.ck-labeled-field-view .ck-labeled-field-view__status.ck-labeled-field-view__status_error {
color: var(--ee-error) !important;
}

.ck.ck-balloon-panel.ck-powered-by-balloon .ck-powered-by:hover {
filter: grayscale(1);
}

.ck.ck-balloon-panel.ck-powered-by-balloon .ck.ck-powered-by a {
padding: 1px;
}

.ck.ck-balloon-panel.ck-powered-by-balloon .ck.ck-powered-by .ck-powered-by__label {
color: var(--ee-text-secondary);
opacity: 0.5;
font-size: 6px;
}

.ck.ck-balloon-panel.ck-powered-by-balloon .ck.ck-powered-by .ck-icon {
color: var(--ee-text-secondary);
opacity: 0.3;
}

.ck.ck-widget__resizer {
background: transparent !important;
}

.rx-toolbar .rx-button-toolbar,
.rx-toolbar .rx-button-topbar,
.rx-topbar .rx-button-toolbar,
Expand Down