From 42c961b14fe40048f2222e8baf4a62fb659453a2 Mon Sep 17 00:00:00 2001 From: Pascal Chevrel Date: Sat, 10 Mar 2012 14:51:08 +0100 Subject: Refactor installation code to be more readable, reduce the use of temporary variables and constants, also switches template to HTML5 --- install.php | 114 +++++++++++++++++++++++++----------------------------------- 1 file changed, 48 insertions(+), 66 deletions(-) (limited to 'install.php') diff --git a/install.php b/install.php index eaf736a..482a8d0 100755 --- a/install.php +++ b/install.php @@ -1,30 +1,31 @@ ' . $str . '' . $msg . ''; +} -if (file_exists(CONFIG_FILE) && file_exists(PWD_FILE)) { - //Nothing to do, already installed; +// If the password and config files exist, moonmoon is already installed +if (file_exists(dirname(__FILE__) . '/custom/config.yml') + && file_exists(dirname(__FILE__) . '/admin/inc/pwd.inc.php')) { $status = 'installed'; } elseif (isset($_REQUEST['url'])) { - $save = Array(); - + require_once dirname(__FILE__) . '/app/app.php'; + $save = array(); //Save config file - $config = Array( - 'url' => $_REQUEST['url'], - 'name' => $_REQUEST['title'], - 'items' => 10, - 'shuffle' => 0, - 'refresh' => 240, - 'cache' => 10, - 'nohtml' => 0, + $config = array( + 'url' => filter_var($_REQUEST['url'], FILTER_SANITIZE_ENCODED), + 'name' => filter_var($_REQUEST['title'], FILTER_SANITIZE_SPECIAL_CHARS), + 'items' => 10, + 'shuffle' => 0, + 'refresh' => 240, + 'cache' => 10, + 'nohtml' => 0, 'postmaxlength' => 0, - 'cachedir' => './cache' + 'cachedir' => './cache' ); + $CreatePlanetConfig = new PlanetConfig($config); $save['config'] = file_put_contents(dirname(__FILE__).'/custom/config.yml', $CreatePlanetConfig->toYaml()); @@ -36,13 +37,12 @@ if (file_exists(CONFIG_FILE) && file_exists(PWD_FILE)) { } } else { - //Requirements + // Server requirements with advices in case there is something wrong $tests = array( 'php5' => array( 'file' => false, 'label' => 'Server is running PHP5', 'solution' => 'Check your server documentation to activate PHP5.', - 'result' => phpversion() >= 5 ), 'custom' => array( 'file' => '/custom', @@ -66,64 +66,49 @@ if (file_exists(CONFIG_FILE) && file_exists(PWD_FILE)) { ), ); + // We start by malking sure we have PHP5 as a base requirement + if(phpversion() >= 5) { + $strInstall = installStatus($tests['php5']['label'], 'OK',true); + $strRecommendation = ''; + } else { + $strInstall = installStatus($tests['php5']['label'], 'FAIL',false); + $strRecommendation = '
  • ' . $tests['php5']['solution'] . '
  • '; + } + + // We now test that all required files are writable foreach ($tests as $k => $v) { - // test file requirements, exclude php5 test if ($tests[$k]['file']) { - if(is_writable(dirname(__FILE__) . $tests[$k]['file'])) { - $tests[$k]['result'] = true; - } else { - $tests[$k]['result'] = false; + if(is_writable(dirname(__FILE__) . $tests[$k]['file'])) { + $strInstall .= installStatus($tests[$k]['label'], 'OK', true); + } else { + $strInstall .= installStatus($tests[$k]['label'], 'FAIL',false); + $strRecommendation .= '
  • ' . $tests[$k]['solution'] . '
  • '; } } } - $bInstallOk = true; - $strInstall = ''; - $strRecommendation = ''; - foreach ($tests as $test) { - $bInstallOk = $bInstallOk && $test['result']; - $strInstall .= " - - ".$test['label']." - ".(($test['result'])?'OK':'FAIL')." - "; - if (!$test['result']) { - $strRecommendation .= '
  • '.$test['solution'].'
  • '; - } - } + // We can now decide if we install moonmoon or not + $status = ($strRecommendation != '') ? 'error' : 'install'; - if ($bInstallOk) { - $status = 'install'; - } else { - $status = 'error'; - } } -header('Content-type: text/html; charset=UTF-8'); ?> - - + + - - - - moonmoon install - -

    moonmoon installation

    - +

    Sorry, your server is not compatible with moonmoon.

    @@ -168,11 +151,11 @@ header('Content-type: text/html; charset=UTF-8');

    Troubleshooting

    To install moonmoon, try the following changes:

      -
      +
    - +
    @@ -203,7 +186,7 @@ header('Content-type: text/html; charset=UTF-8');
    - +

    Congratulations! Your moonmoon is ready.

    What's next?

    @@ -217,6 +200,5 @@ header('Content-type: text/html; charset=UTF-8'); -
    -- cgit v1.2.1