<?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 "<p>Sorry, labels have been administratively disabled for this installation. Please contact instance owner or edit configuration file to enable this functionality.</p>";
- return;
- }
+ $subop = $_REQUEST["subop"];
- $subop = $_GET["subop"];
+ if ($subop == "color-set") {
+ $kind = db_escape_string($_REQUEST["kind"]);
+ $ids = split(',', db_escape_string($_REQUEST["ids"]));
+ $color = db_escape_string($_REQUEST["color"]);
+ $fg = db_escape_string($_REQUEST["fg"]);
+ $bg = db_escape_string($_REQUEST["bg"]);
- if ($subop == "edit") {
+ foreach ($ids as $id) {
- $label_id = db_escape_string($_GET["id"]);
+ if ($kind == "fg" || $kind == "bg") {
+ db_query($link, "UPDATE ttrss_labels2 SET
+ ${kind}_color = '$color' WHERE id = '$id'
+ AND owner_uid = " . $_SESSION["uid"]);
+ } else {
+ db_query($link, "UPDATE ttrss_labels2 SET
+ fg_color = '$fg', bg_color = '$bg' WHERE id = '$id'
+ AND owner_uid = " . $_SESSION["uid"]);
+ }
- $result = db_query($link, "SELECT sql_exp,description FROM ttrss_labels WHERE
- owner_uid = ".$_SESSION["uid"]." AND id = '$label_id' ORDER by description");
+ $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
- $line = db_fetch_assoc($result);
+ /* Remove cached data */
- $sql_exp = htmlspecialchars($line["sql_exp"]);
- $description = htmlspecialchars($line["description"]);
+ db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
+ WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
- print "<div id=\"infoBoxTitle\">Label editor</div>";
- print "<div class=\"infoBoxContents\">";
+ }
- print "<form id=\"label_edit_form\" onsubmit='return false'>";
+ return;
+ }
+
+ if ($subop == "color-reset") {
+ $ids = split(',', db_escape_string($_REQUEST["ids"]));
+
+ foreach ($ids as $id) {
+ db_query($link, "UPDATE ttrss_labels2 SET
+ fg_color = '', bg_color = '' 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\">";
+ $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
- print "<table width='100%'>";
+ /* Remove cached data */
+
+ db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
+ WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
+ }
- print "<tr><td>Caption:</td>
- <td><input onkeypress=\"return filterCR(event, labelEditSave)\"
- onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
- onchange=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
- name=\"description\" class=\"iedit\" value=\"$description\">";
+ }
- print "</td></tr>";
+ if ($subop == "save") {
- print "<tr><td colspan=\"2\">
- <p>SQL Expression:</p>";
+ $id = db_escape_string($_REQUEST["id"]);
+ $caption = db_escape_string(trim($_REQUEST["value"]));
- print "<textarea onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
- rows=\"4\" name=\"sql_exp\" class=\"iedit\">$sql_exp</textarea>";
- print "</td></tr></table>";
+ db_query($link, "BEGIN");
- print "</form>";
+ $result = db_query($link, "SELECT caption FROM ttrss_labels2
+ WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
- print "<div style=\"display : none\" id=\"label_test_result\"></div>";
+ if (db_num_rows($result) != 0) {
+ $old_caption = db_fetch_result($result, 0, "caption");
- print "<div align='right'>";
+ $result = db_query($link, "SELECT id FROM ttrss_labels2
+ WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]);
- print "<input type=\"submit\"
- class=\"button\" onclick=\"return displayHelpInfobox(1)\"
- value=\"".__('Help')."\"> ";
+ 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"]);
- $is_disabled = (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE) ? "disabled" : "";
+ /* Update filters that reference label being renamed */
- print "<input $is_disabled type=\"submit\" onclick=\"return labelTest()\" value=\"Test\">
- ";
+ $old_caption = db_escape_string($old_caption);
- print "<input type=\"submit\"
- id=\"infobox_submit\"
- class=\"button\" onclick=\"return labelEditSave()\"
- value=\"Save\"> ";
+ 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 "<input class=\"button\"
- type=\"submit\" onclick=\"return labelEditCancel()\"
- value=\"Cancel\">";
+ print $_REQUEST["value"];
+ } else {
+ print $old_caption;
+ }
+ } else {
+ print $old_caption;
+ }
+ }
- print "</div>";
+ db_query($link, "COMMIT");
return;
}
- if ($subop == "test") {
+ if ($subop == "remove") {
- // no escaping here on purpose
- $expr = trim($_GET["expr"]);
- $descr = db_escape_string(trim($_GET["descr"]));
+ $ids = split(",", db_escape_string($_REQUEST["ids"]));
- if (!$expr) {
- print "<div>Error: SQL expression is blank.</div>";
- return;
+ foreach ($ids as $id) {
+ label_remove($link, $id, $_SESSION["uid"]);
}
- print "<div>";
+ }
- error_reporting(0);
+ if ($subop == "add") {
+ $caption = db_escape_string($_REQUEST["caption"]);
+ $output = db_escape_string($_REQUEST["output"]);
+ if ($caption) {
- $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);
+ if (label_create($link, $caption)) {
+ if (!$output) {
+ print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
+ }
+ }
- error_reporting (DEFAULT_ERROR_LEVEL);
+ if ($output == "select") {
+ header("Content-Type: text/xml");
- if (!$result) {
- print "<div class=\"labelTestError\">" . db_last_error($link) . "</div>";
- print "</div>";
- return;
- }
+ print "<rpc-reply><payload>";
- $num_matches = db_fetch_result($result, 0, "num_matches");;
-
- if ($num_matches > 0) {
+ print_label_select($link, "select_label",
+ $caption, "");
- if ($num_matches > 10) {
- $showing_msg = ", showing first 10";
+ print "</payload></rpc-reply>";
}
-
- 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"]);
-
- $result = db_query($link, "UPDATE ttrss_labels SET
- sql_exp = '$sql_exp',
- description = '$descr'
- WHERE id = '$label_id'");
+ set_pref($link, "_PREFS_ACTIVE_TAB", "labelConfig");
- if (db_affected_rows($link, $result) != 0) {
- print_notice(T_sprintf("Saved label <b>%s</b>", htmlspecialchars($descr)));
- }
+ $sort = db_escape_string($_REQUEST["sort"]);
+ if (!$sort || $sort == "undefined") {
+ $sort = "caption";
}
- if ($subop == "remove") {
+ $label_search = db_escape_string($_REQUEST["search"]);
- if (!WEB_DEMO_MODE) {
-
- $ids = split(",", db_escape_string($_GET["ids"]));
-
- foreach ($ids as $id) {
- db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
-
- }
- }
+ if (array_key_exists("search", $_REQUEST)) {
+ $_SESSION["prefs_label_search"] = $label_search;
+ } else {
+ $label_search = $_SESSION["prefs_label_search"];
}
- if ($subop == "add") {
+ print "<div style='float : right'>
+ <input id=\"label_search\" size=\"20\" type=\"search\"
+ onfocus=\"javascript:disableHotkeys();\"
+ onblur=\"javascript:enableHotkeys();\"
+ onchange=\"javascript:updateLabelList()\" value=\"$label_search\">
+ <button onclick=\"javascript:updateLabelList()\">".__('Search')."</button>
+ </div>";
- $sql_exp = db_escape_string(trim($_GET["sql_exp"]));
- $description = db_escape_string($_GET["description"]);
+ print "<div class=\"prefGenericAddBox\">";
- if (!$sql_exp || !$description) return;
+ print"<button onclick=\"return addLabel()\">".
+ __('Create label')."</button> ";
- $result = db_query($link,
- "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
- VALUES ('$sql_exp', '$description', '".$_SESSION["uid"]."')");
+ print "<button onclick=\"javascript:removeSelectedLabels()\">".
+ __('Remove')."</button> ";
- if (db_affected_rows($link, $result) != 0) {
- print T_sprintf("Created label <b>%s</b>", htmlspecialchars($description));
- }
+ print "<button onclick=\"labelColorReset()\">".
+ __('Clear colors')."</button>";
- return;
- }
- set_pref($link, "_PREFS_ACTIVE_TAB", "labelConfig");
+ print "</div>";
- $sort = db_escape_string($_GET["sort"]);
+ if ($label_search) {
- if (!$sort || $sort == "undefined") {
- $sort = "description";
- }
+ $label_search = split(" ", $label_search);
+ $tokens = array();
- print "<a class='helpLinkPic' href=\"javascript:displayHelpInfobox(1)\">
- <img src='images/sign_quest.gif'></a>";
+ foreach ($label_search as $token) {
- print "<div class=\"prefGenericAddBox\">";
+ $token = trim($token);
+ array_push($tokens, "(UPPER(caption) LIKE UPPER('%$token%'))");
- print"<input type=\"submit\" class=\"button\"
- id=\"label_create_btn\"
- onclick=\"return displayDlg('quickAddLabel', false)\"
- value=\"".__('Create label')."\"></div>";
+ }
+
+ $label_search_query = "(" . join($tokens, " AND ") . ") AND ";
+
+ } else {
+ $label_search_query = "";
+ }
$result = db_query($link, "SELECT
- id,sql_exp,description
+ *
FROM
- ttrss_labels
+ ttrss_labels2
WHERE
+ $label_search_query
owner_uid = ".$_SESSION["uid"]."
ORDER BY $sort");
-// print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
-
if (db_num_rows($result) != 0) {
print "<p><table width=\"100%\" cellspacing=\"0\"
print "<tr><td class=\"selectPrompt\" colspan=\"8\">
".__('Select:')."
- <a href=\"javascript:selectPrefRows('label', true)\">".__('All')."</a>,
- <a href=\"javascript:selectPrefRows('label', false)\">".__('None')."</a>
+ <a href=\"#\" onclick=\"selectTableRows('prefLabelList', 'all')\">".__('All')."</a>,
+ <a href=\"#\" onclick=\"selectTableRows('prefLabelList', 'none')\">".__('None')."</a>
</td</tr>";
- print "<tr class=\"title\">
- <td width=\"5%\"> </td>
- <td width=\"30%\"><a href=\"javascript:updateLabelList('description')\">".__('Caption')."</a></td>
- <td width=\"\"><a href=\"javascript:updateLabelList('sql_exp')\">".__('SQL Expression')."</a>
- </td>
- </tr>";
-
$lnum = 0;
while ($line = db_fetch_assoc($result)) {
$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"]);
-
- if (!$line["description"]) $line["description"] = "[No caption]";
-
- print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"label\");'
+ $line["caption"] = htmlspecialchars($line["caption"]);
+
+ $fg_color = $line["fg_color"];
+ $bg_color = $line["bg_color"];
+
+ if (!$fg_color) $fg_color = "";
+ if (!$bg_color) $bg_color = "";
+
+ print "<td width='5%' align='center'><input
+ onclick='toggleSelectRow(this);'
type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
- print "<td><a href=\"javascript:editLabel($label_id);\">" .
- $line["description"] . "</td>";
+ $id = $line['id'];
- print "<td><a href=\"javascript:editLabel($label_id);\">" .
- $line["sql_exp"] . "</td>";
+ print "<td>";
+
+ print "<div class='labelColorIndicator' id='LICID-$id'
+ style='color : $fg_color; background-color : $bg_color'
+ title='".__('Click to change color')."'
+ onclick=\"colorPicker('$id', '$fg_color', '$bg_color')\">α";
+ print_color_picker($id);
+ print "</div>";
+
+
+ print "<span class='prefsLabelEntry'
+ id=\"LILT-".$line["id"]."\">" . $line["caption"] .
+ "</span>";
+
+ print "</td>";
print "</tr>";
++$lnum;
}
-
- if ($lnum == 0) {
- print "<tr><td colspan=\"4\" align=\"center\">".__('No labels defined.')."</td></tr>";
- }
-
+
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')."\">";
} else {
- print "<p>".__('No labels defined.')."</p>";
+ print "<p>";
+ if (!$label_search) {
+ print_warning(__('No labels defined.'));
+ } else {
+ print_warning(__('No matching labels found.'));
+ }
+ print "</p>";
+
+ }
+ }
+
+ function print_color_picker($id) {
+
+ print "<div id=\"colorPicker-$id\"
+ onmouseover=\"colorPickerActive(true)\"
+ onmouseout=\"colorPickerActive(false)\"
+ class=\"colorPicker\" style='display : none'>";
+
+ $color_picker_pairs = array(
+ array('#ff0000', '#ffffff'),
+ array('#009000', '#ffffff'),
+ array('#0000ff', '#ffffff'),
+ array('#ff00ff', '#ffffff'),
+ array('#009090', '#ffffff'),
+
+ array('#ffffff', '#ff0000'),
+ array('#000000', '#00ff00'),
+ array('#ffffff', '#0000ff'),
+ array('#ffffff', '#ff00ff'),
+ array('#000000', '#00ffff'),
+
+ array('#7b07e1', '#ffffff'),
+ array('#0091b4', '#ffffff'),
+ array('#00aa71', '#ffffff'),
+ array('#7d9e01', '#ffffff'),
+ array('#e14a00', '#ffffff'),
+
+ array('#ffffff', '#7b07e1'),
+ array('#ffffff', '#00b5e1'),
+ array('#ffffff', '#00e196'),
+ array('#ffffff', '#b3e100'),
+ array('#ffffff', '#e14a00'),
+
+ array('#000000', '#ffffff'),
+ array('#ffffff', '#000000'),
+ array('#ffffff', '#909000'),
+ array('#063064', '#fff7d5'),
+ array('#ffffff', '#4E4E90'),
+ );
+
+ foreach ($color_picker_pairs as $c) {
+ $fg_color = $c[0];
+ $bg_color = $c[1];
+
+ print "<div class='colorPickerEntry'
+ style='color : $fg_color; background-color : $bg_color;'
+ onclick=\"colorPickerDo('$id', '$fg_color', '$bg_color')\">α</div>";
+
}
+
+ print "<br clear='both'>";
+
+ print "<br/><b>".__('custom color:')."</b>";
+ print "<div class=\"ccPrompt\" onclick=\"labelColorAsk('$id', 'fg')\">".__("foreground")."</div>";
+ print "<div class=\"ccPrompt\" onclick=\"labelColorAsk('$id', 'bg')\">".__("background")."</div>";
+
+ print "</div>";
}
+
?>