1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
You may not change or alter any portion of this comment or credits |
5
|
|
|
of supporting developers from this source code or any supporting source code |
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
7
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Module: lexikon |
15
|
|
|
* |
16
|
|
|
* @category Module |
17
|
|
|
* @package lexikon |
18
|
|
|
* @author XOOPS Development Team <https://xoops.org> |
19
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
20
|
|
|
* @license GPL 2.0 or later |
21
|
|
|
* @link https://xoops.org/ |
22
|
|
|
* @since 1.0.0 |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
use XoopsModules\Lexikon\{ |
26
|
|
|
Common\Configurator, |
27
|
|
|
Helper, |
28
|
|
|
Utility |
29
|
|
|
}; |
30
|
|
|
/** @var Helper $helper */ |
31
|
|
|
/** @var Utility $utility */ |
32
|
|
|
/** @var Configurator $configurator */ |
33
|
|
|
|
34
|
|
|
if ((!defined('XOOPS_ROOT_PATH')) || !$GLOBALS['xoopsUser'] instanceof \XoopsUser |
35
|
|
|
|| !$GLOBALS['xoopsUser']->isAdmin()) { |
36
|
|
|
exit('Restricted access' . PHP_EOL); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
require \dirname(__DIR__) . '/preloads/autoloader.php'; |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Prepares system prior to attempting to install module |
45
|
|
|
* @param \XoopsModule $module {@link XoopsModule} |
46
|
|
|
* |
47
|
|
|
* @return bool true if ready to install, false if not |
48
|
|
|
*/ |
49
|
|
|
function xoops_module_pre_update_lexikon(\XoopsModule $module) |
50
|
|
|
{ |
51
|
|
|
|
52
|
|
|
$helper = Helper::getInstance(); |
53
|
|
|
$utility = new Utility(); |
54
|
|
|
|
55
|
|
|
$xoopsSuccess = $utility::checkVerXoops($module); |
56
|
|
|
$phpSuccess = $utility::checkVerPhp($module); |
57
|
|
|
|
58
|
|
|
return $xoopsSuccess && $phpSuccess; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Performs tasks required during update of the module |
63
|
|
|
* @param \XoopsModule $module {@link XoopsModule} |
64
|
|
|
* @param null $previousVersion |
|
|
|
|
65
|
|
|
* |
66
|
|
|
* @return bool true if update successful, false if not |
67
|
|
|
*/ |
68
|
|
|
function xoops_module_update_lexikon(\XoopsModule $module, $previousVersion = null) |
69
|
|
|
{ |
70
|
|
|
$moduleDirName = \basename(\dirname(__DIR__)); |
71
|
|
|
$moduleDirNameUpper = mb_strtoupper($moduleDirName); |
72
|
|
|
|
73
|
|
|
$helper = Helper::getInstance(); |
74
|
|
|
$utility = new Utility(); |
75
|
|
|
$configurator = new Configurator(); |
76
|
|
|
$helper->loadLanguage('common'); |
77
|
|
|
|
78
|
|
|
if ($previousVersion < 240) { |
79
|
|
|
//delete old HTML templates |
80
|
|
|
if (count($configurator->templateFolders) > 0) { |
81
|
|
|
foreach ($configurator->templateFolders as $folder) { |
82
|
|
|
$templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder); |
83
|
|
|
if (is_dir($templateFolder)) { |
84
|
|
|
$templateList = array_diff(scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']); |
85
|
|
|
foreach ($templateList as $k => $v) { |
86
|
|
|
$fileInfo = new \SplFileInfo($templateFolder . $v); |
87
|
|
|
if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
88
|
|
|
if (is_file($templateFolder . $v)) { |
89
|
|
|
unlink($templateFolder . $v); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
// --- DELETE OLD FILES --------------- |
98
|
|
|
if (count($configurator->oldFiles) > 0) { |
99
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
100
|
|
|
foreach (array_keys($configurator->oldFiles) as $i) { |
101
|
|
|
$tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]); |
102
|
|
|
if (is_file($tempFile)) { |
103
|
|
|
unlink($tempFile); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
// --- DELETE OLD FOLDERS --------------- |
109
|
|
|
xoops_load('XoopsFile'); |
110
|
|
|
if (count($configurator->oldFolders) > 0) { |
111
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
112
|
|
|
foreach (array_keys($configurator->oldFolders) as $i) { |
113
|
|
|
$tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]); |
114
|
|
|
/** @var \XoopsObjectHandler $folderHandler */ |
115
|
|
|
$folderHandler = \XoopsFile::getHandler('folder', $tempFolder); |
116
|
|
|
$folderHandler->delete($tempFolder); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
// --- CREATE FOLDERS --------------- |
121
|
|
|
if (count($configurator->uploadFolders) > 0) { |
122
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
123
|
|
|
foreach (array_keys($configurator->uploadFolders) as $i) { |
124
|
|
|
$utility::createFolder($configurator->uploadFolders[$i]); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
// --- COPY blank.png FILES --------------- |
129
|
|
|
if (count($configurator->copyBlankFiles) > 0) { |
130
|
|
|
$file = \dirname(__DIR__) . '/assets/images/blank.png'; |
131
|
|
|
foreach (array_keys($configurator->copyBlankFiles) as $i) { |
132
|
|
|
$dest = $configurator->copyBlankFiles[$i] . '/blank.png'; |
133
|
|
|
$utility::copyFile($file, $dest); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
//delete .html entries from the tpl table |
138
|
|
|
$sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; |
139
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
140
|
|
|
|
141
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
142
|
|
|
$grouppermHandler = xoops_getHandler('groupperm'); |
143
|
|
|
|
144
|
|
|
return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return true; |
148
|
|
|
} |
149
|
|
|
|