]> git.wh0rd.org - tt-rss.git/blobdiff - classes/handler/public.php
generate_syndicated_feed: add support for virtual feeds provided by plugins
[tt-rss.git] / classes / handler / public.php
old mode 100644 (file)
new mode 100755 (executable)
index 4ae65e4..dbed3fe
@@ -15,14 +15,11 @@ class Handler_Public extends Handler {
                if (!$limit) $limit = 60;
 
                $date_sort_field = "date_entered DESC, updated DESC";
-               $date_check_field = "date_entered";
 
                if ($feed == -2 && !$is_cat) {
                        $date_sort_field = "last_published DESC";
-                       $date_check_field = "last_published";
                } else if ($feed == -1 && !$is_cat) {
                        $date_sort_field = "last_marked DESC";
-                       $date_check_field = "last_marked";
                }
 
                switch ($order) {
@@ -40,7 +37,7 @@ class Handler_Public extends Handler {
                $params = array(
                        "owner_uid" => $owner_uid,
                        "feed" => $feed,
-                       "limit" => 1,
+                       "limit" => $limit,
                        "view_mode" => $view_mode,
                        "cat_view" => $is_cat,
                        "search" => $search,
@@ -51,25 +48,26 @@ class Handler_Public extends Handler {
                        "start_ts" => $start_ts
                );
 
-               $qfh_ret = Feeds::queryFeedHeadlines($params);
+               if (!$is_cat && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) {
 
-               $result = $qfh_ret[0];
+                       $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
 
-               $params = array(
-                       "owner_uid" => $owner_uid,
-                       "feed" => $feed,
-                       "limit" => $limit,
-                       "view_mode" => $view_mode,
-                       "cat_view" => $is_cat,
-                       "search" => $search,
-                       "override_order" => $date_sort_field,
-                       "include_children" => true,
-                       "ignore_vfeed_group" => true,
-                       "offset" => $offset,
-                       "start_ts" => $start_ts
-               );
+                       $tmppluginhost = new PluginHost();
+                       $tmppluginhost->load(PLUGINS, PluginHost::KIND_ALL);
+                       $tmppluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
+                       $tmppluginhost->load_data();
 
-               $qfh_ret = Feeds::queryFeedHeadlines($params);
+                       $handler = $tmppluginhost->get_feed_handler(
+                               PluginHost::feed_to_pfeed_id($feed));
+
+                       if ($handler) {
+                               $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed),
+                                       $options);
+                       }
+
+               } else {
+                       $qfh_ret = Feeds::queryFeedHeadlines($params);
+               }
 
                $result = $qfh_ret[0];
                $feed_title = htmlspecialchars($qfh_ret[1]);
@@ -161,7 +159,7 @@ class Handler_Public extends Handler {
                        $tpl->addBlock('feed');
                        $tpl->generateOutputToString($tmp);
 
-                       if (@!$_REQUEST["noxml"]) {
+                       if (@!clean($_REQUEST["noxml"])) {
                                header("Content-Type: text/xml; charset=utf-8");
                        } else {
                                header("Content-Type: text/plain; charset=utf-8");
@@ -241,8 +239,8 @@ class Handler_Public extends Handler {
        }
 
        function getUnread() {
-               $login = $_REQUEST["login"];
-               $fresh = $_REQUEST["fresh"] == "1";
+               $login = clean($_REQUEST["login"]);
+               $fresh = clean($_REQUEST["fresh"]) == "1";
 
                $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?");
                $sth->execute([$login]);
@@ -263,7 +261,7 @@ class Handler_Public extends Handler {
        }
 
        function getProfiles() {
-               $login = $_REQUEST["login"];
+               $login = clean($_REQUEST["login"]);
 
                $sth = $this->pdo->prepare("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users
                        WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = ? ORDER BY title");
@@ -289,7 +287,7 @@ class Handler_Public extends Handler {
        }
 
        function share() {
-               $uuid = $_REQUEST["key"];
+               $uuid = clean($_REQUEST["key"]);
 
                $sth = $this->pdo->prepare("SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
                        uuid = ?");
@@ -312,19 +310,19 @@ class Handler_Public extends Handler {
        }
 
        function rss() {
-               $feed = $_REQUEST["id"];
-               $key = $_REQUEST["key"];
-               $is_cat = sql_bool_to_bool($_REQUEST["is_cat"]);
-               $limit = (int)$_REQUEST["limit"];
-               $offset = (int)$_REQUEST["offset"];
+               $feed = clean($_REQUEST["id"]);
+               $key = clean($_REQUEST["key"]);
+               $is_cat = clean($_REQUEST["is_cat"]);
+               $limit = (int)clean($_REQUEST["limit"]);
+               $offset = (int)clean($_REQUEST["offset"]);
 
-               $search = $_REQUEST["q"];
-               $view_mode = $_REQUEST["view-mode"];
-               $order = $_REQUEST["order"];
-               $start_ts = $_REQUEST["ts"];
+               $search = clean($_REQUEST["q"]);
+               $view_mode = clean($_REQUEST["view-mode"]);
+               $order = clean($_REQUEST["order"]);
+               $start_ts = clean($_REQUEST["ts"]);
 
-               $format = $_REQUEST['format'];
-               $orig_guid = sql_bool_to_bool($_REQUEST["orig_guid"]);
+               $format = clean($_REQUEST['format']);
+               $orig_guid = clean($_REQUEST["orig_guid"]);
 
                if (!$format) $format = 'atom';
 
@@ -360,7 +358,7 @@ class Handler_Public extends Handler {
        }
 
        function globalUpdateFeeds() {
-               RPC::updaterandomfeed_real($this->dbh);
+               RPC::updaterandomfeed_real();
 
                PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false);
        }
@@ -375,23 +373,22 @@ class Handler_Public extends Handler {
                <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
                <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
 
-               echo stylesheet_tag("css/utility.css");
                echo stylesheet_tag("css/default.css");
                echo javascript_tag("lib/prototype.js");
                echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls");
                print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
-                       </head><body id='sharepopup'>";
+                       </head><body id='sharepopup' class='ttrss_utility'>";
 
-               $action = $_REQUEST["action"];
+               $action = clean($_REQUEST["action"]);
 
                if ($_SESSION["uid"]) {
 
                        if ($action == 'share') {
 
-                               $title = strip_tags($_REQUEST["title"]);
-                               $url = strip_tags($_REQUEST["url"]);
-                               $content = strip_tags($_REQUEST["content"]);
-                               $labels = strip_tags($_REQUEST["labels"]);
+                               $title = strip_tags(clean($_REQUEST["title"]));
+                               $url = strip_tags(clean($_REQUEST["url"]));
+                               $content = strip_tags(clean($_REQUEST["content"]));
+                               $labels = strip_tags(clean($_REQUEST["labels"]));
 
                                Article::create_published_article($title, $url, $content, $labels,
                                        $_SESSION["uid"]);
@@ -401,8 +398,8 @@ class Handler_Public extends Handler {
                                print "</script>";
 
                        } else {
-                               $title = htmlspecialchars($_REQUEST["title"]);
-                               $url = htmlspecialchars($_REQUEST["url"]);
+                               $title = htmlspecialchars(clean($_REQUEST["title"]));
+                               $url = htmlspecialchars(clean($_REQUEST["url"]));
 
                                ?>
 
@@ -489,9 +486,9 @@ class Handler_Public extends Handler {
        function login() {
                if (!SINGLE_USER_MODE) {
 
-                       $login = $_POST["login"];
-                       $password = $_POST["password"];
-                       $remember_me = $_POST["remember_me"];
+                       $login = clean($_POST["login"]);
+                       $password = clean($_POST["password"]);
+                       $remember_me = clean($_POST["remember_me"]);
 
                        if ($remember_me) {
                                session_set_cookie_params(SESSION_COOKIE_LIFETIME);
@@ -499,8 +496,6 @@ class Handler_Public extends Handler {
                                session_set_cookie_params(0);
                        }
 
-                       @session_start();
-
                        if (authenticate_user($login, $password)) {
                                $_POST["password"] = "";
 
@@ -509,11 +504,11 @@ class Handler_Public extends Handler {
                                }
 
                                $_SESSION["ref_schema_version"] = get_schema_version(true);
-                               $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
+                               $_SESSION["bw_limit"] = !!clean($_POST["bw_limit"]);
 
-                               if ($_POST["profile"]) {
+                               if (clean($_POST["profile"])) {
 
-                                       $profile = $_POST["profile"];
+                                       $profile = clean($_POST["profile"]);
 
                                        $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles
                                                WHERE id = ? AND owner_uid = ?");
@@ -524,12 +519,18 @@ class Handler_Public extends Handler {
                                        }
                                }
                        } else {
-                               $_SESSION["login_error_msg"] = __("Incorrect username or password");
+
+                               // start an empty session to deliver login error message
+                               @session_start();
+
+                               if (!isset($_SESSION["login_error_msg"]))
+                                       $_SESSION["login_error_msg"] = __("Incorrect username or password");
+
                                user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING);
                        }
 
-                       if ($_REQUEST['return']) {
-                               header("Location: " . $_REQUEST['return']);
+                       if (clean($_REQUEST['return'])) {
+                               header("Location: " . clean($_REQUEST['return']));
                        } else {
                                header("Location: " . get_self_url_prefix());
                        }
@@ -539,7 +540,7 @@ class Handler_Public extends Handler {
        /* function subtest() {
                header("Content-type: text/plain; charset=utf-8");
 
-               $url = $_REQUEST["url"];
+               $url = clean($_REQUEST["url"]);
 
                print "$url\n\n";
 
@@ -555,19 +556,20 @@ class Handler_Public extends Handler {
 
                if ($_SESSION["uid"]) {
 
-                       $feed_url = trim($_REQUEST["feed_url"]);
+                       $feed_url = trim(clean($_REQUEST["feed_url"]));
 
                        header('Content-Type: text/html; charset=utf-8');
                        print "<html>
                                <head>
-                                       <title>Tiny Tiny RSS</title>
-                                       <link rel=\"stylesheet\" type=\"text/css\" href=\"css/utility.css\">
-                                       <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
-                                       <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
-                                       <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">
+                                       <title>Tiny Tiny RSS</title>";
+                       print stylesheet_tag("css/default.css");
+
+            print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
+                <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
+                <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">
 
                                </head>
-                               <body>
+                               <body class='claro ttrss_utility'>
                                <img class=\"floatingLogo\" src=\"images/logo_small.png\"
                                        alt=\"Tiny Tiny RSS\"/>
                                        <h1>".__("Subscribe to feed...")."</h1><div class='content'>";
@@ -660,27 +662,28 @@ class Handler_Public extends Handler {
        function forgotpass() {
                startup_gettext();
 
-               @$hash = $_REQUEST["hash"];
+               @$hash = clean($_REQUEST["hash"]);
 
                header('Content-Type: text/html; charset=utf-8');
                print "<html><head><title>Tiny Tiny RSS</title>
                <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
                <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
 
-               echo stylesheet_tag("css/utility.css");
+               echo stylesheet_tag("lib/dijit/themes/claro/claro.css");
+               echo stylesheet_tag("css/default.css");
                echo javascript_tag("lib/prototype.js");
 
                print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
-                       </head><body id='forgotpass'>";
+                       </head><body class='claro ttrss_utility'>";
 
                print '<div class="floatingLogo"><img src="images/logo_small.png"></div>';
                print "<h1>".__("Password recovery")."</h1>";
                print "<div class='content'>";
 
-               @$method = $_POST['method'];
+               @$method = clean($_POST['method']);
 
                if ($hash) {
-                       $login = $_REQUEST["login"];
+                       $login = clean($_REQUEST["login"]);
 
                        if ($login) {
                                $sth = $this->pdo->prepare("SELECT id, resetpass_token FROM ttrss_users
@@ -727,17 +730,17 @@ class Handler_Public extends Handler {
 
                        print "<fieldset>";
                        print "<label>".__("Login:")."</label>";
-                       print "<input type='text' name='login' value='' required>";
+                       print "<input class='input input-text' type='text' name='login' value='' required>";
                        print "</fieldset>";
 
                        print "<fieldset>";
                        print "<label>".__("Email:")."</label>";
-                       print "<input type='email' name='email' value='' required>";
+                       print "<input class='input input-text' type='email' name='email' value='' required>";
                        print "</fieldset>";
 
                        print "<fieldset>";
                        print "<label>".__("How much is two plus two:")."</label>";
-                       print "<input type='text' name='test' value='' required>";
+                       print "<input class='input input-text' type='text' name='test' value='' required>";
                        print "</fieldset>";
 
                        print "<p/>";
@@ -746,9 +749,9 @@ class Handler_Public extends Handler {
                        print "</form>";
                } else if ($method == 'do') {
 
-                       $login = $_POST["login"];
-                       $email = $_POST["email"];
-                       $test = $_POST["test"];
+                       $login = clean($_POST["login"]);
+                       $email = clean($_POST["email"]);
+                       $test = clean($_POST["test"]);
 
                        if (($test != 4 && $test != 'four') || !$email || !$login) {
                                print_error(__('Some of the required form parameters are missing or incorrect.'));
@@ -851,7 +854,7 @@ class Handler_Public extends Handler {
                        <head>
                        <title>Database Updater</title>
                        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
-                       <link rel="stylesheet" type="text/css" href="css/utility.css"/>
+                       <link rel="stylesheet" type="text/css" href="css/default.css"/>
                        <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
                        <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">
                        </head>
@@ -859,7 +862,7 @@ class Handler_Public extends Handler {
                                span.ok { color : #009000; font-weight : bold; }
                                span.err { color : #ff0000; font-weight : bold; }
                        </style>
-               <body>
+               <body class="claro ttrss_utility">
                        <script type='text/javascript'>
                        function confirmOP() {
                                return confirm("Update the database?");
@@ -873,8 +876,8 @@ class Handler_Public extends Handler {
                        <div class="content">
 
                        <?php
-                               @$op = $_REQUEST["subop"];
-                               $updater = new DbUpdater(Db::get(), DB_TYPE, SCHEMA_VERSION);
+                               @$op = clean($_REQUEST["subop"]);
+                               $updater = new DbUpdater(Db::pdo(), DB_TYPE, SCHEMA_VERSION);
 
                                if ($op == "performupdate") {
                                        if ($updater->isUpdateRequired()) {
@@ -955,17 +958,17 @@ class Handler_Public extends Handler {
        }
 
        function cached_url() {
-               @$hash = basename($_GET['hash']);
+               @$req_filename = basename($_GET['hash']);
 
                // we don't need an extension to find the file, hash is a complete URL
-               $hash = preg_replace("/\.[^\.]*$/", "", $hash);
+               $hash = preg_replace("/\.[^\.]*$/", "", $req_filename);
 
                if ($hash) {
 
                        $filename = CACHE_DIR . '/images/' . $hash;
 
                        if (file_exists($filename)) {
-                               header("Content-Disposition: inline; filename=\"$hash\"");
+                               header("Content-Disposition: inline; filename=\"$req_filename\"");
 
                                send_local_file($filename);
 
@@ -989,8 +992,8 @@ class Handler_Public extends Handler {
        public function pluginhandler() {
                $host = new PluginHost();
 
-               $plugin = basename($_REQUEST["plugin"]);
-               $method = $_REQUEST["pmethod"];
+               $plugin = basename(clean($_REQUEST["plugin"]));
+               $method = clean($_REQUEST["pmethod"]);
 
                $host->load($plugin, PluginHost::KIND_USER, 0);
                $host->load_data();