]> git.wh0rd.org - tt-rss.git/blobdiff - install/index.php
Merge branch 'hookhead' of git://github.com/justauserx/Tiny-Tiny-RSS into justauserx...
[tt-rss.git] / install / index.php
index 99339aca24ff48ee50648f55bd1299d1c89bea56..440954537a2d08d4acf2e3ca4d3dfbd1ff2b034d 100644 (file)
@@ -2,7 +2,7 @@
 <head>
        <title>Tiny Tiny RSS - Installer</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-       <link rel="stylesheet" type="text/css" href="../utility.css">
+       <link rel="stylesheet" type="text/css" href="../css/utility.css">
        <style type="text/css">
        textarea { font-size : 12px; }
        </style>
        }
 
        function print_error($msg) {
-               print "<div class='error'><img src='../images/sign_excl.svg'> $msg</div>";
+               print "<div class='error'><span><img src='../images/alert.png'></span>
+                       <span>$msg</span></div>";
        }
 
        function print_notice($msg) {
                print "<div class=\"notice\">
-                       <img src=\"../images/sign_info.svg\">$msg</div>";
+                       <span><img src=\"../images/information.png\"></span><span>$msg</span></div>";
        }
 
-       function db_connect($host, $user, $pass, $db, $type) {
+       function db_connect($host, $user, $pass, $db, $type, $port = false) {
                if ($type == "pgsql") {
 
                        $string = "dbname=$db user=$user";
                                $string .= " host=$host";
                        }
 
-                       if (defined('DB_PORT')) {
-                               $string = "$string port=" . DB_PORT;
+                       if ($port) {
+                               $string = "$string port=" . $port;
                        }
 
                        $link = pg_connect($string);
                        return $link;
 
                } else if ($type == "mysql") {
-                       $link = mysql_connect($host, $user, $pass);
-                       if ($link) {
-                               $result = mysql_select_db($db, $link);
-                               if ($result) return $link;
+                       if (function_exists("mysqli_connect")) {
+                               if ($port)
+                                       return mysqli_connect($host, $user, $pass, $db, $port);
+                               else
+                                       return mysqli_connect($host, $user, $pass, $db);
+
+                       } else {
+                               $link = mysql_connect($host, $user, $pass);
+                               if ($link) {
+                                       $result = mysql_select_db($db, $link);
+                                       if ($result) return $link;
+                               }
                        }
                }
        }
                        }
                        return $result;
                } else if ($type == "mysql") {
-                       $result = mysql_query($query, $link);
+
+                       if (function_exists("mysqli_connect")) {
+                               $result = mysqli_query($link, $query);
+                       } else {
+                               $result = mysql_query($query, $link);
+                       }
                        if (!$result) {
                                $query = htmlspecialchars($query);
                                if ($die_on_error) {
-                                       die("Query <i>$query</i> failed: " . ($link ? mysql_error($link) : "No connection"));
+                                       die("Query <i>$query</i> failed: " . ($link ? function_exists("mysqli_connect") ? mysqli_error($link) : mysql_error($link) : "No connection"));
                                }
                        }
                        return $result;
        }
 
        function make_self_url_path() {
-               $url_path = ($_SERVER['HTTPS'] != "on" ? 'http://' :  'https://') . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
+               $url_path = ((!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") ? 'http://' :  'https://') . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
 
                return $url_path;
        }
 
 <fieldset>
        <label>Database name</label>
-       <input name="DB_NAME" size="20" value="<?php echo $DB_NAME ?>"/>
+       <input required name="DB_NAME" size="20" value="<?php echo $DB_NAME ?>"/>
 </fieldset>
 
 <fieldset>
        <label>Host name</label>
-       <input  name="DB_HOST" placeholder="if needed" size="20" value="<?php echo $DB_HOST ?>"/>
+       <input name="DB_HOST" size="20" value="<?php echo $DB_HOST ?>"/>
+       <span class="hint">If needed</span>
 </fieldset>
 
 <fieldset>
        <label>Port</label>
-       <input name="DB_PORT" type="number" placeholder="if needed, PgSQL only" size="20" value="<?php echo $DB_PORT ?>"/>
+       <input name="DB_PORT" type="number" size="20" value="<?php echo $DB_PORT ?>"/>
+       <span class="hint">Usually 3306 for MySQL or 5432 for PostgreSQL</span>
 </fieldset>
 
 <h2>Other settings</h2>
        <h2>Checking database</h2>
 
        <?php
-               $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE);
+               $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
 
                if (!$link) {
                        print_error("Unable to connect to database using specified parameters.");
                        <p>Before you can start using tt-rss, database needs to be initialized. Click on the button below to do that now.</p>
 
                        <?php
-                               $result = db_query($link, "SELECT true FROM ttrss_feeds", $DB_TYPE, false);
+                               $result = @db_query($link, "SELECT true FROM ttrss_feeds", $DB_TYPE, false);
 
                                if ($result) {
                                        print_error("Existing tt-rss tables will be removed from the database. If you would like to keep your data, skip database initialization.");
 
                } else if ($op == 'installschema' || $op == 'skipschema') {
 
-                       $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE);
+                       $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
 
                        if (!$link) {
                                print_error("Unable to connect to database using specified parameters.");