This repository has been archived by the owner on Jan 1, 2020. It is now read-only.
/
class.rex_manager.inc.php
519 lines (434 loc) · 16.1 KB
/
class.rex_manager.inc.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
<?php
/**
* Managerklasse zum handeln von rexAddons
*/
/*abstract*/ class rex_baseManager
{
var $i18nPrefix;
/**
* Konstruktor
*
* @param $i18nPrefix Sprachprefix aller I18N Sprachschlüssel
*/
// this is the new style constructor used by newer php versions.
// important: if you change the signatur of this method, change also the signature of rex_baseManager()
function __construct($i18nPrefix)
{
$this->rex_baseManager($i18nPrefix);
}
// this is the deprecated old style constructor kept for compat reasons.
// important: if you change the signatur of this method, change also the signature of __construct()
function rex_baseManager($i18nPrefix)
{
$this->i18nPrefix = $i18nPrefix;
}
/**
* Installiert ein Addon
*
* @param $addonName Name des Addons
* @param $installDump Flag, ob die Datei install.sql importiert werden soll
*/
/*public*/ function install($addonName, $installDump = true)
{
global $REX;
$state = true;
$install_dir = $this->baseFolder($addonName);
$install_file = $install_dir . 'install.inc.php';
$install_sql = $install_dir . 'install.sql';
$config_file = $install_dir . 'config.inc.php';
$files_dir = $install_dir . 'files';
// Prüfen des Addon Ornders auf Schreibrechte,
// damit das Addon später wieder gelöscht werden kann
$state = rex_is_writable($install_dir);
if ($state === true) {
if (is_readable($install_file)) {
// save state of $REX variable for later use with getLastInstalledAddonName()
$rexAddonBeforeInstall = $REX['ADDON']['install'];
// include install file
$this->includeInstaller($addonName, $install_file);
// Wurde das "install" Flag gesetzt?
// Fehlermeldung ausgegeben? Wenn ja, Abbruch
$instmsg = $this->apiCall('getProperty', array($addonName, 'installmsg', ''));
if (!$this->apiCall('isInstalled', array($addonName)) || $instmsg) {
$state = $this->I18N('no_install', $addonName) . '<br />';
if ($instmsg == '') {
// check if there is a mismatch between addon name and addon directory name
$lastInstalledAddonName = $this->getLastInstalledAddonName($rexAddonBeforeInstall);
if ($lastInstalledAddonName != '' && $lastInstalledAddonName != $addonName) {
$state .= $this->I18N('name_mismatch', $lastInstalledAddonName);
} else {
$state .= $this->I18N('no_reason');
}
} else {
$state .= $instmsg;
}
} else {
// check if config file exists
if (is_readable($config_file)) {
if (!$this->apiCall('isActivated', array($addonName))) {
$this->includeConfig($addonName, $config_file);
}
} else {
$state = $this->I18N('config_not_found');
}
if ($installDump === true && $state === true && is_readable($install_sql)) {
$state = rex_install_dump($install_sql);
if ($state !== true) {
$state = 'Error found in install.sql:<br />' . $state;
}
}
// Installation ok
if ($state === true) {
// regenerate Addons file
$state = $this->generateConfig();
}
}
} else {
$state = $this->I18N('install_not_found');
}
}
// Dateien kopieren
if ($state === true && is_dir($files_dir)) {
if (!rex_copyDir($files_dir, $this->mediaFolder($addonName), $REX['MEDIAFOLDER'])) {
$state = $this->I18N('install_cant_copy_files');
}
}
if ($state !== true) {
$this->apiCall('setProperty', array($addonName, 'install', 0));
}
return $state;
}
/**
* De-installiert ein Addon
*
* @param $addonName Name des Addons
*/
/*public*/ function uninstall($addonName)
{
$state = true;
$install_dir = $this->baseFolder($addonName);
$uninstall_file = $install_dir . 'uninstall.inc.php';
$uninstall_sql = $install_dir . 'uninstall.sql';
if (is_readable($uninstall_file)) {
$this->includeUninstaller($addonName, $uninstall_file);
// Wurde das "install" Flag gesetzt?
// Fehlermeldung ausgegeben? Wenn ja, Abbruch
$instmsg = $this->apiCall('getProperty', array($addonName, 'installmsg', ''));
if ($this->apiCall('isInstalled', array($addonName)) || $instmsg) {
$state = $this->I18N('no_uninstall', $addonName) . '<br />';
if ($instmsg == '') {
$state .= $this->I18N('no_reason');
} else {
$state .= $instmsg;
}
} else {
$state = $this->deactivate($addonName);
if ($state === true && is_readable($uninstall_sql)) {
$state = rex_install_dump($uninstall_sql);
if ($state !== true) {
$state = 'Error found in uninstall.sql:<br />' . $state;
}
}
if ($state === true) {
// regenerate Addons file
$state = $this->generateConfig();
}
}
} else {
$state = $this->I18N('uninstall_not_found');
}
$mediaFolder = $this->mediaFolder($addonName);
if ($state === true && is_dir($mediaFolder)) {
if (!rex_deleteDir($mediaFolder, true)) {
$state = $this->I18N('install_cant_delete_files');
}
}
// Fehler beim uninstall -> Addon bleibt installiert
if ($state !== true) {
$this->apiCall('setProperty', array($addonName, 'install', 1));
}
return $state;
}
/**
* Aktiviert ein Addon
*
* @param $addonName Name des Addons
*/
/*public*/ function activate($addonName)
{
if ($this->apiCall('isInstalled', array($addonName))) {
$this->apiCall('setProperty', array($addonName, 'status', 1));
$state = $this->generateConfig();
} else {
$state = $this->I18N('no_activation', $addonName);
}
if ($state !== true) {
$this->apiCall('setProperty', array($addonName, 'status', 0));
}
return $state;
}
/**
* Deaktiviert ein Addon
*
* @param $addonName Name des Addons
*/
/*public*/ function deactivate($addonName)
{
$this->apiCall('setProperty', array($addonName, 'status', 0));
$state = $this->generateConfig();
if ($state !== true) {
$this->apiCall('setProperty', array($addonName, 'status', 1));
}
return $state;
}
/**
* Löscht ein Addon im Filesystem
*
* @param $addonName Name des Addons
*/
/*public*/ function delete($addonName)
{
// zuerst deinstallieren
// bei erfolg, komplett löschen
$state = true;
$state = $state && $this->uninstall($addonName);
$state = $state && rex_deleteDir($this->baseFolder($addonName), true);
$state = $state && $this->generateConfig();
return $state;
}
/**
* Übersetzen eines Sprachschlüssels unter Verwendung des Prefixes
*/
/*protected*/ function I18N()
{
global $I18N;
$args = func_get_args();
$args[0] = $this->i18nPrefix . $args[0];
return rex_call_func(array($I18N, 'msg'), $args, false);
}
/**
* Bindet die config-Datei eines Addons ein
*/
/*protected*/ function includeConfig($addonName, $configFile)
{
trigger_error('Method has to be overridden by subclass!', E_USER_ERROR);
}
/**
* Bindet die installations-Datei eines Addons ein
*/
/*protected*/ function includeInstaller($addonName, $installFile)
{
trigger_error('Method has to be overridden by subclass!', E_USER_ERROR);
}
/**
* Bindet die deinstallations-Datei eines Addons ein
*/
/*protected*/ function includeUninstaller($addonName, $uninstallFile)
{
trigger_error('Method has to be overridden by subclass!', E_USER_ERROR);
}
/**
* Speichert den aktuellen Zustand
*/
/*protected*/ function generateConfig()
{
trigger_error('Method has to be overridden by subclass!', E_USER_ERROR);
}
/**
* Ansprechen einer API funktion
*
* @param $method Name der Funktion
* @param $arguments Array von Parametern/Argumenten
*/
/*protected*/ function apiCall($method, $arguments)
{
trigger_error('Method has to be overridden by subclass!', E_USER_ERROR);
}
/**
* Findet den Basispfad eines Addons
*/
/*protected*/ function baseFolder($addonName)
{
trigger_error('Method has to be overridden by subclass!', E_USER_ERROR);
}
/**
* Findet den Basispfad für Media-Dateien
*/
/*protected*/ function mediaFolder($addonName)
{
trigger_error('Method has to be overridden by subclass!', E_USER_ERROR);
}
/**
* Gibt den Namen des zuletzt installierten Addons aus
*/
/*public*/ function getLastInstalledAddonName($rexAddonBeforeInstall)
{
global $REX;
if (isset($REX['ADDON']['installmsg'])) {
$key = key($REX['ADDON']['installmsg']);
} else {
$diff = array_diff_key($REX['ADDON']['install'], $rexAddonBeforeInstall);
$key = key($diff);
}
if ($key != null) {
return $key;
} else {
return '';
}
}
}
/**
* Manager zum installieren von OOAddons
*/
class rex_addonManager extends rex_baseManager
{
var $configArray;
// this is the new style constructor used by newer php versions.
// important: if you change the signatur of this method, change also the signature of rex_addonManager()
function __construct($configArray)
{
$this->rex_addonManager($configArray);
}
// this is the deprecated old style constructor kept for compat reasons.
// important: if you change the signatur of this method, change also the signature of __construct()
function rex_addonManager($configArray)
{
$this->configArray = $configArray;
parent::rex_baseManager('addon_');
}
/*public*/ function delete($addonName)
{
global $REX, $I18N;
// System AddOns dürfen nicht gelöscht werden!
if (in_array($addonName, $REX['SYSTEM_ADDONS'])) {
return $I18N->msg('addon_systemaddon_delete_not_allowed');
}
return parent::delete($addonName);
}
/*protected*/ function includeConfig($addonName, $configFile)
{
global $REX, $I18N; // Nötig damit im Addon verfügbar
require $configFile;
}
/*protected*/ function includeInstaller($addonName, $installFile)
{
global $REX, $I18N; // Nötig damit im Addon verfügbar
require $installFile;
}
/*protected*/ function includeUninstaller($addonName, $uninstallFile)
{
global $REX, $I18N; // Nötig damit im Addon verfügbar
require $uninstallFile;
}
/*protected*/ function generateConfig()
{
return rex_generateAddons($this->configArray);
}
/*protected*/ function apiCall($method, $arguments)
{
if (!is_array($arguments)) {
trigger_error('Expecting $arguments to be an array!', E_USER_ERROR);
}
return rex_call_func(array('OOAddon', $method), $arguments, false);
}
/*protected*/ function baseFolder($addonName)
{
return rex_addons_folder($addonName);
}
/*protected*/ function mediaFolder($addonName)
{
global $REX;
return $REX['FRONTEND_PATH'] . DIRECTORY_SEPARATOR . $REX['MEDIA_ADDON_DIR'] . DIRECTORY_SEPARATOR . $addonName;
}
}
/**
* Manager zum intallieren von OOPlugins
*/
class rex_pluginManager extends rex_baseManager
{
var $configArray;
var $addonName;
// this is the new style constructor used by newer php versions.
// important: if you change the signatur of this method, change also the signature of rex_pluginManager()
function __construct($configArray, $addonName)
{
$this->rex_pluginManager($configArray, $addonName);
}
// this is the deprecated old style constructor kept for compat reasons.
function rex_pluginManager($configArray, $addonName)
{
$this->configArray = & $configArray;
$this->addonName = $addonName;
parent::rex_baseManager('plugin_');
}
/**
* Wandelt ein AddOn in ein PlugIn eines anderen AddOns um
*
* @param $addonName AddOn dem das PlugIn eingefügt werden soll
* @param $pluginName Name des Plugins
* @param $includeFile Datei die eingebunden und umgewandelt werden soll
*/
static /*public*/ function addon2plugin($addonName, $pluginName, $includeFile)
{
global $REX, $I18N; // Nötig damit im Addon verfügbar
$ADDONSsic = $REX['ADDON'];
$REX['ADDON'] = array();
require $includeFile;
$plugInConfig = array();
if (isset($ADDONSsic['plugins'][$addonName])) {
$plugInConfig = $ADDONSsic['plugins'][$addonName];
}
if (isset($REX['ADDON']) && is_array($REX['ADDON'])) {
foreach (array_keys($REX['ADDON']) as $key) {
// Alle Eigenschaften die das PlugIn betreffen verschieben
if (isset($REX['ADDON'][$key][$pluginName])) {
$plugInConfig[$key][$pluginName] = $REX['ADDON'][$key][$pluginName];
unset($REX['ADDON'][$key][$pluginName]);
// ggf array das leer geworden ist löschen
// damit es beim merge später nicht ein vorhandes überschreibt
if (empty($REX['ADDON'][$key])) {
unset($REX['ADDON'][$key]);
}
}
}
}
// Addoneinstellungen als PlugIndaten speichern
$ADDONSsic['plugins'][$addonName] = $plugInConfig;
// Alle überbleibenden Keys die ggf. andere Addons beinflussen einfließen lassen
$REX['ADDON'] = array_merge_recursive($ADDONSsic, $REX['ADDON']);
}
/*protected*/ function includeConfig($addonName, $configFile)
{
self::addon2plugin($this->addonName, $addonName, $configFile);
}
/*protected*/ function includeInstaller($addonName, $installFile)
{
self::addon2plugin($this->addonName, $addonName, $installFile);
}
/*protected*/ function includeUninstaller($addonName, $uninstallFile)
{
self::addon2plugin($this->addonName, $addonName, $uninstallFile);
}
/*protected*/ function generateConfig()
{
return rex_generatePlugins($this->configArray);
}
/*protected*/ function apiCall($method, $arguments)
{
if (!is_array($arguments)) {
trigger_error('Expecting $arguments to be an array!', E_USER_ERROR);
}
// addonName als 1. Parameter einfügen
array_unshift($arguments, $this->addonName);
return rex_call_func(array('OOPlugin', $method), $arguments, false);
}
/*protected*/ function baseFolder($pluginName)
{
return rex_plugins_folder($this->addonName, $pluginName);
}
/*protected*/ function mediaFolder($pluginName)
{
global $REX;
return $REX['FRONTEND_PATH'] . DIRECTORY_SEPARATOR . $REX['MEDIA_ADDON_DIR'] . DIRECTORY_SEPARATOR . $this->addonName . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $pluginName;
}
}