From ceb30ba49d300d53a0693aba7e1f0e4c523aeedc Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 18 Jan 2009 09:28:42 +0100 Subject: [PATCH] new style labels (bump schema) --- backend.php | 50 ------- config.php-dist | 3 - functions.js | 9 +- functions.php | 226 ++++++++++++++--------------- help/4.php | 2 +- mobile/functions.php | 16 +-- modules/popup-dialog.php | 4 +- modules/pref-filters.php | 43 +++++- modules/pref-labels.php | 263 +++++++--------------------------- prefs.js | 72 +++++----- prefs.php | 2 - sanity_check.php | 2 +- schema/ttrss_schema_mysql.sql | 17 ++- schema/ttrss_schema_pgsql.sql | 17 ++- schema/versions/mysql/51.sql | 16 +++ schema/versions/pgsql/51.sql | 18 +++ viewfeed.js | 25 ---- 17 files changed, 330 insertions(+), 455 deletions(-) create mode 100644 schema/versions/mysql/51.sql create mode 100644 schema/versions/pgsql/51.sql 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(); - - $old_counters = $_SESSION["lctr_last_value"]; - $lctrs_modified = false; - - $count = getFeedUnread($link, -1); - - if (!$ret_mode) { - if (get_pref($link, 'EXTENDED_FEEDLIST')) { - $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\""; - } else { - $xmsg_part = ""; - } + for ($i = -1; $i >= -3; $i--) { - print ""; - } else { - $ret_arr["-1"]["counter"] = $count; - $ret_arr["-1"]["description"] = __("Starred articles"); - } - - $count = getFeedUnread($link, -2); - - if (!$ret_mode) { + $count = getFeedUnread($link, $i); + + if (!$ret_mode) { + + if (get_pref($link, 'EXTENDED_FEEDLIST')) { + $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $i) . " total)\""; + } else { + $xmsg_part = ""; + } - if (get_pref($link, 'EXTENDED_FEEDLIST')) { - $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\""; + print ""; } else { - $xmsg_part = ""; + $ret_arr[$i]["counter"] = $count; + $ret_arr[$i]["description"] = getFeedTitle($link, $i); } - - print ""; - } else { - $ret_arr["-2"]["counter"] = $count; - $ret_arr["-2"]["description"] = __("Published articles"); + } - $count = getFeedUnread($link, -3); - - if (!$ret_mode) { - - if (get_pref($link, 'EXTENDED_FEEDLIST')) { - $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\""; - } else { - $xmsg_part = ""; - } + $old_counters = $_SESSION["lctr_last_value"]; + $lctrs_modified = false; - print ""; - } else { - $ret_arr["-3"]["counter"] = $count; - $ret_arr["-3"]["description"] = __("Fresh articles"); - } - if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) { + $owner_uid = $_SESSION["uid"]; - $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM - ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description"); + $result = db_query($link, + "SELECT id, caption, SUM(unread) AS unread FROM ttrss_labels2 + LEFT JOIN ttrss_user_labels2 ON (label_id = id) + LEFT JOIN ttrss_user_entries ON (ref_id = article_id) + WHERE ttrss_labels2.owner_uid = '$owner_uid' + GROUP BY id"); while ($line = db_fetch_assoc($result)) { $id = -$line["id"] - 11; - $label_name = $line["description"]; - - error_reporting (0); - - $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 - ttrss_feeds.hidden = false AND - $age_qpart AND - ttrss_user_entries.feed_id = ttrss_feeds.id AND - ttrss_user_entries.ref_id = ttrss_entries.id AND - ttrss_user_entries.owner_uid = ".$_SESSION["uid"]); - - $count = db_fetch_result($tmp_result, 0, "count"); - + $label_name = $line["caption"]; + $count = $line["unread"]; + if (!$smart_mode || $old_counters[$id] != $count) { $old_counters[$id] = $count; $lctrs_modified = true; @@ -2721,7 +2717,6 @@ error_reporting (DEFAULT_ERROR_LEVEL); } - } if ($smart_mode && $lctrs_modified) { $_SESSION["lctr_last_value"] = $old_counters; @@ -3000,9 +2995,9 @@ return __("Fresh articles"); } else if ($id < -10) { $label_id = -$id - 11; - $result = db_query($link, "SELECT description FROM ttrss_labels WHERE id = '$label_id'"); + $result = db_query($link, "SELECT caption FROM ttrss_labels2 WHERE id = '$label_id'"); if (db_num_rows($result) == 1) { - return db_fetch_result($result, 0, "description"); + return db_fetch_result($result, 0, "caption"); } else { return "Unknown label ($label_id)"; } @@ -3308,17 +3303,14 @@ $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; } else if ($feed <= -10) { // labels $label_id = -$feed - 11; - - $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels - WHERE id = '$label_id'"); - - $query_strategy_part = "(" . db_fetch_result($tmp_result, 0, "sql_exp") . ")"; - if (!$query_strategy_part) { - return false; - } + $query_strategy_part = "label_id = '$label_id' AND + ttrss_labels2.id = ttrss_user_labels2.label_id AND + ttrss_user_labels2.article_id = ref_id"; $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; + $ext_tables_part = ",ttrss_labels2,ttrss_user_labels2"; + } else { $query_strategy_part = "id > 0"; // dumb } @@ -3386,9 +3378,9 @@ if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; } } else if ($feed < -10) { $label_id = -$feed - 11; - $result = db_query($link, "SELECT description FROM ttrss_labels + $result = db_query($link, "SELECT caption FROM ttrss_labels2 WHERE id = '$label_id'"); - $feed_title = db_fetch_result($result, 0, "description"); + $feed_title = db_fetch_result($result, 0, "caption"); if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; @@ -3440,7 +3432,7 @@ ".SUBSTRING_FOR_DATE."(updated,1,19) as updated_noms, author,score FROM - ttrss_entries,ttrss_user_entries,ttrss_feeds + ttrss_entries,ttrss_user_entries,ttrss_feeds$ext_tables_part WHERE $group_limit_part ttrss_feeds.hidden = false AND @@ -4055,17 +4047,6 @@ print "
  • --------
  • "; print "
  • ".__('Other actions:')."
  • "; - - - if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) { - print " -
  •    - ".__('Search to label')."
  • "; - } else { - print "
  •   ".__('Search to label')."
  • "; - - } print ""; print ""; @@ -4085,15 +4066,7 @@ __('Mark as read:')." ".__('Page').", ".__('Feed').""; - - if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) { - - print "   - - ".__('Convert to label').""; - } - + print ""; } @@ -4258,10 +4231,9 @@ if (!$tags) { - if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) { - - $result = db_query($link, "SELECT id,sql_exp,description FROM - ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description"); + + $result = db_query($link, "SELECT id,caption FROM + ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption"); if (db_num_rows($result) > 0) { if (get_pref($link, 'ENABLE_FEED_CATS')) { @@ -4281,8 +4253,6 @@ while ($line = db_fetch_assoc($result)) { - error_reporting (0); - $label_id = -$line['id'] - 11; $count = getFeedUnread($link, $label_id); @@ -4291,11 +4261,9 @@ if ($count > 0) { $class .= "Unread"; } - - error_reporting (DEFAULT_ERROR_LEVEL); printFeedEntry($label_id, - $class, $line["description"], + $class, $line["caption"], $count, "images/label.png", $link); } @@ -4304,9 +4272,8 @@ if (get_pref($link, 'ENABLE_FEED_CATS')) { print ""; } - } + } - } if (!get_pref($link, 'ENABLE_FEED_CATS')) { print "

  • "; @@ -6067,4 +6034,37 @@ return $unread; } + + function label_find_id($link, $label, $owner_uid) { + $result = db_query($link, + "SELECT id FROM ttrss_labels2 WHERE caption = '$label' + AND owner_uid = '$owner_uid' LIMIT 1"); + + if (db_num_rows($result) == 1) { + return db_fetch_result($result, 0, "id"); + } else { + return 0; + } + } + + function label_add_article($link, $id, $label, $owner_uid) { + + $label_id = label_find_id($link, $label, $owner_uid); + + if (!$label_id) return; + + $result = db_query($link, + "SELECT + article_id FROM ttrss_labels2, ttrss_user_labels2 + WHERE + label_id = id AND + label_id = '$label_id' AND + article_id = '$id' AND owner_uid = '$owner_uid' + LIMIT 1"); + + if (db_num_rows($result) == 0) { + db_query($link, "INSERT INTO ttrss_user_labels2 + (label_id, article_id) VALUES ('$label_id', '$id')"); + } + } ?> diff --git a/help/4.php b/help/4.php index fbf6c8f0..33879eb2 100644 --- a/help/4.php +++ b/help/4.php @@ -23,7 +23,7 @@ c T c c c f - c l + diff --git a/mobile/functions.php b/mobile/functions.php index a37bc020..db8e2947 100644 --- a/mobile/functions.php +++ b/mobile/functions.php @@ -65,11 +65,10 @@ print ""; } - if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) { - $result = db_query($link, "SELECT id,description FROM - ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description"); - + $result = db_query($link, "SELECT id,caption FROM + ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption"); + if (db_num_rows($result) > 0) { if (get_pref($link, 'ENABLE_FEED_CATS')) { print "
  • ".__("Labels")."
  • "; @@ -81,8 +80,6 @@ while ($line = db_fetch_assoc($result)) { - error_reporting (0); - $count = getFeedUnread($link, -$line["id"]-11); $class = "label"; @@ -90,11 +87,9 @@ if ($count > 0) { $class .= "Unread"; } - - error_reporting (DEFAULT_ERROR_LEVEL); - + printMobileFeedEntry(-$line["id"]-11, - $class, $line["description"], $count, "../images/label.png", $link); + $class, $line["caption"], $count, "../images/label.png", $link); } @@ -104,7 +99,6 @@ } } - } if (get_pref($link, 'ENABLE_FEED_CATS')) { $order_by_qpart = "category,title"; diff --git a/modules/popup-dialog.php b/modules/popup-dialog.php index fe8bf5e0..30211d4d 100644 --- a/modules/popup-dialog.php +++ b/modules/popup-dialog.php @@ -219,7 +219,7 @@ } - if ($id == "quickAddLabel") { +/* if ($id == "quickAddLabel") { print "
    ".__('Create Label')."
    "; print "
    "; @@ -279,7 +279,7 @@ value=\"".__('Cancel')."\">"; return; - } + } */ if ($id == "quickAddFilter") { diff --git a/modules/pref-filters.php b/modules/pref-filters.php index d0b4c7fe..ca469d50 100644 --- a/modules/pref-filters.php +++ b/modules/pref-filters.php @@ -98,13 +98,22 @@ print ""; - $param_hidden = ($action_id == 4 || $action_id == 6) ? "" : "display : none"; + $param_hidden = ($action_id == 4 || $action_id == 6 || $action_id == 7) ? "" : "display : none"; print ""; print " " . __("with parameters:") . " "; - print ""; + + $param_int_hidden = ($action_id == 7) ? "" : "display : none"; + + print_label_select($link, "action_param_label", $action_param, + $param_int_hidden); + print ""; print " "; // tiny layout hack @@ -170,6 +179,7 @@ $feed_id = db_escape_string($_GET["feed_id"]); $action_id = db_escape_string($_GET["action_id"]); $action_param = db_escape_string($_GET["action_param"]); + $action_param_label = db_escape_string($_GET["action_param_label"]); $enabled = checkbox_to_sql_bool(db_escape_string($_GET["enabled"])); $inverse = checkbox_to_sql_bool(db_escape_string($_GET["inverse"])); @@ -181,7 +191,14 @@ } else { $feed_id = sprintf("'%s'", db_escape_string($feed_id)); } - + + /* When processing 'assign label' filters, action_param_label dropbox + * overrides action_param */ + + if ($action_id == 7) { + $action_param = $action_param_label; + } + $result = db_query($link, "UPDATE ttrss_filters SET reg_exp = '$reg_exp', feed_id = $feed_id, @@ -475,4 +492,24 @@ } } + + function print_label_select($link, $name, $value, $style = "") { + + $result = db_query($link, "SELECT caption FROM ttrss_labels2 + WHERE owner_uid = '".$_SESSION["uid"]."' ORDER BY caption"); + + print ""; + + + } ?> diff --git a/modules/pref-labels.php b/modules/pref-labels.php index e5455003..d9208c44 100644 --- a/modules/pref-labels.php +++ b/modules/pref-labels.php @@ -1,214 +1,78 @@ Label Editor
    "; - print "
    "; - - print "
    "; - - print ""; - print ""; - print ""; - - print "
    ".__("Caption")."
    "; - - print "
    "; - - print ""; - print "
    "; - - print "
    ".__("Match SQL")."
    "; - - print "
    "; - - print ""; + if ($subop == "save") { - print "
    "; + $id = db_escape_string($_REQUEST["id"]); + $caption = trim(db_escape_string($_REQUEST["value"])); - print_label_dlg_common_examples(); + db_query($link, "BEGIN"); - print "
    "; + $result = db_query($link, "SELECT caption FROM ttrss_labels2 + WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); - print "
    "; - - print "
    "; - - print "
    "; - - print "
    "; - print " "; - print "
    "; - - $is_disabled = (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE) ? "disabled" : ""; - - print " - "; - - print " "; - - print ""; - - print "
    "; - - return; - } - - if ($subop == "test") { - - // no escaping here on purpose - $expr = trim($_GET["expr"]); - $descr = db_escape_string(trim($_GET["descr"])); - - $expr = str_replace(";", "", $expr); - - if (!$expr) { - print "

    ".__("Error: SQL expression is blank.")."

    "; - return; - } + if (db_num_rows($result) != 0) { + $old_caption = db_fetch_result($result, 0, "caption"); - print "
    "; + $result = db_query($link, "SELECT id FROM ttrss_labels2 + WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]); - error_reporting(0); + if (db_num_rows($result) == 0) { + if ($caption) { + $result = db_query($link, "UPDATE ttrss_labels2 SET + caption = '$caption' WHERE id = '$id' AND + owner_uid = " . $_SESSION["uid"]); + /* Update filters that reference label being renamed */ - $result = db_query($link, - "SELECT count(ttrss_entries.id) AS num_matches - 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"], false); + db_query($link, "UPDATE ttrss_filters SET + action_param = '$caption' WHERE action_param = '$old_caption' + AND action_id = 7 + AND owner_uid = " . $_SESSION["uid"]); - error_reporting (DEFAULT_ERROR_LEVEL); - - if (!$result) { - print "
    " . db_last_error($link) . "
    "; - print "
    "; - return; - } - - $num_matches = db_fetch_result($result, 0, "num_matches");; - - if ($num_matches > 0) { - - if ($num_matches > 10) { - $showing_msg = ", showing first 10"; - } - - 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 "
      "; - - $row_class = "even"; - - while ($line = db_fetch_assoc($result)) { - $row_class = toggleEvenOdd($row_class); - - print "
    • ".$line["title"]. - " (".$line["feed_title"].")
    • "; + print $caption; + } + } else { + print $old_caption; } - print "
    "; - - } else { - print "

    Query didn't return any matches.

    "; } - print "
    "; + db_query($link, "COMMIT"); return; } - if ($subop == "editSave") { - - $sql_exp = db_escape_string(trim($_GET["sql_exp"])); - $descr = db_escape_string(trim($_GET["description"])); - $label_id = db_escape_string($_GET["id"]); - - $sql_exp = str_replace(";", "", $sql_exp); - - $result = db_query($link, "UPDATE ttrss_labels SET - sql_exp = '$sql_exp', - description = '$descr' - WHERE id = '$label_id'"); - - if (db_affected_rows($link, $result) != 0) { - print_notice(T_sprintf("Saved label %s", htmlspecialchars($descr))); - } - - } - if ($subop == "remove") { - if (!WEB_DEMO_MODE) { - - $ids = split(",", db_escape_string($_GET["ids"])); + $ids = split(",", db_escape_string($_GET["ids"])); foreach ($ids as $id) { - db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'"); - - } + db_query($link, "DELETE FROM ttrss_labels2 WHERE id = '$id' + AND owner_uid = " . $_SESSION["uid"]); } } if ($subop == "add") { - $sql_exp = db_escape_string(trim($_GET["sql_exp"])); - $description = db_escape_string($_GET["description"]); + $caption = db_escape_string($_GET["caption"]); - $sql_exp = str_replace(";", "", $sql_exp); + if ($caption) { - if (!$sql_exp || !$description) return; + $result = db_query($link, "SELECT id FROM ttrss_labels2 + WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]); - $result = db_query($link, - "INSERT INTO ttrss_labels (sql_exp,description,owner_uid) - VALUES ('$sql_exp', '$description', '".$_SESSION["uid"]."')"); + if (db_num_rows($result) == 0) { - if (db_affected_rows($link, $result) != 0) { - print T_sprintf("Created label %s", htmlspecialchars($description)); + $result = db_query($link, + "INSERT INTO ttrss_labels2 (caption,owner_uid) + VALUES ('$caption', '".$_SESSION["uid"]."')"); + + if (db_affected_rows($link, $result) != 0) { + print T_sprintf("Created label %s", htmlspecialchars($caption)); + } + } } return; @@ -219,7 +83,7 @@ $sort = db_escape_string($_GET["sort"]); if (!$sort || $sort == "undefined") { - $sort = "description"; + $sort = "caption"; } $label_search = db_escape_string($_GET["search"]); @@ -237,28 +101,25 @@ onchange=\"javascript:updateLabelList()\" value=\"$label_search\"> -

    -

    "; print "
    "; print"
    "; if ($label_search) { - $label_search_query = "(sql_exp LIKE '%$label_search%' OR - description LIKE '%$label_search%') AND"; + $label_search_query = "caption LIKE '%$label_search%' AND"; } else { $label_search_query = ""; } $result = db_query($link, "SELECT - id,sql_exp,description + id,caption FROM - ttrss_labels + ttrss_labels2 WHERE $label_search_query owner_uid = ".$_SESSION["uid"]." @@ -279,8 +140,7 @@ print "   - ".__('Caption')." - ".__('SQL Expression')." + ".__('Caption')." "; @@ -291,29 +151,18 @@ $class = ($lnum % 2) ? "even" : "odd"; $label_id = $line["id"]; - $edit_label_id = $_GET["id"]; - - if ($subop == "edit" && $label_id != $edit_label_id) { - $class .= "Grayed"; - $this_row_id = ""; - } else { - $this_row_id = "id=\"LILRR-$label_id\""; - } - + $this_row_id = "id=\"LILRR-$label_id\""; + print ""; - $line["sql_exp"] = htmlspecialchars($line["sql_exp"]); - $line["description"] = htmlspecialchars($line["description"]); + $line["caption"] = htmlspecialchars($line["caption"]); - if (!$line["description"]) $line["description"] = __("[No caption]"); - - $onclick = "onclick='editLabel($label_id)' title='".__('Click to edit')."'"; - - print ""; - print "" . $line["description"] . ""; - print "" . $line["sql_exp"] . ""; + print "" . $line["caption"] . + ""; print ""; @@ -323,11 +172,9 @@ print ""; 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; -- 2.39.2