From 0b126ac277ed5480ef6090ddc7a23a15d21f2960 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 7 Dec 2006 08:48:00 +0100 Subject: [PATCH] tag editor --- backend.php | 14 ++++----- functions.php | 17 +++++++++++ modules/backend-rpc.php | 40 +++++++++++++++++++++++++ modules/popup-dialog.php | 36 ++++++++++++++++++++++- tt-rss.js | 4 +++ viewfeed.js | 63 +++++++++++++++++++++++++++++++++++++++- 6 files changed, 165 insertions(+), 9 deletions(-) diff --git a/backend.php b/backend.php index ee8b089d..b1c0554b 100644 --- a/backend.php +++ b/backend.php @@ -223,7 +223,7 @@ print "" . $line["title"] . "$entry_author"; } else { - print "" . $line["title"] . "$entry_author"; + print "" . $line["title"] . "$entry_author"; } $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'), @@ -247,9 +247,9 @@ $tag = $tmp_line["tag_name"]; $tag_str = "$tag, "; - if ($num_tags == 5) { + if ($num_tags == 3) { $tags_str .= "..."; - } else if ($num_tags < 5) { + } else if ($num_tags < 3) { $tags_str .= $tag_str; } $f_tags_str .= $tag_str; @@ -260,18 +260,18 @@ // $truncated_link = truncate_string($line["link"], 60); - if ($tags_str || $entry_comments) { +# if ($tags_str || $entry_comments) { print " $entry_comments - $tags_str"; - } + $tags_str (+)"; +# } print ""; print "
" . $feed_icon . "
"; print "
"; - if (db_num_rows($tmp_result) > 5) { + if (db_num_rows($tmp_result) > 0) { print "
Tags: $f_tags_str
"; } diff --git a/functions.php b/functions.php index 83f37b61..7b5da022 100644 --- a/functions.php +++ b/functions.php @@ -3009,4 +3009,21 @@ } + function get_article_tags($link, $id) { + + $a_id = db_escape_string($id); + + $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM + ttrss_tags WHERE post_int_id = (SELECT int_id FROM ttrss_user_entries WHERE + ref_id = '$a_id' AND owner_uid = '".$_SESSION["uid"]."') ORDER BY tag_name"); + + $tags = array(); + + while ($tmp_line = db_fetch_assoc($tmp_result)) { + array_push($tags, $tmp_line["tag_name"]); + } + + return $tags; + } + ?> diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index 92fe2346..15359058 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -202,5 +202,45 @@ $key : $value "; } + + if ($subop == "setArticleTags") { + $id = db_escape_string($_GET["id"]); + $tags_str = db_escape_string($_GET["tags_str"]); + + $tags = split(",", $tags_str); + + db_query($link, "BEGIN"); + + $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE + ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); + + if (db_num_rows($result) == 1) { + + $int_id = db_fetch_result($result, 0, "int_id"); + + db_query($link, "DELETE FROM ttrss_tags WHERE + post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'"); + + foreach ($tags as $tag) { + $tag = trim($tag); + + if (preg_match("/^[0-9]*$/", $tag)) { + continue; + } + + if ($tag != '') { + db_query($link, "INSERT INTO ttrss_tags + (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')"); + } + } + } + + db_query($link, "COMMIT"); + + print " + $id + "; + + } } ?> diff --git a/modules/popup-dialog.php b/modules/popup-dialog.php index d3933ae7..a1ead2b0 100644 --- a/modules/popup-dialog.php +++ b/modules/popup-dialog.php @@ -1,7 +1,7 @@ Edit Tags
"; + print "
"; + + print "
"; + + print "Tags for this article (separated by commas):
"; + + $tags = get_article_tags($link, $param); + + $tags_str = join(", ", $tags); + + print ""; + + print ""; + + print "
"; + + print "
"; + + print " "; + + print ""; + + + print "
"; + + } + print "
"; } ?> diff --git a/tt-rss.js b/tt-rss.js index 1257f996..85616b4f 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -22,6 +22,10 @@ var init_params = new Object(); var op_history = new Array(); +function tagsAreDisplayed() { + return display_tags; +} + function toggleTags() { display_tags = !display_tags; diff --git a/viewfeed.js b/viewfeed.js index cc563449..5f338e46 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -1,6 +1,13 @@ var active_post_id = false; var _catchup_callback_func = false; var last_article_view = false; +var active_real_feed_id = false; + +var _tag_active_post_id = false; +var _tag_active_feed_id = false; + +// FIXME: kludge, needs proper implementation +var _reload_feedlist_after_view = false; function catchup_callback() { if (xmlhttp_rpc.readyState == 4) { @@ -47,7 +54,13 @@ function article_callback() { if (typeof correctPNG != 'undefined') { correctPNG(); } - update_all_counters(); + + if (_reload_feedlist_after_view) { + setTimeout('updateFeedList(false, false)', 50); + _reload_feedlist_after_view = false; + } else { + update_all_counters(); + } } } @@ -56,6 +69,8 @@ function view(id, feed_id, skip_history) { try { debug("loading article: " + id + "/" + feed_id); + active_real_feed_id = feed_id; + if (!skip_history) { history_push("ARTICLE:" + id + ":" + feed_id); } @@ -427,4 +442,50 @@ function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) { } +function editArticleTags(id, feed_id) { + _tag_active_post_id = id; + _tag_active_feed_id = feed_id; + displayDlg('editArticleTags', id); +} + + +function tag_saved_callback() { + if (xmlhttp_rpc.readyState == 4) { + try { + debug("in tag_saved_callback"); + + closeInfoBox(); + notify(""); + + if (tagsAreDisplayed()) { + _reload_feedlist_after_view = true; + } + + if (active_post_id == _tag_active_post_id) { + debug("reloading current article"); + view(_tag_active_post_id, _tag_active_feed_id); + } + + } catch (e) { + exception_error("catchup_callback", e); + } + } +} + +function editTagsSave() { + + if (!xmlhttp_ready(xmlhttp_rpc)) { + printLockingError(); + } + + notify("Saving article tags..."); + var form = document.forms["tag_edit_form"]; + + var query = Form.serialize("tag_edit_form"); + + xmlhttp_rpc.open("GET", "backend.php?op=rpc&subop=setArticleTags&" + query, true); + xmlhttp_rpc.onreadystatechange=tag_saved_callback; + xmlhttp_rpc.send(null); + +} -- 2.39.5