From 51a1ae8c2db3547c544111f056ef0f5a768b481c Mon Sep 17 00:00:00 2001 From: Henning Leutz <leutz@pcsg.de> Date: Mon, 6 May 2024 07:36:01 +0200 Subject: [PATCH] style: code style refactor --- ajax/activatePlugin.php | 9 +- ajax/deactivatePlugin.php | 9 +- ajax/getBrickInfo.php | 4 +- ajax/getEditorConfig.php | 14 +-- ajax/getPermissions.php | 8 +- ajax/getPluginData.php | 25 ++-- ajax/getPlugins.php | 10 +- ajax/uploadComplete.php | 10 +- src/QUI/Ckeditor/Plugins/Manager.php | 181 +++++++++++++-------------- 9 files changed, 131 insertions(+), 139 deletions(-) diff --git a/ajax/activatePlugin.php b/ajax/activatePlugin.php index 557bb11..5c24fc6 100644 --- a/ajax/activatePlugin.php +++ b/ajax/activatePlugin.php @@ -2,18 +2,17 @@ /** * Activates the plugin - * - * @param pluginName - * */ +use QUI\Ckeditor\Plugins\Manager; + QUI::$Ajax->registerFunction( 'package_quiqqer_ckeditor4_ajax_activatePlugin', function ($pluginName) { - $PluginManager = new \QUI\Ckeditor\Plugins\Manager(); + $PluginManager = new Manager(); $PluginManager->activate($pluginName); }, - array('pluginName'), + ['pluginName'], "quiqqer.editors.ckeditor.plugins.toggle" ); diff --git a/ajax/deactivatePlugin.php b/ajax/deactivatePlugin.php index f502bb5..5e392e4 100644 --- a/ajax/deactivatePlugin.php +++ b/ajax/deactivatePlugin.php @@ -2,18 +2,17 @@ /** * Deactivates the plugin - * - * @param pluginName - * */ +use QUI\Ckeditor\Plugins\Manager; + QUI::$Ajax->registerFunction( 'package_quiqqer_ckeditor4_ajax_deactivatePlugin', function ($pluginName) { - $PluginManager = new \QUI\Ckeditor\Plugins\Manager(); + $PluginManager = new Manager(); $PluginManager->deactivate($pluginName); }, - array('pluginName'), + ['pluginName'], "quiqqer.editors.ckeditor.plugins.toggle" ); diff --git a/ajax/getBrickInfo.php b/ajax/getBrickInfo.php index bb344c4..1742f1b 100644 --- a/ajax/getBrickInfo.php +++ b/ajax/getBrickInfo.php @@ -9,11 +9,11 @@ QUI::$Ajax->registerFunction( function ($brickId) { try { $Brick = QUI\Bricks\Manager::init()->getBrickById($brickId); - } catch (QUI\Exception $Exception) { + } catch (QUI\Exception) { return ''; } - return '#'.$Brick->getAttribute('id').' - '.$Brick->getAttribute('title'); + return '#' . $Brick->getAttribute('id') . ' - ' . $Brick->getAttribute('title'); }, ['brickId'] ); diff --git a/ajax/getEditorConfig.php b/ajax/getEditorConfig.php index b518c08..03ff742 100644 --- a/ajax/getEditorConfig.php +++ b/ajax/getEditorConfig.php @@ -1,20 +1,20 @@ <?php +use QUI\Ckeditor\Plugins\Manager; + QUI::$Ajax->registerFunction( 'package_quiqqer_ckeditor4_ajax_getEditorConfig', function () { - $config = array(); - - $Pluginmanager = new \QUI\Ckeditor\Plugins\Manager(); + $config = []; + $PluginManager = new Manager(); $PackageConfig = QUI::getPackage("quiqqer/ckeditor4")->getConfig(); - $config['plugins'] = $Pluginmanager->getActivePlugins(); - $config['pluginPath'] = $Pluginmanager->getPluginUrlPath(); + $config['plugins'] = $PluginManager->getActivePlugins(); + $config['pluginPath'] = $PluginManager->getPluginUrlPath(); $config['disableNativeSpellChecker'] = $PackageConfig->get("general", "disablenativeSpellcheck"); return $config; - }, - array() + } ); diff --git a/ajax/getPermissions.php b/ajax/getPermissions.php index 32dd1f8..079d526 100644 --- a/ajax/getPermissions.php +++ b/ajax/getPermissions.php @@ -8,11 +8,10 @@ QUI::$Ajax->registerFunction( 'package_quiqqer_ckeditor4_ajax_getPermissions', function () { - - $result = array( + $result = [ 'toggle' => false, 'upload' => false - ); + ]; if (QUI::getUserBySession()->getId() === 0) { return $result; @@ -36,6 +35,5 @@ QUI::$Ajax->registerFunction( } return $result; - }, - array() + } ); diff --git a/ajax/getPluginData.php b/ajax/getPluginData.php index 097b698..c45ce92 100644 --- a/ajax/getPluginData.php +++ b/ajax/getPluginData.php @@ -8,23 +8,21 @@ * 'plugins' => array('plugin1','plugin2','plugin3'...), * 'pluginpath' => 'path/to/plugins' * ) - * - * @param pluginName - * */ +use QUI\Cache\Manager; + QUI::$Ajax->registerFunction( 'package_quiqqer_ckeditor4_ajax_getPluginData', function () { - if (QUI::getUserBySession()->getId() === 0) { throw new \QUI\Exception("Invalid external function call. Caller must be logged in!"); } try { - return \QUI\Cache\Manager::get("quiqqer/ckeditor/plugins/data"); - } catch (\Exception $Exception) { + return Manager::get("quiqqer/ckeditor/plugins/data"); + } catch (Exception) { } @@ -32,22 +30,19 @@ QUI::$Ajax->registerFunction( // Build the web reachable path for the plugin directory $pluginPath = QUI::getPackage("quiqqer/ckeditor4")->getVarDir() . "plugins"; - $varParent = dirname(VAR_DIR); + $varParent = dirname(VAR_DIR); # Parse the URL directory $pluginUrlPath = str_replace($varParent, "", $pluginPath); - $data = array( - 'plugins' => $Manager->getActivePlugins(), + $data = [ + 'plugins' => $Manager->getActivePlugins(), 'pluginPath' => $pluginUrlPath - ); - - - \QUI\Cache\Manager::set("quiqqer/ckeditor/plugins/data", $data); + ]; + Manager::set("quiqqer/ckeditor/plugins/data", $data); return $data; - }, - array() + } ); diff --git a/ajax/getPlugins.php b/ajax/getPlugins.php index ed382b2..7dc18e8 100644 --- a/ajax/getPlugins.php +++ b/ajax/getPlugins.php @@ -4,17 +4,17 @@ * Gets all plugins and their state */ +use QUI\Ckeditor\Plugins\Manager; + QUI::$Ajax->registerFunction( 'package_quiqqer_ckeditor4_ajax_getPlugins', function () { - if (QUI::getUserBySession()->getId() === 0) { throw new \QUI\Exception("Invalid external function call. Caller must be logged in!"); } - $Pluginmanager = new \QUI\Ckeditor\Plugins\Manager(); + $PluginManager = new Manager(); - return $Pluginmanager->getAllPlugins(); - }, - array() + return $PluginManager->getAllPlugins(); + } ); diff --git a/ajax/uploadComplete.php b/ajax/uploadComplete.php index f192cfe..9cb505d 100644 --- a/ajax/uploadComplete.php +++ b/ajax/uploadComplete.php @@ -1,19 +1,21 @@ <?php +use QUI\Ckeditor\Plugins\Manager; +use QUI\System\Log; + QUI::$Ajax->registerFunction( 'package_quiqqer_ckeditor4_ajax_uploadComplete', function ($File) { - $filePath = $File->getAttribute('filepath'); + $Manager = new Manager(); - $Manager = new \QUI\Ckeditor\Plugins\Manager(); try { $Manager->installPlugin($filePath); } catch (\Exception $Exception) { QUI::getMessagesHandler()->addError($Exception->getMessage()); - \QUI\System\Log::addError($Exception->getMessage()); + Log::addError($Exception->getMessage()); } }, - array('File'), + ['File'], "quiqqer.editors.ckeditor.plugins.upload" ); diff --git a/src/QUI/Ckeditor/Plugins/Manager.php b/src/QUI/Ckeditor/Plugins/Manager.php index 607d6b0..c0ddf77 100644 --- a/src/QUI/Ckeditor/Plugins/Manager.php +++ b/src/QUI/Ckeditor/Plugins/Manager.php @@ -39,7 +39,7 @@ class Manager * * @var array */ - protected $blacklist = array( + protected $blacklist = [ "ckawesome", "copyformatting", "crossreference", @@ -48,7 +48,7 @@ class Manager "enhancedcolorbutton", "footnotes", "textselection" - ); + ]; /** * Manager constructor. @@ -57,8 +57,8 @@ class Manager { $Package = QUI::getPackage("quiqqer/ckeditor4"); - $this->activePluginDir = $Package->getVarDir()."/plugins/bin"; - $this->installedPluginDir = $Package->getVarDir()."/plugins/installed"; + $this->activePluginDir = $Package->getVarDir() . "/plugins/bin"; + $this->installedPluginDir = $Package->getVarDir() . "/plugins/installed"; if (!is_dir($this->activePluginDir)) { mkdir($this->activePluginDir, 0755, true); @@ -78,11 +78,11 @@ class Manager */ public function updatePlugins() { - $srcDirs = array( - OPT_DIR."ckeditor/ckeditor/plugins", - OPT_DIR."quiqqer/ckeditor4/plugins/quiqqer", - OPT_DIR."quiqqer/ckeditor4/plugins/ckeditor4" - ); + $srcDirs = [ + OPT_DIR . "ckeditor/ckeditor/plugins", + OPT_DIR . "quiqqer/ckeditor4/plugins/quiqqer", + OPT_DIR . "quiqqer/ckeditor4/plugins/ckeditor4" + ]; foreach ($srcDirs as $srcDir) { if (!is_dir($srcDir)) { @@ -94,7 +94,7 @@ class Manager continue; } - if (!is_dir($srcDir."/".$entry)) { + if (!is_dir($srcDir . "/" . $entry)) { continue; } @@ -105,10 +105,10 @@ class Manager } # Check if/where the plugin is installed - $targetDir = $this->installedPluginDir."/".$pluginName; + $targetDir = $this->installedPluginDir . "/" . $pluginName; - if (is_dir($this->activePluginDir."/".$pluginName)) { - $targetDir = $this->activePluginDir."/".$pluginName; + if (is_dir($this->activePluginDir . "/" . $pluginName)) { + $targetDir = $this->activePluginDir . "/" . $pluginName; } if (is_dir($targetDir)) { @@ -116,7 +116,7 @@ class Manager } File::dircopy( - $srcDir."/".$entry, + $srcDir . "/" . $entry, $targetDir ); } @@ -129,17 +129,17 @@ class Manager */ public function installPluginsFromSource() { - $srcDirs = array( - OPT_DIR."ckeditor/ckeditor/plugins", - OPT_DIR."quiqqer/ckeditor4/plugins/quiqqer", - OPT_DIR."quiqqer/ckeditor4/plugins/ckeditor4" - ); + $srcDirs = [ + OPT_DIR . "ckeditor/ckeditor/plugins", + OPT_DIR . "quiqqer/ckeditor4/plugins/quiqqer", + OPT_DIR . "quiqqer/ckeditor4/plugins/ckeditor4" + ]; - $activePlugins = array(); - $defaultStateFile = dirname(dirname(dirname(dirname(dirname(__FILE__)))))."/plugins/activePlugins.json"; + $activePlugins = []; + $defaultStateFile = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . "/plugins/activePlugins.json"; if (file_exists($defaultStateFile)) { - $json = file_get_contents($defaultStateFile); + $json = file_get_contents($defaultStateFile); $activePlugins = json_decode($json, true); } @@ -165,15 +165,15 @@ class Manager $targetDir = $this->activePluginDir; } - if (!is_dir($srcDir."/".$entry)) { + if (!is_dir($srcDir . "/" . $entry)) { continue; } - if (is_dir($this->installedPluginDir."/".$pluginName)) { + if (is_dir($this->installedPluginDir . "/" . $pluginName)) { continue; } - - if (is_dir($this->activePluginDir."/".$pluginName)) { + + if (is_dir($this->activePluginDir . "/" . $pluginName)) { continue; } @@ -181,21 +181,20 @@ class Manager continue; } - + $this->copyDir( - $srcDir."/".$entry, - $targetDir."/".$pluginName + $srcDir . "/" . $entry, + $targetDir . "/" . $pluginName ); } } - if (file_exists(OPT_DIR."quiqqer/ckeditor4/plugins/dependencies.json")) { + if (file_exists(OPT_DIR . "quiqqer/ckeditor4/plugins/dependencies.json")) { copy( - OPT_DIR."quiqqer/ckeditor4/plugins/dependencies.json", - $this->getPluginDir()."/dependencies.json" + OPT_DIR . "quiqqer/ckeditor4/plugins/dependencies.json", + $this->getPluginDir() . "/dependencies.json" ); } - #File::deleteDir(OPT_DIR . "ckeditor/ckeditor/plugins"); } @@ -206,12 +205,12 @@ class Manager */ public function getInstalledPlugins() { - $result = array(); + $result = []; $content = scandir($this->installedPluginDir); if ($content === false) { - return array(); + return []; } foreach ($content as $entry) { @@ -219,7 +218,7 @@ class Manager continue; } - $fullpath = $this->installedPluginDir."/".$entry; + $fullpath = $this->installedPluginDir . "/" . $entry; if (!is_dir($fullpath)) { continue; @@ -242,29 +241,29 @@ class Manager { # Check if file exists if (!file_exists($pluginpath)) { - throw new Exception(array("quiqqer/ckeditor4", "exception.install.file.not.found")); + throw new Exception(["quiqqer/ckeditor4", "exception.install.file.not.found"]); } $tmpDir = QUI::getTemp()->createFolder(); copy( $pluginpath, - $tmpDir."/archive.zip" + $tmpDir . "/archive.zip" ); $Zip = new \ZipArchive(); - if ($Zip->open($tmpDir."/archive.zip") === false) { - throw new Exception(array("quiqqer/ckeditor4", "exception.install.file.invalid.format")); + if ($Zip->open($tmpDir . "/archive.zip") === false) { + throw new Exception(["quiqqer/ckeditor4", "exception.install.file.invalid.format"]); } - if ($Zip->extractTo($tmpDir."/content") === false) { - throw new Exception(array("quiqqer/ckeditor4", "exception.install.file.extract.failed")); + if ($Zip->extractTo($tmpDir . "/content") === false) { + throw new Exception(["quiqqer/ckeditor4", "exception.install.file.extract.failed"]); } // Scan dir and remove '.' and '..' - $contents = scandir($tmpDir."/content"); + $contents = scandir($tmpDir . "/content"); foreach (array_keys($contents, ".", true) as $key) { unset($contents[$key]); } @@ -276,10 +275,10 @@ class Manager // Check if the zip contains only one folder if (count($contents) !== 1) { - throw new Exception(array( + throw new Exception([ "quiqqer/ckeditor4", "exception.plugin.install.wrong.format" - )); + ]); } @@ -289,17 +288,17 @@ class Manager continue; } - if (is_dir($this->installedPluginDir."/".$entry)) { - throw new Exception(array("quiqqer/ckeditor4", "exception.install.file.exists")); + if (is_dir($this->installedPluginDir . "/" . $entry)) { + throw new Exception(["quiqqer/ckeditor4", "exception.install.file.exists"]); } - if (is_dir($this->activePluginDir."/".$entry)) { - throw new Exception(array("quiqqer/ckeditor4", "exception.install.file.exists")); + if (is_dir($this->activePluginDir . "/" . $entry)) { + throw new Exception(["quiqqer/ckeditor4", "exception.install.file.exists"]); } rename( - $tmpDir."/content/".$entry, - $this->installedPluginDir."/".$entry + $tmpDir . "/content/" . $entry, + $this->installedPluginDir . "/" . $entry ); } @@ -330,24 +329,24 @@ class Manager $pluginName = str_replace("/", "", $pluginName); if (in_array($pluginName, $this->blacklist)) { - throw new Exception(array( + throw new Exception([ "quiqqer/ckeditor4", "exception.plugin.activate.blacklisted" - )); + ]); } - if (!is_dir($this->installedPluginDir."/".$pluginName)) { - throw new Exception(array( + if (!is_dir($this->installedPluginDir . "/" . $pluginName)) { + throw new Exception([ "quiqqer/ckeditor4", "exception.plugin.activate.plugin.not.found" - )); + ]); } - if (is_dir($this->activePluginDir."/".$pluginName)) { - throw new Exception(array( + if (is_dir($this->activePluginDir . "/" . $pluginName)) { + throw new Exception([ "quiqqer/ckeditor4", "exception.plugin.already.active" - )); + ]); } $deps = $this->getDependencies($pluginName); @@ -360,8 +359,8 @@ class Manager } rename( - $this->installedPluginDir."/".$pluginName, - $this->activePluginDir."/".$pluginName + $this->installedPluginDir . "/" . $pluginName, + $this->activePluginDir . "/" . $pluginName ); QUI\Cache\Manager::clear("quiqqer/ckeditor/plugins/data"); @@ -379,15 +378,15 @@ class Manager $pluginName = Orthos::clearPath($pluginName); $pluginName = str_replace("/", "", $pluginName); - if (!is_dir($this->activePluginDir."/".$pluginName)) { - throw new Exception(array( + if (!is_dir($this->activePluginDir . "/" . $pluginName)) { + throw new Exception([ "quiqqer/ckeditor4", "exception.plugin.activate.plugin.not.active" - )); + ]); } - if (is_dir($this->installedPluginDir."/".$pluginName)) { - File::deleteDir($this->activePluginDir."/".$pluginName); + if (is_dir($this->installedPluginDir . "/" . $pluginName)) { + File::deleteDir($this->activePluginDir . "/" . $pluginName); return; } @@ -400,8 +399,8 @@ class Manager } rename( - $this->activePluginDir."/".$pluginName, - $this->installedPluginDir."/".$pluginName + $this->activePluginDir . "/" . $pluginName, + $this->installedPluginDir . "/" . $pluginName ); QUI\Cache\Manager::clear("quiqqer/ckeditor/plugins/data"); @@ -414,11 +413,11 @@ class Manager */ public function getActivePlugins() { - $result = array(); + $result = []; $content = scandir($this->activePluginDir); if ($content === false) { - return array(); + return []; } foreach ($content as $entry) { @@ -426,7 +425,7 @@ class Manager continue; } - $fullpath = $this->activePluginDir."/".$entry; + $fullpath = $this->activePluginDir . "/" . $entry; if (!is_dir($fullpath)) { continue; @@ -459,10 +458,10 @@ class Manager return false; } - $result = array(); + $result = []; if (!isset($this->dependencies[$pluginName])) { - return array(); + return []; } $deps = $this->dependencies[$pluginName]; @@ -471,7 +470,7 @@ class Manager $result[] = $dep; $subDeps = $this->getDependencies($dep); - $result = array_merge($result, $subDeps); + $result = array_merge($result, $subDeps); } $result = array_unique($result); @@ -489,7 +488,7 @@ class Manager */ public function getDependentPlugins($pluginName) { - $result = array(); + $result = []; try { $this->loadDependencies(); @@ -519,13 +518,13 @@ class Manager return; } - if (!file_exists($this->getPluginDir()."/dependencies.json")) { - Log::addWarning("Missing dependency file: ".$this->getPluginDir()."/dependencies.json"); + if (!file_exists($this->getPluginDir() . "/dependencies.json")) { + Log::addWarning("Missing dependency file: " . $this->getPluginDir() . "/dependencies.json"); throw new Exception("missing.dependency.file"); } - $json = file_get_contents($this->getPluginDir()."/dependencies.json"); + $json = file_get_contents($this->getPluginDir() . "/dependencies.json"); $deps = json_decode($json, true); if (json_last_error() !== JSON_ERROR_NONE) { @@ -553,20 +552,20 @@ class Manager */ public function getAllPlugins() { - $result = array(); + $result = []; foreach ($this->getActivePlugins() as $plugin) { - $result[] = array( - 'name' => $plugin, + $result[] = [ + 'name' => $plugin, 'state' => 1 - ); + ]; } foreach ($this->getInstalledPlugins() as $plugin) { - $result[] = array( - 'name' => $plugin, + $result[] = [ + 'name' => $plugin, 'state' => 0 - ); + ]; } return $result; @@ -579,7 +578,7 @@ class Manager */ public function getPluginDir() { - return QUI::getPackage("quiqqer/ckeditor4")->getVarDir()."/plugins"; + return QUI::getPackage("quiqqer/ckeditor4")->getVarDir() . "/plugins"; } /** @@ -601,14 +600,14 @@ class Manager continue; } - $fullpath = $src."/".$entry; + $fullpath = $src . "/" . $entry; if (is_dir($fullpath)) { - $this->copyDir($fullpath, $target."/".$entry); + $this->copyDir($fullpath, $target . "/" . $entry); continue; } - copy($fullpath, $target."/".$entry); + copy($fullpath, $target . "/" . $entry); } } @@ -620,8 +619,8 @@ class Manager public function getPluginUrlPath() { // Build the web reachable path for the plugin directory - $pluginPath = QUI::getPackage("quiqqer/ckeditor4")->getVarDir()."plugins"; - $varParent = dirname(VAR_DIR); + $pluginPath = QUI::getPackage("quiqqer/ckeditor4")->getVarDir() . "plugins"; + $varParent = dirname(VAR_DIR); # Parse the URL directory $pluginUrlPath = str_replace($varParent, "", $pluginPath); -- GitLab