[ Index ]

PHP Cross Reference of Textpattern 4.0.8

title

Body

[close]

/textpattern/setup/ -> index.php (source)

   1  <?php
   2  /*
   3      This is Textpattern
   4  
   5      Copyright 2005 by Dean Allen
   6      www.textpattern.com
   7      All rights reserved
   8  
   9      Use of this software indicates acceptance of the Textpattern license agreement.
  10  
  11  $HeadURL: https://textpattern.googlecode.com/svn/releases/4.0.8/source/textpattern/setup/index.php $
  12  $LastChangedRevision: 3065 $
  13  
  14  */
  15  
  16  if (!defined('txpath'))
  17  {
  18      define("txpath", dirname(dirname(__FILE__)));
  19      define("txpinterface", "admin");
  20  }
  21  error_reporting(E_ALL);
  22  @ini_set("display_errors","1");
  23  
  24  include_once txpath.'/lib/constants.php';
  25  include_once txpath.'/lib/txplib_html.php';
  26  include_once txpath.'/lib/txplib_forms.php';
  27  include_once txpath.'/lib/txplib_misc.php';
  28  
  29  header("Content-type: text/html; charset=utf-8");
  30  
  31  $rel_siteurl = preg_replace('#^(.*)/textpattern.*$#i','\\1',$_SERVER['PHP_SELF']);
  32  print <<<eod
  33  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  34              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  35      <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  36      <head>
  37      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  38      <title>Textpattern &#8250; setup</title>
  39      <link rel="stylesheet" href="$rel_siteurl/textpattern/textpattern.css" type="text/css" />
  40      </head>
  41      <body style="border-top:15px solid #FC3">
  42      <div align="center">
  43  eod;
  44  
  45      $step = ps('step');
  46      switch ($step) {
  47          case "": chooseLang(); break;
  48          case "getDbInfo": getDbInfo(); break;
  49          case "getTxpLogin": getTxpLogin(); break;
  50          case "printConfig": printConfig(); break;
  51          case "createTxp": createTxp();
  52      }
  53  ?>
  54  </div>
  55  </body>
  56  </html>
  57  <?php
  58  
  59  // -------------------------------------------------------------
  60  	function chooseLang()
  61      {
  62        echo '<form action="'.$GLOBALS['rel_siteurl'].'/textpattern/setup/index.php" method="post">',
  63            '<table id="setup" cellpadding="0" cellspacing="0" border="0">',
  64          tr(
  65              tda(
  66                  hed('Welcome to Textpattern',3).
  67                  graf('Please choose a language:').
  68                  langs().
  69                  graf(fInput('submit','Submit','Submit','publish')).
  70                  sInput('getDbInfo')
  71              ,' width="400" height="50" colspan="4" align="left"')
  72          ),
  73          '</table></form>';
  74      }
  75  
  76  // -------------------------------------------------------------
  77  	function getDbInfo()
  78      {
  79          $GLOBALS['textarray'] = setup_load_lang(ps('lang'));
  80  
  81          @include txpath.'/config.php';
  82  
  83          if (!empty($txpcfg['db']))
  84          {
  85              exit(graf(
  86                  gTxt('already_installed', array('{txpath}' => txpath))
  87              ));
  88          }
  89  
  90          if (@$_SERVER['SCRIPT_NAME'] && (@$_SERVER['SERVER_NAME'] || @$_SERVER['HTTP_HOST']))
  91          {
  92              $guess_siteurl = (@$_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
  93              $guess_siteurl .= $GLOBALS['rel_siteurl'];
  94          }
  95          else
  96          {
  97              $guess_siteurl = 'mysite.com';
  98          }
  99  
 100          echo '<form action="'.$GLOBALS['rel_siteurl'].'/textpattern/setup/index.php" method="post">',
 101              '<table id="setup" cellpadding="0" cellspacing="0" border="0">',
 102          tr(
 103              tda(
 104                hed(gTxt('welcome_to_textpattern'),3).
 105                graf(gTxt('need_details'),' style="margin-bottom:3em"').
 106                hed('MySQL',3).
 107                graf(gTxt('db_must_exist'))
 108              ,' width="400" height="50" colspan="4" align="left"')
 109          ),
 110          tr(
 111              fLabelCell(gTxt('mysql_login')).fInputCell('duser','',1).
 112              fLabelCell(gTxt('mysql_password')).fInputCell('dpass','',2)
 113          ),
 114          tr(
 115              fLabelCell(gTxt('mysql_server')).fInputCell('dhost','localhost',3).
 116              fLabelCell(gTxt('mysql_database')).fInputCell('ddb','',4)
 117          ),
 118          tr(
 119              fLabelCell(gTxt('table_prefix')).fInputCell('dprefix','',5).
 120              tdcs(small(gTxt('prefix_warning')),2)
 121          ),
 122          tr(tdcs('&nbsp;',4)),
 123          tr(
 124              tdcs(
 125                  hed(gTxt('site_url'),3).
 126                  graf(gTxt('please_enter_url')),4)
 127          ),
 128          tr(
 129              fLabelCell('http://').
 130                  tdcs(fInput('text','siteurl',$guess_siteurl,'edit','','',40).
 131                  popHelp('siteurl'),3)
 132          );
 133  
 134          if (is_disabled('mail'))
 135          {
 136              echo tr(
 137                  tdcs(gTxt('warn_mail_unavailable'),3,null,'" style="color:red;text-align:center')
 138              );
 139          }
 140  
 141          echo tr(
 142              td().td(fInput('submit','Submit',gTxt('next'),'publish')).td().td()
 143          );
 144          echo endTable(),
 145          hInput('lang', LANG),
 146          sInput('printConfig'),
 147          '</form>';
 148      }
 149  
 150  // -------------------------------------------------------------
 151  	function printConfig()
 152      {
 153          $carry = psa(array('ddb','duser','dpass','dhost','dprefix','siteurl','lang'));
 154          extract($carry);
 155  
 156          $GLOBALS['textarray'] = setup_load_lang($lang);
 157  
 158          @include txpath.'/config.php';
 159  
 160          if (!empty($txpcfg['db']))
 161          {
 162              exit(graf(
 163                  gTxt('already_installed', array(
 164                      '{txpath}' => txpath
 165                  ))
 166              ));
 167          }
 168  
 169          // FIXME, remove when all languages are updated with this string
 170          if (!isset($GLOBALS['textarray']['prefix_bad_characters']))
 171              $GLOBALS['textarray']['prefix_bad_characters'] =
 172                  'The Table prefix {dbprefix} contains characters that are not allowed.<br />'.
 173                  'The first character must match one of <b>a-zA-Z_</b> and all following
 174                   characters must match one of <b>a-zA-Z0-9_</b>';
 175  
 176          echo graf(gTxt("checking_database"));
 177  
 178          if (($mylink = mysql_connect($dhost, $duser, $dpass)))
 179               $carry['dclient_flags'] = 0;
 180          elseif (($mylink = mysql_connect($dhost, $duser, $dpass, false, MYSQL_CLIENT_SSL)))
 181               $carry['dclient_flags'] = 'MYSQL_CLIENT_SSL';
 182          else
 183              exit(graf(gTxt('db_cant_connect')));
 184  
 185          echo graf(gTxt('db_connected'));
 186  
 187          if (! ($dprefix == '' || preg_match('#^[a-zA-Z_][a-zA-Z0-9_]*$#', $dprefix)) )
 188          {
 189              exit(graf(
 190                  gTxt('prefix_bad_characters', array(
 191                      '{dbprefix}' => strong($dprefix)
 192                  ))
 193              ));
 194          }
 195  
 196          if (!$mydb = mysql_select_db($ddb))
 197          {
 198              exit(graf(
 199                  gTxt('db_doesnt_exist', array(
 200                      '{dbname}' => strong($ddb)
 201                  ))
 202              ));
 203          }
 204  
 205          // On 4.1 or greater use utf8-tables
 206          $version = mysql_get_server_info();
 207  
 208          if ( intval($version[0]) >= 5 || preg_match('#^4\.[1-9]#',$version))
 209          {
 210              if (mysql_query("SET NAMES utf8"))
 211              {
 212                  $carry['dbcharset'] = "utf8";
 213              }
 214              else
 215              {
 216                  $carry['dbcharset'] = "latin1";
 217              }
 218          }
 219          else
 220          {
 221              $carry['dbcharset'] = "latin1";
 222          }
 223  
 224          echo graf(
 225              gTxt('using_db', array('{dbname}' => strong($ddb)))
 226              .' ('. $carry['dbcharset'] .')'
 227          ),
 228          graf(
 229              strong(gTxt('before_you_proceed')).', '.gTxt('create_config', array('{txpath}' => txpath))
 230          ),
 231  
 232          '<textarea name="config" cols="40" rows="5" style="width: 400px; height: 200px">',
 233          makeConfig($carry),
 234          '</textarea>',
 235          '<form action="'.$GLOBALS['rel_siteurl'].'/textpattern/setup/index.php" method="post">',
 236          fInput('submit','submit',gTxt('did_it'),'smallbox'),
 237          sInput('getTxpLogin'),hInput('carry',postEncode($carry)),
 238          '</form>';
 239      }
 240  
 241  // -------------------------------------------------------------
 242  	function getTxpLogin()
 243      {
 244          $carry = postDecode(ps('carry'));
 245          extract($carry);
 246  
 247          $GLOBALS['textarray'] = setup_load_lang($lang);
 248  
 249          @include txpath.'/config.php';
 250  
 251          if (!isset($txpcfg) || ($txpcfg['db'] != $ddb) || ($txpcfg['table_prefix'] != $dprefix))
 252          {
 253              echo graf(
 254                  strong(gTxt('before_you_proceed')).', '.
 255                  gTxt('create_config', array(
 256                      '{txpath}' => txpath
 257                  ))
 258              ),
 259  
 260              '<textarea style="width:400px;height:200px" name="config" rows="1" cols="1">',
 261              makeConfig($carry),
 262              '</textarea>',
 263              '<form action="'.$GLOBALS['rel_siteurl'].'/textpattern/setup/index.php" method="post">',
 264              fInput('submit','submit',gTxt('did_it'),'smallbox'),
 265              sInput('getTxpLogin'),hInput('carry',postEncode($carry)),
 266              '</form>';
 267              return;
 268          }
 269  
 270          echo '<form action="'.$GLOBALS['rel_siteurl'].'/textpattern/setup/index.php" method="post">',
 271            startTable('edit'),
 272          tr(
 273              tda(
 274                  graf(gTxt('thanks')).
 275                  graf(gTxt('about_to_create'))
 276              ,' width="400" colspan="2" align="center"')
 277          ),
 278          tr(
 279              fLabelCell(gTxt('your_full_name')).fInputCell('RealName')
 280          ),
 281          tr(
 282              fLabelCell(gTxt('setup_login')).fInputCell('name')
 283          ),
 284          tr(
 285              fLabelCell(gTxt('choose_password')).fInputCell('pass')
 286          ),
 287          tr(
 288              fLabelCell(gTxt('your_email')).fInputCell('email')
 289          ),
 290          tr(
 291              td().td(fInput('submit','Submit',gTxt('next'),'publish'))
 292          ),
 293          endTable(),
 294          sInput('createTxp'),
 295          hInput('lang', htmlspecialchars($lang)),
 296          hInput('siteurl', htmlspecialchars($siteurl)),
 297          '</form>';
 298      }
 299  
 300  // -------------------------------------------------------------
 301  	function createTxp()
 302      {
 303          $GLOBALS['textarray'] = setup_load_lang(ps('lang'));
 304  
 305          if (!is_valid_email(ps('email')))
 306          {
 307              exit(graf(gTxt('email_required')));
 308          }
 309  
 310          require txpath.'/config.php';
 311          $ddb = $txpcfg['db'];
 312          $duser = $txpcfg['user'];
 313          $dpass = $txpcfg['pass'];
 314          $dhost = $txpcfg['host'];
 315          $dclient_flags = isset($txpcfg['client_flags']) ? $txpcfg['client_flags'] : 0;
 316          $dprefix = $txpcfg['table_prefix'];
 317          $dbcharset = $txpcfg['dbcharset'];
 318  
 319          $siteurl = str_replace("http://",'', ps('siteurl'));
 320          $siteurl = rtrim($siteurl,"/");
 321          $urlpath = preg_replace('#^[^/]+#', '', $siteurl);
 322  
 323          define("PFX",trim($dprefix));
 324          define('TXP_INSTALL', 1);
 325  
 326          include_once txpath.'/lib/txplib_update.php';
 327           include txpath.'/setup/txpsql.php';
 328  
 329          // This has to come after txpsql.php, because otherwise we can't call mysql_real_escape_string
 330          extract(doSlash(psa(array('name','pass','RealName','email'))));
 331  
 332           $nonce = md5( uniqid( rand(), true ) );
 333  
 334          mysql_query("INSERT INTO `".PFX."txp_users` VALUES
 335              (1,'$name',password(lower('$pass')),'$RealName','$email',1,now(),'$nonce')");
 336  
 337          mysql_query("update `".PFX."txp_prefs` set val = '".doSlash($siteurl)."' where `name`='siteurl'");
 338          mysql_query("update `".PFX."txp_prefs` set val = '".LANG."' where `name`='language'");
 339          mysql_query("update `".PFX."txp_prefs` set val = '".getlocale(LANG)."' where `name`='locale'");
 340          mysql_query("update `".PFX."textpattern` set Body = replace(Body, 'siteurl', '".doSlash($urlpath)."'), Body_html = replace(Body_html, 'siteurl', '".doSlash($urlpath)."') WHERE ID = 1");
 341  
 342           echo fbCreate();
 343      }
 344  
 345  // -------------------------------------------------------------
 346  	function makeConfig($ar)
 347      {
 348          define("nl","';\n");
 349          define("o",'$txpcfg[\'');
 350          define("m","'] = '");
 351          $open = chr(60).'?php';
 352          $close = '?'.chr(62);
 353          extract($ar);
 354          return
 355          $open."\n"
 356          .o.'db'           .m.$ddb.nl
 357          .o.'user'         .m.$duser.nl
 358          .o.'pass'         .m.$dpass.nl
 359          .o.'host'         .m.$dhost.nl
 360          .($dclient_flags ? o.'client_flags'."'] = ".$dclient_flags.";\n" : '')
 361          .o.'table_prefix' .m.$dprefix.nl
 362          .o.'txpath'       .m.txpath.nl   // remove in crockery
 363          .o.'dbcharset'    .m.$dbcharset.nl
 364          .$close;
 365      }
 366  
 367  // -------------------------------------------------------------
 368  	function fbCreate()
 369      {
 370          if ($GLOBALS['txp_install_successful'] === false)
 371          {
 372              return '<div width="450" valign="top" style="margin-right: auto; margin-left: auto;">'.
 373                  graf(
 374                      gTxt('errors_during_install', array(
 375                          '{num}' => $GLOBALS['txp_err_count']
 376                      ))
 377                  ,' style="margin-top: 3em;"').
 378                  '</div>';
 379          }
 380  
 381          else
 382          {
 383              $warnings = @find_temp_dir() ? '' : graf(gTxt('set_temp_dir_prefs'));
 384  
 385              return '<div width="450" valign="top" style="margin-right: auto; margin-left: auto;">'.
 386  
 387              graf(
 388                  gTxt('that_went_well')
 389              ,' style="margin-top:3em"').
 390  
 391              $warnings.
 392  
 393              graf(
 394                  gTxt('you_can_access', array(
 395                      'index.php' => $GLOBALS['rel_siteurl'].'/textpattern/index.php',
 396                  ))
 397              ).
 398  
 399              graf(gTxt('thanks_for_interest')).
 400  
 401              '</div>';
 402          }
 403      }
 404  
 405  // -------------------------------------------------------------
 406  	function postEncode($thing)
 407      {
 408          return base64_encode(serialize($thing));
 409      }
 410  
 411  // -------------------------------------------------------------
 412  	function postDecode($thing)
 413      {
 414          return unserialize(base64_decode($thing));
 415      }
 416  
 417  // -------------------------------------------------------------
 418  	function langs()
 419      {
 420          $langs = array(
 421              'ar-dz' => 'جزائري عربي',
 422              'bg-bg' => 'Български',
 423              'bs-ba' => 'Bosanski (Bosna i Hercegovina)',
 424              'ca-es' => 'Català',
 425              'cs-cz' => 'Čeština',
 426              'da-dk' => 'Dansk',
 427              'de-de' => 'Deutsch',
 428              'el-gr' => 'Ελληνικά',
 429              'en-gb' => 'English (Great Britain)',
 430              'en-us' => 'English (United States)',
 431              'es-es' => 'Español',
 432              'et-ee' => 'Eesti',
 433              'fi-fi' => 'Suomi',
 434              'fr-fr' => 'Français',
 435              'gl-gz' => 'Galego',
 436              'he-il' => 'עברית',
 437              'hr-hr' => 'Hrvatski',
 438              'hu-hu' => 'Magyar',
 439              'id-id' => 'Bahasa Indonesia',
 440              'is-is' => 'Íslenska',
 441              'it-it' => 'Italiano',
 442              'ja-jp' => '日本語',
 443              'ko-kr' => '한국말 (대한민국)',
 444              'lv-lv' => 'Latviešu',
 445              'nl-nl' => 'Nederlands',
 446              'no-no' => 'Norsk',
 447              'pl-pl' => 'Polski',
 448              'pt-br' => 'Português (Brasil)',
 449              'pt-pt' => 'Português (Portugal)',
 450              'ro-ro' => 'Română',
 451              'ru-ru' => 'Русский',
 452              'sk-sk' => 'Slovenčina',
 453              'sp-rs' => 'Srpski',
 454              'sr-rs' => 'Српски',
 455              'sv-se' => 'Svenska',
 456              'th-th' => 'ไทย',
 457              'tr-tr' => 'Türkçe',
 458              'uk-ua' => 'Українська',
 459              'vi-vn' => 'Tiếng Việt (Việt Nam)',
 460              'zh-cn' => '中文(简体)',
 461              'zh-tw' => '中文(繁體)',
 462          );
 463  
 464          $default = 'en-gb';
 465  
 466          $out = n.'<select name="lang">';
 467  
 468          foreach ($langs as $a => $b)
 469          {
 470              $out .= n.t.'<option value="'.$a.'"'.
 471                  ( ($a == $default) ? ' selected="selected"' : '').
 472                  '>'.$b.'</option>';
 473          }
 474  
 475          $out .= n.'</select>';
 476  
 477          return $out;
 478      }
 479  
 480  // -------------------------------------------------------------
 481  	function setup_load_lang($lang)
 482      {
 483          require_once txpath.'/setup/setup-langs.php';
 484          $lang = (isset($langs[$lang]) && !empty($langs[$lang]))? $lang : 'en-gb';
 485          define('LANG', $lang);
 486          return $langs[LANG];
 487      }
 488  
 489  ?>


Generated: Thu May 21 23:03:01 2009 Cross-referenced by PHPXref 0.7