]> git.wh0rd.org Git - tt-rss.git/commitdiff
Extended Actions to include Select by tag (add local modifications, fix
authorCraig Meyer <meyercr@themeyers.org>
Thu, 11 Aug 2011 22:51:00 +0000 (18:51 -0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 23 Aug 2011 08:49:18 +0000 (12:49 +0400)
display for tags starting with a number)

backend.php
db.php
functions.js
functions.php
modules/popup-dialog.php
tt-rss.js
tt-rss.php

index cee1b6f07cb18ca09634d87eb88d659cab301c5b..9519fea43db0297c9d9de6c00e776637fcbabd89 100644 (file)
                        @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
                        $order_by = db_escape_string($_REQUEST["order_by"]);
 
+                       if (is_numeric($feed)) $feed = (int) $feed;
+
                        /* Feed -5 is a special case: it is used to display auxiliary information
                         * when there's nothing to load - e.g. no stuff in fresh feed */
 
                                $label_feed = -11-$feed;
                                $result = db_query($link, "SELECT id FROM ttrss_labels2 WHERE
                                        id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
-                       } else if (!$cat_view && $feed > 0) {
+                       } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
                                $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
                                        id = '$feed' AND owner_uid = " . $_SESSION['uid']);
-                       } else if ($cat_view && $feed > 0) {
+                       } else if ($cat_view && is_numeric($feed) && $feed > 0) {
                                $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE
                                        id = '$feed' AND owner_uid = " . $_SESSION['uid']);
                        }
