add search-to-label converter, ability to unsubscribe from label, various label fixes

This commit is contained in:
Andrew Dolgov 2006-08-01 08:54:46 +01:00
parent e939722a14
commit 88040f5795
4 changed files with 172 additions and 54 deletions

View File

@ -208,11 +208,12 @@
error_reporting (0); error_reporting (0);
$tmp_result = db_query($link, "SELECT count(id) as count $tmp_result = db_query($link, "SELECT count(ttrss_entries.id) as count
FROM ttrss_entries,ttrss_user_entries FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
WHERE (" . $line["sql_exp"] . ") AND unread = true AND WHERE (" . $line["sql_exp"] . ") AND unread = true AND
ttrss_user_entries.ref_id = ttrss_entries.id ttrss_user_entries.ref_id = ttrss_entries.id AND
AND owner_uid = '$owner_uid'"); ttrss_user_entries.feed_id = ttrss_feeds.id
AND ttrss_user_entries.owner_uid = '$owner_uid'");
$count = db_fetch_result($tmp_result, 0, "count"); $count = db_fetch_result($tmp_result, 0, "count");
@ -836,9 +837,17 @@
<a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)\">None</a> <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)\">None</a>
&nbsp;&nbsp; &nbsp;&nbsp;
Toggle: <a href='#' onclick=\"javascript:selectionToggleUnread()\">Unread</a>, Toggle: <a href='#' onclick=\"javascript:selectionToggleUnread()\">Unread</a>,
<a href='#' onclick=\"javascript:selectionToggleMarked()\">Starred</a>"; <a href='#' onclick=\"javascript:selectionToggleMarked()\">Starred</a>";
print "</td>"; print "</td>";
if ($search && $feed_id > 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) {
print "<td class=\"headlineActions$rtl_cpart\">
<a href=\"javascript:labelFromSearch('$search', '$search_mode',
'$match_on', '$feed_id', '$is_cat');\">
Convert this search to label</a></td>";
}
} else { } else {
print "<td class=\"headlineActions$rtl_cpart\"> print "<td class=\"headlineActions$rtl_cpart\">
@ -1430,13 +1439,23 @@
$ids = split(",", db_escape_string($_GET["ids"])); $ids = split(",", db_escape_string($_GET["ids"]));
foreach ($ids as $id) { foreach ($ids as $id) {
db_query($link, "DELETE FROM ttrss_feeds
WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
$icons_dir = ICONS_DIR; if ($id > 0) {
db_query($link, "DELETE FROM ttrss_feeds
WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
$icons_dir = ICONS_DIR;
if (file_exists($icons_dir . "/$id.ico")) { if (file_exists($icons_dir . "/$id.ico")) {
unlink($icons_dir . "/$id.ico"); unlink($icons_dir . "/$id.ico");
}
} else if ($id < -10) {
$label_id = -$id - 11;
db_query($link, "DELETE FROM ttrss_labels
WHERE id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
} }
} }
} }
@ -2228,11 +2247,12 @@
// print "<p><b>Expression</b>: $expr</p>"; // print "<p><b>Expression</b>: $expr</p>";
$result = db_query($link, $result = db_query($link,
"SELECT count(id) AS num_matches "SELECT count(ttrss_entries.id) AS num_matches
FROM ttrss_entries,ttrss_user_entries FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
WHERE ($expr) AND WHERE ($expr) AND
ttrss_user_entries.ref_id = ttrss_entries.id AND ttrss_user_entries.ref_id = ttrss_entries.id AND
owner_uid = " . $_SESSION["uid"]); ttrss_user_entries.feed_id = ttrss_feeds.id AND
ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
$num_matches = db_fetch_result($result, 0, "num_matches");; $num_matches = db_fetch_result($result, 0, "num_matches");;
@ -2241,12 +2261,13 @@
print "<p>Query returned <b>$num_matches</b> matches, showing first 15:</p>"; print "<p>Query returned <b>$num_matches</b> matches, showing first 15:</p>";
$result = db_query($link, $result = db_query($link,
"SELECT title, "SELECT ttrss_entries.title,
(SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
FROM ttrss_entries,ttrss_user_entries FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
WHERE ($expr) AND WHERE ($expr) AND
ttrss_user_entries.ref_id = ttrss_entries.id ttrss_user_entries.ref_id = ttrss_entries.id
AND owner_uid = " . $_SESSION["uid"] . " AND ttrss_user_entries.feed_id = ttrss_feeds.id
AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"] . "
ORDER BY date_entered DESC LIMIT 15"); ORDER BY date_entered DESC LIMIT 15");
print "<ul class=\"filterTestResults\">"; print "<ul class=\"filterTestResults\">";
@ -3724,6 +3745,56 @@
return false; return false;
} }
if ($op == "labelFromSearch") {
$search = db_escape_string($_GET["search"]);
$search_mode = db_escape_string($_GET["smode"]);
$match_on = db_escape_string($_GET["match"]);
$is_cat = db_escape_string($_GET["is_cat"]);
$title = db_escape_string($_GET["title"]);
$feed = sprintf("%d", $_GET["feed"]);
$label_qparts = array();
$search_expr = getSearchSql($search, $match_on);
if ($is_cat) {
if ($feed != 0) {
$search_expr .= " AND ttrss_feeds.cat_id = $feed ";
} else {
$search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
}
} else {
if ($search_mode == "all_feeds") {
// NOOP
} else if ($search_mode == "this_cat") {
$tmp_result = db_query($link, "SELECT cat_id
FROM ttrss_feeds WHERE id = '$feed'");
$cat_id = db_fetch_result($tmp_result, 0, "cat_id");
if ($cat_id > 0) {
$search_expr .= " AND ttrss_feeds.cat_id = $cat_id ";
} else {
$search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
}
} else {
$search_expr .= " AND ttrss_feeds.id = $feed ";
}
}
$search_expr = db_escape_string($search_expr);
print $search_expr;
if ($title) {
$result = db_query($link,
"INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')");
}
}
db_close($link); db_close($link);
?> ?>

View File

@ -1261,7 +1261,8 @@
} }
function catchup_feed($link, $feed, $cat_view) { function catchup_feed($link, $feed, $cat_view) {
if (preg_match("/^[0-9][0-9]*$/", $feed) != false && $feed >= 0) {
if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
if ($cat_view) { if ($cat_view) {
@ -1336,11 +1337,12 @@
"SELECT "SELECT
int_id int_id
FROM FROM
ttrss_user_entries,ttrss_entries ttrss_user_entries,ttrss_entries,ttrss_feeds
WHERE WHERE
ref_id = id AND ref_id = ttrss_entries.id AND
ttrss_user_entries.feed_id = ttrss_feeds.id AND
$sql_exp AND $sql_exp AND
owner_uid = " . $_SESSION["uid"]); ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
while ($tmp_line = db_fetch_assoc($tmp2_result)) { while ($tmp_line = db_fetch_assoc($tmp2_result)) {
db_query($link, "UPDATE db_query($link, "UPDATE
@ -1510,8 +1512,10 @@
if ($match_part) { if ($match_part) {
$result = db_query($link, "SELECT count(int_id) AS unread $result = db_query($link, "SELECT count(int_id) AS unread
FROM ttrss_user_entries FROM ttrss_user_entries,ttrss_feeds,ttrss_entries WHERE
WHERE unread = true AND $match_part AND owner_uid = " . $_SESSION["uid"]); ttrss_user_entries.feed_id = ttrss_feeds.id AND
ttrss_user_entries.ref_id = ttrss_entries.id AND
unread = true AND ($match_part) AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
} else { } else {
@ -1607,9 +1611,10 @@
$old_counters = $_SESSION["lctr_last_value"]; $old_counters = $_SESSION["lctr_last_value"];
$lctrs_modified = false; $lctrs_modified = false;
$result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries $result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
unread = true AND owner_uid = ".$_SESSION["uid"]); ttrss_user_entries.feed_id = ttrss_feeds.id AND
unread = true AND ttrss_user_entries.owner_uid = ".$_SESSION["uid"]);
$count = db_fetch_result($result, 0, "count"); $count = db_fetch_result($result, 0, "count");
@ -1631,10 +1636,11 @@
error_reporting (0); error_reporting (0);
$tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries $tmp_result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_user_entries,ttrss_entries,ttrss_feeds
WHERE (" . $line["sql_exp"] . ") AND unread = true AND WHERE (" . $line["sql_exp"] . ") AND unread = true AND
ttrss_user_entries.feed_id = ttrss_feeds.id AND
ttrss_user_entries.ref_id = ttrss_entries.id AND ttrss_user_entries.ref_id = ttrss_entries.id AND
owner_uid = ".$_SESSION["uid"]); ttrss_user_entries.owner_uid = ".$_SESSION["uid"]);
$count = db_fetch_result($tmp_result, 0, "count"); $count = db_fetch_result($tmp_result, 0, "count");
@ -1958,38 +1964,49 @@
print "</runtime-info>"; print "</runtime-info>";
} }
function getSearchSql($search, $match_on) {
$search_query_part = "";
$keywords = split(" ", $search);
$query_keywords = array();
if ($match_on == "both") {
foreach ($keywords as $k) {
array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%')
OR UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
}
$search_query_part = implode("AND", $query_keywords) . " AND ";
} else if ($match_on == "title") {
foreach ($keywords as $k) {
array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%'))");
}
$search_query_part = implode("AND", $query_keywords) . " AND ";
} else if ($match_on == "content") {
foreach ($keywords as $k) {
array_push($query_keywords, "(UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
}
}
$search_query_part = implode("AND", $query_keywords);
return $search_query_part;
}
function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false) { function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false) {
if ($search) { if ($search) {
$keywords = split(" ", $search); $search_query_part = getSearchSql($search, $match_on);
$query_keywords = array(); $search_query_part .= " AND ";
if ($match_on == "both") {
foreach ($keywords as $k) {
array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%')
OR UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
}
$search_query_part = implode("AND", $query_keywords) . " AND ";
} else if ($match_on == "title") {
foreach ($keywords as $k) {
array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%'))");
}
$search_query_part = implode("AND", $query_keywords) . " AND ";
} else if ($match_on == "content") {
foreach ($keywords as $k) {
array_push($query_keywords, "(UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
}
$search_query_part = implode("AND", $query_keywords) . " AND ";
}
} else { } else {
$search_query_part = ""; $search_query_part = "";
} }
@ -2161,6 +2178,10 @@
$result = db_query($link, "SELECT description FROM ttrss_labels $result = db_query($link, "SELECT description FROM ttrss_labels
WHERE id = '$label_id'"); WHERE id = '$label_id'");
$feed_title = db_fetch_result($result, 0, "description"); $feed_title = db_fetch_result($result, 0, "description");
if ($search) {
$feed_title = "Label search results ($search, $feed_title)";
}
} else { } else {
$feed_title = "?"; $feed_title = "?";
} }

View File

@ -571,3 +571,4 @@ function catchupCurrentFeed() {
return viewCurrentFeed(0, 'MarkAllRead') return viewCurrentFeed(0, 'MarkAllRead')
} }
} }

View File

@ -325,6 +325,31 @@ function catchupPage() {
selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
} }
function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
if (!xmlhttp_ready(xmlhttp_rpc)) {
printLockingError();
}
var title = prompt("Please enter label title:", "");
if (title) {
var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
"&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
"&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) +
"&title=" + param_escape(title);
debug("LFS: " + query);
xmlhttp_rpc.open("GET", query, true);
xmlhttp_rpc.onreadystatechange=getMainContext().dlg_frefresh_callback;
xmlhttp_rpc.send(null);
}
}
function init() { function init() {
if (arguments.callee.done) return; if (arguments.callee.done) return;
@ -341,5 +366,5 @@ function init() {
var bt = document.getElementById("headlineActionsBottom"); var bt = document.getElementById("headlineActionsBottom");
bt.className = "headlinesSubToolbar"; bt.className = "headlinesSubToolbar";
} }
} }