Beispiel #1
0
 function save()
 {
     $enable_readability = checkbox_to_sql_bool($_POST["enable_readability"]) == "true";
     $enable_content_dupcheck = checkbox_to_sql_bool($_POST["enable_content_dupcheck"]) == "true";
     $this->host->set($this, "enable_readability", $enable_readability, false);
     $this->host->set($this, "enable_content_dupcheck", $enable_content_dupcheck);
     echo __("Configuration saved");
 }
Beispiel #2
0
 function hook_prefs_save_feed($feed_id)
 {
     $enabled_feeds = $this->host->get($this, "enabled_feeds");
     if (!is_array($enabled_feeds)) {
         $enabled_feeds = array();
     }
     $enable = checkbox_to_sql_bool($_POST["af_readability_enabled"]) == 'true';
     $key = array_search($feed_id, $enabled_feeds);
     if ($enable) {
         if ($key === FALSE) {
             array_push($enabled_feeds, $feed_id);
         }
     } else {
         if ($key !== FALSE) {
             unset($enabled_feeds[$key]);
         }
     }
     $this->host->set($this, "enabled_feeds", $enabled_feeds);
 }
Beispiel #3
0
 function editsaveops($batch)
 {
     $feed_title = $this->dbh->escape_string(trim($_POST["title"]));
     $feed_link = $this->dbh->escape_string(trim($_POST["feed_url"]));
     $upd_intl = (int) $this->dbh->escape_string($_POST["update_interval"]);
     $purge_intl = (int) $this->dbh->escape_string($_POST["purge_interval"]);
     $feed_id = (int) $this->dbh->escape_string($_POST["id"]);
     /* editSave */
     $feed_ids = $this->dbh->escape_string($_POST["ids"]);
     /* batchEditSave */
     $cat_id = (int) $this->dbh->escape_string($_POST["cat_id"]);
     $auth_login = $this->dbh->escape_string(trim($_POST["auth_login"]));
     $auth_pass = trim($_POST["auth_pass"]);
     $private = checkbox_to_sql_bool($this->dbh->escape_string($_POST["private"]));
     $include_in_digest = checkbox_to_sql_bool($this->dbh->escape_string($_POST["include_in_digest"]));
     $cache_images = checkbox_to_sql_bool($this->dbh->escape_string($_POST["cache_images"]));
     $hide_images = checkbox_to_sql_bool($this->dbh->escape_string($_POST["hide_images"]));
     $always_display_enclosures = checkbox_to_sql_bool($this->dbh->escape_string($_POST["always_display_enclosures"]));
     $mark_unread_on_update = checkbox_to_sql_bool($this->dbh->escape_string($_POST["mark_unread_on_update"]));
     $feed_language = $this->dbh->escape_string(trim($_POST["feed_language"]));
     if (strlen(FEED_CRYPT_KEY) > 0) {
         require_once "crypt.php";
         $auth_pass = substr(encrypt_string($auth_pass), 0, 250);
         $auth_pass_encrypted = 'true';
     } else {
         $auth_pass_encrypted = 'false';
     }
     $auth_pass = $this->dbh->escape_string($auth_pass);
     if (get_pref('ENABLE_FEED_CATS')) {
         if ($cat_id && $cat_id != 0) {
             $category_qpart = "cat_id = '{$cat_id}',";
             $category_qpart_nocomma = "cat_id = '{$cat_id}'";
         } else {
             $category_qpart = 'cat_id = NULL,';
             $category_qpart_nocomma = 'cat_id = NULL';
         }
     } else {
         $category_qpart = "";
         $category_qpart_nocomma = "";
     }
     if (!$batch) {
         $result = db_query("SELECT feed_url FROM ttrss_feeds WHERE id = " . $feed_id);
         $orig_feed_url = db_fetch_result($result, 0, "feed_url");
         $reset_basic_info = $orig_feed_url != $feed_link;
         $this->dbh->query("UPDATE ttrss_feeds SET\n\t\t\t\t{$category_qpart}\n\t\t\t\ttitle = '{$feed_title}', feed_url = '{$feed_link}',\n\t\t\t\tupdate_interval = '{$upd_intl}',\n\t\t\t\tpurge_interval = '{$purge_intl}',\n\t\t\t\tauth_login = '******',\n\t\t\t\tauth_pass = '******',\n\t\t\t\tauth_pass_encrypted = {$auth_pass_encrypted},\n\t\t\t\tprivate = {$private},\n\t\t\t\tcache_images = {$cache_images},\n\t\t\t\thide_images = {$hide_images},\n\t\t\t\tinclude_in_digest = {$include_in_digest},\n\t\t\t\talways_display_enclosures = {$always_display_enclosures},\n\t\t\t\tmark_unread_on_update = {$mark_unread_on_update},\n\t\t\t\tfeed_language = '{$feed_language}'\n\t\t\tWHERE id = '{$feed_id}' AND owner_uid = " . $_SESSION["uid"]);
         if ($reset_basic_info) {
             require_once "rssfuncs.php";
             set_basic_feed_info($feed_id);
         }
         PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED, "hook_prefs_save_feed", $feed_id);
     } else {
         $feed_data = array();
         foreach (array_keys($_POST) as $k) {
             if ($k != "op" && $k != "method" && $k != "ids") {
                 $feed_data[$k] = $_POST[$k];
             }
         }
         $this->dbh->query("BEGIN");
         foreach (array_keys($feed_data) as $k) {
             $qpart = "";
             switch ($k) {
                 case "title":
                     $qpart = "title = '{$feed_title}'";
                     break;
                 case "feed_url":
                     $qpart = "feed_url = '{$feed_link}'";
                     break;
                 case "update_interval":
                     $qpart = "update_interval = '{$upd_intl}'";
                     break;
                 case "purge_interval":
                     $qpart = "purge_interval = '{$purge_intl}'";
                     break;
                 case "auth_login":
                     $qpart = "auth_login = '******'";
                     break;
                 case "auth_pass":
                     $qpart = "auth_pass = '******' AND\n\t\t\t\t\t\t\tauth_pass_encrypted = {$auth_pass_encrypted}";
                     break;
                 case "private":
                     $qpart = "private = {$private}";
                     break;
                 case "include_in_digest":
                     $qpart = "include_in_digest = {$include_in_digest}";
                     break;
                 case "always_display_enclosures":
                     $qpart = "always_display_enclosures = {$always_display_enclosures}";
                     break;
                 case "mark_unread_on_update":
                     $qpart = "mark_unread_on_update = {$mark_unread_on_update}";
                     break;
                 case "cache_images":
                     $qpart = "cache_images = {$cache_images}";
                     break;
                 case "hide_images":
                     $qpart = "hide_images = {$hide_images}";
                     break;
                 case "cat_id":
                     $qpart = $category_qpart_nocomma;
                     break;
                 case "feed_language":
                     $qpart = "feed_language = '{$feed_language}'";
                     break;
             }
             if ($qpart) {
                 $this->dbh->query("UPDATE ttrss_feeds SET {$qpart} WHERE id IN ({$feed_ids})\n\t\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]);
                 print "<br/>";
             }
         }
         $this->dbh->query("COMMIT");
     }
     return;
 }
Beispiel #4
0
 function add()
 {
     $savemode = db_escape_string($_REQUEST["savemode"]);
     $regexp = db_escape_string(trim($_REQUEST["reg_exp"]));
     $filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
     $feed_id = db_escape_string($_REQUEST["feed_id"]);
     $cat_id = db_escape_string($_REQUEST["cat_id"]);
     $action_id = db_escape_string($_REQUEST["action_id"]);
     $action_param = db_escape_string($_REQUEST["action_param"]);
     $action_param_label = db_escape_string($_REQUEST["action_param_label"]);
     $inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"]));
     $cat_filter = checkbox_to_sql_bool(db_escape_string($_REQUEST["cat_filter"]));
     # for the time being, no other filters use params anyway...
     $filter_param = db_escape_string($_REQUEST["filter_date_modifier"]);
     if (!$regexp) {
         return;
     }
     if (!$feed_id) {
         $feed_id = 'NULL';
     } else {
         $feed_id = sprintf("'%s'", db_escape_string($feed_id));
     }
     if (!$cat_id) {
         $cat_id = 'NULL';
     } else {
         $cat_id = sprintf("'%d'", db_escape_string($cat_id));
     }
     /* When processing 'assign label' filters, action_param_label dropbox
      * overrides action_param */
     if ($action_id == 7) {
         $action_param = $action_param_label;
     }
     if ($action_id == 6) {
         $action_param = (int) str_replace("+", "", $action_param);
     }
     if ($savemode != "test") {
         $result = db_query($this->link, "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,\n\t\t\t\t\taction_id, action_param, inverse, filter_param, cat_id, cat_filter)\n\t\t\t\tVALUES\n\t\t\t\t\t('{$regexp}', '{$filter_type}','" . $_SESSION["uid"] . "',\n\t\t\t\t\t{$feed_id}, '{$action_id}', '{$action_param}', {$inverse},\n\t\t\t\t\t'{$filter_param}', {$cat_id}, {$cat_filter})");
         if (db_affected_rows($this->link, $result) != 0) {
             print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp));
         }
     } else {
         $this->filter_test($filter_type, $regexp, $action_id, $action_param, $filter_param, sql_bool_to_bool($inverse), (int) $_REQUEST["feed_id"], (int) $_REQUEST['cat_id'], sql_bool_to_bool($cat_filter));
         print "<div align='center'>";
         print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"return dijit.byId('filterTestDlg').hide()\">" . __('Close this window') . "</button>";
         print "</div>";
     }
 }
Beispiel #5
0
 function editsaveops($batch)
 {
     $feed_title = db_escape_string(trim($_POST["title"]));
     $feed_link = db_escape_string(trim($_POST["feed_url"]));
     $upd_intl = (int) db_escape_string($_POST["update_interval"]);
     $purge_intl = (int) db_escape_string($_POST["purge_interval"]);
     $feed_id = (int) db_escape_string($_POST["id"]);
     /* editSave */
     $feed_ids = db_escape_string($_POST["ids"]);
     /* batchEditSave */
     $cat_id = (int) db_escape_string($_POST["cat_id"]);
     $auth_login = db_escape_string(trim($_POST["auth_login"]));
     $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
     $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
     $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
     $include_in_digest = checkbox_to_sql_bool(db_escape_string($_POST["include_in_digest"]));
     $cache_images = checkbox_to_sql_bool(db_escape_string($_POST["cache_images"]));
     $update_method = (int) db_escape_string($_POST["update_method"]);
     $always_display_enclosures = checkbox_to_sql_bool(db_escape_string($_POST["always_display_enclosures"]));
     $mark_unread_on_update = checkbox_to_sql_bool(db_escape_string($_POST["mark_unread_on_update"]));
     $update_on_checksum_change = checkbox_to_sql_bool(db_escape_string($_POST["update_on_checksum_change"]));
     if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
         if ($cat_id && $cat_id != 0) {
             $category_qpart = "cat_id = '{$cat_id}',";
             $category_qpart_nocomma = "cat_id = '{$cat_id}'";
         } else {
             $category_qpart = 'cat_id = NULL,';
             $category_qpart_nocomma = 'cat_id = NULL';
         }
     } else {
         $category_qpart = "";
         $category_qpart_nocomma = "";
     }
     $cache_images_qpart = "cache_images = {$cache_images},";
     if (!$batch) {
         $result = db_query($this->link, "UPDATE ttrss_feeds SET\n\t\t\t\t{$category_qpart}\n\t\t\t\ttitle = '{$feed_title}', feed_url = '{$feed_link}',\n\t\t\t\tupdate_interval = '{$upd_intl}',\n\t\t\t\tpurge_interval = '{$purge_intl}',\n\t\t\t\tauth_login = '******',\n\t\t\t\tauth_pass = '******',\n\t\t\t\tprivate = {$private},\n\t\t\t\trtl_content = {$rtl_content},\n\t\t\t\t{$cache_images_qpart}\n\t\t\t\tinclude_in_digest = {$include_in_digest},\n\t\t\t\talways_display_enclosures = {$always_display_enclosures},\n\t\t\t\tmark_unread_on_update = {$mark_unread_on_update},\n\t\t\t\tupdate_on_checksum_change = {$update_on_checksum_change},\n\t\t\t\tupdate_method = '{$update_method}'\n\t\t\t\tWHERE id = '{$feed_id}' AND owner_uid = " . $_SESSION["uid"]);
     } else {
         $feed_data = array();
         foreach (array_keys($_POST) as $k) {
             if ($k != "op" && $k != "method" && $k != "ids") {
                 $feed_data[$k] = $_POST[$k];
             }
         }
         db_query($this->link, "BEGIN");
         foreach (array_keys($feed_data) as $k) {
             $qpart = "";
             switch ($k) {
                 case "title":
                     $qpart = "title = '{$feed_title}'";
                     break;
                 case "feed_url":
                     $qpart = "feed_url = '{$feed_link}'";
                     break;
                 case "update_interval":
                     $qpart = "update_interval = '{$upd_intl}'";
                     break;
                 case "purge_interval":
                     $qpart = "purge_interval = '{$purge_intl}'";
                     break;
                 case "auth_login":
                     $qpart = "auth_login = '******'";
                     break;
                 case "auth_pass":
                     $qpart = "auth_pass = '******'";
                     break;
                 case "private":
                     $qpart = "private = {$private}";
                     break;
                 case "include_in_digest":
                     $qpart = "include_in_digest = {$include_in_digest}";
                     break;
                 case "always_display_enclosures":
                     $qpart = "always_display_enclosures = {$always_display_enclosures}";
                     break;
                 case "mark_unread_on_update":
                     $qpart = "mark_unread_on_update = {$mark_unread_on_update}";
                     break;
                 case "update_on_checksum_change":
                     $qpart = "update_on_checksum_change = {$update_on_checksum_change}";
                     break;
                 case "cache_images":
                     $qpart = "cache_images = {$cache_images}";
                     break;
                 case "rtl_content":
                     $qpart = "rtl_content = {$rtl_content}";
                     break;
                 case "update_method":
                     $qpart = "update_method = '{$update_method}'";
                     break;
                 case "cat_id":
                     $qpart = $category_qpart_nocomma;
                     break;
             }
             if ($qpart) {
                 db_query($this->link, "UPDATE ttrss_feeds SET {$qpart} WHERE id IN ({$feed_ids})\n\t\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]);
                 print "<br/>";
             }
         }
         db_query($this->link, "COMMIT");
     }
     return;
 }
Beispiel #6
0
 function add()
 {
     if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") {
         return $this->testFilter();
     }
     #		print_r($_REQUEST);
     $enabled = checkbox_to_sql_bool($_REQUEST["enabled"]);
     $match_any_rule = checkbox_to_sql_bool($_REQUEST["match_any_rule"]);
     db_query($this->link, "BEGIN");
     /* create base filter */
     $result = db_query($this->link, "INSERT INTO ttrss_filters2\n\t\t\t(owner_uid, match_any_rule, enabled) VALUES\n\t\t\t(" . $_SESSION["uid"] . ",{$match_any_rule},{$enabled})");
     $result = db_query($this->link, "SELECT MAX(id) AS id FROM ttrss_filters2\n\t\t\tWHERE owner_uid = " . $_SESSION["uid"]);
     $filter_id = db_fetch_result($result, 0, "id");
     $this->saveRulesAndActions($filter_id);
     db_query($this->link, "COMMIT");
 }
 function add()
 {
     if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") {
         return $this->testFilter();
     }
     #		print_r($_REQUEST);
     $enabled = checkbox_to_sql_bool($_REQUEST["enabled"]);
     $match_any_rule = checkbox_to_sql_bool($_REQUEST["match_any_rule"]);
     $title = $this->dbh->escape_string($_REQUEST["title"]);
     $inverse = checkbox_to_sql_bool($_REQUEST["inverse"]);
     $this->dbh->query("BEGIN");
     /* create base filter */
     $result = $this->dbh->query("INSERT INTO ttrss_filters2\n\t\t\t(owner_uid, match_any_rule, enabled, title, inverse) VALUES\n\t\t\t(" . $_SESSION["uid"] . ",{$match_any_rule},{$enabled}, '{$title}', {$inverse})");
     $result = $this->dbh->query("SELECT MAX(id) AS id FROM ttrss_filters2\n\t\t\tWHERE owner_uid = " . $_SESSION["uid"]);
     $filter_id = $this->dbh->fetch_result($result, 0, "id");
     $this->saveRulesAndActions($filter_id);
     $this->dbh->query("COMMIT");
 }
Beispiel #8
0
 function save()
 {
     $json_conf = $_POST['json_conf'];
     $this->host->set($this, 'json_conf', $json_conf);
     $this->host->set($this, "af_fullpost_showinfo", checkbox_to_sql_bool($_POST["af_fullpost_showinfo"]));
     echo __("Configuration saved.");
 }
Beispiel #9
0
 function save()
 {
     $enable_readability = checkbox_to_sql_bool($_POST["enable_readability"]) == "true";
     $this->host->set($this, "enable_readability", $enable_readability);
     echo __("Configuration saved");
 }
