new style labels (bump schema)

This commit is contained in:
Andrew Dolgov 2009-01-18 09:28:42 +01:00
parent abd9b16507
commit ceb30ba49d
17 changed files with 337 additions and 462 deletions

View file

@ -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"]);

View file

@ -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

View file

@ -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);
}

View file

@ -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,7 +2423,7 @@
}
}
return $ctr;
return $ctr; */
}
}
@ -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) {
@ -2627,79 +2657,45 @@
$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 "<counter type=\"label\" id=\"$i\" counter=\"$count\" $xmsg_part/>";
} else {
$ret_arr[$i]["counter"] = $count;
$ret_arr[$i]["description"] = getFeedTitle($link, $i);
}
}
$old_counters = $_SESSION["lctr_last_value"];
$lctrs_modified = false;
$count = getFeedUnread($link, -1);
if (!$ret_mode) {
$owner_uid = $_SESSION["uid"];
if (get_pref($link, 'EXTENDED_FEEDLIST')) {
$xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\"";
} else {
$xmsg_part = "";
}
print "<counter type=\"label\" id=\"-1\" counter=\"$count\" $xmsg_part/>";
} else {
$ret_arr["-1"]["counter"] = $count;
$ret_arr["-1"]["description"] = __("Starred articles");
}
$count = getFeedUnread($link, -2);
if (!$ret_mode) {
if (get_pref($link, 'EXTENDED_FEEDLIST')) {
$xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\"";
} else {
$xmsg_part = "";
}
print "<counter type=\"label\" id=\"-2\" counter=\"$count\" $xmsg_part/>";
} 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 = "";
}
print "<counter type=\"label\" id=\"-3\" counter=\"$count\" $xmsg_part/>";
} else {
$ret_arr["-3"]["counter"] = $count;
$ret_arr["-3"]["description"] = __("Fresh articles");
}
if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) {
$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;
@ -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)";
}
@ -3309,16 +3304,13 @@
} 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
@ -4056,17 +4048,6 @@
print "<li><span class=\"insensitive\">--------</span></li>";
print "<li><span class=\"insensitive\">".__('Other actions:')."</span></li>";
if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) {
print "
<li onclick=\"javascript:labelFromSearch('$search', '$search_mode',
'$match_on', '$feed_id', '$is_cat');\">&nbsp;&nbsp;
".__('Search to label')."</li>";
} else {
print "<li><span class=\"insensitive\">&nbsp;&nbsp;".__('Search to label')."</li>";
}
print "</ul></li></ul>";
print "</td>";
@ -4086,14 +4067,6 @@
<a href=\"#\" onclick=\"$catchup_page_link\">".__('Page')."</a>,
<a href=\"#\" onclick=\"$catchup_feed_link\">".__('Feed')."</a>";
if ($search && $feed_id >= 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) {
print "&nbsp;&nbsp;
<a href=\"javascript:labelFromSearch('$search', '$search_mode',
'$match_on', '$feed_id', '$is_cat');\">
".__('Convert to label')."</a>";
}
print "</td>";
}
@ -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);
@ -4292,10 +4262,8 @@
$class .= "Unread";
}
error_reporting (DEFAULT_ERROR_LEVEL);
printFeedEntry($label_id,
$class, $line["description"],
$class, $line["caption"],
$count, "images/label.png", $link);
}
@ -4306,7 +4274,6 @@
}
}
}
if (!get_pref($link, 'ENABLE_FEED_CATS')) {
print "<li><hr></li>";
@ -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')");
}
}
?>

View file

@ -23,7 +23,7 @@
<tr><td class='n'>c T</td><td><?php echo __("Top 25 feeds") ?></td></tr>
<tr><td class='n'>c c</td><td><?php echo __("Edit feed categories") ?></td></tr>
<tr><td class='n'>c f</td><td><?php echo __("Create filter") ?></td></tr>
<tr><td class='n'>c l</td><td><?php echo __("Create label") ?></td></tr>
<!-- <tr><td class='n'>c l</td><td><?php echo __("Create label") ?></td></tr> -->
<!-- <tr><td class='n'>c u</td><td><?php echo __("Create user") ?></td></tr> -->
</table>

View file

