-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupgrade.php
228 lines (204 loc) · 8 KB
/
upgrade.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
166
167
168
169
170
171
172
173
174
175
176
177
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
220
221
222
223
224
225
226
227
<?php
/**
* extendedWYSIWYG
*
* @author Ralf Hertsch <[email protected]>
* @link https://addons.phpmanufaktur.de/extendedWYSIWYG
* @copyright 2012 phpManufaktur by Ralf Hertsch
* @license MIT License (MIT) http://www.opensource.org/licenses/MIT
*/
// include class.secure.php to protect this file and the whole CMS!
if (defined('WB_PATH')) {
if (defined('LEPTON_VERSION')) include(WB_PATH.'/framework/class.secure.php');
} else {
$oneback = "../";
$root = $oneback;
$level = 1;
while (($level < 10) && (!file_exists($root.'/framework/class.secure.php'))) {
$root .= $oneback;
$level += 1;
}
if (file_exists($root.'/framework/class.secure.php')) {
include($root.'/framework/class.secure.php');
} else {
trigger_error(sprintf("[ <b>%s</b> ] Can't include class.secure.php!",
$_SERVER['SCRIPT_NAME']), E_USER_ERROR);
}
}
// end include class.secure.php
if (!defined('LEPTON_PATH'))
require_once WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/wb2lepton.php';
global $database;
global $admin;
if (defined('LEPTON_VERSION'))
$database->prompt_on_error(false);
/**
* Check if the specified $field in table mod_wysiwyg exists
*
* @param string $field
* @return boolean
*/
function fieldExists($field) {
global $database;
global $admin;
if (null === ($query = $database->query("DESCRIBE `".TABLE_PREFIX."mod_wysiwyg`")))
$admin->print_error($database->get_error());
while (false !== ($data = $query->fetchRow(MYSQL_ASSOC)))
if ($data['Field'] == $field) return true;
return false;
} // sqlFieldExists()
/**
* Delete a directory recursivly
*
* @param string $dir
*/
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir")
rrmdir($dir."/".$object);
else
unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
} //rrmdir()
// update the module name = extendedWYSIWYG
$SQL = "UPDATE `".TABLE_PREFIX."addons` SET `name`='extendedWYSIWYG' WHERE `directory`='wysiwyg'";
if (!$database->query($SQL))
$admin->print_error($database->get_error());
// we have to delete some files and directories from the origin installation
$language_files = array('DA.php','FR.php','NL.php','NO.php','RU.php');
foreach ($language_files as $file)
@unlink(LEPTON_PATH.'/modules/wysiwyg/languages/'.$file);
// WYSIWYG of LEPTON have a directory '/classes' which is no longer needed
rrmdir(LEPTON_PATH.'/modules/wysiwyg/classes');
// now create the WYSIWYG archive table
$SQL = "CREATE TABLE IF NOT EXISTS `".TABLE_PREFIX."mod_wysiwyg_archive` ( ".
"`archive_id` INT(11) NOT NULL AUTO_INCREMENT, ".
"`section_id` INT(11) NOT NULL DEFAULT '0', ".
"`page_id` INT(11) NOT NULL DEFAULT '0', ".
"`content` LONGTEXT NOT NULL, ".
"`hash` VARCHAR(32) NOT NULL DEFAULT '', ".
"`remark` VARCHAR(255) NOT NULL DEFAULT '', ".
"`author` VARCHAR(255) NOT NULL DEFAULT '', ".
"`status` ENUM('ACTIVE','UNPUBLISHED','BACKUP') NOT NULL DEFAULT 'ACTIVE', ".
"`timestamp` TIMESTAMP, ".
"PRIMARY KEY (`archive_id`), ".
"KEY (`section_id`, `page_id`, `status`) ".
") ENGINE=MyIsam AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
if (!$database->query($SQL))
$admin->print_error($database->get_error());
// create the WYSIWYG extension table
$SQL = "CREATE TABLE IF NOT EXISTS `".TABLE_PREFIX."mod_wysiwyg_extension` ( ".
"`extension_id` INT (11) NOT NULL AUTO_INCREMENT, ".
"`section_id` INT(11) NOT NULL DEFAULT '0', ".
"`page_id` INT(11) NOT NULL DEFAULT '0', ".
"`options` VARCHAR(255) NOT NULL DEFAULT '', ".
"`timestamp` TIMESTAMP, ".
"PRIMARY KEY (`extension_id`), ".
"KEY (`section_id`, `page_id`) ".
") ENGINE=MyIsam AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
if (!$database->query($SQL))
$admin->print_error($database->get_error());
// create the TEASER table
$SQL = "CREATE TABLE IF NOT EXISTS `".TABLE_PREFIX."mod_wysiwyg_teaser` ( ".
"`teaser_id` INT(11) NOT NULL AUTO_INCREMENT, ".
"`page_id` INT(11) NOT NULL DEFAULT '0', ".
"`teaser_text` TEXT NOT NULL DEFAULT '', ".
"`hash` VARCHAR(32) NOT NULL DEFAULT '', ".
"`author` VARCHAR(255) NOT NULL DEFAULT '', ".
"`date_publish` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', ".
"`status` ENUM('ACTIVE','UNPUBLISHED','BACKUP') NOT NULL DEFAULT 'ACTIVE', ".
"`timestamp` TIMESTAMP, ".
"PRIMARY KEY (`teaser_id`), ".
"KEY (`page_id`, `status`) ".
") ENGINE=MyIsam AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
if (!$database->query($SQL))
$admin->print_error($database->get_error());
// delete no longer needed files
@unlink(LEPTON_PATH.'/modules/wysiwyg/templates/backend/about.lte');
@unlink(LEPTON_PATH.'/modules/wysiwyg/templates/backend/archive_file.lte');
@unlink(LEPTON_PATH.'/modules/wysiwyg/templates/backend/body.lte');
@unlink(LEPTON_PATH.'/modules/wysiwyg/templates/backend/modify.lte');
// install or upgrade droplets
if (file_exists(WB_PATH.'/modules/droplets/functions.inc.php')) {
include_once(WB_PATH.'/modules/droplets/functions.inc.php');
}
if (!function_exists('wb_unpack_and_import')) {
function wb_unpack_and_import($temp_file, $temp_unzip) {
global $admin, $database;
// Include the PclZip class file
require_once (WB_PATH . '/include/pclzip/pclzip.lib.php');
$errors = array();
$count = 0;
$archive = new PclZip($temp_file);
$list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip);
// now, open all *.php files and search for the header;
// an exported droplet starts with "//:"
if (false !== ($dh = opendir($temp_unzip))) {
while (false !== ($file = readdir($dh))) {
if ($file != "." && $file != "..") {
if (preg_match('/^(.*)\.php$/i', $file, $name_match)) {
// Name of the Droplet = Filename
$name = $name_match[1];
// Slurp file contents
$lines = file($temp_unzip . '/' . $file);
// First line: Description
if (preg_match('#^//\:(.*)$#', $lines[0], $match)) {
$description = $match[1];
}
// Second line: Usage instructions
if (preg_match('#^//\:(.*)$#', $lines[1], $match)) {
$usage = addslashes($match[1]);
}
// Remaining: Droplet code
$code = implode('', array_slice($lines, 2));
// replace 'evil' chars in code
$tags = array(
'<?php',
'?>',
'<?'
);
$code = addslashes(str_replace($tags, '', $code));
// Already in the DB?
$stmt = 'INSERT';
$id = NULL;
$found = $database->get_one("SELECT * FROM " . TABLE_PREFIX . "mod_droplets WHERE name='$name'");
if ($found && $found > 0) {
$stmt = 'REPLACE';
$id = $found;
}
// execute
$result = $database->query("$stmt INTO " . TABLE_PREFIX . "mod_droplets VALUES('$id','$name','$code','$description','" . time() . "','" . $admin->get_user_id() . "',1,0,0,0,'$usage')");
if (!$database->is_error()) {
$count++;
$imports[$name] = 1;
}
else {
$errors[$name] = $database->get_error();
}
}
}
}
closedir($dh);
}
return array(
'count' => $count,
'errors' => $errors,
'imported' => $imports
);
} // function wb_unpack_and_import()
}
// install the droplet(s)
@wb_unpack_and_import(WB_PATH.'/modules/wysiwyg/droplets/droplet_wysiwyg_teaser.zip', WB_PATH . '/temp/unzip/');
require_once LEPTON_PATH.'/modules/manufaktur_config/library.php';
// initialize the configuration
$config = new manufakturConfig();
if (!$config->readXMLfile(LEPTON_PATH.'/modules/wysiwyg/config/extendedWYSIWYG.xml', 'wysiwyg', true)) {
$admin->print_error($config->getError());
}