Exemplo n.º 1
0
 function filter_test($filter_type, $reg_exp, $action_id, $action_param, $filter_param, $inverse, $feed_id, $cat_id, $cat_filter)
 {
     $result = db_query($this->link, "SELECT name FROM ttrss_filter_types WHERE\n\t\t\tid = " . $filter_type);
     $type_name = db_fetch_result($result, 0, "name");
     $result = db_query($this->link, "SELECT name FROM ttrss_filter_actions WHERE\n\t\t\tid = " . $action_id);
     $action_name = db_fetch_result($result, 0, "name");
     $filter["reg_exp"] = $reg_exp;
     $filter["action"] = $action_name;
     $filter["type"] = $type_name;
     $filter["action_param"] = $action_param;
     $filter["filter_param"] = $filter_param;
     $filter["inverse"] = $inverse;
     $filters[$type_name] = array($filter);
     if ($feed_id) {
         $feed = $feed_id;
     } else {
         $feed = -4;
     }
     $regexp_valid = preg_match('/' . $filter['reg_exp'] . '/', $filter['reg_exp']) !== FALSE;
     print __("Articles matching this filter:");
     print "<div class=\"filterTestHolder\">";
     print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
     if ($regexp_valid) {
         $feed_title = getFeedTitle($this->link, $feed);
         $qfh_ret = queryFeedHeadlines($this->link, $cat_filter ? $cat_id : $feed, 30, "", $cat_filter, false, false, false, "date_entered DESC", 0, $_SESSION["uid"], $filter);
         $result = $qfh_ret[0];
         $articles = array();
         $found = 0;
         while ($line = db_fetch_assoc($result)) {
             $entry_timestamp = strtotime($line["updated"]);
             $entry_tags = get_article_tags($this->link, $line["id"], $_SESSION["uid"]);
             $content_preview = truncate_string(strip_tags($line["content_preview"]), 100, '...');
             if ($line["feed_title"]) {
                 $feed_title = $line["feed_title"];
             }
             print "<tr>";
             print "<td width='5%' align='center'><input\n\t\t\t\t\tdojoType=\"dijit.form.CheckBox\" checked=\"1\"\n\t\t\t\t\tdisabled=\"1\" type=\"checkbox\"></td>";
             print "<td>";
             print $line["title"];
             print "&nbsp;(";
             print "<b>" . $feed_title . "</b>";
             print "):&nbsp;";
             print "<span class=\"insensitive\">" . $content_preview . "</span>";
             print " " . mb_substr($line["date_entered"], 0, 16);
             print "</td></tr>";
             $found++;
         }
         if ($found == 0) {
             print "<tr><td align='center'>" . __("No articles matching this filter has been found.") . "</td></tr>";
         }
     } else {
         print "<tr><td align='center' class='error'>" . __("Invalid regular expression.") . "</td></tr>";
     }
     print "</table>";
     print "</div>";
 }
 function digestgetcontents()
 {
     $article_id = db_escape_string($_REQUEST['article_id']);
     $result = db_query($this->link, "SELECT content,title,link,marked,published\n\t\t\tFROM ttrss_entries, ttrss_user_entries\n\t\t\tWHERE id = '{$article_id}' AND ref_id = id AND owner_uid = " . $_SESSION['uid']);
     $content = sanitize($this->link, db_fetch_result($result, 0, "content"));
     $title = strip_tags(db_fetch_result($result, 0, "title"));
     $article_url = htmlspecialchars(db_fetch_result($result, 0, "link"));
     $marked = sql_bool_to_bool(db_fetch_result($result, 0, "marked"));
     $published = sql_bool_to_bool(db_fetch_result($result, 0, "published"));
     print json_encode(array("article" => array("id" => $article_id, "url" => $article_url, "tags" => get_article_tags($this->link, $article_id), "marked" => $marked, "published" => $published, "title" => $title, "content" => $content)));
 }
