eod; $step = ps('step'); switch ($step) { case "": chooseLang(); break; case "getDbInfo": getDbInfo(); break; case "getTxpLogin": getTxpLogin(); break; case "printConfig": printConfig(); break; case "createTxp": createTxp(); } ?>
', '', tr( tda( hed('Welcome to Textpattern',3). graf('Please choose a language:'). langs(). graf(fInput('submit','Submit','Submit','publish')). sInput('getDbInfo') ,' width="400" height="50" colspan="4" align="left"') ), '
'; } // ------------------------------------------------------------- function getDbInfo() { $GLOBALS['textarray'] = setup_load_lang(ps('lang')); @include txpath.'/config.php'; if (!empty($txpcfg['db'])) { exit(graf( gTxt('already_installed', array('{txpath}' => txpath)) )); } if (@$_SERVER['SCRIPT_NAME'] && (@$_SERVER['SERVER_NAME'] || @$_SERVER['HTTP_HOST'])) { $guess_siteurl = (@$_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']; $guess_siteurl .= $GLOBALS['rel_siteurl']; } else { $guess_siteurl = 'mysite.com'; } echo '
', '', tr( tda( hed(gTxt('welcome_to_textpattern'),3). graf(gTxt('need_details'),' style="margin-bottom:3em"'). hed('MySQL',3). graf(gTxt('db_must_exist')) ,' width="400" height="50" colspan="4" align="left"') ), tr( fLabelCell(gTxt('mysql_login')).fInputCell('duser','',1). fLabelCell(gTxt('mysql_password')).fInputCell('dpass','',2) ), tr( fLabelCell(gTxt('mysql_server')).fInputCell('dhost','localhost',3). fLabelCell(gTxt('mysql_database')).fInputCell('ddb','',4) ), tr( fLabelCell(gTxt('table_prefix')).fInputCell('dprefix','',5). tdcs(small(gTxt('prefix_warning')),2) ), tr(tdcs(' ',4)), tr( tdcs( hed(gTxt('site_url'),3). graf(gTxt('please_enter_url')),4) ), tr( fLabelCell('http://'). tdcs(fInput('text','siteurl',$guess_siteurl,'edit','','',40). popHelp('siteurl'),3) ); if (is_disabled('mail')) { echo tr( tdcs(gTxt('warn_mail_unavailable'),3,null,'" style="color:red;text-align:center') ); } echo tr( td().td(fInput('submit','Submit',gTxt('next'),'publish')).td().td() ); echo endTable(), hInput('lang', LANG), sInput('printConfig'), ''; } // ------------------------------------------------------------- function printConfig() { $carry = psa(array('ddb','duser','dpass','dhost','dprefix','siteurl','lang')); extract($carry); $GLOBALS['textarray'] = setup_load_lang($lang); @include txpath.'/config.php'; if (!empty($txpcfg['db'])) { exit(graf( gTxt('already_installed', array( '{txpath}' => txpath )) )); } // FIXME, remove when all languages are updated with this string if (!isset($GLOBALS['textarray']['prefix_bad_characters'])) $GLOBALS['textarray']['prefix_bad_characters'] = 'The Table prefix {dbprefix} contains characters that are not allowed.
'. 'The first character must match one of a-zA-Z_ and all following characters must match one of a-zA-Z0-9_'; echo graf(gTxt("checking_database")); if (($mylink = mysql_connect($dhost, $duser, $dpass))) $carry['dclient_flags'] = 0; elseif (($mylink = mysql_connect($dhost, $duser, $dpass, false, MYSQL_CLIENT_SSL))) $carry['dclient_flags'] = 'MYSQL_CLIENT_SSL'; else exit(graf(gTxt('db_cant_connect'))); echo graf(gTxt('db_connected')); if (! ($dprefix == '' || preg_match('#^[a-zA-Z_][a-zA-Z0-9_]*$#', $dprefix)) ) { exit(graf( gTxt('prefix_bad_characters', array( '{dbprefix}' => strong($dprefix) )) )); } if (!$mydb = mysql_select_db($ddb)) { exit(graf( gTxt('db_doesnt_exist', array( '{dbname}' => strong($ddb) )) )); } // On 4.1 or greater use utf8-tables $version = mysql_get_server_info(); if ( intval($version[0]) >= 5 || preg_match('#^4\.[1-9]#',$version)) { if (mysql_query("SET NAMES utf8")) { $carry['dbcharset'] = "utf8"; } else { $carry['dbcharset'] = "latin1"; } } else { $carry['dbcharset'] = "latin1"; } echo graf( gTxt('using_db', array('{dbname}' => strong($ddb))) .' ('. $carry['dbcharset'] .')' ), graf( strong(gTxt('before_you_proceed')).', '.gTxt('create_config', array('{txpath}' => txpath)) ), '', '', fInput('submit','submit',gTxt('did_it'),'smallbox'), sInput('getTxpLogin'),hInput('carry',postEncode($carry)), ''; } // ------------------------------------------------------------- function getTxpLogin() { $carry = postDecode(ps('carry')); extract($carry); $GLOBALS['textarray'] = setup_load_lang($lang); @include txpath.'/config.php'; if (!isset($txpcfg) || ($txpcfg['db'] != $ddb) || ($txpcfg['table_prefix'] != $dprefix)) { echo graf( strong(gTxt('before_you_proceed')).', '. gTxt('create_config', array( '{txpath}' => txpath )) ), '', '', fInput('submit','submit',gTxt('did_it'),'smallbox'), sInput('getTxpLogin'),hInput('carry',postEncode($carry)), ''; return; } echo '', startTable('edit'), tr( tda( graf(gTxt('thanks')). graf(gTxt('about_to_create')) ,' width="400" colspan="2" align="center"') ), tr( fLabelCell(gTxt('your_full_name')).fInputCell('RealName') ), tr( fLabelCell(gTxt('setup_login')).fInputCell('name') ), tr( fLabelCell(gTxt('choose_password')).fInputCell('pass') ), tr( fLabelCell(gTxt('your_email')).fInputCell('email') ), tr( td().td(fInput('submit','Submit',gTxt('next'),'publish')) ), endTable(), sInput('createTxp'), hInput('lang', htmlspecialchars($lang)), hInput('siteurl', htmlspecialchars($siteurl)), ''; } // ------------------------------------------------------------- function createTxp() { $GLOBALS['textarray'] = setup_load_lang(ps('lang')); if (!is_valid_email(ps('email'))) { exit(graf(gTxt('email_required'))); } require txpath.'/config.php'; $ddb = $txpcfg['db']; $duser = $txpcfg['user']; $dpass = $txpcfg['pass']; $dhost = $txpcfg['host']; $dclient_flags = isset($txpcfg['client_flags']) ? $txpcfg['client_flags'] : 0; $dprefix = $txpcfg['table_prefix']; $dbcharset = $txpcfg['dbcharset']; $siteurl = str_replace("http://",'', ps('siteurl')); $siteurl = rtrim($siteurl,"/"); $urlpath = preg_replace('#^[^/]+#', '', $siteurl); define("PFX",trim($dprefix)); define('TXP_INSTALL', 1); include_once txpath.'/lib/txplib_update.php'; include txpath.'/setup/txpsql.php'; // This has to come after txpsql.php, because otherwise we can't call mysql_real_escape_string extract(doSlash(psa(array('name','pass','RealName','email')))); $nonce = md5( uniqid( rand(), true ) ); mysql_query("INSERT INTO `".PFX."txp_users` VALUES (1,'$name',password(lower('$pass')),'$RealName','$email',1,now(),'$nonce')"); mysql_query("update `".PFX."txp_prefs` set val = '".doSlash($siteurl)."' where `name`='siteurl'"); mysql_query("update `".PFX."txp_prefs` set val = '".LANG."' where `name`='language'"); mysql_query("update `".PFX."txp_prefs` set val = '".getlocale(LANG)."' where `name`='locale'"); mysql_query("update `".PFX."textpattern` set Body = replace(Body, 'siteurl', '".doSlash($urlpath)."'), Body_html = replace(Body_html, 'siteurl', '".doSlash($urlpath)."') WHERE ID = 1"); echo fbCreate(); } // ------------------------------------------------------------- function makeConfig($ar) { define("nl","';\n"); define("o",'$txpcfg[\''); define("m","'] = '"); $open = chr(60).'?php'; $close = '?'.chr(62); extract($ar); return $open."\n" .o.'db' .m.$ddb.nl .o.'user' .m.$duser.nl .o.'pass' .m.$dpass.nl .o.'host' .m.$dhost.nl .($dclient_flags ? o.'client_flags'."'] = ".$dclient_flags.";\n" : '') .o.'table_prefix' .m.$dprefix.nl .o.'txpath' .m.txpath.nl // remove in crockery .o.'dbcharset' .m.$dbcharset.nl .$close; } // ------------------------------------------------------------- function fbCreate() { if ($GLOBALS['txp_install_successful'] === false) { return '
'. graf( gTxt('errors_during_install', array( '{num}' => $GLOBALS['txp_err_count'] )) ,' style="margin-top: 3em;"'). '
'; } else { $warnings = @find_temp_dir() ? '' : graf(gTxt('set_temp_dir_prefs')); return '
'. graf( gTxt('that_went_well') ,' style="margin-top:3em"'). $warnings. graf( gTxt('you_can_access', array( 'index.php' => $GLOBALS['rel_siteurl'].'/textpattern/index.php', )) ). graf(gTxt('thanks_for_interest')). '
'; } } // ------------------------------------------------------------- function postEncode($thing) { return base64_encode(serialize($thing)); } // ------------------------------------------------------------- function postDecode($thing) { return unserialize(base64_decode($thing)); } // ------------------------------------------------------------- function langs() { $langs = array( 'ar-dz' => 'جزائري عربي', 'bg-bg' => 'Български', 'bs-ba' => 'Bosanski (Bosna i Hercegovina)', 'ca-es' => 'Català', 'cs-cz' => 'Čeština', 'da-dk' => 'Dansk', 'de-de' => 'Deutsch', 'el-gr' => 'Ελληνικά', 'en-gb' => 'English (Great Britain)', 'en-us' => 'English (United States)', 'es-es' => 'Español', 'et-ee' => 'Eesti', 'fi-fi' => 'Suomi', 'fr-fr' => 'Français', 'gl-gz' => 'Galego', 'he-il' => 'עברית', 'hr-hr' => 'Hrvatski', 'hu-hu' => 'Magyar', 'id-id' => 'Bahasa Indonesia', 'is-is' => 'Íslenska', 'it-it' => 'Italiano', 'ja-jp' => '日本語', 'ko-kr' => '한국말 (대한민국)', 'lv-lv' => 'Latviešu', 'nl-nl' => 'Nederlands', 'no-no' => 'Norsk', 'pl-pl' => 'Polski', 'pt-br' => 'Português (Brasil)', 'pt-pt' => 'Português (Portugal)', 'ro-ro' => 'Română', 'ru-ru' => 'Русский', 'sk-sk' => 'Slovenčina', 'sp-rs' => 'Srpski', 'sr-rs' => 'Српски', 'sv-se' => 'Svenska', 'th-th' => 'ไทย', 'tr-tr' => 'Türkçe', 'uk-ua' => 'Українська', 'vi-vn' => 'Tiếng Việt (Việt Nam)', 'zh-cn' => '中文(简体)', 'zh-tw' => '中文(繁體)', ); $default = 'en-gb'; $out = n.''; return $out; } // ------------------------------------------------------------- function setup_load_lang($lang) { require_once txpath.'/setup/setup-langs.php'; $lang = (isset($langs[$lang]) && !empty($langs[$lang]))? $lang : 'en-gb'; define('LANG', $lang); return $langs[LANG]; } ?>