From 2809dfaeedbec337a5813aa3b57f0de8d7576eee Mon Sep 17 00:00:00 2001 From: Henning Leutz <leutz@pcsg.de> Date: Thu, 17 Aug 2017 10:33:22 +0200 Subject: [PATCH] style: cs --- src/QUI/Ckeditor/EventHandler.php | 12 +- src/QUI/Ckeditor/Plugins/Manager.php | 179 +++++++++++++++------------ 2 files changed, 110 insertions(+), 81 deletions(-) diff --git a/src/QUI/Ckeditor/EventHandler.php b/src/QUI/Ckeditor/EventHandler.php index f239709..b1596c2 100644 --- a/src/QUI/Ckeditor/EventHandler.php +++ b/src/QUI/Ckeditor/EventHandler.php @@ -1,11 +1,19 @@ <?php +/** + * This file contains QUI\Ckeditor\EventHandler + */ + namespace QUI\Ckeditor; use QUI\Ckeditor\Plugins\Manager; use QUI\Package\Package; -use QUI\System\Log; +/** + * Class EventHandler + * + * @package QUI\Ckeditor + */ class EventHandler { @@ -19,7 +27,6 @@ class EventHandler } $PluginManager = new Manager(); - $PluginManager->installPluginsFromSource(); } @@ -33,7 +40,6 @@ class EventHandler } $PluginManager = new Manager(); - $PluginManager->updatePlugins(); } } diff --git a/src/QUI/Ckeditor/Plugins/Manager.php b/src/QUI/Ckeditor/Plugins/Manager.php index 416bc97..f694554 100644 --- a/src/QUI/Ckeditor/Plugins/Manager.php +++ b/src/QUI/Ckeditor/Plugins/Manager.php @@ -1,9 +1,12 @@ <?php +/** + * This file contains QUI\Ckeditor\Plugins\Manager + */ namespace QUI\Ckeditor\Plugins; -use QUI\Archiver\Zip; +use QUI; use QUI\Exception; use QUI\System\Log; use QUI\Utils\Security\Orthos; @@ -16,13 +19,21 @@ use QUI\Utils\System\File; */ class Manager { - + /** + * @var string + */ protected $activePluginDir; + + /** + * @var string + */ protected $installedPluginDir; + /** + * @var + */ protected $dependencies; - /** * List of plugins which should not be installed * @@ -39,15 +50,15 @@ class Manager "textselection" ); - /** * Manager constructor. */ public function __construct() { - $this->activePluginDir = \QUI::getPackage("quiqqer/ckeditor4")->getVarDir() . "/plugins/bin"; - $this->installedPluginDir = \QUI::getPackage("quiqqer/ckeditor4")->getVarDir() . "/plugins/installed"; + $Package = QUI::getPackage("quiqqer/ckeditor4"); + $this->activePluginDir = $Package->getVarDir()."/plugins/bin"; + $this->installedPluginDir = $Package->getVarDir()."/plugins/installed"; if (!is_dir($this->activePluginDir)) { mkdir($this->activePluginDir, 0755, true); @@ -68,10 +79,9 @@ class Manager public function updatePlugins() { $srcDirs = array( - OPT_DIR . "ckeditor/ckeditor/plugins", - OPT_DIR . "quiqqer/ckeditor4/plugins/quiqqer", - OPT_DIR . "quiqqer/ckeditor4/plugins/ckeditor4", - + OPT_DIR."ckeditor/ckeditor/plugins", + OPT_DIR."quiqqer/ckeditor4/plugins/quiqqer", + OPT_DIR."quiqqer/ckeditor4/plugins/ckeditor4" ); foreach ($srcDirs as $srcDir) { @@ -79,34 +89,34 @@ class Manager return; } - foreach (scandir($srcDir) as $entry) { if ($entry == "." || $entry == "..") { continue; } - if (!is_dir($srcDir . "/" . $entry)) { + if (!is_dir($srcDir."/".$entry)) { continue; } $pluginName = $entry; // Special case, because gitlab gets confused with the dirctory named "codeTag" if ($entry == "code") { - $pluginName= "codeTag"; + $pluginName = "codeTag"; } + # Check if/where the plugin is installed - $targetDir = $this->installedPluginDir . "/" . $pluginName; - if (is_dir($this->activePluginDir . "/" . $pluginName)) { - $targetDir = $this->activePluginDir . "/" . $pluginName; + $targetDir = $this->installedPluginDir."/".$pluginName; + + if (is_dir($this->activePluginDir."/".$pluginName)) { + $targetDir = $this->activePluginDir."/".$pluginName; } if (is_dir($targetDir)) { File::deleteDir($targetDir); } - File::dircopy( - $srcDir . "/" . $entry, + $srcDir."/".$entry, $targetDir ); } @@ -120,20 +130,19 @@ class Manager public function installPluginsFromSource() { $srcDirs = array( - OPT_DIR . "ckeditor/ckeditor/plugins", - OPT_DIR . "quiqqer/ckeditor4/plugins/quiqqer", - OPT_DIR . "quiqqer/ckeditor4/plugins/ckeditor4" - + 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"; + $defaultStateFile = dirname(dirname(dirname(dirname(dirname(__FILE__)))))."/plugins/activePlugins.json"; + if (file_exists($defaultStateFile)) { $json = file_get_contents($defaultStateFile); $activePlugins = json_decode($json, true); } - foreach ($srcDirs as $srcDir) { if (!is_dir($srcDir)) { return; @@ -143,28 +152,29 @@ class Manager if ($entry == "." || $entry == "..") { continue; } - + $pluginName = $entry; // Special case, because gitlab gets confused with the dirctory named "codeTag" if ($entry == "code") { - $pluginName= "codeTag"; + $pluginName = "codeTag"; } - + $targetDir = $this->installedPluginDir; + if (in_array($entry, $activePlugins)) { $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; } @@ -172,18 +182,17 @@ 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" ); } @@ -200,6 +209,7 @@ class Manager $result = array(); $content = scandir($this->installedPluginDir); + if ($content === false) { return array(); } @@ -208,14 +218,13 @@ class Manager if ($entry == "." || $entry == "..") { continue; } - $fullpath = $this->installedPluginDir . "/" . $entry; + $fullpath = $this->installedPluginDir."/".$entry; if (!is_dir($fullpath)) { continue; } - $result[] = $entry; } @@ -236,26 +245,26 @@ class Manager throw new Exception(array("quiqqer/ckeditor4", "exception.install.file.not.found")); } - $tmpDir = \QUI::getTemp()->createFolder(); + $tmpDir = QUI::getTemp()->createFolder(); + copy( $pluginpath, - $tmpDir . "/archive.zip" + $tmpDir."/archive.zip" ); - $Zip = new \ZipArchive(); - if ($Zip->open($tmpDir . "/archive.zip") === false) { + if ($Zip->open($tmpDir."/archive.zip") === false) { throw new Exception(array("quiqqer/ckeditor4", "exception.install.file.invalid.format")); } - if ($Zip->extractTo($tmpDir . "/content") === false) { + if ($Zip->extractTo($tmpDir."/content") === false) { throw new Exception(array("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]); } @@ -280,25 +289,24 @@ class Manager continue; } - - if (is_dir($this->installedPluginDir . "/" . $entry)) { + if (is_dir($this->installedPluginDir."/".$entry)) { throw new Exception(array("quiqqer/ckeditor4", "exception.install.file.exists")); } - if (is_dir($this->activePluginDir . "/" . $entry)) { + if (is_dir($this->activePluginDir."/".$entry)) { throw new Exception(array("quiqqer/ckeditor4", "exception.install.file.exists")); } rename( - $tmpDir . "/content/" . $entry, - $this->installedPluginDir . "/" . $entry + $tmpDir."/content/".$entry, + $this->installedPluginDir."/".$entry ); } File::deleteDir($tmpDir); - \QUI::getMessagesHandler()->addSuccess( - \QUI::getLocale()->get( + QUI::getMessagesHandler()->addSuccess( + QUI::getLocale()->get( "quiqqer/ckeditor4", "message.plugin.install.success" ) @@ -328,15 +336,22 @@ class Manager )); } - if (!is_dir($this->installedPluginDir . "/" . $pluginName)) { - throw new Exception(array("quiqqer/ckeditor4", "exception.plugin.activate.plugin.not.found")); + if (!is_dir($this->installedPluginDir."/".$pluginName)) { + throw new Exception(array( + "quiqqer/ckeditor4", + "exception.plugin.activate.plugin.not.found" + )); } - if (is_dir($this->activePluginDir . "/" . $pluginName)) { - throw new Exception(array("quiqqer/ckeditor4", "exception.plugin.already.active")); + if (is_dir($this->activePluginDir."/".$pluginName)) { + throw new Exception(array( + "quiqqer/ckeditor4", + "exception.plugin.already.active" + )); } $deps = $this->getDependencies($pluginName); + foreach ($deps as $dep) { try { $this->activate($dep); @@ -344,10 +359,12 @@ class Manager } } - rename($this->installedPluginDir . "/" . $pluginName, $this->activePluginDir . "/" . $pluginName); - + rename( + $this->installedPluginDir."/".$pluginName, + $this->activePluginDir."/".$pluginName + ); - \QUI\Cache\Manager::clear("quiqqer/ckeditor/plugins/data"); + QUI\Cache\Manager::clear("quiqqer/ckeditor/plugins/data"); } /** @@ -362,12 +379,15 @@ class Manager $pluginName = Orthos::clearPath($pluginName); $pluginName = str_replace("/", "", $pluginName); - if (!is_dir($this->activePluginDir . "/" . $pluginName)) { - throw new Exception(array("quiqqer/ckeditor4", "exception.plugin.activate.plugin.not.active")); + if (!is_dir($this->activePluginDir."/".$pluginName)) { + throw new Exception(array( + "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; } @@ -379,9 +399,12 @@ class Manager } } - rename($this->activePluginDir . "/" . $pluginName, $this->installedPluginDir . "/" . $pluginName); + rename( + $this->activePluginDir."/".$pluginName, + $this->installedPluginDir."/".$pluginName + ); - \QUI\Cache\Manager::clear("quiqqer/ckeditor/plugins/data"); + QUI\Cache\Manager::clear("quiqqer/ckeditor/plugins/data"); } /** @@ -391,9 +414,9 @@ class Manager */ public function getActivePlugins() { - $result = array(); - + $result = array(); $content = scandir($this->activePluginDir); + if ($content === false) { return array(); } @@ -402,7 +425,8 @@ class Manager if ($entry == "." || $entry == "..") { continue; } - $fullpath = $this->activePluginDir . "/" . $entry; + + $fullpath = $this->activePluginDir."/".$entry; if (!is_dir($fullpath)) { continue; @@ -442,12 +466,12 @@ class Manager } $deps = $this->dependencies[$pluginName]; + foreach ($deps as $dep) { $result[] = $dep; $subDeps = $this->getDependencies($dep); - - $result = array_merge($result, $subDeps); + $result = array_merge($result, $subDeps); } $result = array_unique($result); @@ -473,7 +497,6 @@ class Manager return false; } - foreach ($this->dependencies as $pkg => $deps) { if (in_array($pluginName, $deps)) { $result[] = $pkg; @@ -496,13 +519,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) { @@ -556,7 +579,7 @@ class Manager */ public function getPluginDir() { - return \QUI::getPackage("quiqqer/ckeditor4")->getVarDir() . "/plugins"; + return QUI::getPackage("quiqqer/ckeditor4")->getVarDir()."/plugins"; } /** @@ -578,14 +601,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); } } @@ -597,7 +620,7 @@ class Manager public function getPluginUrlPath() { // Build the web reachable path for the plugin directory - $pluginPath = \QUI::getPackage("quiqqer/ckeditor4")->getVarDir() . "plugins"; + $pluginPath = QUI::getPackage("quiqqer/ckeditor4")->getVarDir()."plugins"; $varParent = dirname(VAR_DIR); # Parse the URL directory -- GitLab