XOOPS  2.6.0
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 */
11 
26 {
30  public $language = 'en_US';
31 
35  public $pages = array();
36 
40  public $currentPage = 'langselect';
41 
45  public $pageIndex = 0;
46 
50  public $configs = array();
51 
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  // Load the main language file
64  $this->initLanguage(!empty($_COOKIE['xo_install_lang']) ? $_COOKIE['xo_install_lang'] : 'en_US');
65  // Setup pages
66  $pages = array();
67  include_once dirname(__DIR__) . '/include/page.php';
68  $this->pages = $pages;
69 
70  // Load default configs
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  // Prevent client caching
83  header("Cache-Control: no-store, no-cache, must-revalidate", false);
84  header("Pragma: no-cache");
85  return true;
86  }
87 
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 
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 
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 
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 
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 
191  public function baseLocation()
192  {
193  $proto = (@$_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 
204  public function pageURI($page)
205  {
206  $pages = array_keys($this->pages);
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  }
227  return $this->baseLocation() . "/page_{$page}.php";
228  }
229 
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  //header( "Status: $status $message" );
243  header("Location: {$location}");
244  }
245 
249  public function CreateForm()
250  {
251  $hidden = '';
252  $ret = '';
253 
254  /* @var Xoops\Form\Form $form */
255  foreach ($this->form as $form) {
256  $ret .= "<fieldset><legend>" . $form->getTitle() . "</legend>\n";
257 
258  /* @var Xoops\Form\Element $ele */
259  foreach ($form->getElements() as $ele) {
260  //todo, ain't this always a object on 2.6?
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 }
redirectToPage($page, $status=303, $message= 'See other')
$i
Definition: dialog.php:68
static getInstance()
Definition: Xoops.php:160
cleanCache($cacheFolder)
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
Definition: browse.php:55
$page
Definition: help.php:31
$_SERVER['REQUEST_URI']
$xoopsOption['nocommon']
Definition: browse.php:22
$files
Definition: index.php:35
$xoops
Definition: admin.php:25
$status
const XOOPS_INSTALL_PATH
Definition: common.inc.php:33
$base
Definition: execute.php:30
$wizard form
initLanguage($language)
install_acceptUser($hash= '')
Definition: functions.php:29
const INSTALL_PASSWORD
Definition: common.inc.php:31
const INSTALL_USER
Definition: common.inc.php:30