Skip to content

Commit

Permalink
Improve installer. support to update exists installed.
Browse files Browse the repository at this point in the history
- Try find app dir from index.php setting.
- Improve some UX.
- Update texts.
  • Loading branch information
uzulla committed Mar 15, 2021
1 parent a54bbfc commit fea6a84
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 26 deletions.
73 changes: 49 additions & 24 deletions dist_zip/installer/fc2blog_installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>fc2blog installer (alpha version)</title>
<title>fc2blog installer</title>
<style>
.notice {
color: red;
Expand All @@ -29,14 +29,15 @@
<body>

<?php if (get_post_val('mode') === null) { ?>
<h1>fc2blog installer (alpha version)</h1>
<h1>fc2blog installer</h1>
This is fc2blog installer. Download fc2blog release file and extract, generate config. <br>
<b class="notice">The installer is now UNDER DEVELOPMENT, ALPHA VERSION.</b> <br>
<b>The installer will manipulate files. </b><span class="notice">PLEASE BACKUP YOUR SITE before use, And remove this script as
soon as possible after install</span> (will be self delete when completed). <br>
<b>The installer will manipulate files. </b>
<span class="notice">
PLEASE BACKUP YOUR SITE FIRST,
And remove this script as soon as possible after install
</span> (will be self delete when completed). <br>
<b>The installer should be place to DocumentRoot dir.</b> <br>
<br>
<!--<b>If you want update. please put to dir that same as `index.php`.</b> <br> TODO -->
<hr>

<h2># requirement check</h2>
Expand Down Expand Up @@ -90,10 +91,6 @@
</li>
</ul>

<?php
// TODO update (read config exists install) not implemented yet.
?>

<form action="" method="post" onsubmit="return block_duplicate_execute();">
<script>
let is_submitted = false;
Expand Down Expand Up @@ -135,33 +132,59 @@ function block_duplicate_execute() {
</li>
</ul>

<?php
// Try recognize $app_dir from index.php if exists.
$is_exists_valid_index_php = false;
$is_found_config_php = false;
$app_dir_path = null;
if (file_exists(__DIR__ . "/index.php") && is_file(__DIR__ . "/index.php")) {
define("READ_FROM_INSTALLER", 1);
$index_php_app_dir_path = require(__DIR__ . "/index.php");
// check exists app dir
if (file_exists($index_php_app_dir_path) && is_dir($index_php_app_dir_path)) {
// found exists app dir.
$app_dir_path = $index_php_app_dir_path;
$is_exists_valid_index_php = true;
if (file_exists($app_dir_path . "/config.php")) {
$is_found_config_php = true;
}
}
}
if (is_null($app_dir_path)) {
$app_dir_path = __DIR__ . '/app';
}
?>
<h2># install dir</h2>
<b>(index.php</b> and <b>assets</b> will be install to
<b><?= hsc(__DIR__) ?></b> (this dir). this is not changeable.) <br>
<b>index.php</b> and <b>assets</b> will be install to
<b><?= hsc(__DIR__) ?></b> (this dir). this is not changeable. <br>
<br>
Please select <b>app</b> directory. (app directory contain code and config. No need to expose.) <br>
<ul>
<li>
<label>
<input type="radio" name="app_dir"
value="<?= hsc(__DIR__) ?>/../app/">
value="<?= hsc(dirname(__DIR__)) ?>/app/">
<b><?= hsc(dirname(__DIR__)) ?>/app/</b>
(In document root parent dir. recommend, but some server will be has problem. please carefull
conflict other installation.)
(In document root's parent dir. recommend, but some server will be has problem.
please careful conflict other installation.)
</label>
</li>
<li><label><input type="radio" name="app_dir"
value="<?= hsc(__DIR__) ?>/app/"
checked>
<?php if (!$is_exists_valid_index_php){ ?>checked<?php } ?>>
<b><?= hsc(__DIR__) ?>/app/</b>
(In document root. less secure, more compatibility)
</label></li>
<li>
<label>
<input type="radio" name="app_dir" value="">
other, path input. <b>path</b>:
<input type="text" name="app_dir_other" size="80"
value="<?= hsc(dirname(__DIR__)) ?>/app">
<input type="radio" name="app_dir" value=""
<?php if ($is_exists_valid_index_php){ ?>checked<?php } ?>>
<?php if ($is_exists_valid_index_php) { ?>
Load from exists index.php :
<?php } else { ?>
Specify another path :
<?php } ?>
<input type="text" name="app_dir_other" size="80" value="<?= hsc($app_dir_path) ?>">
</label>
</li>
</ul>
Expand All @@ -171,9 +194,10 @@ function block_duplicate_execute() {
<ul>
<li>
<label>
<input type="checkbox" name="generate_config" value="Y">
Generate <b>config.php</b> (if checked, generate config.php.
if not, should be create yourself.) <br>
<input type="checkbox" name="generate_config" value="Y"
<?php if (!$is_found_config_php) { ?>checked<?php } ?>>
Generate <b>config.php</b>
(if checked, generate/overwrite config.php. if not, should be create yourself.) <br>
</label>
</li>
<li>
Expand Down Expand Up @@ -290,6 +314,7 @@ function block_duplicate_execute() {

// decide app dir.
$app_dir = get_post_val('app_dir');

if ($app_dir === '') { // read from app_dir_other
$app_dir = get_post_val('app_dir_other');
}
Expand Down Expand Up @@ -338,7 +363,7 @@ function block_duplicate_execute() {

// rewrite app dir path in index.php
$index_php = file_get_contents("index.php");
$index_php = preg_replace('/\n\$app_dir_path.+;/u', "\n\$app_dir_path = \"{$app_dir}\";", $index_php);
$index_php = preg_replace('/\n\$app_dir_path.+;/u', "\n\$app_dir_path = '{$app_dir}';", $index_php);
file_put_contents("index.php", $index_php);

// clean up. delete self.
Expand Down
8 changes: 6 additions & 2 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php
// `app`ディレクトリを$app_dir_pathに設定してください
// `app`ディレクトリのpathを$app_dir_pathに設定してください
// Please set actual `app` directory path to $app_dir_path.
$app_dir_path = __DIR__ . "/../app";
$app_dir_path = '../app';

if (defined("READ_FROM_INSTALLER")){
return $app_dir_path;
}

if (!file_exists($app_dir_path . "/src/include/index_include.php")) {
die("please set correct `\$app_dir_path` in index.php ");
Expand Down

0 comments on commit fea6a84

Please sign in to comment.