]> git.wh0rd.org Git - tt-rss.git/commitdiff
mobile: add preferences
authorAndrew Dolgov <fox@bah.org.ru>
Fri, 18 Dec 2009 10:01:02 +0000 (13:01 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Fri, 18 Dec 2009 10:01:02 +0000 (13:01 +0300)
mobile/backend.php
mobile/functions.php
mobile/index.php
mobile/mobile.js
mobile/prefs.php [new file with mode: 0644]

index c6b75c51b790ed726cada859ece5a2eb2a265761..85018c58048db12769a79fc7c8da38a892898899 100644 (file)
 
                publishArticlesById($link, array($id), $cmode);
                break;
+       case "setPref":
+               $id = db_escape_string($_REQUEST["id"]);
+               $value = db_escape_string($_REQUEST["to"]);
+               mobile_set_pref($link, $id, $value);
+               print_r($_SESSION);
+               break;
        default:
                print json_encode(array("error", "UNKNOWN_METHOD"));
                break;
index 1806e0eda3bc04f7d706d47820f50a447c012920..ff0510dcd4904aa40d2b047af40b1f2f8b166188 100644 (file)
@@ -1,6 +1,21 @@
 <?php
        define('TTRSS_SESSION_NAME', 'ttrss_m_sid');
 
+       /* TODO replace with interface to db-prefs */
+
+       function mobile_pref_toggled($link, $id) {
+               if ($_SESSION["mobile-prefs"][$id]) return "true";
+
+       }
+
+       function mobile_get_pref($link, $id) {
+               return $_SESSION["mobile-prefs"][$id];
+       }
+
+       function mobile_set_pref($link, $id, $value) {
+               $_SESSION["mobile-prefs"][$id] = $value;
+       }
+
        function mobile_feed_has_icon($id) {
                $filename = "../".ICONS_DIR."/$id.ico";
 
        function render_flat_feed_list($link) {
                $owner_uid = $_SESSION["uid"];
 
+               if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
+                       $order_by = "unread DESC, title";
+               } else {
+                       $order_by = "title";
+               }
+
                $result = db_query($link, "SELECT id,
                                title,
                        (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
                                ttrss_feeds.hidden = false AND
                                ttrss_feeds.owner_uid = '$owner_uid' AND 
                                parent_feed IS NULL
-                       ORDER BY unread DESC,title"); 
+                       ORDER BY $order_by"); 
        
-                       print '<ul id="home" title="Feeds" selected="true">';
+               print '<ul id="home" title="Feeds" selected="true"
+                       myBackLabel="Logout" myBackHref="logout.php" myBackTarget="_self">';
 
        //              print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>";
        
                                } else {
                                        $icon_url = "../images/blank_icon.gif";
                                }
-       
-                               print "<li class='$class'><a href='feed.php?id=$id'>" . 
-                                       "<img class='tinyIcon' src='$icon_url'/>".                              
-                                       $line["title"] . "</a></li>";
+
+                               if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
+                                       print "<li class='$class'><a href='feed.php?id=$id'>" . 
+                                               "<img class='tinyIcon' src='$icon_url'/>".                              
+                                               $line["title"] . "</a></li>";
+                               }
                        }
        
                        print "</ul>";
                        } else {
                                $cat_query = "cat_id IS NULL";
                        }
-       
+
+                       if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
+                               $order_by = "unread DESC, title";
+                       } else {
+                               $order_by = "title";
+                       }
+
                        $result = db_query($link, "SELECT id,
                                title,
                        (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
                                ttrss_feeds.owner_uid = '$owner_uid' AND 
                                parent_feed IS NULL AND
                                $cat_query
-                       ORDER BY unread DESC,title"); 
+                       ORDER BY $order_by"); 
                        
                        $title = getCategoryTitle($link, $cat_id);
        
                                } else {
                                        $icon_url = "../images/blank_icon.gif";
                                }
-       
-                               print "<li class='$class'><a href='feed.php?id=$id&cat=$cat_id'>" . 
-                                       "<img class='tinyIcon' src='$icon_url'/>".                              
-                                       $line["title"] . "</a></li>";
+
+                               if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
+                                       print "<li class='$class'><a href='feed.php?id=$id&cat=$cat_id'>" . 
+                                               "<img class='tinyIcon' src='$icon_url'/>".                              
+                                               $line["title"] . "</a></li>";
+                               }
                        }
        
                        print "</ul>";
                                        $class = 'oldItem';
                                }
 
-                               print "<li class='$class'>
-                                       <a href='feed.php?id=$id&cat_id=-1'>$title</a></li>";
+                               if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
+                                       print "<li class='$class'>
+                                               <a href='feed.php?id=$id&cat_id=-1'>$title</a></li>";
+                               }
                        }
 
                        print "</ul>";
                                        $class = 'oldItem';
                                }
 
-                               print "<li class='$class'>
-                                       <a href='feed.php?id=$id&cat=-2'>$title</a></li>";
-
+                               if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
+                                       print "<li class='$class'>
+                                               <a href='feed.php?id=$id&cat=-2'>$title</a></li>";
+                               }
                        }
                        print "</ul>";
                }
                $owner_uid = $_SESSION["uid"];
 
 
