Newer
Older
<?php
namespace QUI\Ckeditor\Plugins;
use QUI\Exception;
use QUI\Utils\Security\Orthos;
use QUI\Utils\System\File;
class Manager
{
protected $activePluginDir;
protected $installedPluginDir;
public function __construct()
{
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
$this->activePluginDir = \QUI::getPackage("quiqqer/ckeditor4")->getVarDir() . "/plugins/bin";
$this->installedPluginDir = \QUI::getPackage("quiqqer/ckeditor4")->getVarDir() . "/plugins/installed";
if (!is_dir($this->activePluginDir)) {
mkdir($this->activePluginDir, 0755, true);
}
if (!is_dir($this->installedPluginDir)) {
mkdir($this->installedPluginDir, 0755, true);
}
}
/**
* Activates the given plugin name
*
* @param $pluginName
*
* @throws Exception
*/
public function activate($pluginName)
{
$pluginName = Orthos::clearPath($pluginName);
$pluginName = str_replace("/", "", $pluginName);
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"));
}
rename($this->installedPluginDir . "/" . $pluginName, $this->activePluginDir . "/" . $pluginName);
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* Deactivates the given plugin name
*
* @param $pluginName
*
* @throws Exception
*/
public function deactivate($pluginName)
{
$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->installedPluginDir . "/" . $pluginName)) {
File::deleteDir($this->activePluginDir . "/" . $pluginName);
return;
}
rename($this->activePluginDir . "/" . $pluginName, $this->installedPluginDir . "/" . $pluginName);
}
/**
* Returns a list of all plugins and their details
* Format:
* array(
* [0] => array(
* ["name"] => "pluginname",
* ["state"] => 0|1 (1 for active; 0 for inactive)
* )
* )
*
* @return array
*/
public function getAllPlugins()
{
$result = array();
foreach ($this->getActivePlugins() as $plugin) {
$result[] = array(
'name' => $plugin,
'state' => 1
);
}
foreach ($this->getInstalledPlugins() as $plugin) {
$result[] = array(
'name' => $plugin,
'state' => 0
);
}
return $result;
}
/**
* Returns all installed plugins
*
* @return string[] - array of plugin names
*/
public function getInstalledPlugins()
{
$result = array();
$content = scandir($this->installedPluginDir);
if ($content === false) {
return array();
}
foreach ($content as $entry) {
if ($entry == "." || $entry == "..") {
continue;
}
$fullpath = $this->installedPluginDir . "/" . $entry;
if (!is_dir($fullpath)) {
continue;
}
$result[] = $entry;
}
return $result;
/**
* Returns all active plugins
*
* @return string[] - Array of active plugin names
*/
public function getActivePlugins()
{
$result = array();
$content = scandir($this->activePluginDir);
if ($content === false) {
return array();
}
foreach ($content as $entry) {
if ($entry == "." || $entry == "..") {
continue;
}
$fullpath = $this->activePluginDir . "/" . $entry;
if (!is_dir($fullpath)) {
continue;
}
$result[] = $entry;
}
return $result;
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/**
* Installs the plugins from the source packages quiqqer/ckeditor4 and ckeditor4/ckeditor4
*
*/
public function installPluginsFromSource()
{
$srcDirs = array(
OPT_DIR . "ckeditor/ckeditor/plugins",
OPT_DIR . "quiqqer/ckeditor4/plugins"
);
foreach ($srcDirs as $srcDir) {
$targetDir = $this->installedPluginDir;
if (!is_dir($srcDir)) {
return;
}
foreach (scandir($srcDir) as $entry) {
if ($entry == "." || $entry == "..") {
continue;
}
if (!is_dir($srcDir . "/" . $entry)) {
continue;
}
if (is_dir($targetDir . "/" . $entry)) {
continue;
}
if (is_dir($this->activePluginDir . "/" . $entry)) {
continue;
}
File::dircopy(
$srcDir . "/" . $entry,
$targetDir . "/" . $entry
);
}
}
/**
* Updates the plugins
*/
public function updatePlugins()
{
$srcDirs = array(
OPT_DIR . "ckeditor/ckeditor/plugins",
OPT_DIR . "quiqqer/ckeditor4/plugins"
);
foreach ($srcDirs as $srcDir) {
if (!is_dir($srcDir)) {
return;
}
foreach (scandir($srcDir) as $entry) {
if ($entry == "." || $entry == "..") {
continue;
}
if (!is_dir($srcDir . "/" . $entry)) {
continue;
}
# Check if/where the plugin is installed
$targetDir = $this->installedPluginDir . "/" . $entry;
if (is_dir($this->activePluginDir . "/" . $entry)) {
$targetDir = $this->activePluginDir . "/" . $entry;
}
if (is_dir($targetDir)) {
File::deleteDir($targetDir);
}
File::dircopy(
$srcDir . "/" . $entry,
$targetDir
);
}
}
/**
* Returns the plugin dir
*
* @return string
*/
public function getPluginDir()
{
return \QUI::getPackage("quiqqer/ckeditor4")->getVarDir() . "/plugins";
}