From 5161564f3d70d1434bc6f7469217de45bb272ff8 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 6 Mar 2009 13:40:59 +0300 Subject: add support for adding syndicated notes to published articles --- functions.php | 78 ++++++++++++++++++++++++++++++++++++------ images/art-pub-note.png | Bin 0 -> 338 bytes modules/backend-rpc.php | 29 +++++++++++++--- sanity_check.php | 2 +- schema/ttrss_schema_mysql.sql | 3 +- schema/ttrss_schema_pgsql.sql | 3 +- schema/versions/mysql/55.sql | 7 ++++ schema/versions/pgsql/55.sql | 7 ++++ tt-rss.css | 25 ++++++++++++++ viewfeed.js | 61 ++++++++++++++++++++++++++++++--- 10 files changed, 193 insertions(+), 22 deletions(-) create mode 100755 images/art-pub-note.png create mode 100644 schema/versions/mysql/55.sql create mode 100644 schema/versions/pgsql/55.sql diff --git a/functions.php b/functions.php index 60a4a4bfd..d5c231b83 100644 --- a/functions.php +++ b/functions.php @@ -3405,6 +3405,7 @@ guid, ttrss_entries.id,ttrss_entries.title, updated, + note, unread,feed_id,marked,published,link,last_read, ".SUBSTRING_FOR_DATE."(last_read,1,19) as last_read_noms, $vfeed_query_part @@ -3435,6 +3436,7 @@ $result = db_query($link, "SELECT guid, + note, ttrss_entries.id as id,title, updated, unread,feed_id, @@ -3463,6 +3465,10 @@ function generate_syndicated_feed($link, $owner_uid, $feed, $is_cat, $limit, $search, $search_mode, $match_on) { + $note_style = "background-color : #fff7d5; border-width : 1px; ". + "padding : 5px; border-style : dashed; border-color : #e7d796;". + "margin-top : 5px; color : #9a8c59;"; + if (!$limit) $limit = 30; $qfh_ret = queryFeedHeadlines($link, $feed, @@ -3502,8 +3508,14 @@ print "" . htmlspecialchars($line["title"]) . ""; - print ""; + print ""; + print $line["note"]; + print ""; + } + print "]]>"; print ""; } @@ -4525,7 +4537,8 @@ ".SUBSTRING_FOR_DATE."(updated,1,16) as updated, (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url, num_comments, - author + author, + note FROM ttrss_entries,ttrss_user_entries WHERE id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]); @@ -4599,7 +4612,7 @@ if (!$entry_comments) $entry_comments = " "; # placeholder print "
- Tags"; + Tags "; if (!$zoom_mode) { print "$tags_str @@ -4619,6 +4632,14 @@ style=\"cursor : pointer\" style=\"cursor : pointer\" onclick=\"zoomToArticle($id)\" alt='Zoom' title='".__('Show article summary in new window')."'>"; + + $note_escaped = htmlspecialchars($line['note'], ENT_QUOTES); + + print "PubNote"; + } print "
"; print "
$entry_comments
"; @@ -4638,6 +4659,12 @@ print $article_content; + print "
"; + if ($line['note']) { + print format_article_note($id, $line['note']); + } + print "
"; + $result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE post_id = '$id' AND content_url != ''"); @@ -5174,6 +5201,13 @@ // print "
"; print sanitize_rss($link, $line["content_preview"]); + + print "
"; + if ($line['note']) { + print format_article_note($id, $line['note']); + } + print "
"; + $article_content = $line["content_preview"]; $e_result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE @@ -5258,13 +5292,22 @@ " "; - print "$marked_pic "; - print "$published_pic "; - print "$marked_pic "; + print "$published_pic "; + print "Zoom"; + title='".__('Show article summary in new window')."'> "; + + $note_escaped = htmlspecialchars($line['note'], ENT_QUOTES); + + print "PubNote"; + + print ""; $tags_str = format_tags_string(get_article_tags($link, $id), $id); @@ -5278,9 +5321,9 @@ print ""; - print "Toggle: - Unread"; + ".__('toggle unread').""; print "
"; print ""; @@ -6062,4 +6105,19 @@ return $labels_str; } + + function format_article_note($id, $note) { + + $note_escaped = htmlspecialchars($note, ENT_QUOTES); + + $str = "
"; + $str .= "
"; + $str .= "". + __('edit note').""; + $str .= "
"; + $str .= $note; + $str .= "
"; + + return $str; + } ?> diff --git a/images/art-pub-note.png b/images/art-pub-note.png new file mode 100755 index 000000000..b9228a5dd Binary files /dev/null and b/images/art-pub-note.png differ diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index afcd82d3f..8b22bf850 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -87,8 +87,9 @@ } if ($subop == "publ") { - $pub = $_GET["pub"]; - $id = db_escape_string($_GET["id"]); + $pub = $_REQUEST["pub"]; + $id = db_escape_string($_REQUEST["id"]); + $note = trim(strip_tags(db_escape_string($_REQUEST["note"]))); if ($pub == "1") { $pub = "true"; @@ -96,18 +97,36 @@ $pub = "false"; } + if ($note != 'undefined') { + $note_qpart = "note = '$note',"; + } + // FIXME this needs collision testing - $result = db_query($link, "UPDATE ttrss_user_entries SET published = $pub + $result = db_query($link, "UPDATE ttrss_user_entries SET + $note_qpart + published = $pub WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); - print ""; + + print ""; + + print ""; getGlobalCounters($link); getLabelCounters($link); if (get_pref($link, 'ENABLE_FEED_CATS')) { getCategoryCounters($link); } - print ""; + print ""; + + if ($note != 'undefined') { + $note_size = strlen($note); + print ""; + print ""; + print ""; + } + + print ""; return; } diff --git a/sanity_check.php b/sanity_check.php index e813f3680..51dc1b5f8 100644 --- a/sanity_check.php +++ b/sanity_check.php @@ -2,7 +2,7 @@ require_once "functions.php"; define('EXPECTED_CONFIG_VERSION', 18); - define('SCHEMA_VERSION', 54); + define('SCHEMA_VERSION', 55); if (!file_exists("config.php")) { print "Fatal Error: You forgot to copy diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index 65e4ffb45..ac057fd5d 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -138,6 +138,7 @@ create table ttrss_user_entries ( published bool not null default 0, last_read datetime, score int not null default 0, + note text, unread bool not null default 1, index (ref_id), foreign key (ref_id) references ttrss_entries(id) ON DELETE CASCADE, @@ -224,7 +225,7 @@ create table ttrss_tags (id integer primary key auto_increment, create table ttrss_version (schema_version int not null) TYPE=InnoDB; -insert into ttrss_version values (54); +insert into ttrss_version values (55); create table ttrss_enclosures (id serial not null primary key, content_url text not null, diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index eecc1d29b..57d2e95d1 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -126,6 +126,7 @@ create table ttrss_user_entries ( published boolean not null default false, last_read timestamp, score int not null default 0, + note text, unread boolean not null default true); -- create index ttrss_user_entries_feed_id_index on ttrss_user_entries(feed_id); @@ -200,7 +201,7 @@ create index ttrss_tags_owner_uid_index on ttrss_tags(owner_uid); create table ttrss_version (schema_version int not null); -insert into ttrss_version values (54); +insert into ttrss_version values (55); create table ttrss_enclosures (id serial not null primary key, content_url text not null, diff --git a/schema/versions/mysql/55.sql b/schema/versions/mysql/55.sql new file mode 100644 index 000000000..75f55b3c3 --- /dev/null +++ b/schema/versions/mysql/55.sql @@ -0,0 +1,7 @@ +begin; + +alter table ttrss_user_entries add column note text; + +update ttrss_version set schema_version = 55; + +commit; diff --git a/schema/versions/pgsql/55.sql b/schema/versions/pgsql/55.sql new file mode 100644 index 000000000..75f55b3c3 --- /dev/null +++ b/schema/versions/pgsql/55.sql @@ -0,0 +1,7 @@ +begin; + +alter table ttrss_user_entries add column note text; + +update ttrss_version set schema_version = 55; + +commit; diff --git a/tt-rss.css b/tt-rss.css index d6360b21c..3946d6fcb 100644 --- a/tt-rss.css +++ b/tt-rss.css @@ -66,9 +66,34 @@ div.postReply div.postEnclosures { div.postReply img.tagsPic { width : 16px; height : 16px; + margin-left : 4px; vertical-align : middle; } +div.articleNote div.articleNoteOps { + float : right; + color : #9a8c59; +} + +div.articleNote div.articleNoteOps a { + color : #9a8c59; +} + +div.articleNote div.articleNoteOps a:hover { + color : black; +} + +div.articleNote { + background-color : #fff7d5; + border-width : 1px; + padding : 5px; + border-style : dashed; + border-color : #e7d796; + font-size : 8px; + margin-top : 5px; + color : #9a8c59; +} + div.postReply span.author { font-size : 12px; } diff --git a/viewfeed.js b/viewfeed.js index be1a442e0..d21e3e623 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -15,6 +15,39 @@ var post_under_pointer = false; var last_requested_article = false; +function toggle_published_callback(transport) { + try { + if (transport.responseXML) { + + all_counters_callback2(transport); + + var note = transport.responseXML.getElementsByTagName("note")[0]; + + if (note) { + var note_id = note.getAttribute("id"); + var note_size = note.getAttribute("size"); + var note_content = note.firstChild.nodeValue; + + var container = $('POSTNOTE-' + note_id); + + cache_invalidate(note_id); + + if (container) { + if (note_size == "0") { + Element.hide(container); + } else { + container.innerHTML = note_content; + Element.show(container); + } + } + } + } + + } catch (e) { + exception_error("toggle_published_callback", e, transport); + } +} + function catchup_callback2(transport, callback) { try { debug("catchup_callback2 " + transport + ", " + callback); @@ -592,13 +625,19 @@ function toggleMark(id, client_only, no_effects) { } } -function togglePub(id, client_only, no_effects) { +function togglePub(id, client_only, no_effects, note) { try { var query = "backend.php?op=rpc&id=" + id + "&subop=publ"; query = query + "&afid=" + getActiveFeedId(); + + if (note != undefined) { + query = query + "¬e=" + param_escape(note); + } else { + query = query + "¬e=undefined"; + } if (tagsAreDisplayed()) { query = query + "&omode=tl"; @@ -613,11 +652,10 @@ function togglePub(id, client_only, no_effects) { var vfeedu = $("FEEDU--2"); var crow = $("RROW-" + id); - if (mark_img.src.match("pub_unset")) { + if (mark_img.src.match("pub_unset") || note != undefined) { mark_img.src = mark_img.src.replace("pub_unset", "pub_set"); mark_img.alt = __("Unpublish article"); query = query + "&pub=1"; - } else { //mark_img.src = "images/pub_unset.png"; @@ -635,7 +673,7 @@ function togglePub(id, client_only, no_effects) { if (!client_only) { new Ajax.Request(query, { onComplete: function(transport) { - all_counters_callback2(transport); + toggle_published_callback(transport); } }); } @@ -2147,3 +2185,18 @@ function toggleHeadlineActions() { exception_error("toggleHeadlineActions", e); } } + +function publishWithNote(id, def_note) { + try { + if (!def_note) def_note = ''; + + var note = prompt(__("Please enter a note for this article:"), def_note); + + if (note != undefined) { + togglePub(id, false, false, note); + } + + } catch (e) { + exception_error("publishWithNote", e); + } +} -- cgit v1.2.3