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