Skip to content
Code-Schnipsel Gruppen Projekte

fix: display CKE notifications on the center of the page

Zusammengeführt Henning Leutz schlägt vor, dev in next zu mergen.
2 Dateien
+ 113
87
Änderungen vergleichen
  • Nebeneinander
  • In der Reihe
Dateien
2
<?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,24 @@ class Manager
if ($entry == "." || $entry == "..") {
continue;
}
$pluginName = $entry;
// Special case, because gitlab gets confused with the dirctory named "codeTag"
// Special case, because gitlab gets confused with the directory 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)) {
continue;
}
if (is_dir($this->installedPluginDir . "/" . $pluginName)) {
if (!is_dir($srcDir."/".$entry)) {
continue;
}
if (is_dir($this->activePluginDir . "/" . $pluginName)) {
if (!is_dir($this->activePluginDir."/".$pluginName)) {
continue;
}
@@ -172,18 +177,20 @@ class Manager
continue;
}
// vorher löschen, da sonst nicht kopiert werden kann
QUI::getTemp()->moveToTemp($targetDir."/".$pluginName);
$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 +207,7 @@ class Manager
$result = array();
$content = scandir($this->installedPluginDir);
if ($content === false) {
return array();
}
@@ -208,14 +216,13 @@ class Manager
if ($entry == "." || $entry == "..") {
continue;
}
$fullpath = $this->installedPluginDir . "/" . $entry;
$fullpath = $this->installedPluginDir."/".$entry;
if (!is_dir($fullpath)) {
continue;
}
$result[] = $entry;
}
@@ -236,26 +243,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 +287,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 +334,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 +357,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 +377,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 +397,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 +412,9 @@ class Manager
*/
public function getActivePlugins()
{
$result = array();
$result = array();
$content = scandir($this->activePluginDir);
if ($content === false) {
return array();
}
@@ -402,7 +423,8 @@ class Manager
if ($entry == "." || $entry == "..") {
continue;
}
$fullpath = $this->activePluginDir . "/" . $entry;
$fullpath = $this->activePluginDir."/".$entry;
if (!is_dir($fullpath)) {
continue;
@@ -442,12 +464,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 +495,6 @@ class Manager
return false;
}
foreach ($this->dependencies as $pkg => $deps) {
if (in_array($pluginName, $deps)) {
$result[] = $pkg;
@@ -496,13 +517,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 +577,7 @@ class Manager
*/
public function getPluginDir()
{
return \QUI::getPackage("quiqqer/ckeditor4")->getVarDir() . "/plugins";
return QUI::getPackage("quiqqer/ckeditor4")->getVarDir()."/plugins";
}
/**
@@ -578,14 +599,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 +618,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