]> git.wh0rd.org - tt-rss.git/blobdiff - classes/handler/public.php
remove pubsubhubbub: dead
[tt-rss.git] / classes / handler / public.php
index 1bf0887011d0248ce8fcaa4da0334b0cdde1bf22..403e20ca588bc3d4220500c7b53383dfd9b4b8a0 100644 (file)
@@ -37,16 +37,6 @@ class Handler_Public extends Handler {
                        break;
                }
 
-               /*$qfh_ret = queryFeedHeadlines($feed,
-                       1, $view_mode, $is_cat, $search, false,
-                       $date_sort_field, $offset, $owner_uid,
-                       false, 0, true, true, false, false, $start_ts);*/
-
-               //function queryFeedHeadlines($feed,
-               // $limit, $view_mode, $cat_view, $search, $search_mode,
-               // $override_order = false, $offset = 0, $owner_uid = 0,
-               // $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false, $override_strategy = false, $override_vfeed = false, $start_ts = false, $check_top_id = false) {
-
                $params = array(
                        "owner_uid" => $owner_uid,
                        "feed" => $feed,
@@ -61,7 +51,7 @@ class Handler_Public extends Handler {
                        "start_ts" => $start_ts
                );
 
-               $qfh_ret = queryFeedHeadlines($params);
+               $qfh_ret = Feeds::queryFeedHeadlines($params);
 
                $result = $qfh_ret[0];
 
@@ -79,11 +69,6 @@ class Handler_Public extends Handler {
                        header("Last-Modified: $last_modified", true);
                }
 
-               /*$qfh_ret = queryFeedHeadlines($feed,
-                       $limit, $view_mode, $is_cat, $search, false,
-                       $date_sort_field, $offset, $owner_uid,
-                       false, 0, true, true, false, false, $start_ts);*/
-
                $params = array(
                        "owner_uid" => $owner_uid,
                        "feed" => $feed,
@@ -98,7 +83,7 @@ class Handler_Public extends Handler {
                        "start_ts" => $start_ts
                );
 
-               $qfh_ret = queryFeedHeadlines($params);
+               $qfh_ret = Feeds::queryFeedHeadlines($params);
 
                $result = $qfh_ret[0];
                $feed_title = htmlspecialchars($qfh_ret[1]);
@@ -120,19 +105,19 @@ class Handler_Public extends Handler {
                        $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 = $this->dbh->fetch_assoc($result)) {
-                               $line["content_preview"] = truncate_string(strip_tags($line["content"]), 100, '...');
+
+                               $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content"]), 100, '...'));
 
                                foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
                                        $line = $p->hook_query_headlines($line);
                                }
 
+                               foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) {
+                                       $line = $p->hook_article_export_feed($line, $feed, $is_cat);
+                               }
+
                                $tpl->setVariable('ARTICLE_ID',
                                        htmlspecialchars($orig_guid ? $line['link'] :
                                                        $this->make_article_tag_uri($line['id'], $line['date_entered'])), true);
@@ -141,7 +126,7 @@ class Handler_Public extends Handler {
                                $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true);
 
                                $content = sanitize($line["content"], false, $owner_uid,
-                                       $feed_site_url);
+                                       $feed_site_url, false, $line["id"]);
 
                                if ($line['note']) {
                                        $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
@@ -161,14 +146,14 @@ class Handler_Public extends Handler {
                                $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ? $line["site_url"] : get_self_url_prefix()), true);
                                $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ? $line['feed_title'] : $feed_title), true);
 
-                               $tags = get_article_tags($line["id"], $owner_uid);
+                               $tags = Article::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"]);
+                               $enclosures = Article::get_article_enclosures($line["id"]);
 
                                foreach ($enclosures as $e) {
                                        $type = htmlspecialchars($e['content_type']);
@@ -205,32 +190,35 @@ class Handler_Public extends Handler {
                        $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, '...');
+
+                               $line["content_preview"] = sanitize(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);
                                }
+
+                               foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) {
+                                       $line = $p->hook_article_export_feed($line, $feed, $is_cat);
+                               }
+
                                $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['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]);
                                $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);
