diff --git a/backend.php b/backend.php
index 3e6eea66..3ce3f4b9 100644
--- a/backend.php
+++ b/backend.php
@@ -467,56 +467,6 @@
}
break; // rss
- case "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"]."')");
- }
- break; // labelFromSearch
-
case "getUnread":
$login = db_escape_string($_GET["login"]);
diff --git a/config.php-dist b/config.php-dist
index 982bcb7a..81d04d0b 100644
--- a/config.php-dist
+++ b/config.php-dist
@@ -43,9 +43,6 @@
// some use-cases (if you have more than one tt-rss window open, for example)
// so it is disabled by default.
- define('GLOBAL_ENABLE_LABELS', false);
- // Labels are a security risk, so this option can globally disable them for all users.
-
define('MAIL_RESET_PASS', true);
// Send mail to user on password reset
diff --git a/functions.js b/functions.js
index 034e463d..cb38ff37 100644
--- a/functions.js
+++ b/functions.js
@@ -1557,8 +1557,15 @@ function filterDlgCheckAction(sender) {
}
// if selected action supports parameters, enable params field
- if (action == 4 || action == 6) {
+ if (action == 4 || action == 6 || action == 7) {
Element.show(action_param);
+ if (action != 7) {
+ Element.show(form.action_param);
+ Element.hide(form.action_param_label);
+ } else {
+ Element.show(form.action_param_label);
+ Element.hide(form.action_param);
+ }
} else {
Element.hide(action_param);
}
diff --git a/functions.php b/functions.php
index a47e0218..2a347290 100644
--- a/functions.php
+++ b/functions.php
@@ -1300,6 +1300,13 @@
db_query($link, "COMMIT");
+ if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
+ _debug("update_rss_feed: assigning labels...");
+ }
+
+ assign_article_to_labels($link, $entry_ref_id, $article_filters,
+ $owner_uid);
+
if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: looking for enclosures...");
}
@@ -1588,6 +1595,13 @@
return $score;
}
+ function assign_article_to_labels($link, $id, $filters, $owner_uid) {
+ foreach ($filters as $f) {
+ if ($f[0] == "label") {
+ label_add_article($link, $id, $f[1], $owner_uid);
+ };
+ }
+ }
function printFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link,
$rtl_content = false, $last_updated = false, $last_error = false) {
@@ -1822,11 +1836,11 @@
function initialize_user($link, $uid) {
- db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description)
+/* db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description)
values ('$uid','unread = true', 'Unread articles')");
db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description)
- values ('$uid','last_read is null and unread = false', 'Updated articles')");
+ values ('$uid','last_read is null and unread = false', 'Updated articles')"); */
db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url)
values ('$uid', 'Tiny Tiny RSS: New Releases',
@@ -2398,7 +2412,9 @@
return getFeedUnread($link, -1) + getFeedUnread($link, -2) + getFeedUnread($link, -3);
} else if ($cat == -2) {
- $rv = getLabelCounters($link, false, true);
+ // FIXME: NEW_LABELS
+
+/* $rv = getLabelCounters($link, false, true);
$ctr = 0;
foreach (array_keys($rv) as $k) {
@@ -2407,8 +2423,8 @@
}
}
- return $ctr;
- }
+ return $ctr; */
+ }
}
function getMaxAgeSubquery($days = COUNTERS_MAX_AGE) {
@@ -2425,6 +2441,22 @@
return getFeedArticles($link, $feed, $is_cat, true, $_SESSION["uid"]);
}
+ function getLabelUnread($link, $label_id, $owner_uid = false) {
+ if (!$owner_uid) $owner_uid = $_SESSION["uid"];
+
+ $result = db_query($link, "
+ SELECT SUM(unread) AS unread FROM
+ ttrss_user_entries, ttrss_labels2, ttrss_user_labels2
+ WHERE label_id = id AND article_id = ref_id AND
+ ttrss_labels2.owner_uid = '$owner_uid' AND id = '$label_id'");
+
+ if (db_num_rows($result) != 0) {
+ return db_fetch_result($result, 0, "unread");
+ } else {
+ return 0;
+ }
+ }
+
function getFeedArticles($link, $feed, $is_cat = false, $unread_only = false,
$owner_uid = false) {
@@ -2499,10 +2531,8 @@
$label_id = -$feed - 11;
- $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE
- id = '$label_id' AND owner_uid = " . $owner_uid);
+ return getLabelUnread($link, $label_id, $owner_uid);
- $match_part = db_fetch_result($result, 0, "sql_exp");
}
if ($match_part) {
@@ -2626,81 +2656,47 @@
}
$ret_arr = array();
-
+
+ for ($i = -1; $i >= -3; $i--) {
+
+ $count = getFeedUnread($link, $i);
+
+ if (!$ret_mode) {
+
+ if (get_pref($link, 'EXTENDED_FEEDLIST')) {
+ $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $i) . " total)\"";
+ } else {
+ $xmsg_part = "";
+ }
+
+ print "
".__("Error: SQL expression is blank.")."
"; - return; - } - - print "Query returned $num_matches matches$showing_msg:
"; - - $result = db_query($link, - "SELECT ttrss_entries.title, - (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title - FROM ttrss_entries,ttrss_user_entries,ttrss_feeds - WHERE ($expr) AND - ttrss_user_entries.ref_id = ttrss_entries.id - AND ttrss_user_entries.feed_id = ttrss_feeds.id - AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"] . " - ORDER BY date_entered LIMIT 10", false); - - print "Query didn't return any matches.
"; - } - - print ""; - print " - "; + print "
"; } else { print ""; diff --git a/prefs.js b/prefs.js index 88ebc3ee..d78e3b9d 100644 --- a/prefs.js +++ b/prefs.js @@ -135,28 +135,36 @@ function filterlist_callback() { } function labellist_callback() { - var container = document.getElementById('prefContent'); - if (xmlhttp.readyState == 4) { - closeInfoBox(); - container.innerHTML=xmlhttp.responseText; - if (active_label) { - var row = document.getElementById("LILRR-" + active_label); - if (row) { - if (!row.className.match("Selected")) { - row.className = row.className + "Selected"; - } + + try { + + var container = document.getElementById('prefContent'); + if (xmlhttp.readyState == 4) { + closeInfoBox(); + container.innerHTML=xmlhttp.responseText; + + if (document.getElementById("prefLabelList")) { + var elems = document.getElementById("prefLabelList").getElementsByTagName("SPAN"); + + for (var i = 0; i < elems.length; i++) { + if (elems[i].id && elems[i].id.match("LILT-")) { + + var id = elems[i].id.replace("LILT-", ""); + new Ajax.InPlaceEditor(elems[i], + 'backend.php?op=pref-labels&subop=save&id=' + id); + } + } } - var checkbox = document.getElementById("LICHK-" + active_label); - - if (checkbox) { - checkbox.checked = true; + + if (typeof correctPNG != 'undefined') { + correctPNG(); } + notify(""); + remove_splash(); } - if (typeof correctPNG != 'undefined') { - correctPNG(); - } - notify(""); - remove_splash(); + + } catch (e) { + exception_error("labellist_callback", e); } } @@ -304,34 +312,32 @@ function updateUsersList(sort_key) { function addLabel() { + try { + if (!xmlhttp_ready(xmlhttp)) { printLockingError(); return } - var form = document.forms['label_edit_form']; + var caption = prompt(__("Please enter label caption:"), ""); - var sql_exp = form.sql_exp.value; - var description = form.description.value; - - if (sql_exp == "") { - alert(__("Can't create label: missing SQL expression.")); - return false; - } - - if (description == "") { + if (caption == "") { alert(__("Can't create label: missing caption.")); return false; } - var query = Form.serialize("label_edit_form"); - // we can be called from some other tab active_tab = "labelConfig"; + var query = "caption=" + param_escape(caption); + xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&" + query, true); xmlhttp.onreadystatechange=infobox_submit_callback; xmlhttp.send(null); + + } catch (e) { + exception_error("addLabel", e); + } } function addFeed() { @@ -1834,10 +1840,10 @@ function pref_hotkey_handler(e) { return false; } - if (keycode == 76) { // l +/* if (keycode == 76) { // l displayDlg("quickAddLabel"); return false; - } + } */ if (keycode == 85) { // u // no-op diff --git a/prefs.php b/prefs.php index 68beff4c..72500d87 100644 --- a/prefs.php +++ b/prefs.php @@ -140,10 +140,8 @@ window.onload = init; onclick="selectTab('pubItems')"> -->
- - = 10) { ?> diff --git a/sanity_check.php b/sanity_check.php index 0ba47b06..b9c8c333 100644 --- a/sanity_check.php +++ b/sanity_check.php @@ -2,7 +2,7 @@ require_once "functions.php"; define('EXPECTED_CONFIG_VERSION', 17); - define('SCHEMA_VERSION', 50); + define('SCHEMA_VERSION', 51); 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 4d081db0..9bfb0a07 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -189,6 +189,9 @@ insert into ttrss_filter_actions (id,name,description) values (5, 'publish', insert into ttrss_filter_actions (id,name,description) values (6, 'score', 'Modify score'); +insert into ttrss_filter_actions (id,name,description) values (7, 'label', + 'Assign label'); + create table ttrss_filters (id integer not null primary key auto_increment, owner_uid integer not null, feed_id integer default null, @@ -232,7 +235,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 (50); +insert into ttrss_version values (51); create table ttrss_enclosures (id serial not null primary key, content_url text not null, @@ -389,4 +392,16 @@ create table ttrss_feedbrowser_cache ( feed_url text not null, subscribers integer not null); +create table ttrss_labels2 (id integer not null primary key auto_increment, + owner_uid integer not null, + caption varchar(250) not null, + foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE +) TYPE=InnoDB; + +create table ttrss_user_labels2 (label_id integer not null, + article_id integer not null, + foreign key (label_id) references ttrss_labels2(id) ON DELETE CASCADE, + foreign key (article_id) references ttrss_entries(id) ON DELETE CASCADE +) TYPE=InnoDB; + commit; diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index 319e6421..9778a044 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -1,3 +1,5 @@ +drop table ttrss_user_labels2; +drop table ttrss_labels2; drop table ttrss_feedbrowser_cache; drop table ttrss_version; drop table ttrss_labels; @@ -175,6 +177,9 @@ insert into ttrss_filter_actions (id,name,description) values (5, 'publish', insert into ttrss_filter_actions (id,name,description) values (6, 'score', 'Modify score'); +insert into ttrss_filter_actions (id,name,description) values (7, 'label', + 'Assign label'); + create table ttrss_filters (id serial not null primary key, owner_uid integer not null references ttrss_users(id) on delete cascade, feed_id integer references ttrss_feeds(id) on delete cascade default null, @@ -208,7 +213,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 (50); +insert into ttrss_version values (51); create table ttrss_enclosures (id serial not null primary key, content_url text not null, @@ -358,4 +363,14 @@ create table ttrss_feedbrowser_cache ( feed_url text not null primary key, subscribers integer not null); +create table ttrss_labels2 (id serial not null primary key, + owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE, + caption varchar(250) not null +); + +create table ttrss_user_labels2 ( + label_id integer not null references ttrss_labels2(id) ON DELETE CASCADE, + article_id integer not null references ttrss_entries(id) ON DELETE CASCADE +); + commit; diff --git a/schema/versions/mysql/51.sql b/schema/versions/mysql/51.sql new file mode 100644 index 00000000..46d0543f --- /dev/null +++ b/schema/versions/mysql/51.sql @@ -0,0 +1,16 @@ +create table ttrss_labels2 (id integer not null primary key auto_increment, + owner_uid integer not null, + caption varchar(250) not null, + foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE +) TYPE=InnoDB; + +create table ttrss_user_labels2 (label_id integer not null, + article_id integer not null, + foreign key (label_id) references ttrss_labels2(id) ON DELETE CASCADE, + foreign key (article_id) references ttrss_entries(id) ON DELETE CASCADE +) TYPE=InnoDB; + +insert into ttrss_filter_actions (id,name,description) values (7, 'label', + 'Assign label'); + +update ttrss_version set schema_version = 51; diff --git a/schema/versions/pgsql/51.sql b/schema/versions/pgsql/51.sql new file mode 100644 index 00000000..dd566072 --- /dev/null +++ b/schema/versions/pgsql/51.sql @@ -0,0 +1,18 @@ +begin; + +create table ttrss_labels2 (id serial not null primary key, + owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE, + caption varchar(250) not null +); + +create table ttrss_user_labels2 ( + label_id integer not null references ttrss_labels2(id) ON DELETE CASCADE, + article_id integer not null references ttrss_entries(id) ON DELETE CASCADE +); + +insert into ttrss_filter_actions (id,name,description) values (7, 'label', + 'Assign label'); + +update ttrss_version set schema_version = 51; + +commit; diff --git a/viewfeed.js b/viewfeed.js index c7194ab1..a93f886d 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -1159,31 +1159,6 @@ function catchupSelection() { } } - -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); - - new Ajax.Request(query, { - onComplete: function(transport) { - dlg_frefresh_callback(transport); - } }); - } -} - function editArticleTags(id, feed_id, cdm_enabled) { _tag_active_post_id = id; _tag_active_feed_id = feed_id;