Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
34 changes: 9 additions & 25 deletions libraries/src/Editor/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,38 +277,22 @@ protected function _loadEditor($config = array())

// Build the path to the needed editor plugin
$name = InputFilter::getInstance()->clean($this->_name, 'cmd');
$path = JPATH_PLUGINS . '/editors/' . $name . '/' . $name . '.php';

if (!is_file($path)) {
Log::add(Text::_('JLIB_HTML_EDITOR_CANNOT_LOAD'), Log::WARNING, 'jerror');

return false;
}
// Boot the editor plugin
$this->_editor = Factory::getApplication()->bootPlugin($name, 'editors');

// Require plugin file
require_once $path;

// Get the plugin
$plugin = PluginHelper::getPlugin('editors', $this->_name);
// Check if the editor can be loaded
if (!$this->_editor) {
Log::add(Text::_('JLIB_HTML_EDITOR_CANNOT_LOAD'), Log::WARNING, 'jerror');

// If no plugin is published we get an empty array and there not so much to do with it
if (empty($plugin)) {
return false;
}

$params = new Registry($plugin->params);
$params->loadArray($config);
$plugin->params = $params;
$this->_editor->params->loadArray($config);

// Build editor plugin classname
$name = 'PlgEditor' . $this->_name;
$this->initialise();
PluginHelper::importPlugin('editors-xtd');

$dispatcher = $this->getDispatcher();

if ($this->_editor = new $name($dispatcher, (array) $plugin)) {
// Load plugin parameters
$this->initialise();
PluginHelper::importPlugin('editors-xtd');
}
return true;
}
}
7 changes: 6 additions & 1 deletion libraries/src/Extension/ExtensionManagerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,13 @@ private function loadPluginFromFilesystem(string $plugin, string $type)
// Compile the classname
$className = 'Plg' . str_replace('-', '', $type) . $plugin;

// Editors don't follow the convention
if ($type === 'editors') {
$className = 'PlgEditor' . ucfirst($plugin);
}

// Editor buttons don't follow the convention
if ($type === 'editors-xtd') {
// This type doesn't follow the convention
$className = 'PlgEditorsXtd' . $plugin;

if (!class_exists($className)) {
Expand Down
51 changes: 51 additions & 0 deletions plugins/editors/tinymce/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Editors.tinymce
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Editors\TinyMCE\Extension\TinyMCE;

return new class implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);

$plugin = new TinyMCE(
$dispatcher,
(array) PluginHelper::getPlugin('editors', 'tinymce')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));

return $plugin;
}
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
*
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt

* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/

namespace Joomla\Plugin\Editors\TinyMCE\Extension;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Plugin\Editors\TinyMCE\PluginTraits\DisplayTrait;

