1
|
|
|
<?php declare(strict_types=1);
|
2
|
|
|
/*
|
3
|
|
|
You may not change or alter any portion of this comment or credits of
|
4
|
|
|
supporting developers from this source code or any supporting source code
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit
|
6
|
|
|
authors.
|
7
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, but
|
9
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
11
|
|
|
*/
|
12
|
|
|
|
13
|
|
|
/**
|
14
|
|
|
* Module: XoopsFAQ
|
15
|
|
|
*
|
16
|
|
|
* @author Richard Griffith <[email protected]>
|
17
|
|
|
* @author trabis <[email protected]>
|
18
|
|
|
* @author XOOPS Module Development Team
|
19
|
|
|
* @copyright Copyright (c) 2001-2017 {@link https://xoops.org XOOPS Project}
|
20
|
|
|
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU Public License
|
21
|
|
|
* @since File available since version 1.25
|
22
|
|
|
*/
|
23
|
|
|
|
24
|
|
|
use XoopsModules\Xoopsfaq\{
|
25
|
|
|
Helper,
|
26
|
|
|
Utility
|
27
|
|
|
};
|
28
|
|
|
|
29
|
|
|
/* @internal {Make sure you PROTECT THIS FILE} */
|
30
|
|
|
|
31
|
|
|
if ((!defined('XOOPS_ROOT_PATH'))
|
32
|
|
|
|| !($GLOBALS['xoopsUser'] instanceof \XoopsUser)
|
33
|
|
|
|| !($GLOBALS['xoopsUser']->isAdmin())) {
|
34
|
|
|
exit('Restricted access' . PHP_EOL);
|
35
|
|
|
}
|
36
|
|
|
|
37
|
|
|
/**
|
38
|
|
|
* Pre-installation checks before installation of Xoopsfaq
|
39
|
|
|
*
|
40
|
|
|
* @param string $prev_version version * 100
|
41
|
|
|
*
|
42
|
|
|
* @return bool success ok to install
|
43
|
|
|
*
|
44
|
|
|
* @see Utility
|
45
|
|
|
*/
|
46
|
|
|
function xoops_module_pre_update_xoopsfaq(\XoopsModule $module, string $prev_version)
|
|
|
|
|
47
|
|
|
{
|
48
|
|
|
$xoopsSuccess = Utility::checkVerXoops($module);
|
49
|
|
|
$phpSuccess = Utility::checkVerPhp($module);
|
50
|
|
|
|
51
|
|
|
return $xoopsSuccess && $phpSuccess;
|
52
|
|
|
}
|
53
|
|
|
|
54
|
|
|
/**
|
55
|
|
|
* Upgrade works to update Xoopsfaq from previous versions
|
56
|
|
|
*
|
57
|
|
|
* @param string $prev_version version * 100
|
58
|
|
|
*
|
59
|
|
|
* @return bool
|
60
|
|
|
*
|
61
|
|
|
* @see Utility
|
62
|
|
|
*
|
63
|
|
|
* @see Xmf\Module\Admin
|
64
|
|
|
*/
|
65
|
|
|
function xoops_module_update_xoopsfaq(XoopsModule $module, string $prev_version)
|
66
|
|
|
{
|
67
|
|
|
$moduleDirName = $module->getVar('dirname');
|
|
|
|
|
68
|
|
|
$helper = Helper::getInstance();
|
69
|
|
|
// if (!class_exists('Xoopsfaq\Utility')) {
|
70
|
|
|
// xoops_load('utility', $moduleDirName);
|
71
|
|
|
// }
|
72
|
|
|
|
73
|
|
|
//----------------------------------------------------------------
|
74
|
|
|
// Upgrade for Xoopsfaq < 1.25
|
75
|
|
|
//----------------------------------------------------------------
|
76
|
|
|
$success = true;
|
77
|
|
|
|
78
|
|
|
$helper->loadLanguage('modinfo');
|
79
|
|
|
$helper->loadLanguage('admin');
|
80
|
|
|
|
81
|
|
|
if ($prev_version < 125) {
|
82
|
|
|
//----------------------------------------------------------------
|
83
|
|
|
// Remove previous .css, .js and .images directories since they've
|
84
|
|
|
// been relocated to ./assets
|
85
|
|
|
//----------------------------------------------------------------
|
86
|
|
|
$old_directories = [
|
87
|
|
|
$helper->path('css/'),
|
88
|
|
|
$helper->path('js/'),
|
89
|
|
|
$helper->path('images/'),
|
90
|
|
|
];
|
91
|
|
|
foreach ($old_directories as $old_dir) {
|
92
|
|
|
$dirInfo = new SplFileInfo($old_dir);
|
93
|
|
|
if ($dirInfo->isDir()) {
|
94
|
|
|
// The directory exists so delete it
|
95
|
|
|
if (!Utility::rrmdir($old_dir)) {
|
96
|
|
|
$module->setErrors(sprintf(_AM_XOOPSFAQ_ERROR_BAD_DEL_PATH, $old_dir));
|
97
|
|
|
|
98
|
|
|
return false;
|
99
|
|
|
}
|
100
|
|
|
}
|
101
|
|
|
unset($dirInfo);
|
102
|
|
|
}
|
103
|
|
|
|
104
|
|
|
//-----------------------------------------------------------------------
|
105
|
|
|
// Remove ./template/*.html (except index.html) files since they've
|
106
|
|
|
// been replaced by *.tpl files
|
107
|
|
|
//-----------------------------------------------------------------------
|
108
|
|
|
$path = $helper->path('templates/');
|
109
|
|
|
$unfiltered = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
|
110
|
|
|
$iterator = new RegexIterator($unfiltered, '/.*\.html/');
|
111
|
|
|
foreach ($iterator as $name => $fObj) {
|
112
|
|
|
if (($fObj->isFile()) && ('index.html' !== $fObj->getFilename())) {
|
113
|
|
|
if (false === ($success = unlink($fObj->getPathname()))) {
|
114
|
|
|
$module->setErrors(sprintf(_AM_XOOPSFAQ_ERROR_BAD_REMOVE, $fObj->getPathname()));
|
115
|
|
|
|
116
|
|
|
return false;
|
117
|
|
|
}
|
118
|
|
|
}
|
119
|
|
|
}
|
120
|
|
|
|
121
|
|
|
//-----------------------------------------------------------------------
|
122
|
|
|
// Now remove a some misc files that were renamed or deprecated
|
123
|
|
|
//-----------------------------------------------------------------------
|
124
|
|
|
$oldFiles = [
|
125
|
|
|
$helper->path('include/functions.php'),
|
126
|
|
|
$helper->path('class/utilities.php'),
|
127
|
|
|
];
|
128
|
|
|
foreach ($oldFiles as $file) {
|
129
|
|
|
if (is_file($file)) {
|
130
|
|
|
if (false === ($delOk = unlink($file))) {
|
131
|
|
|
$module->setErrors(sprintf(_AM_XOOPSFAQ_ERROR_BAD_REMOVE, $file));
|
132
|
|
|
}
|
133
|
|
|
$success = $success && $delOk;
|
134
|
|
|
}
|
135
|
|
|
}
|
136
|
|
|
}
|
137
|
|
|
|
138
|
|
|
return $success;
|
139
|
|
|
}
|
140
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.