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
|
|
|
* @author XOOPS Development Team |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
if ((!defined('XOOPS_ROOT_PATH')) || !($GLOBALS['xoopsUser'] instanceof XoopsUser) |
|
|
|
|
20
|
|
|
|| !$GLOBALS['xoopsUser']->IsAdmin() |
21
|
|
|
) { |
22
|
|
|
exit('Restricted access' . PHP_EOL); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $tablename |
27
|
|
|
* |
28
|
|
|
* @return bool |
29
|
|
|
*/ |
30
|
|
|
function tableExists($tablename) |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$result = $GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'"); |
33
|
|
|
|
34
|
|
|
return ($GLOBALS['xoopsDB']->getRowsNum($result) > 0) ? true : false; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* |
39
|
|
|
* Prepares system prior to attempting to install module |
40
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
41
|
|
|
* |
42
|
|
|
* @return bool true if ready to install, false if not |
43
|
|
|
*/ |
44
|
|
|
function xoops_module_pre_update_extgallery(XoopsModule $module) |
45
|
|
|
{ |
46
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
47
|
|
|
$classUtilities = ucfirst($moduleDirName) . 'Utilities'; |
48
|
|
|
if (!class_exists($classUtilities)) { |
49
|
|
|
xoops_load('utilities', $moduleDirName); |
50
|
|
|
} |
51
|
|
|
//check for minimum XOOPS version |
52
|
|
|
if (!$classUtilities::checkXoopsVer($module)) { |
53
|
|
|
return false; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// check for minimum PHP version |
57
|
|
|
if (!$classUtilities::checkPHPVer($module)) { |
58
|
|
|
return false; |
59
|
|
|
} |
60
|
|
|
return true; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* |
65
|
|
|
* Performs tasks required during update of the module |
66
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
67
|
|
|
* @param null $previousVersion |
68
|
|
|
* |
69
|
|
|
* @return bool true if update successful, false if not |
70
|
|
|
*/ |
71
|
|
|
|
72
|
|
|
function xoops_module_update_extgallery(XoopsModule $module, $previousVersion = null) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
global $xoopsDB; |
|
|
|
|
75
|
|
|
|
76
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
77
|
|
|
|
78
|
|
|
$catHandler = xoops_getModuleHandler('publiccat', $moduleDirName); |
79
|
|
|
$catHandler->rebuild(); |
80
|
|
|
|
81
|
|
View Code Duplication |
if ($previousVersion < 101) { |
|
|
|
|
82
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
83
|
|
|
// Remove the UNIQUE key on the rating table. This constraint is software cheked now |
84
|
|
|
$sql = 'ALTER TABLE `' . $db->prefix($moduleDirName . '_publicrating') . '` DROP INDEX `photo_rate` ;'; |
85
|
|
|
$db->query($sql); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ($previousVersion < 102) { |
89
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
90
|
|
|
|
91
|
|
|
$sql = 'ALTER TABLE `' . $db->prefix($moduleDirName . '_publiccat') . '` ADD `cat_imgurl` VARCHAR(150) NOT NULL AFTER `cat_nb_photo` ;'; |
92
|
|
|
$db->query($sql); |
93
|
|
|
|
94
|
|
|
$sql = 'ALTER TABLE `' . $db->prefix($moduleDirName . '_publicphoto') . '` ADD `photo_title` VARCHAR(150) NOT NULL AFTER `photo_id` ;'; |
95
|
|
|
$db->query($sql); |
96
|
|
|
|
97
|
|
|
$sql = 'ALTER TABLE `' . $db->prefix($moduleDirName . '_publicphoto') . '` ADD `photo_weight` int(11) NOT NULL AFTER `photo_extra` ;'; |
98
|
|
|
$db->query($sql); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
if ($previousVersion < 104) { |
102
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
103
|
|
|
|
104
|
|
|
$sql = 'ALTER TABLE `' . $db->prefix($moduleDirName . '_publicphoto') . "` ADD `dohtml` BOOL NOT NULL DEFAULT '0';"; |
105
|
|
|
$db->query($sql); |
106
|
|
|
|
107
|
|
|
$sql = 'ALTER TABLE `' . $db->prefix($moduleDirName . '_publicphoto') . '` CHANGE `photo_desc` `photo_desc` TEXT;'; |
108
|
|
|
$db->query($sql); |
109
|
|
|
|
110
|
|
|
// Set display parmission for all XOOPS base Groups |
111
|
|
|
$sql = 'SELECT cat_id FROM `' . $db->prefix($moduleDirName . '_publiccat') . '`;'; |
112
|
|
|
$result = $db->query($sql); |
113
|
|
|
$module_id = $xoopsModule->getVar('mid'); |
|
|
|
|
114
|
|
|
/** @var XoopsGroupPermHandler $gpermHandler */ |
115
|
|
|
$gpermHandler = xoops_getHandler('groupperm'); |
116
|
|
|
while ($cat = $db->fetchArray($result)) { |
117
|
|
|
$gpermHandler->addRight('public_displayed', $cat['cat_id'], XOOPS_GROUP_ADMIN, $module_id); |
118
|
|
|
$gpermHandler->addRight('public_displayed', $cat['cat_id'], XOOPS_GROUP_USERS, $module_id); |
119
|
|
|
$gpermHandler->addRight('public_displayed', $cat['cat_id'], XOOPS_GROUP_ANONYMOUS, $module_id); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
if ($previousVersion < 106) { |
124
|
|
View Code Duplication |
if (!file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/index.html')) { |
|
|
|
|
125
|
|
|
$indexFile = XOOPS_ROOT_PATH . '/modules/extgallery/include/index.html'; |
126
|
|
|
copy($indexFile, XOOPS_ROOT_PATH . '/uploads/extgallery/index.html'); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
View Code Duplication |
if (!file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/index.html')) { |
|
|
|
|
130
|
|
|
$indexFile = XOOPS_ROOT_PATH . '/modules/extgallery/include/index.html'; |
131
|
|
|
copy($indexFile, XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/index.html'); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
if ($previousVersion < 107) { |
136
|
|
|
|
137
|
|
|
// Fix extension Bug if it's installed |
138
|
|
|
if (file_exists(XOOPS_ROOT_PATH . '/class/textsanitizer/gallery/gallery.php')) { |
139
|
|
|
$conf = include XOOPS_ROOT_PATH . '/class/textsanitizer/config.php'; |
140
|
|
|
$conf['extensions']['gallery'] = 1; |
141
|
|
|
file_put_contents(XOOPS_ROOT_PATH . '/class/textsanitizer/config.custom.php', "<?php\rreturn \$config = " . var_export($conf, true) . "\r?>"); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
View Code Duplication |
if ($previousVersion < 109) { |
|
|
|
|
146
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
147
|
|
|
|
148
|
|
|
$sql = 'ALTER TABLE `' . $db->prefix($moduleDirName . '_publiccat') . "` CHANGE `cat_weight` `cat_weight` INT( 11 ) NOT NULL DEFAULT '0' ;"; |
149
|
|
|
$db->query($sql); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
|
154
|
|
|
|
155
|
|
|
if ($previousVersion < 111) { |
156
|
|
|
// delete old HTML template files ============================ |
157
|
|
|
$templateDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/templates/'); |
158
|
|
View Code Duplication |
if (is_dir($templateDirectory)) { |
|
|
|
|
159
|
|
|
$templateList = array_diff(scandir($templateDirectory), array('..', '.')); |
160
|
|
|
foreach ($templateList as $k => $v) { |
161
|
|
|
$fileInfo = new SplFileInfo($templateDirectory . $v); |
162
|
|
|
if ($fileInfo->getExtension() === 'html' && $fileInfo->getFilename() !== 'index.html') { |
163
|
|
|
if (file_exists($templateDirectory . $v)) { |
164
|
|
|
unlink($templateDirectory . $v); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
// delete old block html template files ============================ |
170
|
|
|
$templateDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') |
171
|
|
|
. '/templates/blocks/'); |
172
|
|
View Code Duplication |
if (is_dir($templateDirectory)) { |
|
|
|
|
173
|
|
|
$templateList = array_diff(scandir($templateDirectory), array('..', '.')); |
174
|
|
|
foreach ($templateList as $k => $v) { |
175
|
|
|
$fileInfo = new SplFileInfo($templateDirectory . $v); |
176
|
|
|
if ($fileInfo->getExtension() === 'html' && $fileInfo->getFilename() !== 'index.html') { |
177
|
|
|
if (file_exists($templateDirectory . $v)) { |
178
|
|
|
unlink($templateDirectory . $v); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
// delete old admin html template files ============================ |
186
|
|
|
$templateDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') |
187
|
|
|
. '/templates/admin/'); |
188
|
|
View Code Duplication |
if (is_dir($templateDirectory)) { |
|
|
|
|
189
|
|
|
$templateList = array_diff(scandir($templateDirectory), array('..', '.')); |
190
|
|
|
foreach ($templateList as $k => $v) { |
191
|
|
|
$fileInfo = new SplFileInfo($templateDirectory . $v); |
192
|
|
|
if ($fileInfo->getExtension() === 'html' && $fileInfo->getFilename() !== 'index.html') { |
193
|
|
|
if (file_exists($templateDirectory . $v)) { |
194
|
|
|
unlink($templateDirectory . $v); |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
//delete old files: =================== |
201
|
|
|
// $oldFiles = array( |
202
|
|
|
// '/include/update_functions.php', |
203
|
|
|
// '/include/install_functions.php' |
204
|
|
|
// ); |
205
|
|
|
include_once __DIR__ . '/config.php'; |
206
|
|
|
if (count($oldFiles) > 0) { |
207
|
|
|
foreach (array_keys($oldFiles) as $file) { |
208
|
|
|
if (is_file($file)) { |
209
|
|
|
unlink($GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . $oldFiles[$file])); |
|
|
|
|
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
//delete .html entries from the tpl table |
215
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', |
216
|
|
|
'n') |
217
|
|
|
. "' AND `tpl_file` LIKE '%.html%'"; |
218
|
|
|
$xoopsDB->queryF($sql); |
219
|
|
|
|
220
|
|
|
// Load class XoopsFile ==================== |
221
|
|
|
xoops_load('XoopsFile'); |
222
|
|
|
|
223
|
|
|
//delete /images directory ============ |
224
|
|
|
$imagesDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/images/'); |
225
|
|
|
$folderHandler = XoopsFile::getHandler('folder', $imagesDirectory); |
226
|
|
|
$folderHandler->delete($imagesDirectory); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
$gpermHandler = xoops_getHandler('groupperm'); |
230
|
|
|
|
231
|
|
|
return $gpermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
232
|
|
|
} |
233
|
|
|
|
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.