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
|
|
|
* @since |
17
|
|
|
* @author XOOPS Development Team |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
use XoopsModules\Statistics; |
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
|
|
|
* @param string $tablename |
29
|
|
|
* |
30
|
|
|
* @return bool |
31
|
|
|
*/ |
32
|
|
|
function tableExists($tablename) |
33
|
|
|
{ |
34
|
|
|
$result = $GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'"); |
35
|
|
|
|
36
|
|
|
return ($GLOBALS['xoopsDB']->getRowsNum($result) > 0) ? true : false; |
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_statistics(\XoopsModule $module) |
46
|
|
|
{ |
47
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
|
|
|
|
48
|
|
|
/** @var Statistics\Helper $helper */ |
49
|
|
|
/** @var Statistics\Utility $utility */ |
50
|
|
|
$helper = Statistics\Helper::getInstance(); |
|
|
|
|
51
|
|
|
$utility = new Statistics\Utility(); |
52
|
|
|
|
53
|
|
|
$xoopsSuccess = $utility::checkVerXoops($module); |
54
|
|
|
$phpSuccess = $utility::checkVerPhp($module); |
55
|
|
|
|
56
|
|
|
return $xoopsSuccess && $phpSuccess; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Performs tasks required during update of the module |
61
|
|
|
* @param \XoopsModule $module {@link XoopsModule} |
62
|
|
|
* @param null $previousVersion |
|
|
|
|
63
|
|
|
* |
64
|
|
|
* @return bool true if update successful, false if not |
65
|
|
|
*/ |
66
|
|
|
function xoops_module_update_statistics(\XoopsModule $module, $previousVersion = null) |
67
|
|
|
{ |
68
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
69
|
|
|
$moduleDirNameUpper = mb_strtoupper($moduleDirName); |
|
|
|
|
70
|
|
|
|
71
|
|
|
/** @var Statistics\Helper $helper */ /** @var Statistics\Utility $utility */ |
72
|
|
|
/** @var Statistics\Common\Configurator $configurator */ |
73
|
|
|
$helper = Statistics\Helper::getInstance(); |
|
|
|
|
74
|
|
|
$utility = new Statistics\Utility(); |
75
|
|
|
$configurator = new Statistics\Common\Configurator(); |
76
|
|
|
|
77
|
|
|
if ($previousVersion < 240) { |
78
|
|
|
//delete old HTML templates |
79
|
|
|
if (count($configurator->templateFolders) > 0) { |
80
|
|
|
foreach ($configurator->templateFolders as $folder) { |
81
|
|
|
$templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder); |
82
|
|
|
if (is_dir($templateFolder)) { |
83
|
|
|
$templateList = array_diff(scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']); |
|
|
|
|
84
|
|
|
foreach ($templateList as $k => $v) { |
85
|
|
|
$fileInfo = new \SplFileInfo($templateFolder . $v); |
86
|
|
|
if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
87
|
|
|
if (is_file($templateFolder . $v)) { |
88
|
|
|
unlink($templateFolder . $v); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// --- DELETE OLD FILES --------------- |
97
|
|
|
if (count($configurator->oldFiles) > 0) { |
98
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
99
|
|
|
foreach (array_keys($configurator->oldFiles) as $i) { |
100
|
|
|
$tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]); |
101
|
|
|
if (is_file($tempFile)) { |
102
|
|
|
unlink($tempFile); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
// --- DELETE OLD FOLDERS --------------- |
108
|
|
|
xoops_load('XoopsFile'); |
109
|
|
|
if (count($configurator->oldFolders) > 0) { |
110
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
111
|
|
|
foreach (array_keys($configurator->oldFolders) as $i) { |
112
|
|
|
$tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]); |
113
|
|
|
/* @var XoopsObjectHandler $folderHandler */ |
114
|
|
|
$folderHandler = XoopsFile::getHandler('folder', $tempFolder); |
115
|
|
|
$folderHandler->delete($tempFolder); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
// --- CREATE FOLDERS --------------- |
120
|
|
|
if (count($configurator->uploadFolders) > 0) { |
121
|
|
|
// foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
122
|
|
|
foreach (array_keys($configurator->uploadFolders) as $i) { |
123
|
|
|
$utility::createFolder($configurator->uploadFolders[$i]); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
// --- COPY blank.png FILES --------------- |
128
|
|
|
if (count($configurator->copyBlankFiles) > 0) { |
129
|
|
|
$file = dirname(__DIR__) . '/assets/images/blank.png'; |
130
|
|
|
foreach (array_keys($configurator->copyBlankFiles) as $i) { |
131
|
|
|
$dest = $configurator->copyBlankFiles[$i] . '/blank.png'; |
132
|
|
|
$utility::copyFile($file, $dest); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
//delete .html entries from the tpl table |
137
|
|
|
$sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . '\' AND `tpl_file` LIKE \'%.html%\''; |
138
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
139
|
|
|
|
140
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
141
|
|
|
$grouppermHandler = xoops_getHandler('groupperm'); |
142
|
|
|
|
143
|
|
|
return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
return true; |
147
|
|
|
} |
148
|
|
|
|