1
|
|
|
<?php declare(strict_types=1); |
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 https://www.fsf.org/copyleft/gpl.html GNU public license |
15
|
|
|
* @author trabis <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
use XoopsModules\Publisher\Common; |
19
|
|
|
use XoopsModules\Publisher\Helper; |
20
|
|
|
use XoopsModules\Publisher\Utility; |
21
|
|
|
|
22
|
|
|
if ((!defined('XOOPS_ROOT_PATH')) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser) |
23
|
|
|
|| !$GLOBALS['xoopsUser']->isAdmin()) { |
24
|
|
|
exit('Restricted access' . PHP_EOL); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$helper = Helper::getInstance(); |
28
|
|
|
$helper->loadLanguage('field'); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Prepares system prior to attempting to install module |
32
|
|
|
* @param \XoopsModule $module {@link XoopsModule} |
33
|
|
|
* |
34
|
|
|
* @return bool true if ready to install, false if not |
35
|
|
|
*/ |
36
|
|
|
function xoops_module_pre_update_publisher(\XoopsModule $module) |
37
|
|
|
{ |
38
|
|
|
$utility = new Utility(); |
39
|
|
|
|
40
|
|
|
$xoopsSuccess = $utility::checkVerXoops($module); |
41
|
|
|
$phpSuccess = $utility::checkVerPhp($module); |
42
|
|
|
|
43
|
|
|
return $xoopsSuccess && $phpSuccess; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Performs tasks required during update of the module |
48
|
|
|
* @param \XoopsModule $module {@link XoopsModule} |
49
|
|
|
* @param null|string $previousVersion |
50
|
|
|
* |
51
|
|
|
* @return bool true if update successful, false if not |
52
|
|
|
*/ |
53
|
|
|
function xoops_module_update_publisher(\XoopsModule $module, ?string $previousVersion = null) |
54
|
|
|
{ |
55
|
|
|
// global $GLOBALS['xoopsDB']; |
56
|
|
|
$moduleDirName = \basename(\dirname(__DIR__)); |
57
|
|
|
// $moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
58
|
|
|
|
59
|
|
|
/** @var Helper $helper */ |
60
|
|
|
/** @var Common\Configurator $configurator */ |
61
|
|
|
$helper = Helper::getInstance(); |
62
|
|
|
$configurator = new Common\Configurator(); |
63
|
|
|
$utility = new Utility(); |
64
|
|
|
$errors = 0; |
|
|
|
|
65
|
|
|
|
66
|
|
|
$helper->loadLanguage('common'); |
67
|
|
|
$helper->loadLanguage('field'); |
68
|
|
|
|
69
|
|
|
//delete .html entries from the tpl table |
70
|
|
|
$sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; |
71
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
72
|
|
|
$sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('newblocks') . " WHERE `dirname` = '" . $module->getVar('dirname', 'n') . "' AND `template` LIKE '%.html%'"; |
73
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
74
|
|
|
|
75
|
|
|
if ($previousVersion <= 105) { |
76
|
|
|
//change TEXT fields to NULL |
77
|
|
|
$sql = ' ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories') . ' MODIFY `description` TEXT NULL'; |
78
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
79
|
|
|
$sql = ' ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories') . ' MODIFY `header` TEXT NULL'; |
80
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
81
|
|
|
$sql = ' ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories') . ' MODIFY `meta_keywords` TEXT NULL'; |
82
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
83
|
|
|
$sql = ' ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories') . ' MODIFY `meta_description` TEXT NULL'; |
84
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
85
|
|
|
|
86
|
|
|
//delete old HTML templates |
87
|
|
|
if (count($configurator->templateFolders) > 0) { |
88
|
|
|
foreach ($configurator->templateFolders as $folder) { |
89
|
|
|
$templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder); |
90
|
|
|
if (is_dir($templateFolder)) { |
91
|
|
|
$templateList = array_diff(scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']); |
92
|
|
|
foreach ($templateList as $k => $v) { |
93
|
|
|
$fileInfo = new \SplFileInfo($templateFolder . $v); |
94
|
|
|
if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
95
|
|
|
if (\is_file($templateFolder . $v)) { |
96
|
|
|
unlink($templateFolder . $v); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
// --- DELETE OLD FILES --------------- |
105
|
|
|
if (count($configurator->oldFiles) > 0) { |
106
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
107
|
|
|
foreach (array_keys($configurator->oldFiles) as $i) { |
108
|
|
|
$tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]); |
109
|
|
|
if (\is_file($tempFile)) { |
110
|
|
|
unlink($tempFile); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
// --- DELETE OLD FOLDERS --------------- |
116
|
|
|
xoops_load('XoopsFile'); |
117
|
|
|
if (count($configurator->oldFolders) > 0) { |
118
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
119
|
|
|
foreach (array_keys($configurator->oldFolders) as $i) { |
120
|
|
|
$tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]); |
121
|
|
|
/** @var \XoopsObjectHandler $folderHandler */ |
122
|
|
|
$folderHandler = \XoopsFile::getHandler('folder', $tempFolder); |
123
|
|
|
$folderHandler->delete($tempFolder); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
// --- CREATE FOLDERS --------------- |
128
|
|
|
if (count($configurator->uploadFolders) > 0) { |
129
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
130
|
|
|
foreach (array_keys($configurator->uploadFolders) as $i) { |
131
|
|
|
$utility::createFolder($configurator->uploadFolders[$i]); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
// --- COPY blank.png FILES --------------- |
136
|
|
|
if (count($configurator->copyBlankFiles) > 0) { |
137
|
|
|
$file = \dirname(__DIR__) . '/assets/images/blank.png'; |
138
|
|
|
foreach (array_keys($configurator->copyBlankFiles) as $i) { |
139
|
|
|
$dest = $configurator->copyBlankFiles[$i] . '/blank.png'; |
140
|
|
|
$utility::copyFile($file, $dest); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
//delete .html entries from the tpl table |
145
|
|
|
$sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; |
146
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
147
|
|
|
|
148
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
149
|
|
|
$grouppermHandler = xoops_getHandler('groupperm'); |
150
|
|
|
|
151
|
|
|
return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
// check table items for field `dateexpire` |
155
|
|
|
if (!$GLOBALS['xoopsDB']->query('SELECT dateexpire FROM ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_items'))) { |
156
|
|
|
$sql = 'ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_items') . " ADD `dateexpire` INT(11) NULL DEFAULT '0' AFTER `datesub`"; |
157
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
158
|
|
|
} |
159
|
|
|
// check table items for field `votetype` |
160
|
|
|
if (!$GLOBALS['xoopsDB']->query('SELECT votetype FROM ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_items'))) { |
161
|
|
|
$sql = 'ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_items') . " ADD `votetype` TINYINT(1) NOT NULL DEFAULT '0' AFTER `item_tag`"; |
162
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
// Publisher 1.8.0 |
166
|
|
|
// check table items for field `template_item` for custom templates |
167
|
|
|
if (!$GLOBALS['xoopsDB']->query('SELECT template_item FROM ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories'))) { |
168
|
|
|
$sql = 'ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($module->getVar('dirname', 'n') . '_categories') . " ADD `template_item` VARCHAR(150) NOT NULL DEFAULT '' AFTER `template`"; |
169
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
return true; |
173
|
|
|
} |
174
|
|
|
|