Skip to content

Commit

Permalink
feat(ckeditor): replaced ckeditor4 with ckeditor5
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalsem committed Mar 24, 2023
1 parent 6da6a34 commit 52ea348
Show file tree
Hide file tree
Showing 194 changed files with 8,094 additions and 1,045 deletions.
1 change: 1 addition & 0 deletions actions/admin/site/settings.php
Expand Up @@ -74,6 +74,7 @@
elgg_save_config('comments_latest_first', (bool) get_input('comments_latest_first'));
elgg_save_config('comments_per_page', (int) get_input('comments_per_page'));
elgg_save_config('pagination_behaviour', get_input('pagination_behaviour', 'ajax-replace'));
elgg_save_config('mentions_display_format', get_input('mentions_display_format'));

elgg_save_config('user_joined_river', get_input('user_joined_river') === 'on');
elgg_save_config('can_change_username', get_input('can_change_username') === 'on');
Expand Down
9 changes: 9 additions & 0 deletions docs/appendix/upgrade-notes/4.x-to-5.0.rst
Expand Up @@ -5,6 +5,14 @@ From 4.x to 5.0
:local:
:depth: 1

CKEditor
--------

The editor has been updated to version 5. This brings some new features (like mentions and images in content) but also impacts existing plugins.
Most notable are The Wire (which now also has mention support) and the removal of the Embed plugin.

The related 'longtext' menu is no longer available.

Composer
--------

Expand Down Expand Up @@ -431,6 +439,7 @@ Removed functions
* ``groups_prepare_form_vars``
* ``messages_prepare_form_vars``
* ``pages_prepare_form_vars``
* ``thewire_latest_guid``

Removed class functions
~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
5 changes: 4 additions & 1 deletion docs/guides/events-list.rst
Expand Up @@ -912,8 +912,11 @@ Routing
Views
=====

**attributes, htmlawed** |results|
Allows changes to individual attributes.

**allowed_styles, htmlawed** |results|
Filter the HTMLawed allowed style array.
Configure allowed styles for HTMLawed.

**config, htmlawed** |results|
Filter the HTMLawed ``$config`` array.
Expand Down
30 changes: 30 additions & 0 deletions docs/plugins/ckeditor.rst
@@ -0,0 +1,30 @@
CKEditor
========

With this plugin enabled the longtext input fields will get a WYSIWYG editor which allows for some additional markup options for your text.

Depending on the configuration the editor can be enriched with various text style markup options.
Have a look at the CKEditor website for a full featured editor.

Images
------
Elgg also supports uploading images in the editor.
You can upload images using a file dialog or just drag/drop or copy/paste the image into the editor.

Mentions
--------
With the CKEditor plugin you also enable mention capabilities. By default you can mention:

- Users: use `@` to start autocompleting users
- Groups: use `!` to start autocompleting groups
- Searchable content: use `[` to start autocompleting content

When you select something from the autocomplete list a link to the selected user/group/content will be added to the content.
Based on the mentioned users preference they will also be notified they have been mentioned.

Toolbar configuration
---------------------
This plugin provides a standard toolbar configuration for the default and simple editor.
The plugin settings allow you to configure a custom toolbar config.
Almost all ckeditor plugins are available for use.
Information on how to configure a toolbar can be found here: https://ckeditor.com/docs/ckeditor5/latest/features/toolbar/toolbar.html
2 changes: 1 addition & 1 deletion docs/plugins/index.rst
Expand Up @@ -7,6 +7,7 @@ Elgg comes with a set of plugins. These provide the basic functionality for your
:maxdepth: 1

blog
ckeditor
dashboard
discussions
file
Expand All @@ -25,7 +26,6 @@ The following plugins are also bundled with Elgg, but are not (yet) documented

- activity
- bookmarks
- ckeditor
- custom_index
- developers
- externalpages
Expand Down
2 changes: 2 additions & 0 deletions engine/classes/Elgg/Application/SystemEventHandlers.php
Expand Up @@ -3,6 +3,7 @@
namespace Elgg\Application;

use Elgg\Notifications\CreateCommentEventHandler;
use Elgg\Notifications\MentionsEventHandler;
use Elgg\Notifications\UnbanUserEventHandler;
use Elgg\Notifications\MakeAdminUserEventHandler;
use Elgg\Notifications\RemoveAdminUserEventHandler;
Expand Down Expand Up @@ -36,6 +37,7 @@ public static function init() {
}

