|
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 (https://xoops.org) |
|
14
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
15
|
|
|
* @package |
|
16
|
|
|
* @author XOOPS Development Team |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
use XoopsModules\Extgallery; |
|
20
|
|
|
use XoopsModules\Extgallery\Common\Migrate; |
|
21
|
|
|
|
|
22
|
|
|
if ((!defined('XOOPS_ROOT_PATH')) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser) |
|
23
|
|
|
|| !$GLOBALS['xoopsUser']->isAdmin()) { |
|
24
|
|
|
exit('Restricted access' . PHP_EOL); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Prepares system prior to attempting to install module |
|
31
|
|
|
* @param \XoopsModule $module {@link XoopsModule} |
|
32
|
|
|
* |
|
33
|
|
|
* @return bool true if ready to install, false if not |
|
34
|
|
|
*/ |
|
35
|
|
|
function xoops_module_pre_update_extgallery(\XoopsModule $module) |
|
36
|
|
|
{ |
|
37
|
|
|
/** @var Extgallery\Utility $utility */ |
|
38
|
|
|
$utility = new Extgallery\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
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param \XoopsModule $module |
|
56
|
|
|
* @param null $previousVersion |
|
|
|
|
|
|
57
|
|
|
* @return bool |
|
58
|
|
|
*/ |
|
59
|
|
|
function xoops_module_update_extgallery(\XoopsModule $module, $previousVersion = null) |
|
60
|
|
|
{ |
|
61
|
|
|
global $xoopsDB; |
|
62
|
|
|
|
|
63
|
|
|
$moduleDirName = \basename(\dirname(__DIR__)); |
|
64
|
|
|
$moduleDirNameUpper = mb_strtoupper($moduleDirName); |
|
65
|
|
|
|
|
66
|
|
|
/** @var Extgallery\Helper $helper */ /** @var Extgallery\Utility $utility */ |
|
67
|
|
|
/** @var Extgallery\Common\Configurator $configurator */ |
|
68
|
|
|
$helper = Extgallery\Helper::getInstance(); |
|
69
|
|
|
$utility = new Extgallery\Utility(); |
|
70
|
|
|
$configurator = new Extgallery\Common\Configurator(); |
|
71
|
|
|
|
|
72
|
|
|
$migrator = new Migrate($configurator); |
|
73
|
|
|
$migrator->synchronizeSchema(); |
|
74
|
|
|
|
|
75
|
|
|
$catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
|
76
|
|
|
$catHandler->rebuild(); |
|
77
|
|
|
|
|
78
|
|
|
if ($previousVersion < 101) { |
|
79
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
80
|
|
|
// Remove the UNIQUE key on the rating table. This constraint is software cheked now |
|
81
|
|
|
$sql = 'ALTER TABLE `' . $db->prefix($moduleDirName . '_publicrating') . '` DROP INDEX `photo_rate` ;'; |
|
82
|
|
|
$db->query($sql); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if ($previousVersion < 102) { |
|
86
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
87
|
|
|
|
|
88
|
|
|
$sql = 'ALTER TABLE `' . $db->prefix($moduleDirName . '_publiccat') . '` ADD `cat_imgurl` VARCHAR(150) NOT NULL AFTER `cat_nb_photo` ;'; |
|
89
|
|
|
$db->query($sql); |
|
90
|
|
|
|
|
91
|
|
|
$sql = 'ALTER TABLE `' . $db->prefix($moduleDirName . '_publicphoto') . '` ADD `photo_title` VARCHAR(150) NOT NULL AFTER `photo_id` ;'; |
|
92
|
|
|
$db->query($sql); |
|
93
|
|
|
|
|
94
|
|
|
$sql = 'ALTER TABLE `' . $db->prefix($moduleDirName . '_publicphoto') . '` ADD `photo_weight` INT(11) NOT NULL AFTER `photo_extra` ;'; |
|
95
|
|
|
$db->query($sql); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
if ($previousVersion < 104) { |
|
99
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
100
|
|
|
|
|
101
|
|
|
$sql = 'ALTER TABLE `' . $db->prefix($moduleDirName . '_publicphoto') . "` ADD `dohtml` BOOL NOT NULL DEFAULT '0';"; |
|
102
|
|
|
$db->query($sql); |
|
103
|
|
|
|
|
104
|
|
|
$sql = 'ALTER TABLE `' . $db->prefix($moduleDirName . '_publicphoto') . '` CHANGE `photo_desc` `photo_desc` TEXT;'; |
|
105
|
|
|
$db->query($sql); |
|
106
|
|
|
|
|
107
|
|
|
// Set display parmission for all XOOPS base Groups |
|
108
|
|
|
$sql = 'SELECT cat_id FROM `' . $db->prefix($moduleDirName . '_publiccat') . '`;'; |
|
109
|
|
|
$result = $db->query($sql); |
|
110
|
|
|
$moduleId = $module->getVar('mid'); |
|
111
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
|
112
|
|
|
$grouppermHandler = xoops_getHandler('groupperm'); |
|
113
|
|
|
while (false !== ($cat = $db->fetchArray($result))) { |
|
114
|
|
|
$grouppermHandler->addRight('public_displayed', $cat['cat_id'], XOOPS_GROUP_ADMIN, $moduleId); |
|
|
|
|
|
|
115
|
|
|
$grouppermHandler->addRight('public_displayed', $cat['cat_id'], XOOPS_GROUP_USERS, $moduleId); |
|
116
|
|
|
$grouppermHandler->addRight('public_displayed', $cat['cat_id'], XOOPS_GROUP_ANONYMOUS, $moduleId); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
if ($previousVersion < 106) { |
|
121
|
|
|
if (!is_file(XOOPS_ROOT_PATH . '/uploads/extgallery/index.html')) { |
|
122
|
|
|
$indexFile = XOOPS_ROOT_PATH . '/modules/extgallery/include/index.html'; |
|
123
|
|
|
copy($indexFile, XOOPS_ROOT_PATH . '/uploads/extgallery/index.html'); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
if (!is_file(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/index.html')) { |
|
127
|
|
|
$indexFile = XOOPS_ROOT_PATH . '/modules/extgallery/include/index.html'; |
|
128
|
|
|
copy($indexFile, XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/index.html'); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
if ($previousVersion < 107) { |
|
133
|
|
|
// Fix extension Bug if it's installed |
|
134
|
|
|
if (file_exists(XOOPS_ROOT_PATH . '/class/textsanitizer/gallery/gallery.php')) { |
|
135
|
|
|
$conf = require XOOPS_ROOT_PATH . '/class/textsanitizer/config.php'; |
|
136
|
|
|
$conf['extensions']['gallery'] = 1; |
|
137
|
|
|
file_put_contents(XOOPS_ROOT_PATH . '/class/textsanitizer/config.custom.php', "<?php\rreturn \$config = " . var_export($conf, true) . "\r?>", LOCK_EX); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
if ($previousVersion < 109) { |
|
142
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
143
|
|
|
|
|
144
|
|
|
$sql = 'ALTER TABLE `' . $db->prefix($moduleDirName . '_publiccat') . "` CHANGE `cat_weight` `cat_weight` INT( 11 ) NOT NULL DEFAULT '0' ;"; |
|
145
|
|
|
$db->query($sql); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
if ($previousVersion < 114) { |
|
149
|
|
|
// delete old HTML template files ============================ |
|
150
|
|
|
$templateDirectory = $GLOBALS['xoops']->path('modules/' . $moduleDirName . '/templates/'); |
|
151
|
|
|
if (is_dir($templateDirectory)) { |
|
152
|
|
|
$templateList = array_diff(scandir($templateDirectory, SCANDIR_SORT_NONE), ['..', '.']); |
|
153
|
|
|
foreach ($templateList as $k => $v) { |
|
154
|
|
|
$fileInfo = new \SplFileInfo($templateDirectory . $v); |
|
155
|
|
|
if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
|
156
|
|
|
if (is_file($templateDirectory . $v)) { |
|
157
|
|
|
unlink($templateDirectory . $v); |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
// delete old block html template files ============================ |
|
163
|
|
|
$templateDirectory = $GLOBALS['xoops']->path('modules/' . $moduleDirName . '/templates/blocks/'); |
|
164
|
|
|
if (is_dir($templateDirectory)) { |
|
165
|
|
|
$templateList = array_diff(scandir($templateDirectory, SCANDIR_SORT_NONE), ['..', '.']); |
|
166
|
|
|
foreach ($templateList as $k => $v) { |
|
167
|
|
|
$fileInfo = new \SplFileInfo($templateDirectory . $v); |
|
168
|
|
|
if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
|
169
|
|
|
if (is_file($templateDirectory . $v)) { |
|
170
|
|
|
unlink($templateDirectory . $v); |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
// delete old admin html template files ============================ |
|
177
|
|
|
$templateDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/templates/admin/'); |
|
178
|
|
|
if (is_dir($templateDirectory)) { |
|
179
|
|
|
$templateList = array_diff(scandir($templateDirectory, SCANDIR_SORT_NONE), ['..', '.']); |
|
180
|
|
|
foreach ($templateList as $k => $v) { |
|
181
|
|
|
$fileInfo = new \SplFileInfo($templateDirectory . $v); |
|
182
|
|
|
if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
|
183
|
|
|
if (is_file($templateDirectory . $v)) { |
|
184
|
|
|
unlink($templateDirectory . $v); |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
// $configurator = require_once __DIR__ . '/config.php'; |
|
191
|
|
|
/** @var Extgallery\Utility $utility */ |
|
192
|
|
|
$utility = new Extgallery\Utility(); |
|
193
|
|
|
|
|
194
|
|
|
// --- COPY blank.png FILES --------------- |
|
195
|
|
|
if (count($configurator->copyBlankFiles) > 0) { |
|
196
|
|
|
$file = \dirname(__DIR__) . '/assets/images/blank.png'; |
|
197
|
|
|
foreach (array_keys($configurator->copyFiles) as $i) { |
|
198
|
|
|
$dest = $configurator->copyFiles[$i] . '/blank.png'; |
|
|
|
|
|
|
199
|
|
|
$utility::copyFile($file, $dest); |
|
200
|
|
|
} |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
// --- DELETE OLD FILES --------------- |
|
204
|
|
|
if (count($configurator->oldFiles) > 0) { |
|
205
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
|
206
|
|
|
foreach (array_keys($configurator->oldFiles) as $i) { |
|
207
|
|
|
$tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]); |
|
208
|
|
|
if (is_file($tempFile)) { |
|
209
|
|
|
unlink($tempFile); |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
// --- CREATE UPLOAD FOLDERS --------------- |
|
215
|
|
|
if (count($configurator->uploadFolders) > 0) { |
|
216
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
|
217
|
|
|
foreach (array_keys($configurator->uploadFolders) as $i) { |
|
218
|
|
|
$utility::createFolder($configurator->uploadFolders[$i]); |
|
219
|
|
|
} |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
// --- COPY blank.png FILES --------------- |
|
223
|
|
|
if (count($configurator->copyBlankFiles) > 0) { |
|
224
|
|
|
$file = \dirname(__DIR__) . '/assets/images/blank.png'; |
|
225
|
|
|
foreach (array_keys($configurator->copyBlankFiles) as $i) { |
|
226
|
|
|
$dest = $configurator->copyBlankFiles[$i] . '/blank.png'; |
|
227
|
|
|
$utility::copyFile($file, $dest); |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
//--------------------- |
|
232
|
|
|
|
|
233
|
|
|
//delete .html entries from the tpl table |
|
234
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . '\' AND `tpl_file` LIKE \'%.html%\''; |
|
235
|
|
|
$xoopsDB->queryF($sql); |
|
236
|
|
|
|
|
237
|
|
|
// Load class XoopsFile ==================== |
|
238
|
|
|
xoops_load('XoopsFile'); |
|
239
|
|
|
|
|
240
|
|
|
//delete /images directory ============ |
|
241
|
|
|
$imagesDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/images/'); |
|
242
|
|
|
$folderHandler = XoopsFile::getHandler('folder', $imagesDirectory); |
|
243
|
|
|
$folderHandler->delete($imagesDirectory); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
|
247
|
|
|
$grouppermHandler = xoops_getHandler('groupperm'); |
|
248
|
|
|
|
|
249
|
|
|
return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
|
250
|
|
|
} |
|
251
|
|
|
|