|
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 XOOPS Project (https://xoops.org) |
|
16
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
17
|
|
|
* @package |
|
18
|
|
|
* @author XOOPS Development Team |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
use XoopsModules\Gbook; |
|
22
|
|
|
|
|
23
|
|
|
if ((!defined('XOOPS_ROOT_PATH')) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser) |
|
24
|
|
|
|| !$GLOBALS['xoopsUser']->isAdmin()) { |
|
25
|
|
|
exit('Restricted access' . PHP_EOL); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
|
|
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_gbook(\XoopsModule $module) |
|
37
|
|
|
{ |
|
38
|
|
|
$utility = new Gbook\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 $previousVersion |
|
|
|
|
|
|
50
|
|
|
* |
|
51
|
|
|
* @return bool true if update successful, false if not |
|
52
|
|
|
*/ |
|
53
|
|
|
function xoops_module_update_gbook(\XoopsModule $module, $previousVersion = null) |
|
54
|
|
|
{ |
|
55
|
|
|
global $xoopsDB; |
|
56
|
|
|
|
|
57
|
|
|
if ($previousVersion < 111) { |
|
58
|
|
|
// delete old HTML template files ============================ |
|
59
|
|
|
$templateDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/templates/'); |
|
60
|
|
|
if (is_dir($templateDirectory)) { |
|
61
|
|
|
$templateList = array_diff(scandir($templateDirectory, SCANDIR_SORT_NONE), ['..', '.']); |
|
62
|
|
|
foreach ($templateList as $k => $v) { |
|
63
|
|
|
$fileInfo = new \SplFileInfo($templateDirectory . $v); |
|
64
|
|
|
if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
|
65
|
|
|
if (is_file($templateDirectory . $v)) { |
|
66
|
|
|
unlink($templateDirectory . $v); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
// delete old block html template files ============================ |
|
72
|
|
|
$templateDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/templates/blocks/'); |
|
73
|
|
|
if (is_dir($templateDirectory)) { |
|
74
|
|
|
$templateList = array_diff(scandir($templateDirectory, SCANDIR_SORT_NONE), ['..', '.']); |
|
75
|
|
|
foreach ($templateList as $k => $v) { |
|
76
|
|
|
$fileInfo = new \SplFileInfo($templateDirectory . $v); |
|
77
|
|
|
if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
|
78
|
|
|
if (is_file($templateDirectory . $v)) { |
|
79
|
|
|
unlink($templateDirectory . $v); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
//delete old files: =================== |
|
85
|
|
|
$oldFiles = [ |
|
86
|
|
|
'/assets/images/logo_module.png', |
|
87
|
|
|
'/templates/gbook.css', |
|
88
|
|
|
]; |
|
89
|
|
|
|
|
90
|
|
|
foreach (array_keys($oldFiles) as $file) { |
|
91
|
|
|
if (is_file($file)) { |
|
92
|
|
|
unlink($GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . $oldFiles[$file])); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
//delete .html entries from the tpl table |
|
97
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; |
|
98
|
|
|
$xoopsDB->queryF($sql); |
|
99
|
|
|
|
|
100
|
|
|
// Load class XoopsFile ==================== |
|
101
|
|
|
xoops_load('XoopsFile'); |
|
102
|
|
|
|
|
103
|
|
|
//delete /images directory ============ |
|
104
|
|
|
$imagesDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/images/'); |
|
105
|
|
|
$folderHandler = XoopsFile::getHandler('folder', $imagesDirectory); |
|
106
|
|
|
$folderHandler->delete($imagesDirectory); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
|
110
|
|
|
$grouppermHandler = xoops_getHandler('groupperm'); |
|
111
|
|
|
|
|
112
|
|
|
return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
|
113
|
|
|
} |
|
114
|
|
|
|