Exemplo n.º 3
0
function format_article($link, $id, $mark_as_read = true, $zoom_mode = false, $owner_uid = false)
{
    if (!$owner_uid) {
        $owner_uid = $_SESSION["uid"];
    }
    $rv = array();
    $rv['id'] = $id;
    /* we can figure out feed_id from article id anyway, why do we
     * pass feed_id here? let's ignore the argument :( */
    $result = db_query($link, "SELECT feed_id FROM ttrss_user_entries\n\t\t\tWHERE ref_id = '{$id}'");
    $feed_id = (int) db_fetch_result($result, 0, "feed_id");
    $rv['feed_id'] = $feed_id;
    //if (!$zoom_mode) { print "<article id='$id'><![CDATA["; };
    if ($mark_as_read) {
        $result = db_query($link, "UPDATE ttrss_user_entries\n\t\t\t\tSET unread = false,last_read = NOW()\n\t\t\t\tWHERE ref_id = '{$id}' AND owner_uid = {$owner_uid}");
        ccache_update($link, $feed_id, $owner_uid);
    }
    $result = db_query($link, "SELECT id,title,link,content,feed_id,comments,int_id,\n\t\t\t" . SUBSTRING_FOR_DATE . "(updated,1,16) as updated,\n\t\t\t(SELECT site_url FROM ttrss_feeds WHERE id = feed_id) as site_url,\n\t\t\tnum_comments,\n\t\t\ttag_cache,\n\t\t\tauthor,\n\t\t\torig_feed_id,\n\t\t\tnote,\n\t\t\tcached_content\n\t\t\tFROM ttrss_entries,ttrss_user_entries\n\t\t\tWHERE\tid = '{$id}' AND ref_id = id AND owner_uid = {$owner_uid}");
    if ($result) {
        $line = db_fetch_assoc($result);
        $tag_cache = $line["tag_cache"];
        $line["tags"] = get_article_tags($link, $id, $owner_uid, $line["tag_cache"]);
        unset($line["tag_cache"]);
        $line["content"] = sanitize($link, $line["content"], false, $owner_uid, $line["site_url"]);
        global $pluginhost;
        foreach ($pluginhost->get_hooks($pluginhost::HOOK_RENDER_ARTICLE) as $p) {
            $line = $p->hook_render_article($line);
        }
        $num_comments = $line["num_comments"];
        $entry_comments = "";
        if ($num_comments > 0) {
            if ($line["comments"]) {
                $comments_url = htmlspecialchars($line["comments"]);
            } else {
                $comments_url = htmlspecialchars($line["link"]);
            }
            $entry_comments = "<a target='_blank' href=\"{$comments_url}\">{$num_comments} comments</a>";
        } else {
            if ($line["comments"] && $line["link"] != $line["comments"]) {
                $entry_comments = "<a target='_blank' href=\"" . htmlspecialchars($line["comments"]) . "\">comments</a>";
            }
        }
        if ($zoom_mode) {
            header("Content-Type: text/html");
            $rv['content'] .= "<html><head>\n\t\t\t\t\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n\t\t\t\t\t\t<title>Tiny Tiny RSS - " . $line["title"] . "</title>\n\t\t\t\t\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss.css\">\n\t\t\t\t\t</head><body>";
        }
        $title_escaped = htmlspecialchars($line['title']);
        $rv['content'] .= "<div id=\"PTITLE-FULL-{$id}\" style=\"display : none\">" . strip_tags($line['title']) . "</div>";
        $rv['content'] .= "<div class=\"postReply\" id=\"POST-{$id}\">";
        $rv['content'] .= "<div class=\"postHeader\" id=\"POSTHDR-{$id}\">";
        $entry_author = $line["author"];
        if ($entry_author) {
            $entry_author = __(" - ") . $entry_author;
        }
        $parsed_updated = make_local_datetime($link, $line["updated"], true, $owner_uid, true);
        $rv['content'] .= "<div class=\"postDate\">{$parsed_updated}</div>";
        if ($line["link"]) {
            $rv['content'] .= "<div class='postTitle'><a target='_blank'\n\t\t\t\t\ttitle=\"" . htmlspecialchars($line['title']) . "\"\n\t\t\t\t\thref=\"" . htmlspecialchars($line["link"]) . "\">" . $line["title"] . "<span class='author'>{$entry_author}</span></a></div>";
        } else {
            $rv['content'] .= "<div class='postTitle'>" . $line["title"] . "{$entry_author}</div>";
        }
        $tags_str = format_tags_string($line["tags"], $id);
        $tags_str_full = join(", ", $line["tags"]);
        if (!$tags_str_full) {
            $tags_str_full = __("no tags");
        }
        if (!$entry_comments) {
            $entry_comments = "&nbsp;";
        }
        # placeholder
        $rv['content'] .= "<div class='postTags' style='float : right'>\n\t\t\t\t<img src='" . theme_image($link, 'images/tag.png') . "'\n\t\t\t\tclass='tagsPic' alt='Tags' title='Tags'>&nbsp;";
        if (!$zoom_mode) {
            $rv['content'] .= "<span id=\"ATSTR-{$id}\">{$tags_str}</span>\n\t\t\t\t\t<a title=\"" . __('Edit tags for this article') . "\"\n\t\t\t\t\thref=\"#\" onclick=\"editArticleTags({$id}, {$feed_id})\">(+)</a>";
            $rv['content'] .= "<div dojoType=\"dijit.Tooltip\"\n\t\t\t\t\tid=\"ATSTRTIP-{$id}\" connectId=\"ATSTR-{$id}\"\n\t\t\t\t\tposition=\"below\">{$tags_str_full}</div>";
            global $pluginhost;
            foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_BUTTON) as $p) {
                $rv['content'] .= $p->hook_article_button($line);
            }
        } else {
            $tags_str = strip_tags($tags_str);
            $rv['content'] .= "<span id=\"ATSTR-{$id}\">{$tags_str}</span>";
        }
        $rv['content'] .= "</div>";
        $rv['content'] .= "<div clear='both'>{$entry_comments}</div>";
        if ($line["orig_feed_id"]) {
            $tmp_result = db_query($link, "SELECT * FROM ttrss_archived_feeds\n\t\t\t\t\tWHERE id = " . $line["orig_feed_id"]);
            if (db_num_rows($tmp_result) != 0) {
                $rv['content'] .= "<div clear='both'>";
                $rv['content'] .= __("Originally from:");
                $rv['content'] .= "&nbsp;";
                $tmp_line = db_fetch_assoc($tmp_result);
                $rv['content'] .= "<a target='_blank'\n\t\t\t\t\t\thref=' " . htmlspecialchars($tmp_line['site_url']) . "'>" . $tmp_line['title'] . "</a>";
                $rv['content'] .= "&nbsp;";
                $rv['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
                $rv['content'] .= "<img title='" . __('Feed URL') . "'class='tinyFeedIcon' src='images/pub_set.svg'></a>";
                $rv['content'] .= "</div>";
            }
        }
        $rv['content'] .= "</div>";
        $rv['content'] .= "<div id=\"POSTNOTE-{$id}\">";
        if ($line['note']) {
            $rv['content'] .= format_article_note($id, $line['note'], !$zoom_mode);
        }
        $rv['content'] .= "</div>";
        $rv['content'] .= "<div class=\"postContent\">";
        // N-grams
        if (DB_TYPE == "pgsql" and defined('_NGRAM_TITLE_RELATED_THRESHOLD')) {
            $ngram_result = db_query($link, "SELECT id,title FROM\n\t\t\t\t\t\tttrss_entries,ttrss_user_entries\n\t\t\t\t\tWHERE ref_id = id AND updated >= NOW() - INTERVAL '7 day'\n\t\t\t\t\t\tAND similarity(title, '{$title_escaped}') >= " . _NGRAM_TITLE_RELATED_THRESHOLD . "\n\t\t\t\t\t\tAND title != '{$title_escaped}'\n\t\t\t\t\t\tAND owner_uid = {$owner_uid}");
            if (db_num_rows($ngram_result) > 0) {
                $rv['content'] .= "<div dojoType=\"dijit.form.DropDownButton\">" . "<span>" . __('Related') . "</span>";
                $rv['content'] .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
                while ($nline = db_fetch_assoc($ngram_result)) {
                    $rv['content'] .= "<div onclick=\"hlOpenInNewTab(null," . $nline['id'] . ")\"\n\t\t\t\t\t\t\tdojoType=\"dijit.MenuItem\">" . $nline['title'] . "</div>";
                }
                $rv['content'] .= "</div></div><br/";
            }
        }
        if ($cache_content && $line["cached_content"] != "") {
            $line["content"] =& $line["cached_content"];
        }
        $rv['content'] .= $line["content"];
        $rv['content'] .= format_article_enclosures($link, $id, $always_display_enclosures, $line["content"]);
        $rv['content'] .= "</div>";
        $rv['content'] .= "</div>";
    }
    if ($zoom_mode) {
        $rv['content'] .= "\n\t\t\t\t<div style=\"text-align : center\">\n\t\t\t\t<button onclick=\"return window.close()\">" . __("Close this window") . "</button></div>";
        $rv['content'] .= "</body></html>";
    }
    return $rv;
}
 function setArticleTags()
 {
     $id = db_escape_string($_REQUEST["id"]);
     $tags_str = db_escape_string($_REQUEST["tags_str"]);
     $tags = array_unique(trim_array(explode(",", $tags_str)));
     db_query($this->link, "BEGIN");
     $result = db_query($this->link, "SELECT int_id FROM ttrss_user_entries WHERE\n\t\t\t\tref_id = '{$id}' AND owner_uid = '" . $_SESSION["uid"] . "' LIMIT 1");
     if (db_num_rows($result) == 1) {
         $tags_to_cache = array();
         $int_id = db_fetch_result($result, 0, "int_id");
         db_query($this->link, "DELETE FROM ttrss_tags WHERE\n\t\t\t\tpost_int_id = {$int_id} AND owner_uid = '" . $_SESSION["uid"] . "'");
         foreach ($tags as $tag) {
             $tag = sanitize_tag($tag);
             if (!tag_is_valid($tag)) {
                 continue;
             }
             if (preg_match("/^[0-9]*\$/", $tag)) {
                 continue;
             }
             //					print "<!-- $id : $int_id : $tag -->";
             if ($tag != '') {
                 db_query($this->link, "INSERT INTO ttrss_tags\n\t\t\t\t\t\t\t\t(post_int_id, owner_uid, tag_name) VALUES ('{$int_id}', '" . $_SESSION["uid"] . "', '{$tag}')");
             }
             array_push($tags_to_cache, $tag);
         }
         /* update tag cache */
         sort($tags_to_cache);
         $tags_str = join(",", $tags_to_cache);
         db_query($this->link, "UPDATE ttrss_user_entries\n\t\t\t\tSET tag_cache = '{$tags_str}' WHERE ref_id = '{$id}'\n\t\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]);
     }
     db_query($this->link, "COMMIT");
     $tags = get_article_tags($this->link, $id);
     $tags_str = format_tags_string($tags, $id);
     $tags_str_full = join(", ", $tags);
     if (!$tags_str_full) {
         $tags_str_full = __("no tags");
     }
     print json_encode(array("tags_str" => array("id" => $id, "content" => $tags_str, "content_full" => $tags_str_full)));
 }
Exemplo n.º 5
0
 function testFilter()
 {
     $filter = array();
     $filter["enabled"] = true;
     $filter["match_any_rule"] = sql_bool_to_bool(checkbox_to_sql_bool(db_escape_string($_REQUEST["match_any_rule"])));
     $filter["rules"] = array();
     $result = db_query($this->link, "SELECT id,name FROM ttrss_filter_types");
     $filter_types = array();
     while ($line = db_fetch_assoc($result)) {
         $filter_types[$line["id"]] = $line["name"];
     }
     $rctr = 0;
     foreach ($_REQUEST["rule"] as $r) {
         $rule = json_decode($r, true);
         if ($rule && $rctr < 5) {
             $rule["type"] = $filter_types[$rule["filter_type"]];
             unset($rule["filter_type"]);
             if (strpos($rule["feed_id"], "CAT:") === 0) {
                 $rule["cat_id"] = (int) substr($rule["feed_id"], 4);
                 unset($rule["feed_id"]);
             }
             array_push($filter["rules"], $rule);
             ++$rctr;
         } else {
             break;
         }
     }
     $feed_title = getFeedTitle($this->link, $feed);
     $qfh_ret = queryFeedHeadlines($this->link, -4, 30, "", false, false, false, false, "date_entered DESC", 0, $_SESSION["uid"], $filter);
     $result = $qfh_ret[0];
     $articles = array();
     $found = 0;
     print __("Articles matching this filter:");
     print "<div class=\"filterTestHolder\">";
     print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
     while ($line = db_fetch_assoc($result)) {
         $entry_timestamp = strtotime($line["updated"]);
         $entry_tags = get_article_tags($this->link, $line["id"], $_SESSION["uid"]);
         $content_preview = truncate_string(strip_tags($line["content_preview"]), 100, '...');
         if ($line["feed_title"]) {
             $feed_title = $line["feed_title"];
         }
         print "<tr>";
         print "<td width='5%' align='center'><input\n\t\t\t\tdojoType=\"dijit.form.CheckBox\" checked=\"1\"\n\t\t\t\tdisabled=\"1\" type=\"checkbox\"></td>";
         print "<td>";
         print $line["title"];
         print "&nbsp;(";
         print "<b>" . $feed_title . "</b>";
         print "):&nbsp;";
         print "<span class=\"insensitive\">" . $content_preview . "</span>";
         print " " . mb_substr($line["date_entered"], 0, 16);
         print "</td></tr>";
         $found++;
     }
     if ($found == 0) {
         print "<tr><td align='center'>" . __("No recent articles matching this filter have been found.") . "</td></tr>";
     }
     print "</table></div>";
     print "<div style='text-align : center'>";
     print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('filterTestDlg').hide()\">" . __('Close this window') . "</button>";
     print "</div>";
 }
Exemplo n.º 6
0
function outputHeadlinesList($link, $feed, $subop, $view_mode, $limit, $cat_view, $next_unread_feed, $offset, $vgr_last_feed = false, $override_order = false)
{
    $disable_cache = false;
    $timing_info = getmicrotime();
    $topmost_article_ids = array();
    if (!$offset) {
        $offset = 0;
    }
    if ($subop == "undefined") {
        $subop = "";
    }
    $subop_split = split(":", $subop);
    if ($subop == "CatchupSelected") {
        $ids = split(",", db_escape_string($_REQUEST["ids"]));
        $cmode = sprintf("%d", $_REQUEST["cmode"]);
        catchupArticlesById($link, $ids, $cmode);
    }
    if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
        update_generic_feed($link, $feed, $cat_view, true);
    }
    if ($subop == "MarkAllRead") {
        catchup_feed($link, $feed, $cat_view);
        if (get_pref($link, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
            if ($next_unread_feed) {
                $feed = $next_unread_feed;
            }
        }
    }
    if ($subop_split[0] == "MarkAllReadGR") {
        catchup_feed($link, $subop_split[1], false);
    }
    if ($feed_id > 0) {
        $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE id = '{$feed}' LIMIT 1");
        if (db_num_rows($result) == 0) {
            print "<div align='center'>" . __('Feed not found.') . "</div>";
            return;
        }
    }
    if (preg_match("/^-?[0-9][0-9]*\$/", $feed) != false) {
        $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds\n\t\t\t\tWHERE id = '{$feed}' AND owner_uid = " . $_SESSION["uid"]);
        if (db_num_rows($result) == 1) {
            $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
        } else {
            $rtl_content = false;
        }
        if ($rtl_content) {
            $rtl_tag = "dir=\"RTL\"";
        } else {
            $rtl_tag = "";
        }
    } else {
        $rtl_tag = "";
        $rtl_content = false;
    }
    $script_dt_add = get_script_dt_add();
    /// START /////////////////////////////////////////////////////////////////////////////////
    $search = db_escape_string($_REQUEST["query"]);
    if ($search) {
        $disable_cache = true;
    }
    $search_mode = db_escape_string($_REQUEST["search_mode"]);
    $match_on = db_escape_string($_REQUEST["match_on"]);
    if (!$match_on) {
        $match_on = "both";
    }
    $real_offset = $offset * $limit;
    if ($_REQUEST["debug"]) {
        $timing_info = print_checkpoint("H0", $timing_info);
    }
    $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order, $real_offset);
    if ($_REQUEST["debug"]) {
        $timing_info = print_checkpoint("H1", $timing_info);
    }
    $result = $qfh_ret[0];
    $feed_title = $qfh_ret[1];
    $feed_site_url = $qfh_ret[2];
    $last_error = $qfh_ret[3];
    $vgroup_last_feed = $vgr_last_feed;
    if ($feed == -2) {
        $feed_site_url = article_publish_url($link);
    }
    /// STOP //////////////////////////////////////////////////////////////////////////////////
    if (!$offset) {
        print "<div id=\"headlinesContainer\" {$rtl_tag}>";
        if (!$result) {
            print "<div align='center'>" . __("Could not display feed (query failed). Please check label match syntax or local configuration.") . "</div>";
            return;
        }
        print_headline_subtoolbar($link, $feed_site_url, $feed_title, $feed, $cat_view, $search, $match_on, $search_mode);
        print "<div id=\"headlinesInnerContainer\" onscroll=\"headlines_scroll_handler()\">";
    }
    $headlines_count = db_num_rows($result);
    if (db_num_rows($result) > 0) {
        #			print "\{$offset}";
        if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) {
            print "<table class=\"headlinesList\" id=\"headlinesList\" \n\t\t\t\t\tcellspacing=\"0\">";
        }
        $lnum = $limit * $offset;
        error_reporting(DEFAULT_ERROR_LEVEL);
        $num_unread = 0;
        $cur_feed_title = '';
        $fresh_intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
        while ($line = db_fetch_assoc($result)) {
            $class = $lnum % 2 ? "even" : "odd";
            $id = $line["id"];
            $feed_id = $line["feed_id"];
            $labels = get_article_labels($link, $id);
            $labels_str = "<span id=\"HLLCTR-{$id}\">";
            $labels_str .= format_article_labels($labels, $id);
            $labels_str .= "</span>";
            if (count($topmost_article_ids) < 5) {
                array_push($topmost_article_ids, $id);
            }
            if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {
                $update_pic = "<img id='FUPDPIC-{$id}' src=\"" . theme_image($link, 'images/updated.png') . "\" \n\t\t\t\t\t\talt=\"Updated\">";
            } else {
                $update_pic = "<img id='FUPDPIC-{$id}' src=\"images/blank_icon.gif\" \n\t\t\t\t\t\talt=\"Updated\">";
            }
            if (sql_bool_to_bool($line["unread"]) && time() - strtotime($line["updated_noms"]) < $fresh_intl) {
                $update_pic = "<img id='FUPDPIC-{$id}' src=\"" . theme_image($link, 'images/fresh_sign.png') . "\" alt=\"Fresh\">";
            }
            if ($line["unread"] == "t" || $line["unread"] == "1") {
                $class .= "Unread";
                ++$num_unread;
                $is_unread = true;
            } else {
                $is_unread = false;
            }
            if ($line["marked"] == "t" || $line["marked"] == "1") {
                $marked_pic = "<img id=\"FMPIC-{$id}\" \n\t\t\t\t\t\tsrc=\"" . theme_image($link, 'images/mark_set.png') . "\" \n\t\t\t\t\t\tclass=\"markedPic\" alt=\"Unstar article\" \n\t\t\t\t\t\tonclick='javascript:tMark({$id})'>";
            } else {
                $marked_pic = "<img id=\"FMPIC-{$id}\" \n\t\t\t\t\t\tsrc=\"" . theme_image($link, 'images/mark_unset.png') . "\" \n\t\t\t\t\t\tclass=\"markedPic\" alt=\"Star article\" \n\t\t\t\t\t\tonclick='javascript:tMark({$id})'>";
            }
            if ($line["published"] == "t" || $line["published"] == "1") {
                $published_pic = "<img id=\"FPPIC-{$id}\" src=\"" . theme_image($link, 'images/pub_set.png') . "\" \n\t\t\t\t\t\tclass=\"markedPic\"\n\t\t\t\t\t\talt=\"Unpublish article\" onclick='javascript:tPub({$id})'>";
            } else {
                $published_pic = "<img id=\"FPPIC-{$id}\" src=\"" . theme_image($link, 'images/pub_unset.png') . "\" \n\t\t\t\t\t\tclass=\"markedPic\"\n\t\t\t\t\t\talt=\"Publish article\" onclick='javascript:tPub({$id})'>";
            }
            #				$content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
            #					$line["title"] . "</a>";
            #				$content_link = "<a
            #					href=\"" . htmlspecialchars($line["link"]) . "\"
            #					onclick=\"view($id,$feed_id);\">" .
            #					$line["title"] . "</a>";
            #				$content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
            #					$line["title"] . "</a>";
            if (get_pref($link, 'HEADLINES_SMART_DATE')) {
                $updated_fmt = smart_date_time(strtotime($line["updated_noms"]));
            } else {
                $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
                $updated_fmt = date($short_date, strtotime($line["updated_noms"]));
            }
            if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
                $content_preview = truncate_string(strip_tags($line["content_preview"]), 100);
            }
            $score = $line["score"];
            $score_pic = theme_image($link, "images/" . get_score_pic($score));
            /*				$score_title = __("(Click to change)");
            				$score_pic = "<img class='hlScorePic' src=\"images/$score_pic\" 
            					onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
            $score_pic = "<img class='hlScorePic' src=\"{$score_pic}\" \n\t\t\t\t\ttitle=\"{$score}\">";
            if ($score > 500) {
                $hlc_suffix = "H";
            } else {
                if ($score < -100) {
                    $hlc_suffix = "L";
                } else {
                    $hlc_suffix = "";
                }
            }
            $entry_author = $line["author"];
            if ($entry_author) {
                $entry_author = " - {$entry_author}";
            }
            $has_feed_icon = feed_has_icon($feed_id);
            if ($has_feed_icon) {
                $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/{$feed_id}.ico\" alt=\"\">";
            } else {
                //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
                $feed_icon_img = "";
            }
            if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
                if (get_pref($link, 'VFEED_GROUP_BY_FEED')) {
                    if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
                        $cur_feed_title = $line["feed_title"];
                        $vgroup_last_feed = $feed_id;
                        $cur_feed_title = htmlspecialchars($cur_feed_title);
                        $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup({$feed_id});' href='#'>" . __('mark as read') . "</a>)";
                        print "<tr class='feedTitle'><td colspan='7'>" . "<div style=\"float : right\">{$feed_icon_img}</div>" . "<a href=\"javascript:viewfeed({$feed_id}, '', false)\">" . $line["feed_title"] . "</a> {$vf_catchup_link}</td></tr>";
                    }
                }
                $mouseover_attrs = "onmouseover='postMouseIn({$id})' \n\t\t\t\t\t\tonmouseout='postMouseOut({$id})'";
                print "<tr class='{$class}' id='RROW-{$id}' {$mouseover_attrs}>";
                print "<td class='hlUpdPic'>{$update_pic}</td>";
                print "<td class='hlSelectRow'>\n\t\t\t\t\t\t<input type=\"checkbox\" onclick=\"tSR(this)\"\n\t\t\t\t\t\t\tid=\"RCHK-{$id}\">\n\t\t\t\t\t\t</td>";
                print "<td class='hlMarkedPic'>{$marked_pic}</td>";
                print "<td class='hlMarkedPic'>{$published_pic}</td>";
                #					if ($line["feed_title"]) {
                #						print "<td class='hlContent'>$content_link</td>";
                #						print "<td class='hlFeed'>
                #							<a href=\"javascript:viewfeed($feed_id, '', false)\">".
                #								truncate_string($line["feed_title"],30)."</a>&nbsp;</td>";
                #					} else {
                print "<td onclick='view({$id})' class='hlContent{$hlc_suffix}' valign='middle' id='HLC-{$id}'>";
                print "<a id=\"RTITLE-{$id}\" \n\t\t\t\t\t\thref=\"" . htmlspecialchars($line["link"]) . "\"\n\t\t\t\t\t\tonclick=\"return false\">" . $line["title"];
                if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
                    if ($content_preview) {
                        print "<span class=\"contentPreview\"> - {$content_preview}</span>";
                    }
                }
                print "</a>";
                print $labels_str;
                #							<a href=\"javascript:viewfeed($feed_id, '', false)\">".
                #							$line["feed_title"]."</a>
                if (!get_pref($link, 'VFEED_GROUP_BY_FEED')) {
                    if ($line["feed_title"]) {
                        print "<span class=\"hlFeed\">\n\t\t\t\t\t\t\t\t(<a href=\"javascript:viewfeed({$feed_id}, '', false)\">" . $line["feed_title"] . "</a>)\n\t\t\t\t\t\t\t</span>";
                    }
                }
                //					print "<img id='HLL-$id' class='hlLoading'
                //						src='images/indicator_tiny.gif' style='display : none'>";
                print "</td>";
                #					}
                print "<td class=\"hlUpdated\" onclick='view({$id})'><nobr>{$updated_fmt}&nbsp;</nobr></td>";
                print "<td class='hlMarkedPic'>{$score_pic}</td>";
                if ($line["feed_title"] && !get_pref($link, 'VFEED_GROUP_BY_FEED')) {
                    print "<td onclick=\"viewfeed({$feed_id})\" class=\"hlFeedIcon\">{$feed_icon_img}</td>";
                }
                print "</tr>";
            } else {
                if (get_pref($link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
                    if ($feed_id != $vgroup_last_feed) {
                        $cur_feed_title = $line["feed_title"];
                        $vgroup_last_feed = $feed_id;
                        $cur_feed_title = htmlspecialchars($cur_feed_title);
                        $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup({$feed_id});' href='#'>" . __('mark as read') . "</a>)";
                        $has_feed_icon = feed_has_icon($feed_id);
                        if ($has_feed_icon) {
                            $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/{$feed_id}.ico\" alt=\"\">";
                        } else {
                            //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
                        }
                        print "<div class='cdmFeedTitle'>" . "<div style=\"float : right\">{$feed_icon_img}</div>" . "<a href=\"javascript:viewfeed({$feed_id}, '', false)\">" . $line["feed_title"] . "</a> {$vf_catchup_link}</div>";
                    }
                }
                if ($is_unread) {
                    $add_class = "Unread";
                } else {
                    $add_class = "";
                }
                $expand_cdm = get_pref($link, 'CDM_EXPANDED');
                $show_excerpt = false;
                if ($expand_cdm && $score >= -100) {
                    $cdm_cstyle = "";
                    $show_excerpt = false;
                } else {
                    $cdm_cstyle = "style=\"display : none\"";
                    $show_excerpt = true;
                }
                $mouseover_attrs = "onmouseover='postMouseIn({$id})' \n\t\t\t\t\t\tonmouseout='postMouseOut({$id})'";
                print "<div class=\"cdmArticle{$add_class}\" \n\t\t\t\t\t\tid=\"RROW-{$id}\"\t\t\t\t\t\t\n\t\t\t\t\t\t{$mouseover_attrs}'>";
                print "<div class=\"cdmHeader\">";
                if (!get_pref($link, "VFEED_GROUP_BY_FEED") || !$line["feed_title"]) {
                    $cdm_feed_icon = "<span style=\"cursor : pointer\" onclick=\"viewfeed({$feed_id})\">{$feed_icon_img}</span>";
                }
                print "<div class=\"articleUpdated\">{$updated_fmt} {$score_pic} {$cdm_feed_icon}\n\t\t\t\t\t\t</div>";
                print "<span id=\"RTITLE-{$id}\" class=\"titleWrap{$hlc_suffix}\"><a class=\"title\" \n\t\t\t\t\t\tonclick=\"javascript:toggleUnread({$id}, 0)\"\n\t\t\t\t\t\ttarget=\"_blank\" href=\"" . $line["link"] . "\">" . $line["title"] . "</a>\n\t\t\t\t\t\t";
                print $entry_author;
                /*					if (!$expand_cdm || $score < -100) {
                						print "&nbsp;<a id=\"CICH-$id\" 
                							href=\"javascript:cdmExpandArticle($id)\">
                							(".__('Show article').")</a>";
                					} */
                print $labels_str;
                if (!get_pref($link, 'VFEED_GROUP_BY_FEED')) {
                    if ($line["feed_title"]) {
                        print "&nbsp;(<a href='javascript:viewfeed({$feed_id})'>" . $line["feed_title"] . "</a>)";
                    }
                }
                print "</span></div>";
                if ($show_excerpt) {
                    print "<div class=\"cdmExcerpt\" id=\"CEXC-{$id}\"\n\t\t\t\t\t\t\tonclick=\"cdmExpandArticle({$id})\"\n\t\t\t\t\t\t\ttitle=\"" . __('Click to expand article') . "\">";
                    $content_preview = trim(truncate_string(strip_tags($line["content_preview"]), 100));
                    if (strlen($content_preview) != 0) {
                        print $content_preview;
                    } else {
                        print __('Click to expand article');
                    }
                    print "</div>";
                }
                print "<div class=\"cdmContent\" \n\t\t\t\t\t\tonclick=\"cdmClicked({$id})\"\n\t\t\t\t\t\tid=\"CICD-{$id}\" {$cdm_cstyle}>";
                if ($line["orig_feed_id"]) {
                    $tmp_result = db_query($link, "SELECT * FROM ttrss_archived_feeds\n\t\t\t\t\t\tWHERE id = " . $line["orig_feed_id"]);
                    if (db_num_rows($tmp_result) != 0) {
                        print "<div clear='both'>";
                        print __("Originally from:");
                        print "&nbsp;";
                        $tmp_line = db_fetch_assoc($tmp_result);
                        print "<a target='_blank' \n\t\t\t\t\t\t\thref=' " . htmlspecialchars($tmp_line['site_url']) . "'>" . $tmp_line['title'] . "</a>";
                        print "&nbsp;";
                        print "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
                        print "<img title='" . __('Feed URL') . "'class='tinyFeedIcon' src='images/pub_set.gif'></a>";
                        print "</div>";
                    }
                }
                //					print "<div class=\"cdmInnerContent\" id=\"CICD-$id\" $cdm_cstyle>";
                print "<div id=\"POSTNOTE-{$id}\">";
                if ($line['note']) {
                    print format_article_note($id, $line['note']);
                }
                print "</div>";
                print sanitize_rss($link, $line["content_preview"]);
                $article_content = $line["content_preview"];
                $e_result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE\n\t\t\t\t\t\tpost_id = '{$id}' AND content_url != ''");
                if (db_num_rows($e_result) > 0) {
                    $entries_html = array();
                    $entries = array();
                    while ($e_line = db_fetch_assoc($e_result)) {
                        $url = $e_line["content_url"];
                        $ctype = $e_line["content_type"];
                        if (!$ctype) {
                            $ctype = __("unknown type");
                        }
                        $filename = substr($url, strrpos($url, "/") + 1);
                        $entry = format_inline_player($link, $url, $ctype);
                        $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" . $filename . " (" . $ctype . ")" . "</a>";
                        array_push($entries_html, $entry);
                        $entry = array();
                        $entry["type"] = $ctype;
                        $entry["filename"] = $filename;
                        $entry["url"] = $url;
                        array_push($entries, $entry);
                    }
                    $tmp_result = db_query($link, "SELECT always_display_enclosures FROM\n\t\t\t\t\tttrss_feeds WHERE id = " . $line['feed_id'] . " AND owner_uid = " . $_SESSION["uid"]);
                    $always_display_enclosures = db_fetch_result($tmp_result, 0, "always_display_enclosures");
                    if (!get_pref($link, "STRIP_IMAGES")) {
                        if ($always_display_enclosures || !preg_match("/img/i", $article_content)) {
                            foreach ($entries as $entry) {
                                if (preg_match("/image/", $entry["type"]) || preg_match("/\\.(jpg|png|gif|bmp)/i", $entry["filename"])) {
                                    print "<p><img \n\t\t\t\t\t\t\t\t\talt=\"" . htmlspecialchars($entry["filename"]) . "\"\n\t\t\t\t\t\t\t\t\tsrc=\"" . htmlspecialchars($entry["url"]) . "\"></p>";
                                }
                            }
                        }
                    }
                    print "<div class=\"cdmEnclosures\">";
                    if (db_num_rows($e_result) == 1) {
                        print __("Attachment:") . " ";
                    } else {
                        print __("Attachments:") . " ";
                    }
                    print join(", ", $entries_html);
                    print "</div>";
                }
                print "<br clear='both'>";
                //					print "</div>";
                /*					if (!$expand_cdm) {
                						print "<a id=\"CICH-$id\" 
                							href=\"javascript:cdmExpandArticle($id)\">
                							Show article</a>";
                					} */
                print "</div>";
                print "<div class=\"cdmFooter\"><span class='s0'>";
                /* print "<div class=\"markedPic\">Star it: $marked_pic</div>"; */
                print __("Select:") . " <input type=\"checkbox\" onclick=\"toggleSelectRowById(this, \n\t\t\t\t\t\t\t'RROW-{$id}')\" class=\"feedCheckBox\" id=\"RCHK-{$id}\">";
                print "</span><span class='s1'>{$marked_pic}&nbsp;";
                print "{$published_pic}&nbsp;";
                print "<img src=\"images/art-zoom.png\" class='tagsPic' \n\t\t\t\t\t\tonclick=\"zoomToArticle({$id})\"\n\t\t\t\t\t\tstyle=\"cursor : pointer\"\n\t\t\t\t\t\talt='Zoom' \n\t\t\t\t\t\ttitle='" . __('Show article summary in new window') . "'>&nbsp;";
                $note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
                print "<img src=\"images/art-pub-note.png\" class='tagsPic' \n\t\t\t\t\t\tstyle=\"cursor : pointer\" style=\"cursor : pointer\"\n\t\t\t\t\t\tonclick=\"publishWithNote({$id}, '{$note_escaped}')\"\n\t\t\t\t\t\talt='PubNote' title='" . __('Publish article with a note') . "'>";
                print "</span>";
                $tags_str = format_tags_string(get_article_tags($link, $id), $id);
                print "<span class='s1'>\n\t\t\t\t\t\t<img class='tagsPic' src='" . theme_image($link, 'images/tag.png') . "' alt='Tags' title='Tags'>\n\t\t\t\t\t\t<span id=\"ATSTR-{$id}\">{$tags_str}</span>\n\t\t\t\t\t\t<a title=\"" . __('Edit tags for this article') . "\" \n\t\t\t\t\t\thref=\"javascript:editArticleTags({$id}, {$feed_id}, true)\">(+)</a>";
                print "</span>";
                print "<span class='s2'><a class=\"cdmToggleLink\"\n\t\t\t\t\t\t\thref=\"javascript:toggleUnread({$id})\">\n\t\t\t\t\t\t\t" . __('toggle unread') . "</a></span>";
                print "</div>";
                print "</div>";
            }
            ++$lnum;
        }
        if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) {
            print "</table>";
        }
    } else {
        $message = "";
        switch ($view_mode) {
            case "unread":
                $message = __("No unread articles found to display.");
                break;
            case "updated":
                $message = __("No updated articles found to display.");
                break;
            case "marked":
                $message = __("No starred articles found to display.");
                break;
            default:
                if ($feed < -10) {
                    $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
                } else {
                    $message = __("No articles found to display.");
                }
        }
        if (!$offset) {
            print "<div class='whiteBox'>{$message}</div>";
        }
    }
    if (!$offset) {
        print "</div>";
        print "</div>";
    }
    return array($topmost_article_ids, $headlines_count, $feed, $disable_cache, $vgroup_last_feed);
}
 private function generate_syndicated_feed($owner_uid, $feed, $is_cat, $limit, $offset, $search, $search_mode, $view_mode = false, $format = 'atom', $order = false, $orig_guid = false)
 {
     require_once "lib/MiniTemplator.class.php";
     $note_style = "background-color : #fff7d5;\n\t\t\tborder-width : 1px; " . "padding : 5px; border-style : dashed; border-color : #e7d796;" . "margin-bottom : 1em; color : #9a8c59;";
     if (!$limit) {
         $limit = 60;
     }
     $date_sort_field = "date_entered DESC, updated DESC";
     if ($feed == -2) {
         $date_sort_field = "last_published DESC";
     } else {
         if ($feed == -1) {
             $date_sort_field = "last_marked DESC";
         }
     }
     switch ($order) {
         case "title":
             $date_sort_field = "ttrss_entries.title";
             break;
         case "date_reverse":
             $date_sort_field = "date_entered, updated";
             break;
         case "feed_dates":
             $date_sort_field = "updated DESC";
             break;
     }
     $qfh_ret = queryFeedHeadlines($feed, 1, $view_mode, $is_cat, $search, $search_mode, $date_sort_field, $offset, $owner_uid, false, 0, false, true);
     $result = $qfh_ret[0];
     if ($this->dbh->num_rows($result) != 0) {
         $ts = strtotime($this->dbh->fetch_result($result, 0, "date_entered"));
         if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $ts) {
             header('HTTP/1.0 304 Not Modified');
             return;
         }
         $last_modified = gmdate("D, d M Y H:i:s", $ts) . " GMT";
         header("Last-Modified: {$last_modified}", true);
     }
     $qfh_ret = queryFeedHeadlines($feed, $limit, $view_mode, $is_cat, $search, $search_mode, $date_sort_field, $offset, $owner_uid, false, 0, false, true);
     $result = $qfh_ret[0];
     $feed_title = htmlspecialchars($qfh_ret[1]);
     $feed_site_url = $qfh_ret[2];
     $last_error = $qfh_ret[3];
     $feed_self_url = get_self_url_prefix() . "/public.php?op=rss&id={$feed}&key=" . get_feed_access_key($feed, false, $owner_uid);
     if (!$feed_site_url) {
         $feed_site_url = get_self_url_prefix();
     }
     if ($format == 'atom') {
         $tpl = new MiniTemplator();
         $tpl->readTemplateFromFile("templates/generated_feed.txt");
         $tpl->setVariable('FEED_TITLE', $feed_title, true);
         $tpl->setVariable('VERSION', VERSION, true);
         $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
         if (PUBSUBHUBBUB_HUB && $feed == -2) {
             $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB), true);
             $tpl->addBlock('feed_hub');
         }
         $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
         $line["content_preview"] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
         while ($line = $this->dbh->fetch_assoc($result)) {
             foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
                 $line = $p->hook_query_headlines($line);
             }
             $tpl->setVariable('ARTICLE_ID', htmlspecialchars($orig_guid ? $line['link'] : get_self_url_prefix() . "/public.php?url=" . urlencode($line['link'])), true);
             $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
             $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
             $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true);
             $content = sanitize($line["content"], false, $owner_uid);
             if ($line['note']) {
                 $content = "<div style=\"{$note_style}\">Article note: " . $line['note'] . "</div>" . $content;
                 $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
             }
             $tpl->setVariable('ARTICLE_CONTENT', $content, true);
             $tpl->setVariable('ARTICLE_UPDATED_ATOM', date('c', strtotime($line["updated"])), true);
             $tpl->setVariable('ARTICLE_UPDATED_RFC822', date(DATE_RFC822, strtotime($line["updated"])), true);
             $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
             $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url']), true);
             $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title']), true);
             $tags = get_article_tags($line["id"], $owner_uid);
             foreach ($tags as $tag) {
                 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
                 $tpl->addBlock('category');
             }
             $enclosures = get_article_enclosures($line["id"]);
             foreach ($enclosures as $e) {
                 $type = htmlspecialchars($e['content_type']);
                 $url = htmlspecialchars($e['content_url']);
                 $length = $e['duration'];
                 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
                 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
                 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
                 $tpl->addBlock('enclosure');
             }
             $tpl->addBlock('entry');
         }
         $tmp = "";
         $tpl->addBlock('feed');
         $tpl->generateOutputToString($tmp);
         if (@(!$_REQUEST["noxml"])) {
             header("Content-Type: text/xml; charset=utf-8");
         } else {
             header("Content-Type: text/plain; charset=utf-8");
         }
         print $tmp;
     } else {
         if ($format == 'json') {
             $feed = array();
             $feed['title'] = $feed_title;
             $feed['version'] = VERSION;
             $feed['feed_url'] = $feed_self_url;
             if (PUBSUBHUBBUB_HUB && $feed == -2) {
                 $feed['hub_url'] = PUBSUBHUBBUB_HUB;
             }
             $feed['self_url'] = get_self_url_prefix();
             $feed['articles'] = array();
             while ($line = $this->dbh->fetch_assoc($result)) {
                 $line["content_preview"] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
                 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
                     $line = $p->hook_query_headlines($line, 100);
                 }
                 $article = array();
                 $article['id'] = $line['link'];
                 $article['link'] = $line['link'];
                 $article['title'] = $line['title'];
                 $article['excerpt'] = $line["content_preview"];
                 $article['content'] = sanitize($line["content"], false, $owner_uid);
                 $article['updated'] = date('c', strtotime($line["updated"]));
                 if ($line['note']) {
                     $article['note'] = $line['note'];
                 }
                 if ($article['author']) {
                     $article['author'] = $line['author'];
                 }
                 $tags = get_article_tags($line["id"], $owner_uid);
                 if (count($tags) > 0) {
                     $article['tags'] = array();
                     foreach ($tags as $tag) {
                         array_push($article['tags'], $tag);
                     }
                 }
                 $enclosures = get_article_enclosures($line["id"]);
                 if (count($enclosures) > 0) {
                     $article['enclosures'] = array();
                     foreach ($enclosures as $e) {
                         $type = $e['content_type'];
                         $url = $e['content_url'];
                         $length = $e['duration'];
                         array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
                     }
                 }
                 array_push($feed['articles'], $article);
             }
             header("Content-Type: text/json; charset=utf-8");
             print json_encode($feed);
         } else {
             header("Content-Type: text/plain; charset=utf-8");
             print json_encode(array("error" => array("message" => "Unknown format")));
         }
     }
 }