elgg_register_notification_event('object', 'comment', ['create'], CreateCommentEventHandler::class);
elgg_register_notification_event('object', 'comment', ['mentions'], MentionsEventHandler::class);
elgg_register_notification_event('user', 'user', ['make_admin'], MakeAdminUserEventHandler::class);
elgg_register_notification_event('user', 'user', ['remove_admin'], RemoveAdminUserEventHandler::class);
elgg_register_notification_event('user', 'user', ['unban'], UnbanUserEventHandler::class);
Expand Down
2 changes: 2 additions & 0 deletions engine/classes/Elgg/Config.php
Expand Up @@ -74,6 +74,7 @@
* @property bool $memcache
* @property string $memcache_namespace_prefix
* @property array $memcache_servers
* @property string $mentions_display_format How should a mention be displayed
* @property int $min_password_length The minimal length of a password
* @property int $min_password_lower The minimal number of lower case characters in a password
* @property int $min_password_upper The minimal number of upper case characters in a password
Expand Down Expand Up @@ -209,6 +210,7 @@ class Config {
'language' => 'en',
'language_detect_from_browser' => true,
'lastcache' => 0,
'mentions_display_format' => 'display_name',
'message_delay' => 6,
'min_password_length' => 6,
'minusername' => 4,
Expand Down
76 changes: 63 additions & 13 deletions engine/classes/Elgg/Input/ValidateInputHandler.php
Expand Up @@ -47,8 +47,6 @@ public function __invoke(\Elgg\Event $event) {
'hook_tag' => '_elgg_htmlawed_tag_post_processor',

'schemes' => '*:http,https,ftp,news,mailto,rtsp,teamspeak,gopher,mms,callto',
// apparent this doesn't work.
// 'style:color,cursor,text-align,font-size,font-weight,font-style,border,margin,padding,float'
];

// add nofollow to all links on output
Expand All @@ -61,19 +59,71 @@ public function __invoke(\Elgg\Event $event) {

if (!is_array($var)) {
return \Htmlawed::filter($var, $config, $spec);
} else {
$callback = function (&$v, $k, $config_spec) {
if (!is_string($v) || empty($v)) {
return;
}

list ($config, $spec) = $config_spec;
$v = \Htmlawed::filter($v, $config, $spec);
};
}

$callback = function (&$v, $k, $config_spec) {
if (!is_string($v) || empty($v)) {
return;
}

array_walk_recursive($var, $callback, [$config, $spec]);
list ($config, $spec) = $config_spec;
$v = \Htmlawed::filter($v, $config, $spec);
};

array_walk_recursive($var, $callback, [$config, $spec]);

return $var;
}

/**
* Sanitizes style attribute
*
* This function triggers the 'allowed_styles', 'htmlawed' event
*
* @param \Elgg\Event $event 'attributes', 'htmlawed'
*
* @return void|array
*/
public static function sanitizeStyles(\Elgg\Event $event) {
$attributes = $event->getValue();
$style = elgg_extract('style', $attributes);
if (empty($style)) {
return;
}

$allowed_styles = [
'color', 'cursor', 'text-align', 'vertical-align', 'font-size',
'font-weight', 'font-style', 'border', 'border-top', 'background-color',
'border-bottom', 'border-left', 'border-right',
'margin', 'margin-top', 'margin-bottom', 'margin-left',
'margin-right', 'padding', 'float', 'text-decoration',
];

$allowed_styles = elgg_trigger_event_results('allowed_styles', 'htmlawed', ['tag' => $event->getParam('tag')], $allowed_styles);

$styles = explode(';', $style);

$style_str = '';
foreach ($styles as $style) {
if (!trim($style) || !str_contains($style, ':')) {
continue;
}

return $var;
list($style_attr, $style_value) = explode(':', trim($style));
$style_attr = trim($style_attr);
$style_value = trim($style_value);

if (in_array($style_attr, $allowed_styles)) {
$style_str .= "{$style_attr}: {$style_value}; ";
}
}

if (empty($style_str)) {
unset($attributes['style']);
} else {
$attributes['style'] = trim($style_str);
}

return $attributes;
}
}
35 changes: 35 additions & 0 deletions engine/classes/Elgg/Notifications/MentionsEnqueueEventHandler.php
@@ -0,0 +1,35 @@
<?php

namespace Elgg\Notifications;

/**
* Enqueue mention notifications
*
* @since 5.0
*/
class MentionsEnqueueEventHandler {

/**
* @var array Contains entity GUIDs already queued this script run (to prevent doubles)
*/
protected static array $queued = [];

/**
* Queue a mentions notification event for later handling
*
* @param \Elgg\Event $event 'create:after'|'update:after', 'all'
*
* @return void
*/
public function __invoke(\Elgg\Event $event) {
$object = $event->getObject();
if (!$object instanceof \ElggEntity || $object->access_id === ACCESS_PRIVATE || in_array($object->guid, self::$queued)) {
return;
}

// prevent double enqueue
self::$queued[] = $object->guid;

_elgg_services()->notifications->enqueueEvent('mentions', $object);
}
}

0 comments on commit 52ea348

Please sign in to comment.