]> git.wh0rd.org - tt-rss.git/commitdiff
query themes from filesystem; obsolete ttrss_themes
authorAndrew Dolgov <fox@bah.org.ru>
Thu, 14 Jan 2010 10:39:05 +0000 (13:39 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Thu, 14 Jan 2010 10:39:05 +0000 (13:39 +0300)
functions.php
modules/pref-prefs.php
prefs.php
sanity_check.php
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
tt-rss.php

index 71f3cbb16a03e7339f84c6f072d87dd41cf5d0a7..ab779d3e00799b2d8868ec114383aa4d1ded44fd 100644 (file)
                                db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " . 
                                        $_SESSION["uid"]);
        
-                               $user_theme = get_user_theme_path($link);
-       
                                $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"];
                                $_SESSION["pwd_hash"] = db_fetch_result($result, 0, "pwd_hash");
        
                        $_SESSION["uid"] = 1;
                        $_SESSION["name"] = "admin";
 
-                       $user_theme = get_user_theme_path($link);
-       
                        $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"];
        
                        initialize_user_prefs($link, $_SESSION["uid"]);
                }
        }
 
-       function get_user_theme_path($link) {
+       function get_user_theme($link) {
 
                if (get_schema_version($link) >= 63) {
-                       $theme_id = (int) get_pref($link, "_THEME_ID");
+                       return get_pref($link, "_THEME_ID");
                } else {
-                       $theme_id = 1;
+                       return false;
                }
 
-               if (!$_SESSION["theme_path"][$theme_id]) {
-                       $result = db_query($link, "SELECT theme_path 
-                               FROM ttrss_themes       WHERE id = '$theme_id'");
-                       if (db_num_rows($result) != 0) {
-                               $theme = db_fetch_result($result, 0, "theme_path");
-                               $_SESSION["theme_path"][$theme_id] = $theme;
-                               return $theme;
+       }
+
+       function get_user_theme_path($link) {
+
+               if (get_schema_version($link) >= 63) {
+                       $theme_name = get_pref($link, "_THEME_ID");
+
+                       if ($theme_name) {
+                               $theme_path = "themes/$theme_name/";
                        } else {
-                               return null;
+                               $theme_name = '';
                        }
                } else {
-                       return $_SESSION["theme_path"][$theme_id];
+                       $theme_path = '';
+               }
+
+               return $theme_path;
+       }
+
+       function get_all_themes() {
+               $themes = glob("themes/*");
+
+               $rv = array();
+
+               foreach ($themes as $t) {
+                       if (is_file("$t/theme.ini")) {
+                               $ini = parse_ini_file("$t/theme.ini", true);
+                               if ($ini['theme']['version']) {
+                                       $entry = array();
+                                       $entry["path"] = $t;
+                                       $entry["base"] = basename($t);
+                                       $entry["name"] = $ini['theme']['name'];
+                                       $entry["version"] = $ini['theme']['version'];
+                                       $entry["author"] = $ini['theme']['author'];
+                                       array_push($rv, $entry);
+                               }
+                       }
                }
+
+               return $rv;
        }
 
        function smart_date_time($timestamp) {
                        }
                }
 
-               print "<param key=\"theme\" value=\"".get_user_theme_path($link)."\"/>";
+               print "<param key=\"theme\" value=\"".get_user_theme($link)."\"/>";
                print "<param key=\"daemon_enabled\" value=\"" . ENABLE_UPDATE_DAEMON . "\"/>";
                print "<param key=\"feeds_frame_refresh\" value=\"" . FEEDS_FRAME_REFRESH . "\"/>";
                print "<param key=\"daemon_refresh_only\" value=\"true\"/>";
 
                $num_tags = 0;
 
-/*             if (get_user_theme_path($link) == "3pane") {
+/*             if (get_user_theme($link) == "3pane") {
                        $tag_limit = 3;
                } else {
                        $tag_limit = 6;
index 367dfe406857c8d77d9387c3c16f5fb0b9824525..9b58cdbb49200cf4b60caba54ac077054318d5bd 100644 (file)
@@ -85,7 +85,7 @@
 
 //                     print_r($_POST);
 
-                       $orig_theme_id = get_pref($link, "_THEME_ID");
+                       $orig_theme = get_pref($link, "_THEME_ID");
 
                        foreach (array_keys($_POST) as $pref_name) {
                        
 
                        }
 
-                       if ($orig_theme_id != get_pref($link, "_THEME_ID")) {
-
-                               $result = db_query($link, "SELECT theme_path FROM ttrss_themes
-                                       WHERE id = '".get_pref($link, "_THEME_ID")."'");
-
-                               if (db_num_rows($result) == 1) {
-                                       $theme_path = db_fetch_result($result, 0, "theme_path");
-                               } else {
-                                       $theme_path = "";
-                               }
-
+                       if ($orig_theme != get_pref($link, "_THEME_ID")) {
                                print "PREFS_THEME_CHANGED";
                        } else {
                                print __("The configuration was saved.");
 
                                        if ($line["section_id"] == 2) {
                                                print "<tr><td width=\"40%\">".__("Select theme")."</td>";
+
+                                               $user_theme = get_pref($link, "_THEME_ID");
+                                               $themes = get_all_themes();
+
                                                print "<td><select name=\"_THEME_ID\">";
-                                               print "<option value='0'>".__('Default')."</option>";
+                                               print "<option value=''>".__('Default')."</option>";
                                                print "<option disabled>--------</option>";                             
-                       
-                                               $user_theme_id = get_pref($link, "_THEME_ID");
-                       
-                                               $tmp_result = db_query($link, "SELECT
-                                                       id,theme_name FROM ttrss_themes ORDER BY theme_name");
-                       
-                                               while ($tmp_line = db_fetch_assoc($tmp_result)) {       
-                                                       if ($tmp_line["id"] == $user_theme_id) {
-                                                               $selected = "selected";
+
+                                               foreach ($themes as $t) {
+                                                       $base = $t['base'];
+                                                       $name = $t['name'];
+
+                                                       if ($base == $user_theme) {
+                                                               $selected = "selected=\"1\"";
                                                        } else {
                                                                $selected = "";
                                                        }
-                                                       print "<option value=\"".$tmp_line["id"]."\" $selected>" . 
-                                                               $tmp_line["theme_name"] . "</option>";
+
+                                                       print "<option $selected value='$base'>$name</option>";
+
                                                }
+                       
                                                print "</select></td></tr>";
                                        }
 
index 656bdaf19b1c74a8b68e3b1c341a90a5aeeee461..9d2d0a846766c034f8e77cb1d3cefdc4daf98327 100644 (file)
--- a/prefs.php
+++ b/prefs.php
 
        <?php   $user_theme = get_user_theme_path($link);
                if ($user_theme) { ?>
-               <link rel="stylesheet" type="text/css" href="themes/<?php echo $user_theme ?>/theme.css"/>
+               <link rel="stylesheet" type="text/css" href="<?php echo $user_theme ?>/theme.css"/>
        <?php } ?>
-
-       <?php if ($user_theme) { $theme_image_path = "themes/$user_theme/"; } ?>
        
        <?php $user_css_url = get_pref($link, 'USER_STYLESHEET_URL'); ?>
        <?php if ($user_css_url) { ?>
@@ -96,7 +94,7 @@
                        | <a href="logout.php"><?php echo __('Logout') ?></a>
                <?php } ?>
        </div>
-       <img src="<?php echo $theme_image_path ?>images/ttrss_logo.png" alt="Tiny Tiny RSS"/>   
+       <img src="<?php echo $user_theme ?>images/ttrss_logo.png" alt="Tiny Tiny RSS"/> 
 </div>
 
 <div id="prefTabs">
index c50d391a11c271a7e17a043a75104f77155ba00f..e39902ef6ed7eee1c564b019f2e5eaf4954f9eb7 100644 (file)
@@ -2,7 +2,7 @@
        require_once "functions.php";
 
        define('EXPECTED_CONFIG_VERSION', 18);
-       define('SCHEMA_VERSION', 63);
+       define('SCHEMA_VERSION', 64);
 
        if (!file_exists("config.php")) {
                print "<b>Fatal Error</b>: You forgot to copy 
index 862ae3a428436eb5a93e75327480b2fb9e32e940..82284b8bf3affd9961f5985c1307b4f54cd0f149 100644 (file)
@@ -239,7 +239,7 @@ create table ttrss_tags (id integer primary key auto_increment,
 
 create table ttrss_version (schema_version int not null) TYPE=InnoDB;
 
-insert into ttrss_version values (63);
+insert into ttrss_version values (64);
 
 create table ttrss_enclosures (id integer primary key auto_increment,
        content_url text not null,
@@ -396,7 +396,7 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
 
 insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_MOBILE_SORT_FEEDS_UNREAD', 1, 'false', '', 1);
 
-insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_THEME_ID', 3, '0', '', 1);
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_THEME_ID', 2, '0', '', 1);
 
 create table ttrss_user_prefs (
    owner_uid integer not null,
index fb2ac18222fb7c10a8da73460dcd41f711741e37..3a27577f8b64cd12494b86785e883b7715b4bdb4 100644 (file)
@@ -211,7 +211,7 @@ create index ttrss_tags_owner_uid_index on ttrss_tags(owner_uid);
 
 create table ttrss_version (schema_version int not null);
 
-insert into ttrss_version values (63);
+insert into ttrss_version values (64);
 
 create table ttrss_enclosures (id serial not null primary key,
        content_url text not null,
@@ -360,7 +360,7 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
 
 insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_MOBILE_SORT_FEEDS_UNREAD', 1, 'false', '', 1);
 
-insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_THEME_ID', 3, '0', '', 1);
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_THEME_ID', 2, '0', '', 1);
 
 create table ttrss_user_prefs (
        owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
index 0cd784ee00c54bdbd12f5028b5e531ca9aad85ae..6226c05b8319baf0c1e3d80290261011e3c3fc91 100644 (file)
 
        <?php   $user_theme = get_user_theme_path($link);
                if ($user_theme) { ?>
-                       <link rel="stylesheet" type="text/css" href="themes/<?php echo $user_theme ?>/theme.css?<?php echo $dt_add ?>">
+                       <link rel="stylesheet" type="text/css" href="<?php echo $user_theme ?>/theme.css?<?php echo $dt_add ?>">
        <?php } ?>
 
-       <?php if ($user_theme) { $theme_image_path = "themes/$user_theme/"; } ?>
-
        <?php $user_css_url = get_pref($link, 'USER_STYLESHEET_URL'); ?>
        <?php if ($user_css_url) { ?>
                <link rel="stylesheet" type="text/css" href="<?php echo $user_css_url ?>"/> 
 
        </div>
 
-       <img src="<?php echo $theme_image_path ?>images/ttrss_logo.png" alt="Tiny Tiny RSS"/>   
+       <img src="<?php echo $user_theme ?>images/ttrss_logo.png" alt="Tiny Tiny RSS"/> 
 </div>
 
 <div id="feeds-holder">