Exemplo n.º 8
0
 private function generate_syndicated_feed($owner_uid, $feed, $is_cat, $limit, $search, $search_mode, $match_on, $view_mode = false)
 {
     require_once "lib/MiniTemplator.class.php";
     $note_style = "background-color : #fff7d5;\n\t\t\tborder-width : 1px; " . "padding : 5px; border-style : dashed; border-color : #e7d796;" . "margin-bottom : 1em; color : #9a8c59;";
     if (!$limit) {
         $limit = 30;
     }
     if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
         $date_sort_field = "updated";
     } else {
         $date_sort_field = "date_entered";
     }
     $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $is_cat, $search, $search_mode, $match_on, "{$date_sort_field} DESC", 0, $owner_uid);
     $result = $qfh_ret[0];
     $feed_title = htmlspecialchars($qfh_ret[1]);
     $feed_site_url = $qfh_ret[2];
     $last_error = $qfh_ret[3];
     $feed_self_url = get_self_url_prefix() . "/public.php?op=rss&id=-2&key=" . get_feed_access_key($this->link, -2, false, $owner_uid);
     if (!$feed_site_url) {
         $feed_site_url = get_self_url_prefix();
     }
     $tpl = new MiniTemplator();
     $tpl->readTemplateFromFile("templates/generated_feed.txt");
     $tpl->setVariable('FEED_TITLE', $feed_title, true);
     $tpl->setVariable('VERSION', VERSION, true);
     $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
     if (PUBSUBHUBBUB_HUB && $feed == -2) {
         $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB), true);
         $tpl->addBlock('feed_hub');
     }
     $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
     while ($line = db_fetch_assoc($result)) {
         $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
         $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
         $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
         $tpl->setVariable('ARTICLE_EXCERPT', truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
         $content = sanitize($this->link, $line["content_preview"], false, $owner_uid);
         if ($line['note']) {
             $content = "<div style=\"{$note_style}\">Article note: " . $line['note'] . "</div>" . $content;
         }
         $tpl->setVariable('ARTICLE_CONTENT', $content, true);
         $tpl->setVariable('ARTICLE_UPDATED_ATOM', date('c', strtotime($line["updated"])), true);
         $tpl->setVariable('ARTICLE_UPDATED_RFC822', date(DATE_RFC822, strtotime($line["updated"])), true);
         $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
         $tags = get_article_tags($this->link, $line["id"], $owner_uid);
         foreach ($tags as $tag) {
             $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
             $tpl->addBlock('category');
         }
         $enclosures = get_article_enclosures($this->link, $line["id"]);
         foreach ($enclosures as $e) {
             $type = htmlspecialchars($e['content_type']);
             $url = htmlspecialchars($e['content_url']);
             $length = $e['duration'];
             $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
             $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
             $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
             $tpl->addBlock('enclosure');
         }
         $tpl->addBlock('entry');
     }
     $tmp = "";
     $tpl->addBlock('feed');
     $tpl->generateOutputToString($tmp);
     print $tmp;
 }
