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
|
|
|
* See the enclosed file license.txt for licensing information. |
14
|
|
|
* If you did not receive this file, get it at http://www.gnu.org/licenses/gpl-2.0.html |
15
|
|
|
* |
16
|
|
|
* @copyright XOOPS Project (http://xoops.org) |
17
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License (GPL) |
18
|
|
|
* @package installer |
19
|
|
|
* @since 2.3.0 |
20
|
|
|
* @author Haruki Setoyama <[email protected]> |
21
|
|
|
* @author Kazumi Ono <[email protected]> |
22
|
|
|
* @author Skalpa Keo <[email protected]> |
23
|
|
|
* @author Taiwen Jiang <[email protected]> |
24
|
|
|
* @author DuGris (aka L. JEN) <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class XoopsInstallWizard |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
public $language = 'english'; |
29
|
|
|
public $pages = array(); |
30
|
|
|
public $currentPage = 'langselect'; |
31
|
|
|
public $pageIndex = 0; |
32
|
|
|
public $configs = array(); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return bool |
36
|
|
|
*/ |
37
|
|
|
public function xoInit() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
if (@empty($_SERVER['REQUEST_URI'])) { |
40
|
|
|
$_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF']; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
// Load the main language file |
44
|
|
|
$this->initLanguage(!empty($_COOKIE['xo_install_lang']) ? $_COOKIE['xo_install_lang'] : 'english'); |
45
|
|
|
// Setup pages |
46
|
|
|
include_once './../include/page.php'; |
47
|
|
|
$this->pages = $pages; |
|
|
|
|
48
|
|
|
|
49
|
|
|
// Load default configs |
50
|
|
|
include_once './../include/config.php'; |
51
|
|
|
$this->configs = $configs; |
|
|
|
|
52
|
|
|
/* |
53
|
|
|
// Database type |
54
|
|
|
$this->db_types = $db_types; |
55
|
|
|
|
56
|
|
|
// setup config site info |
57
|
|
|
$this->conf_names = $conf_names; |
58
|
|
|
|
59
|
|
|
// languages config files |
60
|
|
|
$this->language_files = $language_files; |
61
|
|
|
|
62
|
|
|
// extension_loaded |
63
|
|
|
$this->extensions = $extensions; |
64
|
|
|
|
65
|
|
|
// Modules to be installed by default |
66
|
|
|
$this->modules = $modules; |
67
|
|
|
|
68
|
|
|
// xoops_lib, xoops_data directories |
69
|
|
|
$this->xoopsPathDefault = $xoopsPathDefault; |
70
|
|
|
|
71
|
|
|
// writable xoops_lib, xoops_data directories |
72
|
|
|
$this->dataPath = $dataPath; |
73
|
|
|
|
74
|
|
|
// Protector default trust_path |
75
|
|
|
$this->trust_path = isset($trust_path) ? $trust_path : false; |
76
|
|
|
|
77
|
|
|
// Writable files and directories |
78
|
|
|
$this->writable = $writable; |
79
|
|
|
*/ |
80
|
|
|
|
81
|
|
|
if (!$this->checkAccess()) { |
82
|
|
|
return false; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$pagename = preg_replace('~(page_)(.*)~', '$2', basename($_SERVER['PHP_SELF'], '.php')); |
86
|
|
|
$this->setPage($pagename); |
87
|
|
|
|
88
|
|
|
// Prevent client caching |
89
|
|
|
header('Cache-Control: no-store, no-cache, must-revalidate', false); |
90
|
|
|
header('Pragma: no-cache'); |
91
|
|
|
|
92
|
|
|
return true; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return bool |
97
|
|
|
*/ |
98
|
|
|
public function checkAccess() |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
if (INSTALL_USER != '' && INSTALL_PASSWORD != '') { |
101
|
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) { |
102
|
|
|
header('WWW-Authenticate: Basic realm="XOOPS Installer"'); |
103
|
|
|
header('HTTP/1.0 401 Unauthorized'); |
104
|
|
|
echo 'You can not access this XOOPS installer.'; |
105
|
|
|
|
106
|
|
|
return false; |
107
|
|
|
} |
108
|
|
|
if (INSTALL_USER != '' && $_SERVER['PHP_AUTH_USER'] != INSTALL_USER) { |
109
|
|
|
header('HTTP/1.0 401 Unauthorized'); |
110
|
|
|
echo 'You can not access this XOOPS installer.'; |
111
|
|
|
|
112
|
|
|
return false; |
113
|
|
|
} |
114
|
|
|
if (INSTALL_PASSWORD != $_SERVER['PHP_AUTH_PW']) { |
115
|
|
|
header('HTTP/1.0 401 Unauthorized'); |
116
|
|
|
echo 'You can not access this XOOPS installer.'; |
117
|
|
|
|
118
|
|
|
return false; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
if (empty($GLOBALS['xoopsOption']['checkadmin'])) { |
123
|
|
|
return true; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
if (empty($GLOBALS['xoopsUser']) && !empty($_COOKIE['xo_install_user'])) { |
127
|
|
|
install_acceptUser($_COOKIE['xo_install_user']); |
128
|
|
|
} |
129
|
|
|
if (empty($GLOBALS['xoopsUser'])) { |
130
|
|
|
redirect_header('../user.php'); |
131
|
|
|
} |
132
|
|
|
if (!$GLOBALS['xoopsUser']->isAdmin()) { |
133
|
|
|
return false; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return true; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param $file |
141
|
|
|
*/ |
142
|
|
|
public function loadLangFile($file) |
143
|
|
|
{ |
144
|
|
|
if (file_exists("./language/{$this->language}/{$file}.php")) { |
145
|
|
|
include_once "./language/{$this->language}/{$file}.php"; |
146
|
|
|
} else { |
147
|
|
|
include_once "./../language/english/$file.php"; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param $language |
153
|
|
|
*/ |
154
|
|
|
public function initLanguage($language) |
155
|
|
|
{ |
156
|
|
|
$language = preg_replace("/[^a-z0-9_\-]/i", '', $language); |
157
|
|
|
if (!file_exists("./language/{$language}/install.php")) { |
158
|
|
|
$language = 'english'; |
159
|
|
|
} |
160
|
|
|
$this->language = $language; |
161
|
|
|
$this->loadLangFile('install'); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param $page |
166
|
|
|
* |
167
|
|
|
* @return bool|mixed |
168
|
|
|
*/ |
169
|
|
|
public function setPage($page) |
|
|
|
|
170
|
|
|
{ |
171
|
|
|
$pages = array_keys($this->pages); |
172
|
|
|
if ((int)$page && $page >= 0 && $page < count($pages)) { |
173
|
|
|
$this->pageIndex = $page; |
174
|
|
|
$this->currentPage = $pages[$page]; |
|
|
|
|
175
|
|
|
} elseif (isset($this->pages[$page])) { |
176
|
|
|
$this->currentPage = $page; |
177
|
|
|
$this->pageIndex = array_search($this->currentPage, $pages); |
|
|
|
|
178
|
|
|
} else { |
179
|
|
|
return false; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
if ($this->pageIndex > 0 && !isset($_COOKIE['xo_install_lang'])) { |
183
|
|
|
header('Location: index.php'); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
return $this->pageIndex; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
|
|
public function baseLocation() |
|
|
|
|
193
|
|
|
{ |
194
|
|
|
$proto = (@$_SERVER['HTTPS'] === 'on') ? 'https' : 'http'; |
195
|
|
|
$host = $_SERVER['HTTP_HOST']; |
196
|
|
|
$base = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')); |
197
|
|
|
|
198
|
|
|
return $proto . '://' . $host . $base; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @param $page |
203
|
|
|
* |
204
|
|
|
* @return string |
205
|
|
|
*/ |
206
|
|
|
public function pageURI($page) |
207
|
|
|
{ |
208
|
|
|
$pages = array_keys($this->pages); |
209
|
|
|
$pageIndex = $this->pageIndex; |
210
|
|
|
if (!(int)$page{0}) { |
211
|
|
|
if ($page{0} == '+') { |
212
|
|
|
$pageIndex += substr($page, 1); |
213
|
|
|
} elseif ($page{0} == '-') { |
214
|
|
|
$pageIndex -= substr($page, 1); |
215
|
|
|
} else { |
216
|
|
|
$pageIndex = (int)array_search($page, $pages); |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
if (!isset($pages[$pageIndex])) { |
220
|
|
|
if (defined('XOOPS_URL')) { |
221
|
|
|
return XOOPS_URL; |
222
|
|
|
} else { |
223
|
|
|
return $this->baseLocation(); |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
$page = $pages[$pageIndex]; |
227
|
|
|
|
228
|
|
|
return $this->baseLocation() . "/page_{$page}.php"; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @param $page |
233
|
|
|
* @param int $status |
234
|
|
|
* @param string $message |
235
|
|
|
*/ |
236
|
|
|
public function redirectToPage($page, $status = 303, $message = 'See other') |
|
|
|
|
237
|
|
|
{ |
238
|
|
|
$location = $this->pageURI($page); |
239
|
|
|
$proto = !@empty($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
240
|
|
|
header("{$proto} {$status} {$message}"); |
241
|
|
|
//header( "Status: $status $message" ); |
|
|
|
|
242
|
|
|
header("Location: {$location}"); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @return string |
247
|
|
|
*/ |
248
|
|
|
public function createForm() |
249
|
|
|
{ |
250
|
|
|
$hidden = ''; |
251
|
|
|
$ret = ''; |
252
|
|
|
|
253
|
|
|
foreach ($this->form as $form) { |
|
|
|
|
254
|
|
|
$ret .= '<fieldset><legend>' . $form->getTitle() . "</legend>\n"; |
255
|
|
|
|
256
|
|
|
foreach ($form->getElements() as $ele) { |
257
|
|
|
if (is_object($ele)) { |
258
|
|
|
if (!$ele->isHidden()) { |
259
|
|
|
if (($caption = $ele->getCaption()) != '') { |
260
|
|
|
$name = $ele->getName(); |
|
|
|
|
261
|
|
|
$ret .= "<label class='xolabel' for='" . $ele->getName() . "'>" . $caption . '</label>'; |
262
|
|
|
if (($desc = $ele->getDescription()) != '') { |
263
|
|
|
$ret .= "<div class='xoform-help'>"; |
264
|
|
|
$ret .= $desc; |
265
|
|
|
$ret .= '</div>'; |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
$ret .= $ele->render() . "\n"; |
269
|
|
|
} else { |
270
|
|
|
$hidden .= $ele->render() . "\n"; |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
$ret .= "</fieldset>\n" . $hidden . "\n" . $form->renderValidationJS(true); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
return $ret; |
278
|
|
|
} |
279
|
|
|
} |
280
|
|
|
|
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.