1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: |
|
11: |
|
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | |
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: | public $form;
|
34: |
|
35: | |
36: | |
37: |
|
38: | public function xoInit()
|
39: | {
|
40: | if (@empty($_SERVER['REQUEST_URI'])) {
|
41: | $_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
|
42: | }
|
43: |
|
44: |
|
45: | $this->initLanguage(!empty($_COOKIE['xo_install_lang']) ? $_COOKIE['xo_install_lang'] : 'english');
|
46: |
|
47: | include_once __DIR__ . '/../include/page.php';
|
48: | $this->pages = $pages;
|
49: |
|
50: |
|
51: | include_once __DIR__ . '/../include/config.php';
|
52: | $this->configs = $configs;
|
53: | |
54: | |
55: | |
56: | |
57: | |
58: | |
59: | |
60: | |
61: | |
62: | |
63: | |
64: | |
65: | |
66: | |
67: | |
68: | |
69: | |
70: | |
71: | |
72: | |
73: | |
74: | |
75: | |
76: | |
77: | |
78: | |
79: | |
80: |
|
81: |
|
82: | if (!$this->checkAccess()) {
|
83: | return false;
|
84: | }
|
85: |
|
86: | $pagename = preg_replace('~(page_)(.*)~', '$2', basename($_SERVER['PHP_SELF'], '.php'));
|
87: | $this->setPage($pagename);
|
88: |
|
89: |
|
90: | header('Cache-Control: no-store, no-cache, must-revalidate', false);
|
91: | header('Pragma: no-cache');
|
92: |
|
93: | return true;
|
94: | }
|
95: |
|
96: | |
97: | |
98: |
|
99: | public function checkAccess()
|
100: | {
|
101: | if (INSTALL_USER != '' && INSTALL_PASSWORD != '') {
|
102: | if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
103: | header('WWW-Authenticate: Basic realm="XOOPS Installer"');
|
104: | header('HTTP/1.0 401 Unauthorized');
|
105: | echo 'You can not access this XOOPS installer.';
|
106: |
|
107: | return false;
|
108: | }
|
109: | if (INSTALL_USER != '' && $_SERVER['PHP_AUTH_USER'] != INSTALL_USER) {
|
110: | header('HTTP/1.0 401 Unauthorized');
|
111: | echo 'You can not access this XOOPS installer.';
|
112: |
|
113: | return false;
|
114: | }
|
115: | if (INSTALL_PASSWORD != $_SERVER['PHP_AUTH_PW']) {
|
116: | header('HTTP/1.0 401 Unauthorized');
|
117: | echo 'You can not access this XOOPS installer.';
|
118: |
|
119: | return false;
|
120: | }
|
121: | }
|
122: |
|
123: | if (empty($GLOBALS['xoopsOption']['checkadmin'])) {
|
124: | return true;
|
125: | }
|
126: |
|
127: | if (empty($GLOBALS['xoopsUser']) && !empty($_COOKIE['xo_install_user'])) {
|
128: | return install_acceptUser($_COOKIE['xo_install_user']);
|
129: | }
|
130: | if (empty($GLOBALS['xoopsUser'])) {
|
131: | redirect_header('../user.php');
|
132: | }
|
133: | if (!$GLOBALS['xoopsUser']->isAdmin()) {
|
134: | return false;
|
135: | }
|
136: |
|
137: | return true;
|
138: | }
|
139: |
|
140: | |
141: | |
142: |
|
143: | public function loadLangFile($file)
|
144: | {
|
145: | if (file_exists(__DIR__ . "/../language/{$this->language}/{$file}.php")) {
|
146: | include_once __DIR__ . "/../language/{$this->language}/{$file}.php";
|
147: | } else {
|
148: | include_once __DIR__ . "/../language/english/$file.php";
|
149: | }
|
150: | }
|
151: |
|
152: | |
153: | |
154: |
|
155: | public function initLanguage($language)
|
156: | {
|
157: | $language = preg_replace("/[^a-z0-9_\-]/i", '', $language);
|
158: | if (!file_exists("./language/{$language}/install.php")) {
|
159: | $language = 'english';
|
160: | }
|
161: | $this->language = $language;
|
162: | $this->loadLangFile('install');
|
163: | }
|
164: |
|
165: | |
166: | |
167: | |
168: | |
169: |
|
170: | public function setPage($page)
|
171: | {
|
172: | $pages = array_keys($this->pages);
|
173: | if ((int)$page && $page >= 0 && $page < count($pages)) {
|
174: | $this->pageIndex = $page;
|
175: | $this->currentPage = $pages[$page];
|
176: | } elseif (isset($this->pages[$page])) {
|
177: | $this->currentPage = $page;
|
178: | $this->pageIndex = array_search($this->currentPage, $pages);
|
179: | } else {
|
180: | return false;
|
181: | }
|
182: |
|
183: | if ($this->pageIndex > 0 && !isset($_COOKIE['xo_install_lang'])) {
|
184: | header('Location: index.php');
|
185: | }
|
186: |
|
187: | return $this->pageIndex;
|
188: | }
|
189: |
|
190: | |
191: | |
192: |
|
193: | public function baseLocation()
|
194: | {
|
195: | $proto = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')) ? 'https' : 'http';
|
196: | $host = $_SERVER['HTTP_HOST'];
|
197: | $base = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
|
198: |
|
199: | return $proto . '://' . $host . $base;
|
200: | }
|
201: |
|
202: | |
203: | |
204: | |
205: | |
206: |
|
207: | public function pageURI($page)
|
208: | {
|
209: | $pages = array_keys($this->pages);
|
210: | $pageIndex = $this->pageIndex;
|
211: | if (!(int)$page[0]) {
|
212: | if ($page[0] == '+') {
|
213: | $pageIndex += substr($page, 1);
|
214: | } elseif ($page[0] == '-') {
|
215: | $pageIndex -= substr($page, 1);
|
216: | } else {
|
217: | $pageIndex = (int)array_search($page, $pages);
|
218: | }
|
219: | }
|
220: | if (!isset($pages[$pageIndex])) {
|
221: | if (defined('XOOPS_URL')) {
|
222: | return XOOPS_URL;
|
223: | } else {
|
224: | return $this->baseLocation();
|
225: | }
|
226: | }
|
227: | $page = $pages[$pageIndex];
|
228: |
|
229: | return $this->baseLocation() . "/page_{$page}.php";
|
230: | }
|
231: |
|
232: | |
233: | |
234: | |
235: | |
236: |
|
237: | public function redirectToPage($page, $status = 303, $message = 'See other')
|
238: | {
|
239: | $location = $this->pageURI($page);
|
240: | $proto = !@empty($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
|
241: | header("{$proto} {$status} {$message}");
|
242: |
|
243: | header("Location: {$location}");
|
244: | }
|
245: |
|
246: | |
247: | |
248: |
|
249: | public function CreateForm()
|
250: | {
|
251: | $hidden = '';
|
252: | $ret = '';
|
253: |
|
254: | foreach ($this->form as $form) {
|
255: | $ret .= '<div class="panel panel-info">';
|
256: | $ret .= '<div class="panel-heading">' . $form->getTitle() . '</div>';
|
257: | $ret .= '<div class="panel-body">';
|
258: |
|
259: | foreach ($form->getElements() as $ele) {
|
260: | if (is_object($ele)) {
|
261: | if (!$ele->isHidden()) {
|
262: | if (($caption = $ele->getCaption()) != '') {
|
263: | $name = $ele->getName();
|
264: | $ret .= "<label class='xolabel' for='" . $ele->getName() . "'>" . $caption . '</label>';
|
265: | if (($desc = $ele->getDescription()) != '') {
|
266: | $ret .= "<div class='xoform-help alert alert-info'>";
|
267: | $ret .= $desc;
|
268: | $ret .= '</div>';
|
269: | }
|
270: | }
|
271: | $ret .= $ele->render() . "\n";
|
272: | } else {
|
273: | $hidden .= $ele->render() . "\n";
|
274: | }
|
275: | }
|
276: | }
|
277: | $ret .= "</div></div>\n" . $hidden . "\n" . $form->renderValidationJS(true);
|
278: | }
|
279: |
|
280: | return $ret;
|
281: | }
|
282: | }
|
283: | |