function format_article($id, $mark_as_read = true, $zoom_mode = false, $owner_uid = false)
{
    if (!$owner_uid) {
        $owner_uid = $_SESSION["uid"];
    }
    $rv = array();
    $rv['id'] = $id;
    /* we can figure out feed_id from article id anyway, why do we
     * pass feed_id here? let's ignore the argument :(*/
    $result = db_query("SELECT feed_id FROM ttrss_user_entries\n\t\t\tWHERE ref_id = '{$id}'");
    $feed_id = (int) db_fetch_result($result, 0, "feed_id");
    $rv['feed_id'] = $feed_id;
    //if (!$zoom_mode) { print "<article id='$id'><![CDATA["; };
    if ($mark_as_read) {
        $result = db_query("UPDATE ttrss_user_entries\n\t\t\t\tSET unread = false,last_read = NOW()\n\t\t\t\tWHERE ref_id = '{$id}' AND owner_uid = {$owner_uid}");
        ccache_update($feed_id, $owner_uid);
    }
    $result = db_query("SELECT id,title,link,content,feed_id,comments,int_id,\n\t\t\t" . SUBSTRING_FOR_DATE . "(updated,1,16) as updated,\n\t\t\t(SELECT site_url FROM ttrss_feeds WHERE id = feed_id) as site_url,\n\t\t\t(SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) as hide_images,\n\t\t\t(SELECT always_display_enclosures FROM ttrss_feeds WHERE id = feed_id) as always_display_enclosures,\n\t\t\tnum_comments,\n\t\t\ttag_cache,\n\t\t\tauthor,\n\t\t\torig_feed_id,\n\t\t\tnote\n\t\t\tFROM ttrss_entries,ttrss_user_entries\n\t\t\tWHERE\tid = '{$id}' AND ref_id = id AND owner_uid = {$owner_uid}");
    if ($result) {
        $line = db_fetch_assoc($result);
        $tag_cache = $line["tag_cache"];
        $line["tags"] = get_article_tags($id, $owner_uid, $line["tag_cache"]);
        unset($line["tag_cache"]);
        $line["content"] = sanitize($line["content"], sql_bool_to_bool($line['hide_images']), $owner_uid, $line["site_url"]);
        foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) {
            $line = $p->hook_render_article($line);
        }
        $num_comments = $line["num_comments"];
        $entry_comments = "";
        if ($num_comments > 0) {
            if ($line["comments"]) {
                $comments_url = htmlspecialchars($line["comments"]);
            } else {
                $comments_url = htmlspecialchars($line["link"]);
            }
            $entry_comments = "<a target='_blank' href=\"{$comments_url}\">{$num_comments} comments</a>";
        } else {
            if ($line["comments"] && $line["link"] != $line["comments"]) {
                $entry_comments = "<a target='_blank' href=\"" . htmlspecialchars($line["comments"]) . "\">comments</a>";
            }
        }
        if ($zoom_mode) {
            header("Content-Type: text/html");
            $rv['content'] .= "<html><head>\n\t\t\t\t\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n\t\t\t\t\t\t<title>Tiny Tiny RSS - " . $line["title"] . "</title>\n\t\t\t\t\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/tt-rss.css\">\n\t\t\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\tfunction openSelectedAttachment(elem) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tvar url = elem[elem.selectedIndex].value;\n\n\t\t\t\t\t\t\t\tif (url) {\n\t\t\t\t\t\t\t\t\twindow.open(url);\n\t\t\t\t\t\t\t\t\telem.selectedIndex = 0;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\texception_error(\"openSelectedAttachment\", e);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t</script>\n\t\t\t\t\t</head><body id=\"ttrssZoom\">";
        }
        $rv['content'] .= "<div class=\"postReply\" id=\"POST-{$id}\">";
        $rv['content'] .= "<div class=\"postHeader\" id=\"POSTHDR-{$id}\">";
        $entry_author = $line["author"];
        if ($entry_author) {
            $entry_author = __(" - ") . $entry_author;
        }
        $parsed_updated = make_local_datetime($line["updated"], true, $owner_uid, true);
        $rv['content'] .= "<div class=\"postDate\">{$parsed_updated}</div>";
        if ($line["link"]) {
            $rv['content'] .= "<div class='postTitle'><a target='_blank'\n\t\t\t\t\ttitle=\"" . htmlspecialchars($line['title']) . "\"\n\t\t\t\t\thref=\"" . htmlspecialchars($line["link"]) . "\">" . $line["title"] . "</a>" . "<span class='author'>{$entry_author}</span></div>";
        } else {
            $rv['content'] .= "<div class='postTitle'>" . $line["title"] . "{$entry_author}</div>";
        }
        $tags_str = format_tags_string($line["tags"], $id);
        $tags_str_full = join(", ", $line["tags"]);
        if (!$tags_str_full) {
            $tags_str_full = __("no tags");
        }
        if (!$entry_comments) {
            $entry_comments = "&nbsp;";
        }
        # placeholder
        $rv['content'] .= "<div class='postTags' style='float : right'>\n\t\t\t\t<img src='images/tag.png'\n\t\t\t\tclass='tagsPic' alt='Tags' title='Tags'>&nbsp;";
        if (!$zoom_mode) {
            $rv['content'] .= "<span id=\"ATSTR-{$id}\">{$tags_str}</span>\n\t\t\t\t\t<a title=\"" . __('Edit tags for this article') . "\"\n\t\t\t\t\thref=\"#\" onclick=\"editArticleTags({$id}, {$feed_id})\">(+)</a>";
            $rv['content'] .= "<div dojoType=\"dijit.Tooltip\"\n\t\t\t\t\tid=\"ATSTRTIP-{$id}\" connectId=\"ATSTR-{$id}\"\n\t\t\t\t\tposition=\"below\">{$tags_str_full}</div>";
            foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_BUTTON) as $p) {
                $rv['content'] .= $p->hook_article_button($line);
            }
        } else {
            $tags_str = strip_tags($tags_str);
            $rv['content'] .= "<span id=\"ATSTR-{$id}\">{$tags_str}</span>";
        }
        $rv['content'] .= "</div>";
        $rv['content'] .= "<div clear='both'>";
        foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) {
            $rv['content'] .= $p->hook_article_left_button($line);
        }
        $rv['content'] .= "{$entry_comments}</div>";
        if ($line["orig_feed_id"]) {
            $tmp_result = db_query("SELECT * FROM ttrss_archived_feeds\n\t\t\t\t\tWHERE id = " . $line["orig_feed_id"]);
            if (db_num_rows($tmp_result) != 0) {
                $rv['content'] .= "<div clear='both'>";
                $rv['content'] .= __("Originally from:");
                $rv['content'] .= "&nbsp;";
                $tmp_line = db_fetch_assoc($tmp_result);
                $rv['content'] .= "<a target='_blank'\n\t\t\t\t\t\thref=' " . htmlspecialchars($tmp_line['site_url']) . "'>" . $tmp_line['title'] . "</a>";
                $rv['content'] .= "&nbsp;";
                $rv['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
                $rv['content'] .= "<img title='" . __('Feed URL') . "'class='tinyFeedIcon' src='images/pub_set.svg'></a>";
                $rv['content'] .= "</div>";
            }
        }
        $rv['content'] .= "</div>";
        $rv['content'] .= "<div id=\"POSTNOTE-{$id}\">";
        if ($line['note']) {
            $rv['content'] .= format_article_note($id, $line['note'], !$zoom_mode);
        }
        $rv['content'] .= "</div>";
        $rv['content'] .= "<div class=\"postContent\">";
        $rv['content'] .= $line["content"];
        $rv['content'] .= format_article_enclosures($id, sql_bool_to_bool($line["always_display_enclosures"]), $line["content"], sql_bool_to_bool($line["hide_images"]));
        $rv['content'] .= "</div>";
        $rv['content'] .= "</div>";
    }
    if ($zoom_mode) {
        $rv['content'] .= "\n\t\t\t\t<div class='footer'>\n\t\t\t\t<button onclick=\"return window.close()\">" . __("Close this window") . "</button></div>";
        $rv['content'] .= "</body></html>";
    }
    return $rv;
}
Exemplo n.º 10
0
function module_popup_dialog($link)
{
    $id = $_REQUEST["id"];
    $param = db_escape_string($_REQUEST["param"]);
    if ($id == "importOpml") {
        print "<div id=\"infoBoxTitle\">" . __('OPML Import') . "</div>";
        print "<div class=\"infoBoxContents\">";
        print "<div class=\"prefFeedCatHolder\">";
        $owner_uid = $_SESSION["uid"];
        db_query($link, "BEGIN");
        /* create Imported feeds category just in case */
        $result = db_query($link, "SELECT id FROM\n\t\t\t\tttrss_feed_categories WHERE title = 'Imported feeds' AND\n\t\t\t\towner_uid = '{$owner_uid}' LIMIT 1");
        if (db_num_rows($result) == 0) {
            db_query($link, "INSERT INTO ttrss_feed_categories\n\t\t\t\t\t(title,owner_uid) \n\t\t\t\t\t\tVALUES ('Imported feeds', '{$owner_uid}')");
        }
        db_query($link, "COMMIT");
        /* Handle OPML import by DOMXML/DOMDocument */
        if (function_exists('domxml_open_file')) {
            print "<ul class='nomarks'>";
            print "<li>" . __("Importing using DOMXML.") . "</li>";
            require_once "modules/opml_domxml.php";
            opml_import_domxml($link, $owner_uid);
            print "</ul>";
        } else {
            if (PHP_VERSION >= 5) {
                print "<ul class='nomarks'>";
                print "<li>" . __("Importing using DOMDocument.") . "</li>";
                require_once "modules/opml_domdoc.php";
                opml_import_domdoc($link, $owner_uid);
                print "</ul>";
            } else {
                print_error(__("DOMXML extension is not found. It is required for PHP versions below 5."));
            }
        }
        print "</div>";
        print "<div align='center'>";
        print "<button onclick=\"return opmlImportDone()\">" . __('Close this window') . "</button>";
        print "</div>";
        print "<script type=\"text/javascript\">";
        print "parent.opmlImportHandler(this)";
        print "</script>";
        print "</div></div>";
        return;
    }
    if ($id == "editPrefProfiles") {
        print "<div id=\"infoBoxTitle\">" . __('Settings Profiles') . "</div>";
        print "<div class=\"infoBoxContents\">";
        print "<div><input id=\"fadd_profile\" \n\t\t\t\t\tonkeypress=\"return filterCR(event, addPrefProfile)\"\n\t\t\t\t\tsize=\"40\">\n\t\t\t\t\t<button onclick=\"javascript:addPrefProfile()\">" . __('Create profile') . "</button></div>";
        print "<p>";
        $result = db_query($link, "SELECT title,id FROM ttrss_settings_profiles\n\t\t\t\tWHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title");
        print __('Select:') . " \n\t\t\t\t<a href=\"javascript:selectPrefRows('fcat', true)\">" . __('All') . "</a>,\n\t\t\t\t<a href=\"javascript:selectPrefRows('fcat', false)\">" . __('None') . "</a>";
        print "<div class=\"prefFeedCatHolder\">";
        print "<form id=\"profile_edit_form\" onsubmit=\"return false\">";
        print "<table width=\"100%\" class=\"prefFeedCatList\" \n\t\t\t\tcellspacing=\"0\" id=\"prefFeedCatList\">";
        print "<tr class=\"odd\" id=\"FCATR-0\">";
        print "<td width='5%' align='center'><input \n\t\t\t\tonclick='toggleSelectPrefRow(this, \"fcat\");' \n\t\t\t\ttype=\"checkbox\" id=\"FCCHK-0\"></td>";
        if (!$_SESSION["profile"]) {
            $is_active = __("(active)");
        } else {
            $is_active = "";
        }
        print "<td><span id=\"FCATT-0\">" . __("Default profile") . " {$is_active}</span></td>";
        print "</tr>";
        $lnum = 1;
        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\tonclick='toggleSelectPrefRow(this, \"fcat\");' \n\t\t\t\t\ttype=\"checkbox\" id=\"FCCHK-{$cat_id}\"></td>";
            if ($_SESSION["profile"] == $line["id"]) {
                $is_active = __("(active)");
            } else {
                $is_active = "";
            }
            print "<td><span id=\"FCATT-{$cat_id}\">" . $edit_title . "</span> {$is_active}</td>";
            print "</tr>";
            ++$lnum;
        }
        print "</table>";
        print "</form>";
        print "</div>";
        print "<div class='dlgButtons'>\n\t\t\t\t<div style='float : left'>\n\t\t\t\t<button onclick=\"return removeSelectedPrefProfiles()\">" . __('Remove') . "</button>\n\t\t\t\t<button onclick=\"return activatePrefProfile()\">" . __('Activate') . "</button>\n\t\t\t\t</div>";
        print "<button onclick=\"return closeInfoBox()\">" . __('Close this window') . "</button>";
        print "</div></div>";
        return;
    }
    if ($id == "pubUrl") {
        print "<div id=\"infoBoxTitle\">" . __('Published Articles') . "</div>";
        print "<div class=\"infoBoxContents\">";
        $url_path = article_publish_url($link);
        print __("Your Published articles feed URL is:");
        print "<div class=\"tagCloudContainer\">";
        print "<a id='pub_feed_url' href='{$url_path}' target='_blank'>{$url_path}</a>";
        print "</div>";
        print "<div align='center'>";
        print "<button onclick=\"return pubRegenKey()\">" . __('Generate new URL') . "</button> ";
        print "<input class=\"button\"\n\t\t\t\ttype=\"submit\" onclick=\"return closeInfoBox()\" \n\t\t\t\tvalue=\"" . __('Close this window') . "\">";
        print "</div></div>";
        return;
    }
    if ($id == "pubOPMLUrl") {
        print "<div id=\"infoBoxTitle\">" . __('Public OPML URL') . "</div>";
        print "<div class=\"infoBoxContents\">";
        $url_path = opml_publish_url($link);
        print __("Your Public OPML URL is:");
        print "<div class=\"tagCloudContainer\">";
        print "<a id='pub_opml_url' href='{$url_path}' target='_blank'>{$url_path}</a>";
        print "</div>";
        print "<div align='center'>";
        print "<button onclick=\"return opmlRegenKey()\">" . __('Generate new URL') . "</button> ";
        print "<input class=\"button\"\n\t\t\t\ttype=\"submit\" onclick=\"return closeInfoBox()\" \n\t\t\t\tvalue=\"" . __('Close this window') . "\">";
        print "</div></div>";
        return;
    }
    if ($id == "explainError") {
        print "<div id=\"infoBoxTitle\">" . __('Notice') . "</div>";
        print "<div class=\"infoBoxContents\">";
        print "<div class=\"errorExplained\">";
        if ($param == 1) {
            print __("Update daemon is enabled in configuration, but daemon process is not running, which prevents all feeds from updating. Please start the daemon process or contact instance owner.");
            $stamp = (int) read_stampfile("update_daemon.stamp");
            print "<p>" . __("Last update:") . " " . date("Y.m.d, G:i", $stamp);
        }
        if ($param == 2) {
            $msg = check_for_update($link);
            if (!$msg) {
                print __("You are running the latest version of Tiny Tiny RSS. The fact that you are seeing this dialog is probably a bug.");
            } else {
                print $msg;
            }
        }
        if ($param == 3) {
            print __("Update daemon is taking too long to perform a feed update. This could indicate a problem like crash or a hang. Please check the daemon process or contact instance owner.");
            $stamp = (int) read_stampfile("update_daemon.stamp");
            print "<p>" . __("Last update:") . " " . date("Y.m.d, G:i", $stamp);
        }
        print "</div>";
        print "<div align='center'>";
        print "<input class=\"button\"\n\t\t\t\ttype=\"submit\" onclick=\"return closeInfoBox()\" \n\t\t\t\tvalue=\"" . __('Close this window') . "\">";
        print "</div></div>";
        return;
    }
    if ($id == "quickAddFeed") {
        print "<div id=\"infoBoxTitle\">" . __('Subscribe to Feed') . "</div>";
        print "<div class=\"infoBoxContents\">";
        print "<form id='feed_add_form' onsubmit='return false'>";
        print "<input type=\"hidden\" name=\"op\" value=\"rpc\">";
        print "<input type=\"hidden\" name=\"subop\" value=\"addfeed\">";
        //print "<input type=\"hidden\" name=\"from\" value=\"tt-rss\">";
        print "<div class=\"dlgSec\">" . __("Feed") . "</div>";
        print "<div class=\"dlgSecCont\">";
        print __("URL:") . " ";
        print "<input size=\"40\"\n\t\t\t\t\tonkeypress=\"return filterCR(event, subscribeToFeed)\"\n\t\t\t\t\tname=\"feed\" id=\"feed_url\"></td></tr>";
        print "<br/>";
        if (get_pref($link, 'ENABLE_FEED_CATS')) {
            print __('Place in category:') . " ";
            print_feed_cat_select($link, "cat");
        }
        print "</div>";
        print "<div id='fadd_login_container' style='display:none'>\n\t\n\t\t\t\t\t<div class=\"dlgSec\">" . __("Authentication") . "</div>\n\t\t\t\t\t<div class=\"dlgSecCont\">" . __('Login:'******'login' size=\"20\" \n\t\t\t\t\t\t\tonkeypress=\"return filterCR(event, subscribeToFeed)\"> " . __('Password:'******'password'\n\t\t\t\t\t\t\tname='pass' size=\"20\" \n\t\t\t\t\t\t\tonkeypress=\"return filterCR(event, subscribeToFeed)\">\n\t\t\t\t</div></div>";
        print "<div style=\"clear : both\">\t\t\t\t\n\t\t\t\t<input type=\"checkbox\" id=\"fadd_login_check\" \n\t\t\t\t\t\tonclick='checkboxToggleElement(this, \"fadd_login_container\")'>\n\t\t\t\t\t<label for=\"fadd_login_check\">" . __('This feed requires authentication.') . "</div>";
        print "</form>";
        print "<div class=\"dlgButtons\">\n\t\t\t\t<button class=\"button\" id=\"fadd_submit_btn\"\n\t\t\t\t\tonclick=\"return subscribeToFeed()\">" . __('Subscribe') . "</button>\n\t\t\t\t<button onclick=\"return displayDlg('feedBrowser')\">" . __('More feeds') . "</button>\n\t\t\t\t<button onclick=\"return closeInfoBox()\">" . __('Cancel') . "</button></div>";
        return;
    }
    if ($id == "feedBrowser") {
        print "<div id=\"infoBoxTitle\">" . __('Feed Browser') . "</div>";
        print "<div class=\"infoBoxContents\">";
        $browser_search = db_escape_string($_REQUEST["search"]);
        print "<form onsubmit='return false;' display='inline' \n\t\t\t\tname='feed_browser' id='feed_browser'>";
        print "<input type=\"hidden\" name=\"op\" value=\"rpc\">";
        print "<input type=\"hidden\" name=\"subop\" value=\"updateFeedBrowser\">";
        print "\n\t\t\t\t<div style='float : right'>\n\t\t\t\t<img style='display : none' \n\t\t\t\t\tid='feed_browser_spinner' src='" . theme_image($link, 'images/indicator_white.gif') . "'>\n\t\t\t\t<input name=\"search\" size=\"20\" type=\"search\"\n\t\t\t\t\tonchange=\"javascript:updateFeedBrowser()\" value=\"{$browser_search}\">\n\t\t\t\t<button onclick=\"javascript:updateFeedBrowser()\">" . __('Search') . "</button>\n\t\t\t</div>";
        print " <select name=\"mode\" onchange=\"updateFeedBrowser()\">\n\t\t\t\t<option value='1'>" . __('Popular feeds') . "</option>\n\t\t\t\t<option value='2'>" . __('Feed archive') . "</option>\n\t\t\t\t</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	__('Select:')." 
        				<a href=\"javascript:selectPrefRows('fbrowse', true)\">".__('All')."</a>,
        					<a href=\"javascript:selectPrefRows('fbrowse', false)\">".__('None')."</a>"; */
        print "<ul class='browseFeedList' id='browseFeedList'>";
        print_feed_browser($link, $search, 25);
        print "</ul>";
        print "<div align='center'>\n\t\t\t\t<button onclick=\"feedBrowserSubscribe()\">" . __('Subscribe') . "</button>\n\t\t\t\t<button style='display : none' id='feed_archive_remove' onclick=\"feedArchiveRemove()\">" . __('Remove') . "</button>\n\t\t\t\t<button onclick=\"closeInfoBox()\" >" . __('Cancel') . "</button></div>";
        print "</div>";
        return;
    }
    if ($id == "search") {
        print "<div id=\"infoBoxTitle\">" . __('Search') . "</div>";
        print "<div class=\"infoBoxContents\">";
        print "<form id='search_form'  onsubmit='return false'>";
        #$active_feed_id = db_escape_string($_REQUEST["param"]);
        $params = split(":", db_escape_string($_REQUEST["param"]));
        $active_feed_id = sprintf("%d", $params[0]);
        $is_cat = $params[1] == "true";
        print "<div class=\"dlgSec\">" . __('Look for') . "</div>";
        print "<div class=\"dlgSecCont\">";
        print "<input onkeypress=\"return filterCR(event, search)\"\n\t\t\t\tname=\"query\" size=\"20\" type=\"search\"\tvalue=''>";
        print " " . __('match on') . " ";
        $search_fields = array("title" => __("Title"), "content" => __("Content"), "both" => __("Title or content"));
        print_select_hash("match_on", 3, $search_fields);
        print "<br/>" . __('Limit search to:') . " ";
        print "<select name=\"search_mode\">\n\t\t\t\t<option value=\"all_feeds\">" . __('All feeds') . "</option>";
        $feed_title = getFeedTitle($link, $active_feed_id);
        if (!$is_cat) {
            $feed_cat_title = getFeedCatTitle($link, $active_feed_id);
        } else {
            $feed_cat_title = getCategoryTitle($link, $active_feed_id);
        }
        if ($active_feed_id && !$is_cat) {
            print "<option selected value=\"this_feed\">{$feed_title}</option>";
        } else {
            print "<option disabled>" . __('This feed') . "</option>";
        }
        if ($is_cat) {
            $cat_preselected = "selected";
        }
        if (get_pref($link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 || $is_cat)) {
            print "<option {$cat_preselected} value=\"this_cat\">{$feed_cat_title}</option>";
        } else {
            //print "<option disabled>".__('This category')."</option>";
        }
        print "</select>";
        print "</div>";
        print "</form>";
        print "<div class=\"dlgButtons\">\n\t\t\t<button onclick=\"javascript:search()\">" . __('Search') . "</button>\n\t\t\t<button onclick=\"javascript:closeInfoBox(true)\">" . __('Cancel') . "</button>\n\t\t\t</div>";
        print "</div>";
        return;
    }
    if ($id == "quickAddFilter") {
        $active_feed_id = db_escape_string($_REQUEST["param"]);
        print "<div id=\"infoBoxTitle\">" . __('Create Filter') . "</div>";
        print "<div class=\"infoBoxContents\">";
        print "<form id=\"filter_add_form\" onsubmit='return false'>";
        print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
        print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
        print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
        $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\">";
        print "<span id=\"filter_dlg_date_mod_box\" style=\"display : none\">";
        print __("Date") . " ";
        $filter_params = array("before" => __("before"), "after" => __("after"));
        print_select_hash("filter_date_modifier", "before", $filter_params);
        print "&nbsp;</span>";
        print "<input onkeypress=\"return filterCR(event, createFilter)\"\n\t\t\t\t name=\"reg_exp\" size=\"30\" value=\"{$reg_exp}\">";
        print "<span id=\"filter_dlg_date_chk_box\" style=\"display : none\">";
        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", 1, $filter_types, 'onchange="filterDlgCheckType(this)"');
        print "<br/>";
        print __("in") . " ";
        print_feed_select($link, "feed_id", $active_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)) {
            printf("<option value='%d'>%s</option>", $line["id"], __($line["description"]));
        }
        print "</select>";
        print "<span id=\"filter_dlg_param_box\" style=\"display : none\">";
        print " " . __("with parameters:") . " ";
        print "<input size=\"20\"\n\t\t\t\t\tonkeypress=\"return filterCR(event, createFilter)\"\n\t\t\t\t\tname=\"action_param\">";
        print_label_select($link, "action_param_label", $action_param);
        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%\">";
        print "<input type=\"checkbox\" name=\"enabled\" id=\"enabled\" checked=\"1\">\n\t\t\t\t\t<label for=\"enabled\">" . __('Enabled') . "</label><br/>";
        print "<input type=\"checkbox\" name=\"inverse\" id=\"inverse\">\n\t\t\t\t<label for=\"inverse\">" . __('Inverse match') . "</label>";
        print "</div>";
        print "</div>";
        print "</form>";
        print "<div class=\"dlgButtons\">";
        print "<button onclick=\"return createFilter()\">" . __('Create') . "</button> ";
        print "<button onclick=\"return closeInfoBox()\">" . __('Cancel') . "</button>";
        print "</div>";
        //			print "</td></tr></table>";
        return;
    }
    if ($id == "feedUpdateErrors") {
        print "<div id=\"infoBoxTitle\">" . __('Update Errors') . "</div>";
        print "<div class=\"infoBoxContents\">";
        print __("These feeds have not been updated because of errors:");
        $result = db_query($link, "SELECT id,title,feed_url,last_error\n\t\t\tFROM ttrss_feeds WHERE last_error != '' AND owner_uid = " . $_SESSION["uid"]);
        print "<ul class='feedErrorsList'>";
        while ($line = db_fetch_assoc($result)) {
            print "<li><b>" . $line["title"] . "</b> (" . $line["feed_url"] . "): " . "<em>" . $line["last_error"] . "</em>";
        }
        print "</ul>";
        print "<div align='center'>";
        print "<button onclick=\"return closeInfoBox()\">" . __('Close this window') . "</button>";
        print "</div>";
        return;
    }
    if ($id == "editArticleTags") {
        print "<div id=\"infoBoxTitle\">" . __('Edit Tags') . "</div>";
        print "<div class=\"infoBoxContents\">";
        print "<form id=\"tag_edit_form\" onsubmit='return false'>";
        print __("Tags for this article (separated by commas):") . "<br>";
        $tags = get_article_tags($link, $param);
        $tags_str = join(", ", $tags);
        print "<table width='100%'>";
        print "<tr><td colspan='2'><input type=\"hidden\" name=\"id\" value=\"{$param}\"></td></tr>";
        print "<tr><td colspan='2'><textarea rows='4' class='iedit' id='tags_str' \n\t\t\t\tname='tags_str'>{$tags_str}</textarea>\n\t\t\t<div class=\"autocomplete\" id=\"tags_choices\" \n\t\t\t\t\tstyle=\"display:none\"></div>\t\n\t\t\t</td></tr>";
        print "</table>";
        print "</form>";
        print "<div align='right'>";
        print "<button onclick=\"return editTagsSave()\">" . __('Save') . "</button> ";
        print "<button onclick=\"return closeInfoBox()\">" . __('Cancel') . "</button>";
        print "</div>";
        return;
    }
    if ($id == "printTagCloud") {
        print "<div id=\"infoBoxTitle\">" . __('Tag Cloud') . "</div>";
        print "<div class=\"infoBoxContents\">";
        print __("Showing most popular tags ") . " (<a \n\t\t\thref='javascript:toggleTags(true)'>" . __('more tags') . "</a>):<br/>";
        print "<div class=\"tagCloudContainer\">";
        printTagCloud($link);
        print "</div>";
        print "<div align='center'>";
        print "<button onclick=\"return closeInfoBox()\">" . __('Close this window') . "</button>";
        print "</div>";
        print "</div>";
        return;
    }
    /*		if ($id == "offlineDownload") {
    			print "<div id=\"infoBoxTitle\">".__('Download articles')."</div>";
    			print "<div class=\"infoBoxContents\">";
    
    			print "<form name='download_ops_form' id='download_ops_form'>";
    
    			print "<div class=\"dlgSec\">".__("Download")."</div>";
    
    			print "<div class=\"dlgSecCont\">";
    
    			$amount = array(
    				50  => 50,
    				100 => 100,
    				250 => 250,
    				500 => 500);
    
    			print_select_hash("amount", 50, $amount);
    
    			print " " . __("latest articles for offline reading.");
    
    			print "<br/>";
    
    			print "<input checked='yes' type='checkbox' name='unread_only' id='unread_only'>";
    			print "<label for='unread_only'>".__('Only include unread articles')."</label>";
    
    			print "</div>";
    
    			print "</form>";
    
    			print "<div class=\"dlgButtons\">
    				<input class=\"button\"
    					type=\"submit\" onclick=\"return initiate_offline_download(0, this)\" value=\"".__('Download')."\">
    				<input class=\"button\"
    					type=\"submit\" onclick=\"return closeInfoBox()\" 
    					value=\"".__('Cancel')."\"></div>";
    
    			print "</div>";
    
    			return;
    		} */
    print "<div id='infoBoxTitle'>Internal Error</div>\n\t\t\t<div id='infoBoxContents'>\n\t\t\t<p>Unknown dialog <b>{$id}</b></p>\n\t\t\t</div></div>";
}
Exemplo n.º 11
0
function module_popup_dialog($link)
{
    $id = $_REQUEST["id"];
    $param = db_escape_string($_REQUEST["param"]);
    print "<dlg id=\"{$id}\">";
    if ($id == "importOpml") {
        print "<div class=\"prefFeedOPMLHolder\">";
        header("Content-Type: text/html");
        # required for iframe
        $owner_uid = $_SESSION["uid"];
        db_query($link, "BEGIN");
        /* create Imported feeds category just in case */
        $result = db_query($link, "SELECT id FROM\n\t\t\t\tttrss_feed_categories WHERE title = 'Imported feeds' AND\n\t\t\t\towner_uid = '{$owner_uid}' LIMIT 1");
        if (db_num_rows($result) == 0) {
            db_query($link, "INSERT INTO ttrss_feed_categories\n\t\t\t\t\t(title,owner_uid)\n\t\t\t\t\t\tVALUES ('Imported feeds', '{$owner_uid}')");
        }
        db_query($link, "COMMIT");
        /* Handle OPML import by DOMXML/DOMDocument */
        if (function_exists('domxml_open_file')) {
            print "<ul class='nomarks'>";
            print "<li>" . __("Importing using DOMXML.") . "</li>";
            require_once "opml_domxml.php";
            opml_import_domxml($link, $owner_uid);
            print "</ul>";
        } else {
            if (PHP_VERSION >= 5) {
                print "<ul class='nomarks'>";
                print "<li>" . __("Importing using DOMDocument.") . "</li>";
                require_once "opml_domdoc.php";
                opml_import_domdoc($link, $owner_uid);
                print "</ul>";
            } else {
                print_error(__("DOMXML extension is not found. It is required for PHP versions below 5."));
            }
        }
        print "</div>";
        print "<div align='center'>";
        print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"dijit.byId('opmlImportDlg').hide()\">" . __('Close this window') . "</button>";
        print "</div>";
        print "</div>";
        //return;
    }
    if ($id == "editPrefProfiles") {
        print "<div dojoType=\"dijit.Toolbar\">";
        #			TODO: depends on selectTableRows() being broken for this list
        #			print "<div dojoType=\"dijit.form.DropDownButton\">".
        #				"<span>" . __('Select')."</span>";
        #			print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
        #			print "<div onclick=\"selectTableRows('prefFeedProfileList', 'all')\"
        #				dojoType=\"dijit.MenuItem\">".__('All')."</div>";
        #			print "<div onclick=\"selectTableRows('prefFeedProfileList', 'none')\"
        #				dojoType=\"dijit.MenuItem\">".__('None')."</div>";
        #			print "</div></div>";
        #			print "<div style='float : right'>";
        print "<input name=\"newprofile\" dojoType=\"dijit.form.ValidationTextBox\"\n\t\t\t\t\trequired=\"1\">\n\t\t\t\t<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"dijit.byId('profileEditDlg').addProfile()\">" . __('Create profile') . "</button></div>";
        #			print "</div>";
        $result = db_query($link, "SELECT title,id FROM ttrss_settings_profiles\n\t\t\t\tWHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title");
        print "<div class=\"prefFeedCatHolder\">";
        print "<form id=\"profile_edit_form\" onsubmit=\"return false\">";
        print "<table width=\"100%\" class=\"prefFeedProfileList\"\n\t\t\t\tcellspacing=\"0\" id=\"prefFeedProfileList\">";
        print "<tr class=\"\" id=\"FCATR-0\">";
        #odd
        print "<td width='5%' align='center'><input\n\t\t\t\tonclick='toggleSelectRow2(this);'\n\t\t\t\tdojoType=\"dijit.form.CheckBox\"\n\t\t\t\ttype=\"checkbox\"></td>";
        if (!$_SESSION["profile"]) {
            $is_active = __("(active)");
        } else {
            $is_active = "";
        }
        print "<td><span>" . __("Default profile") . " {$is_active}</span></td>";
        print "</tr>";
        $lnum = 1;
        while ($line = db_fetch_assoc($result)) {
            $class = $lnum % 2 ? "even" : "odd";
            $profile_id = $line["id"];
            $this_row_id = "id=\"FCATR-{$profile_id}\"";
            print "<tr class=\"\" {$this_row_id}>";
            $edit_title = htmlspecialchars($line["title"]);
            print "<td width='5%' align='center'><input\n\t\t\t\t\tonclick='toggleSelectRow2(this);'\n\t\t\t\t\tdojoType=\"dijit.form.CheckBox\"\n\t\t\t\t\ttype=\"checkbox\"></td>";
            if ($_SESSION["profile"] == $line["id"]) {
                $is_active = __("(active)");
            } else {
                $is_active = "";
            }
            print "<td><span dojoType=\"dijit.InlineEditBox\"\n\t\t\t\t\twidth=\"300px\" autoSave=\"false\"\n\t\t\t\t\tprofile-id=\"{$profile_id}\">" . $edit_title . "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">\n\t\t\t\t\t\tvar elem = this;\n\t\t\t\t\t\tdojo.xhrPost({\n\t\t\t\t\t\t\turl: 'backend.php',\n\t\t\t\t\t\t\tcontent: {op: 'rpc', subop: 'saveprofile',\n\t\t\t\t\t\t\t\tvalue: this.value,\n\t\t\t\t\t\t\t\tid: this.srcNodeRef.getAttribute('profile-id')},\n\t\t\t\t\t\t\t\tload: function(response) {\n\t\t\t\t\t\t\t\t\telem.attr('value', response);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t</script>\n\t\t\t\t</span> {$is_active}</td>";
            print "</tr>";
            ++$lnum;
        }
        print "</table>";
        print "</form>";
        print "</div>";
        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('profileEditDlg').removeSelected()\">" . __('Remove selected profiles') . "</button>\n\t\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').activateProfile()\">" . __('Activate profile') . "</button>\n\t\t\t\t</div>";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').hide()\">" . __('Close this window') . "</button>";
        print "</div>";
    }
    if ($id == "pubOPMLUrl") {
        print "<title>" . __('Public OPML URL') . "</title>";
        print "<content><![CDATA[";
        $url_path = opml_publish_url($link);
        print __("Your Public OPML URL is:");
        print "<div class=\"tagCloudContainer\">";
        print "<a id='pub_opml_url' href='{$url_path}' target='_blank'>{$url_path}</a>";
        print "</div>";
        print "<div align='center'>";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"return opmlRegenKey()\">" . __('Generate new URL') . "</button> ";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"return closeInfoBox()\">" . __('Close this window') . "</button>";
        print "</div>";
        print "]]></content>";
        //return;
    }
    if ($id == "explainError") {
        print "<title>" . __('Notice') . "</title>";
        print "<content><![CDATA[";
        print "<div class=\"errorExplained\">";
        if ($param == 1) {
            print __("Update daemon is enabled in configuration, but daemon process is not running, which prevents all feeds from updating. Please start the daemon process or contact instance owner.");
            $stamp = (int) file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp");
            print "<p>" . __("Last update:") . " " . date("Y.m.d, G:i", $stamp);
        }
        if ($param == 3) {
            print __("Update daemon is taking too long to perform a feed update. This could indicate a problem like crash or a hang. Please check the daemon process or contact instance owner.");
            $stamp = (int) file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp");
            print "<p>" . __("Last update:") . " " . date("Y.m.d, G:i", $stamp);
        }
        print "</div>";
        print "<div align='center'>";
        print "<button onclick=\"return closeInfoBox()\">" . __('Close this window') . "</button>";
        print "</div>";
        print "]]></content>";
        //return;
    }
    if ($id == "quickAddFeed") {
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"addfeed\">";
        print "<div class=\"dlgSec\">" . __("Feed") . "</div>";
        print "<div class=\"dlgSecCont\">";
        print "<input style=\"font-size : 16px; width : 20em;\"\n\t\t\t\tplaceHolder=\"" . __("Feed URL") . "\"\n\t\t\t\tdojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"feed\" id=\"feedDlg_feedUrl\">";
        print "<hr/>";
        if (get_pref($link, 'ENABLE_FEED_CATS')) {
            print __('Place in category:') . " ";
            print_feed_cat_select($link, "cat", false, 'dojoType="dijit.form.Select"');
        }
        print "</div>";
        print '<div id="feedDlg_feedsContainer" style="display : none">

					<div class="dlgSec">' . __('Available feeds') . '</div>
					<div class="dlgSecCont">' . '<select id="feedDlg_feedContainerSelect"
						dojoType="dijit.form.Select" size="3">
						<script type="dojo/method" event="onChange" args="value">
							dijit.byId("feedDlg_feedUrl").attr("value", value);
						</script>
					</select>' . '</div></div>';
        print "<div id='feedDlg_loginContainer' style='display : none'>\n\n\t\t\t\t\t<div class=\"dlgSec\">" . __("Authentication") . "</div>\n\t\t\t\t\t<div class=\"dlgSecCont\">" . " <input dojoType=\"dijit.form.TextBox\" name='login'\"\n\t\t\t\t\t\tplaceHolder=\"" . __("Login") . "\"\n\t\t\t\t\t\tstyle=\"width : 10em;\"> " . " <input\n\t\t\t\t\t\tplaceHolder=\"" . __("Password") . "\"\n\t\t\t\t\t\tdojoType=\"dijit.form.TextBox\" type='password'\n\t\t\t\t\t\tstyle=\"width : 10em;\" name='pass'\">\n\t\t\t\t</div></div>";
        print "<div style=\"clear : both\">\n\t\t\t\t<input type=\"checkbox\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"\n\t\t\t\t\t\tonclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>\n\t\t\t\t\t<label for=\"feedDlg_loginCheck\">" . __('This feed requires authentication.') . "</div>";
        print "</form>";
        print "<div class=\"dlgButtons\">\n\t\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').execute()\">" . __('Subscribe') . "</button>\n\t\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"return feedBrowser()\">" . __('More feeds') . "</button>\n\t\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').hide()\">" . __('Cancel') . "</button>\n\t\t\t\t</div>";
        //return;
    }
    if ($id == "feedBrowser") {
        $browser_search = db_escape_string($_REQUEST["search"]);
        #			print "<form onsubmit='return false;' display='inline'
        #				name='feed_browser' id='feed_browser'>";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"updateFeedBrowser\">";
        print "<div dojoType=\"dijit.Toolbar\">\n\t\t\t\t<div style='float : right'>\n\t\t\t\t<img style='display : none'\n\t\t\t\t\tid='feed_browser_spinner' src='" . theme_image($link, 'images/indicator_white.gif') . "'>\n\t\t\t\t<input name=\"search\" dojoType=\"dijit.form.TextBox\" size=\"20\" type=\"search\"\n\t\t\t\t\tonchange=\"dijit.byId('feedBrowserDlg').update()\" value=\"{$browser_search}\">\n\t\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').update()\">" . __('Search') . "</button>\n\t\t\t</div>";
        print " <select name=\"mode\" dojoType=\"dijit.form.Select\" onchange=\"dijit.byId('feedBrowserDlg').update()\">\n\t\t\t\t<option value='1'>" . __('Popular feeds') . "</option>\n\t\t\t\t<option value='2'>" . __('Feed archive') . "</option>\n\t\t\t\t</select> ";
        print __("limit:");
        print " <select dojoType=\"dijit.form.Select\" name=\"limit\" onchange=\"dijit.byId('feedBrowserDlg').update()\">";
        foreach (array(25, 50, 100, 200) as $l) {
            $issel = $l == $limit ? "selected=\"1\"" : "";
            print "<option {$issel} value=\"{$l}\">{$l}</option>";
        }
        print "</select> ";
        print "</div>";
        $owner_uid = $_SESSION["uid"];
        print "<ul class='browseFeedList' id='browseFeedList'>";
        print make_feed_browser($link, $search, 25);
        print "</ul>";
        print "<div align='center'>\n\t\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').execute()\">" . __('Subscribe') . "</button>\n\t\t\t\t<button dojoType=\"dijit.form.Button\" style='display : none' id='feed_archive_remove' onclick=\"dijit.byId('feedBrowserDlg').removeFromArchive()\">" . __('Remove') . "</button>\n\t\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').hide()\" >" . __('Cancel') . "</button></div>";
    }
    if ($id == "search") {
        $params = explode(":", db_escape_string($_REQUEST["param"]), 2);
        $active_feed_id = sprintf("%d", $params[0]);
        $is_cat = $params[1] != "false";
        print "<div class=\"dlgSec\">" . __('Look for') . "</div>";
        print "<div class=\"dlgSecCont\">";
        if (!SPHINX_ENABLED) {
            print "<input dojoType=\"dijit.form.ValidationTextBox\"\n\t\t\t\t\tstyle=\"font-size : 16px; width : 12em;\"\n\t\t\t\t\trequired=\"1\" name=\"query\" type=\"search\" value=''>";
            print " " . __('match on') . " ";
            $search_fields = array("title" => __("Title"), "content" => __("Content"), "both" => __("Title or content"));
            print_select_hash("match_on", 3, $search_fields, 'dojoType="dijit.form.Select"');
        } else {
            print "<input dojoType=\"dijit.form.ValidationTextBox\"\n\t\t\t\t\tstyle=\"font-size : 16px; width : 20em;\"\n\t\t\t\t\trequired=\"1\" name=\"query\" type=\"search\" value=''>";
        }
        print "<hr/>" . __('Limit search to:') . " ";
        print "<select name=\"search_mode\" dojoType=\"dijit.form.Select\">\n\t\t\t\t<option value=\"all_feeds\">" . __('All feeds') . "</option>";
        $feed_title = getFeedTitle($link, $active_feed_id);
        if (!$is_cat) {
            $feed_cat_title = getFeedCatTitle($link, $active_feed_id);
        } else {
            $feed_cat_title = getCategoryTitle($link, $active_feed_id);
        }
        if ($active_feed_id && !$is_cat) {
            print "<option selected=\"1\" value=\"this_feed\">{$feed_title}</option>";
        } else {
            print "<option disabled=\"1\" value=\"false\">" . __('This feed') . "</option>";
        }
        if ($is_cat) {
            $cat_preselected = "selected=\"1\"";
        }
        if (get_pref($link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 || $is_cat)) {
            print "<option {$cat_preselected} value=\"this_cat\">{$feed_cat_title}</option>";
        } else {
            //print "<option disabled>".__('This category')."</option>";
        }
        print "</select>";
        print "</div>";
        print "<div class=\"dlgButtons\">";
        if (!SPHINX_ENABLED) {
            print "<div style=\"float : left\">\n\t\t\t\t\t<a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/redmine/wiki/tt-rss/SearchSyntax\">Search syntax</a>\n\t\t\t\t\t</div>";
        }
        print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').execute()\">" . __('Search') . "</button>\n\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').hide()\">" . __('Cancel') . "</button>\n\t\t\t</div>";
    }
    if ($id == "quickAddFilter") {
        $active_feed_id = db_escape_string($_REQUEST["param"]);
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"quiet\" value=\"1\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"add\">";
        $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\">";
        print "<span id=\"filterDlg_dateModBox\" style=\"display : none\">";
        $filter_params = array("before" => __("before"), "after" => __("after"));
        print_select_hash("filter_date_modifier", "before", $filter_params, 'dojoType="dijit.form.Select"');
        print "&nbsp;</span>";
        print "<input dojoType=\"dijit.form.ValidationTextBox\"\n\t\t\t\t required=\"true\" id=\"filterDlg_regExp\"\n\t\t\t\t style=\"font-size : 16px\"\n\t\t\t\t name=\"reg_exp\" value=\"{$reg_exp}\"/>";
        print "<span id=\"filterDlg_dateChkBox\" style=\"display : none\">";
        print "&nbsp;<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"return filterDlgCheckDate()\">" . __('Check it') . "</button>";
        print "</span>";
        print "<hr/>" . __("on field") . " ";
        print_select_hash("filter_type", 1, $filter_types, 'onchange="filterDlgCheckType(this)" dojoType="dijit.form.Select"');
        print "<hr/>";
        print __("in") . " ";
        print_feed_select($link, "feed_id", $active_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)) {
            printf("<option value='%d'>%s</option>", $line["id"], __($line["description"]));
        }
        print "</select>";
        print "<span id=\"filterDlg_paramBox\" style=\"display : none\">";
        print " " . __("with parameters:") . " ";
        print "<input dojoType=\"dijit.form.TextBox\"\n\t\t\t\tid=\"filterDlg_actionParam\"\n\t\t\t\tname=\"action_param\">";
        print_label_select($link, "action_param_label", $action_param, '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 "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" checked=\"1\">\n\t\t\t\t\t<label for=\"enabled\">" . __('Enabled') . "</label><hr/>";
        print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\">\n\t\t\t\t<label for=\"inverse\">" . __('Inverse match') . "</label>";
        print "</div>";
        print "<div class=\"dlgButtons\">";
        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()\">" . __('Create') . "</button> ";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">" . __('Cancel') . "</button>";
        print "</div>";
        //return;
    }
    if ($id == "inactiveFeeds") {
        if (DB_TYPE == "pgsql") {
            $interval_qpart = "NOW() - INTERVAL '3 months'";
        } else {
            $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
        }
        $result = db_query($link, "SELECT ttrss_feeds.title, ttrss_feeds.site_url,\n\t\t\t  \t\tttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article\n\t\t\t\tFROM ttrss_feeds, ttrss_entries, ttrss_user_entries 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}\n\t\t\t\tAND ttrss_feeds.owner_uid = " . $_SESSION["uid"] . " AND\n\t\t\t\t\tttrss_user_entries.feed_id = ttrss_feeds.id AND\n\t\t\t\t\tttrss_entries.id = ref_id\n\t\t\t\tGROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url\n\t\t\t\tORDER BY last_article");
        print __("These feeds have not been updated with new content for 3 months (oldest first):");
        print "<div class=\"inactiveFeedHolder\">";
        print "<table width=\"100%\" cellspacing=\"0\" id=\"prefInactiveFeedList\">";
        $lnum = 1;
        while ($line = db_fetch_assoc($result)) {
            $class = $lnum % 2 ? "even" : "odd";
            $feed_id = $line["id"];
            $this_row_id = "id=\"FUPDD-{$feed_id}\"";
            print "<tr class=\"\" {$this_row_id}>";
            $edit_title = htmlspecialchars($line["title"]);
            print "<td width='5%' align='center'><input\n\t\t\t\t\tonclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"\n\t\t\t\t\ttype=\"checkbox\"></td>";
            print "<td>";
            print "<a class=\"visibleLink\" href=\"#\" " . "title=\"" . __("Click to edit feed") . "\" " . "onclick=\"editFeed(" . $line["id"] . ")\">" . htmlspecialchars($line["title"]) . "</a>";
            print "</td><td class=\"insensitive\" align='right'>";
            print make_local_datetime($link, $line['last_article'], false);
            print "</td>";
            print "</tr>";
            ++$lnum;
        }
        print "</table>";
        print "</div>";
        print "<div class='dlgButtons'>";
        print "<div style='float : left'>";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').removeSelected()\">" . __('Unsubscribe from selected feeds') . "</button> ";
        print "</div>";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').hide()\">" . __('Close this window') . "</button>";
        print "</div>";
    }
    if ($id == "feedsWithErrors") {
        #			print "<title>".__('Feeds with update errors')."</title>";
        #			print "<content><![CDATA[";
        print __("These feeds have not been updated because of errors:");
        $result = db_query($link, "SELECT id,title,feed_url,last_error,site_url\n\t\t\tFROM ttrss_feeds WHERE last_error != '' AND owner_uid = " . $_SESSION["uid"]);
        print "<div class=\"inactiveFeedHolder\">";
        print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
        $lnum = 1;
        while ($line = db_fetch_assoc($result)) {
            $class = $lnum % 2 ? "even" : "odd";
            $feed_id = $line["id"];
            $this_row_id = "id=\"FUPDD-{$feed_id}\"";
            print "<tr class=\"\" {$this_row_id}>";
            $edit_title = htmlspecialchars($line["title"]);
            print "<td width='5%' align='center'><input\n\t\t\t\t\tonclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"\n\t\t\t\t\ttype=\"checkbox\"></td>";
            print "<td>";
            print "<a class=\"visibleLink\" href=\"#\" " . "title=\"" . __("Click to edit feed") . "\" " . "onclick=\"editFeed(" . $line["id"] . ")\">" . htmlspecialchars($line["title"]) . "</a>: ";
            print "<span class=\"insensitive\">";
            print htmlspecialchars($line["last_error"]);
            print "</span>";
            print "</td>";
            print "</tr>";
            ++$lnum;
        }
        print "</table>";
        print "</div>";
        print "<div class='dlgButtons'>";
        print "<div style='float : left'>";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">" . __('Unsubscribe from selected feeds') . "</button> ";
        print "</div>";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">" . __('Close this window') . "</button>";
        print "</div>";
    }
    if ($id == "editArticleTags") {
        #			print "<form id=\"tag_edit_form\" onsubmit='return false'>";
        print __("Tags for this article (separated by commas):") . "<br>";
        $tags = get_article_tags($link, $param);
        $tags_str = join(", ", $tags);
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"{$param}\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"setArticleTags\">";
        print "<table width='100%'><tr><td>";
        print "<textarea dojoType=\"dijit.form.SimpleTextarea\" rows='4'\n\t\t\t\tstyle='font-size : 12px; width : 100%' id=\"tags_str\"\n\t\t\t\tname='tags_str'>{$tags_str}</textarea>\n\t\t\t<div class=\"autocomplete\" id=\"tags_choices\"\n\t\t\t\t\tstyle=\"display:none\"></div>";
        print "</td></tr></table>";
        #			print "</form>";
        print "<div class='dlgButtons'>";
        print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"dijit.byId('editTagsDlg').execute()\">" . __('Save') . "</button> ";
        print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"dijit.byId('editTagsDlg').hide()\">" . __('Cancel') . "</button>";
        print "</div>";
    }
    if ($id == "printTagCloud") {
        print "<title>" . __('Tag Cloud') . "</title>";
        print "<content><![CDATA[";
        #			print __("Showing most popular tags ")." (<a
        #			href='javascript:toggleTags(true)'>".__('more tags')."</a>):<br/>";
        print "<div class=\"tagCloudContainer\">";
        printTagCloud($link);
        print "</div>";
        print "<div align='center'>";
        print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"return closeInfoBox()\">" . __('Close this window') . "</button>";
        print "</div>";
        print "]]></content>";
    }
    if ($id == 'printTagSelect') {
        print "<title>" . __('Select item(s) by tags') . "</title>";
        print "<content><![CDATA[";
        print __("Match:") . "&nbsp;" . "<input class=\"noborder\" dojoType=\"dijit.form.RadioButton\" type=\"radio\" checked value=\"any\" name=\"tag_mode\">&nbsp;Any&nbsp;";
        print "<input class=\"noborder\" dojoType=\"dijit.form.RadioButton\" type=\"radio\" value=\"all\" name=\"tag_mode\">&nbsp;All&nbsp;";
        print "&nbsp;tags.";
        print "<select id=\"all_tags\" name=\"all_tags\" title=\"" . __('Which Tags?') . "\" multiple=\"multiple\" size=\"10\" style=\"width : 100%\">";
        $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags WHERE owner_uid = " . $_SESSION['uid'] . "\n\t\t\t\tAND LENGTH(tag_name) <= 30 ORDER BY tag_name ASC");
        while ($row = db_fetch_assoc($result)) {
            $tmp = htmlspecialchars($row["tag_name"]);
            print "<option value=\"" . str_replace(" ", "%20", $tmp) . "\">{$tmp}</option>";
        }
        print "</select>";
        print "<div align='right'>";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"viewfeed(get_all_tags(\$('all_tags')),\n\t\t\t\tget_radio_checked(\$('tag_mode')));\">" . __('Display entries') . "</button>";
        print "&nbsp;";
        print "<button dojoType=\"dijit.form.Button\"\n\t\t\tonclick=\"return closeInfoBox()\">" . __('Close this window') . "</button>";
        print "</div>";
        print "]]></content>";
    }
    if ($id == "emailArticle") {
        $secretkey = sha1(uniqid(rand(), true));
        $_SESSION['email_secretkey'] = $secretkey;
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"secretkey\" value=\"{$secretkey}\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"sendEmail\">";
        $result = db_query($link, "SELECT email, full_name FROM ttrss_users WHERE\n\t\t\t\tid = " . $_SESSION["uid"]);
        $user_email = htmlspecialchars(db_fetch_result($result, 0, "email"));
        $user_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
        if (!$user_name) {
            $user_name = $_SESSION['name'];
        }
        $_SESSION['email_replyto'] = $user_email;
        $_SESSION['email_fromname'] = $user_name;
        require_once "lib/MiniTemplator.class.php";
        $tpl = new MiniTemplator();
        $tpl_t = new MiniTemplator();
        $tpl->readTemplateFromFile("templates/email_article_template.txt");
        $tpl->setVariable('USER_NAME', $_SESSION["name"]);
        $tpl->setVariable('USER_EMAIL', $user_email);
        $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"]);
        //			$tpl->addBlock('header');
        $result = db_query($link, "SELECT link, content, title\n\t\t\t\tFROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND\n\t\t\t\tid IN ({$param}) AND owner_uid = " . $_SESSION["uid"]);
        if (db_num_rows($result) > 1) {
            $subject = __("[Forwarded]") . " " . __("Multiple articles");
        }
        while ($line = db_fetch_assoc($result)) {
            if (!$subject) {
                $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
            }
            $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
            $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
            $tpl->addBlock('article');
        }
        $tpl->addBlock('email');
        $content = "";
        $tpl->generateOutputToString($content);
        print "<table width='100%'><tr><td>";
        print __('From:');
        print "</td><td>";
        print "<input dojoType=\"dijit.form.TextBox\" disabled=\"1\" style=\"width : 30em;\"\n\t\t\t\t\tvalue=\"{$user_name} <{$user_email}>\">";
        print "</td></tr><tr><td>";
        print __('To:');
        print "</td><td>";
        print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"\n\t\t\t\t\tstyle=\"width : 30em;\"\n\t\t\t\t\tname=\"destination\" id=\"emailArticleDlg_destination\">";
        print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\"\n\t\t\t\t\tstyle=\"z-index: 30; display : none\"></div>";
        print "</td></tr><tr><td>";
        print __('Subject:');
        print "</td><td>";
        print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"\n\t\t\t\t\tstyle=\"width : 30em;\"\n\t\t\t\t\tname=\"subject\" value=\"{$subject}\" id=\"subject\">";
        print "</td></tr>";
        print "<tr><td colspan='2'><textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 100%' rows=\"20\"\n\t\t\t\tname='content'>{$content}</textarea>";
        print "</td></tr></table>";
        print "<div class='dlgButtons'>";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').execute()\">" . __('Send e-mail') . "</button> ";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').hide()\">" . __('Cancel') . "</button>";
        print "</div>";
        //return;
    }
    if ($id == "generatedFeed") {
        print "<title>" . __('View as RSS') . "</title>";
        print "<content><![CDATA[";
        $params = explode(":", $param, 3);
        $feed_id = db_escape_string($params[0]);
        $is_cat = (bool) $params[1];
        $key = get_feed_access_key($link, $feed_id, $is_cat);
        $url_path = htmlspecialchars($params[2]) . "&key=" . $key;
        print __("You can view this feed as RSS using the following URL:");
        print "<div class=\"tagCloudContainer\">";
        print "<a id='gen_feed_url' href='{$url_path}' target='_blank'>{$url_path}</a>";
        print "</div>";
        print "<div align='center'>";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"return genUrlChangeKey('{$feed_id}', '{$is_cat}')\">" . __('Generate new URL') . "</button> ";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"return closeInfoBox()\">" . __('Close this window') . "</button>";
        print "</div>";
        print "]]></content>";
        //return;
    }
    if ($id == "newVersion") {
        $version_data = check_for_update($link);
        $version = $version_data['version'];
        $id = $version_data['version_id'];
        print "<div class='tagCloudContainer'>";
        print T_sprintf("New version of Tiny Tiny RSS is available (%s).", "<b>{$version}</b>");
        print "</div>";
        $details = "http://tt-rss.org/redmine/versions/show/{$id}";
        $download = "http://tt-rss.org/#Download";
        print "<div style='text-align : center'>";
        print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"return window.open('{$details}')\">" . __("Details") . "</button>";
        print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"return window.open('{$download}')\">" . __("Download") . "</button>";
        print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"return dijit.byId('newVersionDlg').hide()\">" . __('Close this window') . "</button>";
        print "</div>";
    }
    if ($id == "customizeCSS") {
        $value = get_pref($link, "USER_STYLESHEET");
        $value = str_replace("<br/>", "\n", $value);
        print T_sprintf("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here. <a target=\"_blank\" class=\"visibleLink\" href=\"%s\">This file</a> can be used as a baseline.", "tt-rss.css");
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"setpref\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"key\" value=\"USER_STYLESHEET\">";
        print "<table width='100%'><tr><td>";
        print "<textarea dojoType=\"dijit.form.SimpleTextarea\"\n\t\t\t\tstyle='font-size : 12px; width : 100%; height: 200px;'\n\t\t\t\tplaceHolder='body#ttrssMain { font-size : 14px; };'\n\t\t\t\tname='value'>{$value}</textarea>";
        print "</td></tr></table>";
        print "<div class='dlgButtons'>";
        print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"dijit.byId('cssEditDlg').execute()\">" . __('Save') . "</button> ";
        print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"dijit.byId('cssEditDlg').hide()\">" . __('Cancel') . "</button>";
        print "</div>";
    }
    if ($id == "editArticleNote") {
        $result = db_query($link, "SELECT note FROM ttrss_user_entries WHERE\n\t\t\t\tref_id = '{$param}' AND owner_uid = " . $_SESSION['uid']);
        $note = db_fetch_result($result, 0, "note");
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"{$param}\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"setNote\">";
        print "<table width='100%'><tr><td>";
        print "<textarea dojoType=\"dijit.form.SimpleTextarea\"\n\t\t\t\tstyle='font-size : 12px; width : 100%; height: 100px;'\n\t\t\t\tplaceHolder='body#ttrssMain { font-size : 14px; };'\n\t\t\t\tname='note'>{$note}</textarea>";
        print "</td></tr></table>";
        print "<div class='dlgButtons'>";
        print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"dijit.byId('editNoteDlg').execute()\">" . __('Save') . "</button> ";
        print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"dijit.byId('editNoteDlg').hide()\">" . __('Cancel') . "</button>";
        print "</div>";
    }
    if ($id == "about") {
        print "<table width='100%'><tr><td align='center'>";
        print "<img src=\"images/logo_big.png\">";
        print "</td>";
        print "<td width='70%'>";
        print "<h1>Tiny Riny RSS</h1>\n\t\t\t\t<strong>Version " . VERSION . "</strong>\n\t\t\t\t<p>Copyright &copy; 2005-" . date('Y') . "\n\t\t\t\t<a target=\"_blank\" class=\"visibleLink\"\n\t\t\t\thref=\"http://fakecake.org/\">Andrew Dolgov</a>\n\t\t\t\tand other contributors.</p>\n\t\t\t\t<p class=\"insensitive\">Licensed under GNU GPL version 2.</p>";
        print "<p class=\"insensitive\">\n\t\t\t\t<a class=\"visibleLink\" target=\"_blank\"\n\t\t\t\t\thref=\"http://tt-rss.org/\">Official site</a> &mdash;\n\t\t\t\t<a href=\"http://tt-rss.org/redmine/wiki/tt-rss/Donate\"\n\t\t\t\ttarget=\"_blank\" class=\"visibleLink\">\n\t\t\t\tSupport the project.</a></p>";
        print "</td></tr>";
        print "</table>";
        print "<div align='center'>";
        print "<button dojoType=\"dijit.form.Button\"\n\t\t\t\ttype=\"submit\">" . __('Close this window') . "</button>";
        print "</div>";
    }
    if ($id == "addInstance") {
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\"  name=\"op\" value=\"pref-instances\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\"  name=\"subop\" value=\"add\">";
        print "<div class=\"dlgSec\">" . __("Instance") . "</div>";
        print "<div class=\"dlgSecCont\">";
        /* URL */
        print __("URL:") . " ";
        print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"\n\t\t\t\tplaceHolder=\"" . __("Instance URL") . "\"\n\t\t\t\tregExp='^(http|https)://.*'\n\t\t\t\tstyle=\"font-size : 16px; width: 20em\" name=\"access_url\">";
        print "<hr/>";
        $access_key = sha1(uniqid(rand(), true));
        /* Access key */
        print __("Access key:") . " ";
        print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"\n\t\t\t\tplaceHolder=\"" . __("Access key") . "\" regExp='\\w{40}'\n\t\t\t\tstyle=\"width: 20em\" name=\"access_key\" id=\"instance_add_key\"\n\t\t\t\tvalue=\"{$access_key}\">";
        print "<p class='insensitive'>" . __("Use one access key for both linked instances.");
        print "</div>";
        print "<div class=\"dlgButtons\">\n\t\t\t\t<div style='float : left'>\n\t\t\t\t\t<button dojoType=\"dijit.form.Button\"\n\t\t\t\t\t\tonclick=\"return dijit.byId('instanceAddDlg').regenKey()\">" . __('Generate new key') . "</button>\n\t\t\t\t</div>\n\t\t\t\t<button dojoType=\"dijit.form.Button\"\n\t\t\t\t\tonclick=\"return dijit.byId('instanceAddDlg').execute()\">" . __('Create link') . "</button>\n\t\t\t\t<button dojoType=\"dijit.form.Button\"\n\t\t\t\t\tonclick=\"return dijit.byId('instanceAddDlg').hide()\"\">" . __('Cancel') . "</button></div>";
        return;
    }
    if ($id == "shareArticle") {
        $result = db_query($link, "SELECT uuid, ref_id FROM ttrss_user_entries WHERE int_id = '{$param}'\n\t\t\t\tAND owner_uid = " . $_SESSION['uid']);
        if (db_num_rows($result) == 0) {
            print "Article not found.";
        } else {
            $uuid = db_fetch_result($result, 0, "uuid");
            $ref_id = db_fetch_result($result, 0, "ref_id");
            if (!$uuid) {
                $uuid = db_escape_string(sha1(uniqid(rand(), true)));
                db_query($link, "UPDATE ttrss_user_entries SET uuid = '{$uuid}' WHERE int_id = '{$param}'\n\t\t\t\t\t\tAND owner_uid = " . $_SESSION['uid']);
            }
            print __("You can share this article by the following unique URL:");
            $url_path = get_self_url_prefix();
            $url_path .= "/public.php?op=share&key={$uuid}";
            print "<div class=\"tagCloudContainer\">";
            print "<a id='pub_opml_url' href='{$url_path}' target='_blank'>{$url_path}</a>";
            print "</div>";
            /* if (!label_find_id($link, __('Shared'), $_SESSION["uid"]))
            					label_create($link, __('Shared'), $_SESSION["uid"]);
            
            				label_add_article($link, $ref_id, __('Shared'), $_SESSION['uid']); */
        }
        print "<div align='center'>";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').hide()\">" . __('Close this window') . "</button>";
        print "</div>";
        return;
    }
    print "</dlg>";
}
Exemplo n.º 12
0
function update_rss_feed($feed, $ignore_daemon = false, $no_cache = false, $rss = false)
{
    $debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug'];
    _debug_suppress(!$debug_enabled);
    _debug("start", $debug_enabled);
    $result = db_query("SELECT title FROM ttrss_feeds\n\t\t\tWHERE id = '{$feed}'");
    $title = db_fetch_result($result, 0, "title");
    // feed was batch-subscribed or something, we need to get basic info
    // this is not optimal currently as it fetches stuff separately TODO: optimize
    if ($title == "[Unknown]") {
        _debug("setting basic feed info for {$feed}...");
        set_basic_feed_info($feed);
    }
    $result = db_query("SELECT id,update_interval,auth_login,\n\t\t\tfeed_url,auth_pass,cache_images,\n\t\t\tmark_unread_on_update, owner_uid,\n\t\t\tpubsub_state, auth_pass_encrypted,\n\t\t\tfeed_language,\n\t\t\t(SELECT max(date_entered) FROM\n\t\t\t\tttrss_entries, ttrss_user_entries where ref_id = id AND feed_id = '{$feed}') AS last_article_timestamp\n\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'");
    if (db_num_rows($result) == 0) {
        _debug("feed {$feed} NOT FOUND/SKIPPED", $debug_enabled);
        return false;
    }
    $last_article_timestamp = @strtotime(db_fetch_result($result, 0, "last_article_timestamp"));
    if (defined('_DISABLE_HTTP_304')) {
        $last_article_timestamp = 0;
    }
    $owner_uid = db_fetch_result($result, 0, "owner_uid");
    $mark_unread_on_update = sql_bool_to_bool(db_fetch_result($result, 0, "mark_unread_on_update"));
    $pubsub_state = db_fetch_result($result, 0, "pubsub_state");
    $auth_pass_encrypted = sql_bool_to_bool(db_fetch_result($result, 0, "auth_pass_encrypted"));
    db_query("UPDATE ttrss_feeds SET last_update_started = NOW()\n\t\t\tWHERE id = '{$feed}'");
    $auth_login = db_fetch_result($result, 0, "auth_login");
    $auth_pass = db_fetch_result($result, 0, "auth_pass");
    if ($auth_pass_encrypted) {
        require_once "crypt.php";
        $auth_pass = decrypt_string($auth_pass);
    }
    $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
    $fetch_url = db_fetch_result($result, 0, "feed_url");
    $feed_language = db_escape_string(mb_strtolower(db_fetch_result($result, 0, "feed_language")));
    if (!$feed_language) {
        $feed_language = 'english';
    }
    $feed = db_escape_string($feed);
    $date_feed_processed = date('Y-m-d H:i');
    $cache_filename = CACHE_DIR . "/simplepie/" . sha1($fetch_url) . ".xml";
    $pluginhost = new PluginHost();
    $pluginhost->set_debug($debug_enabled);
    $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
    $pluginhost->load(PLUGINS, PluginHost::KIND_ALL);
    $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
    $pluginhost->load_data();
    if ($rss && is_object($rss) && get_class($rss) == "FeedParser") {
        _debug("using previously initialized parser object");
    } else {
        $rss_hash = false;
        $force_refetch = isset($_REQUEST["force_refetch"]);
        foreach ($pluginhost->get_hooks(PluginHost::HOOK_FETCH_FEED) as $plugin) {
            $feed_data = $plugin->hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, $last_article_timestamp, $auth_login, $auth_pass);
        }
        // try cache
        if (!$feed_data && file_exists($cache_filename) && is_readable($cache_filename) && !$auth_login && !$auth_pass && filemtime($cache_filename) > time() - 30) {
            _debug("using local cache [{$cache_filename}].", $debug_enabled);
            @($feed_data = file_get_contents($cache_filename));
            if ($feed_data) {
                $rss_hash = sha1($feed_data);
            }
        } else {
            _debug("local cache will not be used for this feed", $debug_enabled);
        }
        // fetch feed from source
        if (!$feed_data) {
            _debug("fetching [{$fetch_url}]...", $debug_enabled);
            _debug("If-Modified-Since: " . gmdate('D, d M Y H:i:s \\G\\M\\T', $last_article_timestamp), $debug_enabled);
            $feed_data = fetch_file_contents($fetch_url, false, $auth_login, $auth_pass, false, $no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT, $force_refetch ? 0 : $last_article_timestamp);
            global $fetch_curl_used;
            if (!$fetch_curl_used) {
                $tmp = @gzdecode($feed_data);
                if ($tmp) {
                    $feed_data = $tmp;
                }
            }
            $feed_data = trim($feed_data);
            _debug("fetch done.", $debug_enabled);
            // cache vanilla feed data for re-use
            if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/simplepie")) {
                $new_rss_hash = sha1($feed_data);
                if ($new_rss_hash != $rss_hash) {
                    _debug("saving {$cache_filename}", $debug_enabled);
                    @file_put_contents($cache_filename, $feed_data);
                }
            }
        }
        if (!$feed_data) {
            global $fetch_last_error;
            global $fetch_last_error_code;
            _debug("unable to fetch: {$fetch_last_error} [{$fetch_last_error_code}]", $debug_enabled);
            $error_escaped = '';
            // If-Modified-Since
            if ($fetch_last_error_code != 304) {
                $error_escaped = db_escape_string($fetch_last_error);
            } else {
                _debug("source claims data not modified, nothing to do.", $debug_enabled);
            }
            db_query("UPDATE ttrss_feeds SET last_error = '{$error_escaped}',\n\t\t\t\t\t\tlast_updated = NOW() WHERE id = '{$feed}'");
            return;
        }
    }
    foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_FETCHED) as $plugin) {
        $feed_data = $plugin->hook_feed_fetched($feed_data, $fetch_url, $owner_uid, $feed);
    }
    // set last update to now so if anything *simplepie* crashes later we won't be
    // continuously failing on the same feed
    //db_query("UPDATE ttrss_feeds SET last_updated = NOW() WHERE id = '$feed'");
    if (!$rss) {
        $rss = new FeedParser($feed_data);
        $rss->init();
    }
    //		print_r($rss);
    $feed = db_escape_string($feed);
    if (!$rss->error()) {
        // We use local pluginhost here because we need to load different per-user feed plugins
        $pluginhost->run_hooks(PluginHost::HOOK_FEED_PARSED, "hook_feed_parsed", $rss);
        _debug("language: {$feed_language}", $debug_enabled);
        _debug("processing feed data...", $debug_enabled);
        //			db_query("BEGIN");
        if (DB_TYPE == "pgsql") {
            $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'";
        } else {
            $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)";
        }
        $result = db_query("SELECT owner_uid,favicon_avg_color,\n\t\t\t\t(favicon_last_checked IS NULL OR {$favicon_interval_qpart}) AS\n\t\t\t\t\t\tfavicon_needs_check\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'");
        $favicon_needs_check = sql_bool_to_bool(db_fetch_result($result, 0, "favicon_needs_check"));
        $favicon_avg_color = db_fetch_result($result, 0, "favicon_avg_color");
        $owner_uid = db_fetch_result($result, 0, "owner_uid");
        $site_url = db_escape_string(mb_substr(rewrite_relative_url($fetch_url, $rss->get_link()), 0, 245));
        _debug("site_url: {$site_url}", $debug_enabled);
        _debug("feed_title: " . $rss->get_title(), $debug_enabled);
        if ($favicon_needs_check || $force_refetch) {
            /* terrible hack: if we crash on floicon shit here, we won't check
             * the icon avgcolor again (unless the icon got updated) */
            $favicon_file = ICONS_DIR . "/{$feed}.ico";
            $favicon_modified = @filemtime($favicon_file);
            _debug("checking favicon...", $debug_enabled);
            check_feed_favicon($site_url, $feed);
            $favicon_modified_new = @filemtime($favicon_file);
            if ($favicon_modified_new > $favicon_modified) {
                $favicon_avg_color = '';
            }
            if (file_exists($favicon_file) && function_exists("imagecreatefromstring") && $favicon_avg_color == '') {
                require_once "colors.php";
                db_query("UPDATE ttrss_feeds SET favicon_avg_color = 'fail' WHERE\n\t\t\t\t\t\t\tid = '{$feed}'");
                $favicon_color = db_escape_string(calculate_avg_color($favicon_file));
                $favicon_colorstring = ",favicon_avg_color = '" . $favicon_color . "'";
            } else {
                if ($favicon_avg_color == 'fail') {
                    _debug("floicon failed on this file, not trying to recalculate avg color", $debug_enabled);
                }
            }
            db_query("UPDATE ttrss_feeds SET favicon_last_checked = NOW()\n\t\t\t\t\t{$favicon_colorstring}\n\t\t\t\t\tWHERE id = '{$feed}'");
        }
        _debug("loading filters & labels...", $debug_enabled);
        $filters = load_filters($feed, $owner_uid);
        _debug("" . count($filters) . " filters loaded.", $debug_enabled);
        $items = $rss->get_items();
        if (!is_array($items)) {
            _debug("no articles found.", $debug_enabled);
            db_query("UPDATE ttrss_feeds\n\t\t\t\t\tSET last_updated = NOW(), last_error = '' WHERE id = '{$feed}'");
            return;
            // no articles
        }
        if ($pubsub_state != 2 && PUBSUBHUBBUB_ENABLED) {
            _debug("checking for PUSH hub...", $debug_enabled);
            $feed_hub_url = false;
            $links = $rss->get_links('hub');
            if ($links && is_array($links)) {
                foreach ($links as $l) {
                    $feed_hub_url = $l;
                    break;
                }
            }
            _debug("feed hub url: {$feed_hub_url}", $debug_enabled);
            $feed_self_url = $fetch_url;
            $links = $rss->get_links('self');
            if ($links && is_array($links)) {
                foreach ($links as $l) {
                    $feed_self_url = $l;
                    break;
                }
            }
            _debug("feed self url = {$feed_self_url}");
            if ($feed_hub_url && $feed_self_url && function_exists('curl_init') && !ini_get("open_basedir")) {
                require_once 'lib/pubsubhubbub/subscriber.php';
                $callback_url = get_self_url_prefix() . "/public.php?op=pubsub&id={$feed}";
                $s = new Subscriber($feed_hub_url, $callback_url);
                $rc = $s->subscribe($feed_self_url);
                _debug("feed hub url found, subscribe request sent. [rc={$rc}]", $debug_enabled);
                db_query("UPDATE ttrss_feeds SET pubsub_state = 1\n\t\t\t\t\t\tWHERE id = '{$feed}'");
            }
        }
        _debug("processing articles...", $debug_enabled);
        $tstart = time();
        foreach ($items as $item) {
            if ($_REQUEST['xdebug'] == 3) {
                print_r($item);
            }
            if (ini_get("max_execution_time") > 0 && time() - $tstart >= ini_get("max_execution_time") * 0.7) {
                _debug("looks like there's too many articles to process at once, breaking out", $debug_enabled);
                break;
            }
            $entry_guid = $item->get_id();
            if (!$entry_guid) {
                $entry_guid = $item->get_link();
            }
            if (!$entry_guid) {
                $entry_guid = make_guid_from_title($item->get_title());
            }
            if (!$entry_guid) {
                continue;
            }
            $entry_guid = "{$owner_uid},{$entry_guid}";
            $entry_guid_hashed = db_escape_string('SHA1:' . sha1($entry_guid));
            _debug("guid {$entry_guid} / {$entry_guid_hashed}", $debug_enabled);
            $entry_timestamp = "";
            $entry_timestamp = $item->get_date();
            _debug("orig date: " . $item->get_date(), $debug_enabled);
            if ($entry_timestamp == -1 || !$entry_timestamp || $entry_timestamp > time()) {
                $entry_timestamp = time();
            }
            $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
            _debug("date {$entry_timestamp} [{$entry_timestamp_fmt}]", $debug_enabled);
            //				$entry_title = html_entity_decode($item->get_title(), ENT_COMPAT, 'UTF-8');
            //				$entry_title = decode_numeric_entities($entry_title);
            $entry_title = $item->get_title();
            $entry_link = rewrite_relative_url($site_url, $item->get_link());
            _debug("title {$entry_title}", $debug_enabled);
            _debug("link {$entry_link}", $debug_enabled);
            if (!$entry_title) {
                $entry_title = date("Y-m-d H:i:s", $entry_timestamp);
            }
            $entry_content = $item->get_content();
            if (!$entry_content) {
                $entry_content = $item->get_description();
            }
            if ($_REQUEST["xdebug"] == 2) {
                print "content: ";
                print $entry_content;
                print "\n";
            }
            $entry_comments = $item->get_comments_url();
            $entry_author = $item->get_author();
            $entry_guid = db_escape_string(mb_substr($entry_guid, 0, 245));
            $entry_comments = db_escape_string(mb_substr(trim($entry_comments), 0, 245));
            $entry_author = db_escape_string(mb_substr(trim($entry_author), 0, 245));
            $num_comments = (int) $item->get_comments_count();
            _debug("author {$entry_author}", $debug_enabled);
            _debug("num_comments: {$num_comments}", $debug_enabled);
            _debug("looking for tags...", $debug_enabled);
            // parse <category> entries into tags
            $additional_tags = array();
            $additional_tags_src = $item->get_categories();
            if (is_array($additional_tags_src)) {
                foreach ($additional_tags_src as $tobj) {
                    array_push($additional_tags, $tobj);
                }
            }
            $entry_tags = array_unique($additional_tags);
            for ($i = 0; $i < count($entry_tags); $i++) {
                $entry_tags[$i] = mb_strtolower($entry_tags[$i], 'utf-8');
            }
            _debug("tags found: " . join(",", $entry_tags), $debug_enabled);
            _debug("done collecting data.", $debug_enabled);
            $result = db_query("SELECT id, content_hash, lang FROM ttrss_entries\n\t\t\t\t\tWHERE guid = '" . db_escape_string($entry_guid) . "' OR guid = '{$entry_guid_hashed}'");
            if (db_num_rows($result) != 0) {
                $base_entry_id = db_fetch_result($result, 0, "id");
                $entry_stored_hash = db_fetch_result($result, 0, "content_hash");
                $article_labels = get_article_labels($base_entry_id, $owner_uid);
                $entry_language = db_fetch_result($result, 0, "lang");
                $existing_tags = get_article_tags($base_entry_id, $owner_uid);
                $entry_tags = array_unique(array_merge($entry_tags, $existing_tags));
            } else {
                $base_entry_id = false;
                $entry_stored_hash = "";
                $article_labels = array();
                $entry_language = "";
            }
            $article = array("owner_uid" => $owner_uid, "guid" => $entry_guid, "guid_hashed" => $entry_guid_hashed, "title" => $entry_title, "content" => $entry_content, "link" => $entry_link, "labels" => $article_labels, "tags" => $entry_tags, "author" => $entry_author, "force_catchup" => false, "score_modifier" => 0, "language" => $entry_language, "feed" => array("id" => $feed, "fetch_url" => $fetch_url, "site_url" => $site_url));
            $entry_plugin_data = "";
            $entry_current_hash = calculate_article_hash($article, $pluginhost);
            _debug("article hash: {$entry_current_hash} [stored={$entry_stored_hash}]", $debug_enabled);
            if ($entry_current_hash == $entry_stored_hash && !isset($_REQUEST["force_rehash"])) {
                _debug("stored article seems up to date [IID: {$base_entry_id}], updating timestamp only", $debug_enabled);
                // we keep encountering the entry in feeds, so we need to
                // update date_updated column so that we don't get horrible
                // dupes when the entry gets purged and reinserted again e.g.
                // in the case of SLOW SLOW OMG SLOW updating feeds
                $base_entry_id = db_fetch_result($result, 0, "id");
                db_query("UPDATE ttrss_entries SET date_updated = NOW()\n\t\t\t\t\t\tWHERE id = '{$base_entry_id}'");
                // if we allow duplicate posts, we have to continue to
                // create the user entries for this feed
                if (!get_pref("ALLOW_DUPLICATE_POSTS", $owner_uid, false)) {
                    continue;
                }
            }
            _debug("hash differs, applying plugin filters:", $debug_enabled);
            foreach ($pluginhost->get_hooks(PluginHost::HOOK_ARTICLE_FILTER) as $plugin) {
                _debug("... " . get_class($plugin), $debug_enabled);
                $start = microtime(true);
                $article = $plugin->hook_article_filter($article);
                _debug("=== " . sprintf("%.4f (sec)", microtime(true) - $start), $debug_enabled);
                $entry_plugin_data .= mb_strtolower(get_class($plugin)) . ",";
            }
            $entry_plugin_data = db_escape_string($entry_plugin_data);
            _debug("plugin data: {$entry_plugin_data}", $debug_enabled);
            // Workaround: 4-byte unicode requires utf8mb4 in MySQL. See https://tt-rss.org/forum/viewtopic.php?f=1&t=3377&p=20077#p20077
            if (DB_TYPE == "mysql") {
                foreach ($article as $k => $v) {
                    // i guess we'll have to take the risk of 4byte unicode labels & tags here
                    if (!is_array($article[$k])) {
                        $article[$k] = preg_replace('/[\\x{10000}-\\x{10FFFF}]/u', "�", $v);
                    }
                }
            }
            /* Collect article tags here so we could filter by them: */
            $article_filters = get_article_filters($filters, $article["title"], $article["content"], $article["link"], 0, $article["author"], $article["tags"]);
            if ($debug_enabled) {
                _debug("article filters: ", $debug_enabled);
                if (count($article_filters) != 0) {
                    print_r($article_filters);
                }
            }
            $plugin_filter_names = find_article_filters($article_filters, "plugin");
            $plugin_filter_actions = $pluginhost->get_filter_actions();
            if (count($plugin_filter_names) > 0) {
                _debug("applying plugin filter actions...", $debug_enabled);
                foreach ($plugin_filter_names as $pfn) {
                    list($pfclass, $pfaction) = explode(":", $pfn["param"]);
                    if (isset($plugin_filter_actions[$pfclass])) {
                        $plugin = $pluginhost->get_plugin($pfclass);
                        _debug("... {$pfclass}: {$pfaction}", $debug_enabled);
                        if ($plugin) {
                            $start = microtime(true);
                            $article = $plugin->hook_article_filter_action($article, $pfaction);
                            _debug("=== " . sprintf("%.4f (sec)", microtime(true) - $start), $debug_enabled);
                        } else {
                            _debug("??? {$pfclass}: plugin object not found.");
                        }
                    } else {
                        _debug("??? {$pfclass}: filter plugin not registered.");
                    }
                }
            }
            $entry_tags = $article["tags"];
            $entry_guid = db_escape_string($entry_guid);
            $entry_title = db_escape_string($article["title"]);
            $entry_author = db_escape_string($article["author"]);
            $entry_link = db_escape_string($article["link"]);
            $entry_content = $article["content"];
            // escaped below
            $entry_force_catchup = $article["force_catchup"];
            $article_labels = $article["labels"];
            $entry_score_modifier = (int) $article["score_modifier"];
            $entry_language = db_escape_string($article["language"]);
            if ($debug_enabled) {
                _debug("article labels:", $debug_enabled);
                print_r($article_labels);
            }
            _debug("force catchup: {$entry_force_catchup}");
            if ($cache_images && is_writable(CACHE_DIR . '/images')) {
                cache_images($entry_content, $site_url, $debug_enabled);
            }
            $entry_content = db_escape_string($entry_content, false);
            //db_query("BEGIN");
            $result = db_query("SELECT id FROM\tttrss_entries\n\t\t\t\t\tWHERE (guid = '{$entry_guid}' OR guid = '{$entry_guid_hashed}')");
            if (db_num_rows($result) == 0) {
                _debug("base guid [{$entry_guid}] not found", $debug_enabled);
                // base post entry does not exist, create it
                $result = db_query("INSERT INTO ttrss_entries\n\t\t\t\t\t\t\t(title,\n\t\t\t\t\t\t\tguid,\n\t\t\t\t\t\t\tlink,\n\t\t\t\t\t\t\tupdated,\n\t\t\t\t\t\t\tcontent,\n\t\t\t\t\t\t\tcontent_hash,\n\t\t\t\t\t\t\tno_orig_date,\n\t\t\t\t\t\t\tdate_updated,\n\t\t\t\t\t\t\tdate_entered,\n\t\t\t\t\t\t\tcomments,\n\t\t\t\t\t\t\tnum_comments,\n\t\t\t\t\t\t\tplugin_data,\n\t\t\t\t\t\t\tlang,\n\t\t\t\t\t\t\tauthor)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t('{$entry_title}',\n\t\t\t\t\t\t\t'{$entry_guid_hashed}',\n\t\t\t\t\t\t\t'{$entry_link}',\n\t\t\t\t\t\t\t'{$entry_timestamp_fmt}',\n\t\t\t\t\t\t\t'{$entry_content}',\n\t\t\t\t\t\t\t'{$entry_current_hash}',\n\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\tNOW(),\n\t\t\t\t\t\t\t'{$date_feed_processed}',\n\t\t\t\t\t\t\t'{$entry_comments}',\n\t\t\t\t\t\t\t'{$num_comments}',\n\t\t\t\t\t\t\t'{$entry_plugin_data}',\n\t\t\t\t\t\t\t'{$entry_language}',\n\t\t\t\t\t\t\t'{$entry_author}')");
            } else {
                $base_entry_id = db_fetch_result($result, 0, "id");
            }
            // now it should exist, if not - bad luck then
            $result = db_query("SELECT id FROM ttrss_entries\n\t\t\t\t\tWHERE guid = '{$entry_guid}' OR guid = '{$entry_guid_hashed}'");
            $entry_ref_id = 0;
            $entry_int_id = 0;
            if (db_num_rows($result) == 1) {
                _debug("base guid found, checking for user record", $debug_enabled);
                $ref_id = db_fetch_result($result, 0, "id");
                $entry_ref_id = $ref_id;
                /* $stored_guid = db_fetch_result($result, 0, "guid");
                					if ($stored_guid != $entry_guid_hashed) {
                						if ($debug_enabled) _debug("upgrading compat guid to hashed one", $debug_enabled);
                
                						db_query("UPDATE ttrss_entries SET guid = '$entry_guid_hashed' WHERE
                							id = '$ref_id'");
                					} */
                // check for user post link to main table
                // do we allow duplicate posts with same GUID in different feeds?
                if (get_pref("ALLOW_DUPLICATE_POSTS", $owner_uid, false)) {
                    $dupcheck_qpart = "AND (feed_id = '{$feed}' OR feed_id IS NULL)";
                } else {
                    $dupcheck_qpart = "";
                }
                if (find_article_filter($article_filters, "filter")) {
                    //db_query("COMMIT"); // close transaction in progress
                    continue;
                }
                $score = calculate_article_score($article_filters) + $entry_score_modifier;
                _debug("initial score: {$score} [including plugin modifier: {$entry_score_modifier}]", $debug_enabled);
                $query = "SELECT ref_id, int_id FROM ttrss_user_entries WHERE\n\t\t\t\t\t\t\tref_id = '{$ref_id}' AND owner_uid = '{$owner_uid}'\n\t\t\t\t\t\t\t{$dupcheck_qpart}";
                //					if ($_REQUEST["xdebug"]) print "$query\n";
                $result = db_query($query);
                // okay it doesn't exist - create user entry
                if (db_num_rows($result) == 0) {
                    _debug("user record not found, creating...", $debug_enabled);
                    if ($score >= -500 && !find_article_filter($article_filters, 'catchup') && !$entry_force_catchup) {
                        $unread = 'true';
                        $last_read_qpart = 'NULL';
                    } else {
                        $unread = 'false';
                        $last_read_qpart = 'NOW()';
                    }
                    if (find_article_filter($article_filters, 'mark') || $score > 1000) {
                        $marked = 'true';
                    } else {
                        $marked = 'false';
                    }
                    if (find_article_filter($article_filters, 'publish')) {
                        $published = 'true';
                    } else {
                        $published = 'false';
                    }
                    // N-grams
                    /* if (DB_TYPE == "pgsql" and defined('_NGRAM_TITLE_DUPLICATE_THRESHOLD')) {
                    
                    							$result = db_query("SELECT COUNT(*) AS similar FROM
                    									ttrss_entries,ttrss_user_entries
                    								WHERE ref_id = id AND updated >= NOW() - INTERVAL '7 day'
                    									AND similarity(title, '$entry_title') >= "._NGRAM_TITLE_DUPLICATE_THRESHOLD."
                    									AND owner_uid = $owner_uid");
                    
                    							$ngram_similar = db_fetch_result($result, 0, "similar");
                    
                    							_debug("N-gram similar results: $ngram_similar", $debug_enabled);
                    
                    							if ($ngram_similar > 0) {
                    								$unread = 'false';
                    							}
                    						} */
                    $last_marked = $marked == 'true' ? 'NOW()' : 'NULL';
                    $last_published = $published == 'true' ? 'NOW()' : 'NULL';
                    $result = db_query("INSERT INTO ttrss_user_entries\n\t\t\t\t\t\t\t\t(ref_id, owner_uid, feed_id, unread, last_read, marked,\n\t\t\t\t\t\t\t\tpublished, score, tag_cache, label_cache, uuid,\n\t\t\t\t\t\t\t\tlast_marked, last_published)\n\t\t\t\t\t\t\tVALUES ('{$ref_id}', '{$owner_uid}', '{$feed}', {$unread},\n\t\t\t\t\t\t\t\t{$last_read_qpart}, {$marked}, {$published}, '{$score}', '', '',\n\t\t\t\t\t\t\t\t'', {$last_marked}, {$last_published})");
                    if (PUBSUBHUBBUB_HUB && $published == 'true') {
                        $rss_link = get_self_url_prefix() . "/public.php?op=rss&id=-2&key=" . get_feed_access_key(-2, false, $owner_uid);
                        $p = new Publisher(PUBSUBHUBBUB_HUB);
                        /* $pubsub_result = */
                        $p->publish_update($rss_link);
                    }
                    $result = db_query("SELECT int_id FROM ttrss_user_entries WHERE\n\t\t\t\t\t\t\t\tref_id = '{$ref_id}' AND owner_uid = '{$owner_uid}' AND\n\t\t\t\t\t\t\t\tfeed_id = '{$feed}' LIMIT 1");
                    if (db_num_rows($result) == 1) {
                        $entry_int_id = db_fetch_result($result, 0, "int_id");
                    }
                } else {
                    _debug("user record FOUND", $debug_enabled);
                    $entry_ref_id = db_fetch_result($result, 0, "ref_id");
                    $entry_int_id = db_fetch_result($result, 0, "int_id");
                }
                _debug("RID: {$entry_ref_id}, IID: {$entry_int_id}", $debug_enabled);
                if (DB_TYPE == "pgsql") {
                    $tsvector_combined = db_escape_string(mb_substr($entry_title . ' ' . strip_tags(str_replace('<', ' <', $entry_content)), 0, 1000000));
                    $tsvector_qpart = "tsvector_combined = to_tsvector('{$feed_language}', '{$tsvector_combined}'),";
                } else {
                    $tsvector_qpart = "";
                }
                db_query("UPDATE ttrss_entries\n\t\t\t\t\t\tSET title = '{$entry_title}',\n\t\t\t\t\t\t\tcontent = '{$entry_content}',\n\t\t\t\t\t\t\tcontent_hash = '{$entry_current_hash}',\n\t\t\t\t\t\t\tupdated = '{$entry_timestamp_fmt}',\n\t\t\t\t\t\t\t{$tsvector_qpart}\n\t\t\t\t\t\t\tnum_comments = '{$num_comments}',\n\t\t\t\t\t\t\tplugin_data = '{$entry_plugin_data}',\n\t\t\t\t\t\t\tauthor = '{$entry_author}',\n\t\t\t\t\t\t\tlang = '{$entry_language}'\n\t\t\t\t\t\tWHERE id = '{$ref_id}'");
                // update aux data
                db_query("UPDATE ttrss_user_entries\n\t\t\t\t\t\t\tSET score = '{$score}' WHERE ref_id = '{$ref_id}'");
                if ($mark_unread_on_update) {
                    _debug("article updated, marking unread as requested.", $debug_enabled);
                    db_query("UPDATE ttrss_user_entries\n\t\t\t\t\t\t\tSET last_read = null, unread = true WHERE ref_id = '{$ref_id}'");
                }
            }
            //db_query("COMMIT");
            _debug("assigning labels [other]...", $debug_enabled);
            foreach ($article_labels as $label) {
                label_add_article($entry_ref_id, $label[1], $owner_uid);
            }
            _debug("assigning labels [filters]...", $debug_enabled);
            assign_article_to_label_filters($entry_ref_id, $article_filters, $owner_uid, $article_labels);
            _debug("looking for enclosures...", $debug_enabled);
            // enclosures
            $enclosures = array();
            $encs = $item->get_enclosures();
            if (is_array($encs)) {
                foreach ($encs as $e) {
                    $e_item = array($e->link, $e->type, $e->length, $e->title, $e->width, $e->height);
                    array_push($enclosures, $e_item);
                }
            }
            if ($debug_enabled) {
                _debug("article enclosures:", $debug_enabled);
                print_r($enclosures);
            }
            //db_query("BEGIN");
            //				debugging
            //				db_query("DELETE FROM ttrss_enclosures WHERE post_id = '$entry_ref_id'");
            foreach ($enclosures as $enc) {
                $enc_url = db_escape_string($enc[0]);
                $enc_type = db_escape_string($enc[1]);
                $enc_dur = db_escape_string($enc[2]);
                $enc_title = db_escape_string($enc[3]);
                $enc_width = intval($enc[4]);
                $enc_height = intval($enc[5]);
                $result = db_query("SELECT id FROM ttrss_enclosures\n\t\t\t\t\t\tWHERE content_url = '{$enc_url}' AND post_id = '{$entry_ref_id}'");
                if (db_num_rows($result) == 0) {
                    db_query("INSERT INTO ttrss_enclosures\n\t\t\t\t\t\t\t(content_url, content_type, title, duration, post_id, width, height) VALUES\n\t\t\t\t\t\t\t('{$enc_url}', '{$enc_type}', '{$enc_title}', '{$enc_dur}', '{$entry_ref_id}', {$enc_width}, {$enc_height})");
                }
            }
            //db_query("COMMIT");
            // check for manual tags (we have to do it here since they're loaded from filters)
            foreach ($article_filters as $f) {
                if ($f["type"] == "tag") {
                    $manual_tags = trim_array(explode(",", $f["param"]));
                    foreach ($manual_tags as $tag) {
                        if (tag_is_valid($tag)) {
                            array_push($entry_tags, $tag);
                        }
                    }
                }
            }
            // Skip boring tags
            $boring_tags = trim_array(explode(",", mb_strtolower(get_pref('BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8')));
            $filtered_tags = array();
            $tags_to_cache = array();
            if ($entry_tags && is_array($entry_tags)) {
                foreach ($entry_tags as $tag) {
                    if (array_search($tag, $boring_tags) === false) {
                        array_push($filtered_tags, $tag);
                    }
                }
            }
            $filtered_tags = array_unique($filtered_tags);
            if ($debug_enabled) {
                _debug("filtered article tags:", $debug_enabled);
                print_r($filtered_tags);
            }
            // Save article tags in the database
            if (count($filtered_tags) > 0) {
                //db_query("BEGIN");
                foreach ($filtered_tags as $tag) {
                    $tag = sanitize_tag($tag);
                    $tag = db_escape_string($tag);
                    if (!tag_is_valid($tag)) {
                        continue;
                    }
                    $result = db_query("SELECT id FROM ttrss_tags\n\t\t\t\t\t\t\tWHERE tag_name = '{$tag}' AND post_int_id = '{$entry_int_id}' AND\n\t\t\t\t\t\t\towner_uid = '{$owner_uid}' LIMIT 1");
                    if ($result && db_num_rows($result) == 0) {
                        db_query("INSERT INTO ttrss_tags\n\t\t\t\t\t\t\t\t\t(owner_uid,tag_name,post_int_id)\n\t\t\t\t\t\t\t\t\tVALUES ('{$owner_uid}','{$tag}', '{$entry_int_id}')");
                    }
                    array_push($tags_to_cache, $tag);
                }
                /* update the cache */
                $tags_to_cache = array_unique($tags_to_cache);
                $tags_str = db_escape_string(join(",", $tags_to_cache));
                db_query("UPDATE ttrss_user_entries\n\t\t\t\t\t\tSET tag_cache = '{$tags_str}' WHERE ref_id = '{$entry_ref_id}'\n\t\t\t\t\t\tAND owner_uid = {$owner_uid}");
                //db_query("COMMIT");
            }
            _debug("article processed", $debug_enabled);
        }
        _debug("purging feed...", $debug_enabled);
        purge_feed($feed, 0, $debug_enabled);
        db_query("UPDATE ttrss_feeds\n\t\t\t\tSET last_updated = NOW(), last_error = '' WHERE id = '{$feed}'");
        //			db_query("COMMIT");
    } else {
        $error_msg = db_escape_string(mb_substr($rss->error(), 0, 245));
        _debug("fetch error: {$error_msg}", $debug_enabled);
        if (count($rss->errors()) > 1) {
            foreach ($rss->errors() as $error) {
                _debug("+ {$error}");
            }
        }
        db_query("UPDATE ttrss_feeds SET last_error = '{$error_msg}',\n\t\t\t\tlast_updated = NOW() WHERE id = '{$feed}'");
        unset($rss);
    }
    _debug("done", $debug_enabled);
    return $rss;
}
Exemplo n.º 13
0
function api_get_headlines($link, $feed_id, $limit, $offset, $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order, $include_attachments, $since_id)
{
    /* do not rely on params below */
    $search = db_escape_string($_REQUEST["search"]);
    $search_mode = db_escape_string($_REQUEST["search_mode"]);
    $match_on = db_escape_string($_REQUEST["match_on"]);
    $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit, $view_mode, $is_cat, $search, $search_mode, $match_on, $order, $offset, 0, false, $since_id);
    $result = $qfh_ret[0];
    $feed_title = $qfh_ret[1];
    $headlines = array();
    while ($line = db_fetch_assoc($result)) {
        $is_updated = $line["last_read"] == "" && ($line["unread"] != "t" && $line["unread"] != "1");
        $headline_row = array("id" => (int) $line["id"], "unread" => sql_bool_to_bool($line["unread"]), "marked" => sql_bool_to_bool($line["marked"]), "published" => sql_bool_to_bool($line["published"]), "updated" => strtotime($line["updated"]), "is_updated" => $is_updated, "title" => $line["title"], "link" => $line["link"], "feed_id" => $line["feed_id"], "tags" => get_article_tags($link, $line["id"]));
        if ($include_attachments) {
            $headline_row['attachments'] = get_article_enclosures($link, $line['id']);
        }
        if ($show_excerpt) {
            $excerpt = truncate_string(strip_tags($line["content_preview"]), 100);
            $headline_row["excerpt"] = $excerpt;
        }
        if ($show_content) {
            $headline_row["content"] = $line["content_preview"];
        }
        array_push($headlines, $headline_row);
    }
    return $headlines;
}
/**
 * get_article
 * 
 * 
 * 
 * 
 * 
 * 
 */
