function setArticleLabel() { $article_ids = array_filter(explode(",", $this->dbh->escape_string($_REQUEST["article_ids"])), is_numeric); $label_id = (int) $this->dbh->escape_string($_REQUEST['label_id']); $assign = (bool) $this->dbh->escape_string($_REQUEST['assign']) == "true"; $label = $this->dbh->escape_string(label_find_caption(feed_to_label_id($label_id), $_SESSION["uid"])); $num_updated = 0; if ($label) { foreach ($article_ids as $id) { if ($assign) { label_add_article($id, $label, $_SESSION["uid"]); } else { label_remove_article($id, $label, $_SESSION["uid"]); } ++$num_updated; } } $this->wrap(self::STATUS_OK, array("status" => "OK", "updated" => $num_updated)); }
function colorreset() { $ids = split(',', db_escape_string($_REQUEST["ids"])); foreach ($ids as $id) { db_query($this->link, "UPDATE ttrss_labels2 SET\n\t\t\t\tfg_color = '', bg_color = '' WHERE id = '{$id}'\n\t\t\t\tAND owner_uid = " . $_SESSION["uid"]); $caption = db_escape_string(label_find_caption($this->link, $id, $_SESSION["uid"])); /* Remove cached data */ db_query($this->link, "UPDATE ttrss_user_entries SET label_cache = ''\n\t\t\t\tWHERE label_cache LIKE '%{$caption}%' AND owner_uid = " . $_SESSION["uid"]); } }
function labelops($assign) { $reply = array(); $ids = explode(",", db_escape_string($_REQUEST["ids"])); $label_id = db_escape_string($_REQUEST["lid"]); $label = db_escape_string(label_find_caption($this->link, $label_id, $_SESSION["uid"])); $reply["info-for-headlines"] = array(); if ($label) { foreach ($ids as $id) { if ($assign) { label_add_article($this->link, $id, $label, $_SESSION["uid"]); } else { label_remove_article($this->link, $id, $label, $_SESSION["uid"]); } $labels = get_article_labels($this->link, $id, $_SESSION["uid"]); array_push($reply["info-for-headlines"], array("id" => $id, "labels" => format_article_labels($labels, $id))); } } $reply["message"] = "UPDATE_COUNTERS"; print json_encode($reply); }
function module_pref_labels($link) { $subop = $_REQUEST["subop"]; if ($subop == "edit") { $label_id = db_escape_string($_REQUEST['id']); $result = db_query($link, "SELECT * FROM ttrss_labels2 WHERE\n\t\t\t\tid = '{$label_id}' AND owner_uid = " . $_SESSION["uid"]); $line = db_fetch_assoc($result); # print "<form id=\"label_edit_form\" name=\"label_edit_form\" # onsubmit=\"return false;\">"; print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"{$label_id}\">"; print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-labels\">"; print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"save\">"; print "<div class=\"dlgSec\">" . __("Caption") . "</div>"; print "<div class=\"dlgSecCont\">"; $fg_color = $line['fg_color']; $bg_color = $line['bg_color']; print "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : {$fg_color}; background-color : {$bg_color}; margin-bottom : 4px; margin-right : 4px'>α</span>"; print "<input style=\"font-size : 16px\" name=\"caption\" \n\t\t\t\tdojoType=\"dijit.form.ValidationTextBox\"\n\t\t\t\trequired=\"true\"\n\t\t\t\tvalue=\"" . htmlspecialchars($line['caption']) . "\">"; print "</div>"; print "<div class=\"dlgSec\">" . __("Colors") . "</div>"; print "<div class=\"dlgSecCont\">"; print "<table cellspacing=\"0\">"; print "<tr><td>" . __("Foreground:") . "</td><td>" . __("Background:") . "</td></tr>"; print "<tr><td style='padding-right : 10px'>"; print "<input dojoType=\"dijit.form.TextBox\" \n\t\t\t\tstyle=\"display : none\" id=\"labelEdit_fgColor\"\n\t\t\t\tname=\"fg_color\" value=\"{$fg_color}\">"; print "<input dojoType=\"dijit.form.TextBox\" \n\t\t\t\tstyle=\"display : none\" id=\"labelEdit_bgColor\"\n\t\t\t\tname=\"bg_color\" value=\"{$bg_color}\">"; print "<div dojoType=\"dijit.ColorPalette\">\n\t\t\t\t<script type=\"dojo/method\" event=\"onChange\" args=\"fg_color\">\n\t\t\t\t\tdijit.byId(\"labelEdit_fgColor\").attr('value', fg_color);\n\t\t\t\t\t\$('label-editor-indicator').setStyle({color: fg_color});\n\t\t\t\t</script>\n\t\t\t</div>"; print "</div>"; print "</td><td>"; print "<div dojoType=\"dijit.ColorPalette\">\n\t\t\t\t<script type=\"dojo/method\" event=\"onChange\" args=\"bg_color\">\n\t\t\t\t\tdijit.byId(\"labelEdit_bgColor\").attr('value', bg_color);\n\t\t\t\t\t\$('label-editor-indicator').setStyle({backgroundColor: bg_color});\n\t\t\t\t</script>\n\t\t\t</div>"; print "</div>"; print "</td></tr></table>"; print "</div>"; # print "</form>"; print "<div class=\"dlgButtons\">"; print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').execute()\">" . __('Save') . "</button>"; print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').hide()\">" . __('Cancel') . "</button>"; print "</div>"; return; } if ($subop == "getlabeltree") { $root = array(); $root['id'] = 'root'; $root['name'] = __('Labels'); $root['items'] = array(); $result = db_query($link, "SELECT *\n\t\t\t\tFROM ttrss_labels2\n\t\t\t\tWHERE owner_uid = " . $_SESSION["uid"] . "\n\t\t\t\tORDER BY caption"); while ($line = db_fetch_assoc($result)) { $label = array(); $label['id'] = 'LABEL:' . $line['id']; $label['bare_id'] = $line['id']; $label['name'] = $line['caption']; $label['fg_color'] = $line['fg_color']; $label['bg_color'] = $line['bg_color']; $label['type'] = 'label'; $label['checkbox'] = false; array_push($root['items'], $label); } $fl = array(); $fl['identifier'] = 'id'; $fl['label'] = 'name'; $fl['items'] = array($root); print json_encode($fl); return; } 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"]); foreach ($ids as $id) { if ($kind == "fg" || $kind == "bg") { db_query($link, "UPDATE ttrss_labels2 SET\n\t\t\t\t\t\t{$kind}_color = '{$color}' WHERE id = '{$id}'\n\t\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]); } else { db_query($link, "UPDATE ttrss_labels2 SET\n\t\t\t\t\t\tfg_color = '{$fg}', bg_color = '{$bg}' WHERE id = '{$id}'\n\t\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]); } $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"])); /* Remove cached data */ db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''\n\t\t\t\t\tWHERE label_cache LIKE '%{$caption}%' AND owner_uid = " . $_SESSION["uid"]); } return; } if ($subop == "color-reset") { $ids = split(',', db_escape_string($_REQUEST["ids"])); foreach ($ids as $id) { db_query($link, "UPDATE ttrss_labels2 SET\n\t\t\t\t\tfg_color = '', bg_color = '' WHERE id = '{$id}'\n\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]); $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"])); /* Remove cached data */ db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''\n\t\t\t\t\tWHERE label_cache LIKE '%{$caption}%' AND owner_uid = " . $_SESSION["uid"]); } } if ($subop == "save") { $id = db_escape_string($_REQUEST["id"]); $caption = db_escape_string(trim($_REQUEST["caption"])); db_query($link, "BEGIN"); $result = db_query($link, "SELECT caption FROM ttrss_labels2\n\t\t\t\tWHERE id = '{$id}' AND owner_uid = " . $_SESSION["uid"]); if (db_num_rows($result) != 0) { $old_caption = db_fetch_result($result, 0, "caption"); $result = db_query($link, "SELECT id FROM ttrss_labels2\n\t\t\t\t\tWHERE caption = '{$caption}' AND owner_uid = " . $_SESSION["uid"]); if (db_num_rows($result) == 0) { if ($caption) { $result = db_query($link, "UPDATE ttrss_labels2 SET\n\t\t\t\t\t\t\tcaption = '{$caption}' WHERE id = '{$id}' AND\n\t\t\t\t\t\t\towner_uid = " . $_SESSION["uid"]); /* Update filters that reference label being renamed */ $old_caption = db_escape_string($old_caption); db_query($link, "UPDATE ttrss_filters SET\n\t\t\t\t\t\t\taction_param = '{$caption}' WHERE action_param = '{$old_caption}'\n\t\t\t\t\t\t\tAND action_id = 7\n\t\t\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]); print $_REQUEST["value"]; } else { print $old_caption; } } else { print $old_caption; } } db_query($link, "COMMIT"); return; } if ($subop == "remove") { $ids = split(",", db_escape_string($_REQUEST["ids"])); foreach ($ids as $id) { label_remove($link, $id, $_SESSION["uid"]); } } if ($subop == "add") { $caption = db_escape_string($_REQUEST["caption"]); $output = db_escape_string($_REQUEST["output"]); if ($caption) { if (label_create($link, $caption)) { if (!$output) { print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption)); } } if ($output == "select") { header("Content-Type: text/xml"); print "<rpc-reply><payload>"; print_label_select($link, "select_label", $caption, ""); print "</payload></rpc-reply>"; } } return; } $sort = db_escape_string($_REQUEST["sort"]); if (!$sort || $sort == "undefined") { $sort = "caption"; } $label_search = db_escape_string($_REQUEST["search"]); if (array_key_exists("search", $_REQUEST)) { $_SESSION["prefs_label_search"] = $label_search; } else { $label_search = $_SESSION["prefs_label_search"]; } print "<div id=\"pref-label-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">"; print "<div id=\"pref-label-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">"; print "<div id=\"pref-label-toolbar\" dojoType=\"dijit.Toolbar\">"; print "<div dojoType=\"dijit.form.DropDownButton\">" . "<span>" . __('Select') . "</span>"; print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\" \n\t\t\tdojoType=\"dijit.MenuItem\">" . __('All') . "</div>"; print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\" \n\t\t\tdojoType=\"dijit.MenuItem\">" . __('None') . "</div>"; print "</div></div>"; print "<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">" . __('Create label') . "</button dojoType=\"dijit.form.Button\"> "; print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">" . __('Remove') . "</button dojoType=\"dijit.form.Button\"> "; print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">" . __('Clear colors') . "</button dojoType=\"dijit.form.Button\">"; print "</div>"; #toolbar print "</div>"; #pane print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">"; print "<div id=\"labellistLoading\">\n\t\t<img src='images/indicator_tiny.gif'>" . __("Loading, please wait...") . "</div>"; print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\" \n\t\t\turl=\"backend.php?op=pref-labels&subop=getlabeltree\">\n\t\t</div>\n\t\t<div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\"\n\t\tquery=\"{id:'root'}\" rootId=\"root\"\n\t\t\tchildrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">\n\t\t</div>\n\t\t<div dojoType=\"fox.PrefLabelTree\" id=\"labelTree\" \n\t\t\tmodel=\"labelModel\" openOnClick=\"true\">\n\t\t<script type=\"dojo/method\" event=\"onLoad\" args=\"item\">\n\t\t\tElement.hide(\"labellistLoading\");\n\t\t</script>\n\t\t<script type=\"dojo/method\" event=\"onClick\" args=\"item\">\n\t\t\tvar id = String(item.id);\n\t\t\tvar bare_id = id.substr(id.indexOf(':')+1);\n\n\t\t\tif (id.match('LABEL:')) {\n\t\t\t\teditLabel(bare_id);\n\t\t\t}\t\t\t\n\t\t</script>\n\t\t</div>"; print "</div>"; #pane print "</div>"; #container }