install/includes/common.php
changeset 348 87e08a6e4fec
child 349 fdaf9070566c
equal deleted inserted replaced
347:299a90e28abc 348:87e08a6e4fec
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
       
     5  * Version 1.1.1
       
     6  * Copyright (C) 2006-2007 Dan Fuhry
       
     7  * Installation package
       
     8  * common.php - Installer common functions
       
     9  *
       
    10  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
       
    11  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
       
    12  *
       
    13  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
       
    14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
       
    15  */
       
    16 
       
    17 // Our version number. This needs to be changed for any custom releases.
       
    18 $installer_version = array(
       
    19   'version' => '1.1.1',
       
    20   'type' => 'alpha'
       
    21   // If type is set to "rc", "beta", or "alpha", optionally another version number can be issued with the key 'sub':
       
    22   // 'sub' => '3' will produce Enano 1.1.1a3 / Enano 1.1.1 alpha 3
       
    23 );
       
    24  
       
    25 // Determine Enano root directory
       
    26 
       
    27 $enano_root = dirname(dirname(dirname(__FILE__)));
       
    28 if ( preg_match('#/repo$#', $enano_root) && file_exists("$enano_root/../.enanodev") )
       
    29 {
       
    30   $enano_root = preg_replace('#/repo$#', '', $enano_root);
       
    31 }
       
    32 
       
    33 define('ENANO_ROOT', $enano_root);
       
    34 
       
    35 chdir(ENANO_ROOT);
       
    36 
       
    37 // Determine our scriptPath
       
    38 if ( isset($_SERVER['REQUEST_URI']) )
       
    39 {
       
    40   // Use reverse-matching to determine where the REQUEST_URI overlaps the Enano root.
       
    41   $requri = $_SERVER['REQUEST_URI'];
       
    42   if ( isset($_SERVER['PATH_INFO']) && !preg_match('/index\.php$/', $_SERVER['PATH_INFO']) )
       
    43   {
       
    44     $requri = preg_replace(';' . preg_quote($_SERVER['PATH_INFO']) . '$;', '', $requri);
       
    45   }
       
    46   if ( !preg_match('/\.php$/', $requri) )
       
    47   {
       
    48     // user requested http://foo/enano as opposed to http://foo/enano/index.php
       
    49     $requri .= '/index.php';
       
    50   }
       
    51   $sp = dirname($_SERVER['REQUEST_URI']);
       
    52   if ( $sp == '/' || $sp == '\\' )
       
    53   {
       
    54     $sp = '';
       
    55   }
       
    56   $sp = preg_replace('#/install$#', '', $sp);
       
    57   define('scriptPath', $sp);
       
    58 }
       
    59 
       
    60 // is Enano already installed?
       
    61 @include(ENANO_ROOT . '/config.php');
       
    62 if ( defined('ENANO_INSTALLED') && defined('ENANO_DANGEROUS') )
       
    63 {
       
    64   $title = 'Installation locked';
       
    65   require('includes/common.php');
       
    66   $template->header();
       
    67   echo '<p>The installer has detected that an installation of Enano already exists on your server. You MUST delete config.php if you wish to reinstall Enano.</p>';
       
    68   $template->footer();
       
    69   exit();
       
    70 }
       
    71 
       
    72 function microtime_float()
       
    73 {
       
    74   list($usec, $sec) = explode(" ", microtime());
       
    75   return ((float)$usec + (float)$sec);
       
    76 }
       
    77 
       
    78 define('IN_ENANO_INSTALL', 1);
       
    79 
       
    80 require(ENANO_ROOT . '/install/includes/ui.php');
       
    81 require(ENANO_ROOT . '/includes/functions.php');
       
    82 require(ENANO_ROOT . '/includes/json.php');
       
    83 require(ENANO_ROOT . '/includes/constants.php');
       
    84 require(ENANO_ROOT . '/includes/rijndael.php');
       
    85 // If we have at least PHP 5, load json2
       
    86 if ( version_compare(PHP_VERSION, '5.0.0', '>=') )
       
    87 {
       
    88   require(ENANO_ROOT . '/includes/json2.php');
       
    89 }
       
    90 
       
    91 // Build a list of available languages
       
    92 $dir = @opendir( ENANO_ROOT . '/language' );
       
    93 if ( !$dir )
       
    94   die('CRITICAL: could not open language directory');
       
    95 
       
    96 $languages = array();
       
    97 // Use the old PHP4-compatible JSON decoder
       
    98 $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
       
    99 
       
   100 while ( $dh = @readdir($dir) )
       
   101 {
       
   102   if ( $dh == '.' || $dh == '..' )
       
   103     continue;
       
   104   if ( file_exists( ENANO_ROOT . "/language/$dh/meta.json" ) )
       
   105   {
       
   106     // Found a language directory, determine metadata
       
   107     $meta = @file_get_contents( ENANO_ROOT . "/language/$dh/meta.json" );
       
   108     if ( empty($meta) )
       
   109       // Could not read metadata file, continue silently
       
   110       continue;
       
   111     $meta = $json->decode($meta);
       
   112     if ( isset($meta['lang_name_english']) && isset($meta['lang_name_native']) && isset($meta['lang_code']) )
       
   113     {
       
   114       $languages[$meta['lang_code']] = array(
       
   115           'name' => $meta['lang_name_native'],
       
   116           'dir' => $dh
       
   117         );
       
   118     }
       
   119   }
       
   120 }
       
   121 
       
   122 if ( count($languages) < 1 )
       
   123 {
       
   124   die('CRITICAL: No languages are available');
       
   125 }
       
   126 
       
   127 // List of available DB drivers
       
   128 $supported_drivers = array('mysql', 'postgresql');
       
   129 
       
   130 ?>