function get_article($article_id = '')
{
    $article_id = (int) $article_id;
    $conn = reader_connect();
    $query = "SELECT\n\t\t\t\t\tarticles.id, \n\t\t\t\t \tarticles.title, \n\t\t\t\t\tarticles.url, \n\t\t\t\t\tarticles.summary, \n\t\t\t\t\tarticles.body, \n\t\t\t\t\tarticles.date_uploaded, \n\t\t\t\t\tarticles.date_amended,\n\t\t\t\t\tcategories.title AS category_title, \n\t\t\t\t\tcategories.url AS category_url,\n\t\t\t\t\tparent.title AS parent_category_title,\n\t\t\t\t\tparent.url AS parent_category_url,\n\t\t\t\t\tauthors.name AS author_name, \n\t\t\t\t\tauthors.url AS author_url,\n\t\t\t\t\tauthors.email AS author_email,\n\t\t\t\t\tauthors.contact_flag, \n\t\t\t\t\tarticles.seo_title,\n\t\t\t\t\tarticles.seo_desc, \n\t\t\t\t\tarticles.seo_keywords,\n\t\t\t\t\tarticles.comments_disable, \n\t\t\t\t\tarticles.comments_hide\n\t\t\t\tFROM articles\n\t\t\t\t\tLEFT JOIN authors ON articles.author_id = authors.id \n\t\t\t\t\tLEFT JOIN categories ON articles.category_id = categories.id\n\t\t\t\t\tLEFT JOIN categories AS parent ON categories.category_id = parent.id\n\t\t\t\tWHERE articles.status IN('P','A')\n\t\t\t\t\tAND articles.date_uploaded <= NOW()";
    $query .= !empty($article_id) ? " AND articles.id = " . $article_id : " ORDER BY articles.id DESC LIMIT 0,1";
    // echo $query;
    $result = $conn->query($query);
    $row = $result->fetch_assoc();
    $row = stripslashes_deep($row);
    $result->close();
    // fix relative urls
    $row['body'] = convert_relative_urls($row['body']);
    // check pagination
    $row['pages'] = paginate_article_body($row['body']);
    $row['total_pages'] = count($row['pages']);
    // create links
    $row['link']['blog'] = WW_REAL_WEB_ROOT . '/' . date('Y/m/d', strtotime($row['date_uploaded'])) . '/' . $row['url'] . '/';
    $row['link']['cms'] = WW_REAL_WEB_ROOT . '/' . $row['category_url'] . '/' . $row['url'] . '/';
    // get tags
    $tags = get_article_tags($article_id);
    $row['tags'] = !empty($tags) ? $tags : '';
    // get attachments
    $attachments = get_article_attachments($article_id);
    $row['attachments'] = !empty($attachments) ? $attachments : '';
    // get comments
    if (empty($row['comments_hide'])) {
        $comments = get_article_comments($article_id);
        $row['comments'] = !empty($comments) ? $comments : '';
    }
    return $row;
}
/**
 * get_article
 * 
 * 
 * 
 * 
 * 
 * 
 */
