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: class XoopsInstallWizard
26: {
27: 28: 29:
30: public $language = 'en_US';
31:
32: 33: 34:
35: public $pages = array();
36:
37: 38: 39:
40: public $currentPage = 'langselect';
41:
42: 43: 44:
45: public $pageIndex = 0;
46:
47: 48: 49:
50: public $configs = array();
51:
52: 53: 54:
55: public $form;
56:
57: public function xoInit()
58: {
59: if (@empty($_SERVER['REQUEST_URI'])) {
60: $_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
61: }
62:
63:
64: $this->initLanguage(!empty($_COOKIE['xo_install_lang']) ? $_COOKIE['xo_install_lang'] : 'en_US');
65:
66: $pages = array();
67: include_once dirname(__DIR__) . '/include/page.php';
68: $this->pages = $pages;
69:
70:
71: $configs = array();
72: include_once dirname(__DIR__) . '/include/config.php';
73: $this->configs = $configs;
74:
75: if (!$this->checkAccess()) {
76: return false;
77: }
78:
79: $pagename = preg_replace('~(page_)(.*)~', '$2', basename($_SERVER['PHP_SELF'], ".php"));
80: $this->setPage($pagename);
81:
82:
83: header("Cache-Control: no-store, no-cache, must-revalidate", false);
84: header("Pragma: no-cache");
85: return true;
86: }
87:
88: 89: 90:
91: public function checkAccess()
92: {
93: global $xoopsOption;
94: if (INSTALL_USER != '' && INSTALL_PASSWORD != '') {
95: if (!isset($_SERVER['PHP_AUTH_USER'])) {
96: header('WWW-Authenticate: Basic realm="XOOPS Installer"');
97: header('HTTP/1.0 401 Unauthorized');
98: echo 'You can not access this XOOPS installer.';
99: return false;
100: }
101: if (INSTALL_USER != '' && $_SERVER['PHP_AUTH_USER'] != INSTALL_USER) {
102: header('HTTP/1.0 401 Unauthorized');
103: echo 'You can not access this XOOPS installer.';
104: return false;
105: }
106: if (INSTALL_PASSWORD != $_SERVER['PHP_AUTH_PW']) {
107: header('HTTP/1.0 401 Unauthorized');
108: echo 'You can not access this XOOPS installer.';
109: return false;
110: }
111: }
112:
113: if (!isset($xoopsOption['checkadmin']) || !$xoopsOption['checkadmin']) {
114: return true;
115: }
116:
117: $xoops = Xoops::getInstance();
118: if (!$xoops->isUser() && !empty($_COOKIE["xo_install_user"])) {
119: install_acceptUser($_COOKIE["xo_install_user"]);
120: }
121:
122: if (!$xoops->isUser()) {
123: $xoops->redirect($xoops->url('user.php'));
124: }
125: if (!$xoops->isAdmin()) {
126: return false;
127: }
128: return true;
129: }
130:
131: 132: 133: 134: 135:
136: public function loadLangFile($file)
137: {
138: if (file_exists($file = XOOPS_INSTALL_PATH . "/locale/{$this->language}/{$file}.php")) {
139: include_once $file;
140: } else {
141: $file = XOOPS_INSTALL_PATH . "/locale/en_US/{$file}.php";
142: include_once $file;
143: }
144: }
145:
146: 147: 148: 149: 150:
151: public function initLanguage($language)
152: {
153: $language = preg_replace("/[^a-z0-9_\-]/i", "", $language);
154: if (!file_exists(XOOPS_INSTALL_PATH . "/locale/{$language}/install.php")) {
155: $language = 'en_US';
156: }
157: $this->language = $language;
158: $this->loadLangFile('install');
159: }
160:
161: 162: 163: 164: 165:
166: public function setPage($page)
167: {
168: $pages = array_keys($this->pages);
169: if ((int)$page && $page >= 0 && $page < count($pages)) {
170: $this->pageIndex = $page;
171: $this->currentPage = $pages[$page];
172: } else {
173: if (isset($this->pages[$page])) {
174: $this->currentPage = $page;
175: $this->pageIndex = array_search($this->currentPage, $pages);
176: } else {
177: return false;
178: }
179: }
180:
181: if ($this->pageIndex > 0 && !isset($_COOKIE['xo_install_lang'])) {
182: header('Location: index.php');
183: }
184:
185: return $this->pageIndex;
186: }
187:
188: 189: 190:
191: public function baseLocation()
192: {
193: $proto = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? 'https' : 'http';
194: $host = $_SERVER['HTTP_HOST'];
195: $base = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
196: return $proto . '://' . $host . $base;
197: }
198:
199: 200: 201: 202: 203:
204: public function pageURI($page)
205: {
206: $pages = array_keys($this->pages);
207: $pageIndex = $this->pageIndex;
208: if (!(int)$page{0}) {
209: if ($page{0} == '+') {
210: $pageIndex += substr($page, 1);
211: } else {
212: if ($page{0} == '-') {
213: $pageIndex -= substr($page, 1);
214: } else {
215: $pageIndex = (int)array_search($page, $pages);
216: }
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: return $this->baseLocation() . "/page_{$page}.php";
228: }
229:
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:
255: foreach ($this->form as $form) {
256: $ret .= "<fieldset><legend>" . $form->getTitle() . "</legend>\n";
257:
258:
259: foreach ($form->getElements() as $ele) {
260:
261: if ($ele instanceof Xoops\Form\Element) {
262: if (!$ele->isHidden()) {
263: if (($caption = $ele->getCaption()) != '') {
264: $ret .= "<label class='xolabel' for='" . $ele->getName() . "'>" . $caption . "</label>";
265: if (($desc = $ele->getDescription()) != '') {
266: $ret .= "<div class='xoform-help'>";
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 .= "</fieldset>\n" . $hidden . "\n" . $form->renderValidationJS(true);
278: }
279: return $ret;
280: }
281:
282: function cleanCache($cacheFolder) {
283: $cache = array(1,2,3);
284: if (!empty($cache)) {
285: for ($i = 0; $i < count($cache); ++$i) {
286: switch ($cache[$i]) {
287: case 1:
288: $files = glob($cacheFolder. '/caches/smarty_cache/*.*');
289: foreach ($files as $filename) {
290: if (basename(strtolower($filename)) !== 'index.html') {
291: unlink($filename);
292: }
293: }
294: break;
295:
296: case 2:
297: $files = glob($cacheFolder . '/caches/smarty_compile/*.*');
298: foreach ($files as $filename) {
299: if (basename(strtolower($filename)) !== 'index.html') {
300: unlink($filename);
301: }
302: }
303: break;
304:
305: case 3:
306: $files = glob($cacheFolder . '/caches/xoops_cache/*.*');
307: foreach ($files as $filename) {
308: if (basename(strtolower($filename)) !== 'index.html') {
309: unlink($filename);
310: }
311: }
312: break;
313: }
314: }
315: return true;
316: } else {
317: return false;
318: }
319: }
320: }
321: