]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - install/index.php
Convert the MySQL charset to utf8mb4 to support the full range of unicode characters
[github/wallabag/wallabag.git] / install / index.php
old mode 100644 (file)
new mode 100755 (executable)
index b21cec5..2b080c1
@@ -1,9 +1,39 @@
 <?php
+/**
+ * wallabag, self hostable application allowing you to not miss any content anymore
+ *
+ * @category   wallabag
+ * @author     Nicolas Lœuillet <nicolas@loeuillet.org>
+ * @copyright  2013
+ * @license    http://opensource.org/licenses/MIT see COPYING file
+ */
+
 $errors = array();
 $successes = array();
-if ($_POST['download']) {
+
+/* Function taken from at http://php.net/manual/en/function.rmdir.php#110489
+ * Idea : nbari at dalmp dot com
+ * Rights unknown
+ * Here in case of .gitignore files
+ */
+function delTree($dir) {
+    $files = array_diff(scandir($dir), array('.','..'));
+    foreach ($files as $file) {
+      (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
+    }
+    return rmdir($dir);
+  }
+
+if (isset($_GET['clean'])) {
+    if (is_dir('install')){
+    delTree('install');
+    header('Location: index.php');      
+    }
+}
+
+if (isset($_POST['download'])) {
     if (!file_put_contents("cache/vendor.zip", fopen("http://static.wallabag.org/files/vendor.zip", 'r'))) {
-        $errors[] = 'Impossible to download vendor.zip. Please <a href="http://wllbg.org/vendor">download it manually<a> and unzip it in your wallabag folder.';
+        $errors[] = 'Impossible to download vendor.zip. Please <a href="http://wllbg.org/vendor">download it manually</a> and unzip it in your wallabag folder.';
     }
     else {
         if (extension_loaded('zip')) {
@@ -25,14 +55,14 @@ if ($_POST['download']) {
         }
     }
 }
-else if ($_POST['install']) {
+else if (isset($_POST['install'])) {
     if (!is_dir('vendor')) {
         $errors[] = 'You must install twig before.';
     }
     else {
         $continue = true;
         // Create config.inc.php
-        if (!copy('inc/poche/config.inc.php.new', 'inc/poche/config.inc.php')) {
+        if (!copy('inc/poche/config.inc.default.php', 'inc/poche/config.inc.php')) {
             $errors[] = 'Installation aborted, impossible to create inc/poche/config.inc.php file. Maybe you don\'t have write access to create it.';
             $continue = false;
         }
@@ -64,22 +94,25 @@ else if ($_POST['install']) {
                 else {
                     $db_path = 'sqlite:' . realpath('') . '/db/poche.sqlite';
                     $handle = new PDO($db_path);
+                    $sql_structure = "";
                 }
             }
             else {
                 $content = file_get_contents('inc/poche/config.inc.php');
 
                 if ($_POST['db_engine'] == 'mysql') {
-                    $db_path = 'mysql:host=' . $_POST['mysql_server'] . ';dbname=' . $_POST['mysql_database'];
+                    $db_path = 'mysql:host=' . $_POST['mysql_server'] . ';dbname=' . $_POST['mysql_database'] . ';charset=utf8mb4';
                     $content = str_replace("define ('STORAGE_SERVER', 'localhost');", "define ('STORAGE_SERVER', '".$_POST['mysql_server']."');", $content);
                     $content = str_replace("define ('STORAGE_DB', 'poche');", "define ('STORAGE_DB', '".$_POST['mysql_database']."');", $content);
                     $content = str_replace("define ('STORAGE_USER', 'poche');", "define ('STORAGE_USER', '".$_POST['mysql_user']."');", $content);
                     $content = str_replace("define ('STORAGE_PASSWORD', 'poche');", "define ('STORAGE_PASSWORD', '".$_POST['mysql_password']."');", $content);
-                    $handle = new PDO($db_path, $_POST['mysql_user'], $_POST['mysql_password']); 
+                    $handle = new PDO($db_path, $_POST['mysql_user'], $_POST['mysql_password'], array(
+                        PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4',
+                    ));
 
                     $sql_structure = file_get_contents('install/mysql.sql');
                 }
-                else if ($_POST['db_engine'] == 'postgresql') {
+                else if ($_POST['db_engine'] == 'postgres') {
                     $db_path = 'pgsql:host=' . $_POST['pg_server'] . ';dbname=' . $_POST['pg_database'];
                     $content = str_replace("define ('STORAGE_SERVER', 'localhost');", "define ('STORAGE_SERVER', '".$_POST['pg_server']."');", $content);
                     $content = str_replace("define ('STORAGE_DB', 'poche');", "define ('STORAGE_DB', '".$_POST['pg_database']."');", $content);
@@ -129,7 +162,7 @@ else if ($_POST['install']) {
                 $params = array($id_user, 'language', 'en_EN.UTF8');
                 $query = executeQuery($handle, $sql, $params);
 
-                $successes[] = 'wallabag is now installed. Don\'t forget to delete install folder. Then, <a href="index.php">reload this page</a>.';
+                $successes[] = 'wallabag is now installed. You can now <a href="index.php?clean=0">access it !</a>';
             }
         }
     }
@@ -143,7 +176,7 @@ else if ($_POST['install']) {
         <!--[if IE]>
         <meta http-equiv="X-UA-Compatible" content="IE=10">
         <![endif]-->
-        <title>wallabag  installation</title>
+        <title>wallabag - installation</title>
         <link rel="shortcut icon" type="image/x-icon" href="themes/baggy/img/favicon.ico" />
         <link rel="apple-touch-icon-precomposed" sizes="144x144" href="themes/baggy/img/apple-touch-icon-144x144-precomposed.png">
         <link rel="apple-touch-icon-precomposed" sizes="72x72" href="themes/baggy/img/apple-touch-icon-72x72-precomposed.png">
@@ -154,7 +187,7 @@ else if ($_POST['install']) {
         <link rel="stylesheet" href="themes/baggy/css/main.css" media="all">
         <link rel="stylesheet" href="themes/baggy/css/messages.css" media="all">
         <link rel="stylesheet" href="themes/baggy/css/print.css" media="print">
-        <script src="themes/baggy/js/jquery-2.0.3.min.js"></script>
+        <script src="themes/default/js/jquery-2.0.3.min.js"></script>
         <script src="themes/baggy/js/init.js"></script>
     </head>
     <body>
@@ -198,18 +231,18 @@ else if ($_POST['install']) {
                 <?php if (file_exists('inc/poche/config.inc.php') && is_dir('vendor')) : ?>
                 <div class='messages success install'>
                     <p>
-                        wallabag seems already installed. If you want to update it, you only have to delete install folder.
+                        wallabag seems already installed. If you want to update it, you only have to delete install folder, then <a href="index.php">reload this page</a>.
                     </p>
                 </div>
                 <?php endif; ?>    
             <?php endif; ?>
             <p>To install wallabag, you just have to fill the following fields. That's all.</p>
-            <p>Don't forget to check your server compatibility <a href="wallabag_compatibility_test.php">here</a>.</p>
+            <p>Don't forget to check your server compatibility <a href="wallabag_compatibility_test.php?from=install">here</a>.</p>
             <form method="post">
                 <fieldset>
                     <legend><strong>Technical settings</strong></legend>
                     <?php if (!is_dir('vendor')) : ?>
-                        <div class='messages notice install'>wallabag needs twig, a template engine (<a href="http://twig.sensiolabs.org/">?</a>). Two ways to install it: 
+                        <div class='messages notice install'>wallabag needs twig, a template engine (<a href="http://twig.sensiolabs.org/">?</a>). Two ways to install it:<br />
                         <ul>
                             <li>automatically download and extract vendor.zip into your wallabag folder. 
                             <p><input type="submit" name="download" value="Download vendor.zip" /></p>
@@ -240,12 +273,12 @@ php composer.phar install</code></pre></li>
                                 </ul>
                             </li>
                             <li>
-                                <label for="postgresql">PostgreSQL</label> <input name="db_engine" type="radio" id="postgresql" value="postgresql" />
+                                <label for="postgres">PostgreSQL</label> <input name="db_engine" type="radio" id="postgres" value="postgres" />
                                 <ul id="pg_infos">
                                     <li><label for="pg_server">Server</label> <input type="text" placeholder="localhost" id="pg_server" name="pg_server" /></li>
                                     <li><label for="pg_database">Database</label> <input type="text" placeholder="wallabag" id="pg_database" name="pg_database" /></li>
                                     <li><label for="pg_user">User</label> <input type="text" placeholder="user" id="pg_user" name="pg_user" /></li>
-                                  id  <li><label for="pg_password">Password</label> <input type="text" placeholder="p4ssw0rd" id="pg_password" name="pg_password" /></li>
+                                    <li><label for="pg_password">Password</label> <input type="text" placeholder="p4ssw0rd" id="pg_password" name="pg_password" /></li>
                                 </ul>
                             </li>
                         </ul>
@@ -294,7 +327,7 @@ php composer.phar install</code></pre></li>
                         $("#install_button").show();
                     }
                     else {
-                        if ( $("#postgresql").prop('checked')) {
+                        if ( $("#postgres").prop('checked')) {
                             $("#mysql_infos").hide();
                             $("#pg_infos").show();
                             $("#pdo_sqlite").hide();