]> git.wh0rd.org - tt-rss.git/blobdiff - classes/handler/public.php
generate_syndicated_feed: pass article id to sanitize()
[tt-rss.git] / classes / handler / public.php
index 34d57744151ea20cf8912284ecef46a5b013debb..1cc5686220ab4ee30dbfbf74975e6cf907364765 100644 (file)
@@ -2,7 +2,7 @@
 class Handler_Public extends Handler {
 
        private function generate_syndicated_feed($owner_uid, $feed, $is_cat,
-               $limit, $offset, $search, $search_mode,
+               $limit, $offset, $search,
                $view_mode = false, $format = 'atom', $order = false, $orig_guid = false, $start_ts = false) {
 
                require_once "lib/MiniTemplator.class.php";
@@ -37,12 +37,31 @@ class Handler_Public extends Handler {
                        break;
                }
 
-               //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) {
-
-               $qfh_ret = queryFeedHeadlines($feed,
-                       1, $view_mode, $is_cat, $search, $search_mode,
+               /*$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);
+                       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,
+                       "limit" => 1,
+                       "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
+               );
+
+               $qfh_ret = queryFeedHeadlines($params);
 
                $result = $qfh_ret[0];
 
@@ -60,11 +79,26 @@ class Handler_Public extends Handler {
                        header("Last-Modified: $last_modified", true);
                }
 
-               $qfh_ret = queryFeedHeadlines($feed,
-                       $limit, $view_mode, $is_cat, $search, $search_mode,
+               /*$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);
-
+                       false, 0, true, true, false, false, $start_ts);*/
+
+               $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
+               );
+
+               $qfh_ret = queryFeedHeadlines($params);
 
                $result = $qfh_ret[0];
                $feed_title = htmlspecialchars($qfh_ret[1]);
@@ -101,14 +135,13 @@ class Handler_Public extends Handler {
 
                                $tpl->setVariable('ARTICLE_ID',
                                        htmlspecialchars($orig_guid ? $line['link'] :
-                                               get_self_url_prefix() .
-                                                       "/public.php?url=" . urlencode($line['link'])), true);
+                                                       $this->make_article_tag_uri($line['id'], $line['date_entered'])), 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,
-                                       $feed_site_url);
+                                       $feed_site_url, false, $line["id"]);
 
                                if ($line['note']) {
                                        $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
@@ -125,7 +158,7 @@ class Handler_Public extends Handler {
 
                                $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
 
-                               $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url']), true);
+                               $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);
@@ -140,7 +173,7 @@ class Handler_Public extends Handler {
                                foreach ($enclosures as $e) {
                                        $type = htmlspecialchars($e['content_type']);
                                        $url = htmlspecialchars($e['content_url']);
-                                       $length = $e['duration'];
+                                       $length = $e['duration'] ? $e['duration'] : 1;
 
                                        $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
                                        $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
@@ -191,7 +224,7 @@ class Handler_Public extends Handler {
                                $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'];
@@ -375,7 +408,6 @@ class Handler_Public extends Handler {
                $offset = (int)$this->dbh->escape_string($_REQUEST["offset"]);
 
                $search = $this->dbh->escape_string($_REQUEST["q"]);
-               $search_mode = $this->dbh->escape_string($_REQUEST["smode"]);
                $view_mode = $this->dbh->escape_string($_REQUEST["view-mode"]);
                $order = $this->dbh->escape_string($_REQUEST["order"]);
                $start_ts = $this->dbh->escape_string($_REQUEST["ts"]);
@@ -401,7 +433,7 @@ class Handler_Public extends Handler {
 
                if ($owner_id) {
                        $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
-                               $offset, $search, $search_mode, $view_mode, $format, $order, $orig_guid, $start_ts);
+                               $offset, $search, $view_mode, $format, $order, $orig_guid, $start_ts);
                } else {
                        header('HTTP/1.1 403 Forbidden');
                }
@@ -500,7 +532,7 @@ class Handler_Public extends Handler {
                                        </div>
                                        <button type="submit"><?php echo __('Share') ?></button>
                                        <button onclick="return window.close()"><?php echo __('Cancel') ?></button>
-                                       </div>
+                                       </td>
 
                                </form>
                                </td></tr></table>
@@ -707,7 +739,7 @@ class Handler_Public extends Handler {
 
        function index() {
                header("Content-Type: text/plain");
-               print json_encode(array("error" => array("code" => 7)));
+               print error_json(13);
        }
 
        function forgotpass() {
@@ -972,10 +1004,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.");
 
@@ -1002,5 +1034,42 @@ class Handler_Public extends Handler {
                <?php
        }
 
+       function cached_image() {
+               @$hash = basename($_GET['hash']);
+
+               if ($hash) {
+
+                       $filename = CACHE_DIR . '/images/' . $hash . '.png';
+
+                       if (file_exists($filename)) {
+                               /* See if we can use X-Sendfile */
+                               $xsendfile = false;
+                               if (function_exists('apache_get_modules') &&
+                                   array_search('mod_xsendfile', apache_get_modules()))
+                                       $xsendfile = true;
+
+                               if ($xsendfile) {
+                                       header("X-Sendfile: $filename");
+                                       header("Content-type: application/octet-stream");
+                                       header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
+                               } else {
+                                       header("Content-type: image/png");
+                                       $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)). " GMT";
+                                       header("Last-Modified: $stamp", true);
+                                       readfile($filename);
+                               }
+                       } else {
+                               header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
+                               echo "File not found.";
+                       }
+               }
+       }
+
+       private function make_article_tag_uri($id, $timestamp) {
+
+               $timestamp = date("Y-m-d", strtotime($timestamp));
+
+               return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST) . ",$timestamp:/$id";
+       }
 }
 ?>