1
|
|
|
<?php |
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
|
|
|
* Module: xsitemap |
14
|
|
|
* |
15
|
|
|
* @package module\Xsitemap\includes |
16
|
|
|
* @author Taiwen Jiang <[email protected]> |
17
|
|
|
* @author ZySpec <[email protected]> |
18
|
|
|
* @copyright https://xoops.org 2001-2017 XOOPS Project |
19
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
20
|
|
|
* @link https://xoops.org XOOPS |
21
|
|
|
* @since 1.00 |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
use XoopsModules\Xsitemap; |
25
|
|
|
use XoopsModules\Xsitemap\Helper; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @internal {Make sure you PROTECT THIS FILE} |
29
|
|
|
*/ |
30
|
|
|
if ((!defined('XOOPS_ROOT_PATH')) |
31
|
|
|
|| !($GLOBALS['xoopsUser'] instanceof \XoopsUser) |
32
|
|
|
|| !$GLOBALS['xoopsUser']->isAdmin()) { |
33
|
|
|
exit('Restricted access' . PHP_EOL); |
34
|
|
|
} |
35
|
|
|
/** |
36
|
|
|
* Prepares system prior to attempting to install module |
37
|
|
|
* |
38
|
|
|
* @param \XoopsModule $module |
39
|
|
|
* |
40
|
|
|
* @return bool true if ready to install, false if not |
41
|
|
|
*/ |
42
|
|
|
function xoops_module_pre_install_xsitemap(\XoopsModule $module) |
43
|
|
|
{ |
44
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
|
|
|
|
45
|
|
|
$utility = new Xsitemap\Utility(); |
46
|
|
|
$xoopsSuccess = $utility::checkVerXoops($module); |
47
|
|
|
$phpSuccess = $utility::checkVerPhp($module); |
48
|
|
|
return $xoopsSuccess && $phpSuccess; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Performs tasks required during installation of the module |
53
|
|
|
* |
54
|
|
|
* @param \XoopsModule $module |
55
|
|
|
* |
56
|
|
|
* @return bool true if installation successful, false if not |
57
|
|
|
*/ |
58
|
|
|
function xoops_module_install_xsitemap(\XoopsModule $module) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
return true; |
61
|
|
|
/** @internal following code removed, it will fail because module not fully loaded/available until |
62
|
|
|
* after install, module now uses XOOPS preload instead */ |
63
|
|
|
/* |
64
|
|
|
//28/08/2009 by urbanspaceman |
65
|
|
|
require_once $GLOBALS['xoops']->path("class/tree.php"); |
66
|
|
|
require_once $GLOBALS['xoops']->path("modules/" . $module->dirname() . "/class/plugin.php"); |
67
|
|
|
require_once $GLOBALS['xoops']->path("modules/" . $module->dirname() . "/include/functions.php"); |
68
|
|
|
require_once $GLOBALS['xoops']->path("modules/" . $module->dirname(). "/class/DummyObject.php"); |
69
|
|
|
|
70
|
|
|
//Create the xsitemap.xml file in the site root |
71
|
|
|
$xsitemap_show = Utility::generateSitemap(); |
72
|
|
|
return Utility::saveSitemap($xsitemap_show) ? true : false; |
73
|
|
|
*/ |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Prepares system prior to attempting to update module |
78
|
|
|
* |
79
|
|
|
* @param \XoopsModule $module |
80
|
|
|
* |
81
|
|
|
* @return bool true if successfully ready to update module, false if not |
82
|
|
|
*/ |
83
|
|
|
function xoops_module_pre_update_xsitemap(\XoopsModule $module) |
84
|
|
|
{ |
85
|
|
|
/** @var Xsitemap\Helper $helper */ |
86
|
|
|
/** @var Xsitemap\Utility $utility */ |
87
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
|
|
|
|
88
|
|
|
$helper = Helper::getInstance(); |
|
|
|
|
89
|
|
|
$utility = new Xsitemap\Utility(); |
90
|
|
|
$xoopsSuccess = $utility::checkVerXoops($module); |
91
|
|
|
$phpSuccess = $utility::checkVerPhp($module); |
92
|
|
|
return $xoopsSuccess && $phpSuccess; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Functions to upgrade from previous version of the module |
97
|
|
|
* |
98
|
|
|
* @param \XoopsModule $module |
99
|
|
|
* @param int|null $previousVersion |
100
|
|
|
* @return bool true if successfully updated module, false if not |
101
|
|
|
* @internal param int $curr_version version number of module currently installed |
102
|
|
|
*/ |
103
|
|
|
function xoops_module_update_xsitemap(\XoopsModule $module, $previousVersion = null) |
104
|
|
|
{ |
105
|
|
|
/*====================================================================== |
106
|
|
|
//---------------------------------------------------------------- |
107
|
|
|
// Remove xSitemap uploads folder (and all subfolders) if they exist |
108
|
|
|
//----------------------------------------------------------------* |
109
|
|
|
$utility = new Xsitemap\Utility(); |
110
|
|
|
if (!class_exists($utility)) { |
111
|
|
|
xoops_load('utility', $moduleDirName); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
// Recursively delete directories |
115
|
|
|
$xsUploadDir = realpath(XOOPS_UPLOAD_PATH . "/" . $module->dirname()); |
116
|
|
|
$success = $utility::rrmdir($xsUploadDir); |
117
|
|
|
if (true !== $success) { |
118
|
|
|
\Xmf\Language::load('admin', $module->dirname()); |
119
|
|
|
$module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $xsUploadDir)); |
120
|
|
|
} |
121
|
|
|
return $success; |
122
|
|
|
======================================================================*/ |
123
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
124
|
|
|
$moduleDirNameUpper = mb_strtoupper($moduleDirName); |
|
|
|
|
125
|
|
|
/** @var Xsitemap\Helper $helper */ /** @var Xsitemap\Utility $utility */ |
126
|
|
|
/** @var Xsitemap\Common\Configurator $configurator */ |
127
|
|
|
$helper = Helper::getInstance(); |
128
|
|
|
$utility = new Xsitemap\Utility(); |
129
|
|
|
$configurator = new Xsitemap\Common\Configurator(); |
|
|
|
|
130
|
|
|
//----------------------------------------------------------------------- |
131
|
|
|
// Upgrade for Xsitemap < 1.54 |
132
|
|
|
//----------------------------------------------------------------------- |
133
|
|
|
$success = true; |
134
|
|
|
$helper->loadLanguage('modinfo'); |
135
|
|
|
$helper->loadLanguage('admin'); |
136
|
|
|
if ($previousVersion < 154) { |
137
|
|
|
//---------------------------------------------------------------- |
138
|
|
|
// Remove previous css & images directories since they've been relocated to ./assets |
139
|
|
|
// Also remove uploads directories since they're no longer used |
140
|
|
|
//---------------------------------------------------------------- |
141
|
|
|
$old_directories = [ |
142
|
|
|
$helper->path('css/'), |
143
|
|
|
$helper->path('js/'), |
144
|
|
|
$helper->path('images/'), |
145
|
|
|
XOOPS_UPLOAD_PATH . '/' . $module->dirname(), |
146
|
|
|
]; |
147
|
|
|
foreach ($old_directories as $old_dir) { |
148
|
|
|
$dirInfo = new \SplFileInfo($old_dir); |
149
|
|
|
if ($dirInfo->isDir()) { |
150
|
|
|
// The directory exists so delete it |
151
|
|
|
if (false === $utility::rrmdir($old_dir)) { |
152
|
|
|
$module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $old_dir)); |
153
|
|
|
return false; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
unset($dirInfo); |
157
|
|
|
} |
158
|
|
|
//----------------------------------------------------------------------- |
159
|
|
|
// Remove ./template/*.html (except index.html) files since they've |
160
|
|
|
// been replaced by *.tpl files |
161
|
|
|
// Note: this will also remove /template/xsitemap_style.html since it's no longer used |
162
|
|
|
//----------------------------------------------------------------------- |
163
|
|
|
$path = $helper->path('templates/'); |
164
|
|
|
$unfiltered = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); |
165
|
|
|
$iterator = new RegexIterator($unfiltered, "/.*\.html/"); |
166
|
|
|
foreach ($iterator as $name => $fObj) { |
167
|
|
|
if ($fObj->isFile() && ('index.html' !== $fObj->getFilename())) { |
168
|
|
|
if (false === ($success = unlink($fObj->getPathname()))) { |
169
|
|
|
$module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $fObj->getPathname())); |
170
|
|
|
return false; |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
//----------------------------------------------------------------------- |
175
|
|
|
// Now remove a some misc files that were renamed or deprecated |
176
|
|
|
//----------------------------------------------------------------------- |
177
|
|
|
$oldFiles = [ |
178
|
|
|
$helper->path('include/install.php'), |
179
|
|
|
$helper->path('class/module.php'), |
180
|
|
|
$helper->path('class/menu.php'), |
181
|
|
|
]; |
182
|
|
|
foreach ($oldFiles as $file) { |
183
|
|
|
if (is_file($file)) { |
184
|
|
|
if (false === ($delOk = unlink($file))) { |
185
|
|
|
$module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $file)); |
186
|
|
|
} |
187
|
|
|
$success = $success && $delOk; |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
return $success; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Function to perform before module uninstall |
196
|
|
|
* |
197
|
|
|
* @param \XoopsModule $module |
198
|
|
|
* |
199
|
|
|
* @return bool true if successfully executed, false if not |
200
|
|
|
*/ |
201
|
|
|
function xoops_module_pre_uninstall_xsitemap(\XoopsModule $module) |
|
|
|
|
202
|
|
|
{ |
203
|
|
|
return true; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Function to complete upon module uninstall |
208
|
|
|
* |
209
|
|
|
* @param \XoopsModule $module |
210
|
|
|
* |
211
|
|
|
* @return bool true if successfully executed uninstall of module, false if not |
212
|
|
|
*/ |
213
|
|
|
function xoops_module_uninstall_xsitemap(\XoopsModule $module) |
214
|
|
|
{ |
215
|
|
|
// return true; |
216
|
|
|
$moduleDirName = $module->getVar('dirname'); |
217
|
|
|
/** @var \XoopsModules\Xsitemap\Utility $utility */ |
218
|
|
|
$helper = Helper::getInstance(); |
219
|
|
|
$utility = new Xsitemap\Utility(); |
220
|
|
|
// if (!class_exists($utility)) { |
221
|
|
|
// xoops_load('utility', $moduleDirName); |
222
|
|
|
// } |
223
|
|
|
$success = true; |
224
|
|
|
$helper->loadLanguage('admin'); |
225
|
|
|
//------------------------------------------------------------------ |
226
|
|
|
// Remove xSitemap uploads folder (and all subfolders) if they exist |
227
|
|
|
//------------------------------------------------------------------ |
228
|
|
|
$old_directories = [$GLOBALS['xoops']->path("uploads/{$moduleDirName}")]; |
229
|
|
|
foreach ($old_directories as $old_dir) { |
230
|
|
|
$dirInfo = new \SplFileInfo($old_dir); |
231
|
|
|
if ($dirInfo->isDir()) { |
232
|
|
|
// The directory exists so delete it |
233
|
|
|
if (false === $utility::rrmdir($old_dir)) { |
234
|
|
|
$module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $old_dir)); |
235
|
|
|
$success = false; |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
unset($dirInfo); |
239
|
|
|
} |
240
|
|
|
//------------------------------------------------------------------ |
241
|
|
|
// Remove xsitemap.xml from XOOPS root folder if it exists |
242
|
|
|
//------------------------------------------------------------------ |
243
|
|
|
$xmlfile = $GLOBALS['xoops']->path('xsitemap.xml'); |
244
|
|
|
if (is_file($xmlfile)) { |
245
|
|
|
if (false === ($delOk = unlink($xmlfile))) { |
246
|
|
|
$module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $xmlfile)); |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
return $success && $delOk; |
|
|
|
|
250
|
|
|
} |
251
|
|
|
|