function get_article($article_id = '')
{
    $article_id = (int) $article_id;
    $conn = reader_connect();
    $query = "SELECT\n\t\t\t\t\tarticles.id, \n\t\t\t\t \tarticles.title, \n\t\t\t\t\tarticles.url, \n\t\t\t\t\tarticles.summary, \n\t\t\t\t\tarticles.body, \n\t\t\t\t\tarticles.date_uploaded, \n\t\t\t\t\tarticles.date_amended,\n\t\t\t\t\tcategories.title AS category_title, \n\t\t\t\t\tcategories.url AS category_url,\n\t\t\t\t\tparent.title AS parent_category_title,\n\t\t\t\t\tparent.url AS parent_category_url,\n\t\t\t\t\tauthors.name AS author_name, \n\t\t\t\t\tauthors.url AS author_url,\n\t\t\t\t\tauthors.email AS author_email,\n\t\t\t\t\tauthors.contact_flag, \n\t\t\t\t\tarticles.seo_title,\n\t\t\t\t\tarticles.seo_desc, \n\t\t\t\t\tarticles.seo_keywords,\n\t\t\t\t\tarticles.redirect_url,\n\t\t\t\t\tarticles.redirect_code,\n\t\t\t\t\tarticles.comments_disable, \n\t\t\t\t\tarticles.comments_hide\n\t\t\t\tFROM articles\n\t\t\t\t\tLEFT JOIN authors ON articles.author_id = authors.id \n\t\t\t\t\tLEFT JOIN categories ON articles.category_id = categories.id\n\t\t\t\t\tLEFT JOIN categories AS parent ON categories.category_id = parent.id\n\t\t\t\tWHERE articles.status IN('P','A')\n\t\t\t\t\tAND articles.date_uploaded <= UTC_TIMESTAMP()";
    $query .= !empty($article_id) ? " AND articles.id = " . $article_id : " ORDER BY articles.id DESC LIMIT 0,1";
    $result = $conn->query($query);
    $row = $result->fetch_assoc();
    // if a redirect url has been set we redirect right here
    if (!empty($row['redirect_url'])) {
        // send 301 redirect unless another valid code has been set
        $redirect_code = (int) $row['redirect_code'];
        $redirect_code = !empty($redirect_code) ? $redirect_code : 301;
        redirect_article($row['redirect_url'], $redirect_code);
    }
    $row = stripslashes_deep($row);
    $result->close();
    // adjust times to local timezone if necessary
    $ts = strtotime($row['date_uploaded']);
    $offset = date('Z');
    $row['date_ts'] = $ts + $offset;
    $row['date_uploaded'] = date('Y-m-d H:i:s', $row['date_ts']);
    // fix relative urls
    $row['body'] = convert_relative_urls($row['body']);
    // check pagination
    $row['pages'] = paginate_article_body($row['body']);
    $row['total_pages'] = count($row['pages']);
    // create links
    $row['link']['blog'] = WW_REAL_WEB_ROOT . '/' . date('Y/m/d', $row['date_ts']) . '/' . $row['url'] . '/';
    $row['link']['cms'] = WW_REAL_WEB_ROOT . '/' . $row['category_url'] . '/' . $row['url'] . '/';
    // put category url in a get param if not set (for custom css styles)
    $_GET['category_url'] = isset($_GET['category_url']) ? $_GET['category_url'] : $row['category_url'];
    // get tags
    $tags = get_article_tags($article_id);
    $row['tags'] = !empty($tags) ? $tags : '';
    // get attachments
    $attachments = get_article_attachments($article_id);
    $row['attachments'] = !empty($attachments) ? $attachments : '';
    // get comments
    if (empty($row['comments_hide'])) {
        $comments = get_article_comments($article_id);
        $row['comments'] = !empty($comments) ? $comments : '';
    }
    return $row;
}
Exemplo n.º 16
0
 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, $next_unread_feed, $offset, $vgr_last_feed = false, $override_order = false, $include_children = false)
 {
     $disable_cache = false;
     $reply = array();
     $timing_info = getmicrotime();
     $topmost_article_ids = array();
     if (!$offset) {
         $offset = 0;
     }
     if ($method == "undefined") {
         $method = "";
     }
     $method_split = explode(":", $method);
     if ($method == "ForceUpdate" && $feed && is_numeric($feed) > 0) {
         include "rssfuncs.php";
         update_rss_feed($this->link, $feed, true);
     }
     if ($method_split[0] == "MarkAllReadGR") {
         catchup_feed($this->link, $method_split[1], false);
     }
     // FIXME: might break tag display?
     if (is_numeric($feed) && $feed > 0 && !$cat_view) {
         $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE id = '{$feed}' LIMIT 1");
         if (db_num_rows($result) == 0) {
             $reply['content'] = "<div align='center'>" . __('Feed not found.') . "</div>";
         }
     }
     if (is_numeric($feed) && $feed > 0) {
         $result = db_query($this->link, "SELECT rtl_content FROM ttrss_feeds\r\n\t\t\t\tWHERE id = '{$feed}' AND owner_uid = " . $_SESSION["uid"]);
         if (db_num_rows($result) == 1) {
             $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
         } else {
             $rtl_content = false;
         }
         if ($rtl_content) {
             $rtl_tag = "dir=\"RTL\"";
         } else {
             $rtl_tag = "";
         }
     } else {
         $rtl_tag = "";
         $rtl_content = false;
     }
     @($search = db_escape_string($_REQUEST["query"]));
     if ($search) {
         $disable_cache = true;
     }
     @($search_mode = db_escape_string($_REQUEST["search_mode"]));
     @($match_on = db_escape_string($_REQUEST["match_on"]));
     if (!$match_on) {
         $match_on = "both";
     }
     if ($_REQUEST["debug"]) {
         $timing_info = print_checkpoint("H0", $timing_info);
     }
     //		error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
     if ($search_mode == '' && $method != '') {
         $search_mode = $method;
     }
     //		error_log("search_mode: " . $search_mode);
     $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order, $offset, 0, false, 0, $include_children);
     if ($_REQUEST["debug"]) {
         $timing_info = print_checkpoint("H1", $timing_info);
     }
     $result = $qfh_ret[0];
     $feed_title = $qfh_ret[1];
     $feed_site_url = $qfh_ret[2];
     $last_error = $qfh_ret[3];
     $vgroup_last_feed = $vgr_last_feed;
     //		if (!$offset) {
     if (db_num_rows($result) > 0) {
         $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url, $feed_title, $feed, $cat_view, $search, $match_on, $search_mode, $view_mode, $last_error);
     }
     //		}
     $headlines_count = db_num_rows($result);
     if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
         $button_plugins = array();
         foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {
             $pclass = trim("button_{$p}");
             if (class_exists($pclass)) {
                 $plugin = new $pclass($link);
                 array_push($button_plugins, $plugin);
             }
         }
     }
     if (db_num_rows($result) > 0) {
         $lnum = $offset;
         $num_unread = 0;
         $cur_feed_title = '';
         $fresh_intl = get_pref($this->link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
         if ($_REQUEST["debug"]) {
             $timing_info = print_checkpoint("PS", $timing_info);
         }
         while ($line = db_fetch_assoc($result)) {
             $class = $lnum % 2 ? "even" : "odd";
             $id = $line["id"];
             $feed_id = $line["feed_id"];
             $label_cache = $line["label_cache"];
             $labels = false;
             if ($label_cache) {
                 $label_cache = json_decode($label_cache, true);
                 if ($label_cache) {
                     if ($label_cache["no-labels"] == 1) {
                         $labels = array();
                     } else {
                         $labels = $label_cache;
                     }
                 }
             }
             if (!is_array($labels)) {
                 $labels = get_article_labels($this->link, $id);
             }
             $labels_str = "<span id=\"HLLCTR-{$id}\">";
             $labels_str .= format_article_labels($labels, $id);
             $labels_str .= "</span>";
             if (count($topmost_article_ids) < 3) {
                 array_push($topmost_article_ids, $id);
             }
             if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {
                 $update_pic = "<img id='FUPDPIC-{$id}' src=\"" . theme_image($this->link, 'images/updated.png') . "\"\r\n\t\t\t\t\t\talt=\"Updated\">";
             } else {
                 $update_pic = "<img id='FUPDPIC-{$id}' src=\"images/blank_icon.gif\"\r\n\t\t\t\t\t\talt=\"Updated\">";
             }
             if (sql_bool_to_bool($line["unread"]) && time() - strtotime($line["updated_noms"]) < $fresh_intl) {
                 $update_pic = "<img id='FUPDPIC-{$id}' src=\"" . theme_image($this->link, 'images/fresh_sign.png') . "\" alt=\"Fresh\">";
             }
             if ($line["unread"] == "t" || $line["unread"] == "1") {
                 $class .= " Unread";
                 ++$num_unread;
                 $is_unread = true;
             } else {
                 $is_unread = false;
             }
             if ($line["marked"] == "t" || $line["marked"] == "1") {
                 $marked_pic = "<img id=\"FMPIC-{$id}\"\r\n\t\t\t\t\t\tsrc=\"" . theme_image($this->link, 'images/mark_set.png') . "\"\r\n\t\t\t\t\t\tclass=\"markedPic\" alt=\"Unstar article\"\r\n\t\t\t\t\t\tonclick='javascript:toggleMark({$id})'>";
             } else {
                 $marked_pic = "<img id=\"FMPIC-{$id}\"\r\n\t\t\t\t\t\tsrc=\"" . theme_image($this->link, 'images/mark_unset.png') . "\"\r\n\t\t\t\t\t\tclass=\"markedPic\" alt=\"Star article\"\r\n\t\t\t\t\t\tonclick='javascript:toggleMark({$id})'>";
             }
             if ($line["published"] == "t" || $line["published"] == "1") {
                 $published_pic = "<img id=\"FPPIC-{$id}\" src=\"" . theme_image($this->link, 'images/pub_set.png') . "\"\r\n\t\t\t\t\t\tclass=\"markedPic\"\r\n\t\t\t\t\t\talt=\"Unpublish article\" onclick='javascript:togglePub({$id})'>";
             } else {
                 $published_pic = "<img id=\"FPPIC-{$id}\" src=\"" . theme_image($this->link, 'images/pub_unset.png') . "\"\r\n\t\t\t\t\t\tclass=\"markedPic\"\r\n\t\t\t\t\t\talt=\"Publish article\" onclick='javascript:togglePub({$id})'>";
             }
             #				$content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
             #					$line["title"] . "</a>";
             #				$content_link = "<a
             #					href=\"" . htmlspecialchars($line["link"]) . "\"
             #					onclick=\"view($id,$feed_id);\">" .
             #					$line["title"] . "</a>";
             #				$content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
             #					$line["title"] . "</a>";
             $updated_fmt = make_local_datetime($this->link, $line["updated_noms"], false);
             if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
                 $content_preview = truncate_string(strip_tags($line["content_preview"]), 100);
             }
             $score = $line["score"];
             $score_pic = theme_image($this->link, "images/" . get_score_pic($score));
             /*				$score_title = __("(Click to change)");
             				$score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
             					onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
             $score_pic = "<img class='hlScorePic' src=\"{$score_pic}\"\r\n\t\t\t\t\ttitle=\"{$score}\">";
             if ($score > 500) {
                 $hlc_suffix = "H";
             } else {
                 if ($score < -100) {
                     $hlc_suffix = "L";
                 } else {
                     $hlc_suffix = "";
                 }
             }
             $entry_author = $line["author"];
             if ($entry_author) {
                 $entry_author = " - {$entry_author}";
             }
             $has_feed_icon = feed_has_icon($feed_id);
             if ($has_feed_icon) {
                 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/{$feed_id}.ico\" alt=\"\">";
             } else {
                 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";
             }
             if (!get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
                 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
                     if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
                         $cur_feed_title = $line["feed_title"];
                         $vgroup_last_feed = $feed_id;
                         $cur_feed_title = htmlspecialchars($cur_feed_title);
                         $vf_catchup_link = "(<a onclick='catchupFeedInGroup({$feed_id});' href='#'>" . __('mark as read') . "</a>)";
                         $reply['content'] .= "<div class='cdmFeedTitle'>" . "<div style=\"float : right\">{$feed_icon_img}</div>" . "<a href=\"#\" onclick=\"viewfeed({$feed_id})\">" . $line["feed_title"] . "</a> {$vf_catchup_link}</div>";
                     }
                 }
                 $mouseover_attrs = "onmouseover='postMouseIn({$id})'\r\n\t\t\t\t\t\tonmouseout='postMouseOut({$id})'";
                 $reply['content'] .= "<div class='{$class}' id='RROW-{$id}' {$mouseover_attrs}>";
                 $reply['content'] .= "<div class='hlUpdPic'>{$update_pic}</div>";
                 $reply['content'] .= "<div class='hlLeft'>";
                 $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"\r\n\t\t\t\t\t\t\tid=\"RCHK-{$id}\">";
                 $reply['content'] .= "{$marked_pic}";
                 $reply['content'] .= "{$published_pic}";
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "<div onclick='return hlClicked(event, {$id})'\r\n\t\t\t\t\t\tclass=\"hlTitle\"><span class='hlContent{$hlc_suffix}'>";
                 $reply['content'] .= "<a id=\"RTITLE-{$id}\"\r\n\t\t\t\t\t\thref=\"" . htmlspecialchars($line["link"]) . "\"\r\n\t\t\t\t\t\tonclick=\"\">" . truncate_string($line["title"], 200);
                 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
                     if ($content_preview) {
                         $reply['content'] .= "<span class=\"contentPreview\"> - {$content_preview}</span>";
                     }
                 }
                 $reply['content'] .= "</a></span>";
                 $reply['content'] .= $labels_str;
                 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') && defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
                     if (@$line["feed_title"]) {
                         $reply['content'] .= "<span class=\"hlFeed\">\r\n\t\t\t\t\t\t\t\t(<a href=\"#\" onclick=\"viewfeed({$feed_id})\">" . $line["feed_title"] . "</a>)\r\n\t\t\t\t\t\t\t</span>";
                     }
                 }
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "<span class=\"hlUpdated\">{$updated_fmt}</span>";
                 $reply['content'] .= "<div class=\"hlRight\">";
                 $reply['content'] .= $score_pic;
                 if ($line["feed_title"] && !get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
                     $reply['content'] .= "<span onclick=\"viewfeed({$feed_id})\"\r\n\t\t\t\t\t\t\tstyle=\"cursor : pointer\"\r\n\t\t\t\t\t\t\ttitle=\"" . htmlspecialchars($line['feed_title']) . "\">\r\n\t\t\t\t\t\t\t{$feed_icon_img}<span>";
                 }
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "</div>";
             } else {
                 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
                     if ($feed_id != $vgroup_last_feed) {
                         $cur_feed_title = $line["feed_title"];
                         $vgroup_last_feed = $feed_id;
                         $cur_feed_title = htmlspecialchars($cur_feed_title);
                         $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup({$feed_id});' href='#'>" . __('mark as read') . "</a>)";
                         $has_feed_icon = feed_has_icon($feed_id);
                         if ($has_feed_icon) {
                             $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/{$feed_id}.ico\" alt=\"\">";
                         } else {
                             //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
                         }
                         $reply['content'] .= "<div class='cdmFeedTitle'>" . "<div style=\"float : right\">{$feed_icon_img}</div>" . "<a href=\"#\" onclick=\"viewfeed({$feed_id})\">" . $line["feed_title"] . "</a> {$vf_catchup_link}</div>";
                     }
                 }
                 $expand_cdm = get_pref($this->link, 'CDM_EXPANDED');
                 $mouseover_attrs = "onmouseover='postMouseIn({$id})'\r\n\t\t\t\t\t\tonmouseout='postMouseOut({$id})'";
                 $reply['content'] .= "<div class=\"{$class}\"\r\n\t\t\t\t\t\tid=\"RROW-{$id}\" {$mouseover_attrs}'>";
                 $reply['content'] .= "<div class=\"cdmHeader\">";
                 $reply['content'] .= "<div>";
                 $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,\r\n\t\t\t\t\t\t\t'RROW-{$id}')\" id=\"RCHK-{$id}\"/>";
                 $reply['content'] .= "{$marked_pic}";
                 $reply['content'] .= "{$published_pic}";
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "<div id=\"PTITLE-FULL-{$id}\" style=\"display : none\">" . strip_tags($line['title']) . "</div>";
                 $reply['content'] .= "<span id=\"RTITLE-{$id}\"\r\n\t\t\t\t\t\tonclick=\"return cdmClicked(event, {$id});\"\r\n\t\t\t\t\t\tclass=\"titleWrap{$hlc_suffix}\">\r\n\t\t\t\t\t\t<a class=\"title\"\r\n\t\t\t\t\t\ttitle=\"" . htmlspecialchars($line['title']) . "\"\r\n\t\t\t\t\t\ttarget=\"_blank\" href=\"" . htmlspecialchars($line["link"]) . "\">" . truncate_string($line["title"], 100) . " {$entry_author}</a>";
                 $reply['content'] .= $labels_str;
                 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') && defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
                     if (@$line["feed_title"]) {
                         $reply['content'] .= "<span class=\"hlFeed\">\r\n\t\t\t\t\t\t\t\t(<a href=\"#\" onclick=\"viewfeed({$feed_id})\">" . $line["feed_title"] . "</a>)\r\n\t\t\t\t\t\t\t</span>";
                     }
                 }
                 if (!$expand_cdm) {
                     $content_hidden = "style=\"display : none\"";
                 } else {
                     $excerpt_hidden = "style=\"display : none\"";
                 }
                 $reply['content'] .= "<span {$excerpt_hidden}\r\n\t\t\t\t\t\tid=\"CEXC-{$id}\" class=\"cdmExcerpt\"> - {$content_preview}</span>";
                 $reply['content'] .= "</span>";
                 $reply['content'] .= "<div>";
                 $reply['content'] .= "<span class='updated'>{$updated_fmt}</span>";
                 $reply['content'] .= "{$score_pic}";
                 if (!get_pref($this->link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
                     $reply['content'] .= "<span style=\"cursor : pointer\"\r\n\t\t\t\t\t\t\ttitle=\"" . htmlspecialchars($line["feed_title"]) . "\"\r\n\t\t\t\t\t\t\tonclick=\"viewfeed({$feed_id})\">{$feed_icon_img}</span>";
                 }
                 $reply['content'] .= "<div class=\"updPic\">{$update_pic}</div>";
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "<div class=\"cdmContent\" {$content_hidden}\r\n\t\t\t\t\t\tonclick=\"return cdmClicked(event, {$id});\"\r\n\t\t\t\t\t\tid=\"CICD-{$id}\">";
                 $reply['content'] .= "<div class=\"cdmContentInner\">";
                 if ($line["orig_feed_id"]) {
                     $tmp_result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds\r\n\t\t\t\t\tWHERE id = " . $line["orig_feed_id"]);
                     if (db_num_rows($tmp_result) != 0) {
                         $reply['content'] .= "<div clear='both'>";
                         $reply['content'] .= __("Originally from:");
                         $reply['content'] .= "&nbsp;";
                         $tmp_line = db_fetch_assoc($tmp_result);
                         $reply['content'] .= "<a target='_blank'\r\n\t\t\t\t\t\t\t\thref=' " . htmlspecialchars($tmp_line['site_url']) . "'>" . $tmp_line['title'] . "</a>";
                         $reply['content'] .= "&nbsp;";
                         $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
                         $reply['content'] .= "<img title='" . __('Feed URL') . "'class='tinyFeedIcon' src='images/pub_set.png'></a>";
                         $reply['content'] .= "</div>";
                     }
                 }
                 $feed_site_url = $line["site_url"];
                 $article_content = sanitize($this->link, $line["content_preview"], false, false, $feed_site_url);
                 $reply['content'] .= "<div id=\"POSTNOTE-{$id}\">";
                 if ($line['note']) {
                     $reply['content'] .= format_article_note($id, $line['note']);
                 }
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "<span id=\"CWRAP-{$id}\">";
                 $reply['content'] .= $expand_cdm ? $article_content : '';
                 $reply['content'] .= "</span>";
                 /*					$tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM
                 						ttrss_feeds WHERE id = ".
                 						(($line['feed_id'] == null) ? $line['orig_feed_id'] :
                 							$line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);
                 
                 					$always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,
                 						0, "always_display_enclosures")); */
                 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
                 $reply['content'] .= format_article_enclosures($this->link, $id, $always_display_enclosures, $article_content);
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "<div class=\"cdmFooter\">";
                 $tag_cache = $line["tag_cache"];
                 $tags_str = format_tags_string(get_article_tags($this->link, $id, $_SESSION["uid"], $tag_cache), $id);
                 $reply['content'] .= "<img src='" . theme_image($this->link, 'images/tag.png') . "' alt='Tags' title='Tags'>\r\n\t\t\t\t\t\t<span id=\"ATSTR-{$id}\">{$tags_str}</span>\r\n\t\t\t\t\t\t<a title=\"" . __('Edit tags for this article') . "\"\r\n\t\t\t\t\t\thref=\"#\" onclick=\"editArticleTags({$id}, {$feed_id}, true)\">(+)</a>";
                 $num_comments = $line["num_comments"];
                 $entry_comments = "";
                 if ($num_comments > 0) {
                     if ($line["comments"]) {
                         $comments_url = $line["comments"];
                     } else {
                         $comments_url = $line["link"];
                     }
                     $entry_comments = "<a target='_blank' href=\"{$comments_url}\">{$num_comments} comments</a>";
                 } else {
                     if ($line["comments"] && $line["link"] != $line["comments"]) {
                         $entry_comments = "<a target='_blank' href=\"" . $line["comments"] . "\">comments</a>";
                     }
                 }
                 if ($entry_comments) {
                     $reply['content'] .= "&nbsp;({$entry_comments})";
                 }
                 $reply['content'] .= "<div style=\"float : right\">";
                 $reply['content'] .= "<img src=\"images/art-zoom.png\"\r\n\t\t\t\t\t\tonclick=\"zoomToArticle(event, {$id})\"\r\n\t\t\t\t\t\tstyle=\"cursor : pointer\"\r\n\t\t\t\t\t\talt='Zoom'\r\n\t\t\t\t\t\ttitle='" . __('Open article in new tab') . "'>";
                 //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
                 foreach ($button_plugins as $p) {
                     $reply['content'] .= $p->render($id, $line);
                 }
                 $reply['content'] .= "<img src=\"images/digest_checkbox.png\"\r\n\t\t\t\t\t\tstyle=\"cursor : pointer\" style=\"cursor : pointer\"\r\n\t\t\t\t\t\tonclick=\"dismissArticle({$id})\"\r\n\t\t\t\t\t\ttitle='" . __('Close article') . "'>";
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "</div>";
             }
             ++$lnum;
         }
         if ($_REQUEST["debug"]) {
             $timing_info = print_checkpoint("PE", $timing_info);
         }
     } else {
         $message = "";
         switch ($view_mode) {
             case "unread":
                 $message = __("No unread articles found to display.");
                 break;
             case "updated":
                 $message = __("No updated articles found to display.");
                 break;
             case "marked":
                 $message = __("No starred articles found to display.");
                 break;
             default:
                 if ($feed < -10) {
                     $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
                 } else {
                     $message = __("No articles found to display.");
                 }
         }
         if (!$offset && $message) {
             $reply['content'] .= "<div class='whiteBox'>{$message}";
             $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
             $result = db_query($this->link, "SELECT " . SUBSTRING_FOR_DATE . "(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds\r\n\t\t\t\t\tWHERE owner_uid = " . $_SESSION['uid']);
             $last_updated = db_fetch_result($result, 0, "last_updated");
             $last_updated = make_local_datetime($this->link, $last_updated, false);
             $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
             $result = db_query($this->link, "SELECT COUNT(id) AS num_errors\r\n\t\t\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) {
                 $reply['content'] .= "<br/>";
                 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">" . __('Some feeds have update errors (click for details)') . "</a>";
             }
             $reply['content'] .= "</span></p></div>";
         }
     }
     if ($_REQUEST["debug"]) {
         $timing_info = print_checkpoint("H2", $timing_info);
     }
     return array($topmost_article_ids, $headlines_count, $feed, $disable_cache, $vgroup_last_feed, $reply);
 }
 private function generate_syndicated_feed($owner_uid, $feed, $is_cat, $limit, $offset, $search, $search_mode, $match_on, $view_mode = false, $format = 'atom')
 {
     require_once "lib/MiniTemplator.class.php";
     $note_style = "background-color : #fff7d5;\n\t\t\tborder-width : 1px; " . "padding : 5px; border-style : dashed; border-color : #e7d796;" . "margin-bottom : 1em; color : #9a8c59;";
     if (!$limit) {
         $limit = 100;
     }
     if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
         $date_sort_field = "updated";
     } else {
         $date_sort_field = "date_entered";
     }
     if ($feed == -2) {
         $date_sort_field = "last_read";
     }
     $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $is_cat, $search, $search_mode, $match_on, "{$date_sort_field} DESC", $offset, $owner_uid, false, 0, false, true);
     $result = $qfh_ret[0];
     $feed_title = htmlspecialchars($qfh_ret[1]);
     $feed_site_url = $qfh_ret[2];
     $last_error = $qfh_ret[3];
     $feed_self_url = get_self_url_prefix() . "/public.php?op=rss&id=-2&key=" . get_feed_access_key($this->link, -2, false, $owner_uid);
     if (!$feed_site_url) {
         $feed_site_url = get_self_url_prefix();
     }
     if ($format == 'atom') {
         $tpl = new MiniTemplator();
         $tpl->readTemplateFromFile("templates/generated_feed.txt");
         $tpl->setVariable('FEED_TITLE', $feed_title, true);
         $tpl->setVariable('VERSION', VERSION, true);
         $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
         if (PUBSUBHUBBUB_HUB && $feed == -2) {
             $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB), true);
             $tpl->addBlock('feed_hub');
         }
         $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
         while ($line = db_fetch_assoc($result)) {
             $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
             $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
             $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
             $tpl->setVariable('ARTICLE_EXCERPT', truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
             $content = sanitize($this->link, $line["content_preview"], false, $owner_uid);
             if ($line['note']) {
                 $content = "<div style=\"{$note_style}\">Article note: " . $line['note'] . "</div>" . $content;
             }
             $tpl->setVariable('ARTICLE_CONTENT', $content, true);
             $tpl->setVariable('ARTICLE_UPDATED_ATOM', date('c', strtotime($line["updated"])), true);
             $tpl->setVariable('ARTICLE_UPDATED_RFC822', date(DATE_RFC822, strtotime($line["updated"])), true);
             $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
             $tags = get_article_tags($this->link, $line["id"], $owner_uid);
             foreach ($tags as $tag) {
                 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
                 $tpl->addBlock('category');
             }
             $enclosures = get_article_enclosures($this->link, $line["id"]);
             foreach ($enclosures as $e) {
                 $type = htmlspecialchars($e['content_type']);
                 $url = htmlspecialchars($e['content_url']);
                 $length = $e['duration'];
                 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
                 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
                 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
                 $tpl->addBlock('enclosure');
             }
             $tpl->addBlock('entry');
         }
         $tmp = "";
         $tpl->addBlock('feed');
         $tpl->generateOutputToString($tmp);
         if (@(!$_REQUEST["noxml"])) {
             header("Content-Type: text/xml; charset=utf-8");
         } else {
             header("Content-Type: text/plain; charset=utf-8");
         }
         print $tmp;
     } else {
         if ($format == 'json') {
             $feed = array();
             $feed['title'] = $feed_title;
             $feed['version'] = VERSION;
             $feed['feed_url'] = $feed_self_url;
             if (PUBSUBHUBBUB_HUB && $feed == -2) {
                 $feed['hub_url'] = PUBSUBHUBBUB_HUB;
             }
             $feed['self_url'] = get_self_url_prefix();
             $feed['articles'] = array();
             while ($line = db_fetch_assoc($result)) {
                 $article = array();
                 $article['id'] = $line['link'];
                 $article['link'] = $line['link'];
                 $article['title'] = $line['title'];
                 $article['excerpt'] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
                 $article['content'] = sanitize($this->link, $line["content_preview"], false, $owner_uid);
                 $article['updated'] = date('c', strtotime($line["updated"]));
                 if ($line['note']) {
                     $article['note'] = $line['note'];
                 }
                 if ($article['author']) {
                     $article['author'] = $line['author'];
                 }
                 $tags = get_article_tags($this->link, $line["id"], $owner_uid);
                 if (count($tags) > 0) {
                     $article['tags'] = array();
                     foreach ($tags as $tag) {
                         array_push($article['tags'], $tag);
                     }
                 }
                 $enclosures = get_article_enclosures($this->link, $line["id"]);
                 if (count($enclosures) > 0) {
                     $article['enclosures'] = array();
                     foreach ($enclosures as $e) {
                         $type = $e['content_type'];
                         $url = $e['content_url'];
                         $length = $e['duration'];
                         array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
                     }
                 }
                 array_push($feed['articles'], $article);
             }
             header("Content-Type: text/json; charset=utf-8");
             print json_encode($feed);
         } else {
             header("Content-Type: text/plain; charset=utf-8");
             print json_encode(array("error" => array("message" => "Unknown format")));
         }
     }
 }
