refactoring

This commit is contained in:
O3-Shop 2023-04-05 08:53:11 +02:00
bovenliggende efa900bb91
commit e6278a71e9
34 gewijzigde bestanden met toevoegingen van 225 en 100 verwijderingen

Bestand weergeven

@ -30,6 +30,7 @@ use O3\TinyMCE\Application\Core\TinyMCE\Options\ContextMenu;
use O3\TinyMCE\Application\Core\TinyMCE\Options\DocumentBaseUrl;
use O3\TinyMCE\Application\Core\TinyMCE\Options\EntityEncoding;
use O3\TinyMCE\Application\Core\TinyMCE\Options\ExternalPlugins;
use O3\TinyMCE\Application\Core\TinyMCE\Options\FilePickerCallback;
use O3\TinyMCE\Application\Core\TinyMCE\Options\FilemanagerUrl;
use O3\TinyMCE\Application\Core\TinyMCE\Options\ImageAdvtab;
use O3\TinyMCE\Application\Core\TinyMCE\Options\Language;
@ -44,6 +45,7 @@ use O3\TinyMCE\Application\Core\TinyMCE\Options\QuickbarsInsertToolbar;
use O3\TinyMCE\Application\Core\TinyMCE\Options\RelativeUrls;
use O3\TinyMCE\Application\Core\TinyMCE\Options\Selector;
use O3\TinyMCE\Application\Core\TinyMCE\Options\Toolbar;
use O3\TinyMCE\Application\Core\TinyMCE\Options\ToolbarMode;
use O3\TinyMCE\Application\Core\TinyMCE\Options\ToolbarSticky;
class Configuration
@ -68,7 +70,7 @@ class Configuration
$this->addToolbar();
}
protected function addOption($key, OptionInterface $optionInstance): void
protected function addOption(OptionInterface $optionInstance): void
{
if (!$optionInstance->requireRegistration()) return;
@ -78,7 +80,7 @@ class Configuration
$option = (oxNew(Utils::class))->quote($option);
}
$this->options[$key] = $option;
$this->options[$optionInstance->getKey()] = $option;
}
public function getConfig()
@ -113,54 +115,56 @@ class Configuration
*/
protected function addIntegrateOptions(): void
{
$this->addOption( BaseUrl::KEY, oxNew( BaseUrl::class, $this->loader));
$this->addOption( CacheSuffix::KEY, oxNew( CacheSuffix::class, $this->loader));
$this->addOption( Selector::KEY, oxNew( Selector::class, $this->loader));
$this->addOption(oxNew( BaseUrl::class, $this->loader));
$this->addOption(oxNew( CacheSuffix::class, $this->loader));
$this->addOption(oxNew( Selector::class, $this->loader));
}
protected function addGuiOptions(): void
{
$this->addOption(ContextMenu::KEY, oxNew(ContextMenu::class, $this->loader));
$this->addOption(MinHeight::KEY, oxNew(MinHeight::class, $this->loader));
$this->addOption(MaxHeight::KEY, oxNew(MaxHeight::class, $this->loader));
$this->addOption(MaxWidth::KEY, oxNew(MaxWidth::class, $this->loader));
$this->addOption(Menubar::KEY, oxNew(Menubar::class, $this->loader));
$this->addOption(ToolbarSticky::KEY, oxNew(ToolbarSticky::class, $this->loader));
$this->addOption(oxNew(ContextMenu::class, $this->loader));
$this->addOption(oxNew(MinHeight::class, $this->loader));
$this->addOption(oxNew(MaxHeight::class, $this->loader));
$this->addOption(oxNew(MaxWidth::class, $this->loader));
$this->addOption(oxNew(Menubar::class, $this->loader));
$this->addOption(oxNew(ToolbarSticky::class, $this->loader));
$this->addOption(oxNew(ToolbarMode::class, $this->loader));
}
protected function addContentAppearance(): void
{
$this->addOption(ContentCss::KEY, oxNew(ContentCss::class,$this->loader));
$this->addOption(oxNew(ContentCss::class,$this->loader));
}
protected function addContentFiltering(): void
{
$this->addOption(EntityEncoding::KEY, oxNew(EntityEncoding::class,$this->loader));
$this->addOption(Protect::KEY, oxNew(Protect::class,$this->loader));
$this->addOption(oxNew(EntityEncoding::class,$this->loader));
$this->addOption(oxNew(Protect::class,$this->loader));
}
protected function addLocalizationOptions(): void
{
$this->addOption( Language::KEY, oxNew( Language::class, $this->loader));
$this->addOption(oxNew( Language::class, $this->loader));
}
protected function addUrlHandling(): void
{
$this->addOption( DocumentBaseUrl::KEY, oxNew( DocumentBaseUrl::class, $this->loader));
$this->addOption( RelativeUrls::KEY, oxNew( RelativeUrls::class, $this->loader));
$this->addOption(oxNew( DocumentBaseUrl::class, $this->loader));
$this->addOption(oxNew( RelativeUrls::class, $this->loader));
}
protected function addPlugins(): void
{
$this->addOption( ImageAdvtab::KEY, oxNew( ImageAdvtab::class, $this->loader));
$this->addOption( Plugins::KEY, oxNew( Plugins::class, $this->loader));
$this->addOption( ExternalPlugins::KEY, oxNew( ExternalPlugins::class, $this->loader));
$this->addOption( FilemanagerUrl::KEY, oxNew( FilemanagerUrl::class, $this->loader));
$this->addOption(QuickbarsInsertToolbar::KEY, oxNew(QuickbarsInsertToolbar::class, $this->loader));
$this->addOption(oxNew( ImageAdvtab::class, $this->loader));
$this->addOption(oxNew( Plugins::class, $this->loader));
$this->addOption(oxNew( ExternalPlugins::class, $this->loader));
$this->addOption(oxNew( FilemanagerUrl::class, $this->loader));
$this->addOption(oxNew( FilePickerCallback::class, $this->loader));
$this->addOption(oxNew(QuickbarsInsertToolbar::class, $this->loader));
}
protected function addToolbar(): void
{
$this->addOption( Toolbar::KEY, oxNew( Toolbar::class, $this->loader));
$this->addOption(oxNew( Toolbar::class, $this->loader));
}
}
}

