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
|
|
|
* XOOPS XoopsPartners module |
14
|
|
|
* |
15
|
|
|
* @package module\xoopspartners\include |
16
|
|
|
* @author Taiwen Jiang <[email protected]> |
17
|
|
|
* @author zyspec <[email protected]> |
18
|
|
|
* @author XOOPS Module Development Team |
19
|
|
|
* @copyright {@link https://xoops.org 2001-2016 XOOPS Project} |
20
|
|
|
* @license {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License} |
21
|
|
|
* @link https://xoops.org XOOPS |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @internal {Make sure you PROTECT THIS FILE} |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
if ((!defined('XOOPS_ROOT_PATH')) |
29
|
|
|
|| !isset($GLOBALS['xoopsUser']) |
30
|
|
|
|| !($GLOBALS['xoopsUser'] instanceof XoopsUser) |
|
|
|
|
31
|
|
|
|| !$GLOBALS['xoopsUser']->isAdmin() |
32
|
|
|
) { |
33
|
|
|
exit('Restricted access' . PHP_EOL); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* |
38
|
|
|
* Prepares system prior to attempting to install module |
39
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
|
|
|
|
40
|
|
|
* |
41
|
|
|
* @return bool true if ready to install, false if not |
42
|
|
|
*/ |
43
|
|
View Code Duplication |
function xoops_module_pre_install_xoopspartners(XoopsModule $xoopsModule) |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
if (!class_exists('XoopspartnersUtilities')) { |
46
|
|
|
xoops_load('utilities', 'xoopspartners'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
//check for minimum XOOPS version |
50
|
|
|
if (!XoopspartnersUtilities::checkXoopsVer($xoopsModule)) { |
51
|
|
|
return false; |
52
|
|
|
} |
53
|
|
|
// check for minimum PHP version |
54
|
|
|
if (!XoopspartnersUtilities::checkPHPVer($xoopsModule)) { |
55
|
|
|
return false; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return true; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* |
63
|
|
|
* Performs tasks required during installation of the module |
64
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
65
|
|
|
* |
66
|
|
|
* @return bool true if installation successful, false if not |
67
|
|
|
*/ |
68
|
|
|
function xoops_module_install_xoopspartners(XoopsModule $module) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
|
71
|
|
|
$indexFile = $GLOBALS['xoops']->path('/modules/' . $module->dirname() . '/include/index.html'); |
72
|
|
|
|
73
|
|
|
//Create the "uploads" directory for the module |
74
|
|
|
$module_uploads = $GLOBALS['xoops']->path('/uploads/' . $module->dirname()); |
75
|
|
|
if (!is_dir($module_uploads)) { |
76
|
|
|
mkdir($module_uploads, 0777); |
77
|
|
|
} |
78
|
|
|
chmod($module_uploads, 0777); |
79
|
|
|
//now copy the index file to help prevent 'browsing' the directory |
80
|
|
|
copy($indexFile, $GLOBALS['xoops']->path('/uploads/' . $module->dirname() . '/index.html')); |
81
|
|
|
|
82
|
|
|
return true; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* |
87
|
|
|
* Prepares system prior to attempting to update module |
88
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
89
|
|
|
* |
90
|
|
|
* @return bool true if successfully ready to update module, false if not |
91
|
|
|
*/ |
92
|
|
View Code Duplication |
function xoops_module_pre_update_xoopspartners(XoopsModule $module) |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
if (!class_exists('XoopspartnersUtilities')) { |
95
|
|
|
xoops_load('utilities', 'xoopspartners'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
//check for minimum XOOPS version |
99
|
|
|
if (!XoopspartnersUtilities::checkXoopsVer($xoopsModule)) { |
100
|
|
|
return false; |
101
|
|
|
} |
102
|
|
|
// check for minimum PHP version |
103
|
|
|
if (!XoopspartnersUtilities::checkPHPVer($xoopsModule)) { |
104
|
|
|
return false; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return true; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* |
112
|
|
|
* Functions to upgrade from previous version of the module |
113
|
|
|
* |
114
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
115
|
|
|
* @param int $curr_version version number of module currently installed |
|
|
|
|
116
|
|
|
* |
117
|
|
|
* @return bool true if successfully updated module, false if not |
118
|
|
|
*/ |
119
|
|
|
function xoops_module_update_xoopspartners(XoopsModule $module, $curr_version = null) |
|
|
|
|
120
|
|
|
{ |
121
|
|
|
return true; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* |
126
|
|
|
* Function to perform before module uninstall |
127
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
128
|
|
|
* |
129
|
|
|
* @return bool true if successfully executed, false if not |
130
|
|
|
*/ |
131
|
|
|
function xoops_module_pre_uninstall_xoopspartners(XoopsModule $module) |
|
|
|
|
132
|
|
|
{ |
133
|
|
|
return true; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* |
138
|
|
|
* Function to complete upon module uninstall |
139
|
|
|
* @param XoopsModule $module {@link XoopsModule} |
140
|
|
|
* |
141
|
|
|
* @return bool true if successfully executed uninstall of module, false if not |
142
|
|
|
*/ |
143
|
|
|
function xoops_module_uninstall_xoopspartners(XoopsModule $module) |
|
|
|
|
144
|
|
|
{ |
145
|
|
|
return true; |
146
|
|
|
} |
147
|
|
|
|
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.