]> git.wh0rd.org - tt-rss.git/blobdiff - functions.php
move some cookies to init-params
[tt-rss.git] / functions.php
index 343315eb175d0aa1f0a7adc9eec4933210e1ae8d..30f309dd3c8ba4d9bf26fab1367f4b68f416df47 100644 (file)
        }
 
        function print_select($id, $default, $values, $attributes = "") {
-               print "<select id=\"$id\" $attributes>";
+               print "<select name=\"$id\" id=\"$id\" $attributes>";
                foreach ($values as $v) {
                        if ($v == $default)
                                $sel = " selected";
                print "</select>";
        }
 
-       function print_select_hash($id, $values, $default, $attributes = "") {
-               print "<select id='$id' $attributes>";
+       function print_select_hash($id, $default, $values, $attributes = "") {
+               print "<select name=\"$id\" id='$id' $attributes>";
                foreach (array_keys($values) as $v) {
                        if ($v == $default)
                                $sel = "selected";
 
        function basic_nosid_redirect_check() {
                if (!SINGLE_USER_MODE) {
-                       if (!$_COOKIE["ttrss_sid"]) {
+                       if (!$_COOKIE[get_session_cookie_name()]) {
                                $redirect_uri = get_login_redirect();
                                $return_to = preg_replace('/.*?\//', '', $_SERVER["REQUEST_URI"]);
                                header("Location: $redirect_uri?rt=$return_to");
        function print_feed_select($link, $id, $default_id = "", 
                $attributes = "", $include_all_feeds = true) {
 
-               print "<select id=\"$id\" $attributes>";
+               print "<select id=\"$id\" name=\"$id\" $attributes>";
                if ($include_all_feeds) { 
-                       print "<option id=\"0\">All feeds</option>";
+                       print "<option value=\"0\">All feeds</option>";
                }
        
                $result = db_query($link, "SELECT id,title FROM ttrss_feeds
                        } else {
                                $is_selected = "";
                        }
-                       printf("<option $is_selected id='%d'>%s</option>", 
-                               $line["id"], db_unescape_string($line["title"]));
+                       printf("<option $is_selected value='%d'>%s</option>", 
+                               $line["id"], htmlspecialchars(db_unescape_string($line["title"])));
                }
        
                print "</select>";
        function print_feed_cat_select($link, $id, $default_id = "", 
                $attributes = "", $include_all_cats = true) {
                
-               print "<select id=\"$id\" $attributes>";
+               print "<select id=\"$id\" name=\"$id\" $attributes>";
 
                if ($include_all_cats) {
-                       print "<option id=\"0\">Uncategorized</option>";
+                       print "<option value=\"0\">Uncategorized</option>";
                }
 
                $result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
                        } else {
                                $is_selected = "";
                        }
-                       printf("<option $is_selected id='%d'>%s</option>", 
-                               $line["id"], $line["title"]);
+                       printf("<option $is_selected value='%d'>%s</option>", 
+                               $line["id"], htmlspecialchars(db_unescape_string($line["title"])));
                }
 
                print "</select>";
        }
        
+       function checkbox_to_sql_bool($val) {
+               return ($val == "on") ? "true" : "false";
+       }
+
+       function getFeedCatTitle($link, $id) {
+               if ($id == -1) {
+                       return "Special";
+               } else if ($id < -10) {
+                       return "Labels";
+               } else if ($id > 0) {
+                       $result = db_query($link, "SELECT ttrss_feed_categories.title 
+                               FROM ttrss_feeds, ttrss_feed_categories WHERE ttrss_feeds.id = '$id' AND
+                                       cat_id = ttrss_feed_categories.id");
+                       if (db_num_rows($result) == 1) {
+                               return db_fetch_result($result, 0, "title");
+                       } else {
+                               return "Uncategorized";
+                       }
+               } else {
+                       return "getFeedCatTitle($id) failed";
+               }
+
+       }
+
+       function getFeedTitle($link, $id) {
+               if ($id == -1) {
+                       return "Starred articles";
+               } else if ($id < -10) {
+                       $label_id = -10 - $id;
+                       $result = db_query($link, "SELECT description FROM ttrss_labels WHERE id = '$label_id'");
+                       if (db_num_rows($result) == 1) {
+                               return db_fetch_result($result, 0, "description");
+                       } else {
+                               return "Unknown label ($label_id)";
+                       }
+
+               } else if ($id > 0) {
+                       $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$id'");
+                       if (db_num_rows($result) == 1) {
+                               return db_fetch_result($result, 0, "title");
+                       } else {
+                               return "Unknown feed ($id)";
+                       }
+               } else {
+                       return "getFeedTitle($id) failed";
+               }
+
+       }
+
+       function get_session_cookie_name() {
+               return ((!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid" : TTRSS_SESSION_NAME);
+       }
+
+       function print_init_params($link) {
+               print "<init-params>";
+               if ($_SESSION["stored-params"]) {
+                       foreach (array_keys($_SESSION["stored-params"]) as $key) {
+                               $value = htmlspecialchars($_SESSION["stored-params"][$key]);
+                               print "<param key=\"$key\" value=\"$value\"/>";
+                       }
+               }
+
+               print "<param key=\"daemon_enabled\" value=\"" . ENABLE_UPDATE_DAEMON . "\"/>";
+               print "<param key=\"feeds_frame_refresh\" value=\"" . FEEDS_FRAME_REFRESH . "\"/>";
+
+               print "<param key=\"on_catchup_show_next_feed\" value=\"" . 
+                       get_pref($link, "ON_CATCHUP_SHOW_NEXT_FEED") . "\"/>";
+
+               print "</init-params>";
+       }
 ?>