diff --git a/db.php b/db.php
index 9b1ce5d84cc2319230d6d467a37b9d1208523fc4..81da431b9b58424e11929ba72fed60fe5236f50f 100644 (file)
--- a/db.php
+++ b/db.php
@@ -3,14 +3,14 @@
 require_once "config.php";
 
 function db_connect($host, $user, $pass, $db) {
-       if (DB_TYPE == "pgsql") {       
-                         
+       if (DB_TYPE == "pgsql") {
+
                $string = "dbname=$db user=$user";
-         
+
                if ($pass) {
-                       $string .= " password=$pass";   
+                       $string .= " password=$pass";
                }
-               
+
                if ($host) {
                        $string .= " host=$host";
                }
@@ -30,10 +30,10 @@ function db_connect($host, $user, $pass, $db) {
        } else if (DB_TYPE == "mysql") {
                $link = mysql_connect($host, $user, $pass);
                if ($link) {
-                       $result = mysql_select_db($db, $link);                  
+                       $result = mysql_select_db($db, $link);
                        if (!$result) {
                                die("Can't select DB: " . mysql_error($link));
-                       }                       
+                       }
                        return $link;
                } else {
                        die("Connection failed: " . mysql_error($link));
@@ -44,7 +44,7 @@ function db_connect($host, $user, $pass, $db) {
 function db_escape_string($s, $strip_tags = true) {
        if ($strip_tags) $s = strip_tags($s);
 
-       if (DB_TYPE == "pgsql") {       
+       if (DB_TYPE == "pgsql") {
                return pg_escape_string($s);
        } else {
                return mysql_real_escape_string($s);
@@ -57,7 +57,7 @@ function db_query($link, $query, $die_on_error = true) {
                if (!$result) {
                        $query = htmlspecialchars($query); // just in case
                        if ($die_on_error) {
-                               die("Query <i>$query</i> failed [$result]: " . pg_last_error($link));                   
+                               die("Query <i>$query</i> failed [$result]: " . pg_last_error($link));
                        }
                }
                return $result;
@@ -131,4 +131,8 @@ function db_last_error($link) {
        }
 }
 
+function db_quote($str){
+       return("'$str'");
+}
+
 ?>
index e8bd6af3399c495d97f3d99771ae7872be20ea35..1a06a9bf3c606d11bc06e1eb274258a3cd6880c5 100644 (file)
@@ -1619,4 +1619,54 @@ function showFeedsWithErrors() {
 
 }
 
+/* new support functions for SelectByTag */
 
+function get_all_tags(selObj){
+       try {
+               if( !selObj ) return "";
+
+               var result = "";
+               var len = selObj.options.length;
+
+               for (var i=0; i < len; i++){
+                       if (selObj.options[i].selected) {
+                               result += selObj[i].value + "%2C";   // is really a comma
+                       }
+               }
+
+               if (result.length > 0){
+                       result = result.substr(0, result.length-3);  // remove trailing %2C
+               }
+
+               return(result);
+
+       } catch (e) {
+               exception_error("get_all_tags", e);
+       }
+}
+
+function get_radio_checked(radioObj) {
+       try {
+               if (!radioObj) return "";
+
+               var len = radioObj.length;
+
+               if (len == undefined){
+                       if(radioObj.checked){
+                               return(radioObj.value);
+                       } else {
+                               return("");
+                       }
+               }
+
+               for( var i=0; i < len; i++ ){
+                       if( radioObj[i].checked ){
+                               return( radioObj[i].value);
+                       }
+               }
+
+       } catch (e) {
+               exception_error("get_radio_checked", e);
+       }
+       return("");
+}
index 694f5bef973e467de69686fc245e9f5e9ae64218..d6f116a8d1edec1d6e0b1c83bd10e324ab50e082 100644 (file)
                                }
 
                                // try to remove possible duplicates from feed counter cache
-                               ccache_cleanup($link, $_SESSION["uid"]);
+//                             ccache_cleanup($link, $_SESSION["uid"]);
                        }
 
                } else {
                                return "Unknown label ($label_id)";
                        }
 
-               } else if ($id > 0) {
+               } else if (is_numeric($id) && $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");
                return $search_query_part;
        }
 
+
        function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false) {
 
                if (!$owner_uid) $owner_uid = $_SESSION["uid"];
                                if ($cat_view) {
                                        $feed_title = getCategoryTitle($link, $feed);
                                } else {
-                                       if ((int)$feed == $feed && $feed > 0) {
+                                       if (is_numeric($feed) && $feed > 0) {
                                                $result = db_query($link, "SELECT title,site_url,last_error
                                                        FROM ttrss_feeds WHERE id = '$feed' AND owner_uid = $owner_uid");
 
                        } else {
                                // browsing by tag
 
+                               $select_qpart = "SELECT DISTINCT " .
+                                                               "date_entered," .
+                                                               "guid," .
+                                                               "note," .
+                                                               "ttrss_entries.id as id," .
+                                                               "title," .
+                                                               "updated," .
+                                                               "unread," .
+                                                               "feed_id," .
+                                                               "orig_feed_id," .
+                                                               "marked," .
+                                                               "link," .
+                                                               "last_read," .
+                                                               SUBSTRING_FOR_DATE . "(last_read,1,19) as last_read_noms," .
+                                                               $vfeed_query_part .
+                                                               $content_query_part .
+                                                               SUBSTRING_FOR_DATE . "(updated,1,19) as updated_noms," .
+                                                               "score ";
+
                                $feed_kind = "Tags";
+                               $all_tags = explode(",", $feed);
+                               if ($search_mode == 'any') {
+                                       $tag_sql = "tag_name in (" . implode(", ", array_map("db_quote", $all_tags)) . ")";
+                                       $from_qpart = " FROM ttrss_entries,ttrss_user_entries,ttrss_tags ";
+                                       $where_qpart = " WHERE " .
+                                                                  "ref_id = ttrss_entries.id AND " .
+                                                                  "ttrss_user_entries.owner_uid = $owner_uid AND " .
+                                                                  "post_int_id = int_id AND $tag_sql AND " .
+                                                                  $view_query_part .
+                                                                  $search_query_part .
+                                                                  $query_strategy_part . " ORDER BY $order_by " .
+                                                                  $limit_query_part;
 
-                               $result = db_query($link, "SELECT DISTINCT
-                                       date_entered,
-                                       guid,
-                                       note,
-                                       ttrss_entries.id as id,title,
-                                       updated,
-                                       unread,feed_id,orig_feed_id,
-                                       marked,link,last_read,
-                                       ".SUBSTRING_FOR_DATE."(last_read,1,19) as last_read_noms,
-                                       $vfeed_query_part
-                                       $content_query_part
-                                       ".SUBSTRING_FOR_DATE."(updated,1,19) as updated_noms,
-                                       score
-                                       FROM
-                                               ttrss_entries,ttrss_user_entries,ttrss_tags
-                                       WHERE
-                                               ref_id = ttrss_entries.id AND
-                                               ttrss_user_entries.owner_uid = '$owner_uid' AND
-                                               post_int_id = int_id AND tag_name = '$feed' AND
-                                               $view_query_part
-                                               $search_query_part
-                                               $query_strategy_part ORDER BY $order_by
-                                       $limit_query_part");
+                               } else {
+                                       $i = 1;
+                                       $sub_selects = array();
+                                       $sub_ands = array();
+                                       foreach ($all_tags as $term) {
+                                               array_push($sub_selects, "(SELECT post_int_id from ttrss_tags WHERE tag_name = " . db_quote($term) . " AND owner_uid = $owner_uid) as A$i");
+                                               $i++;
+                                       }
+                                       if ($i > 2) {
+                                               $x = 1;
+                                               $y = 2;
+                                               do {
+                                                       array_push($sub_ands, "A$x.post_int_id = A$y.post_int_id");
+                                                       $x++;
+                                                       $y++;
+                                               } while ($y < $i);
+                                       }
+                                       array_push($sub_ands, "A1.post_int_id = ttrss_user_entries.int_id and ttrss_user_entries.owner_uid = $owner_uid");
+                                       array_push($sub_ands, "ttrss_user_entries.ref_id = ttrss_entries.id");
+                                       $from_qpart = " FROM " . implode(", ", $sub_selects) . ", ttrss_user_entries, ttrss_entries";
+                                       $where_qpart = " WHERE " . implode(" AND ", $sub_ands);
+                               }
+                               //                              error_log("TAG SQL: " . $tag_sql);
+                               // $tag_sql = "tag_name = '$feed'";   DEFAULT way
+
+                               //                              error_log("[". $select_qpart . "][" . $from_qpart . "][" .$where_qpart . "]");
+                               $result = db_query($link, $select_qpart . $from_qpart . $where_qpart);
                        }
 
                        return array($result, $feed_title, $feed_site_url, $last_error);
                        catchupArticlesById($link, $ids, $cmode);
                } */
 
-               if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
+               if ($subop == "ForceUpdate" && $feed && is_numeric($feed) > 0) {
                        update_rss_feed($link, $feed, true);
                }
 
 
                // FIXME: might break tag display?
 
-               if ($feed > 0 && !$cat_view) {
+               if (is_numeric($feed) && $feed > 0 && !$cat_view) {
                        $result = db_query($link,
                                "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
 
 
                if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
 
+//             error_log("format_headlines_list: [" . $feed . "] subop [" . $subop . "]");
+               if( $search_mode == '' && $subop != '' ){
+                   $search_mode = $subop;
+               }
+//             error_log("search_mode: " . $search_mode);
                $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view,
                        $search, $search_mode, $match_on, $override_order, $offset);
 
index 6cb60eef43fa53edbdb06ade74309e202978c48a..4d2408d15197795718abb136f4d42b9446665d09 100644 (file)
                        print "</div>";
 
                        print "]]></content>";
+               }
 
-                       //return;
+               if ($id == 'printTagSelect') {
+                       print "<title>" . __('Select item(s) by tags') . "</title>";
+                       print "<content><![CDATA[";
+
+                       print __("Match:"). "&nbsp;" .
+                                 "<input class=\"noborder\" dojoType=\"dijit.form.RadioButton\" type=\"radio\" checked value=\"any\" name=\"tag_mode\">&nbsp;Any&nbsp;";
+                       print "<input class=\"noborder\" dojoType=\"dijit.form.RadioButton\" type=\"radio\" value=\"all\" name=\"tag_mode\">&nbsp;All&nbsp;";
+                       print "&nbsp;tags.";
+
+                       print "<select id=\"all_tags\" name=\"all_tags\" title=\"" . __('Which Tags?') . "\" multiple=\"multiple\" size=\"10\" style=\"width : 100%\">";
+                       $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags WHERE owner_uid = ".$_SESSION['uid']."
+                               AND LENGTH(tag_name) <= 30 ORDER BY tag_name ASC");
+
+                       while ($row = db_fetch_assoc($result)) {
+                               $tmp = htmlspecialchars($row["tag_name"]);
+                               print "<option value=\"" . str_replace(" ", "%20", $tmp) . "\">$tmp</option>";
+                       }
+
+                       print "</select>";
+
+                       print "<div align='right'>";
+                       print "<button dojoType=\"dijit.form.Button\" onclick=\"viewfeed(get_all_tags($('all_tags')),
+                               get_radio_checked($('tag_mode')));\">" . __('Display entries') . "</button>";
+                       print "&nbsp;";
+                       print "<button dojoType=\"dijit.form.Button\"
+                       onclick=\"return closeInfoBox()\">" .
+                               __('Close this window') . "</button>";
+                       print "</div>";
+
+                       print "]]></content>";
                }
 
                if ($id == "emailArticle") {
index d613b7d49670f333139cef1ab2e8a424f56b244f..7987be7ab5bce1dd8ab83168c7e44c1dc5cfa1e1 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -350,6 +350,10 @@ function quickMenuGo(opid) {
                        displayDlg("printTagCloud");
                }
 
+               if (opid == "qmcTagSelect") {
+                       displayDlg("printTagSelect");
+               }
+
                if (opid == "qmcSearch") {
                        search();
                        return;
index 16b15e84af9efa0f3de39e158c28de4d9149ba96..65dcdde830cd59fa25d713a7ec9ed33e99ce5b5c 100644 (file)
                                        <div dojoType="dijit.MenuItem" disabled="1"><?php echo __('Other actions:') ?></div>
                                        <div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcDigest')"><?php echo __('Switch to digest...') ?></div>
                                        <div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcTagCloud')"><?php echo __('Show tag cloud...') ?></div>
+                                       <div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcTagSelect')"><?php echo __('Select by tags...') ?></div>
                                        <div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcAddLabel')"><?php echo __('Create label...') ?></div>
                                        <div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcAddFilter')"><?php echo __('Create filter...') ?></div>
                                        <div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcHKhelp')"><?php echo __('Keyboard shortcuts help') ?></div>