|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
14
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
|
15
|
|
|
* @author trabis <[email protected]> |
|
16
|
|
|
* |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* |
|
21
|
|
|
* Prepares system prior to attempting to install module |
|
22
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
|
23
|
|
|
* |
|
24
|
|
|
* @return bool true if ready to install, false if not |
|
25
|
|
|
*/ |
|
26
|
|
|
function xoops_module_pre_update_publisher(XoopsModule $module) |
|
27
|
|
|
{ |
|
28
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
|
29
|
|
|
|
|
30
|
|
|
$className = ucfirst($moduleDirName) . 'Utility'; |
|
31
|
|
|
if (!class_exists($className)) { |
|
32
|
|
|
xoops_load('utility', $moduleDirName); |
|
33
|
|
|
} |
|
34
|
|
|
//check for minimum XOOPS version |
|
35
|
|
|
if (!$className::checkVerXoops($module)) { |
|
36
|
|
|
return false; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
// check for minimum PHP version |
|
40
|
|
|
if (!$className::checkVerPhp($module)) { |
|
41
|
|
|
return false; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return true; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* |
|
49
|
|
|
* Performs tasks required during update of the module |
|
50
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
|
51
|
|
|
* @param null $previousVersion |
|
52
|
|
|
* |
|
53
|
|
|
* @return bool true if update successful, false if not |
|
54
|
|
|
*/ |
|
55
|
|
|
|
|
56
|
|
|
function xoops_module_update_publisher(XoopsModule $module, $previousVersion = null) |
|
|
|
|
|
|
57
|
|
|
{ |
|
58
|
|
|
global $xoopsDB; |
|
|
|
|
|
|
59
|
|
|
require_once __DIR__ . '/../../../mainfile.php'; |
|
60
|
|
|
require_once __DIR__ . '/../include/config.php'; |
|
61
|
|
|
|
|
62
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
|
63
|
|
|
|
|
64
|
|
|
if (false !== ($moduleHelper = Xmf\Module\Helper::getHelper($moduleDirName))) { |
|
|
|
|
|
|
65
|
|
|
} else { |
|
66
|
|
|
$moduleHelper = Xmf\Module\Helper::getHelper('system'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
// Load language files |
|
70
|
|
|
$moduleHelper->loadLanguage('admin'); |
|
71
|
|
|
$moduleHelper->loadLanguage('modinfo'); |
|
72
|
|
|
|
|
73
|
|
|
$configurator = new PublisherConfigurator(); |
|
74
|
|
|
/** @var PublisherUtility $utilityClass */ |
|
75
|
|
|
$utilityClass = ucfirst($moduleDirName) . 'Utility'; |
|
76
|
|
|
if (!class_exists($utilityClass)) { |
|
77
|
|
|
xoops_load('utility', $moduleDirName); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
//delete .html entries from the tpl table |
|
81
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; |
|
82
|
|
|
$xoopsDB->queryF($sql); |
|
83
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('newblocks') . " WHERE `dirname` = '" . $module->getVar('dirname', 'n') . "' AND `template` LIKE '%.html%'"; |
|
84
|
|
|
$xoopsDB->queryF($sql); |
|
85
|
|
|
|
|
86
|
|
|
if ($previousVersion <= 105) { |
|
87
|
|
|
|
|
88
|
|
|
//change TEXT fields to NULL |
|
89
|
|
|
$sql = ' ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories') . ' MODIFY `description` TEXT NULL'; |
|
90
|
|
|
$xoopsDB->queryF($sql); |
|
91
|
|
|
$sql = ' ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories') . ' MODIFY `header` TEXT NULL'; |
|
92
|
|
|
$xoopsDB->queryF($sql); |
|
93
|
|
|
$sql = ' ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories') . ' MODIFY `meta_keywords` TEXT NULL'; |
|
94
|
|
|
$xoopsDB->queryF($sql); |
|
95
|
|
|
$sql = ' ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories') . ' MODIFY `meta_description` TEXT NULL'; |
|
96
|
|
|
$xoopsDB->queryF($sql); |
|
97
|
|
|
/** @var PublisherUtility $utilityClass */ |
|
98
|
|
|
$utilityClass = ucfirst($moduleDirName) . 'Utility'; |
|
99
|
|
|
if (!class_exists($utilityClass)) { |
|
100
|
|
|
xoops_load('utility', $moduleDirName); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
//delete old HTML templates |
|
104
|
|
|
if (count($configurator->templateFolders) > 0) { |
|
105
|
|
|
foreach ($configurator->templateFolders as $folder) { |
|
106
|
|
|
$templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder); |
|
107
|
|
|
if (is_dir($templateFolder)) { |
|
108
|
|
|
$templateList = array_diff(scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']); |
|
109
|
|
|
foreach ($templateList as $k => $v) { |
|
110
|
|
|
$fileInfo = new SplFileInfo($templateFolder . $v); |
|
111
|
|
|
if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
|
112
|
|
|
if (file_exists($templateFolder . $v)) { |
|
113
|
|
|
unlink($templateFolder . $v); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
// --- DELETE OLD FILES --------------- |
|
122
|
|
|
if (count($configurator->oldFiles) > 0) { |
|
123
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
|
|
|
|
|
|
124
|
|
|
foreach (array_keys($configurator->oldFiles) as $i) { |
|
125
|
|
|
$tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]); |
|
126
|
|
|
if (is_file($tempFile)) { |
|
127
|
|
|
unlink($tempFile); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
// --- DELETE OLD FOLDERS --------------- |
|
133
|
|
|
xoops_load('XoopsFile'); |
|
134
|
|
|
if (count($configurator->oldFolders) > 0) { |
|
135
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
|
|
|
|
|
|
136
|
|
|
foreach (array_keys($configurator->oldFolders) as $i) { |
|
137
|
|
|
$tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]); |
|
138
|
|
|
/** @var XoopsObjectHandler $folderHandler */ |
|
139
|
|
|
$folderHandler = XoopsFile::getHandler('folder', $tempFolder); |
|
140
|
|
|
$folderHandler->delete($tempFolder); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
// --- CREATE FOLDERS --------------- |
|
145
|
|
View Code Duplication |
if (count($configurator->uploadFolders) > 0) { |
|
|
|
|
|
|
146
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
|
|
|
|
|
|
147
|
|
|
foreach (array_keys($configurator->uploadFolders) as $i) { |
|
148
|
|
|
$utilityClass::createFolder($configurator->uploadFolders[$i]); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
// --- COPY blank.png FILES --------------- |
|
153
|
|
View Code Duplication |
if (count($configurator->blankFiles) > 0) { |
|
|
|
|
|
|
154
|
|
|
$file = __DIR__ . '/../assets/images/blank.png'; |
|
155
|
|
|
foreach (array_keys($configurator->blankFiles) as $i) { |
|
156
|
|
|
$dest = $configurator->blankFiles[$i] . '/blank.png'; |
|
157
|
|
|
$utilityClass::copyFile($file, $dest); |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
//delete .html entries from the tpl table |
|
162
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; |
|
163
|
|
|
$xoopsDB->queryF($sql); |
|
164
|
|
|
} |
|
165
|
|
|
/* @var $gpermHandler XoopsGroupPermHandler */ |
|
166
|
|
|
$gpermHandler = xoops_getHandler('groupperm'); |
|
167
|
|
|
|
|
168
|
|
|
return $gpermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
|
169
|
|
|
} |
|
170
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: