jce.php
5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
56
57
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/**
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved
* @copyright Copyright (C) 2018 Ryan Demmer. All rights reserved
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* JCE extension plugin.
*
* @since 2.6
*/
class PlgExtensionJce extends JPlugin
{
/**
* Check the installer is for a valid plugin group.
*
* @param JInstaller $installer Installer object
*
* @return bool
*
* @since 2.6
*/
private function isValidPlugin($installer)
{
if (empty($installer->manifest)) {
return false;
}
foreach (array('type', 'group') as $var) {
$$var = (string) $installer->manifest->attributes()->{$var};
}
return $type === 'plugin' && $group === 'jce';
}
public function onExtensionBeforeInstall($method, $type, $manifest, $extension = 0)
{
if ((string) $type === "file") {
// get a reference to the current installer
$manifestPath = JInstaller::getInstance()->getPath('manifest');
if (empty($manifestPath)) {
return true;
}
// get the filename of the manifest file, eg: pkg_jce_de-DE
$element = basename($manifestPath, '.xml');
// if this matches the current install...
if (strpos($element, 'pkg_jce_') !== false) {
// find an existing legacy language install, eg: jce-de-DE
$element = str_replace('pkg_jce_', 'jce-', $element);
$table = JTable::getInstance('extension');
$id = $table->find(array('type' => 'file', 'element' => $element));
if ($id) {
$installer = new JInstaller();
// try unisntall, if this fails, delete database entry
if (!$installer->uninstall('file', $id)) {
$table->delete($id);
}
}
}
}
}
/**
* Handle post extension install update sites.
*
* @param JInstaller $installer Installer object
* @param int $eid Extension Identifier
*
* @since 2.6
*/
public function onExtensionAfterInstall($installer, $eid)
{
if ($eid) {
if (!$this->isValidPlugin($installer)) {
return false;
}
$basename = basename($installer->getPath('extension_root'));
if (strpos($basename, '-') === false) {
return false;
}
require_once JPATH_ADMINISTRATOR . '/components/com_jce/helpers/plugins.php';
// enable plugin
$plugin = JTable::getInstance('extension');
$plugin->load($eid);
$plugin->publish();
$parts = explode('-', $basename);
$type = $parts[0];
$name = $parts[1];
$plugin = new StdClass();
$plugin->name = $name;
if ($type === 'editor') {
$plugin->icon = (string) $installer->manifest->icon;
$plugin->row = (int) (string) $installer->manifest->attributes()->row;
$plugin->type = 'plugin';
} else {
$plugin->type = 'extension';
}
$plugin->path = $installer->getPath('extension_root');
JcePluginsHelper::postInstall('install', $plugin, $installer);
// clean up legacy extensions
if ($plugin->type == 'extension') {
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
$path = JPATH_SITE . '/components/com_jce/editor/extensions/' . $type;
// delete manifest
if (is_file($path . '/' . $plugin->name . '.xml')) {
JFile::delete($path . '/' . $plugin->name . '.xml');
}
// delete file
if (is_file($path . '/' . $plugin->name . '.php')) {
JFile::delete($path . '/' . $plugin->name . '.php');
}
// delete folder
if (is_dir($path . '/' . $plugin->name)) {
JFolder::delete($path . '/' . $plugin->name);
}
}
}
}
/**
* Handle extension uninstall.
*
* @param JInstaller $installer Installer instance
* @param int $eid Extension id
* @param int $result Installation result
*
* @since 1.6
*/
public function onExtensionAfterUninstall($installer, $eid, $result)
{
if ($eid) {
if (!$this->isValidPlugin($installer)) {
return false;
}
$basename = basename($installer->getPath('extension_root'));
if (strpos($basename, '-') === false) {
return false;
}
require_once JPATH_ADMINISTRATOR . '/components/com_jce/helpers/plugins.php';
$parts = explode('-', $basename);
$type = $parts[0];
$name = $parts[1];
$plugin = new StdClass();
$plugin->name = $name;
if ($type === 'editor') {
$plugin->icon = (string) $installer->manifest->icon;
$plugin->row = (int) (string) $installer->manifest->attributes()->row;
$plugin->type = 'plugin';
}
$plugin->path = $installer->getPath('extension_root');
JcePluginsHelper::postInstall('uninstall', $plugin, $installer);
}
}
}