Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/setup/index.php - 932 lines - 29426 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*
   4   * Textpattern Content Management System
   5   * http://textpattern.com
   6   *
   7   * Copyright (C) 2005 Dean Allen
   8   * Copyright (C) 2016 The Textpattern Development Team
   9   *
  10   * This file is part of Textpattern.
  11   *
  12   * Textpattern is free software; you can redistribute it and/or
  13   * modify it under the terms of the GNU General Public License
  14   * as published by the Free Software Foundation, version 2.
  15   *
  16   * Textpattern is distributed in the hope that it will be useful,
  17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19   * GNU General Public License for more details.
  20   *
  21   * You should have received a copy of the GNU General Public License
  22   * along with Textpattern. If not, see <http://www.gnu.org/licenses/>.
  23   */
  24  
  25  if (!defined('txpath')) {
  26      define("txpath", dirname(dirname(__FILE__)));
  27  }
  28  
  29  define("txpinterface", "admin");
  30  error_reporting(E_ALL | E_STRICT);
  31  @ini_set("display_errors", "1");
  32  
  33  include txpath.'/lib/class.trace.php';
  34  $trace = new Trace();
  35  include_once txpath.'/lib/constants.php';
  36  include_once txpath.'/lib/txplib_misc.php';
  37  include txpath.'/vendors/Textpattern/Loader.php';
  38  
  39  $loader = new \Textpattern\Loader(txpath.'/vendors');
  40  $loader->register();
  41  
  42  $loader = new \Textpattern\Loader(txpath.'/lib');
  43  $loader->register();
  44  
  45  if (!isset($_SESSION)) {
  46      if (headers_sent()) {
  47          $_SESSION = array();
  48      } else {
  49          session_start();
  50      }
  51  }
  52  
  53  include_once txpath.'/lib/txplib_html.php';
  54  include_once txpath.'/lib/txplib_forms.php';
  55  include_once txpath.'/include/txp_auth.php';
  56  
  57  assert_system_requirements();
  58  
  59  header("Content-type: text/html; charset=utf-8");
  60  header('X-UA-Compatible: '.X_UA_COMPATIBLE);
  61  
  62  // Drop trailing cruft.
  63  $_SERVER['PHP_SELF'] = preg_replace('#^(.*index.php).*$#i', '$1', $_SERVER['PHP_SELF']);
  64  
  65  // Sniff out the 'textpattern' directory's name '/path/to/site/textpattern/setup/index.php'.
  66  $txpdir = explode('/', $_SERVER['PHP_SELF']);
  67  
  68  if (count($txpdir) > 3) {
  69      // We live in the regular directory structure.
  70      $txpdir = '/'.$txpdir[count($txpdir) - 3];
  71  } else {
  72      // We probably came here from a clever assortment of symlinks and DocumentRoot.
  73      $txpdir = '/';
  74  }
  75  
  76  $step = ps('step');
  77  $rel_siteurl = preg_replace("#^(.*?)($txpdir)?/setup.*$#i", '$1', $_SERVER['PHP_SELF']);
  78  $rel_txpurl = rtrim(dirname(dirname($_SERVER['PHP_SELF'])), '/\\');
  79  
  80  switch ($step) {
  81      case '':
  82          chooseLang();
  83          break;
  84      case 'getDbInfo':
  85          getDbInfo();
  86          break;
  87      case 'getTxpLogin':
  88          getTxpLogin();
  89          break;
  90      case 'printConfig':
  91          printConfig();
  92          break;
  93      case 'createTxp':
  94          createTxp();
  95  }
  96  ?>
  97  </main>
  98  </body>
  99  </html>
 100  <?php
 101  
 102  /**
 103   * Return the top of page furniture.
 104   *
 105   * @param  string $step Name of the current Textpattern step of the setup wizard
 106   * @return HTML
 107   */
 108  
 109  function preamble($step = null)
 110  {
 111      global $textarray_script;
 112  
 113      $out = array();
 114      $bodyclass = ($step == '') ? ' welcome' : '';
 115      gTxtScript(array(
 116          'setup_password_strength_0',
 117          'setup_password_strength_1',
 118          'setup_password_strength_2',
 119          'setup_password_strength_3',
 120          'setup_password_strength_4',
 121          )
 122      );
 123  
 124      $out[] = <<<eod
 125      <!DOCTYPE html>
 126      <html lang="en">
 127      <head>
 128      <meta charset="utf-8">
 129      <meta name="robots" content="noindex, nofollow">
 130      <title>Setup &#124; Textpattern CMS</title>
 131  eod;
 132  
 133      $out[] = script_js('../vendors/jquery/jquery/jquery.js', TEXTPATTERN_SCRIPT_URL).
 134          script_js('../vendors/jquery/jquery-ui/jquery-ui.js', TEXTPATTERN_SCRIPT_URL).
 135          script_js('../vendors/dropbox/zxcvbn/zxcvbn.js', TEXTPATTERN_SCRIPT_URL).
 136          script_js(
 137              'var textpattern = '.json_encode(array(
 138                  'event'         => 'setup',
 139                  'step'          => $step,
 140                  'textarray'     => (object) $textarray_script,
 141                  )).';').
 142          script_js('../textpattern.js', TEXTPATTERN_SCRIPT_URL);
 143  
 144      $out[] = <<<eod
 145      <link rel="stylesheet" href="../admin-themes/hive/assets/css/textpattern.min.css">
 146      <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
 147      </head>
 148      <body class="setup{$bodyclass}" id="page-setup">
 149      <main class="txp-body">
 150  eod;
 151  
 152      return join(n, $out);
 153  }
 154  
 155  /**
 156   * Renders stage 0: welcome/choose language panel.
 157   */
 158  
 159  function chooseLang()
 160  {
 161      $_SESSION = array();
 162  
 163      echo preamble();
 164      echo n.'<div class="txp-setup">',
 165          hed('Welcome to Textpattern CMS', 1),
 166          n.'<form class="prefs-form" method="post" action="'.txpspecialchars($_SERVER['PHP_SELF']).'">',
 167          langs(),
 168          graf(fInput('submit', 'Submit', 'Submit', 'publish')),
 169          sInput('getDbInfo'),
 170          n.'</form>',
 171          n.'</div>';
 172  }
 173  
 174  /**
 175   * Renders progress meter displayed on stages 1 to 4 of installation process.
 176   *
 177   * @param int $stage The stage
 178   */
 179  
 180  function txp_setup_progress_meter($stage = 1)
 181  {
 182      $stages = array(
 183          1 => setup_gTxt('set_db_details'),
 184          2 => setup_gTxt('add_config_file'),
 185          3 => setup_gTxt('populate_db'),
 186          4 => setup_gTxt('get_started'),
 187      );
 188  
 189      $out = array();
 190  
 191      $out[] = n.'<aside class="progress-meter">'.
 192          graf(setup_gTxt('progress_steps'), ' class="txp-accessibility"').
 193          n.'<ol>';
 194  
 195      foreach ($stages as $idx => $phase) {
 196          $active = ($idx == $stage);
 197          $sel = $active ? ' class="active"' : '';
 198          $out[] = n.'<li'.$sel.'>'.($active ? strong($phase) : $phase).'</li>';
 199      }
 200  
 201      $out[] = n.'</ol>'.
 202          n.'</aside>';
 203  
 204      return join('', $out);
 205  }
 206  
 207  /**
 208   * Renders stage 1: database details panel.
 209   */
 210  
 211  function getDbInfo()
 212  {
 213      $lang = ps('lang');
 214  
 215      if ($lang) {
 216          $_SESSION['lang'] = $lang;
 217      }
 218  
 219      $GLOBALS['textarray'] = setup_load_lang($_SESSION['lang']);
 220  
 221      global $txpcfg, $step;
 222  
 223      echo preamble($step);
 224      echo txp_setup_progress_meter(1),
 225          n.'<div class="txp-setup">';
 226  
 227      if (!isset($txpcfg['db'])) {
 228          @include txpath.'/config.php';
 229      }
 230  
 231      if (!empty($txpcfg['db'])) {
 232          echo graf(
 233                  span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 234                  setup_gTxt('already_installed', array('{txpath}' => basename(txpath))),
 235                  array('class' => 'alert-block warning')
 236              ).
 237              setup_back_button(__FUNCTION__).
 238              n.'</div>';
 239  
 240          exit;
 241      }
 242  
 243      if (isset($_SESSION['siteurl'])) {
 244          $guess_siteurl = $_SESSION['siteurl'];
 245      } elseif (@$_SERVER['SCRIPT_NAME'] && (@$_SERVER['SERVER_NAME'] || @$_SERVER['HTTP_HOST'])) {
 246          $guess_siteurl = (@$_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
 247          $guess_siteurl .= $GLOBALS['rel_siteurl'];
 248      } else {
 249          $guess_siteurl = 'mysite.com';
 250      }
 251  
 252      echo '<form class="prefs-form" method="post" action="'.txpspecialchars($_SERVER['PHP_SELF']).'">'.
 253          hed(setup_gTxt('need_details'), 1).
 254          hed('MySQL', 2).
 255          graf(setup_gTxt('db_must_exist')).
 256          inputLabel(
 257              'setup_mysql_login',
 258              fInput('text', 'duser', (isset($_SESSION['duser']) ? $_SESSION['duser'] : ''), '', '', '', INPUT_REGULAR, '', 'setup_mysql_login'),
 259              'mysql_login', '', array('class' => 'txp-form-field')
 260          ).
 261          inputLabel(
 262              'setup_mysql_pass',
 263              fInput('password', 'dpass', (isset($_SESSION['dpass']) ? $_SESSION['dpass'] : ''), 'txp-maskable', '', '', INPUT_REGULAR, '', 'setup_mysql_pass').
 264              n.tag(
 265                  checkbox('unmask', 1, false, 0, 'show_password').
 266                  n.tag(gTxt('setup_show_password'), 'label', array('for' => 'show_password')),
 267                  'div', array('class' => 'show-password')),
 268              'mysql_password', '', array('class' => 'txp-form-field')
 269          ).
 270          inputLabel(
 271              'setup_mysql_server',
 272              fInput('text', 'dhost', (isset($_SESSION['dhost']) ? $_SESSION['dhost'] : 'localhost'), '', '', '', INPUT_REGULAR, '', 'setup_mysql_server', '', true),
 273              'mysql_server', '', array('class' => 'txp-form-field')
 274          ).
 275          inputLabel(
 276              'setup_mysql_db',
 277              fInput('text', 'ddb', (isset($_SESSION['ddb']) ? $_SESSION['ddb'] : ''), '', '', '', INPUT_REGULAR, '', 'setup_mysql_db', '', true),
 278              'mysql_database', '', array('class' => 'txp-form-field')
 279          ).
 280          inputLabel(
 281              'setup_table_prefix',
 282              fInput('text', 'dprefix', (isset($_SESSION['dprefix']) ? $_SESSION['dprefix'] : ''), 'input-medium', '', '', INPUT_MEDIUM, '', 'setup_table_prefix'),
 283              'table_prefix', 'table_prefix', array('class' => 'txp-form-field')
 284          ).
 285          hed(
 286              setup_gTxt('site_url'), 2
 287          ).
 288          graf(
 289              setup_gTxt('please_enter_url')
 290          ).
 291          inputLabel(
 292              'setup_site_url',
 293              fInput('text', 'siteurl', $guess_siteurl, '', '', '', INPUT_REGULAR, '', 'setup_site_url', '', true),
 294              'http(s)://', 'siteurl', array('class' => 'txp-form-field')
 295          );
 296  
 297      if (is_disabled('mail')) {
 298          echo graf(
 299              span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 300              setup_gTxt('warn_mail_unavailable'),
 301              array('class' => 'alert-block warning')
 302          );
 303      }
 304  
 305      echo graf(
 306          fInput('submit', 'Submit', setup_gTxt('next_step', '', 'raw'), 'publish')
 307      );
 308  
 309      echo sInput('printConfig').
 310          n.'</form>'.
 311          n.'</div>';
 312  }
 313  
 314  /**
 315   * Renders stage 2: either config details panel (on success) or database details
 316   * error message (on fail).
 317   */
 318  
 319  function printConfig()
 320  {
 321      $_SESSION['ddb'] = ps('ddb');
 322      $_SESSION['duser'] = ps('duser');
 323      $_SESSION['dpass'] = ps('dpass');
 324      $_SESSION['dhost'] = ps('dhost');
 325      $_SESSION['dprefix'] = ps('dprefix');
 326      $_SESSION['siteurl'] = ps('siteurl');
 327      $GLOBALS['textarray'] = setup_load_lang($_SESSION['lang']);
 328  
 329      global $txpcfg, $step;
 330  
 331      echo preamble($step);
 332      echo txp_setup_progress_meter(2).
 333          n.'<div class="txp-setup">';
 334  
 335      if (!isset($txpcfg['db'])) {
 336          @include txpath.'/config.php';
 337      }
 338  
 339      if (!empty($txpcfg['db'])) {
 340          echo graf(
 341                  span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 342                  setup_gTxt('already_installed', array('{txpath}' => basename(txpath))),
 343                  array('class' => 'alert-block warning')
 344              ).
 345              setup_back_button(__FUNCTION__).
 346              n.'</div>';
 347  
 348          exit;
 349      }
 350  
 351  // TODO: @see http://forum.textpattern.com/viewtopic.php?pid=263205#p263205
 352  //    if ('' === $_SESSION['dhost'] || '' === $_SESSION['duser'] || '' === $_SESSION['ddb']) {
 353  //        echo graf(
 354  //                span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 355  //                setup_gTxt('missing_db_details'),
 356  //                array('class' => 'alert-block warning')
 357  //            ).
 358  //            n.setup_back_button(__FUNCTION__).
 359  //            n.'</div>';
 360  //
 361  //        exit;
 362  //    }
 363  
 364      echo hed(setup_gTxt("checking_database"), 2);
 365  
 366      if (strpos($_SESSION['dhost'], ':') === false) {
 367          $dhost = $_SESSION['dhost'];
 368          $dport = ini_get("mysqli.default_port");
 369      } else {
 370          list($dhost, $dport) = explode(':', $_SESSION['dhost'], 2);
 371          $dport = intval($dport);
 372      }
 373  
 374      $dsocket = ini_get("mysqli.default_socket");
 375  
 376      $mylink = mysqli_init();
 377  
 378      if (@mysqli_real_connect($mylink, $dhost, $_SESSION['duser'], $_SESSION['dpass'], '', $dport, $dsocket)) {
 379          $_SESSION['dclient_flags'] = 0;
 380      } elseif (@mysqli_real_connect($mylink, $dhost, $_SESSION['duser'], $_SESSION['dpass'], '', $dport, $dsocket, MYSQLI_CLIENT_SSL)) {
 381          $_SESSION['dclient_flags'] = 'MYSQLI_CLIENT_SSL';
 382      } else {
 383          echo graf(
 384                  span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 385                  setup_gTxt('db_cant_connect'),
 386                  array('class' => 'alert-block error')
 387              ).
 388              setup_back_button(__FUNCTION__).
 389              n.'</div>';
 390  
 391          exit;
 392      }
 393  
 394      echo graf(
 395          span(null, array('class' => 'ui-icon ui-icon-check')).' '.
 396          setup_gTxt('db_connected'),
 397          array('class' => 'alert-block success')
 398      );
 399  
 400      if (!($_SESSION['dprefix'] == '' || preg_match('#^[a-zA-Z_][a-zA-Z0-9_]*$#', $_SESSION['dprefix']))) {
 401          echo graf(
 402                  span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 403                  setup_gTxt('prefix_bad_characters', array(
 404                      '{dbprefix}' => strong(txpspecialchars($_SESSION['dprefix']))
 405                  ), 'raw'),
 406                  array('class' => 'alert-block error')
 407              ).
 408              setup_back_button(__FUNCTION__).
 409              n.'</div>';
 410  
 411          exit;
 412      }
 413  
 414      if (!$mydb = mysqli_select_db($mylink, $_SESSION['ddb'])) {
 415          echo graf(
 416                  span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 417                  setup_gTxt('db_doesnt_exist', array(
 418                      '{dbname}' => strong(txpspecialchars($_SESSION['ddb']))
 419                  ), 'raw'),
 420                  array('class' => 'alert-block error')
 421              ).
 422              setup_back_button(__FUNCTION__).
 423              n.'</div>';
 424  
 425          exit;
 426      }
 427  
 428      $tables_exist = mysqli_query($mylink, "DESCRIBE `".$_SESSION['dprefix']."textpattern`");
 429      if ($tables_exist) {
 430          echo graf(
 431                  span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 432                  setup_gTxt('tables_exist', array(
 433                      '{dbname}' => strong(txpspecialchars($_SESSION['ddb']))
 434                  ), 'raw'),
 435                  array('class' => 'alert-block error')
 436              ).
 437              setup_back_button(__FUNCTION__).
 438              n.'</div>';
 439  
 440          exit;
 441      }
 442  
 443      // On MySQL 5.5.3+ use real UTF-8 tables, if the client supports it.
 444      $_SESSION['dbcharset'] = "utf8mb4";
 445      // Lower versions only support UTF-8 limited to 3 bytes per character
 446      if (mysqli_get_server_version($mylink) < 50503) {
 447          $_SESSION['dbcharset'] = "utf8";
 448      } else {
 449          if (false !== strpos(mysqli_get_client_info($mylink), 'mysqlnd')) {
 450              // mysqlnd 5.0.9+ required
 451              if (mysqli_get_client_version($mylink) < 50009) {
 452                  $_SESSION['dbcharset'] = "utf8";
 453              }
 454          } else {
 455              // libmysqlclient 5.5.3+ required
 456              if (mysqli_get_client_version($mylink) < 50503) {
 457                  $_SESSION['dbcharset'] = "utf8";
 458              }
 459          }
 460      }
 461  
 462      echo graf(
 463          span(null, array('class' => 'ui-icon ui-icon-check')).' '.
 464          setup_gTxt('using_db', array(
 465              '{dbname}' => strong(txpspecialchars($_SESSION['ddb'])), ), 'raw').' ('.$_SESSION['dbcharset'].')',
 466          array('class' => 'alert-block success')
 467      );
 468  
 469      echo setup_config_contents().
 470          n.'</div>';
 471  }
 472  
 473  /**
 474   * Renders either stage 3: admin user details panel (on success), or stage 2:
 475   * config details error message (on fail).
 476   */
 477  
 478  function getTxpLogin()
 479  {
 480      $GLOBALS['textarray'] = setup_load_lang($_SESSION['lang']);
 481  
 482      global $txpcfg, $step;
 483  
 484      $problems = array();
 485  
 486      echo preamble($step);
 487  
 488      if (!isset($txpcfg['db'])) {
 489          if (!is_readable(txpath.'/config.php')) {
 490              $problems[] = graf(
 491                  span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 492                  setup_gTxt('config_php_not_found', array(
 493                      '{file}' => txpspecialchars(txpath.'/config.php')
 494                  ), 'raw'),
 495                  array('class' => 'alert-block error')
 496              );
 497          } else {
 498              @include txpath.'/config.php';
 499          }
 500      }
 501  
 502      if (!isset($txpcfg) || ($txpcfg['db'] != $_SESSION['ddb']) || ($txpcfg['table_prefix'] != $_SESSION['dprefix'])) {
 503          $problems[] = graf(
 504              span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 505              setup_gTxt('config_php_does_not_match_input', '', 'raw'),
 506              array('class' => 'alert-block error')
 507          );
 508  
 509          echo txp_setup_progress_meter(2).
 510              n.'<div class="txp-setup">'.
 511              n.join(n, $problems).
 512              setup_config_contents().
 513              n.'</div>';
 514  
 515          exit;
 516      }
 517  
 518      // Default theme selector.
 519      $core_themes = array('hive', 'hiveneutral');
 520  
 521      $themes = \Textpattern\Admin\Theme::names();
 522  
 523      foreach ($themes as $t) {
 524          $theme = \Textpattern\Admin\Theme::factory($t);
 525  
 526          if ($theme) {
 527              $m = $theme->manifest();
 528              $title = empty($m['title']) ? ucwords($theme->name) : $m['title'];
 529              $vals[$t] = (in_array($t, $core_themes) ? setup_gTxt('core_theme', array('{theme}' => $title)) : $title);
 530              unset($theme);
 531          }
 532      }
 533  
 534      asort($vals, SORT_STRING);
 535  
 536      $theme_chooser = selectInput('theme', $vals, (isset($_SESSION['theme']) ? txpspecialchars($_SESSION['theme']) : 'hive'), '', '', 'setup_admin_theme');
 537  
 538      echo txp_setup_progress_meter(3).
 539          n.'<div class="txp-setup">'.
 540          n.'<form class="prefs-form" method="post" action="'.txpspecialchars($_SERVER['PHP_SELF']).'">'.
 541          hed(
 542              setup_gTxt('creating_db_tables'), 2
 543          ).
 544          graf(
 545              setup_gTxt('about_to_create')
 546          ).
 547          inputLabel(
 548              'setup_user_realname',
 549              fInput('text', 'RealName', (isset($_SESSION['realname']) ? $_SESSION['realname'] : ''), '', '', '', INPUT_REGULAR, '', 'setup_user_realname', '', true),
 550              'your_full_name', '', array('class' => 'txp-form-field')
 551          ).
 552          inputLabel(
 553              'setup_user_email',
 554              fInput('text', 'email', (isset($_SESSION['email']) ? $_SESSION['email'] : ''), '', '', '', INPUT_REGULAR, '', 'setup_user_email', '', true),
 555              'your_email', '', array('class' => 'txp-form-field')
 556          ).
 557          inputLabel(
 558              'setup_user_login',
 559              fInput('text', 'name', (isset($_SESSION['name']) ? $_SESSION['name'] : ''), '', '', '', INPUT_REGULAR, '', 'setup_user_login', '', true),
 560              'setup_login', 'setup_user_login', array('class' => 'txp-form-field')
 561          ).
 562          inputLabel(
 563              'setup_user_pass',
 564              fInput('password', 'pass', (isset($_SESSION['pass']) ? $_SESSION['pass'] : ''), 'txp-maskable txp-strength-hint', '', '', INPUT_REGULAR, '', 'setup_user_pass', '', true).
 565              n.tag(null, 'div', array('class' => 'strength-meter')).
 566              n.tag(
 567                  checkbox('unmask', 1, false, 0, 'show_password').
 568                  n.tag(gTxt('setup_show_password'), 'label', array('for' => 'show_password')),
 569                  'div', array('class' => 'show-password')),
 570              'choose_password', 'setup_user_pass', array('class' => 'txp-form-field')
 571          ).
 572          hed(
 573              setup_gTxt('site_config'), 2
 574          ).
 575          inputLabel(
 576              'setup_admin_theme',
 577              $theme_chooser,
 578              'admin_theme', 'theme_name', array('class' => 'txp-form-field')
 579          ).
 580          graf(
 581              fInput('submit', 'Submit', setup_gTxt('next_step'), 'publish')
 582          ).
 583          sInput('createTxp').
 584          n.'</form>'.
 585          n.'</div>';
 586  }
 587  
 588  /**
 589   * Re-renders stage 3: admin user details panel, due to user input errors.
 590   */
 591  
 592  function createTxp()
 593  {
 594      global $link, $step;
 595      $GLOBALS['textarray'] = setup_load_lang($_SESSION['lang']);
 596  
 597      echo preamble($step);
 598  
 599      $_SESSION['name'] = ps('name');
 600      $_SESSION['realname'] = ps('RealName');
 601      $_SESSION['pass'] = ps('pass');
 602      $_SESSION['email'] = ps('email');
 603      $_SESSION['theme'] = ps('theme');
 604  
 605      if ($_SESSION['name'] == '') {
 606          echo txp_setup_progress_meter(3).
 607              n.'<div class="txp-setup">'.
 608              graf(
 609                  span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 610                  setup_gTxt('name_required'),
 611                  array('class' => 'alert-block error')
 612              ).
 613              setup_back_button(__FUNCTION__).
 614              n.'</div>';
 615  
 616          exit;
 617      }
 618  
 619      if (!$_SESSION['pass']) {
 620          echo txp_setup_progress_meter(3).
 621              n.'<div class="txp-setup">'.
 622              graf(
 623                  span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 624                  setup_gTxt('pass_required'),
 625                  array('class' => 'alert-block error')
 626              ).
 627              setup_back_button(__FUNCTION__).
 628              n.'</div>';
 629  
 630          exit;
 631      }
 632  
 633      if (!is_valid_email($_SESSION['email'])) {
 634          echo txp_setup_progress_meter(3).
 635              n.'<div class="txp-setup">'.
 636              graf(
 637                  span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 638                  setup_gTxt('email_required'),
 639                  array('class' => 'alert-block error')
 640              ).
 641              setup_back_button(__FUNCTION__).
 642              n.'</div>';
 643  
 644          exit;
 645      }
 646  
 647      global $txpcfg;
 648  
 649      if (!isset($txpcfg['db'])) {
 650          if (!is_readable(txpath.'/config.php')) {
 651              $problems[] = graf(
 652                  span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 653                  setup_gTxt('config_php_not_found', array(
 654                      '{file}' => txpspecialchars(txpath.'/config.php')
 655                  ), 'raw'),
 656                  array('class' => 'alert-block error')
 657              );
 658          } else {
 659              @include txpath.'/config.php';
 660          }
 661      }
 662  
 663      if (!isset($txpcfg) || ($txpcfg['db'] != $_SESSION['ddb']) || ($txpcfg['table_prefix'] != $_SESSION['dprefix'])) {
 664          $problems[] = graf(
 665              span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 666              setup_gTxt('config_php_does_not_match_input', '', 'raw'),
 667              array('class' => 'alert-block error')
 668          );
 669  
 670          echo txp_setup_progress_meter(3).
 671              n.'<div class="txp-setup">'.
 672              n.join(n, $problems).
 673              n.setup_config_contents().
 674              n.'</div>';
 675  
 676          exit;
 677      }
 678  
 679      define('TXP_INSTALL', 1);
 680  
 681      include_once txpath.'/lib/txplib_update.php';
 682      include txpath.'/setup/txpsql.php';
 683  
 684      echo fbCreate();
 685  }
 686  
 687  /**
 688   * Populate a textarea with config.php file code.
 689   */
 690  
 691  function makeConfig()
 692  {
 693      define("nl", "';\n");
 694      define("o", '$txpcfg[\'');
 695      define("m", "'] = '");
 696      $open = chr(60).'?php';
 697      $close = '?'.chr(62);
 698  
 699      // Escape single quotes and backslashes in literal PHP strings.
 700      foreach ($_SESSION as $k => $v) {
 701          $_SESSION[$k] = addcslashes($_SESSION[$k], "'\\");
 702      }
 703  
 704      $_SESSION = doSpecial($_SESSION);
 705  
 706      return
 707      $open."\n"
 708      .o.'db'.m.$_SESSION['ddb'].nl
 709      .o.'user'.m.$_SESSION['duser'].nl
 710      .o.'pass'.m.$_SESSION['dpass'].nl
 711      .o.'host'.m.$_SESSION['dhost'].nl
 712      .($_SESSION['dclient_flags'] ? o.'client_flags'."'] = ".$_SESSION['dclient_flags'].";\n" : '')
 713      .o.'table_prefix'.m.$_SESSION['dprefix'].nl
 714      .o.'txpath'.m.txpath.nl
 715      .o.'dbcharset'.m.$_SESSION['dbcharset'].nl
 716      .$close;
 717  }
 718  
 719  /**
 720   * Renders stage 4: either installation completed panel (success) or
 721   * installation error message (fail).
 722   */
 723  
 724  function fbCreate()
 725  {
 726      echo txp_setup_progress_meter(4).
 727          n.'<div class="txp-setup">';
 728  
 729      if ($GLOBALS['txp_install_successful'] === false) {
 730          return graf(
 731                  span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 732                  setup_gTxt('config_php_not_found', array(
 733                      '{num}' => $GLOBALS['txp_err_count']
 734                  )),
 735                  array('class' => 'alert-block error')
 736              ).
 737              n.'<ol>'.
 738              $GLOBALS['txp_err_html'].
 739              n.'</ol>'.
 740              n.'</div>';
 741      } else {
 742          // Clear the session so no data is leaked.
 743          $_SESSION = array();
 744  
 745          $warnings = @find_temp_dir() ? '' : graf(
 746              span(null, array('class' => 'ui-icon ui-icon-alert')).' '.
 747              setup_gTxt('set_temp_dir_prefs'),
 748              array('class' => 'alert-block warning')
 749          );
 750  
 751          $login_url = $GLOBALS['rel_txpurl'].'/index.php';
 752  
 753          return hed(setup_gTxt('that_went_well'), 1).
 754              $warnings.
 755              graf(
 756                  setup_gTxt('you_can_access', array(
 757                      'index.php' => $login_url,
 758                  ))
 759              ).
 760              graf(
 761                  setup_gTxt('installation_postamble')
 762              ).
 763              hed(setup_gTxt('thanks_for_interest'), 3).
 764              graf(
 765                  href(setup_gTxt('go_to_login'), $login_url, ' class="navlink publish"')
 766              ).
 767              n.'</div>';
 768      }
 769  }
 770  
 771  // -------------------------------------------------------------
 772  
 773  function setup_config_contents()
 774  {
 775      return hed(setup_gTxt('creating_config'), 2).
 776          graf(
 777              strong(setup_gTxt('before_you_proceed')).' '.
 778              setup_gTxt('create_config', array('{txpath}' => basename(txpath)))
 779          ).
 780          n.'<textarea class="code" name="config" cols="'.INPUT_LARGE.'" rows="'.TEXTAREA_HEIGHT_REGULAR.'" dir="ltr" readonly>'.
 781              makeConfig().
 782          n.'</textarea>'.
 783          n.'<form method="post" action="'.txpspecialchars($_SERVER['PHP_SELF']).'">'.
 784              graf(fInput('submit', 'submit', setup_gTxt('did_it'), 'publish')).
 785              sInput('getTxpLogin').
 786          n.'</form>';
 787  }
 788  
 789  // -------------------------------------------------------------
 790  
 791  function setup_back_button($current = null)
 792  {
 793      $prevSteps = array(
 794          'getDbInfo'   => '',
 795          'getTxpLogin' => 'getDbInfo',
 796          'printConfig' => 'getDbInfo',
 797          'createTxp'   => 'getTxpLogin',
 798          'fbCreate'    => 'createTxp',
 799      );
 800  
 801      $prev = isset($prevSteps[$current]) ? $prevSteps[$current] : '';
 802  
 803      return graf(setup_gTxt('please_go_back')).
 804          n.'<form method="post" action="'.txpspecialchars($_SERVER['PHP_SELF']).'">'.
 805          sInput($prev).
 806          fInput('submit', 'submit', setup_gTxt('back'), 'navlink publish').
 807          n.'</form>';
 808  }
 809  
 810  // -------------------------------------------------------------
 811  
 812  function langs()
 813  {
 814      $langs = array(
 815          'ar-dz' => 'جزائري عربي',
 816          'bg-bg' => 'Български',
 817          'bs-ba' => 'Bosanski (Bosna i Hercegovina)',
 818          'ca-es' => 'Català',
 819          'cs-cz' => 'Čeština',
 820          'da-dk' => 'Dansk',
 821          'de-de' => 'Deutsch',
 822          'el-gr' => 'Ελληνικά',
 823          'en-gb' => 'English (Great Britain)',
 824          'en-us' => 'English (United States)',
 825          'es-es' => 'Español',
 826          'et-ee' => 'Eesti',
 827          'fa-ir' => 'Persian (پارسی)',
 828          'fi-fi' => 'Suomi',
 829          'fr-fr' => 'Français',
 830          'gl-gz' => 'Galego',
 831          'he-il' => 'עברית',
 832          'hr-hr' => 'Hrvatski',
 833          'hu-hu' => 'Magyar',
 834          'id-id' => 'Bahasa Indonesia',
 835          'is-is' => 'Íslenska',
 836          'it-it' => 'Italiano',
 837          'ja-jp' => '日本語',
 838          'ko-kr' => '한국말 (대한민국)',
 839          'lt-lt' => 'Lietuvių',
 840          'lv-lv' => 'Latviešu',
 841          'nl-nl' => 'Nederlands',
 842          'no-no' => 'Norsk',
 843          'pl-pl' => 'Polski',
 844          'pt-br' => 'Português (Brasil)',
 845          'pt-pt' => 'Português (Portugal)',
 846          'ro-ro' => 'Română',
 847          'ru-ru' => 'Русский',
 848          'sk-sk' => 'Slovenčina',
 849          'sp-rs' => 'Srpski',
 850          'sr-rs' => 'Српски',
 851          'sv-se' => 'Svenska',
 852          'th-th' => 'ไทย',
 853          'tr-tr' => 'Türkçe',
 854          'uk-ua' => 'Українська',
 855          'ur-in' => 'اردو (بھارت',
 856          'vi-vn' => 'Tiếng Việt (Việt Nam)',
 857          'zh-cn' => '中文(简体)',
 858          'zh-tw' => '中文(繁體)',
 859      );
 860  
 861      $default = (!empty($_SESSION['lang']) ? $_SESSION['lang'] : 'en-gb');
 862  
 863      $out = n.'<div class="txp-form-field">'.
 864          n.'<div class="txp-form-field-label">'.
 865          n.'<label for="setup_language">Please choose a language</label>'.
 866          n.'</div>'.
 867          n.'<div class="txp-form-field-value">'.
 868          n.'<select id="setup_language" name="lang">';
 869  
 870      foreach ($langs as $a => $b) {
 871          $out .= n.'<option value="'.txpspecialchars($a).'"'.
 872              (($a == $default) ? ' selected="selected"' : '').
 873              '>'.txpspecialchars($b).'</option>';
 874      }
 875  
 876      $out .= n.'</select>'.
 877          n.'</div>'.
 878          n.'</div>';
 879  
 880      return $out;
 881  }
 882  
 883  // -------------------------------------------------------------
 884  
 885  function setup_load_lang($lang)
 886  {
 887      global $en_gb_strings;
 888  
 889      require_once txpath.'/setup/setup-langs.php';
 890      $en_gb_strings = $langs['en-gb'];
 891      $lang = (isset($langs[$lang]) && !empty($langs[$lang])) ? $lang : 'en-gb';
 892      define('LANG', $lang);
 893  
 894      return $langs[LANG];
 895  }
 896  
 897  // -------------------------------------------------------------
 898  
 899  function setup_gTxt($var, $atts = array(), $escape = 'html')
 900  {
 901      global $en_gb_strings;
 902  
 903      // Try to translate the string in chosen native language.
 904      $xlate = gTxt($var, $atts, $escape);
 905  
 906      if (!is_array($atts)) {
 907          $atts = array();
 908      }
 909  
 910      if ($escape == 'html') {
 911          foreach ($atts as $key => $value) {
 912              $atts[$key] = txpspecialchars($value);
 913          }
 914      }
 915  
 916      $v = strtolower($var);
 917  
 918      // Find out if the translated string is the same as the $var input.
 919      if ($atts) {
 920          $compare = ($xlate == $v.': '.join(', ', $atts));
 921      } else {
 922          $compare = ($xlate == $v);
 923      }
 924  
 925      // No translation string available, so grab an English string we know exists
 926      // as fallback.
 927      if ($compare) {
 928          $xlate = strtr($en_gb_strings[$v], $atts);
 929      }
 930  
 931      return $xlate;
 932  }

title

Description

title

Description

title

Description

title

title

Body