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
|
|
|
|
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.