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
|
|
|
//include_once dirname(__DIR__) . '/include/common.php'; |
|
|
|
|
23
|
|
|
|
24
|
|
|
//namespace GBook; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class GBookUtilities |
28
|
|
|
*/ |
29
|
|
|
class GBookUtilities |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Function responsible for checking if a directory exists, we can also write in and create an index.html file |
33
|
|
|
* |
34
|
|
|
* @param string $folder The full path of the directory to check |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
public static function createFolder($folder) |
39
|
|
|
{ |
40
|
|
|
try { |
41
|
|
|
if (!@mkdir($folder) && !is_dir($folder)) { |
42
|
|
|
throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
43
|
|
|
} else { |
44
|
|
|
file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
45
|
|
|
} |
46
|
|
|
} catch (Exception $e) { |
47
|
|
|
echo 'Caught exception: ', $e->getMessage(), "\n", '<br/>'; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param $file |
53
|
|
|
* @param $folder |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
|
|
public static function copyFile($file, $folder) |
57
|
|
|
{ |
58
|
|
|
return copy($file, $folder); |
59
|
|
|
// try { |
60
|
|
|
// if (!is_dir($folder)) { |
|
|
|
|
61
|
|
|
// throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder)); |
|
|
|
|
62
|
|
|
// } else { |
|
|
|
|
63
|
|
|
// return copy($file, $folder); |
|
|
|
|
64
|
|
|
// } |
65
|
|
|
// } catch (Exception $e) { |
|
|
|
|
66
|
|
|
// echo 'Caught exception: ', $e->getMessage(), "\n", "<br/>"; |
|
|
|
|
67
|
|
|
// } |
68
|
|
|
// return false; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param $src |
73
|
|
|
* @param $dst |
74
|
|
|
*/ |
75
|
|
|
public static function recurseCopy($src, $dst) |
76
|
|
|
{ |
77
|
|
|
$dir = opendir($src); |
78
|
|
|
// @mkdir($dst); |
79
|
|
|
while (false !== ($file = readdir($dir))) { |
80
|
|
|
if (($file !== '.') && ($file !== '..')) { |
81
|
|
|
if (is_dir($src . '/' . $file)) { |
82
|
|
|
self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
83
|
|
|
} else { |
84
|
|
|
copy($src . '/' . $file, $dst . '/' . $file); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
closedir($dir); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param $name |
93
|
|
|
* @param $value |
94
|
|
|
* @return XoopsFormDhtmlTextArea|XoopsFormEditor |
95
|
|
|
*/ |
96
|
|
|
public static function getEditor($name, $value) |
97
|
|
|
{ |
98
|
|
|
global $xoopsUser, $xoopsModule, $xoopsModuleConfig; |
|
|
|
|
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
|
|
|
// $form->addElement($descEditor); |
|
|
|
|
117
|
|
|
|
118
|
|
|
return $descEditor; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param $nameTmp |
123
|
|
|
* @param $emailTmp |
124
|
|
|
* @param $urlTmp |
125
|
|
|
* @param $messageTmp |
126
|
|
|
* @return XoopsThemeForm |
127
|
|
|
*/ |
128
|
|
View Code Duplication |
public static function gbookSignForm($nameTmp, $emailTmp, $urlTmp, $messageTmp) |
|
|
|
|
129
|
|
|
{ |
130
|
|
|
$name = new XoopsFormText(_GBOOK_NAME, 'Name', 43, 100, $nameTmp); |
131
|
|
|
$email = new XoopsFormText(_GBOOK_EMAIL, 'Email', 43, 100, $emailTmp); |
132
|
|
|
$url = new XoopsFormText(_GBOOK_URL, 'URL', 43, 100, $urlTmp); |
133
|
|
|
$message = new XoopsFormTextArea(_GBOOK_MESSAGE, 'Message', $messageTmp); |
134
|
|
|
$submit = new XoopsFormButton('', 'submit', _GBOOK_SUBMIT, 'submit'); |
135
|
|
|
$gbookform = new XoopsThemeForm(_GBOOK_SIGN, 'gbookform', 'sign.php'); |
136
|
|
|
|
137
|
|
|
$gbookform->addElement($name, true); |
138
|
|
|
$gbookform->addElement($email); |
139
|
|
|
$gbookform->addElement($url); |
140
|
|
|
$gbookform->addElement($message, true); |
141
|
|
|
$gbookform->addElement(new XoopsFormCaptcha(), true); |
142
|
|
|
$gbookform->addElement($submit); |
143
|
|
|
|
144
|
|
|
return $gbookform; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return string |
149
|
|
|
*/ |
150
|
|
View Code Duplication |
public static function gbookIP() |
|
|
|
|
151
|
|
|
{ |
152
|
|
|
$ip = 'UNKNOWN'; |
153
|
|
|
if (getenv('HTTP_CLIENT_IP')) { |
154
|
|
|
$ip = getenv('HTTP_CLIENT_IP'); |
155
|
|
|
} else { |
156
|
|
|
if (getenv('HTTP_X_FORWARDED_FOR')) { |
157
|
|
|
$ip = getenv('HTTP_X_FORWARDED_FOR'); |
158
|
|
|
} else { |
159
|
|
|
if (getenv('REMOTE_ADDR')) { |
160
|
|
|
$ip = getenv('REMOTE_ADDR'); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
return $ip; |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.