XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
installwizard.php
Go to the documentation of this file.
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 */
28 {
29  var $language = 'english';
30  var $pages = array();
31  var $currentPage = 'langselect';
32  var $pageIndex = 0;
33  var $configs = array();
34 
35  function xoInit()
36  {
37  if (@empty( $_SERVER['REQUEST_URI'])) {
38  $_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
39  }
40 
41  // Load the main language file
42  $this->initLanguage(!empty( $_COOKIE['xo_install_lang']) ? $_COOKIE['xo_install_lang'] : 'english');
43  // Setup pages
44  include_once './include/page.php';
45  $this->pages = $pages;
46 
47  // Load default configs
48  include_once './include/config.php';
49  $this->configs = $configs;
50  /*
51  // Database type
52  $this->db_types = $db_types;
53 
54  // setup config site info
55  $this->conf_names = $conf_names;
56 
57  // languages config files
58  $this->language_files = $language_files;
59 
60  // extension_loaded
61  $this->extensions = $extensions;
62 
63  // Modules to be installed by default
64  $this->modules = $modules;
65 
66  // xoops_lib, xoops_data directories
67  $this->xoopsPathDefault = $xoopsPathDefault;
68 
69  // writable xoops_lib, xoops_data directories
70  $this->dataPath = $dataPath;
71 
72  // Protector default trust_path
73  $this->trust_path = isset($trust_path) ? $trust_path : false;
74 
75  // Writable files and directories
76  $this->writable = $writable;
77  */
78 
79  if (!$this->checkAccess()) {
80  return false;
81  }
82 
83  $pagename = preg_replace('~(page_)(.*)~','$2', basename($_SERVER['PHP_SELF'], ".php"));
84  $this->setPage($pagename);
85 
86  // Prevent client caching
87  header("Cache-Control: no-store, no-cache, must-revalidate", false);
88  header("Pragma: no-cache");
89  return true;
90  }
91 
92  function checkAccess()
93  {
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 (empty($GLOBALS['xoopsOption']['checkadmin'])) {
114  return true;
115  }
116 
117  if (empty($GLOBALS['xoopsUser']) && !empty($_COOKIE["xo_install_user"])) {
118  install_acceptUser( $_COOKIE["xo_install_user"] );
119  }
120  if (empty($GLOBALS['xoopsUser'])) {
121  redirect_header("../user.php");
122  }
123  if (!$GLOBALS['xoopsUser']->isAdmin()) {
124  return false;
125  }
126  return true;
127  }
128 
129  function loadLangFile($file)
130  {
131  if (file_exists("./language/{$this->language}/{$file}.php")) {
132  include_once "./language/{$this->language}/{$file}.php";
133  } else {
134  include_once "./language/english/$file.php";
135  }
136  }
137 
139  {
140  $language = preg_replace("/[^a-z0-9_\-]/i", "", $language);
141  if (!file_exists("./language/{$language}/install.php")) {
142  $language = 'english';
143  }
144  $this->language = $language;
145  $this->loadLangFile('install');
146  }
147 
148  function setPage($page)
149  {
150  $pages = array_keys($this->pages);
151  if ((int)$page && $page >= 0 && $page < count($pages)) {
152  $this->pageIndex = $page;
153  $this->currentPage = $pages[$page];
154  } else if (isset( $this->pages[$page])) {
155  $this->currentPage = $page;
156  $this->pageIndex = array_search($this->currentPage, $pages);
157  } else {
158  return false;
159  }
160 
161  if ($this->pageIndex > 0 && !isset($_COOKIE['xo_install_lang'])) {
162  header('Location: index.php');
163  }
164 
165  return $this->pageIndex;
166  }
167 
168  function baseLocation()
169  {
170  $proto = ( @$_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
171  $host = $_SERVER['HTTP_HOST'];
172  $base = substr( $_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
173  return $proto . '://' . $host . $base;
174  }
175 
176  function pageURI( $page )
177  {
178  $pages = array_keys($this->pages);
180  if (!(int)$page{0}) {
181  if ($page{0} == '+') {
182  $pageIndex += substr($page, 1);
183  } else if ($page{0} == '-') {
184  $pageIndex -= substr($page, 1);
185  } else {
186  $pageIndex = (int)array_search($page, $pages);
187  }
188  }
189  if (!isset($pages[$pageIndex])) {
190  if (defined("XOOPS_URL")) {
191  return XOOPS_URL;
192  } else {
193  return $this->baseLocation();
194  }
195  }
197  return $this->baseLocation() . "/page_{$page}.php";
198  }
199 
200  function redirectToPage( $page, $status = 303, $message = 'See other' )
201  {
202  $location = $this->pageURI( $page );
203  $proto = !@empty($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
204  header("{$proto} {$status} {$message}");
205  //header( "Status: $status $message" );
206  header("Location: {$location}");
207  }
208 
209  function CreateForm()
210  {
211  $hidden = '';
212  $ret = '';
213 
214  foreach ($this->form as $form) {
215  $ret .= "<fieldset><legend>" . $form->getTitle() . "</legend>\n";
216 
217  foreach ($form->getElements() as $ele) {
218  if (is_object($ele)) {
219  if (!$ele->isHidden() ) {
220  if (($caption = $ele->getCaption()) != '') {
221  $name = $ele->getName();
222  $ret .= "<label class='xolabel' for='" . $ele->getName() . "'>" . $caption . "</label>";
223  if (($desc = $ele->getDescription()) != '') {
224  $ret .= "<div class='xoform-help'>";
225  $ret .= $desc;
226  $ret .= "</div>";
227  }
228  }
229  $ret .= $ele->render() . "\n";
230  } else {
231  $hidden .= $ele->render() . "\n";
232  }
233  }
234  }
235  $ret .= "</fieldset>\n" . $hidden. "\n" . $form->renderValidationJS(true);
236  }
237  return $ret;
238  }
239 
240 }
241 ?>