Beispiel #10
0
function module_pref_filters($link)
{
    $subop = $_REQUEST["subop"];
    $quiet = $_REQUEST["quiet"];
    if ($subop == "getfiltertree") {
        $root = array();
        $root['id'] = 'root';
        $root['name'] = __('Filters');
        $root['items'] = array();
        $result = db_query($link, "SELECT\n\t\t\t\t\tttrss_filters.id AS id,reg_exp,\n\t\t\t\t\tttrss_filter_types.name AS filter_type_name,\n\t\t\t\t\tttrss_filter_types.description AS filter_type_descr,\n\t\t\t\t\tenabled,\n\t\t\t\t\tinverse,\n\t\t\t\t\tfeed_id,\n\t\t\t\t\taction_id,\n\t\t\t\t\tfilter_param,\n\t\t\t\t\tfilter_type,\n\t\t\t\t\tttrss_filter_actions.description AS action_description,\n\t\t\t\t\tttrss_feeds.title AS feed_title,\n\t\t\t\t\tttrss_filter_actions.name AS action_name,\n\t\t\t\t\tttrss_filters.action_param AS action_param\n\t\t\t\tFROM\n\t\t\t\t\tttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN\n\t\t\t\t\t\tttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)\n\t\t\t\tWHERE\n\t\t\t\t\tfilter_type = ttrss_filter_types.id AND\n\t\t\t\t\tttrss_filter_actions.id = action_id AND\n\t\t\t\t\tttrss_filters.owner_uid = " . $_SESSION["uid"] . "\n\t\t\t\tORDER by action_description, reg_exp");
        $cat = false;
        $cur_action_description = "";
        if (db_num_rows($result) > 0) {
            while ($line = db_fetch_assoc($result)) {
                if ($cur_action_description != $line['action_description']) {
                    if ($cat) {
                        array_push($root['items'], $cat);
                    }
                    $cat = array();
                    $cat['id'] = 'ACTION:' . $line['action_id'];
                    $cat['name'] = $line['action_description'];
                    $cat['items'] = array();
                    $cur_action_description = $line['action_description'];
                }
                if (array_search($line["action_name"], array("score", "tag", "label")) === false) {
                    $line["action_param"] = '';
                } else {
                    if ($line['action_name'] == 'label') {
                        $tmp_result = db_query($link, "SELECT fg_color, bg_color\n\t\t\t\t\t\t\t\tFROM ttrss_labels2 WHERE caption = '" . db_escape_string($line["action_param"]) . "' AND\n\t\t\t\t\t\t\t\t\towner_uid = " . $_SESSION["uid"]);
                        if (db_num_rows($tmp_result) != 0) {
                            $fg_color = db_fetch_result($tmp_result, 0, "fg_color");
                            $bg_color = db_fetch_result($tmp_result, 0, "bg_color");
                            $tmp = "<span class=\"labelColorIndicator\" style='color : {$fg_color}; background-color : {$bg_color}'>&alpha;</span> " . $line['action_param'];
                            $line['action_param'] = $tmp;
                        }
                    }
                }
                $filter = array();
                $filter['id'] = 'FILTER:' . $line['id'];
                $filter['bare_id'] = $line['id'];
                $filter['name'] = $line['reg_exp'];
                $filter['type'] = $line['filter_type'];
                $filter['enabled'] = sql_bool_to_bool($line['enabled']);
                $filter['param'] = $line['action_param'];
                $filter['inverse'] = sql_bool_to_bool($line['inverse']);
                $filter['checkbox'] = false;
                if ($line['feed_id']) {
                    $filter['feed'] = $line['feed_title'];
                }
                array_push($cat['items'], $filter);
            }
            array_push($root['items'], $cat);
        }
        $fl = array();
        $fl['identifier'] = 'id';
        $fl['label'] = 'name';
        $fl['items'] = array($root);
        print json_encode($fl);
        return;
    }
    if ($subop == "edit") {
        $filter_id = db_escape_string($_REQUEST["id"]);
        $result = db_query($link, "SELECT * FROM ttrss_filters WHERE id = '{$filter_id}' AND owner_uid = " . $_SESSION["uid"]);
        $reg_exp = htmlspecialchars(db_fetch_result($result, 0, "reg_exp"));
        $filter_type = db_fetch_result($result, 0, "filter_type");
        $feed_id = db_fetch_result($result, 0, "feed_id");
        $action_id = db_fetch_result($result, 0, "action_id");
        $action_param = db_fetch_result($result, 0, "action_param");
        $filter_param = db_fetch_result($result, 0, "filter_param");
        $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
        $inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));
        print "<form id=\"filter_edit_form\" onsubmit='return false'>";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"{$filter_id}\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"editSave\">";
        $result = db_query($link, "SELECT id,description\n\t\t\t\tFROM ttrss_filter_types ORDER BY description");
        $filter_types = array();
        while ($line = db_fetch_assoc($result)) {
            //array_push($filter_types, $line["description"]);
            $filter_types[$line["id"]] = __($line["description"]);
        }
        print "<div class=\"dlgSec\">" . __("Match") . "</div>";
        print "<div class=\"dlgSecCont\">";
        if ($filter_type != 5) {
            $date_ops_invisible = 'style="display : none"';
        }
        print "<span id=\"filterDlg_dateModBox\" {$date_ops_invisible}>";
        print __("Date") . " ";
        $filter_params = array("before" => __("before"), "after" => __("after"));
        print_select_hash("filter_date_modifier", $filter_param, $filter_params, 'dojoType="dijit.form.Select"');
        print "&nbsp;</span>";
        print "<input dojoType=\"dijit.form.ValidationTextBox\"\n\t\t\t\t\t required=\"1\"\n\t\t\t\t\t name=\"reg_exp\" style=\"font-size : 16px;\" value=\"{$reg_exp}\">";
        print "<span id=\"filterDlg_dateChkBox\" {$date_ops_invisible}>";
        print "&nbsp;<button dojoType=\"dijit.form.Button\" onclick=\"return filterDlgCheckDate()\">" . __('Check it') . "</button>";
        print "</span>";
        print "<hr/> " . __("on field") . " ";
        print_select_hash("filter_type", $filter_type, $filter_types, 'onchange="filterDlgCheckType(this)" dojoType="dijit.form.Select"');
        print "<hr/>";
        print __("in") . " ";
        print_feed_select($link, "feed_id", $feed_id, 'dojoType="dijit.form.FilteringSelect"');
        print "</div>";
        print "<div class=\"dlgSec\">" . __("Perform Action") . "</div>";
        print "<div class=\"dlgSecCont\">";
        print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"\n\t\t\t\tonchange=\"filterDlgCheckAction(this)\">";
        $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions\n\t\t\t\tORDER BY name");
        while ($line = db_fetch_assoc($result)) {
            $is_sel = $line["id"] == $action_id ? "selected=\"1\"" : "";
            printf("<option value='%d' {$is_sel}>%s</option>", $line["id"], __($line["description"]));
        }
        print "</select>";
        $param_hidden = $action_id == 4 || $action_id == 6 || $action_id == 7 ? "" : "display : none";
        print "<span id=\"filterDlg_paramBox\" style=\"{$param_hidden}\">";
        print " " . __("with parameters:") . " ";
        $param_int_hidden = $action_id != 7 ? "" : "display : none";
        print "<input style=\"{$param_int_hidden}\"\n\t\t\t\t\tdojoType=\"dijit.form.TextBox\" id=\"filterDlg_actionParam\"\n\t\t\t\t\tname=\"action_param\" value=\"{$action_param}\">";
        $param_int_hidden = $action_id == 7 ? "" : "display : none";
        print_label_select($link, "action_param_label", $action_param, "style=\"{$param_int_hidden}\"" . 'id="filterDlg_actionParamLabel" dojoType="dijit.form.Select"');
        print "</span>";
        print "&nbsp;";
        // tiny layout hack
        print "</div>";
        print "<div class=\"dlgSec\">" . __("Options") . "</div>";
        print "<div class=\"dlgSecCont\">";
        print "<div style=\"line-height : 100%\">";
        if ($enabled) {
            $checked = "checked=\"1\"";
        } else {
            $checked = "";
        }
        print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" {$checked}>\n\t\t\t\t\t<label for=\"enabled\">" . __('Enabled') . "</label><hr/>";
        if ($inverse) {
            $checked = "checked=\"1\"";
        } else {
            $checked = "";
        }
        print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" {$checked}>\n\t\t\t\t<label for=\"inverse\">" . __('Inverse match') . "</label>";
        print "</div>";
        print "</div>";
        print "<div class=\"dlgButtons\">";
        print "<div style=\"float : left\">";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').removeFilter()\">" . __('Remove') . "</button>";
        print "</div>";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">" . __('Test') . "</button> ";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">" . __('Save') . "</button> ";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">" . __('Cancel') . "</button>";
        print "</div>";
        return;
    }
    if ($subop == "editSave") {
        global $memcache;
        if ($memcache) {
            $memcache->flush();
        }
        $savemode = db_escape_string($_REQUEST["savemode"]);
        $reg_exp = db_escape_string(trim($_REQUEST["reg_exp"]));
        $filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
        $filter_id = db_escape_string($_REQUEST["id"]);
        $feed_id = db_escape_string($_REQUEST["feed_id"]);
        $action_id = db_escape_string($_REQUEST["action_id"]);
        $action_param = db_escape_string($_REQUEST["action_param"]);
        $action_param_label = db_escape_string($_REQUEST["action_param_label"]);
        $enabled = checkbox_to_sql_bool(db_escape_string($_REQUEST["enabled"]));
        $inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"]));
        # for the time being, no other filters use params anyway...
        $filter_param = db_escape_string($_REQUEST["filter_date_modifier"]);
        if (!$feed_id) {
            $feed_id = 'NULL';
        } 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;
        }
        if ($action_id == 6) {
            $action_param = (int) str_replace("+", "", $action_param);
        }
        if ($savemode != "test") {
            $result = db_query($link, "UPDATE ttrss_filters SET\n\t\t\t\t\treg_exp = '{$reg_exp}',\n\t\t\t\t\tfeed_id = {$feed_id},\n\t\t\t\t\taction_id = '{$action_id}',\n\t\t\t\t\tfilter_type = '{$filter_type}',\n\t\t\t\t\tenabled = {$enabled},\n\t\t\t\t\tinverse = {$inverse},\n\t\t\t\t\taction_param = '{$action_param}',\n\t\t\t\t\tfilter_param = '{$filter_param}'\n\t\t\t\t\tWHERE id = '{$filter_id}' AND owner_uid = " . $_SESSION["uid"]);
        } else {
            filter_test($link, $filter_type, $reg_exp, $action_id, $action_param, $filter_param, sql_bool_to_bool($inverse), (int) $_REQUEST["feed_id"]);
            print "<div align='center'>";
            print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\t\tonclick=\"return dijit.byId('filterTestDlg').hide()\">" . __('Close this window') . "</button>";
            print "</div>";
        }
        return;
    }
    if ($subop == "remove") {
        if ($memcache) {
            $memcache->flush();
        }
        $ids = split(",", db_escape_string($_REQUEST["ids"]));
        foreach ($ids as $id) {
            db_query($link, "DELETE FROM ttrss_filters WHERE id = '{$id}' AND owner_uid = " . $_SESSION["uid"]);
        }
        return;
    }
    if ($subop == "add") {
        if ($memcache) {
            $memcache->flush();
        }
        $savemode = db_escape_string($_REQUEST["savemode"]);
        $regexp = db_escape_string(trim($_REQUEST["reg_exp"]));
        $filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
        $feed_id = db_escape_string($_REQUEST["feed_id"]);
        $action_id = db_escape_string($_REQUEST["action_id"]);
        $action_param = db_escape_string($_REQUEST["action_param"]);
        $action_param_label = db_escape_string($_REQUEST["action_param_label"]);
        $inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"]));
        # for the time being, no other filters use params anyway...
        $filter_param = db_escape_string($_REQUEST["filter_date_modifier"]);
        if (!$regexp) {
            return;
        }
        if (!$feed_id) {
            $feed_id = 'NULL';
        } 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;
        }
        if ($action_id == 6) {
            $action_param = (int) str_replace("+", "", $action_param);
        }
        if ($savemode != "test") {
            $result = db_query($link, "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,\n\t\t\t\t\t\taction_id, action_param, inverse, filter_param)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t('{$regexp}', '{$filter_type}','" . $_SESSION["uid"] . "',\n\t\t\t\t\t\t{$feed_id}, '{$action_id}', '{$action_param}', {$inverse},\n\t\t\t\t\t\t'{$filter_param}')");
            if (db_affected_rows($link, $result) != 0) {
                print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp));
            }
        } else {
            filter_test($link, $filter_type, $regexp, $action_id, $action_param, $filter_param, sql_bool_to_bool($inverse), (int) $_REQUEST["feed_id"]);
            print "<div align='center'>";
            print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\t\tonclick=\"return dijit.byId('filterTestDlg').hide()\">" . __('Close this window') . "</button>";
            print "</div>";
        }
        return;
    }
    if ($quiet) {
        return;
    }
    $sort = db_escape_string($_REQUEST["sort"]);
    if (!$sort || $sort == "undefined") {
        $sort = "reg_exp";
    }
    $result = db_query($link, "SELECT id,description\n\t\t\tFROM ttrss_filter_types ORDER BY description");
    $filter_types = array();
    while ($line = db_fetch_assoc($result)) {
        //array_push($filter_types, $line["description"]);
        $filter_types[$line["id"]] = $line["description"];
    }
    $filter_search = db_escape_string($_REQUEST["search"]);
    if (array_key_exists("search", $_REQUEST)) {
        $_SESSION["prefs_filter_search"] = $filter_search;
    } else {
        $filter_search = $_SESSION["prefs_filter_search"];
    }
    print "<div id=\"pref-filter-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
    print "<div id=\"pref-filter-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
    print "<div id=\"pref-filter-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('filterTree').model.setAllChecked(true)\"\n\t\t\tdojoType=\"dijit.MenuItem\">" . __('All') . "</div>";
    print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\"\n\t\t\tdojoType=\"dijit.MenuItem\">" . __('None') . "</div>";
    print "</div></div>";
    print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">" . __('Create filter') . "</button> ";
    print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">" . __('Edit') . "</button> ";
    print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">" . __('Remove') . "</button> ";
    if (defined('_ENABLE_FEED_DEBUGGING')) {
        print "<button dojoType=\"dijit.form.Button\" onclick=\"rescore_all_feeds()\">" . __('Rescore articles') . "</button> ";
    }
    print "</div>";
    # toolbar
    print "</div>";
    # toolbar-frame
    print "<div id=\"pref-filter-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
    print "<div id=\"filterlistLoading\">\n\t\t<img src='images/indicator_tiny.gif'>" . __("Loading, please wait...") . "</div>";
    print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"filterStore\"\n\t\t\turl=\"backend.php?op=pref-filters&subop=getfiltertree\">\n\t\t</div>\n\t\t<div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\"\n\t\tquery=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"\n\t\t\tchildrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">\n\t\t</div>\n\t\t<div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\"\n\t\t\tmodel=\"filterModel\" openOnClick=\"true\">\n\t\t<script type=\"dojo/method\" event=\"onLoad\" args=\"item\">\n\t\t\tElement.hide(\"filterlistLoading\");\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('FILTER:')) {\n\t\t\t\teditFilter(bare_id);\n\t\t\t}\n\t\t</script>\n\n\t\t</div>";
    print "</div>";
    #pane
    print "</div>";
    #container
}
Beispiel #11
0
function module_pref_feeds($link)
{
    global $update_intervals;
    global $purge_intervals;
    global $update_methods;
    $subop = $_REQUEST["subop"];
    $quiet = $_REQUEST["quiet"];
    $mode = $_REQUEST["mode"];
    if ($subop == "removeicon") {
        $feed_id = db_escape_string($_REQUEST["feed_id"]);
        $result = db_query($link, "SELECT id FROM ttrss_feeds\n\t\t\t\tWHERE id = '{$feed_id}' AND owner_uid = " . $_SESSION["uid"]);
        if (db_num_rows($result) != 0) {
            unlink(ICONS_DIR . "/{$feed_id}.ico");
        }
        return;
    }
    if ($subop == "uploadicon") {
        $icon_file = $_FILES['icon_file']['tmp_name'];
        $feed_id = db_escape_string($_REQUEST["feed_id"]);
        if (is_file($icon_file) && $feed_id) {
            if (filesize($icon_file) < 20000) {
                $result = db_query($link, "SELECT id FROM ttrss_feeds\n\t\t\t\t\t\tWHERE id = '{$feed_id}' AND owner_uid = " . $_SESSION["uid"]);
                if (db_num_rows($result) != 0) {
                    unlink(ICONS_DIR . "/{$feed_id}.ico");
                    move_uploaded_file($icon_file, ICONS_DIR . "/{$feed_id}.ico");
                    $rc = 0;
                } else {
                    $rc = 2;
                }
            } else {
                $rc = 1;
            }
        } else {
            $rc = 2;
        }
        print "<script type=\"text/javascript\">";
        print "parent.uploadIconHandler({$rc});";
        print "</script>";
        return;
    }
    /*		if ($subop == "massSubscribe") {
    			$ids = split(",", db_escape_string($_REQUEST["ids"]));
    
    			$subscribed = array();
    
    			foreach ($ids as $id) {
    
    				if ($mode == 1) {
    					$result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
    						WHERE id = '$id'");
    				} else if ($mode == 2) {
    					$result = db_query($link, "SELECT * FROM ttrss_archived_feeds
    						WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
    					$orig_id = db_escape_string(db_fetch_result($result, 0, "id"));
    					$site_url = db_escape_string(db_fetch_result($result, 0, "site_url"));
    				}
    	
    				$feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
    				$title = db_escape_string(db_fetch_result($result, 0, "title"));
    	
    				$title_orig = db_fetch_result($result, 0, "title");
    	
    				$result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
    						feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
    	
    				if (db_num_rows($result) == 0) {			
    					if ($mode == 1) {
    						$result = db_query($link,
    							"INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) 
    							VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
    					} else if ($mode == 2) {
    						$result = db_query($link,
    							"INSERT INTO ttrss_feeds (id,owner_uid,feed_url,title,cat_id,site_url) 
    							VALUES ('$orig_id','".$_SESSION["uid"]."', '$feed_url', '$title', NULL, '$site_url')");
    					}
    					array_push($subscribed, $title_orig);
    				}
    			}
    
    			if (count($subscribed) > 0) {
    				$msg = "<b>".__('Subscribed to feeds:')."</b>".
    					"<ul class=\"nomarks\">";
    
    				foreach ($subscribed as $title) {
    					$msg .= "<li>$title</li>";
    				}
    				$msg .= "</ul>";
    
    				print format_notice($msg);
    			}
    
    			return;
    		} */
    /*		if ($subop == "browse") {
    
    			print "<div id=\"infoBoxTitle\">".__('Feed Browser')."</div>";
    			
    			print "<div class=\"infoBoxContents\">";
    
    			$browser_search = db_escape_string($_REQUEST["search"]);
    
    			//print "<p>".__("Showing top 25 registered feeds, sorted by popularity:")."</p>";
    
    			print "<form onsubmit='return false;' display='inline' name='feed_browser' id='feed_browser'>";
    
    			print "
    				<div style='float : right'>
    				<img style='display : none' 
    					id='feed_browser_spinner' src='images/indicator_white.gif'>
    				<input name=\"search\" size=\"20\" type=\"search\"
    					onchange=\"javascript:updateFeedBrowser()\" value=\"$browser_search\">
    				<button onclick=\"javascript:updateFeedBrowser()\">".__('Search')."</button>
    			</div>";
    
    			print " <select name=\"mode\" onchange=\"updateFeedBrowser()\">
    				<option value='1'>" . __('Popular feeds') . "</option>
    				<option value='2'>" . __('Feed archive') . "</option>
    				</select> ";
    
    			print __("limit:");
    
    			print " <select name=\"limit\" onchange='updateFeedBrowser()'>";
    
    			foreach (array(25, 50, 100, 200) as $l) {
    				$issel = ($l == $limit) ? "selected" : "";
    				print "<option $issel>$l</option>";
    			}
    			
    			print "</select> ";
    
    			print "<p>";
    
    			$owner_uid = $_SESSION["uid"];
    
    			print "<ul class='browseFeedList' id='browseFeedList'>";
    			print_feed_browser($link, $search, 25);
    			print "</ul>";
    
    			print "<div align='center'>
    				<button onclick=\"feedBrowserSubscribe()\">".__('Subscribe')."</button>
    				<button onclick=\"closeInfoBox()\" >".__('Cancel')."</button></div>";
    
    			print "</div>";
    			return;
    		} */
    if ($subop == "editfeed") {
        $feed_id = db_escape_string($_REQUEST["id"]);
        $result = db_query($link, "SELECT * FROM ttrss_feeds WHERE id = '{$feed_id}' AND\n\t\t\t\t\towner_uid = " . $_SESSION["uid"]);
        $title = htmlspecialchars(db_fetch_result($result, 0, "title"));
        $icon_file = ICONS_DIR . "/{$feed_id}.ico";
        if (file_exists($icon_file) && filesize($icon_file) > 0) {
            $feed_icon = "<img width=\"16\" height=\"16\"\n\t\t\t\t\t\tsrc=\"" . ICONS_URL . "/{$feed_id}.ico\">";
        } else {
            $feed_icon = "";
        }
        print "<div id=\"infoBoxTitle\">" . __('Feed Editor') . "</div>";
        print "<div class=\"infoBoxContents\">";
        print "<form id=\"edit_feed_form\" onsubmit=\"return false\">";
        print "<input type=\"hidden\" name=\"id\" value=\"{$feed_id}\">";
        print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
        print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
        print "<div class=\"dlgSec\">" . __("Feed") . "</div>";
        print "<div class=\"dlgSecCont\">";
        /* Title */
        print "<input style=\"font-size : 16px\" size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"\n\t\t\t\t            name=\"title\" value=\"{$title}\">";
        /* Feed URL */
        $feed_url = db_fetch_result($result, 0, "feed_url");
        $feed_url = htmlspecialchars(db_fetch_result($result, 0, "feed_url"));
        print "<br/>";
        print __('URL:') . " ";
        print "<input size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"\n\t\t\t\tname=\"feed_url\" value=\"{$feed_url}\">";
        /* Category */
        if (get_pref($link, 'ENABLE_FEED_CATS')) {
            $cat_id = db_fetch_result($result, 0, "cat_id");
            print "<br/>";
            print __('Place in category:') . " ";
            $parent_feed = db_fetch_result($result, 0, "parent_feed");
            if (sprintf("%d", $parent_feed) > 0) {
                $disabled = "disabled";
            } else {
                $disabled = "";
            }
            print_feed_cat_select($link, "cat_id", $cat_id, $disabled);
        }
        /* Link to */
        print "<br/>";
        print __('Link to feed:') . " ";
        $tmp_result = db_query($link, "SELECT COUNT(id) AS count\n\t\t\t\tFROM ttrss_feeds WHERE parent_feed = '{$feed_id}'");
        $linked_count = db_fetch_result($tmp_result, 0, "count");
        $parent_feed = db_fetch_result($result, 0, "parent_feed");
        if ($linked_count > 0) {
            $disabled = "disabled";
        } else {
            $disabled = "";
        }
        print "<select {$disabled} name=\"parent_feed\">";
        print "<option value=\"0\">" . __('Not linked') . "</option>";
        if (get_pref($link, 'ENABLE_FEED_CATS')) {
            if ($cat_id) {
                $cat_qpart = "AND cat_id = '{$cat_id}'";
            } else {
                $cat_qpart = "AND cat_id IS NULL";
            }
        }
        $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds\n\t\t\t\tWHERE id != '{$feed_id}' AND owner_uid = " . $_SESSION["uid"] . " AND\n\t\t\t  \t\t(SELECT COUNT(id) FROM ttrss_feeds AS T2 WHERE T2.id = ttrss_feeds.parent_feed) = 0\n\t\t\t\t\t{$cat_qpart} ORDER BY title");
        if (db_num_rows($tmp_result) > 0) {
            print "<option disabled>--------</option>";
        }
        while ($tmp_line = db_fetch_assoc($tmp_result)) {
            if ($tmp_line["id"] == $parent_feed) {
                $is_selected = "selected";
            } else {
                $is_selected = "";
            }
            $linked_title = truncate_string(htmlspecialchars($tmp_line["title"]), 40);
            printf("<option {$is_selected} value='%d'>%s</option>", $tmp_line["id"], $linked_title);
        }
        print "</select>";
        print "</div>";
        print "<div class=\"dlgSec\">" . __("Update") . "</div>";
        print "<div class=\"dlgSecCont\">";
        /* Update Interval */
        $update_interval = db_fetch_result($result, 0, "update_interval");
        print_select_hash("update_interval", $update_interval, $update_intervals);
        /* Update method */
        if (ALLOW_SELECT_UPDATE_METHOD) {
            $update_method = db_fetch_result($result, 0, "update_method");
            print " " . __('using') . " ";
            print_select_hash("update_method", $update_method, $update_methods);
        }
        $purge_interval = db_fetch_result($result, 0, "purge_interval");
        if (FORCE_ARTICLE_PURGE == 0) {
            /* Purge intl */
            print "<br/>";
            print __('Article purging:') . " ";
            print_select_hash("purge_interval", $purge_interval, $purge_intervals);
        } else {
            print "<input type='hidden' name='purge_interval' value='{$purge_interval}'>";
        }
        print "</div>";
        print "<div class=\"dlgSec\">" . __("Authentication") . "</div>";
        print "<div class=\"dlgSecCont\">";
        $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login"));
        print "<table>";
        print "<tr><td>" . __('Login:'******'Hide from Popular feeds') . "</label>";
        $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
        if ($rtl_content) {
            $checked = "checked";
        } else {
            $checked = "";
        }
        print "<br/><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"\n\t\t\t\t{$checked}>&nbsp;<label for=\"rtl_content\">" . __('Right-to-left content') . "</label>";
        $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
        if ($include_in_digest) {
            $checked = "checked";
        } else {
            $checked = "";
        }
        print "<br/><input type=\"checkbox\" id=\"include_in_digest\" \n\t\t\t\tname=\"include_in_digest\"\n\t\t\t\t{$checked}>&nbsp;<label for=\"include_in_digest\">" . __('Include in e-mail digest') . "</label>";
        $always_display_enclosures = sql_bool_to_bool(db_fetch_result($result, 0, "always_display_enclosures"));
        if ($always_display_enclosures) {
            $checked = "checked";
        } else {
            $checked = "";
        }
        print "<br/><input type=\"checkbox\" id=\"always_display_enclosures\" \n\t\t\t\tname=\"always_display_enclosures\"\n\t\t\t\t{$checked}>&nbsp;<label for=\"always_display_enclosures\">" . __('Always display image attachments') . "</label>";
        $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
        if ($cache_images) {
            $checked = "checked";
        } else {
            $checked = "";
        }
        if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
            $disabled = "";
            $label_class = "";
        } else {
            $disabled = "disabled";
            $label_class = "class='insensitive'";
        }
        print "<br/><input type=\"checkbox\" id=\"cache_images\" \n\t\t\t\tname=\"cache_images\" {$disabled}\n\t\t\t\t{$checked}>&nbsp;<label {$label_class} for=\"cache_images\">" . __('Cache images locally') . "</label>";
        print "</div>";
        print "</div>";
        print "</form>";
        /* Icon */
        print "<br/>";
        print "<div class=\"dlgSec\">" . __("Icon") . "</div>";
        print "<div class=\"dlgSecCont\">";
        print "<iframe name=\"icon_upload_iframe\"\n\t\t\t\tstyle=\"width: 400px; height: 100px; display: none;\"></iframe>";
        print "<form style='display : block' target=\"icon_upload_iframe\"\n\t\t\t\tenctype=\"multipart/form-data\" method=\"POST\" \n\t\t\t\taction=\"backend.php\">\n\t\t\t\t<input id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\">\n\t\t\t\t<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">\n\t\t\t\t<input type=\"hidden\" name=\"feed_id\" value=\"{$feed_id}\">\n\t\t\t\t<input type=\"hidden\" name=\"subop\" value=\"uploadicon\">\n\t\t\t\t<button onclick=\"return uploadFeedIcon();\"\n\t\t\t\t\ttype=\"submit\">" . __('Replace') . "</button>\n\t\t\t\t<button onclick=\"return removeFeedIcon({$feed_id});\"\n\t\t\t\t\ttype=\"submit\">" . __('Remove') . "</button>\n\t\t\t\t</form>";
        print "</div>";
        $title = htmlspecialchars($title, ENT_QUOTES);
        print "<div class='dlgButtons'>\n\t\t\t\t<div style=\"float : left\">\n\t\t\t\t<button onclick='return unsubscribeFeed({$feed_id}, \"{$title}\")'>" . __('Unsubscribe') . "</button>\n\t\t\t\t</div>\n\t\t\t\t<button onclick=\"return feedEditSave()\">" . __('Save') . "</button>\n\t\t\t\t<button onclick=\"return feedEditCancel()\">" . __('Cancel') . "</button>\n\t\t\t\t</div>";
        return;
    }
    if ($subop == "editfeeds") {
        $feed_ids = db_escape_string($_REQUEST["ids"]);
        print "<div id=\"infoBoxTitle\">" . __('Multiple Feed Editor') . "</div>";
        print "<div class=\"infoBoxContents\">";
        print "<form id=\"batch_edit_feed_form\" onsubmit=\"return false\">";
        print "<input type=\"hidden\" name=\"ids\" value=\"{$feed_ids}\">";
        print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
        print "<input type=\"hidden\" name=\"subop\" value=\"batchEditSave\">";
        print "<div class=\"dlgSec\">" . __("Feed") . "</div>";
        print "<div class=\"dlgSecCont\">";
        /* Title */
        print "<input disabled style=\"font-size : 16px\" size=\"35\" onkeypress=\"return filterCR(event, feedEditSave)\"\n\t\t\t\t            name=\"title\" value=\"{$title}\">";
        batch_edit_cbox("title");
        /* Feed URL */
        print "<br/>";
        print __('URL:') . " ";
        print "<input disabled size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"\n\t\t\t\tname=\"feed_url\" value=\"{$feed_url}\">";
        batch_edit_cbox("feed_url");
        /* Category */
        if (get_pref($link, 'ENABLE_FEED_CATS')) {
            print "<br/>";
            print __('Place in category:') . " ";
            print_feed_cat_select($link, "cat_id", $cat_id, "disabled");
            batch_edit_cbox("cat_id");
        }
        print "</div>";
        print "<div class=\"dlgSec\">" . __("Update") . "</div>";
        print "<div class=\"dlgSecCont\">";
        /* Update Interval */
        print_select_hash("update_interval", $update_interval, $update_intervals, "disabled");
        batch_edit_cbox("update_interval");
        /* Update method */
        if (ALLOW_SELECT_UPDATE_METHOD) {
            print " " . __('using') . " ";
            print_select_hash("update_method", $update_method, $update_methods, "disabled");
            batch_edit_cbox("update_method");
        }
        /* Purge intl */
        if (FORCE_ARTICLE_PURGE != 0) {
            print "<br/>";
            print __('Article purging:') . " ";
            print_select_hash("purge_interval", $purge_interval, $purge_intervals, "disabled");
            batch_edit_cbox("purge_interval");
        }
        print "</div>";
        print "<div class=\"dlgSec\">" . __("Authentication") . "</div>";
        print "<div class=\"dlgSecCont\">";
        print __('Login:'******'insensitive' for=\"private\">" . __('Hide from Popular feeds') . "</label>";
        print "&nbsp;";
        batch_edit_cbox("private", "private_l");
        print "<br/><input disabled type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"\n\t\t\t\t{$checked}>&nbsp;<label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">" . __('Right-to-left content') . "</label>";
        print "&nbsp;";
        batch_edit_cbox("rtl_content", "rtl_content_l");
        print "<br/><input disabled type=\"checkbox\" id=\"include_in_digest\" \n\t\t\t\tname=\"include_in_digest\" \n\t\t\t\t{$checked}>&nbsp;<label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">" . __('Include in e-mail digest') . "</label>";
        print "&nbsp;";
        batch_edit_cbox("include_in_digest", "include_in_digest_l");
        print "<br/><input disabled type=\"checkbox\" id=\"always_display_enclosures\" \n\t\t\t\tname=\"always_display_enclosures\" \n\t\t\t\t{$checked}>&nbsp;<label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">" . __('Always display image attachments') . "</label>";
        print "&nbsp;";
        batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
        print "<br/><input disabled type=\"checkbox\" id=\"cache_images\" \n\t\t\t\tname=\"cache_images\" \n\t\t\t\t{$checked}>&nbsp;<label class='insensitive' id=\"cache_images_l\" \n\t\t\t\t\tfor=\"cache_images\">" . __('Cache images locally') . "</label>";
        if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
            print "&nbsp;";
            batch_edit_cbox("cache_images", "cache_images_l");
        }
        print "</div>";
        print "</div>";
        print "</form>";
        print "<div class='dlgButtons'>\n\t\t\t\t<input type=\"submit\" class=\"button\" \n\t\t\t\tonclick=\"return feedsEditSave()\" value=\"" . __('Save') . "\">\n\t\t\t\t<input type='submit' class='button'\t\t\t\n\t\t\t\tonclick=\"return feedEditCancel()\" value=\"" . __('Cancel') . "\">\n\t\t\t\t</div>";
        return;
    }
    if ($subop == "editSave" || $subop == "batchEditSave") {
        $feed_title = db_escape_string(trim($_POST["title"]));
        $feed_link = db_escape_string(trim($_POST["feed_url"]));
        $upd_intl = db_escape_string($_POST["update_interval"]);
        $purge_intl = db_escape_string($_POST["purge_interval"]);
        $feed_id = db_escape_string($_POST["id"]);
        /* editSave */
        $feed_ids = db_escape_string($_POST["ids"]);
        /* batchEditSave */
        $cat_id = db_escape_string($_POST["cat_id"]);
        $auth_login = db_escape_string(trim($_POST["auth_login"]));
        $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
        $parent_feed = db_escape_string($_POST["parent_feed"]);
        $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
        $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
        $include_in_digest = checkbox_to_sql_bool(db_escape_string($_POST["include_in_digest"]));
        $cache_images = checkbox_to_sql_bool(db_escape_string($_POST["cache_images"]));
        $update_method = (int) db_escape_string($_POST["update_method"]);
        $always_display_enclosures = checkbox_to_sql_bool(db_escape_string($_POST["always_display_enclosures"]));
        if (get_pref($link, 'ENABLE_FEED_CATS')) {
            if ($cat_id && $cat_id != 0) {
                $category_qpart = "cat_id = '{$cat_id}',";
                $category_qpart_nocomma = "cat_id = '{$cat_id}'";
            } else {
                $category_qpart = 'cat_id = NULL,';
                $category_qpart_nocomma = 'cat_id = NULL';
            }
        } else {
            $category_qpart = "";
            $category_qpart_nocomma = "";
        }
        if ($parent_feed && $parent_feed != 0) {
            $parent_qpart = "parent_feed = '{$parent_feed}'";
        } else {
            $parent_qpart = 'parent_feed = NULL';
        }
        if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
            $cache_images_qpart = "cache_images = {$cache_images},";
        } else {
            $cache_images_qpart = "";
        }
        if ($subop == "editSave") {
            $result = db_query($link, "UPDATE ttrss_feeds SET \n\t\t\t\t\t{$category_qpart} {$parent_qpart},\n\t\t\t\t\ttitle = '{$feed_title}', feed_url = '{$feed_link}',\n\t\t\t\t\tupdate_interval = '{$upd_intl}',\n\t\t\t\t\tpurge_interval = '{$purge_intl}',\n\t\t\t\t\tauth_login = '******',\n\t\t\t\t\tauth_pass = '******',\n\t\t\t\t\tprivate = {$private},\n\t\t\t\t\trtl_content = {$rtl_content},\n\t\t\t\t\t{$cache_images_qpart}\n\t\t\t\t\tinclude_in_digest = {$include_in_digest},\n\t\t\t\t\talways_display_enclosures = {$always_display_enclosures},\n\t\t\t\t\tupdate_method = '{$update_method}'\n\t\t\t\t\tWHERE id = '{$feed_id}' AND owner_uid = " . $_SESSION["uid"]);
            if (get_pref($link, 'ENABLE_FEED_CATS')) {
                # update linked feed categories
                $result = db_query($link, "UPDATE ttrss_feeds SET\n\t\t\t\t\t\t{$category_qpart_nocomma} WHERE parent_feed = '{$feed_id}' AND\n\t\t\t\t\t\towner_uid = " . $_SESSION["uid"]);
            }
        } else {
            if ($subop == "batchEditSave") {
                $feed_data = array();
                foreach (array_keys($_POST) as $k) {
                    if ($k != "op" && $k != "subop" && $k != "ids") {
                        $feed_data[$k] = $_POST[$k];
                    }
                }
                db_query($link, "BEGIN");
                foreach (array_keys($feed_data) as $k) {
                    $qpart = "";
                    switch ($k) {
                        case "title":
                            $qpart = "title = '{$feed_title}'";
                            break;
                        case "feed_url":
                            $qpart = "feed_url = '{$feed_link}'";
                            break;
                        case "update_interval":
                            $qpart = "update_interval = '{$upd_intl}'";
                            break;
                        case "purge_interval":
                            $qpart = "purge_interval = '{$purge_intl}'";
                            break;
                        case "auth_login":
                            $qpart = "auth_login = '******'";
                            break;
                        case "auth_pass":
                            $qpart = "auth_pass = '******'";
                            break;
                        case "private":
                            $qpart = "private = '{$private}'";
                            break;
                        case "include_in_digest":
                            $qpart = "include_in_digest = '{$include_in_digest}'";
                            break;
                        case "always_display_enclosures":
                            $qpart = "always_display_enclosures = '{$always_display_enclosures}'";
                            break;
                        case "cache_images":
                            $qpart = "cache_images = '{$cache_images}'";
                            break;
                        case "rtl_content":
                            $qpart = "rtl_content = '{$rtl_content}'";
                            break;
                        case "update_method":
                            $qpart = "update_method = '{$update_method}'";
                            break;
                        case "cat_id":
                            $qpart = $category_qpart_nocomma;
                            break;
                    }
                    if ($qpart) {
                        db_query($link, "UPDATE ttrss_feeds SET {$qpart} WHERE id IN ({$feed_ids})\n\t\t\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]);
                        print "<br/>";
                    }
                }
                db_query($link, "COMMIT");
            }
        }
    }
    if ($subop == "remove") {
        $ids = split(",", db_escape_string($_REQUEST["ids"]));
        foreach ($ids as $id) {
            remove_feed($link, $id, $_SESSION["uid"]);
        }
        return;
    }
    if ($subop == "clear") {
        $id = db_escape_string($_REQUEST["id"]);
        clear_feed_articles($link, $id);
    }
    if ($subop == "rescore") {
        $ids = split(",", db_escape_string($_REQUEST["ids"]));
        foreach ($ids as $id) {
            $filters = load_filters($link, $id, $_SESSION["uid"], 6);
            $result = db_query($link, "SELECT title, content, link, ref_id FROM\n\t\t\t\t\t\tttrss_user_entries, ttrss_entries \n\t\t\t\t\t\tWHERE ref_id = id AND feed_id = '{$id}' AND \n\t\t\t\t\t\t\towner_uid = " . $_SESSION['uid'] . "\n\t\t\t\t\t\t");
            $scores = array();
            while ($line = db_fetch_assoc($result)) {
                $article_filters = get_article_filters($filters, $line['title'], $line['content'], $line['link']);
                $new_score = calculate_article_score($article_filters);
                if (!$scores[$new_score]) {
                    $scores[$new_score] = array();
                }
                array_push($scores[$new_score], $line['ref_id']);
            }
            foreach (array_keys($scores) as $s) {
                if ($s > 1000) {
                    db_query($link, "UPDATE ttrss_user_entries SET score = '{$s}', \n\t\t\t\t\t\t\tmarked = true WHERE\n\t\t\t\t\t\t\tref_id IN (" . join(',', $scores[$s]) . ")");
                } else {
                    if ($s < -500) {
                        db_query($link, "UPDATE ttrss_user_entries SET score = '{$s}', \n\t\t\t\t\t\t\tunread = false WHERE\n\t\t\t\t\t\t\tref_id IN (" . join(',', $scores[$s]) . ")");
                    } else {
                        db_query($link, "UPDATE ttrss_user_entries SET score = '{$s}' WHERE\n\t\t\t\t\t\t\tref_id IN (" . join(',', $scores[$s]) . ")");
                    }
                }
            }
        }
        print __("All done.");
    }
    if ($subop == "rescoreAll") {
        $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
        while ($feed_line = db_fetch_assoc($result)) {
            $id = $feed_line["id"];
            $filters = load_filters($link, $id, $_SESSION["uid"], 6);
            $tmp_result = db_query($link, "SELECT title, content, link, ref_id FROM\n\t\t\t\t\t\tttrss_user_entries, ttrss_entries \n\t\t\t\t\t\tWHERE ref_id = id AND feed_id = '{$id}' AND \n\t\t\t\t\t\t\towner_uid = " . $_SESSION['uid'] . "\n\t\t\t\t\t\t");
            $scores = array();
            while ($line = db_fetch_assoc($tmp_result)) {
                $article_filters = get_article_filters($filters, $line['title'], $line['content'], $line['link']);
                $new_score = calculate_article_score($article_filters);
                if (!$scores[$new_score]) {
                    $scores[$new_score] = array();
                }
                array_push($scores[$new_score], $line['ref_id']);
            }
            foreach (array_keys($scores) as $s) {
                if ($s > 1000) {
                    db_query($link, "UPDATE ttrss_user_entries SET score = '{$s}', \n\t\t\t\t\t\t\tmarked = true WHERE\n\t\t\t\t\t\t\tref_id IN (" . join(',', $scores[$s]) . ")");
                } else {
                    db_query($link, "UPDATE ttrss_user_entries SET score = '{$s}' WHERE\n\t\t\t\t\t\t\tref_id IN (" . join(',', $scores[$s]) . ")");
                }
            }
        }
        print __("All done.");
    }
    if ($subop == "add") {
        $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
        $cat_id = db_escape_string($_REQUEST["cat_id"]);
        $p_from = db_escape_string($_REQUEST["from"]);
        /* only read authentication information from POST */
        $auth_login = db_escape_string(trim($_POST["auth_login"]));
        $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
        if ($p_from != 'tt-rss') {
            print "<html>\n\t\t\t\t\t<head>\n\t\t\t\t\t\t<title>Tiny Tiny RSS</title>\n\t\t\t\t\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">\n\t\t\t\t\t</head>\n\t\t\t\t\t<body>\n\t\t\t\t\t<img class=\"floatingLogo\" src=\"images/ttrss_logo.png\"\n\t\t\t\t  \t\talt=\"Tiny Tiny RSS\"/>\t\n\t\t\t\t\t<h1>Subscribe to feed...</h1>";
        }
        $rc = subscribe_to_feed($link, $feed_url, $cat_id, $auth_login, $auth_pass);
        switch ($rc) {
            case 1:
                print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
                break;
            case 2:
                print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
                break;
            case 0:
                print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
                break;
        }
        if ($p_from != 'tt-rss') {
            $tt_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\\.php.*$/', 'tt-rss.php', $_SERVER["REQUEST_URI"]);
            $tp_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\\.php.*$/', 'prefs.php', $_SERVER["REQUEST_URI"]);
            $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE\n\t\t\t\t\tfeed_url = '{$feed_url}' AND owner_uid = " . $_SESSION["uid"]);
            $feed_id = db_fetch_result($result, 0, "id");
            print "<p>";
            if ($feed_id) {
                print "<form method=\"GET\" style='display: inline' \n\t\t\t\t\t\taction=\"{$tp_uri}\">\n\t\t\t\t\t\t<input type=\"hidden\" name=\"tab\" value=\"feedConfig\">\n\t\t\t\t\t\t<input type=\"hidden\" name=\"subop\" value=\"editFeed\">\n\t\t\t\t\t\t<input type=\"hidden\" name=\"subopparam\" value=\"{$feed_id}\">\n\t\t\t\t\t\t<input type=\"submit\" value=\"" . __("Edit subscription options") . "\">\n\t\t\t\t\t\t</form>";
            }
            print "<form style='display: inline' method=\"GET\" action=\"{$tt_uri}\">\n\t\t\t\t\t<input type=\"submit\" value=\"" . __("Return to Tiny Tiny RSS") . "\">\n\t\t\t\t\t</form></p>";
            print "</body></html>";
            return;
        }
    }
    if ($subop == "categorize") {
        if (!WEB_DEMO_MODE) {
            $ids = split(",", db_escape_string($_REQUEST["ids"]));
            $cat_id = db_escape_string($_REQUEST["cat_id"]);
            if ($cat_id == 0) {
                $cat_id_qpart = 'NULL';
            } else {
                $cat_id_qpart = "'{$cat_id}'";
            }
            db_query($link, "BEGIN");
            foreach ($ids as $id) {
                db_query($link, "UPDATE ttrss_feeds SET cat_id = {$cat_id_qpart}\n\t\t\t\t\t\tWHERE id = '{$id}' AND parent_feed IS NULL\n\t\t\t\t\t  \tAND owner_uid = " . $_SESSION["uid"]);
                # update linked feed categories
                db_query($link, "UPDATE ttrss_feeds SET\n\t\t\t\t\t\tcat_id = {$cat_id_qpart} WHERE parent_feed = '{$id}' AND \n\t\t\t\t\t\towner_uid = " . $_SESSION["uid"]);
            }
            db_query($link, "COMMIT");
        }
    }
    if ($subop == "editCats") {
        $action = $_REQUEST["action"];
        if ($action == "save") {
            $cat_title = db_escape_string(trim($_REQUEST["value"]));
            $cat_id = db_escape_string($_REQUEST["cid"]);
            db_query($link, "BEGIN");
            $result = db_query($link, "SELECT title FROM ttrss_feed_categories\n\t\t\t\t\tWHERE id = '{$cat_id}' AND owner_uid = " . $_SESSION["uid"]);
            if (db_num_rows($result) == 1) {
                $old_title = db_fetch_result($result, 0, "title");
                if ($cat_title != "") {
                    $result = db_query($link, "UPDATE ttrss_feed_categories SET\n\t\t\t\t\t\t\ttitle = '{$cat_title}' WHERE id = '{$cat_id}' AND \n\t\t\t\t\t\t\towner_uid = " . $_SESSION["uid"]);
                    print $cat_title;
                } else {
                    print $old_title;
                }
            } else {
                print $_REQUEST["value"];
            }
            db_query($link, "COMMIT");
            return;
        }
        print "<div id=\"infoBoxTitle\">" . __('Category editor') . "</div>";
        print "<div class=\"infoBoxContents\">";
        if ($action == "add") {
            if (!WEB_DEMO_MODE) {
                $feed_cat = db_escape_string(trim($_REQUEST["cat"]));
                $result = db_query($link, "SELECT id FROM ttrss_feed_categories\n\t\t\t\t\t\tWHERE title = '{$feed_cat}' AND owner_uid = " . $_SESSION["uid"]);
                if (db_num_rows($result) == 0) {
                    $result = db_query($link, "INSERT INTO ttrss_feed_categories (owner_uid,title) \n\t\t\t\t\t\t\tVALUES ('" . $_SESSION["uid"] . "', '{$feed_cat}')");
                } else {
                    print_warning(T_sprintf("Category <b>\$%s</b> already exists in the database.", $feed_cat));
                }
            }
        }
        if ($action == "remove") {
            $ids = split(",", db_escape_string($_REQUEST["ids"]));
            foreach ($ids as $id) {
                remove_feed_category($link, $id, $_SESSION["uid"]);
            }
        }
        print "<div>\n\t\t\t\t<input id=\"fadd_cat\" \n\t\t\t\t\tonkeypress=\"return filterCR(event, addFeedCat)\"\n\t\t\t\t\tsize=\"40\">\n\t\t\t\t\t<button onclick=\"javascript:addFeedCat()\">" . __('Create category') . "</button></div>";
        $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories\n\t\t\t\tWHERE owner_uid = " . $_SESSION["uid"] . "\n\t\t\t\tORDER BY title");
        print "<p>";
        if (db_num_rows($result) != 0) {
            print __('Select:') . " \n\t\t\t\t\t<a href=\"javascript:selectPrefRows('fcat', true)\">" . __('All') . "</a>,\n\t\t\t\t\t<a href=\"javascript:selectPrefRows('fcat', false)\">" . __('None') . "</a>";
            print "<div class=\"prefFeedCatHolder\">";
            print "<form id=\"feed_cat_edit_form\" onsubmit=\"return false\">";
            print "<table width=\"100%\" class=\"prefFeedCatList\" \n\t\t\t\t\tcellspacing=\"0\" id=\"prefFeedCatList\">";
            $lnum = 0;
            while ($line = db_fetch_assoc($result)) {
                $class = $lnum % 2 ? "even" : "odd";
                $cat_id = $line["id"];
                $this_row_id = "id=\"FCATR-{$cat_id}\"";
                print "<tr class=\"{$class}\" {$this_row_id}>";
                $edit_title = htmlspecialchars($line["title"]);
                print "<td width='5%' align='center'><input \n\t\t\t\t\t\tonclick='toggleSelectPrefRow(this, \"fcat\");' \n\t\t\t\t\t\ttype=\"checkbox\" id=\"FCCHK-{$cat_id}\"></td>";
                print "<td><span id=\"FCATT-{$cat_id}\">" . $edit_title . "</span></td>";
                print "</tr>";
                ++$lnum;
            }
            print "</table>";
            print "</form>";
            print "</div>";
        } else {
            print "<p>" . __('No feed categories defined.') . "</p>";
        }
        print "<div class='dlgButtons'>\n\t\t\t\t<div style='float : left'>\n\t\t\t\t<button onclick=\"return removeSelectedFeedCats()\">" . __('Remove') . "</button>\n\t\t\t\t</div>";
        print "<button onclick=\"selectTab('feedConfig')\">" . __('Close this window') . "</button></div>";
        print "</div>";
        return;
    }
    if ($quiet) {
        return;
    }
    set_pref($link, "_PREFS_ACTIVE_TAB", "feedConfig");
    $result = db_query($link, "SELECT COUNT(id) AS num_errors\n\t\t\tFROM ttrss_feeds WHERE last_error != '' AND owner_uid = " . $_SESSION["uid"]);
    $num_errors = db_fetch_result($result, 0, "num_errors");
    if ($num_errors > 0) {
        print format_notice("<a href=\"javascript:showFeedsWithErrors()\">" . __('Some feeds have update errors (click for details)') . "</a>");
    }
    $feed_search = db_escape_string($_REQUEST["search"]);
    if (array_key_exists("search", $_REQUEST)) {
        $_SESSION["prefs_feed_search"] = $feed_search;
    } else {
        $feed_search = $_SESSION["prefs_feed_search"];
    }
    print "<div style='float : right'> \n\t\t\t<input id=\"feed_search\" size=\"20\" type=\"search\"\n\t\t\t\tonfocus=\"javascript:disableHotkeys();\" \n\t\t\t\tonblur=\"javascript:enableHotkeys();\"\n\t\t\t\tonchange=\"javascript:updateFeedList()\" value=\"{$feed_search}\">\n\t\t\t<button onclick=\"javascript:updateFeedList()\">" . __('Search') . "</button>\n\t\t\t</div>";
    print "<button onclick=\"quickAddFeed()\">" . __('Subscribe to feed') . "</button> ";
    print "<button onclick=\"editSelectedFeed()\">" . __('Edit feeds') . "</button> ";
    if (get_pref($link, 'ENABLE_FEED_CATS')) {
        print "<button onclick=\"javascript:editFeedCats()\">" . __('Edit categories') . "</button> ";
    }
    print "<button onclick=\"javascript:removeSelectedFeeds()\">" . __('Unsubscribe') . "</button> ";
    if (defined('_ENABLE_FEED_DEBUGGING')) {
        print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">\n\t\t\t\t<option value=\"facDefault\" selected>" . __('More actions...') . "</option>";
        if (FORCE_ARTICLE_PURGE == 0) {
            print "<option value=\"facPurge\">" . __('Manual purge') . "</option>";
        }
        print "\n\t\t\t\t<option value=\"facClear\">" . __('Clear feed data') . "</option>\n\t\t\t\t<option value=\"facRescore\">" . __('Rescore articles') . "</option>";
        print "</select>";
    }
    $feeds_sort = db_escape_string($_REQUEST["sort"]);
    if (!$feeds_sort || $feeds_sort == "undefined") {
        $feeds_sort = $_SESSION["pref_sort_feeds"];
        if (!$feeds_sort) {
            $feeds_sort = "title";
        }
    }
    $_SESSION["pref_sort_feeds"] = $feeds_sort;
    if ($feed_search) {
        $feed_search = split(" ", $feed_search);
        $tokens = array();
        foreach ($feed_search as $token) {
            $token = trim($token);
            array_push($tokens, "(UPPER(F1.title) LIKE UPPER('%{$token}%') OR\n\t\t\t\t\tUPPER(C1.title) LIKE UPPER('%{$token}%') OR\n\t\t\t\t\tUPPER(F1.feed_url) LIKE UPPER('%{$token}%'))");
        }
        $search_qpart = "(" . join($tokens, " AND ") . ") AND ";
    } else {
        $search_qpart = "";
    }
    $show_last_article_info = false;
    $show_last_article_checked = "";
    $show_last_article_qpart = "";
    if ($_REQUEST["slat"] == "true") {
        $show_last_article_info = true;
        $show_last_article_checked = "checked";
        $show_last_article_qpart = ", (SELECT " . SUBSTRING_FOR_DATE . "(MAX(updated),1,16) FROM ttrss_user_entries,\n\t\t\t\tttrss_entries WHERE ref_id = ttrss_entries.id\n\t\t\t\tAND feed_id = F1.id) AS last_article";
    } else {
        if ($feeds_sort == "last_article") {
            $feeds_sort = "title";
        }
    }
    if (get_pref($link, 'ENABLE_FEED_CATS')) {
        $order_by_qpart = "category,{$feeds_sort},title";
    } else {
        $order_by_qpart = "{$feeds_sort},title";
    }
    $result = db_query($link, "SELECT \n\t\t\t\tF1.id,\n\t\t\t\tF1.title,\n\t\t\t\tF1.feed_url,\n\t\t\t\t" . SUBSTRING_FOR_DATE . "(F1.last_updated,1,16) AS last_updated,\n\t\t\t\tF1.parent_feed,\n\t\t\t\tF1.update_interval,\n\t\t\t\tF1.last_error,\n\t\t\t\tF1.purge_interval,\n\t\t\t\tF1.cat_id,\n\t\t\t\tF2.title AS parent_title,\n\t\t\t\tC1.title AS category,\n\t\t\t\tF1.include_in_digest\n\t\t\t\t{$show_last_article_qpart}\n\t\t\tFROM \n\t\t\t\tttrss_feeds AS F1 \n\t\t\t\tLEFT JOIN ttrss_feeds AS F2\n\t\t\t\t\tON (F1.parent_feed = F2.id)\n\t\t\t\tLEFT JOIN ttrss_feed_categories AS C1\n\t\t\t\t\tON (F1.cat_id = C1.id)\n\t\t\tWHERE \n\t\t\t\t{$search_qpart} F1.owner_uid = '" . $_SESSION["uid"] . "' \t\t\t\n\t\t\tORDER by {$order_by_qpart}");
    if (db_num_rows($result) != 0) {
        //			print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
        print "<p><table width=\"100%\" cellspacing=\"0\" \n\t\t\t\tclass=\"prefFeedList\" id=\"prefFeedList\">";
        print "<tr><td class=\"selectPrompt\" colspan=\"8\">" . "<div style='float : right'>" . "<input id='show_last_article_times' type='checkbox' onchange='feedlistToggleSLAT()'\n\t\t\t\t{$show_last_article_checked}><label \n\t\t\t\t\tfor='show_last_article_times'>" . __('Show last article times') . "</label></div>" . __('Select:') . "\n\t\t\t\t\t<a href=\"javascript:selectPrefRows('feed', true)\">" . __('All') . "</a>,\n\t\t\t\t\t<a href=\"javascript:selectPrefRows('feed', false)\">" . __('None') . "</a>\n\t\t\t\t</td</tr>";
        if (!get_pref($link, 'ENABLE_FEED_CATS')) {
            print "<tr class=\"title\">\n\t\t\t\t\t<td width='5%' align='center'>&nbsp;</td>";
            if (get_pref($link, 'ENABLE_FEED_ICONS')) {
                print "<td width='3%'>&nbsp;</td>";
            }
            print "<td width='60%'><a href=\"javascript:updateFeedList('title')\">" . __('Title') . "</a></td>";
            if ($show_last_article_info) {
                print "<td width='20%' align='right'><a href=\"javascript:updateFeedList('last_article')\">" . __('Last&nbsp;Article') . "</a></td>";
            }
            print "<td width='20%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">" . __('Updated') . "</a></td>";
        }
        $lnum = 0;
        $cur_cat_id = -1;
        while ($line = db_fetch_assoc($result)) {
            $feed_id = $line["id"];
            $cat_id = $line["cat_id"];
            $edit_title = htmlspecialchars($line["title"]);
            $edit_cat = htmlspecialchars($line["category"]);
            $last_error = $line["last_error"];
            if (!$edit_cat) {
                $edit_cat = __("Uncategorized");
            }
            $last_updated = $line["last_updated"];
            if (!$last_updated) {
                $last_updated = "&mdash;";
            } else {
                if (get_pref($link, 'HEADLINES_SMART_DATE')) {
                    $last_updated = smart_date_time(strtotime($last_updated));
                } else {
                    $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
                    $last_updated = date($short_date, strtotime($last_updated));
                }
            }
            $last_article = $line["last_article"];
            if (!$last_article) {
                $last_article = "&mdash;";
            } else {
                if (get_pref($link, 'HEADLINES_SMART_DATE')) {
                    $last_article = smart_date_time(strtotime($last_article));
                } else {
                    $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
                    $last_article = date($short_date, strtotime($last_article));
                }
            }
            if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
                $lnum = 0;
                print "<tr><td colspan=\"6\" class=\"feedEditCat\">{$edit_cat}</td></tr>";
                print "<tr class=\"title\">\n\t\t\t\t\t\t<td width='5%'>&nbsp;</td>";
                if (get_pref($link, 'ENABLE_FEED_ICONS')) {
                    print "<td width='3%'>&nbsp;</td>";
                }
                print "<td width='60%'><a href=\"javascript:updateFeedList('title')\">" . __('Title') . "</a></td>";
                if ($show_last_article_info) {
                    print "<td width='20%' align='right'>\n\t\t\t\t\t\t\t<a href=\"javascript:updateFeedList('last_article')\">" . __('Last&nbsp;Article') . "</a></td>";
                }
                print "<td width='20%' align='right'>\n\t\t\t\t\t\t<a href=\"javascript:updateFeedList('last_updated')\">" . __('Updated') . "</a></td>";
                $cur_cat_id = $cat_id;
            }
            $class = $lnum % 2 ? "even" : "odd";
            $this_row_id = "id=\"FEEDR-{$feed_id}\"";
            print "<tr class=\"{$class}\" {$this_row_id}>";
            $icon_file = ICONS_DIR . "/{$feed_id}.ico";
            if (file_exists($icon_file) && filesize($icon_file) > 0) {
                $feed_icon = "<img class=\"tinyFeedIcon\"\tsrc=\"" . ICONS_URL . "/{$feed_id}.ico\">";
            } else {
                $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
            }
            print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");' \n\t\t\t\ttype=\"checkbox\" id=\"FRCHK-" . $line["id"] . "\"></td>";
            $onclick = "onclick='editFeed({$feed_id})' title='" . __('Click to edit') . "'";
            if (get_pref($link, 'ENABLE_FEED_ICONS')) {
                print "<td {$onclick} class='feedIcon'>{$feed_icon}</td>";
            }
            if ($last_error) {
                $edit_title = "<span class=\"feed_error\">{$edit_title}</span>";
                $last_updated = "<span class=\"feed_error\">{$last_updated}</span>";
                $last_article = "<span class=\"feed_error\">{$last_article}</span>";
            }
            $parent_title = $line["parent_title"];
            if ($parent_title) {
                $linked_to = sprintf(__("(linked to %s)"), $parent_title);
                $parent_title = "<span class='groupPrompt'>{$linked_to}</span>";
            }
            print "<td {$onclick}>" . "{$edit_title} {$parent_title}" . "</td>";
            if ($show_last_article_info) {
                print "<td align='right' {$onclick}>" . "{$last_article}</td>";
            }
            print "<td {$onclick} align='right'>{$last_updated}</td>";
            print "</tr>";
            ++$lnum;
        }
        print "</table>";
        print "<p>";
    } else {
        print "<p>";
        if (!$feed_search) {
            print_warning(__("You don't have any subscribed feeds."));
        } else {
            print_warning(__('No matching feeds found.'));
        }
        print "</p>";
    }
    print "<h3>" . __('OPML') . "</h3>";
    /*		print "<div style='float : left'>
    		<form	enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
    		".__('File:')." <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
    			<input type=\"hidden\" name=\"op\" value=\"Import\">
    			<button onclick=\"return validateOpmlImport();\"
    				type=\"submit\">".__('Import')."</button>
    				</form></div>";
    
    		print "&nbsp;"; */
    print "<iframe name=\"upload_iframe\"\n\t\t\tstyle=\"width: 400px; height: 100px; display: none;\"></iframe>";
    print "<div style='float : left'>";
    print "<form style='display : block' target=\"upload_iframe\"\n\t\t\tenctype=\"multipart/form-data\" method=\"POST\" \n\t\t\t\taction=\"backend.php\">\n\t\t\t<input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;\n\t\t\t<input type=\"hidden\" name=\"op\" value=\"dlg\">\n\t\t\t<input type=\"hidden\" name=\"id\" value=\"importOpml\">\n\t\t\t<button onclick=\"return opmlImport();\"\n\t\t\t\ttype=\"submit\">" . __('Import') . "</button>\n\t\t\t</form>";
    print "</div>&nbsp;";
    print "<button onclick=\"gotoExportOpml()\">" . __('Export OPML') . "</button>";
    print "<h3>" . __("Firefox Integration") . "</h3>";
    print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "</p>";
    print "<p";
    print "<button onclick='window.navigator.registerContentHandler(" . "\"application/vnd.mozilla.maybe.feed\", " . "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" . __('Click here to register this site as a feed reader.') . "</button>";
    print "</p>";
    print "<h3>" . __("Published articles") . "</h3>";
    if (!get_pref($link, "_PREFS_PUBLISH_KEY")) {
        set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key());
    }
    if (!get_pref($link, "_PREFS_OPML_PUBLISH_KEY")) {
        set_pref($link, "_PREFS_OPML_PUBLISH_KEY", generate_publish_key());
    }
    print "<p>" . __('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.') . "</p>";
    print "<button onclick=\"return displayDlg('pubUrl')\">" . __('Display URL') . "</button> ";
    print "<p>" . __('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . "</p>";
    print "<button onclick=\"return displayDlg('pubOPMLUrl')\">" . __('Display URL') . "</button> ";
}
function module_pref_filters($link)
{
    $subop = $_REQUEST["subop"];
    $quiet = $_REQUEST["quiet"];
    if ($subop == "edit") {
        $filter_id = db_escape_string($_REQUEST["id"]);
        $result = db_query($link, "SELECT * FROM ttrss_filters WHERE id = '{$filter_id}' AND owner_uid = " . $_SESSION["uid"]);
        $reg_exp = htmlspecialchars(db_fetch_result($result, 0, "reg_exp"));
        $filter_type = db_fetch_result($result, 0, "filter_type");
        $feed_id = db_fetch_result($result, 0, "feed_id");
        $action_id = db_fetch_result($result, 0, "action_id");
        $action_param = db_fetch_result($result, 0, "action_param");
        $filter_param = db_fetch_result($result, 0, "filter_param");
        $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
        $inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));
        print "<div id=\"infoBoxTitle\">" . __('Filter Editor') . "</div>";
        print "<div class=\"infoBoxContents\">";
        print "<form id=\"filter_edit_form\" onsubmit='return false'>";
        print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
        print "<input type=\"hidden\" name=\"id\" value=\"{$filter_id}\">";
        print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
        $result = db_query($link, "SELECT id,description \n\t\t\t\tFROM ttrss_filter_types ORDER BY description");
        $filter_types = array();
        while ($line = db_fetch_assoc($result)) {
            //array_push($filter_types, $line["description"]);
            $filter_types[$line["id"]] = __($line["description"]);
        }
        print "<div class=\"dlgSec\">" . __("Match") . "</div>";
        print "<div class=\"dlgSecCont\">";
        if ($filter_type != 5) {
            $date_ops_invisible = 'style="display : none"';
        }
        print "<span id=\"filter_dlg_date_mod_box\" {$date_ops_invisible}>";
        print __("Date") . " ";
        $filter_params = array("before" => __("before"), "after" => __("after"));
        print_select_hash("filter_date_modifier", $filter_param, $filter_params);
        print "&nbsp;</span>";
        print "<input onkeypress=\"return filterCR(event, filterEditSave)\"\n\t\t\t\t\t name=\"reg_exp\" size=\"30\" value=\"{$reg_exp}\">";
        print "<span id=\"filter_dlg_date_chk_box\" {$date_ops_invisible}>";
        print "&nbsp;<input class=\"button\"\n\t\t\t\ttype=\"submit\" onclick=\"return filterDlgCheckDate()\" \n\t\t\t\tvalue=\"" . __('Check it') . "\">";
        print "</span>";
        print "<br/> " . __("on field") . " ";
        print_select_hash("filter_type", $filter_type, $filter_types, 'onchange="filterDlgCheckType(this)"');
        print "<br/>";
        print __("in") . " ";
        print_feed_select($link, "feed_id", $feed_id);
        print "</div>";
        print "<div class=\"dlgSec\">" . __("Perform Action") . "</div>";
        print "<div class=\"dlgSecCont\">";
        print "<select name=\"action_id\"\n\t\t\t\tonchange=\"filterDlgCheckAction(this)\">";
        $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions \n\t\t\t\tORDER BY name");
        while ($line = db_fetch_assoc($result)) {
            $is_sel = $line["id"] == $action_id ? "selected" : "";
            printf("<option value='%d' {$is_sel}>%s</option>", $line["id"], __($line["description"]));
        }
        print "</select>";
        $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:") . " ";
        $param_int_hidden = $action_id != 7 ? "" : "display : none";
        print "<input size=\"20\" style=\"{$param_int_hidden}\"\n\t\t\t\t\tonkeypress=\"return filterCR(event, filterEditSave)\"\t\t\n\t\t\t\t\tname=\"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
        print "</div>";
        print "<div class=\"dlgSec\">" . __("Options") . "</div>";
        print "<div class=\"dlgSecCont\">";
        print "<div style=\"line-height : 100%\">";
        if ($enabled) {
            $checked = "checked";
        } else {
            $checked = "";
        }
        print "<input type=\"checkbox\" name=\"enabled\" id=\"enabled\" {$checked}>\n\t\t\t\t\t<label for=\"enabled\">" . __('Enabled') . "</label><br/>";
        if ($inverse) {
            $checked = "checked";
        } else {
            $checked = "";
        }
        print "<input type=\"checkbox\" name=\"inverse\" id=\"inverse\" {$checked}>\n\t\t\t\t<label for=\"inverse\">" . __('Inverse match') . "</label>";
        print "</div>";
        print "</div>";
        print "<div class=\"dlgButtons\">";
        $reg_exp = htmlspecialchars($reg_exp, ENT_QUOTES);
        // second escaping seems to be needed for javascript
        print "<div style=\"float : left\">";
        print "<button onclick='return removeFilter({$filter_id}, \"{$reg_exp}\")'>" . __('Remove') . "</button>";
        print "</div>";
        print "<button onclick=\"return filterEditSave()\">" . __('Save') . "</button> ";
        print "<button onclick=\"return filterEditCancel()\">" . __('Cancel') . "</button>";
        print "</div>";
        return;
    }
    if ($subop == "editSave") {
        global $memcache;
        if ($memcache) {
            $memcache->flush();
        }
        $reg_exp = db_escape_string(trim($_REQUEST["reg_exp"]));
        $filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
        $filter_id = db_escape_string($_REQUEST["id"]);
        $feed_id = db_escape_string($_REQUEST["feed_id"]);
        $action_id = db_escape_string($_REQUEST["action_id"]);
        $action_param = db_escape_string($_REQUEST["action_param"]);
        $action_param_label = db_escape_string($_REQUEST["action_param_label"]);
        $enabled = checkbox_to_sql_bool(db_escape_string($_REQUEST["enabled"]));
        $inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"]));
        # for the time being, no other filters use params anyway...
        $filter_param = db_escape_string($_REQUEST["filter_date_modifier"]);
        if (!$feed_id) {
            $feed_id = 'NULL';
        } 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 \n\t\t\t\t\treg_exp = '{$reg_exp}', \n\t\t\t\t\tfeed_id = {$feed_id},\n\t\t\t\t\taction_id = '{$action_id}',\n\t\t\t\t\tfilter_type = '{$filter_type}',\n\t\t\t\t\tenabled = {$enabled},\n\t\t\t\t\tinverse = {$inverse},\n\t\t\t\t\taction_param = '{$action_param}',\n\t\t\t\t\tfilter_param = '{$filter_param}'\n\t\t\t\t\tWHERE id = '{$filter_id}' AND owner_uid = " . $_SESSION["uid"]);
        if (db_affected_rows($link, $result) != 0) {
            print_notice(T_sprintf("Saved filter <b>%s</b>", htmlspecialchars($reg_exp)));
        }
    }
    if ($subop == "remove") {
        if ($memcache) {
            $memcache->flush();
        }
        $ids = split(",", db_escape_string($_REQUEST["ids"]));
        foreach ($ids as $id) {
            db_query($link, "DELETE FROM ttrss_filters WHERE id = '{$id}' AND owner_uid = " . $_SESSION["uid"]);
        }
    }
    if ($subop == "add") {
        if ($memcache) {
            $memcache->flush();
        }
        $regexp = db_escape_string(trim($_REQUEST["reg_exp"]));
        $filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
        $feed_id = db_escape_string($_REQUEST["feed_id"]);
        $action_id = db_escape_string($_REQUEST["action_id"]);
        $action_param = db_escape_string($_REQUEST["action_param"]);
        $action_param_label = db_escape_string($_REQUEST["action_param_label"]);
        $inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"]));
        # for the time being, no other filters use params anyway...
        $filter_param = db_escape_string($_REQUEST["filter_date_modifier"]);
        if (!$regexp) {
            return;
        }
        if (!$feed_id) {
            $feed_id = 'NULL';
        } 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, "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,\n\t\t\t\t\taction_id, action_param, inverse, filter_param) \n\t\t\t\tVALUES \n\t\t\t\t\t('{$regexp}', '{$filter_type}','" . $_SESSION["uid"] . "', \n\t\t\t\t\t\t{$feed_id}, '{$action_id}', '{$action_param}', {$inverse}, '{$filter_param}')");
        if (db_affected_rows($link, $result) != 0) {
            print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp));
        }
        return;
    }
    if ($quiet) {
        return;
    }
    set_pref($link, "_PREFS_ACTIVE_TAB", "filterConfig");
    $sort = db_escape_string($_REQUEST["sort"]);
    if (!$sort || $sort == "undefined") {
        $sort = "reg_exp";
    }
    //		print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
    $result = db_query($link, "SELECT id,description \n\t\t\tFROM ttrss_filter_types ORDER BY description");
    $filter_types = array();
    while ($line = db_fetch_assoc($result)) {
        //array_push($filter_types, $line["description"]);
        $filter_types[$line["id"]] = $line["description"];
    }
    $filter_search = db_escape_string($_REQUEST["search"]);
    if (array_key_exists("search", $_REQUEST)) {
        $_SESSION["prefs_filter_search"] = $filter_search;
    } else {
        $filter_search = $_SESSION["prefs_filter_search"];
    }
    print "<div style='float : right'>\n\t\t\t<input id=\"filter_search\" size=\"20\" type=\"search\"\n\t\t\t\tonfocus=\"javascript:disableHotkeys();\" \n\t\t\t\tonblur=\"javascript:enableHotkeys();\"\n\t\t\t\tonchange=\"javascript:updateFilterList()\" value=\"{$filter_search}\">\n\t\t\t<button onclick=\"javascript:updateFilterList()\">" . __('Search') . "</button>\n\t\t\t&nbsp;\n\t\t\t<a class='helpLinkPic' href=\"javascript:displayHelpInfobox(2)\">\n\t\t\t<img style='vertical-align : top;' src='" . theme_image($link, "images/sign_quest.png") . "'></a>\n\t\t</div>";
    print "<button onclick=\"return quickAddFilter()\">" . __('Create filter') . "</button> ";
    print "<button onclick=\"return editSelectedFilter()\">" . __('Edit') . "</button> ";
    print "<button onclick=\"return removeSelectedFilters()\">" . __('Remove') . "</button> ";
    print "<button onclick=\"rescore_all_feeds()\">" . __('Rescore articles') . "</button> ";
    if ($filter_search) {
        $filter_search = split(' ', db_escape_string($filter_search));
        $tokens = array();
        foreach ($filter_search as $token) {
            $token = trim($token);
            array_push($tokens, "(\n\t\t\t\t\tUPPER(ttrss_filter_actions.description) LIKE UPPER('%{$token}%') OR \n\t\t\t\t\tUPPER(reg_exp) LIKE UPPER('%{$token}%') OR \n\t\t\t\t\tUPPER(action_param) LIKE UPPER('%{$token}%') OR \n\t\t\t\t\tUPPER(ttrss_feeds.title) LIKE UPPER('%{$token}%') OR\n\t\t\t\t\tUPPER(ttrss_filter_types.description) LIKE UPPER('%{$token}%'))");
        }
        $filter_search_query = "(" . join($tokens, " AND ") . ") AND ";
    } else {
        $filter_search_query = "";
    }
    $result = db_query($link, "SELECT \n\t\t\t\tttrss_filters.id AS id,reg_exp,\n\t\t\t\tttrss_filter_types.name AS filter_type_name,\n\t\t\t\tttrss_filter_types.description AS filter_type_descr,\n\t\t\t\tenabled,\n\t\t\t\tinverse,\n\t\t\t\tfeed_id,\n\t\t\t\tfilter_param,\n\t\t\t\tfilter_type,\n\t\t\t\tttrss_filter_actions.description AS action_description,\n\t\t\t\tttrss_feeds.title AS feed_title,\n\t\t\t\tttrss_filter_actions.name AS action_name,\n\t\t\t\tttrss_filters.action_param AS action_param\n\t\t\tFROM \n\t\t\t\tttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN\n\t\t\t\t\tttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)\n\t\t\tWHERE\n\t\t\t\tfilter_type = ttrss_filter_types.id AND\n\t\t\t\t{$filter_search_query}\n\t\t\t\tttrss_filter_actions.id = action_id AND\n\t\t\t\tttrss_filters.owner_uid = " . $_SESSION["uid"] . "\n\t\t\tORDER by action_description, {$sort}");
    if (db_num_rows($result) != 0) {
        print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\" \n\t\t\t\tid=\"prefFilterList\">";
        print "<tr><td class=\"selectPrompt\" colspan=\"8\">\n\t\t\t\t" . __('Select:') . " \n\t\t\t\t\t<a href=\"javascript:selectPrefRows('filter', true)\">" . __('All') . "</a>,\n\t\t\t\t\t<a href=\"javascript:selectPrefRows('filter', false)\">" . __('None') . "</a>\n\t\t\t\t</td</tr>";
        $lnum = 0;
        $cur_action_description = "";
        while ($line = db_fetch_assoc($result)) {
            $filter_id = $line["id"];
            $edit_filter_id = $_REQUEST["id"];
            $enabled = sql_bool_to_bool($line["enabled"]);
            $inverse = sql_bool_to_bool($line["inverse"]);
            $this_row_id = "id=\"FILRR-{$filter_id}\"";
            $line["filter_type_descr"] = __($line["filter_type_descr"]);
            $line["action_description"] = __($line["action_description"]);
            if ($line["action_description"] != $cur_action_description) {
                $cur_action_description = $line["action_description"];
                print "<tr><td class='filterEditCat' colspan='6'>{$cur_action_description}</td></tr>";
                print "<tr class=\"title\">\n\t\t\t\t\t\t<td align='center' width=\"5%\">&nbsp;</td>\n\t\t\t\t\t\t<td width=\"20%\"><a href=\"javascript:updateFilterList('reg_exp')\">" . __('Match') . "</a></td>\n\t\t\t\t\t\t<td width=\"\"><a href=\"javascript:updateFilterList('feed_title')\">" . __('Feed') . "</a></td>\n\t\t\t\t\t\t<td width=\"20%\"><a href=\"javascript:updateFilterList('filter_type')\">" . __('Field') . "</a></td>\n\t\t\t\t\t\t<td width=\"20%\"><a href=\"javascript:updateFilterList('action_param')\">" . __('Params') . "</a></td>";
                $lnum = 0;
            }
            $class = $lnum % 2 ? "even" : "odd";
            print "<tr class=\"{$class}\" {$this_row_id}>";
            $line["reg_exp"] = htmlspecialchars($line["reg_exp"]);
            if (!$line["feed_title"]) {
                $line["feed_title"] = __("All feeds");
            }
            if (!$line["action_param"]) {
                $line["action_param"] = "&mdash;";
            } else {
                if ($line["action_name"] == "score") {
                    $score_pic = theme_image($link, "images/" . get_score_pic($line["action_param"]));
                    $score_pic = "<img class='hlScorePic' src=\"{$score_pic}\">";
                    $line["action_param"] = "{$score_pic} " . $line["action_param"];
                }
            }
            $line["feed_title"] = htmlspecialchars($line["feed_title"]);
            print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"filter\");' \n\t\t\t\t\ttype=\"checkbox\" id=\"FICHK-" . $line["id"] . "\"></td>";
            $filter_params = array("before" => __("before"), "after" => __("after"));
            if ($line["action_name"] == 'label') {
                $tmp_result = db_query($link, "SELECT fg_color, bg_color\n\t\t\t\t\t\tFROM ttrss_labels2 WHERE caption = '" . db_escape_string($line["action_param"]) . "' AND\n\t\t\t\t\t\t\towner_uid = " . $_SESSION["uid"]);
                $fg_color = db_fetch_result($tmp_result, 0, "fg_color");
                $bg_color = db_fetch_result($tmp_result, 0, "bg_color");
                $tmp = "<div class='labelColorIndicator' id='LICID-{$id}' \n\t\t\t\t\t\tstyle='color : {$fg_color}; background-color : {$bg_color}'>\n\t\t\t\t\t\t&alpha;";
                $tmp .= "</div>";
                $line["action_param"] = "{$tmp} " . $line["action_param"];
            }
            if ($line["filter_type"] == 5) {
                if (!strtotime($line["reg_exp"])) {
                    $line["reg_exp"] = "<span class=\"filterDateError\">" . $line["reg_exp"] . "</span>";
                }
                $line["reg_exp"] = __("Date") . " " . $filter_params[$line['filter_param']] . " " . $line["reg_exp"];
            }
            if (!$enabled) {
                $line["reg_exp"] = "<span class=\"insensitive\">" . $line["reg_exp"] . " " . __("(Disabled)") . "</span>";
                $line["feed_title"] = "<span class=\"insensitive\">" . $line["feed_title"] . "</span>";
                $line["filter_type_descr"] = "<span class=\"insensitive\">" . $line["filter_type_descr"] . "</span>";
                $line["action_description"] = "<span class=\"insensitive\">" . $line["action_description"] . "</span>";
                $line["action_param"] = "<span class=\"insensitive\">" . $line["action_param"] . "</span>";
            }
            $onclick = "onclick='editFilter({$filter_id})' title='" . __('Click to edit') . "'";
            $inverse_label = "";
            if ($inverse) {
                $inverse_label = " <span class='insensitive'>" . __('(Inverse)') . "</span>";
            }
            print "<td {$onclick}>" . $line["reg_exp"] . "{$inverse_label}</td>";
            print "<td {$onclick}>" . $line["feed_title"] . "</td>";
            print "<td {$onclick}>" . $line["filter_type_descr"] . "</td>";
            print "<td {$onclick}>" . $line["action_param"] . "</td>";
            print "</tr>";
            ++$lnum;
        }
        print "</table>";
    } else {
        print "<p>";
        if (!$filter_search) {
            print_warning(__('No filters defined.'));
        } else {
            print_warning(__('No matching filters found.'));
        }
        print "</p>";
    }
}
Beispiel #13
0
function module_pref_feeds($link)
{
    global $update_intervals;
    global $purge_intervals;
    global $update_methods;
    $subop = $_REQUEST["subop"];
    $quiet = $_REQUEST["quiet"];
    $mode = $_REQUEST["mode"];
    if ($subop == "renamecat") {
        $title = db_escape_string($_REQUEST['title']);
        $id = db_escape_string($_REQUEST['id']);
        if ($title) {
            db_query($link, "UPDATE ttrss_feed_categories SET\n\t\t\t\t\ttitle = '{$title}' WHERE id = '{$id}' AND owner_uid = " . $_SESSION["uid"]);
        }
        return;
    }
    if ($subop == "remtwitterinfo") {
        db_query($link, "UPDATE ttrss_users SET twitter_oauth = NULL\n\t\t\t\tWHERE id = " . $_SESSION['uid']);
        return;
    }
    if ($subop == "getfeedtree") {
        $search = $_SESSION["prefs_feed_search"];
        if ($search) {
            $search_qpart = " AND LOWER(title) LIKE LOWER('%{$search}%')";
        }
        $root = array();
        $root['id'] = 'root';
        $root['name'] = __('Feeds');
        $root['items'] = array();
        $root['type'] = 'category';
        if (get_pref($link, 'ENABLE_FEED_CATS')) {
            $result = db_query($link, "SELECT id, title FROM ttrss_feed_categories\n\t\t\t\t\tWHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY order_id, title");
            while ($line = db_fetch_assoc($result)) {
                $cat = array();
                $cat['id'] = 'CAT:' . $line['id'];
                $cat['bare_id'] = $feed_id;
                $cat['name'] = $line['title'];
                $cat['items'] = array();
                $cat['checkbox'] = false;
                $cat['type'] = 'category';
                $feed_result = db_query($link, "SELECT id, title, last_error,\n\t\t\t\t\t\t" . SUBSTRING_FOR_DATE . "(last_updated,1,19) AS last_updated\n\t\t\t\t\t\tFROM ttrss_feeds\n\t\t\t\t\t\tWHERE cat_id = '" . $line['id'] . "' AND owner_uid = " . $_SESSION["uid"] . "{$search_qpart} ORDER BY order_id, title");
                while ($feed_line = db_fetch_assoc($feed_result)) {
                    $feed = array();
                    $feed['id'] = 'FEED:' . $feed_line['id'];
                    $feed['bare_id'] = $feed_line['id'];
                    $feed['name'] = $feed_line['title'];
                    $feed['checkbox'] = false;
                    $feed['error'] = $feed_line['last_error'];
                    $feed['icon'] = getFeedIcon($feed_line['id']);
                    $feed['param'] = make_local_datetime($link, $feed_line['last_updated'], true);
                    array_push($cat['items'], $feed);
                }
                $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
                if (count($cat['items']) > 0) {
                    array_push($root['items'], $cat);
                }
                $root['param'] += count($cat['items']);
            }
            /* Uncategorized is a special case */
            $cat = array();
            $cat['id'] = 'CAT:0';
            $cat['bare_id'] = 0;
            $cat['name'] = __("Uncategorized");
            $cat['items'] = array();
            $cat['type'] = 'category';
            $cat['checkbox'] = false;
            $feed_result = db_query($link, "SELECT id, title,last_error,\n\t\t\t\t\t" . SUBSTRING_FOR_DATE . "(last_updated,1,19) AS last_updated\n\t\t\t\t\tFROM ttrss_feeds\n\t\t\t\t\tWHERE cat_id IS NULL AND owner_uid = " . $_SESSION["uid"] . "{$search_qpart} ORDER BY order_id, title");
            while ($feed_line = db_fetch_assoc($feed_result)) {
                $feed = array();
                $feed['id'] = 'FEED:' . $feed_line['id'];
                $feed['bare_id'] = $feed_line['id'];
                $feed['name'] = $feed_line['title'];
                $feed['checkbox'] = false;
                $feed['error'] = $feed_line['last_error'];
                $feed['icon'] = getFeedIcon($feed_line['id']);
                $feed['param'] = make_local_datetime($link, $feed_line['last_updated'], true);
                array_push($cat['items'], $feed);
            }
            $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
            if (count($cat['items']) > 0) {
                array_push($root['items'], $cat);
            }
            $root['param'] += count($cat['items']);
            $root['param'] = T_sprintf('(%d feeds)', $root['param']);
        } else {
            $feed_result = db_query($link, "SELECT id, title, last_error,\n\t\t\t\t\t" . SUBSTRING_FOR_DATE . "(last_updated,1,19) AS last_updated\n\t\t\t\t\tFROM ttrss_feeds\n\t\t\t\t\tWHERE owner_uid = " . $_SESSION["uid"] . "{$search_qpart} ORDER BY order_id, title");
            while ($feed_line = db_fetch_assoc($feed_result)) {
                $feed = array();
                $feed['id'] = 'FEED:' . $feed_line['id'];
                $feed['bare_id'] = $feed_line['id'];
                $feed['name'] = $feed_line['title'];
                $feed['checkbox'] = false;
                $feed['error'] = $feed_line['last_error'];
                $feed['icon'] = getFeedIcon($feed_line['id']);
                $feed['param'] = make_local_datetime($link, $feed_line['last_updated'], true);
                array_push($root['items'], $feed);
            }
            $root['param'] = T_sprintf('(%d feeds)', count($root['items']));
        }
        $fl = array();
        $fl['identifier'] = 'id';
        $fl['label'] = 'name';
        $fl['items'] = array($root);
        print json_encode($fl);
        return;
    }
    if ($subop == "catsortreset") {
        db_query($link, "UPDATE ttrss_feed_categories\n\t\t\t\t\tSET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
        return;
    }
    if ($subop == "feedsortreset") {
        db_query($link, "UPDATE ttrss_feeds\n\t\t\t\t\tSET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
        return;
    }
    if ($subop == "savefeedorder") {
        #			if ($_POST['payload']) {
        #				file_put_contents("/tmp/blahblah.txt", $_POST['payload']);
        #				$data = json_decode($_POST['payload'], true);
        #			} else {
        #				$data = json_decode(file_get_contents("/tmp/blahblah.txt"), true);
        #			}
        $data = json_decode($_POST['payload'], true);
        if (is_array($data) && is_array($data['items'])) {
            $cat_order_id = 0;
            $data_map = array();
            foreach ($data['items'] as $item) {
                if ($item['id'] != 'root') {
                    if (is_array($item['items'])) {
                        if (isset($item['items']['_reference'])) {
                            $data_map[$item['id']] = array($item['items']);
                        } else {
                            $data_map[$item['id']] =& $item['items'];
                        }
                    }
                }
            }
            foreach ($data['items'][0]['items'] as $item) {
                $id = $item['_reference'];
                $bare_id = substr($id, strpos($id, ':') + 1);
                ++$cat_order_id;
                if ($bare_id > 0) {
                    db_query($link, "UPDATE ttrss_feed_categories\n\t\t\t\t\t\t\tSET order_id = '{$cat_order_id}' WHERE id = '{$bare_id}' AND\n\t\t\t\t\t\t\towner_uid = " . $_SESSION["uid"]);
                }
                $feed_order_id = 0;
                if (is_array($data_map[$id])) {
                    foreach ($data_map[$id] as $feed) {
                        $id = $feed['_reference'];
                        $feed_id = substr($id, strpos($id, ':') + 1);
                        if ($bare_id != 0) {
                            $cat_query = "cat_id = '{$bare_id}'";
                        } else {
                            $cat_query = "cat_id = NULL";
                        }
                        db_query($link, "UPDATE ttrss_feeds\n\t\t\t\t\t\t\t\tSET order_id = '{$feed_order_id}',\n\t\t\t\t\t\t\t\t{$cat_query}\n\t\t\t\t\t\t\t\tWHERE id = '{$feed_id}' AND\n\t\t\t\t\t\t\t\t\towner_uid = " . $_SESSION["uid"]);
                        ++$feed_order_id;
                    }
                }
            }
        }
        return;
    }
    if ($subop == "removeicon") {
        $feed_id = db_escape_string($_REQUEST["feed_id"]);
        $result = db_query($link, "SELECT id FROM ttrss_feeds\n\t\t\t\tWHERE id = '{$feed_id}' AND owner_uid = " . $_SESSION["uid"]);
        if (db_num_rows($result) != 0) {
            unlink(ICONS_DIR . "/{$feed_id}.ico");
        }
        return;
    }
    if ($subop == "uploadicon") {
        $icon_file = $_FILES['icon_file']['tmp_name'];
        $feed_id = db_escape_string($_REQUEST["feed_id"]);
        if (is_file($icon_file) && $feed_id) {
            if (filesize($icon_file) < 20000) {
                $result = db_query($link, "SELECT id FROM ttrss_feeds\n\t\t\t\t\t\tWHERE id = '{$feed_id}' AND owner_uid = " . $_SESSION["uid"]);
                if (db_num_rows($result) != 0) {
                    unlink(ICONS_DIR . "/{$feed_id}.ico");
                    move_uploaded_file($icon_file, ICONS_DIR . "/{$feed_id}.ico");
                    $rc = 0;
                } else {
                    $rc = 2;
                }
            } else {
                $rc = 1;
            }
        } else {
            $rc = 2;
        }
        print "<script type=\"text/javascript\">";
        print "parent.uploadIconHandler({$rc});";
        print "</script>";
        return;
    }
    if ($subop == "editfeed") {
        $feed_id = db_escape_string($_REQUEST["id"]);
        $result = db_query($link, "SELECT * FROM ttrss_feeds WHERE id = '{$feed_id}' AND\n\t\t\t\t\towner_uid = " . $_SESSION["uid"]);
        $title = htmlspecialchars(db_fetch_result($result, 0, "title"));
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"{$feed_id}\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"editSave\">";
        print "<div class=\"dlgSec\">" . __("Feed") . "</div>";
        print "<div class=\"dlgSecCont\">";
        /* Title */
        print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"\n\t\t\t\tplaceHolder=\"" . __("Feed Title") . "\"\n\t\t\t\tstyle=\"font-size : 16px; width: 20em\" name=\"title\" value=\"{$title}\">";
        /* Feed URL */
        $feed_url = db_fetch_result($result, 0, "feed_url");
        $feed_url = htmlspecialchars(db_fetch_result($result, 0, "feed_url"));
        print "<hr/>";
        print __('URL:') . " ";
        print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"\n\t\t\t\tplaceHolder=\"" . __("Feed URL") . "\"\n\t\t\t\tregExp='^(http|https)://.*' style=\"width : 20em\"\n\t\t\t\tname=\"feed_url\" value=\"{$feed_url}\">";
        $last_error = db_fetch_result($result, 0, "last_error");
        if ($last_error) {
            print "&nbsp;<span title=\"" . htmlspecialchars($last_error) . "\"\n\t\t\t\t\tclass=\"feed_error\">(error)</span>";
        }
        /* Category */
        if (get_pref($link, 'ENABLE_FEED_CATS')) {
            $cat_id = db_fetch_result($result, 0, "cat_id");
            print "<hr/>";
            print __('Place in category:') . " ";
            print_feed_cat_select($link, "cat_id", $cat_id, 'dojoType="dijit.form.Select"');
        }
        print "</div>";
        print "<div class=\"dlgSec\">" . __("Update") . "</div>";
        print "<div class=\"dlgSecCont\">";
        /* Update Interval */
        $update_interval = db_fetch_result($result, 0, "update_interval");
        print_select_hash("update_interval", $update_interval, $update_intervals, 'dojoType="dijit.form.Select"');
        /* Update method */
        $update_method = db_fetch_result($result, 0, "update_method", 'dojoType="dijit.form.Select"');
        print " " . __('using') . " ";
        print_select_hash("update_method", $update_method, $update_methods, 'dojoType="dijit.form.Select"');
        $purge_interval = db_fetch_result($result, 0, "purge_interval");
        /* Purge intl */
        print "<hr/>";
        print __('Article purging:') . " ";
        print_select_hash("purge_interval", $purge_interval, $purge_intervals, 'dojoType="dijit.form.Select" ' . (FORCE_ARTICLE_PURGE == 0 ? "" : 'disabled="1"'));
        print "</div>";
        print "<div class=\"dlgSec\">" . __("Authentication") . "</div>";
        print "<div class=\"dlgSecCont\">";
        $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login"));
        #			print "<table>";
        #			print "<tr><td>" . __('Login:'******'<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.') . "\n\t\t\t\t</div>";
        #			print "</td></tr></table>";
        print "</div>";
        print "<div class=\"dlgSec\">" . __("Options") . "</div>";
        print "<div class=\"dlgSecCont\">";
        #			print "<div style=\"line-height : 100%\">";
        $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
        if ($private) {
            $checked = "checked=\"1\"";
        } else {
            $checked = "";
        }
        print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"private\" id=\"private\"\n\t\t\t\t{$checked}>&nbsp;<label for=\"private\">" . __('Hide from Popular feeds') . "</label>";
        $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
        if ($rtl_content) {
            $checked = "checked=\"1\"";
        } else {
            $checked = "";
        }
        print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"\n\t\t\t\t{$checked}>&nbsp;<label for=\"rtl_content\">" . __('Right-to-left content') . "</label>";
        $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
        if ($include_in_digest) {
            $checked = "checked=\"1\"";
        } else {
            $checked = "";
        }
        print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\"\n\t\t\t\tname=\"include_in_digest\"\n\t\t\t\t{$checked}>&nbsp;<label for=\"include_in_digest\">" . __('Include in e-mail digest') . "</label>";
        $always_display_enclosures = sql_bool_to_bool(db_fetch_result($result, 0, "always_display_enclosures"));
        if ($always_display_enclosures) {
            $checked = "checked";
        } else {
            $checked = "";
        }
        print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\"\n\t\t\t\tname=\"always_display_enclosures\"\n\t\t\t\t{$checked}>&nbsp;<label for=\"always_display_enclosures\">" . __('Always display image attachments') . "</label>";
        $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
        if ($cache_images) {
            $checked = "checked=\"1\"";
        } else {
            $checked = "";
        }
        if (SIMPLEPIE_CACHE_IMAGES) {
            print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\"\n\t\t\t\tname=\"cache_images\"\n\t\t\t\t{$checked}>&nbsp;<label for=\"cache_images\">" . __('Cache images locally (SimplePie only)') . "</label>";
        }
        $mark_unread_on_update = sql_bool_to_bool(db_fetch_result($result, 0, "mark_unread_on_update"));
        if ($mark_unread_on_update) {
            $checked = "checked";
        } else {
            $checked = "";
        }
        print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"mark_unread_on_update\"\n\t\t\t\tname=\"mark_unread_on_update\"\n\t\t\t\t{$checked}>&nbsp;<label for=\"mark_unread_on_update\">" . __('Mark updated articles as unread') . "</label>";
        $update_on_checksum_change = sql_bool_to_bool(db_fetch_result($result, 0, "update_on_checksum_change"));
        if ($update_on_checksum_change) {
            $checked = "checked";
        } else {
            $checked = "";
        }
        print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"update_on_checksum_change\"\n\t\t\t\tname=\"update_on_checksum_change\"\n\t\t\t\t{$checked}>&nbsp;<label for=\"update_on_checksum_change\">" . __('Mark posts as updated on content change') . "</label>";
        #			print "</div>";
        print "</div>";
        /* Icon */
        print "<div class=\"dlgSec\">" . __("Icon") . "</div>";
        print "<div class=\"dlgSecCont\">";
        print "<iframe name=\"icon_upload_iframe\"\n\t\t\t\tstyle=\"width: 400px; height: 100px; display: none;\"></iframe>";
        print "<form style='display : block' target=\"icon_upload_iframe\"\n\t\t\t\tenctype=\"multipart/form-data\" method=\"POST\"\n\t\t\t\taction=\"backend.php\">\n\t\t\t\t<input id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\">\n\t\t\t\t<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">\n\t\t\t\t<input type=\"hidden\" name=\"feed_id\" value=\"{$feed_id}\">\n\t\t\t\t<input type=\"hidden\" name=\"subop\" value=\"uploadicon\">\n\t\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\"\n\t\t\t\t\ttype=\"submit\">" . __('Replace') . "</button>\n\t\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon({$feed_id});\"\n\t\t\t\t\ttype=\"submit\">" . __('Remove') . "</button>\n\t\t\t\t</form>";
        print "</div>";
        $title = htmlspecialchars($title, ENT_QUOTES);
        print "<div class='dlgButtons'>\n\t\t\t\t<div style=\"float : left\">\n\t\t\t\t<button dojoType=\"dijit.form.Button\" onclick='return unsubscribeFeed({$feed_id}, \"{$title}\")'>" . __('Unsubscribe') . "</button>";
        if (PUBSUBHUBBUB_ENABLED) {
            $pubsub_state = db_fetch_result($result, 0, "pubsub_state");
            $pubsub_btn_disabled = $pubsub_state == 2 ? "" : "disabled=\"1\"";
            print "<button dojoType=\"dijit.form.Button\" id=\"pubsubReset_Btn\" {$pubsub_btn_disabled}\n\t\t\t\t\t\tonclick='return resetPubSub({$feed_id}, \"{$title}\")'>" . __('Resubscribe to push updates') . "</button>";
        }
        print "</div>";
        print "<div dojoType=\"dijit.Tooltip\" connectId=\"pubsubReset_Btn\" position=\"below\">" . __('Resets PubSubHubbub subscription status for push-enabled feeds.') . "</div>";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').execute()\">" . __('Save') . "</button>\n\t\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').hide()\">" . __('Cancel') . "</button>\n\t\t\t</div>";
        return;
    }
    if ($subop == "editfeeds") {
        $feed_ids = db_escape_string($_REQUEST["ids"]);
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"ids\" value=\"{$feed_ids}\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"batchEditSave\">";
        print "<div class=\"dlgSec\">" . __("Feed") . "</div>";
        print "<div class=\"dlgSecCont\">";
        /* Title */
        print "<input dojoType=\"dijit.form.ValidationTextBox\"\n\t\t\t\tdisabled=\"1\" style=\"font-size : 16px; width : 20em;\" required=\"1\"\n\t\t\t\tname=\"title\" value=\"{$title}\">";
        batch_edit_cbox("title");
        /* Feed URL */
        print "<br/>";
        print __('URL:') . " ";
        print "<input dojoType=\"dijit.form.ValidationTextBox\" disabled=\"1\"\n\t\t\t\trequired=\"1\" regExp='^(http|https)://.*' style=\"width : 20em\"\n\t\t\t\tname=\"feed_url\" value=\"{$feed_url}\">";
        batch_edit_cbox("feed_url");
        /* Category */
        if (get_pref($link, 'ENABLE_FEED_CATS')) {
            print "<br/>";
            print __('Place in category:') . " ";
            print_feed_cat_select($link, "cat_id", $cat_id, 'disabled="1" dojoType="dijit.form.Select"');
            batch_edit_cbox("cat_id");
        }
        print "</div>";
        print "<div class=\"dlgSec\">" . __("Update") . "</div>";
        print "<div class=\"dlgSecCont\">";
        /* Update Interval */
        print_select_hash("update_interval", $update_interval, $update_intervals, 'disabled="1" dojoType="dijit.form.Select"');
        batch_edit_cbox("update_interval");
        /* Update method */
        print " " . __('using') . " ";
        print_select_hash("update_method", $update_method, $update_methods, 'disabled="1" dojoType="dijit.form.Select"');
        batch_edit_cbox("update_method");
        /* Purge intl */
        if (FORCE_ARTICLE_PURGE == 0) {
            print "<br/>";
            print __('Article purging:') . " ";
            print_select_hash("purge_interval", $purge_interval, $purge_intervals, 'disabled="1" dojoType="dijit.form.Select"');
            batch_edit_cbox("purge_interval");
        }
        print "</div>";
        print "<div class=\"dlgSec\">" . __("Authentication") . "</div>";
        print "<div class=\"dlgSecCont\">";
        print "<input dojoType=\"dijit.form.TextBox\"\n\t\t\t\tplaceHolder=\"" . __("Login") . "\" disabled=\"1\"\n\t\t\t\tname=\"auth_login\" value=\"{$auth_login}\">";
        batch_edit_cbox("auth_login");
        print "<br/><input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"\n\t\t\t\tplaceHolder=\"" . __("Password") . "\" disabled=\"1\"\n\t\t\t\tvalue=\"{$auth_pass}\">";
        batch_edit_cbox("auth_pass");
        print "</div>";
        print "<div class=\"dlgSec\">" . __("Options") . "</div>";
        print "<div class=\"dlgSecCont\">";
        print "<input disabled=\"1\" type=\"checkbox\" name=\"private\" id=\"private\"\n\t\t\t\tdojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"private_l\" class='insensitive' for=\"private\">" . __('Hide from Popular feeds') . "</label>";
        print "&nbsp;";
        batch_edit_cbox("private", "private_l");
        print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"\n\t\t\t\tdojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">" . __('Right-to-left content') . "</label>";
        print "&nbsp;";
        batch_edit_cbox("rtl_content", "rtl_content_l");
        print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"include_in_digest\"\n\t\t\t\tname=\"include_in_digest\"\n\t\t\t\tdojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">" . __('Include in e-mail digest') . "</label>";
        print "&nbsp;";
        batch_edit_cbox("include_in_digest", "include_in_digest_l");
        print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"always_display_enclosures\"\n\t\t\t\tname=\"always_display_enclosures\"\n\t\t\t\tdojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">" . __('Always display image attachments') . "</label>";
        print "&nbsp;";
        batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
        if (SIMPLEPIE_CACHE_IMAGES) {
            print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"cache_images\"\n\t\t\t\t\tname=\"cache_images\"\n\t\t\t\t\tdojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"cache_images_l\"\n\t\t\t\t\tfor=\"cache_images\">" . __('Cache images locally') . "</label>";
            print "&nbsp;";
            batch_edit_cbox("cache_images", "cache_images_l");
        }
        print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"mark_unread_on_update\"\n\t\t\t\tname=\"mark_unread_on_update\"\n\t\t\t\tdojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"mark_unread_on_update_l\" class='insensitive' for=\"mark_unread_on_update\">" . __('Mark updated articles as unread') . "</label>";
        print "&nbsp;";
        batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l");
        print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"update_on_checksum_change\"\n\t\t\t\tname=\"update_on_checksum_change\"\n\t\t\t\tdojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"update_on_checksum_change_l\" class='insensitive' for=\"update_on_checksum_change\">" . __('Mark posts as updated on content change') . "</label>";
        print "&nbsp;";
        batch_edit_cbox("update_on_checksum_change", "update_on_checksum_change_l");
        print "</div>";
        print "<div class='dlgButtons'>\n\t\t\t\t<button dojoType=\"dijit.form.Button\"\n\t\t\t\t\tonclick=\"return dijit.byId('feedEditDlg').execute()\">" . __('Save') . "</button>\n\t\t\t\t<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"return dijit.byId('feedEditDlg').hide()\">" . __('Cancel') . "</button>\n\t\t\t\t</div>";
        return;
    }
    if ($subop == "editSave" || $subop == "batchEditSave") {
        $feed_title = db_escape_string(trim($_POST["title"]));
        $feed_link = db_escape_string(trim($_POST["feed_url"]));
        $upd_intl = (int) db_escape_string($_POST["update_interval"]);
        $purge_intl = (int) db_escape_string($_POST["purge_interval"]);
        $feed_id = (int) db_escape_string($_POST["id"]);
        /* editSave */
        $feed_ids = db_escape_string($_POST["ids"]);
        /* batchEditSave */
        $cat_id = (int) db_escape_string($_POST["cat_id"]);
        $auth_login = db_escape_string(trim($_POST["auth_login"]));
        $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
        $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
        $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
        $include_in_digest = checkbox_to_sql_bool(db_escape_string($_POST["include_in_digest"]));
        $cache_images = checkbox_to_sql_bool(db_escape_string($_POST["cache_images"]));
        $update_method = (int) db_escape_string($_POST["update_method"]);
        $always_display_enclosures = checkbox_to_sql_bool(db_escape_string($_POST["always_display_enclosures"]));
        $mark_unread_on_update = checkbox_to_sql_bool(db_escape_string($_POST["mark_unread_on_update"]));
        $update_on_checksum_change = checkbox_to_sql_bool(db_escape_string($_POST["update_on_checksum_change"]));
        if (get_pref($link, 'ENABLE_FEED_CATS')) {
            if ($cat_id && $cat_id != 0) {
                $category_qpart = "cat_id = '{$cat_id}',";
                $category_qpart_nocomma = "cat_id = '{$cat_id}'";
            } else {
                $category_qpart = 'cat_id = NULL,';
                $category_qpart_nocomma = 'cat_id = NULL';
            }
        } else {
            $category_qpart = "";
            $category_qpart_nocomma = "";
        }
        if (SIMPLEPIE_CACHE_IMAGES) {
            $cache_images_qpart = "cache_images = {$cache_images},";
        } else {
            $cache_images_qpart = "";
        }
        if ($subop == "editSave") {
            $result = db_query($link, "UPDATE ttrss_feeds SET\n\t\t\t\t\t{$category_qpart}\n\t\t\t\t\ttitle = '{$feed_title}', feed_url = '{$feed_link}',\n\t\t\t\t\tupdate_interval = '{$upd_intl}',\n\t\t\t\t\tpurge_interval = '{$purge_intl}',\n\t\t\t\t\tauth_login = '******',\n\t\t\t\t\tauth_pass = '******',\n\t\t\t\t\tprivate = {$private},\n\t\t\t\t\trtl_content = {$rtl_content},\n\t\t\t\t\t{$cache_images_qpart}\n\t\t\t\t\tinclude_in_digest = {$include_in_digest},\n\t\t\t\t\talways_display_enclosures = {$always_display_enclosures},\n\t\t\t\t\tmark_unread_on_update = {$mark_unread_on_update},\n\t\t\t\t\tupdate_on_checksum_change = {$update_on_checksum_change},\n\t\t\t\t\tupdate_method = '{$update_method}'\n\t\t\t\t\tWHERE id = '{$feed_id}' AND owner_uid = " . $_SESSION["uid"]);
        } else {
            if ($subop == "batchEditSave") {
                $feed_data = array();
                foreach (array_keys($_POST) as $k) {
                    if ($k != "op" && $k != "subop" && $k != "ids") {
                        $feed_data[$k] = $_POST[$k];
                    }
                }
                db_query($link, "BEGIN");
                foreach (array_keys($feed_data) as $k) {
                    $qpart = "";
                    switch ($k) {
                        case "title":
                            $qpart = "title = '{$feed_title}'";
                            break;
                        case "feed_url":
                            $qpart = "feed_url = '{$feed_link}'";
                            break;
                        case "update_interval":
                            $qpart = "update_interval = '{$upd_intl}'";
                            break;
                        case "purge_interval":
                            $qpart = "purge_interval = '{$purge_intl}'";
                            break;
                        case "auth_login":
                            $qpart = "auth_login = '******'";
                            break;
                        case "auth_pass":
                            $qpart = "auth_pass = '******'";
                            break;
                        case "private":
                            $qpart = "private = '{$private}'";
                            break;
                        case "include_in_digest":
                            $qpart = "include_in_digest = '{$include_in_digest}'";
                            break;
                        case "always_display_enclosures":
                            $qpart = "always_display_enclosures = '{$always_display_enclosures}'";
                            break;
                        case "mark_unread_on_update":
                            $qpart = "mark_unread_on_update = '{$mark_unread_on_update}'";
                            break;
                        case "update_on_checksum_change":
                            $qpart = "update_on_checksum_change = '{$update_on_checksum_change}'";
                            break;
                        case "cache_images":
                            $qpart = "cache_images = '{$cache_images}'";
                            break;
                        case "rtl_content":
                            $qpart = "rtl_content = '{$rtl_content}'";
                            break;
                        case "update_method":
                            $qpart = "update_method = '{$update_method}'";
                            break;
                        case "cat_id":
                            $qpart = $category_qpart_nocomma;
                            break;
                    }
                    if ($qpart) {
                        db_query($link, "UPDATE ttrss_feeds SET {$qpart} WHERE id IN ({$feed_ids})\n\t\t\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]);
                        print "<br/>";
                    }
                }
                db_query($link, "COMMIT");
            }
        }
        return;
    }
    if ($subop == "resetPubSub") {
        $ids = db_escape_string($_REQUEST["ids"]);
        db_query($link, "UPDATE ttrss_feeds SET pubsub_state = 0 WHERE id IN ({$ids})\n\t\t\t\tAND owner_uid = " . $_SESSION["uid"]);
        return;
    }
    if ($subop == "remove") {
        $ids = split(",", db_escape_string($_REQUEST["ids"]));
        foreach ($ids as $id) {
            remove_feed($link, $id, $_SESSION["uid"]);
        }
        return;
    }
    if ($subop == "clear") {
        $id = db_escape_string($_REQUEST["id"]);
        clear_feed_articles($link, $id);
    }
    if ($subop == "rescore") {
        $ids = split(",", db_escape_string($_REQUEST["ids"]));
        foreach ($ids as $id) {
            $filters = load_filters($link, $id, $_SESSION["uid"], 6);
            $result = db_query($link, "SELECT\n\t\t\t\t\ttitle, content, link, ref_id, author," . SUBSTRING_FOR_DATE . "(updated, 1, 19) AS updated\n\t\t\t\t  \tFROM\n\t\t\t\t\t\tttrss_user_entries, ttrss_entries\n\t\t\t\t\t\tWHERE ref_id = id AND feed_id = '{$id}' AND\n\t\t\t\t\t\t\towner_uid = " . $_SESSION['uid'] . "\n\t\t\t\t\t\t");
            $scores = array();
            while ($line = db_fetch_assoc($result)) {
                $tags = get_article_tags($link, $line["ref_id"]);
                $article_filters = get_article_filters($filters, $line['title'], $line['content'], $line['link'], strtotime($line['updated']), $line['author'], $tags);
                $new_score = calculate_article_score($article_filters);
                if (!$scores[$new_score]) {
                    $scores[$new_score] = array();
                }
                array_push($scores[$new_score], $line['ref_id']);
            }
            foreach (array_keys($scores) as $s) {
                if ($s > 1000) {
                    db_query($link, "UPDATE ttrss_user_entries SET score = '{$s}',\n\t\t\t\t\t\t\tmarked = true WHERE\n\t\t\t\t\t\t\tref_id IN (" . join(',', $scores[$s]) . ")");
                } else {
                    if ($s < -500) {
                        db_query($link, "UPDATE ttrss_user_entries SET score = '{$s}',\n\t\t\t\t\t\t\tunread = false WHERE\n\t\t\t\t\t\t\tref_id IN (" . join(',', $scores[$s]) . ")");
                    } else {
                        db_query($link, "UPDATE ttrss_user_entries SET score = '{$s}' WHERE\n\t\t\t\t\t\t\tref_id IN (" . join(',', $scores[$s]) . ")");
                    }
                }
            }
        }
        print __("All done.");
    }
    if ($subop == "rescoreAll") {
        $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
        while ($feed_line = db_fetch_assoc($result)) {
            $id = $feed_line["id"];
            $filters = load_filters($link, $id, $_SESSION["uid"], 6);
            $tmp_result = db_query($link, "SELECT\n\t\t\t\t\ttitle, content, link, ref_id, author," . SUBSTRING_FOR_DATE . "(updated, 1, 19) AS updated\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\tttrss_user_entries, ttrss_entries\n\t\t\t\t\t\tWHERE ref_id = id AND feed_id = '{$id}' AND\n\t\t\t\t\t\t\towner_uid = " . $_SESSION['uid'] . "\n\t\t\t\t\t\t");
            $scores = array();
            while ($line = db_fetch_assoc($tmp_result)) {
                $tags = get_article_tags($link, $line["ref_id"]);
                $article_filters = get_article_filters($filters, $line['title'], $line['content'], $line['link'], strtotime($line['updated']), $line['author'], $tags);
                $new_score = calculate_article_score($article_filters);
                if (!$scores[$new_score]) {
                    $scores[$new_score] = array();
                }
                array_push($scores[$new_score], $line['ref_id']);
            }
            foreach (array_keys($scores) as $s) {
                if ($s > 1000) {
                    db_query($link, "UPDATE ttrss_user_entries SET score = '{$s}',\n\t\t\t\t\t\t\tmarked = true WHERE\n\t\t\t\t\t\t\tref_id IN (" . join(',', $scores[$s]) . ")");
                } else {
                    db_query($link, "UPDATE ttrss_user_entries SET score = '{$s}' WHERE\n\t\t\t\t\t\t\tref_id IN (" . join(',', $scores[$s]) . ")");
                }
            }
        }
        print __("All done.");
    }
    if ($subop == "add") {
        $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
        $cat_id = db_escape_string($_REQUEST["cat_id"]);
        $p_from = db_escape_string($_REQUEST["from"]);
        /* only read authentication information from POST */
        $auth_login = db_escape_string(trim($_POST["auth_login"]));
        $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
        if ($p_from != 'tt-rss') {
            header("Content-Type: text/html");
            print "<html>\n\t\t\t\t\t<head>\n\t\t\t\t\t\t<title>Tiny Tiny RSS</title>\n\t\t\t\t\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">\n\t\t\t\t\t</head>\n\t\t\t\t\t<body>\n\t\t\t\t\t<img class=\"floatingLogo\" src=\"images/ttrss_logo.png\"\n\t\t\t\t  \t\talt=\"Tiny Tiny RSS\"/>\n\t\t\t\t\t<h1>Subscribe to feed...</h1>";
        }
        $rc = subscribe_to_feed($link, $feed_url, $cat_id, $auth_login, $auth_pass);
        switch ($rc) {
            case 1:
                print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
                break;
            case 2:
                print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
                break;
            case 3:
                print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
                break;
            case 0:
                print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
                break;
            case 4:
                print_notice("Multiple feed URLs found.");
                $feed_urls = get_feeds_from_html($feed_url);
                break;
            case 5:
                print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
                break;
        }
        if ($p_from != 'tt-rss') {
            if ($feed_urls) {
                print "<form action=\"backend.php\">";
                print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
                print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
                print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
                print "<select name=\"feed_url\">";
                foreach ($feed_urls as $url => $name) {
                    $url = htmlspecialchars($url);
                    $name = htmlspecialchars($name);
                    print "<option value=\"{$url}\">{$name}</option>";
                }
                print "<input type=\"submit\" value=\"" . __("Subscribe to selected feed") . "\">";
                print "</form>";
            }
            $tp_uri = get_self_url_prefix() . "/prefs.php";
            $tt_uri = get_self_url_prefix();
            if ($rc <= 2) {
                $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE\n\t\t\t\t\t\tfeed_url = '{$feed_url}' AND owner_uid = " . $_SESSION["uid"]);
                $feed_id = db_fetch_result($result, 0, "id");
            } else {
                $feed_id = 0;
            }
            print "<p>";
            if ($feed_id) {
                print "<form method=\"GET\" style='display: inline'\n\t\t\t\t\t\taction=\"{$tp_uri}\">\n\t\t\t\t\t\t<input type=\"hidden\" name=\"tab\" value=\"feedConfig\">\n\t\t\t\t\t\t<input type=\"hidden\" name=\"subop\" value=\"editFeed\">\n\t\t\t\t\t\t<input type=\"hidden\" name=\"subopparam\" value=\"{$feed_id}\">\n\t\t\t\t\t\t<input type=\"submit\" value=\"" . __("Edit subscription options") . "\">\n\t\t\t\t\t\t</form>";
            }
            print "<form style='display: inline' method=\"GET\" action=\"{$tt_uri}\">\n\t\t\t\t\t<input type=\"submit\" value=\"" . __("Return to Tiny Tiny RSS") . "\">\n\t\t\t\t\t</form></p>";
            print "</body></html>";
            return;
        }
    }
    if ($subop == "categorize") {
        $ids = split(",", db_escape_string($_REQUEST["ids"]));
        $cat_id = db_escape_string($_REQUEST["cat_id"]);
        if ($cat_id == 0) {
            $cat_id_qpart = 'NULL';
        } else {
            $cat_id_qpart = "'{$cat_id}'";
        }
        db_query($link, "BEGIN");
        foreach ($ids as $id) {
            db_query($link, "UPDATE ttrss_feeds SET cat_id = {$cat_id_qpart}\n\t\t\t\t\tWHERE id = '{$id}'\n\t\t\t\t  \tAND owner_uid = " . $_SESSION["uid"]);
        }
        db_query($link, "COMMIT");
    }
    if ($subop == "editCats") {
        $action = $_REQUEST["action"];
        if ($action == "save") {
            $cat_title = db_escape_string(trim($_REQUEST["value"]));
            $cat_id = db_escape_string($_REQUEST["cid"]);
            db_query($link, "BEGIN");
            $result = db_query($link, "SELECT title FROM ttrss_feed_categories\n\t\t\t\t\tWHERE id = '{$cat_id}' AND owner_uid = " . $_SESSION["uid"]);
            if (db_num_rows($result) == 1) {
                $old_title = db_fetch_result($result, 0, "title");
                if ($cat_title != "") {
                    $result = db_query($link, "UPDATE ttrss_feed_categories SET\n\t\t\t\t\t\t\ttitle = '{$cat_title}' WHERE id = '{$cat_id}' AND\n\t\t\t\t\t\t\towner_uid = " . $_SESSION["uid"]);
                    print $cat_title;
                } else {
                    print $old_title;
                }
            } else {
                print $_REQUEST["value"];
            }
            db_query($link, "COMMIT");
            return;
        }
        if ($action == "add") {
            $feed_cat = db_escape_string(trim($_REQUEST["cat"]));
            if (!add_feed_category($link, $feed_cat)) {
                print_warning(T_sprintf("Category <b>\$%s</b> already exists in the database.", $feed_cat));
            }
        }
        if ($action == "remove") {
            $ids = split(",", db_escape_string($_REQUEST["ids"]));
            foreach ($ids as $id) {
                remove_feed_category($link, $id, $_SESSION["uid"]);
            }
        }
        print "<div dojoType=\"dijit.Toolbar\">\n\t\t\t\t<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"newcat\">\n\t\t\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').addCategory()\">" . __('Create category') . "</button></div>";
        $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories\n\t\t\t\tWHERE owner_uid = " . $_SESSION["uid"] . "\n\t\t\t\tORDER BY title");
        #			print "<p>";
        if (db_num_rows($result) != 0) {
            print "<div class=\"prefFeedCatHolder\">";
            #				print "<form id=\"feed_cat_edit_form\" onsubmit=\"return false\">";
            print "<table width=\"100%\" class=\"prefFeedCatList\"\n\t\t\t\t\tcellspacing=\"0\" id=\"prefFeedCatList\">";
            $lnum = 0;
            while ($line = db_fetch_assoc($result)) {
                $class = $lnum % 2 ? "even" : "odd";
                $cat_id = $line["id"];
                $this_row_id = "id=\"FCATR-{$cat_id}\"";
                print "<tr class=\"\" {$this_row_id}>";
                $edit_title = htmlspecialchars($line["title"]);
                print "<td width='5%' align='center'><input\n\t\t\t\t\t\tonclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"\n\t\t\t\t\t\ttype=\"checkbox\"></td>";
                print "<td>";
                #					print "<span id=\"FCATT-$cat_id\">" .
                #						$edit_title . "</span>";
                print "<span dojoType=\"dijit.InlineEditBox\"\n\t\t\t\t\t\twidth=\"300px\" autoSave=\"false\"\n\t\t\t\t\t\tcat-id=\"{$cat_id}\">" . $edit_title . "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">\n\t\t\t\t\t\t\tvar elem = this;\n\t\t\t\t\t\t\tdojo.xhrPost({\n\t\t\t\t\t\t\t\turl: 'backend.php',\n\t\t\t\t\t\t\t\tcontent: {op: 'pref-feeds', subop: 'editCats',\n\t\t\t\t\t\t\t\t\taction: 'save',\n\t\t\t\t\t\t\t\t\tvalue: this.value,\n\t\t\t\t\t\t\t\t\tcid: this.srcNodeRef.getAttribute('cat-id')},\n\t\t\t\t\t\t\t\t\tload: function(response) {\n\t\t\t\t\t\t\t\t\t\telem.attr('value', response);\n\t\t\t\t\t\t\t\t\t\tupdateFeedList();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t</script>\n\t\t\t\t\t</span>";
                print "</td></tr>";
                ++$lnum;
            }
            print "</table>";
            #				print "</form>";
            print "</div>";
        } else {
            print "<p>" . __('No feed categories defined.') . "</p>";
        }
        print "<div class='dlgButtons'>\n\t\t\t\t<div style='float : left'>\n\t\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').removeSelected()\">" . __('Remove selected categories') . "</button>\n\t\t\t\t</div>";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').hide()\">" . __('Close this window') . "</button></div>";
        return;
    }
    if ($quiet) {
        return;
    }
    print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
    print "<div id=\"pref-feeds-feeds\" dojoType=\"dijit.layout.AccordionPane\" title=\"" . __('Feeds') . "\">";
    /* print "<div dojoType=\"dijit.layout.BorderContainer\">";
    		print "<
    			print "</div>"; */
    $result = db_query($link, "SELECT COUNT(id) AS num_errors\n\t\t\tFROM ttrss_feeds WHERE last_error != '' AND owner_uid = " . $_SESSION["uid"]);
    $num_errors = db_fetch_result($result, 0, "num_errors");
    if ($num_errors > 0) {
        $error_button = "<button dojoType=\"dijit.form.Button\"\n\t\t\t  \t\tonclick=\"showFeedsWithErrors()\" id=\"errorButton\">" . __("Feeds with errors") . "</button>";
        //			print format_notice("<a href=\"javascript:showFeedsWithErrors()\">".
        //				__('Some feeds have update errors (click for details)')."</a>");
    }
    if (DB_TYPE == "pgsql") {
        $interval_qpart = "NOW() - INTERVAL '3 months'";
    } else {
        $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
    }
    $result = db_query($link, "SELECT COUNT(*) AS num_inactive FROM ttrss_feeds WHERE\n\t\t\t\t\t(SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE\n\t\t\t\t\t\tttrss_entries.id = ref_id AND\n\t\t\t\t\t\t\tttrss_user_entries.feed_id = ttrss_feeds.id) < {$interval_qpart} AND\n\t\t\tttrss_feeds.owner_uid = " . $_SESSION["uid"]);
    $num_inactive = db_fetch_result($result, 0, "num_inactive");
    if ($num_inactive > 0) {
        $inactive_button = "<button dojoType=\"dijit.form.Button\"\n\t\t\t  \t\tonclick=\"showInactiveFeeds()\">" . __("Inactive feeds") . "</button>";
    }
    $feed_search = db_escape_string($_REQUEST["search"]);
    if (array_key_exists("search", $_REQUEST)) {
        $_SESSION["prefs_feed_search"] = $feed_search;
    } else {
        $feed_search = $_SESSION["prefs_feed_search"];
    }
    print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
    print "<div region='top' dojoType=\"dijit.Toolbar\">";
    #toolbar
    print "<div style='float : right; padding-right : 4px;'>\n\t\t\t<input dojoType=\"dijit.form.TextBox\" id=\"feed_search\" size=\"20\" type=\"search\"\n\t\t\t\tvalue=\"{$feed_search}\">\n\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"updateFeedList()\">" . __('Search') . "</button>\n\t\t\t</div>";
    print "<div dojoType=\"dijit.form.DropDownButton\">" . "<span>" . __('Select') . "</span>";
    print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
    print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\"\n\t\t\tdojoType=\"dijit.MenuItem\">" . __('All') . "</div>";
    print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\"\n\t\t\tdojoType=\"dijit.MenuItem\">" . __('None') . "</div>";
    print "</div></div>";
    print "<div dojoType=\"dijit.form.DropDownButton\">" . "<span>" . __('Feeds') . "</span>";
    print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
    print "<div onclick=\"quickAddFeed()\"\n\t\t\tdojoType=\"dijit.MenuItem\">" . __('Subscribe to feed') . "</div>";
    print "<div onclick=\"editSelectedFeed()\"\n\t\t\tdojoType=\"dijit.MenuItem\">" . __('Edit selected feeds') . "</div>";
    print "<div onclick=\"resetFeedOrder()\"\n\t\t\tdojoType=\"dijit.MenuItem\">" . __('Reset sort order') . "</div>";
    print "</div></div>";
    if (get_pref($link, 'ENABLE_FEED_CATS')) {
        print "<div dojoType=\"dijit.form.DropDownButton\">" . "<span>" . __('Categories') . "</span>";
        print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
        print "<div onclick=\"editFeedCats()\"\n\t\t\t\tdojoType=\"dijit.MenuItem\">" . __('Edit categories') . "</div>";
        print "<div onclick=\"resetCatOrder()\"\n\t\t\t\tdojoType=\"dijit.MenuItem\">" . __('Reset sort order') . "</div>";
        print "</div></div>";
    }
    print $error_button;
    print $inactive_button;
    print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedFeeds()\">" . __('Unsubscribe') . "</button dojoType=\"dijit.form.Button\"> ";
    if (defined('_ENABLE_FEED_DEBUGGING')) {
        print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">\n\t\t\t\t<option value=\"facDefault\" selected>" . __('More actions...') . "</option>";
        if (FORCE_ARTICLE_PURGE == 0) {
            print "<option value=\"facPurge\">" . __('Manual purge') . "</option>";
        }
        print "\n\t\t\t\t<option value=\"facClear\">" . __('Clear feed data') . "</option>\n\t\t\t\t<option value=\"facRescore\">" . __('Rescore articles') . "</option>";
        print "</select>";
    }
    print "</div>";
    # toolbar
    //print '</div>';
    print '<div dojoType="dijit.layout.ContentPane" region="center">';
    print "<div id=\"feedlistLoading\">\n\t\t<img src='images/indicator_tiny.gif'>" . __("Loading, please wait...") . "</div>";
    print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\"\n\t\t\turl=\"backend.php?op=pref-feeds&subop=getfeedtree\">\n\t\t</div>\n\t\t<div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\"\n\t\tquery=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"\n\t\t\tchildrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">\n\t\t</div>\n\t\t<div dojoType=\"fox.PrefFeedTree\" id=\"feedTree\"\n\t\t\tdndController=\"dijit.tree.dndSource\"\n\t\t\tbetweenThreshold=\"5\"\n\t\t\tmodel=\"feedModel\" openOnClick=\"false\">\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('FEED:')) {\n\t\t\t\teditFeed(bare_id);\n\t\t\t} else if (id.match('CAT:')) {\n\t\t\t\teditCat(bare_id, item);\n\t\t\t}\n\t\t</script>\n\t\t<script type=\"dojo/method\" event=\"onLoad\" args=\"item\">\n\t\t\tElement.hide(\"feedlistLoading\");\n\t\t</script>\n\t\t</div>";
    print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\">\n\t\t\t" . __('<b>Hint:</b> you can drag feeds and categories around.') . "\n\t\t\t</div>";
    print '</div>';
    print '</div>';
    print "</div>";
    # feeds pane
    print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"" . __('OPML') . "\">";
    print "<p>" . __("Using OPML you can export and import your feeds and Tiny Tiny RSS settings.") . " ";
    print "<span class=\"insensitive\">" . __("Note: Only main settings profile can be migrated using OPML.") . "</span>";
    print "</p>";
    print "<h3>" . __("Import") . "</h3>";
    print "<br/><iframe id=\"upload_iframe\"\n\t\t\tname=\"upload_iframe\" onload=\"opmlImportComplete(this)\"\n\t\t\tstyle=\"width: 400px; height: 100px; display: none;\"></iframe>";
    print "<form  name=\"opml_form\" style='display : block' target=\"upload_iframe\"\n\t\t\tenctype=\"multipart/form-data\" method=\"POST\"\n\t\t\t\taction=\"backend.php\">\n\t\t\t<input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;\n\t\t\t<input type=\"hidden\" name=\"op\" value=\"dlg\">\n\t\t\t<input type=\"hidden\" name=\"id\" value=\"importOpml\">\n\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"return opmlImport();\" type=\"submit\">" . __('Import') . "</button>";
    print "<h3>" . __("Export") . "</h3>";
    print "<p>" . __('Filename:') . " <input type=\"text\" id=\"filename\" value=\"TinyTinyRSS.opml\" />&nbsp;" . __('Include settings') . "<input type=\"checkbox\" id=\"settings\" CHECKED />" . "<button dojoType=\"dijit.form.Button\"\n\t\t\tonclick=\"gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked)\" >" . __('Export') . "</button></p></form>";
    print "<h3>" . __("Publish") . "</h3>";
    print "<p>" . __('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . " ";
    print "<span class=\"insensitive\">" . __("Note: Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") . "</span>" . "</p>";
    print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('pubOPMLUrl')\">" . __('Display URL') . "</button> ";
    print "</div>";
    # pane
    if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) {
        print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"" . __('Firefox integration') . "\">";
        print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "</p>";
        print "<p>";
        print "<button onclick='window.navigator.registerContentHandler(" . "\"application/vnd.mozilla.maybe.feed\", " . "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" . __('Click here to register this site as a feed reader.') . "</button>";
        print "</p>";
        print "</div>";
        # pane
    }
    print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"" . __('Subscribing using bookmarklet') . "\">";
    print "<p>" . __("Drag the link below to your browser toolbar, open the feed you're interested in in your browser and click on the link to subscribe to it.") . "</p>";
    $bm_subscribe_url = str_replace('%s', '', add_feed_url());
    $confirm_str = __('Subscribe to %s in Tiny Tiny RSS?');
    $bm_url = htmlspecialchars("javascript:{if(confirm('{$confirm_str}'.replace('%s',window.location.href)))window.location.href='{$bm_subscribe_url}'+window.location.href}");
    print "<a href=\"{$bm_url}\" class='bookmarklet'>" . __('Subscribe in Tiny Tiny RSS') . "</a>";
    print "</div>";
    #pane
    print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"" . __('Published & shared articles and generated feeds') . "\">";
    print "<h3>" . __("Published articles and generated feeds") . "</h3>";
    print "<p>" . __('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.') . "</p>";
    $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() . "/public.php?op=rss&id=-2&view-mode=all_articles");
    print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('generatedFeed', '{$rss_url}')\">" . __('Display URL') . "</button> ";
    print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">" . __('Clear all generated URLs') . "</button> ";
    print "<h3>" . __("Articles shared by URL") . "</h3>";
    print "<p>" . __("You can disable all articles shared by unique URLs here.") . "</p>";
    print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">" . __('Unshare all articles') . "</button> ";
    print "</div>";
    #pane
    if (defined('CONSUMER_KEY') && CONSUMER_KEY != '') {
        print "<div id=\"pref-feeds-twitter\" dojoType=\"dijit.layout.AccordionPane\" title=\"" . __('Twitter') . "\">";
        $result = db_query($link, "SELECT COUNT(*) AS cid FROM ttrss_users\n\t\t\t\tWHERE twitter_oauth IS NOT NULL AND twitter_oauth != '' AND\n\t\t\t\tid = " . $_SESSION['uid']);
        $is_registered = db_fetch_result($result, 0, "cid") != 0;
        if (!$is_registered) {
            print_notice(__('Before you can update your Twitter feeds, you must register this instance of Tiny Tiny RSS with Twitter.com.'));
        } else {
            print_notice(__('You have been successfully registered with Twitter.com and should be able to access your Twitter feeds.'));
        }
        print "<button dojoType=\"dijit.form.Button\" onclick=\"window.location.href = 'twitter.php?op=register'\">" . __("Register with Twitter.com") . "</button>";
        print " ";
        print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"return clearTwitterCredentials()\">" . __("Clear stored credentials") . "</button>";
        print "</div>";
        # pane
    }
    print "</div>";
    #container
}