improve code

This commit is contained in:
O3-Shop 2023-04-08 22:47:11 +02:00
parent c6496efc62
commit 192a9aa52d
23 changed files with 87 additions and 13 deletions

View File

@ -53,6 +53,7 @@ use O3\TinyMCE\Application\Core\TinyMCE\Options\ToolbarSticky;
class Configuration
{
protected Loader $loader;
/** @var array<String, String> */
protected array $options = [];
public function __construct(Loader $loader)
@ -89,6 +90,10 @@ class Configuration
{
$sConfig = '';
/**
* @var string $param
* @var string $value
*/
foreach ($this->options as $param => $value) {
$sConfig .= "$param: $value, ";
}

View File

@ -49,7 +49,11 @@ class Loader
{
if (!$this->isEnabledForCurrentController()) return '';
if ($this->contentIsPlain()) return $this->language->translateString('TINYMCE_PLAINCMS');
if ($this->contentIsPlain()) {
/** @var string $message */
$message = $this->language->translateString('TINYMCE_PLAINCMS');
return $message;
}
$configuration = oxNew(Configuration::class, $this);
$configuration->build();
@ -66,6 +70,7 @@ class Loader
*/
protected function isEnabledForCurrentController(): bool
{
/** @var string[] $aEnabledClasses */
$aEnabledClasses = $this->getShopConfig()->getConfigParam( "aTinyMCE_classes", []);
return in_array( $this->getShopConfig()->getActiveView()->getClassKey(), $aEnabledClasses);
@ -109,7 +114,7 @@ class Loader
$sInit = str_replace(
"'CONFIG':'VALUES'",
$configuration->getConfig(),
file_get_contents(__DIR__.'/../../../out/scripts/init.js')
(string) file_get_contents(__DIR__.'/../../../out/scripts/init.js')
);
$smarty = Registry::getUtilsView()->getSmarty();
$sSufix = ($smarty->_tpl_vars["__oxid_include_dynamic"]) ? '_dynamic' : '';
@ -131,6 +136,7 @@ class Loader
$smarty = Registry::getUtilsView()->getSmarty();
$sSuffix = ($smarty->_tpl_vars["__oxid_include_dynamic"]) ? '_dynamic' : '';
/** @var array<int, string[]> $aInclude */
$aInclude = (array) Registry::getConfig()->getGlobalParameter('includes' . $sSuffix);
$aInclude[3][] = Registry::getConfig()->getActiveView()->getViewConfig()->getModuleUrl(
@ -138,14 +144,17 @@ class Loader
'out/tinymce/tinymce.min.js'
);
/** @var string[] $aExtjs */
$aExtjs = Registry::getConfig()->getConfigParam('aTinyMCE_extjs', []);
foreach ($aExtjs as $js) {
$aInclude[3][] = $js;
}
if (strlen(trim(Registry::getConfig()->getConfigParam('sTinyMCE_apikey', '')))) {
/** @var string $apiKey */
$apiKey = Registry::getConfig()->getConfigParam('sTinyMCE_apikey', '');
if (strlen(trim($apiKey))) {
$aInclude[3][] = "https://cdn.tiny.cloud/1/".
trim(Registry::getConfig()->getConfigParam('sTinyMCE_apikey', '')).
trim($apiKey).
"/tinymce/6/plugins.min.js";
}

View File

@ -36,12 +36,15 @@ class ContentCss extends AbstractOption
public function get(): string
{
/** @var string $theme */
$theme = Registry::getConfig()->getConfigParam('sTheme');
return implode(
',',
[
$this->darkMode ?
'dark' :
'/out/'.strtolower(Registry::getConfig()->getConfigParam('sTheme')).'/src/css/styles.min.css'
'/out/'.strtolower($theme).'/src/css/styles.min.css'
]
);
}

View File

@ -35,6 +35,7 @@ class FilemanagerUrl extends AbstractOption
public function get(): string
{
/** @var string $sFilemanagerKey */
$sFilemanagerKey = md5_file(Registry::getConfig()->getConfigParam("sShopDir")."/config.inc.php");
Registry::get(UtilsServer::class)->setOxCookie("filemanagerkey", $sFilemanagerKey);

View File

@ -46,7 +46,7 @@ class Language extends AbstractOption
"nl" => "nl",
"ru" => "ru"
);
return $aLang[ $oLang->getLanguageAbbr( $oLang->getTplLanguage() ) ] ?? "en";
return $aLang[ $oLang->getLanguageAbbr( (int) $oLang->getTplLanguage() ) ] ?? "en";
}
public function mustQuote(): bool

View File

@ -31,9 +31,9 @@ class MinHeight extends AbstractOption
public function get(): string
{
$profile = Registry::getSession()->getVariable('profile');
$profile = (array) Registry::getSession()->getVariable('profile');
if (isset($profile) && $profile[1]) {
if (array_key_exists(1, $profile)) {
return (string) (max($profile[1] * 20, 350));
}

View File

@ -34,7 +34,7 @@ class Setup extends AbstractOption
editor.options.register("filemanager_url", { processor: "string" });
}
JS;
return trim(preg_replace('!\s+!', ' ', $js));
return trim((string) preg_replace('!\s+!', ' ', $js));
}
/**

View File

@ -48,7 +48,11 @@ class Toolbar extends AbstractOption
$this->getMultiLineToolbar($toolbarList);
}
protected function getSingleLineToolbar($toolbarList): string
/**
* @param ToolbarList $toolbarList
* @return string
*/
protected function getSingleLineToolbar(ToolbarList $toolbarList): string
{
$all = [];
@ -90,7 +94,11 @@ class Toolbar extends AbstractOption
return $toolbarElements . ' | ' . $pluginToolbarElements;
}
protected function getMultiLineToolbar($toolbarList): string
/**
* @param ToolbarList $toolbarList
* @return string
*/
protected function getMultiLineToolbar(ToolbarList $toolbarList): string
{
$list = [];

View File

@ -37,6 +37,7 @@ use O3\TinyMCE\Application\Core\TinyMCE\Plugins\Lists;
use O3\TinyMCE\Application\Core\TinyMCE\Plugins\Media;
use O3\TinyMCE\Application\Core\TinyMCE\Plugins\Nonbreaking;
use O3\TinyMCE\Application\Core\TinyMCE\Plugins\Pagebreak;
use O3\TinyMCE\Application\Core\TinyMCE\Plugins\PluginInterface;
use O3\TinyMCE\Application\Core\TinyMCE\Plugins\Preview;
use O3\TinyMCE\Application\Core\TinyMCE\Plugins\Quickbars;
use O3\TinyMCE\Application\Core\TinyMCE\Plugins\Roxy;
@ -47,6 +48,9 @@ use O3\TinyMCE\Application\Core\TinyMCE\Plugins\WordCount;
class PluginList
{
/**
* @return array<string, PluginInterface>
*/
public function get(): array
{
return [

View File

@ -30,6 +30,9 @@ class Nonbreaking extends AbstractPlugin
return 'nonbreaking';
}
/**
* @return string[]
*/
public function getToolbarElements(): array
{
return [

View File

@ -30,6 +30,9 @@ class Pagebreak extends AbstractPlugin
return 'pagebreak';
}
/**
* @return string[]
*/
public function getToolbarElements(): array
{
return [

View File

@ -27,6 +27,9 @@ interface PluginInterface
{
public function getPluginName(): string;
/**
* @return string[]
*/
public function getToolbarElements(): array;
public function getScriptPath(): ?string;

View File

@ -30,6 +30,9 @@ class Preview extends AbstractPlugin
return 'preview';
}
/**
* @return string[]
*/
public function getToolbarElements(): array
{
return [

View File

@ -30,6 +30,9 @@ class SearchReplace extends AbstractPlugin
return 'searchreplace';
}
/**
* @return string[]
*/
public function getToolbarElements(): array
{
return [

View File

@ -30,6 +30,9 @@ class Table extends AbstractPlugin
return 'table';
}
/**
* @return string[]
*/
public function getToolbarElements(): array
{
return [

View File

@ -30,6 +30,9 @@ class Visualblocks extends AbstractPlugin
return 'visualblocks';
}
/**
* @return string[]
*/
public function getToolbarElements(): array
{
return [

View File

@ -30,6 +30,9 @@ class WordCount extends AbstractPlugin
return 'wordcount';
}
/**
* @return string[]
*/
public function getToolbarElements(): array
{
return [];

View File

@ -25,5 +25,8 @@ namespace O3\TinyMCE\Application\Core\TinyMCE\Toolbar;
interface ToolbarInterface
{
/**
* @return string[]
*/
public function getButtons(): array;
}

View File

@ -25,6 +25,9 @@ namespace O3\TinyMCE\Application\Core\TinyMCE\Toolbar;
class Undo extends AbstractToolbar
{
/**
* @return string[]
*/
public function getButtons(): array
{
return [

View File

@ -31,9 +31,13 @@ use O3\TinyMCE\Application\Core\TinyMCE\Toolbar\Blocks;
use O3\TinyMCE\Application\Core\TinyMCE\Toolbar\Indent;
use O3\TinyMCE\Application\Core\TinyMCE\Toolbar\Lists;
use O3\TinyMCE\Application\Core\TinyMCE\Toolbar\RemoveFormat;
use O3\TinyMCE\Application\Core\TinyMCE\Toolbar\ToolbarInterface;
class ToolbarList
{
/**
* @return array<int, array<string, ToolbarInterface>>
*/
public function get(): array
{
return [

View File

@ -25,7 +25,7 @@ namespace O3\TinyMCE\Application\Core\TinyMCE;
class Utils
{
public function quote($string): string
public function quote(string $string): string
{
return '"'.addslashes($string).'"';
}

View File

@ -21,7 +21,7 @@
declare(strict_types=1);
function checkAccess($action)
function checkAccess(string $action): void
{
if($_COOKIE['filemanagerkey'] !== md5($_SERVER['DOCUMENT_ROOT'].$_COOKIE['admin_sid'])) die('Access Denied!!');
}

10
phpstan.neon Normal file
View File

@ -0,0 +1,10 @@
parameters:
scanFiles:
- .ide-helper.php
- ../../o3-shop/shop-ce/source/oxfunctions.php
paths:
- Application
excludePaths:
- Application/fileman
level: 9
phpVersion: 70400