+                               $tags = Article::get_article_tags($line["id"], $owner_uid);
 
                                if (count($tags) > 0) {
                                        $article['tags'] = array();
@@ -240,7 +228,7 @@ class Handler_Public extends Handler {
                                        }
                                }
 
-                               $enclosures = get_article_enclosures($line["id"]);
+                               $enclosures = Article::get_article_enclosures($line["id"]);
 
                                if (count($enclosures) > 0) {
                                        $article['enclosures'] = array();
@@ -275,11 +263,11 @@ class Handler_Public extends Handler {
                if ($this->dbh->num_rows($result) == 1) {
                        $uid = $this->dbh->fetch_result($result, 0, "id");
 
-                       print getGlobalUnread($uid);
+                       print Feeds::getGlobalUnread($uid);
 
                        if ($fresh) {
                                print ";";
-                               print getFeedArticles(-3, false, true, $uid);
+                               print Feeds::getFeedArticles(-3, false, true, $uid);
                        }
 
                } else {
@@ -308,71 +296,6 @@ class Handler_Public extends Handler {
                print "</select>";
        }
 
-       function pubsub() {
-               $mode = $this->dbh->escape_string($_REQUEST['hub_mode']);
-               if (!$mode) $mode = $this->dbh->escape_string($_REQUEST['hub.mode']);
-
-               $feed_id = (int) $this->dbh->escape_string($_REQUEST['id']);
-               $feed_url = $this->dbh->escape_string($_REQUEST['hub_topic']);
-
-               if (!$feed_url) $feed_url = $this->dbh->escape_string($_REQUEST['hub.topic']);
-
-               if (!PUBSUBHUBBUB_ENABLED) {
-                       header('HTTP/1.0 404 Not Found');
-                       echo "404 Not found (Disabled by server)";
-                       return;
-               }
-
-               // TODO: implement hub_verifytoken checking
-               // TODO: store requested rel=self or whatever for verification
-               // (may be different from stored feed url) e.g. http://url/ or http://url
-
-               $result = $this->dbh->query("SELECT feed_url FROM ttrss_feeds
-                       WHERE id = '$feed_id'");
-
-               if ($this->dbh->num_rows($result) != 0) {
-
-                       $check_feed_url = $this->dbh->fetch_result($result, 0, "feed_url");
-
-                       // ignore url checking for the time being
-                       if ($check_feed_url && (true || $check_feed_url == $feed_url || !$feed_url)) {
-                               if ($mode == "subscribe") {
-
-                                       $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 2
-                                               WHERE id = '$feed_id'");
-
-                                       print $_REQUEST['hub_challenge'];
-                                       return;
-
-                               } else if ($mode == "unsubscribe") {
-
-                                       $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 0
-                                               WHERE id = '$feed_id'");
-
-                                       print $_REQUEST['hub_challenge'];
-                                       return;
-
-                               } else if (!$mode) {
-
-                                       // Received update ping, schedule feed update.
-                                       //update_rss_feed($feed_id, true, true);
-
-                                       $this->dbh->query("UPDATE ttrss_feeds SET
-                                               last_update_started = '1970-01-01',
-                                               last_updated = '1970-01-01' WHERE id = '$feed_id'");
-
-                               }
-                       } else {
-                               header('HTTP/1.0 404 Not Found');
-                               echo "404 Not found (URL check failed)";
-                       }
-               } else {
-                       header('HTTP/1.0 404 Not Found');
-                       echo "404 Not found (Feed not found)";
-               }
-
-       }
-
        function logout() {
                logout_user();
                header("Location: index.php");
@@ -390,7 +313,7 @@ class Handler_Public extends Handler {
                        $id = $this->dbh->fetch_result($result, 0, "ref_id");
                        $owner_uid = $this->dbh->fetch_result($result, 0, "owner_uid");
 
-                       $article = format_article($id, false, true, $owner_uid);
+                       $article = Article::format_article($id, false, true, $owner_uid);
 
                        print_r($article['content']);
 
@@ -659,7 +582,7 @@ class Handler_Public extends Handler {
                                        alt=\"Tiny Tiny RSS\"/>
                                        <h1>".__("Subscribe to feed...")."</h1><div class='content'>";
 
-                       $rc = subscribe_to_feed($feed_url);
+                       $rc = Feeds::subscribe_to_feed($feed_url);
 
                        switch ($rc['code']) {
                        case 0:
@@ -968,7 +891,7 @@ class Handler_Public extends Handler {
                                                for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) {
                                                        print "<li>Performing update up to version $i...";
 
-                                                       $result = $updater->performUpdateTo($i);
+                                                       $result = $updater->performUpdateTo($i, true);
 
                                                        if (!$result) {
                                                                print "<span class='err'>FAILED!</span></li></ul>";
@@ -978,7 +901,7 @@ class Handler_Public extends Handler {
                                                                <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
                                                                </form>";
 
-                                                               break;
+                                                               return;
                                                        } else {
                                                                print "<span class='ok'>OK!</span></li>";
                                                        }
@@ -1004,10 +927,10 @@ class Handler_Public extends Handler {
 
                                                print "<h2>Database update required</h2>";
 
-                                               print "<h3>";
-                                               printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.",
-                                                       $updater->getSchemaVersion(), SCHEMA_VERSION);
-                                               print "</h3>";
+                                               print_notice("<h4>".
+                                               sprintf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.",
+                                                       $updater->getSchemaVersion(), SCHEMA_VERSION).
+                                               "</h4>");
 
                                                print_warning("Please backup your database before proceeding.");
 
@@ -1034,14 +957,20 @@ class Handler_Public extends Handler {
                <?php
        }
 
-       function cached_image() {
+       function cached_url() {
                @$hash = basename($_GET['hash']);
 
+               // we don't need an extension to find the file, hash is a complete URL
+               $hash = preg_replace("/\.[^\.]*$/", "", $hash);
+
                if ($hash) {
 
-                       $filename = CACHE_DIR . '/images/' . $hash . '.png';
+                       $filename = CACHE_DIR . '/images/' . $hash;
 
                        if (file_exists($filename)) {
+                               header("Content-Disposition: inline; filename=\"$hash\"");
+                               $mimetype = mime_content_type($filename);
+
                                /* See if we can use X-Sendfile */
                                $xsendfile = false;
                                if (function_exists('apache_get_modules') &&
@@ -1050,10 +979,10 @@ class Handler_Public extends Handler {
 
                                if ($xsendfile) {
                                        header("X-Sendfile: $filename");
-                                       header("Content-type: application/octet-stream");
-                                       header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
+                                       header("Content-type: $mimetype");
+                                       header('Content-Disposition: inline; filename="' . basename($filename) . '"');
                                } else {
-                                       header("Content-type: image/png");
+                                       header("Content-type: $mimetype");
                                        $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)). " GMT";
                                        header("Last-Modified: $stamp", true);
                                        readfile($filename);
@@ -1071,5 +1000,37 @@ class Handler_Public extends Handler {
 
                return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST) . ",$timestamp:/$id";
        }
+
+       // this should be used very carefully because this endpoint is exposed to unauthenticated users
+       // plugin data is not loaded because there's no user context and owner_uid/session may or may not be available
+       // in general, don't do anything user-related in here and do not modify $_SESSION
+       public function pluginhandler() {
+               $host = new PluginHost();
+
+               $plugin = basename($_REQUEST["plugin"]);
+               $method = $_REQUEST["pmethod"];
+
+               $host->load($plugin, PluginHost::KIND_USER, 0);
+               $host->load_data();
+
+               $pclass = $host->get_plugin($plugin);
+
+               if ($pclass) {
+                       if (method_exists($pclass, $method)) {
+                               if ($pclass->is_public_method($method)) {
+                                       $pclass->$method();
+                               } else {
+                                       header("Content-Type: text/json");
+                                       print error_json(6);
+                               }
+                       } else {
+                               header("Content-Type: text/json");
+                               print error_json(13);
+                       }
+               } else {
+                       header("Content-Type: text/json");
+                       print error_json(14);
+               }
+       }
 }
-?>
+?>
\ No newline at end of file