@ -65,10 +65,9 @@
print "</ul>";
}
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')) {
@ -81,8 +80,6 @@
while ($line = db_fetch_assoc($result)) {
error_reporting (0);
$count = getFeedUnread($link, -$line["id"]-11);
$class = "label";
@ -91,10 +88,8 @@
$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";

View file

@ -219,7 +219,7 @@
}
if ($id == "quickAddLabel") {
/* if ($id == "quickAddLabel") {
print "<div id=\"infoBoxTitle\">".__('Create Label')."</div>";
print "<div class=\"infoBoxContents\">";
@ -279,7 +279,7 @@
value=\"".__('Cancel')."\">";
return;
}
} */
if ($id == "quickAddFilter") {

View file

@ -98,13 +98,22 @@
print "</select>";
$param_hidden = ($action_id == 4 || $action_id == 6) ? "" : "display : none";
$param_hidden = ($action_id == 4 || $action_id == 6 || $action_id == 7) ? "" : "display : none";
print "<span id=\"filter_dlg_param_box\" style=\"$param_hidden\">";
print " " . __("with parameters:") . " ";
print "<input size=\"20\"
$param_int_hidden = ($action_id != 7) ? "" : "display : none";
print "<input size=\"20\" style=\"$param_int_hidden\"
onkeypress=\"return filterCR(event, filterEditSave)\"
name=\"action_param\" value=\"$action_param\">";
$param_int_hidden = ($action_id == 7) ? "" : "display : none";
print_label_select($link, "action_param_label", $action_param,
$param_int_hidden);
print "</span>";
print "&nbsp;"; // 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"]));
@ -182,6 +192,13 @@
$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 "<select name=\"$name\" style=\"$style\">";
while ($line = db_fetch_assoc($result)) {
$issel = ($line["caption"] == $value) ? "selected" : "";
print "<option $issel>" . $line["caption"] . "</option>";
}
print "</select>";
}
?>

View file

@ -1,214 +1,78 @@
<?php
// We need to accept raw SQL data in label queries, so not everything is escaped
// here, this is by design. If you don't like it, disable labels
// altogether with GLOBAL_ENABLE_LABELS = false
function module_pref_labels($link) {
if (!GLOBAL_ENABLE_LABELS) {
print __("Sorry, labels have been administratively disabled for this installation. Please contact instance owner or edit configuration file to enable this functionality.");
return;
}
$subop = $_GET["subop"];
if ($subop == "edit") {
if ($subop == "save") {
$label_id = db_escape_string($_GET["id"]);
$id = db_escape_string($_REQUEST["id"]);
$caption = trim(db_escape_string($_REQUEST["value"]));
$result = db_query($link, "SELECT sql_exp,description FROM ttrss_labels WHERE
owner_uid = ".$_SESSION["uid"]." AND id = '$label_id' ORDER by description");
db_query($link, "BEGIN");
$line = db_fetch_assoc($result);
$result = db_query($link, "SELECT caption FROM ttrss_labels2
WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
$sql_exp = htmlspecialchars($line["sql_exp"]);
$description = htmlspecialchars($line["description"]);
if (db_num_rows($result) != 0) {
$old_caption = db_fetch_result($result, 0, "caption");
print "<div id=\"infoBoxTitle\">Label Editor</div>";
print "<div class=\"infoBoxContents\">";
$result = db_query($link, "SELECT id FROM ttrss_labels2
WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]);
print "<form id=\"label_edit_form\" onsubmit='return false'>";
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"]);
print "<input type=\"hidden\" name=\"op\" value=\"pref-labels\">";
print "<input type=\"hidden\" name=\"id\" value=\"$label_id\">";
print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
/* Update filters that reference label being renamed */
print "<div class=\"dlgSec\">".__("Caption")."</div>";
db_query($link, "UPDATE ttrss_filters SET
action_param = '$caption' WHERE action_param = '$old_caption'
AND action_id = 7
AND owner_uid = " . $_SESSION["uid"]);
print "<div class=\"dlgSecCont\">";
print $caption;
}
} else {
print $old_caption;
}
}
print "<input onkeypress=\"return filterCR(event, labelEditSave)\"
onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
onchange=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
name=\"description\" size=\"30\" value=\"$description\">";
print "</div>";
print "<div class=\"dlgSec\">".__("Match SQL")."</div>";
print "<div class=\"dlgSecCont\">";
print "<textarea onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
rows=\"6\" name=\"sql_exp\" class=\"labelSQL\" cols=\"50\">$sql_exp</textarea>";
print "<br/>";
print_label_dlg_common_examples();
print "</div>";
print "</form>";
print "<div style=\"display : none\" id=\"label_test_result\"></div>";
print "<div class=\"dlgButtons\">";
print "<div style='float : left'>";
print "<input type=\"submit\"
class=\"button\" onclick=\"return displayHelpInfobox(1)\"
value=\"".__('Help')."\"> ";
print "</div>";
$is_disabled = (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE) ? "disabled" : "";
print "<input $is_disabled type=\"submit\" onclick=\"return labelTest()\" value=\"Test\">
";
print "<input type=\"submit\"
id=\"infobox_submit\"
class=\"button\" onclick=\"return labelEditSave()\"
value=\"Save\"> ";
print "<input class=\"button\"
type=\"submit\" onclick=\"return labelEditCancel()\"
value=\"Cancel\">";
print "</div>";
db_query($link, "COMMIT");
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 "<p>".__("Error: SQL expression is blank.")."</p>";
return;
}
print "<div>";
error_reporting(0);
$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);
error_reporting (DEFAULT_ERROR_LEVEL);
if (!$result) {
print "<div class=\"labelTestError\">" . db_last_error($link) . "</div>";
print "</div>";
return;
}
$num_matches = db_fetch_result($result, 0, "num_matches");;
if ($num_matches > 0) {
if ($num_matches > 10) {
$showing_msg = ", showing first 10";
}
print "<p>Query returned <b>$num_matches</b> matches$showing_msg:</p>";
$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 "<ul class=\"labelTestResults\">";
$row_class = "even";
while ($line = db_fetch_assoc($result)) {
$row_class = toggleEvenOdd($row_class);
print "<li class=\"$row_class\">".$line["title"].
" <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
}
print "</ul>";
} else {
print "<p>Query didn't return any matches.</p>";
}
print "</div>";
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 <b>%s</b>", 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 <b>%s</b>", 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 <b>%s</b>", 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\">
<input type=\"submit\" class=\"button\"
onclick=\"javascript:updateLabelList()\" value=\"".__('Search')."\">
<p><a class='helpLinkPic' href=\"javascript:displayHelpInfobox(1)\">
<img src='images/sign_quest.gif'></a></p>
</div>";
print "<div class=\"prefGenericAddBox\">";
print"<input type=\"submit\" class=\"button\"
id=\"label_create_btn\"
onclick=\"return displayDlg('quickAddLabel', false)\"
onclick=\"return addLabel()\"
value=\"".__('Create label')."\"></div>";
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 "<tr class=\"title\">
<td width=\"5%\">&nbsp;</td>
<td width=\"30%\"><a href=\"javascript:updateLabelList('description')\">".__('Caption')."</a></td>
<td width=\"\"><a href=\"javascript:updateLabelList('sql_exp')\">".__('SQL Expression')."</a>
<td width=\"95%\"><a href=\"javascript:updateLabelList('description')\">".__('Caption')."</a></td>
</td>
</tr>";
@ -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 "<tr class=\"$class\" $this_row_id>";
$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 "<td align='center'><input onclick='toggleSelectPrefRow(this, \"label\");'
print "<td align='center'><input
onclick='toggleSelectPrefRow(this, \"label\");'
type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
print "<td $onclick>" . $line["description"] . "</td>";
print "<td $onclick>" . $line["sql_exp"] . "</td>";
print "<td><span id=\"LILT-".$line["id"]."\">" . $line["caption"] .
"</span></td>";
print "</tr>";
@ -323,11 +172,9 @@
print "</table>";
print "<p id=\"labelOpToolbar\">";
print "<input type=\"submit\" class=\"button\" disabled=\"true\"
onclick=\"javascript:editSelectedLabel()\" value=\"".__('Edit')."\">
<input type=\"submit\" class=\"button\" disabled=\"true\"
onclick=\"javascript:removeSelectedLabels()\" value=\"".__('Remove')."\">";
print "</p>";
} else {
print "<p>";

View file

@ -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

View file

@ -140,10 +140,8 @@ window.onload = init;
onclick="selectTab('pubItems')"><?php echo __('Published Articles') ?></div> -->
<div id="filterConfigTab" class="prefsTab"
onclick="selectTab('filterConfig')"><?php echo __('Content Filtering') ?></div>
<?php if (get_pref($link, 'ENABLE_LABELS')) { ?>
<div id="labelConfigTab" class="prefsTab"
onclick="selectTab('labelConfig')"><?php echo __('Label Editor') ?></div>
<?php } ?>
<?php if ($_SESSION["access_level"] >= 10) { ?>
<div id="userConfigTab" class="prefsTab"
onclick="selectTab('userConfig')"><?php echo __('User Manager') ?></div>

View file

@ -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 __("<b>Fatal Error</b>: You forgot to copy

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;