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:
34: 35: 36:
37: public function xoInit()
38: {
39: if (@empty($_SERVER['REQUEST_URI'])) {
40: $_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
41: }
42:
43:
44: $this->initLanguage(!empty($_COOKIE['xo_install_lang']) ? $_COOKIE['xo_install_lang'] : 'english');
45:
46: include_once './include/page.php';
47: $this->pages = $pages;
48:
49:
50: include_once './include/config.php';
51: $this->configs = $configs;
52: 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: 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:
89: header('Cache-Control: no-store, no-cache, must-revalidate', false);
90: header('Pragma: no-cache');
91:
92: return true;
93: }
94:
95: 96: 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: return 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: 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: 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: 166: 167: 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: 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: 203: 204: 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: 233: 234: 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:
242: header("Location: {$location}");
243: }
244:
245: 246: 247:
248: public function CreateForm()
249: {
250: $hidden = '';
251: $ret = '';
252:
253: foreach ($this->form as $form) {
254: $ret .= '<div class="panel panel-info">';
255: $ret .= '<div class="panel-heading">' . $form->getTitle() . '</div>';
256: $ret .= '<div class="panel-body">';
257:
258: foreach ($form->getElements() as $ele) {
259: if (is_object($ele)) {
260: if (!$ele->isHidden()) {
261: if (($caption = $ele->getCaption()) != '') {
262: $name = $ele->getName();
263: $ret .= "<label class='xolabel' for='" . $ele->getName() . "'>" . $caption . '</label>';
264: if (($desc = $ele->getDescription()) != '') {
265: $ret .= "<div class='xoform-help alert alert-info'>";
266: $ret .= $desc;
267: $ret .= '</div>';
268: }
269: }
270: $ret .= $ele->render() . "\n";
271: } else {
272: $hidden .= $ele->render() . "\n";
273: }
274: }
275: }
276: $ret .= "</div></div>\n" . $hidden . "\n" . $form->renderValidationJS(true);
277: }
278:
279: return $ret;
280: }
281: }
282: