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
|
|
|
* @copyright XOOPS Project http://xoops.org/ |
14
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
15
|
|
|
* @package |
16
|
|
|
* @since |
17
|
|
|
* @author XOOPS Development Team |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
if ((!defined('XOOPS_ROOT_PATH')) || !($GLOBALS['xoopsUser'] instanceof XoopsUser) |
|
|
|
|
21
|
|
|
|| !$GLOBALS['xoopsUser']->IsAdmin() |
22
|
|
|
) { |
23
|
|
|
exit('Restricted access' . PHP_EOL); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param string $tablename |
28
|
|
|
* |
29
|
|
|
* @return bool |
30
|
|
|
*/ |
31
|
|
|
function tableExists($tablename) |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$result = $GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'"); |
34
|
|
|
|
35
|
|
|
return ($GLOBALS['xoopsDB']->getRowsNum($result) > 0) ? true : false; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* |
40
|
|
|
* Prepares system prior to attempting to install module |
41
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
42
|
|
|
* |
43
|
|
|
* @return bool true if ready to install, false if not |
44
|
|
|
*/ |
45
|
|
|
function xoops_module_pre_update_xfguestbook(XoopsModule $module) |
46
|
|
|
{ |
47
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
48
|
|
|
$className = ucfirst($moduleDirName) . 'Util'; |
49
|
|
|
if (!class_exists($className)) { |
50
|
|
|
xoops_load('util', $moduleDirName); |
51
|
|
|
} |
52
|
|
|
//check for minimum XOOPS version |
53
|
|
|
if (!$className::checkVerXoops($module)) { |
54
|
|
|
return false; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// check for minimum PHP version |
58
|
|
|
if (!$className::checkVerPhp($module)) { |
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
global $xoopsDB; |
|
|
|
|
62
|
|
|
//delete .html entries from the tpl table |
63
|
|
|
|
64
|
|
|
// $sql = 'DELETE FROM ' . $xoopsDB->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . '\' AND `tpl_file` LIKE \'%.tpl%\''; |
65
|
|
|
// $xoopsDB->queryF($sql); |
66
|
|
|
// |
67
|
|
|
// $sql = 'DELETE FROM ' . $xoopsDB->prefix('newblocks') . " WHERE `dirname` = '" . $module->getVar('dirname', 'n') . "' AND `template` LIKE '%.tpl%'"; |
68
|
|
|
// $xoopsDB->queryF($sql); |
69
|
|
|
|
70
|
|
|
return true; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* |
75
|
|
|
* Performs tasks required during update of the module |
76
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
77
|
|
|
* @param null $previousVersion |
78
|
|
|
* |
79
|
|
|
* @return bool true if update successful, false if not |
80
|
|
|
*/ |
|
|
|
|
81
|
|
|
|
82
|
|
|
function xoops_module_update_xfguestbook(XoopsModule $module, $previousVersion = null) |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
global $xoopsDB; |
|
|
|
|
85
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
86
|
|
|
$capsDirName = strtoupper($moduleDirName); |
|
|
|
|
87
|
|
|
|
88
|
|
|
if ($previousVersion < 330) { |
89
|
|
|
|
90
|
|
|
include_once __DIR__ . '/config.php'; |
91
|
|
|
$configurator = new ModuleConfigurator(); |
92
|
|
|
$classUtil = ucfirst($moduleDirName) . 'Util'; |
93
|
|
|
if (!class_exists($classUtil)) { |
94
|
|
|
xoops_load('util', $moduleDirName); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
//delete old HTML templates |
98
|
|
|
if (count($configurator->templateFolders) > 0) { |
99
|
|
|
foreach ($configurator->templateFolders as $folder) { |
100
|
|
|
$templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder); |
101
|
|
|
if (is_dir($templateFolder)) { |
102
|
|
|
$templateList = array_diff(scandir($templateFolder), array('..', '.')); |
103
|
|
|
foreach ($templateList as $k => $v) { |
104
|
|
|
$fileInfo = new SplFileInfo($templateFolder . $v); |
105
|
|
|
if ($fileInfo->getExtension() === 'html' && $fileInfo->getFilename() !== 'index.html') { |
106
|
|
|
if (file_exists($templateFolder . $v)) { |
107
|
|
|
unlink($templateFolder . $v); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
// --- DELETE OLD FILES --------------- |
116
|
|
|
if (count($configurator->oldFiles) > 0) { |
117
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
|
|
|
|
118
|
|
|
foreach (array_keys($configurator->oldFiles) as $i) { |
119
|
|
|
$tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]); |
120
|
|
|
if (is_file($tempFile)) { |
121
|
|
|
unlink($tempFile); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
// --- DELETE OLD FOLDERS --------------- |
127
|
|
|
xoops_load('XoopsFile'); |
128
|
|
|
if (count($configurator->oldFolders) > 0) { |
129
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
|
|
|
|
130
|
|
|
foreach (array_keys($configurator->oldFolders) as $i) { |
131
|
|
|
$tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]); |
132
|
|
|
/** @var XoopsObjectHandler $folderHandler */ |
133
|
|
|
$folderHandler = XoopsFile::getHandler('folder', $tempFolder); |
134
|
|
|
$folderHandler->delete($tempFolder); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
// --- CREATE FOLDERS --------------- |
139
|
|
View Code Duplication |
if (count($configurator->uploadFolders) > 0) { |
|
|
|
|
140
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
|
|
|
|
141
|
|
|
foreach (array_keys($configurator->uploadFolders) as $i) { |
142
|
|
|
$classUtil::createFolder($configurator->uploadFolders[$i]); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
// --- COPY blank.png FILES --------------- |
147
|
|
View Code Duplication |
if (count($configurator->blankFiles) > 0) { |
|
|
|
|
148
|
|
|
$file = __DIR__ . '/../assets/images/blank.png'; |
149
|
|
|
foreach (array_keys($configurator->blankFiles) as $i) { |
150
|
|
|
$dest = $configurator->blankFiles[$i] . '/blank.png'; |
151
|
|
|
$classUtil::copyFile($file, $dest); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
//delete .html entries from the tpl table |
156
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . '\' AND `tpl_file` LIKE \'%.html%\''; |
157
|
|
|
$xoopsDB->queryF($sql); |
158
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('newblocks') . " WHERE `dirname` = '" . $module->getVar('dirname', 'n') . "' AND `template` LIKE '%.html%'"; |
159
|
|
|
$xoopsDB->queryF($sql); |
160
|
|
|
|
161
|
|
|
/** @var XoopsGroupPermHandler $gpermHandler */ |
162
|
|
|
// $gpermHandler = xoops_getHandler('groupperm'); |
|
|
|
|
163
|
|
|
// return $gpermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
|
|
|
|
164
|
|
|
|
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.