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