Bestand weergeven

@ -43,11 +43,11 @@ class Loader
/**
* @return string
*/
public function getEditorSwitch(): string
public function getEditorCode(): string
{
if (!$this->isEnabledForCurrentController()) return '';
if ($this->contentIsPlain()) return $this->language->translateString('BLA_TINYMCE_PLAINCMS');
if ($this->contentIsPlain()) return $this->language->translateString('TINYMCE_PLAINCMS');
$configuration = oxNew(Configuration::class, $this);
$configuration->build();

Bestand weergeven

@ -27,6 +27,8 @@ use O3\TinyMCE\Application\Core\TinyMCE\Loader;
abstract class AbstractOption implements OptionInterface
{
protected string $key = 'undefinedKey';
protected Loader $loader;
public function __construct(Loader $loader)
@ -34,6 +36,14 @@ abstract class AbstractOption implements OptionInterface
$this->loader = $loader;
}
/**
* @return string
*/
public function getKey(): string
{
return $this->key;
}
abstract public function get(): string;
public function mustQuote(): bool

Bestand weergeven

@ -25,7 +25,7 @@ namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
class BaseUrl extends AbstractOption
{
public const KEY = 'base_url';
protected string $key = 'base_url';
/**
* @return string

Bestand weergeven

@ -27,7 +27,7 @@ use O3\TinyMCE\Application\Core\TinyMCE\Loader;
class CacheSuffix extends AbstractOption
{
public const KEY = 'cache_suffix';
protected string $key = 'cache_suffix';
protected Loader $loader;

Bestand weergeven

@ -24,21 +24,21 @@ declare(strict_types=1);
namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
use O3\TinyMCE\Application\Core\TinyMCE\Loader;
use OxidEsales\Eshop\Core\Registry;
class ContentCss extends AbstractOption
{
public const KEY = 'content_css';
protected string $key = 'content_css';
protected Loader $loader;
public function get(): string
{
// ToDo: use current theme
return '/out/wave/src/css/styles.min.css';
return '/out/'.strtolower(Registry::getConfig()->getConfigParam('sTheme')).'/src/css/styles.min.css';
}
public function mustQuote(): bool
{
return true;
}
}
}

Bestand weergeven

@ -25,7 +25,7 @@ namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
class ContextMenu extends AbstractOption
{
public const KEY = 'contextmenu';
protected string $key = 'contextmenu';
public function get(): string
{

Bestand weergeven

@ -27,7 +27,7 @@ use OxidEsales\Eshop\Core\Registry;
class DocumentBaseUrl extends AbstractOption
{
public const KEY = 'document_base_url';
protected string $key = 'document_base_url';
public function get(): string
{

Bestand weergeven

@ -27,7 +27,7 @@ use O3\TinyMCE\Application\Core\TinyMCE\Loader;
class EntityEncoding extends AbstractOption
{
public const KEY = 'entity_encoding';
protected string $key = 'entity_encoding';
protected Loader $loader;

Bestand weergeven

@ -29,7 +29,7 @@ use O3\TinyMCE\Application\Core\TinyMCE\Utils;
class ExternalPlugins extends AbstractOption
{
public const KEY = 'external_plugins';
protected string $key = 'external_plugins';
public function get(): string
{

Bestand weergeven

@ -0,0 +1,43 @@
<?php
/**
* This file is part of O3-Shop TinyMCE editor module.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
*
* @copyright Copyright (c) 2022 OXID Marat Bedoev, bestlife AG
* @copyright Copyright (c) 2023 O3-Shop (https://www.o3-shop.com)
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
*/
declare(strict_types=1);
namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
use O3\TinyMCE\Application\Core\TinyMCE\Loader;
class FilePickerCallback extends AbstractOption
{
protected string $key = 'file_picker_callback';
protected Loader $loader;
public function get(): string
{
return 'RoxyFileBrowser';
}
public function requireRegistration(): bool
{
return (bool) $this->loader->getShopConfig()->getConfigParam("blTinyMCE_filemanager");
}
}

Bestand weergeven

@ -29,7 +29,7 @@ use OxidEsales\Eshop\Core\UtilsServer;
class FilemanagerUrl extends AbstractOption
{
public const KEY = 'filemanager_url';
protected string $key = 'filemanager_url';
protected Loader $loader;
@ -41,7 +41,7 @@ class FilemanagerUrl extends AbstractOption
return str_replace(
'&amp;',
'&',
Registry::getConfig()->getActiveView()->getViewConfig()->getSslSelfLink()."cl=tinyfilemanager"
Registry::getConfig()->getActiveView()->getViewConfig()->getSslSelfLink()."cl=tinyfilemanager&input=form-field_3980235013121680647721848"
);
}

Bestand weergeven

@ -25,7 +25,7 @@ namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
class ImageAdvtab extends AbstractOption
{
public const KEY = 'image_advtab';
protected string $key = 'image_advtab';
public function get(): string
{

Bestand weergeven

@ -25,7 +25,7 @@ namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
class Language extends AbstractOption
{
public const KEY = 'language';
protected string $key = 'language';
/**
* @return string

Bestand weergeven

@ -25,7 +25,7 @@ namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
class MaxHeight extends AbstractOption
{
public const KEY = 'max_height';
protected string $key = 'max_height';
public function get(): string
{

Bestand weergeven

@ -25,7 +25,7 @@ namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
class MaxWidth extends AbstractOption
{
public const KEY = 'max_width';
protected string $key = 'max_width';
public function get(): string
{

Bestand weergeven

@ -25,7 +25,7 @@ namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
class Menubar extends AbstractOption
{
public const KEY = 'menubar';
protected string $key = 'menubar';
public function get(): string
{

Bestand weergeven

@ -23,12 +23,20 @@ declare(strict_types=1);
namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
use OxidEsales\Eshop\Core\Registry;
class MinHeight extends AbstractOption
{
public const KEY = 'min_height';
protected string $key = 'min_height';
public function get(): string
{
$profile = Registry::getSession()->getVariable('profile');
if (isset($profile) && $profile[1]) {
return (string) (max($profile[1] * 20, 350));
}
return '350';
}
}

Bestand weergeven

@ -29,6 +29,8 @@ interface OptionInterface
{
public function __construct(Loader $loader);
public function getKey(): string;
public function get(): string;
public function mustQuote(): bool;

Bestand weergeven

@ -28,7 +28,7 @@ use O3\TinyMCE\Application\Core\TinyMCE\Plugins\PluginInterface;
class Plugins extends AbstractOption
{
public const KEY = 'plugins';
protected string $key = 'plugins';
public function get(): string
{

Bestand weergeven

@ -25,7 +25,7 @@ namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
class Protect extends AbstractOption
{
public const KEY = 'protect';
protected string $key = 'protect';
public function get(): string
{

Bestand weergeven

@ -30,13 +30,14 @@ use O3\TinyMCE\Application\Core\TinyMCE\Utils;
class QuickbarsInsertToolbar extends AbstractOption
{
public const KEY = 'quickbars_insert_toolbar';
protected string $key = 'quickbars_insert_toolbar';
public function get(): string
{
return implode(
' | ',
[
// 'quickimage', // disabled, as images are only inserted inline. This is too much for a typical database field length.
'quicktable',
'hr',
'pagebreak'

Bestand weergeven

@ -25,7 +25,7 @@ namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
class RelativeUrls extends AbstractOption
{
public const KEY = 'relative_urls';
protected string $key = 'relative_urls';
public function get(): string
{

Bestand weergeven

@ -27,7 +27,7 @@ use O3\TinyMCE\Application\Core\TinyMCE\Loader;
class Selector extends AbstractOption
{
public const KEY = 'selector';
protected string $key = 'selector';
public function get(): string
{

Bestand weergeven

@ -30,7 +30,9 @@ use O3\TinyMCE\Application\Core\TinyMCE\ToolbarList;
class Toolbar extends AbstractOption
{
public const KEY = 'toolbar';
protected string $key = 'toolbar';
protected bool $forceSingleLineToolbar = true;
public function __construct( Loader $loader )
{
@ -40,6 +42,56 @@ class Toolbar extends AbstractOption
public function get(): string
{
$toolbarList = oxNew(ToolbarList::class);
return $this->forceSingleLineToolbar ?
$this->getSingleLineToolbar($toolbarList) :
$this->getMultiLineToolbar($toolbarList);
}
protected function getSingleLineToolbar($toolbarList)
{
$all = [];
foreach ($toolbarList->get() as $toolbar) {
$all = array_merge($all, $toolbar);
}
$toolbarElements = implode(
' | ',
array_filter(
array_map(
function ($toolbarElement) {
return implode(
' ',
$toolbarElement->getButtons()
);
},
$all
)
)
);
$pluginList = oxNew(PluginList::class);
$pluginToolbarElements = implode(
' | ',
array_filter(
array_map(
function (PluginInterface $plugin) {
return count($plugin->getToolbarElements()) ? implode(
' ',
$plugin->getToolbarElements()
) : null;
},
$pluginList->get()
)
)
);
return $toolbarElements . ' | ' . $pluginToolbarElements;
}
protected function getMultiLineToolbar($toolbarList)
{
$list = [];
foreach ($toolbarList->get() as $toolbar) {
@ -77,4 +129,9 @@ class Toolbar extends AbstractOption
return '["'.implode('", "', $list).'"]';
}
public function mustQuote(): bool
{
return true;
}
}

Bestand weergeven

@ -0,0 +1,39 @@
<?php
/**
* This file is part of O3-Shop TinyMCE editor module.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
*
* @copyright Copyright (c) 2022 OXID Marat Bedoev, bestlife AG
* @copyright Copyright (c) 2023 O3-Shop (https://www.o3-shop.com)
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
*/
declare(strict_types=1);
namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
class ToolbarMode extends AbstractOption
{
protected string $key = 'toolbar_mode';
public function get(): string
{
return 'sliding';
}
public function mustQuote(): bool
{
return true;
}
}

Bestand weergeven

@ -25,7 +25,7 @@ namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
class ToolbarSticky extends AbstractOption
{
public const KEY = 'toolbar_sticky';
protected string $key = 'toolbar_sticky';
public function get(): string
{

Bestand weergeven

@ -28,6 +28,9 @@ class Font extends AbstractToolbar
public function getButtons(): array
{
return [
// 'fontselect',
//'fontsizeselect',
// '|',
'bold',
'italic',
'underline',

Bestand weergeven

@ -58,39 +58,5 @@ class ToolbarList
'removeformat' => oxNew(RemoveFormat::class),
]
];
$all = $this->getAll();
if ($count && isset($all[$count])) {
return $all[$count];
} elseif (!$count) {
$allList = [];
foreach ($all as $toolbars) {
$allList = array_merge($allList, $toolbars);
}
return $allList;
}
}
protected function getAll(): array
{
return [
1 => [
'formatselect' => oxNew(Formatselect::class),
'font' => oxNew(Font::class),
'color' => oxNew(Color::class),
'align' => oxNew(Align::class),
'subscript' => oxNew(Subscript::class),
'superscript' => oxNew(Superscript::class),
],
2 => [
'undo' => oxNew(Undo::class),
'copypaste' => oxNew(CopyPaste::class),
'lists' => oxNew(Lists::class),
'indent' => oxNew(Indent::class),
'blockquote' => oxNew(Blockquote::class),
'removeformat' => oxNew(RemoveFormat::class),
]
];
}
}

Bestand weergeven

@ -38,14 +38,6 @@ class ViewConfig extends ViewConfig_parent
$loader = oxNew(Loader::class, $config, $language);
return $loader->getEditorSwitch();
return $loader->getEditorCode();
}
}
// ToDo:
// https://www.tiny.cloud/docs/tinymce/6/toolbar-configuration-options/
// flexible MinHeight je nach Logineinstellung
// flexibles CSS basierend auf Wave
// MediaSelect Bug

Bestand-diff onderdrukt omdat een of meer regels te lang zijn

Bestand weergeven

@ -19,8 +19,8 @@
$sLangName = 'Deutsch';
$aLang = array(
'charset' => 'UTF-8',
'BLA_TINYMCE_TOGGLE' => 'TinyMCE zeigen/verstecken',
'BLA_TINYMCE_PLAINCMS' => '<b class="errorbox">TinyMCE wurde für diese Seite deaktiviert, weil sie keine HTML Formatierung enthalten darf </b>',
'TINYMCE_TOGGLE' => 'Editor zeigen/verstecken',
'TINYMCE_PLAINCMS' => '<b class="errorbox">TinyMCE wurde für diese Seite deaktiviert, weil sie keine HTML Formatierung enthalten darf </b>',
'SHOP_MODULE_GROUP_tinyMceMain' => '<style type="text/css">.groupExp a.rc b {font-size:medium;color:#ff3600;}.groupExp dt input.txt {width:430px !important} .groupExp dl {display:block !important;} input.confinput {position:fixed;top:20px;right:70px;background:#008B2D;padding:10px 25px;color:white;border:1px solid black;cursor:pointer;font-size:125%;} input.confinput:hover {outline:3px solid #ff3600;} .groupExp dt textarea.txtfield {width:430px;height:150px;}</style>Moduleinstellungen',
'SHOP_MODULE_blTinyMCE_filemanager' => 'Dateimanager aktivieren',
'HELP_SHOP_MODULE_blTinyMCE_filemanager' => 'Ist diese Option aktiv, können Bilder hochgeladen werden. Der Speicherort ist: out/pictures/wysiwigpro/',

Bestand weergeven

@ -2,7 +2,7 @@
<button style="border: 1px solid #0089EE; color: #0089EE;padding: 3px 10px; margin-top: -10px; background: white;"
onclick="tinymce.each(tinymce.editors, function(editor) { if(editor.isHidden()) { editor.show(); } else { editor.hide(); } });">
<span>
[{oxmultilang ident="BLA_TINYMCE_TOGGLE"}]
[{oxmultilang ident="TINYMCE_TOGGLE"}]
</span>
</button>
</li>

Bestand weergeven

@ -19,8 +19,8 @@
$sLangName = 'English';
$aLang = array(
'charset' => 'UTF-8',
'BLA_TINYMCE_TOGGLE' => 'toggle TinyMCE',
'BLA_TINYMCE_PLAINCMS' => '<b class="errorbox">TinyMCE was disabled for this page because it may not contain HTML code</b>',
'TINYMCE_TOGGLE' => 'toggle editor',
'TINYMCE_PLAINCMS' => '<b class="errorbox">TinyMCE was disabled for this page because it may not contain HTML code</b>',
'SHOP_MODULE_GROUP_tinyMceMain' => '<style type="text/css">.groupExp a.rc b {font-size:medium;color:#ff3600;}.groupExp dt input.txt {width:430px !important} .groupExp dl {display:block !important;} input.confinput {position:fixed;top:20px;right:70px;background:#008B2D;padding:10px 25px;color:white;border:1px solid black;cursor:pointer; font-size: 125%; } input.confinput:hover {outline: 3px solid #ff3600;} .groupExp dt textarea.txtfield {width: 430px; height: 150px;}</style>module settings',
'SHOP_MODULE_blTinyMCE_filemanager' => 'enable filemanager',
'HELP_SHOP_MODULE_blTinyMCE_filemanager' => 'When enabled, you can upload pictures into this directory: out/pictures/wysiwigpro/',