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 1 commit
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
Prev Previous commit
Next Next commit
fix how regex for RTE configs are built
  • Loading branch information
intoeetive committed Mar 21, 2024
commit 05528b6bab713a185e34a596776dfee3a37ddf0d
35 changes: 35 additions & 0 deletions system/ee/ExpressionEngine/Addons/rte/Service/CkeditorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,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
19 changes: 0 additions & 19 deletions themes/ee/asset/javascript/src/fields/rte/rte.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ window.Rte;

this.config = (EE.Rte.configs[config] || EE.Rte.configs['default']);

if (typeof(this.config.typing) !== 'undefined' && typeof(this.config.typing.transformations) !== 'undefined' && typeof(this.config.typing.transformations.extra) !== 'undefined') {
for (const index in this.config.typing.transformations.extra) {
var value = this.config.typing.transformations.extra[index];
if (typeof value.from === 'string' && value.from.indexOf('/') === 0 && value.from.lastIndexOf('$/') === value.from.length - 2) {
this.config.typing.transformations.extra[index].from = new RegExp(value.from.substring(1, value.from.length - 2) + '$');
}
}
}

if (typeof defer == "undefined") {
this.defer = this.$element.data('defer') == "y";
} else {
Expand Down Expand Up @@ -139,16 +130,6 @@ window.Rte;
* Init CKEditor
*/
initCKEditor: function() {
if (typeof this.config.htmlSupport !== 'undefined') {
if (typeof this.config.htmlSupport.allow !== 'undefined') {
this.config.htmlSupport.allow.forEach((elem, index) => {
var value = this.config.htmlSupport.allow[index];
if (typeof value.name === 'string' && value.name.indexOf('/') === 0 && value.name.lastIndexOf('/') === value.name.length - 1) {
this.config.htmlSupport.allow[index].name = new RegExp(value.name.substring(1, value.name.length - 1));
}
})
}
}
var textareaId = this.id;
ClassicEditor.create(document.querySelector('#'+this.id), this.config)
.then( editor => {
Expand Down