Passed
Pull Request — master (#88)
by Michael
02:56
created

include/oninstall.php (2 issues)

Severity
1
<?php declare(strict_types=1);
2
3
/**
4
 * TDMDownload
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * @copyright   Gregory Mage (Aka Mage)
14
 * @license     GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
15
 * @author      Gregory Mage (Aka Mage)
16
 */
17
18
use XoopsModules\Tdmdownloads\Helper;
19
20
/**
21
 * Prepares system prior to attempting to install module
22
 * @param \XoopsModule $module {@link XoopsModule}
23
 *
24
 * @return bool true if ready to install, false if not
25
 */
26
function xoops_module_pre_install_tdmdownloads(\XoopsModule $module)
27
{
28
    require_once dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
29
30
//    require_once __DIR__ . '/common.php';
31
32
    /** @var \XoopsModules\Tdmdownloads\Utility $utility */
33
34
    $utility = new \XoopsModules\Tdmdownloads\Utility();
35
36
    $xoopsSuccess0 = $utility::checkVerXoops($module);
0 ignored issues
show
The assignment to $xoopsSuccess0 is dead and can be removed.
Loading history...
37
38
    $xoopsSuccess = $utility::checkVerXoops($module);
39
40
    $phpSuccess0 = $utility::checkVerPhp($module);
0 ignored issues
show
The assignment to $phpSuccess0 is dead and can be removed.
Loading history...
41
42
    $phpSuccess = $utility::checkVerPhp($module);
43
44
    if ($xoopsSuccess && $phpSuccess) {
45
        $mod_tables = &$module->getInfo('tables');
46
47
        foreach ($mod_tables as $table) {
48
            $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
49
        }
50
    }
51
52
    return $xoopsSuccess && $phpSuccess;
53
}
54
55
/**
56
 * @return bool
57
 */
58
function xoops_module_install_tdmdownloads()
59
{
60
    global $xoopsModule, $xoopsConfig, $xoopsDB;
61
62
    $moduleDirName = basename(dirname(__DIR__));
63
64
    $namemodule = $moduleDirName;
65
66
    if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/' . $xoopsConfig['language'] . '/admin.php')) {
67
        require_once XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/' . $xoopsConfig['language'] . '/admin.php';
68
    } else {
69
        require_once XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/english/admin.php';
70
    }
71
72
    $fieldHandler = Helper::getInstance()->getHandler('Field');
73
74
    $obj = $fieldHandler->create();
75
76
    $obj->setVar('title', _AM_TDMDOWNLOADS_FORMHOMEPAGE);
77
78
    $obj->setVar('img', 'homepage.png');
79
80
    $obj->setVar('weight', 1);
81
82
    $obj->setVar('search', 0);
83
84
    $obj->setVar('status', 1);
85
86
    $obj->setVar('status_def', 1);
87
88
    $fieldHandler->insert($obj);
89
90
    $obj = $fieldHandler->create();
91
92
    $obj->setVar('title', _AM_TDMDOWNLOADS_FORMVERSION);
93
94
    $obj->setVar('img', 'version.png');
95
96
    $obj->setVar('weight', 2);
97
98
    $obj->setVar('search', 0);
99
100
    $obj->setVar('status', 1);
101
102
    $obj->setVar('status_def', 1);
103
104
    $fieldHandler->insert($obj);
105
106
    $obj = $fieldHandler->create();
107
108
    $obj->setVar('title', _AM_TDMDOWNLOADS_FORMSIZE);
109
110
    $obj->setVar('img', 'size.png');
111
112
    $obj->setVar('weight', 3);
113
114
    $obj->setVar('search', 0);
115
116
    $obj->setVar('status', 1);
117
118
    $obj->setVar('status_def', 1);
119
120
    $fieldHandler->insert($obj);
121
122
    $obj = $fieldHandler->create();
123
124
    $obj->setVar('title', _AM_TDMDOWNLOADS_FORMPLATFORM);
125
126
    $obj->setVar('img', 'platform.png');
127
128
    $obj->setVar('weight', 4);
129
130
    $obj->setVar('search', 0);
131
132
    $obj->setVar('status', 1);
133
134
    $obj->setVar('status_def', 1);
135
136
    $fieldHandler->insert($obj);
137
138
    //File creation ".$namemodule."/
139
140
    $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '';
141
142
    if (!is_dir($dir)) {
143
        if (!mkdir($dir, 0777) && !is_dir($dir)) {
144
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
145
        }
146
    }
147
148
    chmod($dir, 0777);
149
150
    //File creation ".$namemodule."/images/
151
152
    $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images';
153
154
    if (!is_dir($dir)) {
155
        if (!mkdir($dir, 0777) && !is_dir($dir)) {
156
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
157
        }
158
    }
159
160
    chmod($dir, 0777);
161
162
    //File creation ".$namemodule."/images/cat
163
164
    $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats';
165
166
    if (!is_dir($dir)) {
167
        if (!mkdir($dir, 0777) && !is_dir($dir)) {
168
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
169
        }
170
    }
171
172
    chmod($dir, 0777);
173
174
    //File creation ".$namemodule."/images/shots
175
176
    $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots';
177
178
    if (!is_dir($dir)) {
179
        if (!mkdir($dir, 0777) && !is_dir($dir)) {
180
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
181
        }
182
    }
183
184
    chmod($dir, 0777);
185
186
    //File creation ".$namemodule."/images/field
187
188
    $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field';
189
190
    if (!is_dir($dir)) {
191
        if (!mkdir($dir, 0777) && !is_dir($dir)) {
192
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
193
        }
194
    }
195
196
    chmod($dir, 0777);
197
198
    //File creation ".$namemodule."/downloads
199
200
    $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/downloads';
201
202
    if (!is_dir($dir)) {
203
        if (!mkdir($dir, 0777) && !is_dir($dir)) {
204
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
205
        }
206
    }
207
208
    chmod($dir, 0777);
209
210
    //Copy index.html
211
212
    $indexFile = XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/include/index.html';
213
214
    copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/index.html');
215
216
    copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/index.html');
217
218
    copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats/index.html');
219
220
    copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots/index.html');
221
222
    copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/index.html');
223
224
    copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/downloads/index.html');
225
226
    //Copy blank.gif
227
228
    $blankFile = XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/blank.gif';
229
230
    copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats/blank.gif');
231
232
    copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots/blank.gif');
233
234
    copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/blank.gif');
235
236
    //Copy images for fields
237
238
    copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/homepage.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/homepage.png');
239
240
    copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/version.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/version.png');
241
242
    copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/size.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/size.png');
243
244
    copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/platform.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/platform.png');
245
246
    return true;
247
}
248