// phpcs:disable PSR1.Files.SideEffects
Expand All @@ -22,18 +23,10 @@
*
* @since 1.5
*/
class PlgEditorTinymce extends CMSPlugin
final class TinyMCE extends CMSPlugin
{
use DisplayTrait;

/**
* Base path for editor files
*
* @since 3.5
*
* @deprecated 5.0
*/
protected $_basePath = 'media/vendor/tinymce';
use DatabaseAwareTrait;

/**
* Load the language file on instantiation.
Expand All @@ -44,15 +37,7 @@ class PlgEditorTinymce extends CMSPlugin
protected $autoloadLanguage = true;

/**
* Loads the application object
*
* @var \Joomla\CMS\Application\CMSApplication
* @since 3.2
*/
protected $app = null;

/**
* Initialises the Editor.
* Initializes the Editor.
*
* @return void
*
Expand Down
8 changes: 3 additions & 5 deletions plugins/editors/tinymce/src/Field/TinymcebuilderField.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Joomla\CMS\Form\FormField;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Plugin\Editors\TinyMCE\Extension\TinyMCE;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -74,9 +75,6 @@ protected function getLayoutData()
$data['value'] = array();
}

// Get the plugin
require_once JPATH_PLUGINS . '/editors/tinymce/tinymce.php';

$menus = array(
'edit' => array('label' => 'Edit'),
'insert' => array('label' => 'Insert'),
Expand All @@ -89,9 +87,9 @@ protected function getLayoutData()

$data['menus'] = $menus;
$data['menubarSource'] = array_keys($menus);
$data['buttons'] = \PlgEditorTinymce::getKnownButtons();
$data['buttons'] = TinyMCE::getKnownButtons();
$data['buttonsSource'] = array_keys($data['buttons']);
$data['toolbarPreset'] = \PlgEditorTinymce::getToolbarPreset();
$data['toolbarPreset'] = TinyMCE::getToolbarPreset();
$data['setsAmount'] = $setsAmount;

// Get array of sets names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ trait ActiveSiteTemplate
*/
protected function getActiveSiteTemplate()
{
$db = Factory::getContainer()->get('db');
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select('*')
->from($db->quoteName('#__template_styles'))
Expand All @@ -50,7 +50,7 @@ protected function getActiveSiteTemplate()
try {
return $db->loadObject();
} catch (RuntimeException $e) {
$this->app->enqueueMessage(Text::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
$this->getApplication()->enqueueMessage(Text::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');

return new \stdClass();
}
Expand Down
12 changes: 6 additions & 6 deletions plugins/editors/tinymce/src/PluginTraits/DisplayTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public function onDisplay(
$params = []
) {
$id = empty($id) ? $name : $id;
$user = $this->app->getIdentity();
$language = $this->app->getLanguage();
$doc = $this->app->getDocument();
$user = $this->getApplication()->getIdentity();
$language = $this->getApplication()->getLanguage();
$doc = $this->getApplication()->getDocument();
$id = preg_replace('/(\s|[^A-Za-z0-9_])+/', '_', $id);
$nameGroup = explode('[', preg_replace('/\[\]|\]/', '', $name));
$fieldName = end($nameGroup);
Expand All @@ -94,7 +94,7 @@ public function onDisplay(
// Render Editor markup
$editor = '<div class="js-editor-tinymce">';
$editor .= LayoutHelper::render('joomla.tinymce.textarea', $textarea);
$editor .= !$this->app->client->mobile ? LayoutHelper::render('joomla.tinymce.togglebutton') : '';
$editor .= !$this->getApplication()->client->mobile ? LayoutHelper::render('joomla.tinymce.togglebutton') : '';
$editor .= '</div>';

// Prepare the instance specific options
Expand Down Expand Up @@ -176,7 +176,7 @@ public function onDisplay(
$levelParams->loadObject($extraOptions);

// Set the selected skin
$skin = $levelParams->get($this->app->isClient('administrator') ? 'skin_admin' : 'skin', 'oxide');
$skin = $levelParams->get($this->getApplication()->isClient('administrator') ? 'skin_admin' : 'skin', 'oxide');

// Check that selected skin exists.
$skin = Folder::exists(JPATH_ROOT . '/media/vendor/tinymce/skins/ui/' . $skin) ? $skin : 'oxide';
Expand Down Expand Up @@ -362,7 +362,7 @@ public function onDisplay(
if ($dragdrop && $user->authorise('core.create', 'com_media')) {
$externalPlugins['jdragndrop'] = HTMLHelper::_('script', 'plg_editors_tinymce/plugins/dragdrop/plugin.min.js', ['relative' => true, 'version' => 'auto', 'pathOnly' => true]);
$uploadUrl = Uri::base(false) . 'index.php?option=com_media&format=json&url=1&task=api.files';
$uploadUrl = $this->app->isClient('site') ? htmlentities($uploadUrl, ENT_NOQUOTES, 'UTF-8', false) : $uploadUrl;
$uploadUrl = $this->getApplication()->isClient('site') ? htmlentities($uploadUrl, ENT_NOQUOTES, 'UTF-8', false) : $uploadUrl;

Text::script('PLG_TINY_ERR_UNSUPPORTEDBROWSER');
Text::script('ERROR');
Expand Down
2 changes: 1 addition & 1 deletion plugins/editors/tinymce/tinymce.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<description>PLG_TINY_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Editors\TinyMCE</namespace>
<files>
<filename plugin="tinymce">tinymce.php</filename>
<folder>forms</folder>
<folder plugin="tinymce">services</folder>
<folder>src</folder>
</files>
<media destination="editors" folder="media">
Expand Down