Exemplo n.º 18
0
 function editArticleTags()
 {
     print __("Tags for this article (separated by commas):") . "<br>";
     $tags = get_article_tags($this->link, $this->param);
     $tags_str = join(", ", $tags);
     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"{$this->param}\">";
     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setArticleTags\">";
     print "<table width='100%'><tr><td>";
     print "<textarea dojoType=\"dijit.form.SimpleTextarea\" rows='4'\n\t\t\tstyle='font-size : 12px; width : 100%' id=\"tags_str\"\n\t\t\tname='tags_str'>{$tags_str}</textarea>\n\t\t<div class=\"autocomplete\" id=\"tags_choices\"\n\t\t\t\tstyle=\"display:none\"></div>";
     print "</td></tr></table>";
     print "<div class='dlgButtons'>";
     print "<button dojoType=\"dijit.form.Button\"\n\t\t\tonclick=\"dijit.byId('editTagsDlg').execute()\">" . __('Save') . "</button> ";
     print "<button dojoType=\"dijit.form.Button\"\n\t\t\tonclick=\"dijit.byId('editTagsDlg').hide()\">" . __('Cancel') . "</button>";
     print "</div>";
 }
Exemplo n.º 19
0
 function rescoreAll()
 {
     $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
     while ($feed_line = $this->dbh->fetch_assoc($result)) {
         $id = $feed_line["id"];
         $filters = load_filters($id, $_SESSION["uid"], 6);
         $tmp_result = $this->dbh->query("SELECT\n\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\tttrss_user_entries, ttrss_entries\n\t\t\t\t\tWHERE ref_id = id AND feed_id = '{$id}' AND\n\t\t\t\t\t\towner_uid = " . $_SESSION['uid'] . "\n\t\t\t\t\t");
         $scores = array();
         while ($line = $this->dbh->fetch_assoc($tmp_result)) {
             $tags = get_article_tags($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) {
                 $this->dbh->query("UPDATE ttrss_user_entries SET score = '{$s}',\n\t\t\t\t\t\tmarked = true WHERE\n\t\t\t\t\t\tref_id IN (" . join(',', $scores[$s]) . ")");
             } else {
                 $this->dbh->query("UPDATE ttrss_user_entries SET score = '{$s}' WHERE\n\t\t\t\t\t\tref_id IN (" . join(',', $scores[$s]) . ")");
             }
         }
     }
     print __("All done.");
 }
Exemplo n.º 20
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
}