-               print '<ul id="home" title="Feeds" selected="true">';
+               print '<ul id="home" title="'.__('Categories').'" selected="true"
+                       myBackLabel="Logout" myBackHref="logout.php" myBackTarget="_self">';
 
                foreach (array(-1, -2) as $id) {
                        $title = getCategoryTitle($link, $id);
                                        ttrss_feed_categories.title
                                ORDER BY ttrss_feed_categories.title");
 
-               $cat_ids = array();
-
                while ($line = db_fetch_assoc($result)) {
 
                        if ($line["num_feeds"] > 0) {
                                } else {
                                        $class = 'oldItem';
                                }
-                               
-
-                               print "<li class='$class'><a href='cat.php?id=$id'>" . 
-                                       $line["title"] . "</a></li>";
-
-                               array_push($cat_ids, $id);
 
+                               if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
+                                       print "<li class='$class'><a href='cat.php?id=$id'>" . 
+                                               $line["title"] . "</a></li>";
+                               }
                        }
                }
 
                                $class = 'oldItem';
                        }
 
-                       array_push($cat_ids, 0);
-
-                       print "<li class='$class'><a href='cat.php?id=0'>$title</a></li>";
+                       if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
+                               print "<li class='$class'><a href='cat.php?id=0'>$title</a></li>";
+                       }
                }
 
                print "</ul>";
                        $content = sanitize_rss($link, $line["content"]);
                        $content = preg_replace("/href=/i", "target=\"_blank\" href=", $content);
 
+                       if (!mobile_get_pref($link, "SHOW_IMAGES")) {
+                               $content = preg_replace('/<img[^>]+>/is', '', $content);
+                       }
+
                        print "<p>$content</p>";
 
                        print "<fieldset>";
                        print "</div>";
 
                }
-
        }
 ?>
index 3b933f96d882c16cc93b06dffcedaa602e47f434..a530d0e8bc4fb5f41886baf5b6259cc719a6a680 100644 (file)
@@ -65,7 +65,7 @@
     <div class="toolbar">
         <h1 id="pageTitle"></h1>
                  <a id="myBackButton" class="button" href="#"></a>
-        <a class="button"  target="_self" href="logout.php">Logout</a>
+        <a class="button" href="prefs.php">Preferences</a>
     </div>
 
        <?php    
index 655987cee947d4aff7886338e8bc41da953e03ec..669e63d091eed15a6236849d1f0db13a37a30c27 100644 (file)
@@ -39,3 +39,22 @@ function togglePublished(id, elem) {
 
 }
 
+function setPref(elem) {
+       var toggled = false;
+       var id = elem.id;
+
+       if (elem.getAttribute("toggled") == "true") {
+               toggled = 1;
+       } else {
+               toggled = 0;
+       }
+
+       var query = "?op=setPref&id=" + id + "&to=" + toggled;
+
+       new Ajax.Request(backend, {
+               parameters: query,
+               onComplete: function (transport) {
+                       //
+               } });
+
+}
diff --git a/mobile/prefs.php b/mobile/prefs.php
new file mode 100644 (file)
index 0000000..b004b15
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+       error_reporting(E_ERROR | E_WARNING | E_PARSE);
+
+       header('Content-Type: text/html; charset=utf-8');
+
+       define('MOBILE_VERSION', true);
+
+       require_once "../config.php";
+       require_once "functions.php";
+       require_once "../functions.php"; 
+
+       require_once "../sessions.php";
+
+       require_once "../version.php"; 
+       require_once "../db-prefs.php";
+
+       $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
+
+       init_connection($link);
+
+       login_sequence($link, true);
+?>
+
+<div class="panel" id="prefs" selected="yes" title="Preferences"
+       myBackLabel="Feeds" myBackHref="home.php">
+
+<fieldset>
+<div class="row">
+       <label>Hide read items</label>
+       <div class="toggle" id="HIDE_READ" onclick="setPref(this)" toggled="<?php echo mobile_pref_toggled($link, "HIDE_READ") ?>"><span class="thumb"></span><span class="toggleOn">ON</span><span class="toggleOff">OFF</span></div>
+</div>
+
+<div class="row">
+       <label>Sort feeds by unread</label>
+       <div class="toggle" id="SORT_FEEDS_UNREAD" onclick="setPref(this)" toggled="<?php echo mobile_pref_toggled($link, "SORT_FEEDS_UNREAD") ?>"><span class="thumb"></span><span class="toggleOn">ON</span><span class="toggleOff">OFF</span></div>
+</div>
+
+<div class="row">
+       <label>Show images</label>
+       <div class="toggle" id="SHOW_IMAGES" onclick="setPref(this)" toggled="<?php echo mobile_pref_toggled($link, "SHOW_IMAGES") ?>"><span class="thumb"></span><span class="toggleOn">ON</span><span class="toggleOff">OFF</span></div>
+</div>
+
+</fieldset>