]> git.wh0rd.org - tt-rss.git/blobdiff - classes/api.php
prevent frontend updating of feeds on view if open_basedir is set to prevent plugins...
[tt-rss.git] / classes / api.php
index 08c1846d2ad8353b9e8f16282fa6d62229cdeeea..9be04cff93cd0fb882b102ef2e38009587ec1dd2 100644 (file)
@@ -2,7 +2,7 @@
 
 class API extends Handler {
 
-       const API_LEVEL  = 12;
+       const API_LEVEL  = 13;
 
        const STATUS_OK  = 0;
        const STATUS_ERR = 1;
@@ -210,6 +210,8 @@ class API extends Handler {
 
                        $_SESSION['hasSandbox'] = $has_sandbox;
 
+                       $skip_first_id_check = false;
+
                        $override_order = false;
                        switch ($_REQUEST["order_by"]) {
                                case "title":
@@ -217,6 +219,7 @@ class API extends Handler {
                                        break;
                                case "date_reverse":
                                        $override_order = "score DESC, date_entered, updated";
+                                       $skip_first_id_check = true;
                                        break;
                                case "feed_dates":
                                        $override_order = "updated DESC";
@@ -230,7 +233,7 @@ class API extends Handler {
                        list($headlines, $headlines_header) = $this->api_get_headlines($feed_id, $limit, $offset,
                                $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $override_order,
                                $include_attachments, $since_id, $search,
-                               $include_nested, $sanitize_content, $force_update, $excerpt_length, $check_first_id);
+                               $include_nested, $sanitize_content, $force_update, $excerpt_length, $check_first_id, $skip_first_id_check);
 
                        if ($include_header) {
                                $this->wrap(self::STATUS_OK, array($headlines_header, $headlines));
@@ -322,13 +325,17 @@ class API extends Handler {
        function getArticle() {
 
                $article_id = join(",", array_filter(explode(",", $this->dbh->escape_string($_REQUEST["article_id"])), is_numeric));
+               $sanitize_content = !isset($_REQUEST["sanitize"]) ||
+                       sql_bool_to_bool($_REQUEST["sanitize"]);
 
                if ($article_id) {
 
                        $query = "SELECT id,title,link,content,feed_id,comments,int_id,
                                marked,unread,published,score,note,lang,
                                ".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
-                               author,(SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
+                               author,(SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title,
+                               (SELECT site_url FROM ttrss_feeds WHERE id = feed_id) AS site_url,
+                               (SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) AS hide_images
                                FROM ttrss_entries,ttrss_user_entries
                                WHERE   id IN ($article_id) AND ref_id = id AND owner_uid = " .
                                        $_SESSION["uid"] ;
@@ -354,7 +361,6 @@ class API extends Handler {
                                                "comments" => $line["comments"],
                                                "author" => $line["author"],
                                                "updated" => (int) strtotime($line["updated"]),
-                                               "content" => $line["content"],
                                                "feed_id" => $line["feed_id"],
                                                "attachments" => $attachments,
                                                "score" => (int)$line["score"],
@@ -363,6 +369,15 @@ class API extends Handler {
                                                "lang" => $line["lang"]
                                        );
 
+                                       if ($sanitize_content) {
+                                               $article["content"] = sanitize(
+                                                       $line["content"],
+                                                       sql_bool_to_bool($line['hide_images']),
+                                                       false, $line["site_url"], false, $line["id"]);
+                                       } else {
+                                               $article["content"] = $line["content"];
+                                       }
+
                                        foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) {
                                                $article = $p->hook_render_article_api(array("article" => $article));
                                        }
@@ -401,7 +416,9 @@ class API extends Handler {
 
                $feed_id = (int) $this->dbh->escape_string($_REQUEST["feed_id"]);
 
-               update_rss_feed($feed_id, true);
+               if (!ini_get("open_basedir")) {
+                       update_rss_feed($feed_id, true);
+               }
 
                $this->wrap(self::STATUS_OK, array("status" => "OK"));
        }
@@ -644,7 +661,7 @@ class API extends Handler {
                                $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order,
                                $include_attachments, $since_id,
                                $search = "", $include_nested = false, $sanitize_content = true,
-                               $force_update = false, $excerpt_length = 100, $check_first_id = false) {
+                               $force_update = false, $excerpt_length = 100, $check_first_id = false, $skip_first_id_check = false) {
 
                        if ($force_update && $feed_id > 0 && is_numeric($feed_id)) {
                                // Update the feed if required with some basic flood control
@@ -686,7 +703,8 @@ class API extends Handler {
                                "offset" => $offset,
                                "since_id" => $since_id,
                                "include_children" => $include_nested,
-                               "check_first_id" => $check_first_id
+                               "check_first_id" => $check_first_id,
+                               "skip_first_id_check" => $skip_first_id_check
                        );
 
                        $qfh_ret = queryFeedHeadlines($params);