|
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
|
|
|
* GBookUtilities Class |
|
13
|
|
|
* |
|
14
|
|
|
* @copyright XOOPS Project (http://xoops.org) |
|
15
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
|
16
|
|
|
* @author XOOPS Development Team |
|
17
|
|
|
* @package GBook |
|
18
|
|
|
* @since 1.03 |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
//namespace GBook; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class GBookUtilities |
|
26
|
|
|
*/ |
|
27
|
|
|
class GBookUtilities |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $folder The full path of the directory to check |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
public static function createFolder($folder) |
|
37
|
|
|
{ |
|
38
|
|
|
try { |
|
39
|
|
|
if (!@mkdir($folder) && !is_dir($folder)) { |
|
40
|
|
|
throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
41
|
|
|
} else { |
|
42
|
|
|
file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
catch (Exception $e) { |
|
46
|
|
|
echo 'Caught exception: ', $e->getMessage(), "\n", '<br/>'; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param $file |
|
52
|
|
|
* @param $folder |
|
53
|
|
|
* @return bool |
|
54
|
|
|
*/ |
|
55
|
|
|
public static function copyFile($file, $folder) |
|
56
|
|
|
{ |
|
57
|
|
|
return copy($file, $folder); |
|
58
|
|
|
// try { |
|
59
|
|
|
// if (!is_dir($folder)) { |
|
|
|
|
|
|
60
|
|
|
// throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder)); |
|
|
|
|
|
|
61
|
|
|
// } else { |
|
|
|
|
|
|
62
|
|
|
// return copy($file, $folder); |
|
|
|
|
|
|
63
|
|
|
// } |
|
64
|
|
|
// } catch (Exception $e) { |
|
|
|
|
|
|
65
|
|
|
// echo 'Caught exception: ', $e->getMessage(), "\n", "<br/>"; |
|
|
|
|
|
|
66
|
|
|
// } |
|
67
|
|
|
// return false; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param $src |
|
72
|
|
|
* @param $dst |
|
73
|
|
|
*/ |
|
74
|
|
|
public static function recurseCopy($src, $dst) |
|
75
|
|
|
{ |
|
76
|
|
|
$dir = opendir($src); |
|
77
|
|
|
// @mkdir($dst); |
|
78
|
|
|
while (false !== ($file = readdir($dir))) { |
|
79
|
|
|
if (($file !== '.') && ($file !== '..')) { |
|
80
|
|
|
if (is_dir($src . '/' . $file)) { |
|
81
|
|
|
self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
82
|
|
|
} else { |
|
83
|
|
|
copy($src . '/' . $file, $dst . '/' . $file); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
closedir($dir); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param $name |
|
92
|
|
|
* @param $value |
|
93
|
|
|
* @return XoopsFormDhtmlTextArea|XoopsFormEditor |
|
94
|
|
|
*/ |
|
95
|
|
|
public static function getEditor($name, $value) |
|
96
|
|
|
{ |
|
97
|
|
|
global $xoopsUser, $xoopsModule, $xoopsModuleConfig; |
|
|
|
|
|
|
98
|
|
|
$options = array(); |
|
99
|
|
|
$isAdmin = $xoopsUser->isAdmin($xoopsModule->getVar('mid')); |
|
100
|
|
|
|
|
101
|
|
|
if (class_exists('XoopsFormEditor')) { |
|
102
|
|
|
$options['name'] = $name; |
|
103
|
|
|
$options['value'] = $value; |
|
104
|
|
|
$options['rows'] = 5; |
|
105
|
|
|
$options['cols'] = '100%'; |
|
106
|
|
|
$options['width'] = '100%'; |
|
107
|
|
|
$options['height'] = '200px'; |
|
108
|
|
|
if ($isAdmin) { |
|
109
|
|
|
$descEditor = new XoopsFormEditor(ucfirst($name), $xoopsModuleConfig['editorAdmin'], $options, $nohtml = false, $onfailure = 'textarea'); |
|
110
|
|
|
} else { |
|
111
|
|
|
$descEditor = new XoopsFormEditor(ucfirst($name), $xoopsModuleConfig['editorUser'], $options, $nohtml = false, $onfailure = 'textarea'); |
|
112
|
|
|
} |
|
113
|
|
|
} else { |
|
114
|
|
|
$descEditor = new XoopsFormDhtmlTextArea(ucfirst($name), $name, $value, '100%', '100%'); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
// $form->addElement($descEditor); |
|
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
return $descEditor; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param $nameTmp |
|
124
|
|
|
* @param $emailTmp |
|
125
|
|
|
* @param $urlTmp |
|
126
|
|
|
* @param $messageTmp |
|
127
|
|
|
* @return XoopsThemeForm |
|
128
|
|
|
*/ |
|
129
|
|
|
public static function getSignForm($nameTmp, $emailTmp, $urlTmp, $messageTmp) |
|
130
|
|
|
{ |
|
131
|
|
|
$name = new XoopsFormText(_MD_GBOOK_NAME, 'Name', 43, 100, $nameTmp); |
|
132
|
|
|
$email = new XoopsFormText(_MD_GBOOK_EMAIL, 'Email', 43, 100, $emailTmp); |
|
133
|
|
|
$url = new XoopsFormText(_MD_GBOOK_URL, 'URL', 43, 100, $urlTmp); |
|
134
|
|
|
$message = new XoopsFormTextArea(_MD_GBOOK_MESSAGE, 'Message', $messageTmp); |
|
135
|
|
|
$submit = new XoopsFormButton('', 'submit', _MD_GBOOK_SUBMIT, 'submit'); |
|
136
|
|
|
$gbookform = new XoopsThemeForm(_MD_GBOOK_SIGN, 'gbookform', 'sign.php'); |
|
137
|
|
|
|
|
138
|
|
|
$gbookform->addElement($name, true); |
|
139
|
|
|
$gbookform->addElement($email); |
|
140
|
|
|
$gbookform->addElement($url); |
|
141
|
|
|
$gbookform->addElement($message, true); |
|
142
|
|
|
$gbookform->addElement(new XoopsFormCaptcha(), true); |
|
143
|
|
|
$gbookform->addElement($submit); |
|
144
|
|
|
|
|
145
|
|
|
return $gbookform; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @return string |
|
150
|
|
|
*/ |
|
151
|
|
|
public static function gbookIP() |
|
152
|
|
|
{ |
|
153
|
|
|
$ip = 'UNKNOWN'; |
|
154
|
|
|
if (getenv('HTTP_CLIENT_IP')) { |
|
155
|
|
|
$ip = getenv('HTTP_CLIENT_IP'); |
|
156
|
|
|
} else { |
|
157
|
|
|
if (getenv('HTTP_X_FORWARDED_FOR')) { |
|
158
|
|
|
$ip = getenv('HTTP_X_FORWARDED_FOR'); |
|
159
|
|
|
} else { |
|
160
|
|
|
if (getenv('REMOTE_ADDR')) { |
|
161
|
|
|
$ip = getenv('REMOTE_ADDR'); |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
return $ip; |
|
167
|
|
|
} |
|
168
|
|
|
/** |
|
169
|
|
|
* |
|
170
|
|
|
* Verifies XOOPS version meets minimum requirements for this module |
|
171
|
|
|
* @static |
|
172
|
|
|
* @param XoopsModule $module |
|
173
|
|
|
* |
|
174
|
|
|
* @return bool true if meets requirements, false if not |
|
175
|
|
|
*/ |
|
176
|
|
|
public static function checkXoopsVer(XoopsModule $module) |
|
177
|
|
|
{ |
|
178
|
|
|
xoops_loadLanguage('admin', $module->dirname()); |
|
179
|
|
|
//check for minimum XOOPS version |
|
180
|
|
|
$currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
|
181
|
|
|
$currArray = explode('.', $currentVer); |
|
182
|
|
|
$requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
|
183
|
|
|
$reqArray = explode('.', $requiredVer); |
|
184
|
|
|
$success = true; |
|
185
|
|
|
foreach ($reqArray as $k => $v) { |
|
186
|
|
|
if (isset($currArray[$k])) { |
|
187
|
|
|
if ($currArray[$k] > $v) { |
|
188
|
|
|
break; |
|
189
|
|
|
} elseif ($currArray[$k] == $v) { |
|
190
|
|
|
continue; |
|
191
|
|
|
} else { |
|
192
|
|
|
$success = false; |
|
193
|
|
|
break; |
|
194
|
|
|
} |
|
195
|
|
|
} else { |
|
196
|
|
|
if ((int)$v > 0) { // handles things like x.x.x.0_RC2 |
|
197
|
|
|
$success = false; |
|
198
|
|
|
break; |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
if (!$success) { |
|
204
|
|
|
$module->setErrors(sprintf(_AM_GBOOK_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
return $success; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* |
|
212
|
|
|
* Verifies PHP version meets minimum requirements for this module |
|
213
|
|
|
* @static |
|
214
|
|
|
* @param XoopsModule $module |
|
215
|
|
|
* |
|
216
|
|
|
* @return bool true if meets requirements, false if not |
|
217
|
|
|
*/ |
|
218
|
|
|
public static function checkPhpVer(XoopsModule $module) |
|
219
|
|
|
{ |
|
220
|
|
|
xoops_loadLanguage('admin', $module->dirname()); |
|
221
|
|
|
// check for minimum PHP version |
|
222
|
|
|
$success = true; |
|
223
|
|
|
$verNum = phpversion(); |
|
224
|
|
|
$reqVer =& $module->getInfo('min_php'); |
|
225
|
|
|
if (false !== $reqVer && '' !== $reqVer) { |
|
226
|
|
|
if (version_compare($verNum, $reqVer, '<')) { |
|
227
|
|
|
$module->setErrors(sprintf(_AM_GBOOK_ERROR_BAD_PHP, $reqVer, $verNum)); |
|
228
|
|
|
$success = false; |
|
229
|
|
|
} |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
return $success; |
|
233
|
|
|
} |
|
234
|
|
|
} |
|
235
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.