|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* TDMDownload |
|
7
|
|
|
* |
|
8
|
|
|
* You may not change or alter any portion of this comment or credits |
|
9
|
|
|
* of supporting developers from this source code or any supporting source code |
|
10
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
11
|
|
|
* This program is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright Gregory Mage (Aka Mage) |
|
16
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
17
|
|
|
* @author Gregory Mage (Aka Mage) |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
use XoopsModules\Tdmdownloads\Helper; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Prepares system prior to attempting to install module |
|
24
|
|
|
* @param \XoopsModule $module {@link XoopsModule} |
|
25
|
|
|
* |
|
26
|
|
|
* @return bool true if ready to install, false if not |
|
27
|
|
|
*/ |
|
28
|
|
|
function xoops_module_pre_install_tdmdownloads(\XoopsModule $module) |
|
29
|
|
|
{ |
|
30
|
|
|
require_once dirname(__DIR__, 3) . '/mainfile.php'; |
|
31
|
|
|
// require_once __DIR__ . '/common.php'; |
|
32
|
|
|
$utility = new \XoopsModules\Tdmdownloads\Utility(); |
|
33
|
|
|
$xoopsSuccess0 = $utility::checkVerXoops($module); |
|
|
|
|
|
|
34
|
|
|
$xoopsSuccess = $utility::checkVerXoops($module); |
|
35
|
|
|
$phpSuccess0 = $utility::checkVerPhp($module); |
|
|
|
|
|
|
36
|
|
|
$phpSuccess = $utility::checkVerPhp($module); |
|
37
|
|
|
if ($xoopsSuccess && $phpSuccess) { |
|
38
|
|
|
$mod_tables = &$module->getInfo('tables'); |
|
39
|
|
|
foreach ($mod_tables as $table) { |
|
40
|
|
|
$GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';'); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
return $xoopsSuccess && $phpSuccess; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return bool |
|
48
|
|
|
*/ |
|
49
|
|
|
function xoops_module_install_tdmdownloads() |
|
50
|
|
|
{ |
|
51
|
|
|
global $xoopsModule, $xoopsConfig, $xoopsDB; |
|
52
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
|
53
|
|
|
$namemodule = $moduleDirName; |
|
54
|
|
|
if (is_file(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/' . $xoopsConfig['language'] . '/admin.php')) { |
|
55
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/' . $xoopsConfig['language'] . '/admin.php'; |
|
56
|
|
|
} else { |
|
57
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/english/admin.php'; |
|
58
|
|
|
} |
|
59
|
|
|
$fieldHandler = Helper::getInstance()->getHandler('Field'); |
|
60
|
|
|
$obj = $fieldHandler->create(); |
|
61
|
|
|
$obj->setVar('title', _AM_TDMDOWNLOADS_FORMHOMEPAGE); |
|
62
|
|
|
$obj->setVar('img', 'homepage.png'); |
|
63
|
|
|
$obj->setVar('weight', 1); |
|
64
|
|
|
$obj->setVar('search', 0); |
|
65
|
|
|
$obj->setVar('status', 1); |
|
66
|
|
|
$obj->setVar('status_def', 1); |
|
67
|
|
|
$fieldHandler->insert($obj); |
|
68
|
|
|
$obj = $fieldHandler->create(); |
|
69
|
|
|
$obj->setVar('title', _AM_TDMDOWNLOADS_FORMVERSION); |
|
70
|
|
|
$obj->setVar('img', 'version.png'); |
|
71
|
|
|
$obj->setVar('weight', 2); |
|
72
|
|
|
$obj->setVar('search', 0); |
|
73
|
|
|
$obj->setVar('status', 1); |
|
74
|
|
|
$obj->setVar('status_def', 1); |
|
75
|
|
|
$fieldHandler->insert($obj); |
|
76
|
|
|
$obj = $fieldHandler->create(); |
|
77
|
|
|
$obj->setVar('title', _AM_TDMDOWNLOADS_FORMSIZE); |
|
78
|
|
|
$obj->setVar('img', 'size.png'); |
|
79
|
|
|
$obj->setVar('weight', 3); |
|
80
|
|
|
$obj->setVar('search', 0); |
|
81
|
|
|
$obj->setVar('status', 1); |
|
82
|
|
|
$obj->setVar('status_def', 1); |
|
83
|
|
|
$fieldHandler->insert($obj); |
|
84
|
|
|
$obj = $fieldHandler->create(); |
|
85
|
|
|
$obj->setVar('title', _AM_TDMDOWNLOADS_FORMPLATFORM); |
|
86
|
|
|
$obj->setVar('img', 'platform.png'); |
|
87
|
|
|
$obj->setVar('weight', 4); |
|
88
|
|
|
$obj->setVar('search', 0); |
|
89
|
|
|
$obj->setVar('status', 1); |
|
90
|
|
|
$obj->setVar('status_def', 1); |
|
91
|
|
|
$fieldHandler->insert($obj); |
|
92
|
|
|
//File creation ".$namemodule."/ |
|
93
|
|
|
$dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . ''; |
|
94
|
|
|
if (!is_dir($dir)) { |
|
95
|
|
|
if (!mkdir($dir, 0777) && !is_dir($dir)) { |
|
96
|
|
|
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
chmod($dir, 0777); |
|
100
|
|
|
//File creation ".$namemodule."/images/ |
|
101
|
|
|
$dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images'; |
|
102
|
|
|
if (!is_dir($dir)) { |
|
103
|
|
|
if (!mkdir($dir, 0777) && !is_dir($dir)) { |
|
104
|
|
|
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
chmod($dir, 0777); |
|
108
|
|
|
//File creation ".$namemodule."/images/cat |
|
109
|
|
|
$dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats'; |
|
110
|
|
|
if (!is_dir($dir)) { |
|
111
|
|
|
if (!mkdir($dir, 0777) && !is_dir($dir)) { |
|
112
|
|
|
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
chmod($dir, 0777); |
|
116
|
|
|
//File creation ".$namemodule."/images/shots |
|
117
|
|
|
$dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots'; |
|
118
|
|
|
if (!is_dir($dir)) { |
|
119
|
|
|
if (!mkdir($dir, 0777) && !is_dir($dir)) { |
|
120
|
|
|
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
chmod($dir, 0777); |
|
124
|
|
|
//File creation ".$namemodule."/images/field |
|
125
|
|
|
$dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field'; |
|
126
|
|
|
if (!is_dir($dir)) { |
|
127
|
|
|
if (!mkdir($dir, 0777) && !is_dir($dir)) { |
|
128
|
|
|
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
chmod($dir, 0777); |
|
132
|
|
|
//File creation ".$namemodule."/downloads |
|
133
|
|
|
$dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/downloads'; |
|
134
|
|
|
if (!is_dir($dir)) { |
|
135
|
|
|
if (!mkdir($dir, 0777) && !is_dir($dir)) { |
|
136
|
|
|
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
chmod($dir, 0777); |
|
140
|
|
|
//Copy index.html |
|
141
|
|
|
$indexFile = XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/include/index.php'; |
|
142
|
|
|
copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/index.php'); |
|
143
|
|
|
copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/index.php'); |
|
144
|
|
|
copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats/index.php'); |
|
145
|
|
|
copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots/index.php'); |
|
146
|
|
|
copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/index.php'); |
|
147
|
|
|
copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/downloads/index.php'); |
|
148
|
|
|
//Copy blank.gif |
|
149
|
|
|
$blankFile = XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/blank.gif'; |
|
150
|
|
|
copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats/blank.gif'); |
|
151
|
|
|
copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots/blank.gif'); |
|
152
|
|
|
copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/blank.gif'); |
|
153
|
|
|
//Copy images for fields |
|
154
|
|
|
copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/homepage.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/homepage.png'); |
|
155
|
|
|
copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/version.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/version.png'); |
|
156
|
|
|
copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/size.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/size.png'); |
|
157
|
|
|
copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/platform.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/platform.png'); |
|
158
|
|
|
return true; |
|
159
|
|
|
} |
|
160
|
|
|
|