This repository has been archived by the owner on Jul 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_ckeditor.php
165 lines (138 loc) · 3 KB
/
install_ckeditor.php
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
<?php
/**
* CKEditor for Joomla!
*
* @version 5.x
* @package CKEditor
* @author Denys D. Nosov (denys@joomla-ua.org)
* @copyright (C) 2014-2019 by Denys D. Nosov (https://joomla-ua.org)
* @license LICENSE.md
*
**/
defined('_JEXEC') or die('Restricted access');
class com_ckeditorInstallerScript
{
/**
* @param $parent
*
*
* @since 5.0
*/
public function install($parent)
{
$parent->getParent()->setRedirectURL('index.php?option=com_ckeditor');
}
/**
* @param $parent
*
* @return mixed
*
* @since 5.0
*/
public function uninstall($parent)
{
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
jimport('joomla.installer.installer');
$installer = JInstaller::getInstance();
$editor_result = JText::_('Success');
if(JFolder::exists(dirname($installer->getPath('extension_site')) . '/../plugins/editors'))
{
$editor_result = JText::_('Error');
if(JFolder::delete(dirname($installer->getPath('extension_site')) . '/../plugins/editors/ckeditor'))
{
$editor_result = JText::_('Success');
}
}
return $editor_result;
}
/**
* @param $type
* @param $parent
*
* @return string
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
* @since 5.0
*/
public function preflight($type, $parent)
{
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
jimport('joomla.installer.installer');
$installer = JInstaller::getInstance();
$source = $installer->getPath('source');
$packages = $source . '/packages';
$folders = [
JPATH_SITE . '/plugins/editors/ckeditor'
];
$html = '';
foreach($folders AS $folder)
{
if(is_dir($folder))
{
$this->unlinkRecursive($folder, 1);
$html .= '<p style="color: green;">Delete: ' . $folder . '</p>';
}
}
if(is_dir($packages))
{
$editor = JFolder::files($packages, 'plg_ckeditor.zip', false, true);
}
$editor_result = JText::_('Error');
if(!empty($editor) && is_file($editor[ 0 ]))
{
$packagePath = dirname($editor[ 0 ]) . '/ckeditor';
$jArchive = new Joomla\Archive\Archive();
if(!$jArchive->extract($editor[ 0 ], $packagePath))
{
$editor_result = JText::_('EDITOR EXTRACT ERROR');
}
else
{
$installer = JInstaller::getInstance();
if(JFolder::copy($packagePath, dirname($installer->getPath('extension_site')) . '/../plugins/editors', '', true))
{
$editor_result = JText::_('Success');
}
else
{
$editor_result = JText::_('Error');
}
}
}
$html .= $editor_result;
return $html;
}
/**
* @param $dir
* @param $deleteRootToo
*
*
* @since 5.0
*/
public function unlinkRecursive($dir, $deleteRootToo)
{
if(!$dh = @opendir($dir))
{
return;
}
while(false !== ($obj = readdir($dh)))
{
if($obj == '.' || $obj == '..')
{
continue;
}
if(!@unlink($dir . '/' . $obj))
{
$this->unlinkRecursive($dir . '/' . $obj, true);
}
}
closedir($dh);
if($deleteRootToo == 1)
{
@rmdir($dir);
}
}
}