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 GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
15
|
|
|
* @author XOOPS Development Team |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
use XoopsModules\Marquee\{ |
19
|
|
|
Common\Configurator, |
20
|
|
|
Helper, |
21
|
|
|
Utility |
22
|
|
|
}; |
23
|
|
|
|
24
|
|
|
if ((!defined('XOOPS_ROOT_PATH')) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser) |
25
|
|
|
|| !$GLOBALS['xoopsUser']->isAdmin()) { |
26
|
|
|
exit('Restricted access' . PHP_EOL); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Prepares system prior to attempting to install module |
31
|
|
|
* @param \XoopsModule $module {@link XoopsModule} |
32
|
|
|
* |
33
|
|
|
* @return bool true if ready to install, false if not |
34
|
|
|
*/ |
35
|
|
|
function xoops_module_pre_update_marquee(\XoopsModule $module) |
36
|
|
|
{ |
37
|
|
|
$utility = new Utility(); |
38
|
|
|
$xoopsSuccess = $utility::checkVerXoops($module); |
39
|
|
|
$phpSuccess = $utility::checkVerPhp($module); |
40
|
|
|
|
41
|
|
|
return $xoopsSuccess && $phpSuccess; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Performs tasks required during update of the module |
46
|
|
|
* @param \XoopsModule $module {@link XoopsModule} |
47
|
|
|
* @param null $previousVersion |
|
|
|
|
48
|
|
|
* |
49
|
|
|
* @return bool true if update successful, false if not |
50
|
|
|
*/ |
51
|
|
|
function xoops_module_update_marquee(\XoopsModule $module, $previousVersion = null) |
52
|
|
|
{ |
53
|
|
|
$moduleDirName = \basename(\dirname(__DIR__)); |
54
|
|
|
$moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
|
|
|
|
55
|
|
|
/** @var Marquee\Helper $helper */ /** @var Marquee\Utility $utility */ |
56
|
|
|
/** @var Marquee\Common\Configurator $configurator */ |
57
|
|
|
$helper = Helper::getInstance(); |
|
|
|
|
58
|
|
|
$utility = new Utility(); |
59
|
|
|
$configurator = new Configurator(); |
60
|
|
|
if ($previousVersion < 260) { |
61
|
|
|
//rename column EXAMPLE |
62
|
|
|
$tables = new Xmf\Database\Tables(); |
63
|
|
|
$table = 'marqueex_categories'; |
64
|
|
|
$column = 'ordre'; |
65
|
|
|
$newName = 'order'; |
66
|
|
|
$attributes = "INT(5) NOT NULL DEFAULT '0'"; |
67
|
|
|
if ($tables->useTable($table)) { |
68
|
|
|
$tables->alterColumn($table, $column, $attributes, $newName); |
69
|
|
|
if (!$tables->executeQueue()) { |
70
|
|
|
echo '<br>' . _AM_MARQUEE_UPGRADEFAILED0 . ' ' . $tables->getLastError(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
//delete old HTML templates |
74
|
|
|
if (count($configurator->templateFolders) > 0) { |
75
|
|
|
foreach ($configurator->templateFolders as $folder) { |
76
|
|
|
$templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder); |
77
|
|
|
if (is_dir($templateFolder)) { |
78
|
|
|
$templateList = array_diff(scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']); |
79
|
|
|
foreach ($templateList as $k => $v) { |
80
|
|
|
$fileInfo = new \SplFileInfo($templateFolder . $v); |
81
|
|
|
if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
82
|
|
|
if (\is_file($templateFolder . $v)) { |
83
|
|
|
unlink($templateFolder . $v); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
// --- DELETE OLD FILES --------------- |
91
|
|
|
if (count($configurator->oldFiles) > 0) { |
92
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
93
|
|
|
foreach (array_keys($configurator->oldFiles) as $i) { |
94
|
|
|
$tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]); |
95
|
|
|
if (\is_file($tempFile)) { |
96
|
|
|
unlink($tempFile); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
// --- DELETE OLD FOLDERS --------------- |
101
|
|
|
xoops_load('XoopsFile'); |
102
|
|
|
if (count($configurator->oldFolders) > 0) { |
103
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
104
|
|
|
foreach (array_keys($configurator->oldFolders) as $i) { |
105
|
|
|
$tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]); |
106
|
|
|
/** @var XoopsObjectHandler $folderHandler */ |
107
|
|
|
$folderHandler = \XoopsFile::getHandler('folder', $tempFolder); |
108
|
|
|
$folderHandler->delete($tempFolder); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
// --- CREATE FOLDERS --------------- |
112
|
|
|
if (count($configurator->uploadFolders) > 0) { |
113
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
114
|
|
|
foreach (array_keys($configurator->uploadFolders) as $i) { |
115
|
|
|
$utility::createFolder($configurator->uploadFolders[$i]); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
// --- COPY blank.png FILES --------------- |
119
|
|
|
if (count($configurator->copyBlankFiles) > 0) { |
120
|
|
|
$file = \dirname(__DIR__) . '/assets/images/blank.png'; |
121
|
|
|
foreach (array_keys($configurator->copyBlankFiles) as $i) { |
122
|
|
|
$dest = $configurator->copyBlankFiles[$i] . '/blank.png'; |
123
|
|
|
$utility::copyFile($file, $dest); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
//delete .html entries from the tpl table |
127
|
|
|
$sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; |
128
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
129
|
|
|
|
130
|
|
|
//delete old .html entries from the newblocks table |
131
|
|
|
$sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('newblocks') . " WHERE `mid` = '" . $module->getVar('mid') . "' AND `template` LIKE '%.html%'"; |
132
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
133
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
134
|
|
|
$grouppermHandler = xoops_getHandler('groupperm'); |
135
|
|
|
|
136
|
|
|
return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
return true; |
140
|
|
|
} |
141
|
|
|
|