install/install.php
changeset 1227 bdac73ed481e
parent 1081 745200a9cc2a
equal deleted inserted replaced
1226:de56132c008d 1227:bdac73ed481e
    17 
    17 
    18 define('IN_ENANO', 1);
    18 define('IN_ENANO', 1);
    19 // DEFINE THIS BEFORE RELEASE!
    19 // DEFINE THIS BEFORE RELEASE!
    20 $dangerous = true;
    20 $dangerous = true;
    21 if ( !empty($_GET['do']) )
    21 if ( !empty($_GET['do']) )
    22   if ( $_GET['do'] === 'lang_js' )
    22 	if ( $_GET['do'] === 'lang_js' )
    23     $dangerous = false;
    23 		$dangerous = false;
    24 if ( $dangerous )
    24 if ( $dangerous )
    25   define('ENANO_DANGEROUS', 1);
    25 	define('ENANO_DANGEROUS', 1);
    26 
    26 
    27 require_once('includes/common.php');
    27 require_once('includes/common.php');
    28 @ini_set('display_errors', 'on');
    28 @ini_set('display_errors', 'on');
    29 
    29 
    30 $stages = array('language', 'license', 'sysreqs', 'database', 'website', 'login', 'confirm', 'install', 'finish');
    30 $stages = array('language', 'license', 'sysreqs', 'database', 'website', 'login', 'confirm', 'install', 'finish');
    31 $stage_ids = array();
    31 $stage_ids = array();
    32 
    32 
    33 if ( isset($_POST['language']) )
    33 if ( isset($_POST['language']) )
    34 {
    34 {
    35   // Include language lib and additional PHP5-only JSON functions
    35 	// Include language lib and additional PHP5-only JSON functions
    36   require_once( ENANO_ROOT . '/includes/json2.php' );
    36 	require_once( ENANO_ROOT . '/includes/json2.php' );
    37   require_once( ENANO_ROOT . '/includes/lang.php' );
    37 	require_once( ENANO_ROOT . '/includes/lang.php' );
    38   
    38 	
    39   // We have a language ID - init language
    39 	// We have a language ID - init language
    40   $lang_id = $_POST['language'];
    40 	$lang_id = $_POST['language'];
    41   if ( !isset($languages[$lang_id]) )
    41 	if ( !isset($languages[$lang_id]) )
    42   {
    42 	{
    43     die('Invalid language selection - can\'t load metadata');
    43 		die('Invalid language selection - can\'t load metadata');
    44   }
    44 	}
    45   
    45 	
    46   $language_dir = $languages[$lang_id]['dir'];
    46 	$language_dir = $languages[$lang_id]['dir'];
    47   
    47 	
    48   // Initialize language support
    48 	// Initialize language support
    49   $lang = new Language($lang_id);
    49 	$lang = new Language($lang_id);
    50   $lang->load_file(ENANO_ROOT . '/language/' . $language_dir . '/install.json');
    50 	$lang->load_file(ENANO_ROOT . '/language/' . $language_dir . '/install.json');
    51   $lang_uri = 'install.php?do=lang_js&language=%s';
    51 	$lang_uri = 'install.php?do=lang_js&language=%s';
    52   
    52 	
    53   // Init UI
    53 	// Init UI
    54   $ui = new Enano_Installer_UI($lang->get('meta_site_name'), false);
    54 	$ui = new Enano_Installer_UI($lang->get('meta_site_name'), false);
    55   
    55 	
    56   // Add stages
    56 	// Add stages
    57   foreach ( $stages as $stage )
    57 	foreach ( $stages as $stage )
    58   {
    58 	{
    59     $stage_ids[$stage] = $ui->add_stage($lang->get("{$stage}_modetitle"), true);
    59 		$stage_ids[$stage] = $ui->add_stage($lang->get("{$stage}_modetitle"), true);
    60   }
    60 	}
    61   
    61 	
    62   // Determine stage
    62 	// Determine stage
    63   if ( isset($_REQUEST['stage']) && isset($stage_ids[$_REQUEST['stage']]) )
    63 	if ( isset($_REQUEST['stage']) && isset($stage_ids[$_REQUEST['stage']]) )
    64   {
    64 	{
    65     $ui->set_visible_stage($stage_ids[$_REQUEST['stage']]);
    65 		$ui->set_visible_stage($stage_ids[$_REQUEST['stage']]);
    66     $stage = $_REQUEST['stage'];
    66 		$stage = $_REQUEST['stage'];
    67   }
    67 	}
    68   else
    68 	else
    69   {
    69 	{
    70     $stage = 'license';
    70 		$stage = 'license';
    71   }
    71 	}
    72   
    72 	
    73   $stage_num = array_search($stage, $stages);
    73 	$stage_num = array_search($stage, $stages);
    74   if ( $stage_num )
    74 	if ( $stage_num )
    75   {
    75 	{
    76     $stage_num++;
    76 		$stage_num++;
    77     $ui->step = $lang->get('meta_step', array('step' => $stage_num, 'title' => $lang->get("{$stage}_modetitle_long")));
    77 		$ui->step = $lang->get('meta_step', array('step' => $stage_num, 'title' => $lang->get("{$stage}_modetitle_long")));
    78   }
    78 	}
    79 }
    79 }
    80 else
    80 else
    81 {
    81 {
    82   $ui = new Enano_Installer_UI('Enano installation', false);
    82 	$ui = new Enano_Installer_UI('Enano installation', false);
    83   
    83 	
    84   if ( version_compare(PHP_VERSION, '5.0.0', '<') )
    84 	if ( version_compare(PHP_VERSION, '5.0.0', '<') )
    85   {
    85 	{
    86     $ui->__construct('Enano installation', false);
    86 		$ui->__construct('Enano installation', false);
    87   }
    87 	}
    88   
    88 	
    89   $ui->step = 'Step 1: Choose language';
    89 	$ui->step = 'Step 1: Choose language';
    90   
    90 	
    91   $stage = 'language';
    91 	$stage = 'language';
    92   $stage_ids['language'] = $ui->add_stage('Language', true);
    92 	$stage_ids['language'] = $ui->add_stage('Language', true);
    93   $stage_ids['license'] = $ui->add_stage('License', true);
    93 	$stage_ids['license'] = $ui->add_stage('License', true);
    94   $stage_ids['sysreqs'] = $ui->add_stage('Requirements', true);
    94 	$stage_ids['sysreqs'] = $ui->add_stage('Requirements', true);
    95   $stage_ids['database'] = $ui->add_stage('Database', true);
    95 	$stage_ids['database'] = $ui->add_stage('Database', true);
    96   $stage_ids['website'] = $ui->add_stage('Site info', true);
    96 	$stage_ids['website'] = $ui->add_stage('Site info', true);
    97   $stage_ids['login'] = $ui->add_stage('Admin login', true);
    97 	$stage_ids['login'] = $ui->add_stage('Admin login', true);
    98   $stage_ids['confirm'] = $ui->add_stage('Review', true);
    98 	$stage_ids['confirm'] = $ui->add_stage('Review', true);
    99   $stage_ids['install'] = $ui->add_stage('Install', true);
    99 	$stage_ids['install'] = $ui->add_stage('Install', true);
   100   $stage_ids['finish'] = $ui->add_stage('Finish', true);
   100 	$stage_ids['finish'] = $ui->add_stage('Finish', true);
   101 }
   101 }
   102 
   102 
   103 // If we don't have PHP 5, show a friendly error message and bail out
   103 // If we don't have PHP 5, show a friendly error message and bail out
   104 if ( version_compare(PHP_VERSION, '5.0.0', '<') || isset($_GET['debug_warn_php4']) )
   104 if ( version_compare(PHP_VERSION, '5.0.0', '<') || isset($_GET['debug_warn_php4']) )
   105 {
   105 {
   106   $ui->set_visible_stage(
   106 	$ui->set_visible_stage(
   107     $ui->add_stage('PHP compatibility notice', false)
   107 		$ui->add_stage('PHP compatibility notice', false)
   108   );
   108 	);
   109   $ui->step = '';
   109 	$ui->step = '';
   110   $ui->show_header();
   110 	$ui->show_header();
   111 
   111 
   112   // This isn't localized because all localization code is dependent on
   112 	// This isn't localized because all localization code is dependent on
   113   // PHP 5 (loading lang.php will throw a parser error under PHP4). This
   113 	// PHP 5 (loading lang.php will throw a parser error under PHP4). This
   114   // one message probably doesn't need to be localized anyway.
   114 	// one message probably doesn't need to be localized anyway.
   115   
   115 	
   116   ?>
   116 	?>
   117   <h2 class="heading-error">
   117 	<h2 class="heading-error">
   118     Your server doesn't have support for PHP 5.
   118 		Your server doesn't have support for PHP 5.
   119   </h2>
   119 	</h2>
   120   <p>
   120 	<p>
   121     PHP 5 is the latest version of the language on which Enano was built. Its many new features have been available since early 2004, yet
   121 		PHP 5 is the latest version of the language on which Enano was built. Its many new features have been available since early 2004, yet
   122     many web hosts have not migrated to it because of the work involved. In 2007, Zend Corporation announced that support for the aging
   122 		many web hosts have not migrated to it because of the work involved. In 2007, Zend Corporation announced that support for the aging
   123     PHP 4.x would be discontinued at the end of the year. An initiative called <a href="http://gophp5.org/">GoPHP5</a> was started to
   123 		PHP 4.x would be discontinued at the end of the year. An initiative called <a href="http://gophp5.org/">GoPHP5</a> was started to
   124     encourage web hosts to migrate to PHP 5.
   124 		encourage web hosts to migrate to PHP 5.
   125   </p>
   125 	</p>
   126   <p>
   126 	<p>
   127     Because of the industry's decision to not support PHP 4 any longer, the Enano team decided that it was time to begin using the powerful
   127 		Because of the industry's decision to not support PHP 4 any longer, the Enano team decided that it was time to begin using the powerful
   128     features of PHP 5 at the expense of PHP 4 compatibility. Therefore, this version of Enano cannot be installed on your server until it
   128 		features of PHP 5 at the expense of PHP 4 compatibility. Therefore, this version of Enano cannot be installed on your server until it
   129     is upgraded to at least PHP 5.0.0, and preferably the latest available version.
   129 		is upgraded to at least PHP 5.0.0, and preferably the latest available version.
   130     <!-- No, not even removing the check in this installer script will help. As soon as the PHP4 check is passed, the installer shows the
   130 		<!-- No, not even removing the check in this installer script will help. As soon as the PHP4 check is passed, the installer shows the
   131          language selection page, after which the language code is loaded. The language code and libjson2 will trigger parse errors under
   131  				language selection page, after which the language code is loaded. The language code and libjson2 will trigger parse errors under
   132          PHP <5.0.0. -->
   132  				PHP <5.0.0. -->
   133   </p>
   133 	</p>
   134   <p>
   134 	<p>
   135     If you need to use Enano but can't upgrade your PHP because you're on a shared or reseller hosting service, you can use the
   135 		If you need to use Enano but can't upgrade your PHP because you're on a shared or reseller hosting service, you can use the
   136     <a href="http://enanocms.org/download?series=1.0">1.0.x series of Enano</a> on your site. While the Enano team attempts to make this
   136 		<a href="http://enanocms.org/download?series=1.0">1.0.x series of Enano</a> on your site. While the Enano team attempts to make this
   137     older series work on PHP 4, official support is not provided for installations of Enano on PHP 4.
   137 		older series work on PHP 4, official support is not provided for installations of Enano on PHP 4.
   138   </p>
   138 	</p>
   139   <?php
   139 	<?php
   140   
   140 	
   141   $ui->show_footer();
   141 	$ui->show_footer();
   142   exit();
   142 	exit();
   143 }
   143 }
   144 
   144 
   145 if ( isset($_SERVER['PATH_INFO']) && !isset($_GET['str']) && isset($_GET['do']) )
   145 if ( isset($_SERVER['PATH_INFO']) && !isset($_GET['str']) && isset($_GET['do']) )
   146 {
   146 {
   147   $_GET['str'] = substr($_SERVER['PATH_INFO'], 1);
   147 	$_GET['str'] = substr($_SERVER['PATH_INFO'], 1);
   148 }
   148 }
   149 
   149 
   150 if ( isset($_GET['do']) )
   150 if ( isset($_GET['do']) )
   151 {
   151 {
   152   switch ( $_GET['do'] )
   152 	switch ( $_GET['do'] )
   153   {
   153 	{
   154     case 'lang_js':
   154 		case 'lang_js':
   155       if ( !isset($_GET['language']) )
   155 			if ( !isset($_GET['language']) )
   156         die();
   156 				die();
   157       $lang_id = $_GET['language'];
   157 			$lang_id = $_GET['language'];
   158       header('Content-type: text/javascript');
   158 			header('Content-type: text/javascript');
   159       if ( !isset($languages[$lang_id]) )
   159 			if ( !isset($languages[$lang_id]) )
   160       {
   160 			{
   161         die('// Bad language ID');
   161 				die('// Bad language ID');
   162       }
   162 			}
   163       $language_dir = $languages[$lang_id]['dir'];
   163 			$language_dir = $languages[$lang_id]['dir'];
   164       
   164 			
   165       // Include language lib and additional PHP5-only JSON functions
   165 			// Include language lib and additional PHP5-only JSON functions
   166       require_once( ENANO_ROOT . '/includes/json2.php' );
   166 			require_once( ENANO_ROOT . '/includes/json2.php' );
   167       require_once( ENANO_ROOT . '/includes/lang.php' );
   167 			require_once( ENANO_ROOT . '/includes/lang.php' );
   168   
   168 	
   169       // Initialize language support
   169 			// Initialize language support
   170       $lang = new Language($lang_id);
   170 			$lang = new Language($lang_id);
   171       $lang->load_file(ENANO_ROOT . '/language/' . $language_dir . '/install.json');
   171 			$lang->load_file(ENANO_ROOT . '/language/' . $language_dir . '/install.json');
   172       $lang->load_file(ENANO_ROOT . '/language/' . $language_dir . '/core.json');
   172 			$lang->load_file(ENANO_ROOT . '/language/' . $language_dir . '/core.json');
   173       $lang->load_file(ENANO_ROOT . '/language/' . $language_dir . '/user.json');
   173 			$lang->load_file(ENANO_ROOT . '/language/' . $language_dir . '/user.json');
   174       
   174 			
   175       $time_now = microtime_float();
   175 			$time_now = microtime_float();
   176       $test = "if ( typeof(enano_lang) != 'object' )
   176 			$test = "if ( typeof(enano_lang) != 'object' )
   177 {
   177 {
   178   var enano_lang = new Object();
   178 	var enano_lang = new Object();
   179   var enano_lang_code = new Object();
   179 	var enano_lang_code = new Object();
   180 }
   180 }
   181 
   181 
   182 enano_lang[{$lang->lang_id}] = " . enano_json_encode($lang->strings) . ";
   182 enano_lang[{$lang->lang_id}] = " . enano_json_encode($lang->strings) . ";
   183 enano_lang_code[{$lang->lang_id}] = '{$lang->lang_code}';";
   183 enano_lang_code[{$lang->lang_id}] = '{$lang->lang_code}';";
   184       $time_total = round(microtime_float() - $time_now, 4);
   184 			$time_total = round(microtime_float() - $time_now, 4);
   185       echo "// Generated in $time_total seconds\n";
   185 			echo "// Generated in $time_total seconds\n";
   186       echo $test;
   186 			echo $test;
   187 
   187 
   188       exit();
   188 			exit();
   189     case 'modrewrite_test':
   189 		case 'modrewrite_test':
   190       // Include language lib and additional PHP5-only JSON functions
   190 			// Include language lib and additional PHP5-only JSON functions
   191       require_once( ENANO_ROOT . '/includes/json2.php' );
   191 			require_once( ENANO_ROOT . '/includes/json2.php' );
   192       
   192 			
   193       if ( isset($_GET['str']) && in_array($_GET['str'], array('standard', 'shortened', 'rewrite')) )
   193 			if ( isset($_GET['str']) && in_array($_GET['str'], array('standard', 'shortened', 'rewrite')) )
   194       {
   194 			{
   195         echo 'good_' . $_GET['str'];
   195 				echo 'good_' . $_GET['str'];
   196       }
   196 			}
   197       else if ( $_SERVER['QUERY_STRING'] == '/tiny&do=modrewrite_test' )
   197 			else if ( $_SERVER['QUERY_STRING'] == '/tiny&do=modrewrite_test' )
   198       {
   198 			{
   199         echo 'good_tiny';
   199 				echo 'good_tiny';
   200       }
   200 			}
   201       else
   201 			else
   202       {
   202 			{
   203         echo 'bad';
   203 				echo 'bad';
   204       }
   204 			}
   205       exit();
   205 			exit();
   206   }
   206 	}
   207 }
   207 }
   208 
   208 
   209 switch ( $stage )
   209 switch ( $stage )
   210 {
   210 {
   211   default:
   211 	default:
   212     $ui->show_header();
   212 		$ui->show_header();
   213     echo '<p>Invalid stage.</p>';
   213 		echo '<p>Invalid stage.</p>';
   214     break;
   214 		break;
   215   case 'language':
   215 	case 'language':
   216     $ui->show_header();
   216 		$ui->show_header();
   217     ?>
   217 		?>
   218     <h2>Welcome to Enano.</h2>
   218 		<h2>Welcome to Enano.</h2>
   219     <h3>Bienvenido a Enano /
   219 		<h3>Bienvenido a Enano /
   220        Wilkommen in Enano /
   220  			Wilkommen in Enano /
   221        Bienvenue à Enano /
   221  			Bienvenue à Enano /
   222        Benvenuti a Enano /
   222  			Benvenuti a Enano /
   223        欢迎 Enano /
   223  			欢迎 Enano /
   224        Enano へようこそ。
   224  			Enano へようこそ。
   225        </h3>
   225  			</h3>
   226     <p>
   226 		<p>
   227        <b>Please select a language:</b> /
   227  			<b>Please select a language:</b> /
   228        Por favor, seleccione un idioma: /
   228  			Por favor, seleccione un idioma: /
   229        Bitte wählen Sie eine Sprache: /
   229  			Bitte wählen Sie eine Sprache: /
   230        S’il vous plaît choisir une langue: /
   230  			S’il vous plaît choisir une langue: /
   231        Selezionare una lingua: /
   231  			Selezionare una lingua: /
   232        请选择一种语言: /
   232  			请选择一种语言: /
   233        言語を選択してください:</p>
   233  			言語を選択してください:</p>
   234     <form action="install.php?stage=license" method="post">
   234 		<form action="install.php?stage=license" method="post">
   235       <select name="language" style="width: 200px;" tabindex="1">
   235 			<select name="language" style="width: 200px;" tabindex="1">
   236         <?php
   236 				<?php
   237         foreach ( $languages as $code => $meta )
   237 				foreach ( $languages as $code => $meta )
   238         {
   238 				{
   239           $sel = ( $code == 'eng' ) ? ' selected="selected"' : '';
   239 					$sel = ( $code == 'eng' ) ? ' selected="selected"' : '';
   240           echo '<option value="' . $code . '"' . $sel . '>' . $meta['name'] . '</option>';
   240 					echo '<option value="' . $code . '"' . $sel . '>' . $meta['name'] . '</option>';
   241         }
   241 				}
   242         ?>
   242 				?>
   243       </select>
   243 			</select>
   244       <input tabindex="2" type="submit" value="&gt;&gt;" />
   244 			<input tabindex="2" type="submit" value="&gt;&gt;" />
   245     </form>
   245 		</form>
   246     <?php
   246 		<?php
   247     break;
   247 		break;
   248   case 'license':
   248 	case 'license':
   249     $ui->show_header();
   249 		$ui->show_header();
   250     require( ENANO_ROOT . '/install/includes/stages/license.php' );
   250 		require( ENANO_ROOT . '/install/includes/stages/license.php' );
   251     break;
   251 		break;
   252   case 'sysreqs':
   252 	case 'sysreqs':
   253     $ui->show_header();
   253 		$ui->show_header();
   254     require( ENANO_ROOT . '/install/includes/stages/sysreqs.php' );
   254 		require( ENANO_ROOT . '/install/includes/stages/sysreqs.php' );
   255     break;
   255 		break;
   256   case 'database':
   256 	case 'database':
   257     if ( isset($_POST['driver']) && in_array($_POST['driver'], $supported_drivers) )
   257 		if ( isset($_POST['driver']) && in_array($_POST['driver'], $supported_drivers) )
   258     {
   258 		{
   259       // This is SAFE! It's validated against the array in in_array() above.
   259 			// This is SAFE! It's validated against the array in in_array() above.
   260       $driver = $_POST['driver'];
   260 			$driver = $_POST['driver'];
   261       require( ENANO_ROOT . "/install/includes/stages/database_{$driver}.php" );
   261 			require( ENANO_ROOT . "/install/includes/stages/database_{$driver}.php" );
   262     }
   262 		}
   263     else
   263 		else
   264     {
   264 		{
   265       $ui->show_header();
   265 			$ui->show_header();
   266       // No driver selected - give the DB drive selection page
   266 			// No driver selected - give the DB drive selection page
   267       require( ENANO_ROOT . '/install/includes/stages/database.php' );
   267 			require( ENANO_ROOT . '/install/includes/stages/database.php' );
   268     }
   268 		}
   269     break;
   269 		break;
   270   case 'website':
   270 	case 'website':
   271     require( ENANO_ROOT . '/install/includes/stages/website.php' );
   271 		require( ENANO_ROOT . '/install/includes/stages/website.php' );
   272     break;
   272 		break;
   273   case 'login':
   273 	case 'login':
   274     require( ENANO_ROOT . '/install/includes/stages/login.php' );
   274 		require( ENANO_ROOT . '/install/includes/stages/login.php' );
   275     break;
   275 		break;
   276   case 'confirm':
   276 	case 'confirm':
   277     require( ENANO_ROOT . '/install/includes/stages/confirm.php' );
   277 		require( ENANO_ROOT . '/install/includes/stages/confirm.php' );
   278     break;
   278 		break;
   279   case 'install':
   279 	case 'install':
   280     require( ENANO_ROOT . '/install/includes/stages/install.php' );
   280 		require( ENANO_ROOT . '/install/includes/stages/install.php' );
   281     break;
   281 		break;
   282   case 'finish':
   282 	case 'finish':
   283     require( ENANO_ROOT . '/install/includes/stages/finish.php' );
   283 		require( ENANO_ROOT . '/install/includes/stages/finish.php' );
   284     break;
   284 		break;
   285 }
   285 }
   286 
   286 
   287 $ui->show_footer();
   287 $ui->show_footer();
   288 
   288 
   289 ?>
   289 ?>