From bc3c887f4f1c0fd1b9a0a2bd290980683988106e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 20 Jun 2013 21:16:06 +0400 Subject: better root element detection for atom content type xhtml (closes #720) --- classes/feeditem/atom.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'classes/feeditem') diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index 9680748f9..fa6b3a34c 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -58,7 +58,13 @@ class FeedItem_Atom extends FeedItem_Common { if ($content) { if ($content->hasAttribute('type')) { if ($content->getAttribute('type') == 'xhtml') { - return $this->doc->saveXML($content->firstChild->nextSibling); + for ($i = 0; $i < $content->childNodes->length; $i++) { + $child = $content->childNodes->item($i); + + if ($child->hasChildNodes()) { + return $this->doc->saveXML($child); + } + } } } @@ -72,7 +78,13 @@ class FeedItem_Atom extends FeedItem_Common { if ($content) { if ($content->hasAttribute('type')) { if ($content->getAttribute('type') == 'xhtml') { - return $this->doc->saveXML($content->firstChild->nextSibling); + for ($i = 0; $i < $content->childNodes->length; $i++) { + $child = $content->childNodes->item($i); + + if ($child->hasChildNodes()) { + return $this->doc->saveXML($child); + } + } } } -- cgit v1.2.3-54-g00ecf From b584460302b674c8e9c52718d0e6682e427a913a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 25 Jun 2013 14:43:59 +0400 Subject: parser: remove atom element --- classes/feeditem/common.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'classes/feeditem') diff --git a/classes/feeditem/common.php b/classes/feeditem/common.php index 0787a42cb..f8fd3c62a 100644 --- a/classes/feeditem/common.php +++ b/classes/feeditem/common.php @@ -8,6 +8,12 @@ abstract class FeedItem_Common extends FeedItem { $this->elem = $elem; $this->xpath = $xpath; $this->doc = $doc; + + $source = $elem->getElementsByTagName("source")->item(0); + + // we don't need element + if ($source) + $elem->removeChild($source); } function get_author() { -- cgit v1.2.3-54-g00ecf From bfc24f3794fa658b23215a430aafda050460d21b Mon Sep 17 00:00:00 2001 From: syrnon Date: Wed, 3 Jul 2013 22:36:33 +0300 Subject: Update atom.php --- classes/feeditem/atom.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'classes/feeditem') diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index fa6b3a34c..c58d2a5ff 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -1,5 +1,13 @@ baseUrl= $baseUrl; + } + function get_id() { $id = $this->elem->getElementsByTagName("id")->item(0); @@ -39,7 +47,7 @@ class FeedItem_Atom extends FeedItem_Common { || $link->getAttribute("rel") == "alternate" || $link->getAttribute("rel") == "standout")) { - return $link->getAttribute("href"); + return $this->baseUrl.$link->getAttribute("href"); } } } -- cgit v1.2.3-54-g00ecf From b28b2ce9eb4265b7360f170ae7f706906fc6d1f9 Mon Sep 17 00:00:00 2001 From: syrnon Date: Tue, 9 Jul 2013 17:29:25 +0300 Subject: calculating base locally --- classes/feeditem/atom.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'classes/feeditem') diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index c58d2a5ff..522ca633e 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -1,13 +1,6 @@ baseUrl= $baseUrl; - } - function get_id() { $id = $this->elem->getElementsByTagName("id")->item(0); @@ -46,8 +39,8 @@ class FeedItem_Atom extends FeedItem_Common { (!$link->hasAttribute("rel") || $link->getAttribute("rel") == "alternate" || $link->getAttribute("rel") == "standout")) { - - return $this->baseUrl.$link->getAttribute("href"); + $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)",$link); + return $base.$link->getAttribute("href"); } } } -- cgit v1.2.3-54-g00ecf From 6aeb37d062d18519b0f36816f7bd56cb3358cf28 Mon Sep 17 00:00:00 2001 From: syrnon Date: Tue, 9 Jul 2013 18:05:16 +0300 Subject: fixing the rel url to abs --- classes/feeditem/atom.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'classes/feeditem') diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index 522ca633e..532c599cc 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -30,7 +30,36 @@ class FeedItem_Atom extends FeedItem_Common { return strtotime($date->nodeValue); } } - + + function rel2abs($rel, $base) + { + /* return if already absolute URL */ + if (parse_url($rel, PHP_URL_SCHEME) != '') return $rel; + + /* queries and anchors */ + if ($rel[0]=='#' || $rel[0]=='?') return $base.$rel; + + /* parse base URL and convert to local variables: + $scheme, $host, $path */ + extract(parse_url($base)); + + /* remove non-directory element from path */ + $path = preg_replace('#/[^/]*$#', '', $path); + + /* destroy path if relative url points to root */ + if ($rel[0] == '/') $path = ''; + + /* dirty absolute URL */ + $abs = "$host$path/$rel"; + + /* replace '//' or '/./' or '/foo/../' with '/' */ + $re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#'); + for($n=1; $n>0; $abs=preg_replace($re, '/', $abs, -1, $n)) {} + + /* absolute URL is ready! */ + return $scheme.'://'.$abs; + } + function get_link() { $links = $this->elem->getElementsByTagName("link"); @@ -40,7 +69,7 @@ class FeedItem_Atom extends FeedItem_Common { || $link->getAttribute("rel") == "alternate" || $link->getAttribute("rel") == "standout")) { $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)",$link); - return $base.$link->getAttribute("href"); + return $this->rel2abs($link->getAttribute("href"), $base); } } } -- cgit v1.2.3-54-g00ecf From 0156128702a7477c6a2f725fa6bf24c66952aa48 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 10 Jul 2013 12:50:42 +0400 Subject: catch warning when removing source element --- classes/feeditem/common.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'classes/feeditem') diff --git a/classes/feeditem/common.php b/classes/feeditem/common.php index f8fd3c62a..58065b198 100644 --- a/classes/feeditem/common.php +++ b/classes/feeditem/common.php @@ -9,11 +9,16 @@ abstract class FeedItem_Common extends FeedItem { $this->xpath = $xpath; $this->doc = $doc; - $source = $elem->getElementsByTagName("source")->item(0); + try { - // we don't need element - if ($source) - $elem->removeChild($source); + $source = $elem->getElementsByTagName("source")->item(0); + + // we don't need element + if ($source) + $elem->removeChild($source); + } catch (DOMException $e) { + // + } } function get_author() { -- cgit v1.2.3-54-g00ecf From 3c4dead676a7c5199aef1b022f54f7763c17311e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 11 Jul 2013 14:21:29 +0400 Subject: atom: remove rel2abs; use rewrite_relative_url --- classes/feeditem/atom.php | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) (limited to 'classes/feeditem') diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index 532c599cc..f82c582da 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -30,36 +30,8 @@ class FeedItem_Atom extends FeedItem_Common { return strtotime($date->nodeValue); } } - - function rel2abs($rel, $base) - { - /* return if already absolute URL */ - if (parse_url($rel, PHP_URL_SCHEME) != '') return $rel; - - /* queries and anchors */ - if ($rel[0]=='#' || $rel[0]=='?') return $base.$rel; - - /* parse base URL and convert to local variables: - $scheme, $host, $path */ - extract(parse_url($base)); - - /* remove non-directory element from path */ - $path = preg_replace('#/[^/]*$#', '', $path); - - /* destroy path if relative url points to root */ - if ($rel[0] == '/') $path = ''; - - /* dirty absolute URL */ - $abs = "$host$path/$rel"; - - /* replace '//' or '/./' or '/foo/../' with '/' */ - $re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#'); - for($n=1; $n>0; $abs=preg_replace($re, '/', $abs, -1, $n)) {} - - /* absolute URL is ready! */ - return $scheme.'://'.$abs; - } - + + function get_link() { $links = $this->elem->getElementsByTagName("link"); @@ -68,8 +40,9 @@ class FeedItem_Atom extends FeedItem_Common { (!$link->hasAttribute("rel") || $link->getAttribute("rel") == "alternate" || $link->getAttribute("rel") == "standout")) { - $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)",$link); - return $this->rel2abs($link->getAttribute("href"), $base); + $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link); + + return rewrite_relative_url($base, $link->getAttribute("href")); } } } -- cgit v1.2.3-54-g00ecf From 491ef970727e335c3f398612480bb482e0a1a42b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 29 Jul 2013 16:16:47 +0400 Subject: atom: only perform xml:base based rewriting if base element exists (closes #761) --- classes/feeditem/atom.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'classes/feeditem') diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index f82c582da..8a21d6142 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -42,7 +42,11 @@ class FeedItem_Atom extends FeedItem_Common { || $link->getAttribute("rel") == "standout")) { $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link); - return rewrite_relative_url($base, $link->getAttribute("href")); + if ($base) + return rewrite_relative_url($base, $link->getAttribute("href")); + else + return $link->getAttribute("href"); + } } } -- cgit v1.2.3-54-g00ecf From 4289b68f0d4e4bcf5e9c09cf03367be3e638ccba Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 5 Aug 2013 10:33:13 +0400 Subject: parser: support media:content elements within media:group --- classes/feeditem/atom.php | 12 ++++++++++++ classes/feeditem/rss.php | 12 ++++++++++++ 2 files changed, 24 insertions(+) (limited to 'classes/feeditem') diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index 8a21d6142..e88b5ec1d 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -149,6 +149,18 @@ class FeedItem_Atom extends FeedItem_Common { array_push($encs, $enc); } + $enclosures = $this->xpath->query("media:group/media:content", $this->elem); + + foreach ($enclosures as $enclosure) { + $enc = new FeedEnclosure(); + + $enc->type = $enclosure->getAttribute("type"); + $enc->link = $enclosure->getAttribute("url"); + $enc->length = $enclosure->getAttribute("length"); + + array_push($encs, $enc); + } + return $encs; } diff --git a/classes/feeditem/rss.php b/classes/feeditem/rss.php index e5960243c..a2e9f01a2 100644 --- a/classes/feeditem/rss.php +++ b/classes/feeditem/rss.php @@ -124,6 +124,18 @@ class FeedItem_RSS extends FeedItem_Common { array_push($encs, $enc); } + $enclosures = $this->xpath->query("media:group/media:content", $this->elem); + + foreach ($enclosures as $enclosure) { + $enc = new FeedEnclosure(); + + $enc->type = $enclosure->getAttribute("type"); + $enc->link = $enclosure->getAttribute("url"); + $enc->length = $enclosure->getAttribute("length"); + + array_push($encs, $enc); + } + return $encs; } -- cgit v1.2.3-54-g00ecf From 6bf61bdc639f60957ce4edc9e0160de3e78dc7df Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 5 Aug 2013 11:50:15 +0400 Subject: simplify media:content xpath --- classes/feeditem/atom.php | 14 +------------- classes/feeditem/rss.php | 14 +------------- 2 files changed, 2 insertions(+), 26 deletions(-) (limited to 'classes/feeditem') diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index e88b5ec1d..b1251e6d3 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -137,19 +137,7 @@ class FeedItem_Atom extends FeedItem_Common { } } - $enclosures = $this->xpath->query("media:content", $this->elem); - - foreach ($enclosures as $enclosure) { - $enc = new FeedEnclosure(); - - $enc->type = $enclosure->getAttribute("type"); - $enc->link = $enclosure->getAttribute("url"); - $enc->length = $enclosure->getAttribute("length"); - - array_push($encs, $enc); - } - - $enclosures = $this->xpath->query("media:group/media:content", $this->elem); + $enclosures = $this->xpath->query("media:content | media:group/media:content", $this->elem); foreach ($enclosures as $enclosure) { $enc = new FeedEnclosure(); diff --git a/classes/feeditem/rss.php b/classes/feeditem/rss.php index a2e9f01a2..095225a2a 100644 --- a/classes/feeditem/rss.php +++ b/classes/feeditem/rss.php @@ -112,19 +112,7 @@ class FeedItem_RSS extends FeedItem_Common { array_push($encs, $enc); } - $enclosures = $this->xpath->query("media:content", $this->elem); - - foreach ($enclosures as $enclosure) { - $enc = new FeedEnclosure(); - - $enc->type = $enclosure->getAttribute("type"); - $enc->link = $enclosure->getAttribute("url"); - $enc->length = $enclosure->getAttribute("length"); - - array_push($encs, $enc); - } - - $enclosures = $this->xpath->query("media:group/media:content", $this->elem); + $enclosures = $this->xpath->query("media:content | media:group/media:content", $this->elem); foreach ($enclosures as $enclosure) { $enc = new FeedEnclosure(); -- cgit v1.2.3-54-g00ecf From 5c54e6838870498134bbfb2994c25d2140b43bad Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 5 Aug 2013 12:26:09 +0400 Subject: support media:description for media: enclosures --- classes/feedenclosure.php | 1 + classes/feeditem/atom.php | 3 +++ classes/feeditem/rss.php | 3 +++ css/tt-rss.css | 5 +++++ include/functions.php | 12 +++++++++++- include/rssfuncs.php | 8 ++++++-- 6 files changed, 29 insertions(+), 3 deletions(-) (limited to 'classes/feeditem') diff --git a/classes/feedenclosure.php b/classes/feedenclosure.php index d610dd7c8..b57100b06 100644 --- a/classes/feedenclosure.php +++ b/classes/feedenclosure.php @@ -3,5 +3,6 @@ class FeedEnclosure { public $link; public $type; public $length; + public $title; } ?> diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index b1251e6d3..b7a228aed 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -146,6 +146,9 @@ class FeedItem_Atom extends FeedItem_Common { $enc->link = $enclosure->getAttribute("url"); $enc->length = $enclosure->getAttribute("length"); + $desc = $this->xpath->query("media:description", $enclosure)->item(0); + if ($desc) $enc->title = strip_tags($desc->nodeValue); + array_push($encs, $enc); } diff --git a/classes/feeditem/rss.php b/classes/feeditem/rss.php index 095225a2a..1f59f0612 100644 --- a/classes/feeditem/rss.php +++ b/classes/feeditem/rss.php @@ -121,6 +121,9 @@ class FeedItem_RSS extends FeedItem_Common { $enc->link = $enclosure->getAttribute("url"); $enc->length = $enclosure->getAttribute("length"); + $desc = $this->xpath->query("media:description", $enclosure)->item(0); + if ($desc) $enc->title = strip_tags($desc->nodeValue); + array_push($encs, $enc); } diff --git a/css/tt-rss.css b/css/tt-rss.css index 3392c3c7a..9e500a759 100644 --- a/css/tt-rss.css +++ b/css/tt-rss.css @@ -1177,3 +1177,8 @@ span.highlight { background-color : #ffff00; color : #cc90cc; } + +div.enclosure_title { + +} + diff --git a/include/functions.php b/include/functions.php index 56361472e..6bc52e9d9 100644 --- a/include/functions.php +++ b/include/functions.php @@ -3776,6 +3776,7 @@ $url = $line["content_url"]; $ctype = $line["content_type"]; + $title = $line["title"]; if (!$ctype) $ctype = __("unknown type"); @@ -3798,6 +3799,7 @@ $entry["type"] = $ctype; $entry["filename"] = $filename; $entry["url"] = $url; + $entry["title"] = $title; array_push($entries, $entry); } @@ -3819,7 +3821,10 @@ $rv .= "

" .htmlspecialchars($entry["url"]) . "

"; + } + if ($entry['title']) { + $rv.= "
${entry['title']}
"; } } } @@ -3836,7 +3841,12 @@ ""; foreach ($entries as $entry) { - $rv .= ""; + if ($entry["title"]) + $title = "— " . truncate_string($entry["title"], 30); + else + $title = ""; + + $rv .= ""; }; diff --git a/include/rssfuncs.php b/include/rssfuncs.php index 4b1b30c4b..dbe5c8bc9 100644 --- a/include/rssfuncs.php +++ b/include/rssfuncs.php @@ -954,7 +954,7 @@ if (is_array($encs)) { foreach ($encs as $e) { $e_item = array( - $e->link, $e->type, $e->length); + $e->link, $e->type, $e->length, $e->title); array_push($enclosures, $e_item); } } @@ -966,10 +966,14 @@ 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]); $result = db_query("SELECT id FROM ttrss_enclosures WHERE content_url = '$enc_url' AND post_id = '$entry_ref_id'"); @@ -977,7 +981,7 @@ if (db_num_rows($result) == 0) { db_query("INSERT INTO ttrss_enclosures (content_url, content_type, title, duration, post_id) VALUES - ('$enc_url', '$enc_type', '', '$enc_dur', '$entry_ref_id')"); + ('$enc_url', '$enc_type', '$enc_title', '$enc_dur', '$entry_ref_id')"); } } -- cgit v1.2.3-54-g00ecf From ed449a9aaa08d507b92dad934239f4c371f5ca3e Mon Sep 17 00:00:00 2001 From: Jeffrey Tolar Date: Sun, 17 Nov 2013 17:58:43 -0600 Subject: Follow the spec for s Each section specifies multiple representations of the same content. --- classes/feeditem/atom.php | 25 ++++++++++++++++++++++++- classes/feeditem/rss.php | 25 ++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) (limited to 'classes/feeditem') diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index b7a228aed..5f0400fea 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -137,7 +137,7 @@ class FeedItem_Atom extends FeedItem_Common { } } - $enclosures = $this->xpath->query("media:content | media:group/media:content", $this->elem); + $enclosures = $this->xpath->query("media:content", $this->elem); foreach ($enclosures as $enclosure) { $enc = new FeedEnclosure(); @@ -152,6 +152,29 @@ class FeedItem_Atom extends FeedItem_Common { array_push($encs, $enc); } + + $enclosures = $this->xpath->query("media:group", $this->elem); + + foreach ($enclosures as $enclosure) { + $enc = new FeedEnclosure(); + + $content = $this->xpath->query("media:content", $enclosure)->item(0); + + $enc->type = $content->getAttribute("type"); + $enc->link = $content->getAttribute("url"); + $enc->length = $content->getAttribute("length"); + + $desc = $this->xpath->query("media:description", $content)->item(0); + if ($desc) { + $enc->title = strip_tags($desc->nodeValue); + } else { + $desc = $this->xpath->query("media:description", $enclosure)->item(0); + if ($desc) $enc->title = strip_tags($desc->nodeValue); + } + + array_push($encs, $enc); + } + return $encs; } diff --git a/classes/feeditem/rss.php b/classes/feeditem/rss.php index 1f59f0612..b5d9695e2 100644 --- a/classes/feeditem/rss.php +++ b/classes/feeditem/rss.php @@ -112,7 +112,7 @@ class FeedItem_RSS extends FeedItem_Common { array_push($encs, $enc); } - $enclosures = $this->xpath->query("media:content | media:group/media:content", $this->elem); + $enclosures = $this->xpath->query("media:content", $this->elem); foreach ($enclosures as $enclosure) { $enc = new FeedEnclosure(); @@ -127,6 +127,29 @@ class FeedItem_RSS extends FeedItem_Common { array_push($encs, $enc); } + + $enclosures = $this->xpath->query("media:group", $this->elem); + + foreach ($enclosures as $enclosure) { + $enc = new FeedEnclosure(); + + $content = $this->xpath->query("media:content", $enclosure)->item(0); + + $enc->type = $content->getAttribute("type"); + $enc->link = $content->getAttribute("url"); + $enc->length = $content->getAttribute("length"); + + $desc = $this->xpath->query("media:description", $content)->item(0); + if ($desc) { + $enc->title = strip_tags($desc->nodeValue); + } else { + $desc = $this->xpath->query("media:description", $enclosure)->item(0); + if ($desc) $enc->title = strip_tags($desc->nodeValue); + } + + array_push($encs, $enc); + } + return $encs; } -- cgit v1.2.3-54-g00ecf From e23aedd402a0621e3f92f9325b77952968aadbe7 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 15 Dec 2013 12:35:30 +0400 Subject: parser: add basic support for media:thumbnail --- classes/feeditem/atom.php | 11 +++++++++++ classes/feeditem/rss.php | 11 +++++++++++ 2 files changed, 22 insertions(+) (limited to 'classes/feeditem') diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index 5f0400fea..244fb1f84 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -175,6 +175,17 @@ class FeedItem_Atom extends FeedItem_Common { array_push($encs, $enc); } + $enclosures = $this->xpath->query("media:thumbnail", $this->elem); + + foreach ($enclosures as $enclosure) { + $enc = new FeedEnclosure(); + + $enc->type = "image/generic"; + $enc->link = $enclosure->getAttribute("url"); + + array_push($encs, $enc); + } + return $encs; } diff --git a/classes/feeditem/rss.php b/classes/feeditem/rss.php index b5d9695e2..f632d3bbf 100644 --- a/classes/feeditem/rss.php +++ b/classes/feeditem/rss.php @@ -150,6 +150,17 @@ class FeedItem_RSS extends FeedItem_Common { array_push($encs, $enc); } + $enclosures = $this->xpath->query("media:thumbnail", $this->elem); + + foreach ($enclosures as $enclosure) { + $enc = new FeedEnclosure(); + + $enc->type = "image/generic"; + $enc->link = $enclosure->getAttribute("url"); + + array_push($encs, $enc); + } + return $encs; } -- cgit v1.2.3-54-g00ecf From d71ac5d3dabde7dda4aef6efa2af3a68ee2095c6 Mon Sep 17 00:00:00 2001 From: wltb Date: Wed, 18 Dec 2013 17:05:43 +0100 Subject: implemented get_comments_url() and Atom Threading Extension --- classes/feeditem/common.php | 17 +++++++++++++++-- classes/feedparser.php | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'classes/feeditem') diff --git a/classes/feeditem/common.php b/classes/feeditem/common.php index 58065b198..80bebf8fb 100644 --- a/classes/feeditem/common.php +++ b/classes/feeditem/common.php @@ -44,13 +44,26 @@ abstract class FeedItem_Common extends FeedItem { } } - // todo function get_comments_url() { + //RSS only. Use a query here to avoid namespace clashes (e.g. with slash). + //might give a wrong result if a default namespace was declared (possible with XPath 2.0) + $com_url = $this->xpath->query("comments", $this->elem)->item(0); + if($com_url) + return $com_url->nodeValue; + + //Atom Threading Extension (RFC 4685) stuff. Could be used in RSS feeds, so it's in common. + //'text/html' for type is too restrictive? + $com_url = $this->xpath->query("atom:link[@rel='replies' and contains(@type,'text/html')]/@href", $this->elem)->item(0); + + if($com_url) + return $com_url->nodeValue; } function get_comments_count() { - $comments = $this->xpath->query("slash:comments", $this->elem)->item(0); + //also query for ATE stuff here + $query = "slash:comments|thread:total|atom:link[@rel='replies']/@thread:count"; + $comments = $this->xpath->query($query, $this->elem)->item(0); if ($comments) { return $comments->nodeValue; diff --git a/classes/feedparser.php b/classes/feedparser.php index de6c56542..187875b5f 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -97,6 +97,7 @@ class FeedParser { $xpath->registerNamespace('slash', 'http://purl.org/rss/1.0/modules/slash/'); $xpath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/'); $xpath->registerNamespace('content', 'http://purl.org/rss/1.0/modules/content/'); + $xpath->registerNamespace('thread', 'http://purl.org/syndication/thread/1.0'); $this->xpath = $xpath; -- cgit v1.2.3-54-g00ecf From f6c61b2d55ff70819bc1582791fdc8df149eb22f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 19 Dec 2013 13:19:30 +0400 Subject: rss: choose between description and content:encoded based on which one is longer because publishers are idiots and can't use tags properly --- classes/feeditem/rss.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'classes/feeditem') diff --git a/classes/feeditem/rss.php b/classes/feeditem/rss.php index f632d3bbf..7d445a6c3 100644 --- a/classes/feeditem/rss.php +++ b/classes/feeditem/rss.php @@ -59,16 +59,21 @@ class FeedItem_RSS extends FeedItem_Common { } function get_content() { - $content = $this->xpath->query("content:encoded", $this->elem)->item(0); + $contentA = $this->xpath->query("content:encoded", $this->elem)->item(0); + $contentB = $this->elem->getElementsByTagName("description")->item(0); - if ($content) { - return $content->nodeValue; + if ($contentA && !$contentB) { + return $contentA->nodeValue; } - $content = $this->elem->getElementsByTagName("description")->item(0); - if ($content) { - return $content->nodeValue; + if ($contentB && !$contentA) { + return $contentB->nodeValue; + } + + if ($contentA && $contentB) { + return mb_strlen($contentA->nodeValue) > mb_strlen($contentB->nodeValue) ? + $contentA->nodeValue : $contentB->nodeValue; } } -- cgit v1.2.3-54-g00ecf From 2ab7ccb695fa690ee56100304b93d20e2c20debc Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 12 Jan 2014 08:53:30 +0400 Subject: parser: fix failing on empty media:group tags --- classes/feeditem/atom.php | 26 ++++++++++++++------------ classes/feeditem/rss.php | 26 ++++++++++++++------------ 2 files changed, 28 insertions(+), 24 deletions(-) (limited to 'classes/feeditem') diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index 244fb1f84..74be03d80 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -160,19 +160,21 @@ class FeedItem_Atom extends FeedItem_Common { $content = $this->xpath->query("media:content", $enclosure)->item(0); - $enc->type = $content->getAttribute("type"); - $enc->link = $content->getAttribute("url"); - $enc->length = $content->getAttribute("length"); - - $desc = $this->xpath->query("media:description", $content)->item(0); - if ($desc) { - $enc->title = strip_tags($desc->nodeValue); - } else { - $desc = $this->xpath->query("media:description", $enclosure)->item(0); - if ($desc) $enc->title = strip_tags($desc->nodeValue); - } + if ($content) { + $enc->type = $content->getAttribute("type"); + $enc->link = $content->getAttribute("url"); + $enc->length = $content->getAttribute("length"); + + $desc = $this->xpath->query("media:description", $content)->item(0); + if ($desc) { + $enc->title = strip_tags($desc->nodeValue); + } else { + $desc = $this->xpath->query("media:description", $enclosure)->item(0); + if ($desc) $enc->title = strip_tags($desc->nodeValue); + } - array_push($encs, $enc); + array_push($encs, $enc); + } } $enclosures = $this->xpath->query("media:thumbnail", $this->elem); diff --git a/classes/feeditem/rss.php b/classes/feeditem/rss.php index 7d445a6c3..28f4a388d 100644 --- a/classes/feeditem/rss.php +++ b/classes/feeditem/rss.php @@ -140,19 +140,21 @@ class FeedItem_RSS extends FeedItem_Common { $content = $this->xpath->query("media:content", $enclosure)->item(0); - $enc->type = $content->getAttribute("type"); - $enc->link = $content->getAttribute("url"); - $enc->length = $content->getAttribute("length"); - - $desc = $this->xpath->query("media:description", $content)->item(0); - if ($desc) { - $enc->title = strip_tags($desc->nodeValue); - } else { - $desc = $this->xpath->query("media:description", $enclosure)->item(0); - if ($desc) $enc->title = strip_tags($desc->nodeValue); + if ($content) { + $enc->type = $content->getAttribute("type"); + $enc->link = $content->getAttribute("url"); + $enc->length = $content->getAttribute("length"); + + $desc = $this->xpath->query("media:description", $content)->item(0); + if ($desc) { + $enc->title = strip_tags($desc->nodeValue); + } else { + $desc = $this->xpath->query("media:description", $enclosure)->item(0); + if ($desc) $enc->title = strip_tags($desc->nodeValue); + } + + array_push($encs, $enc); } - - array_push($encs, $enc); } $enclosures = $this->xpath->query("media:thumbnail", $this->elem); -- cgit v1.2.3-54-g00ecf From 31bd6f7643bf139802a224f4584caca3cbbcc9b8 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 4 Mar 2014 16:38:04 +0400 Subject: parser: trim some some feed-extracted data link titles and links --- classes/feeditem/atom.php | 10 +++++----- classes/feeditem/rss.php | 12 ++++++------ classes/feedparser.php | 8 ++++++-- 3 files changed, 17 insertions(+), 13 deletions(-) (limited to 'classes/feeditem') diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index 74be03d80..48e3aa567 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -43,9 +43,9 @@ class FeedItem_Atom extends FeedItem_Common { $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link); if ($base) - return rewrite_relative_url($base, $link->getAttribute("href")); + return rewrite_relative_url($base, trim($link->getAttribute("href"))); else - return $link->getAttribute("href"); + return trim($link->getAttribute("href")); } } @@ -55,7 +55,7 @@ class FeedItem_Atom extends FeedItem_Common { $title = $this->elem->getElementsByTagName("title")->item(0); if ($title) { - return $title->nodeValue; + return trim($title->nodeValue); } } @@ -106,13 +106,13 @@ class FeedItem_Atom extends FeedItem_Common { foreach ($categories as $cat) { if ($cat->hasAttribute("term")) - array_push($cats, $cat->getAttribute("term")); + array_push($cats, trim($cat->getAttribute("term"))); } $categories = $this->xpath->query("dc:subject", $this->elem); foreach ($categories as $cat) { - array_push($cats, $cat->nodeValue); + array_push($cats, trim($cat->nodeValue)); } return $cats; diff --git a/classes/feeditem/rss.php b/classes/feeditem/rss.php index 28f4a388d..bf08a1dfe 100644 --- a/classes/feeditem/rss.php +++ b/classes/feeditem/rss.php @@ -33,20 +33,20 @@ class FeedItem_RSS extends FeedItem_Common { || $link->getAttribute("rel") == "alternate" || $link->getAttribute("rel") == "standout")) { - return $link->getAttribute("href"); + return trim($link->getAttribute("href")); } } $link = $this->elem->getElementsByTagName("guid")->item(0); if ($link && $link->hasAttributes() && $link->getAttribute("isPermaLink") == "true") { - return $link->nodeValue; + return trim($link->nodeValue); } $link = $this->elem->getElementsByTagName("link")->item(0); if ($link) { - return $link->nodeValue; + return trim($link->nodeValue); } } @@ -54,7 +54,7 @@ class FeedItem_RSS extends FeedItem_Common { $title = $this->elem->getElementsByTagName("title")->item(0); if ($title) { - return $title->nodeValue; + return trim($title->nodeValue); } } @@ -90,13 +90,13 @@ class FeedItem_RSS extends FeedItem_Common { $cats = array(); foreach ($categories as $cat) { - array_push($cats, $cat->nodeValue); + array_push($cats, trim($cat->nodeValue)); } $categories = $this->xpath->query("dc:subject", $this->elem); foreach ($categories as $cat) { - array_push($cats, $cat->nodeValue); + array_push($cats, trim($cat->nodeValue)); } return $cats; diff --git a/classes/feedparser.php b/classes/feedparser.php index 187875b5f..239fdb7a6 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -205,6 +205,10 @@ class FeedParser { break; } + + if ($this->title) $this->title = trim($this->title); + if ($this->link) $this->link = trim($this->link); + } else { if( !isset($this->error) ){ $this->error = "Unknown/unsupported feed type"; @@ -252,7 +256,7 @@ class FeedParser { foreach ($links as $link) { if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) { - array_push($rv, $link->getAttribute('href')); + array_push($rv, trim($link->getAttribute('href'))); } } break; @@ -261,7 +265,7 @@ class FeedParser { foreach ($links as $link) { if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) { - array_push($rv, $link->getAttribute('href')); + array_push($rv, trim($link->getAttribute('href'))); } } break; -- cgit v1.2.3-54-g00ecf From 523bd90bafffee18d9c7652c68f4c08d25be339e Mon Sep 17 00:00:00 2001 From: Felix Eckhofer Date: Tue, 15 Jul 2014 15:32:28 +0200 Subject: Store size of enclosure to database --- classes/feedenclosure.php | 2 ++ classes/feeditem/atom.php | 6 ++++++ classes/feeditem/rss.php | 8 ++++++++ include/rssfuncs.php | 8 +++++--- 4 files changed, 21 insertions(+), 3 deletions(-) (limited to 'classes/feeditem') diff --git a/classes/feedenclosure.php b/classes/feedenclosure.php index b57100b06..64f1a0616 100644 --- a/classes/feedenclosure.php +++ b/classes/feedenclosure.php @@ -4,5 +4,7 @@ class FeedEnclosure { public $type; public $length; public $title; + public $height; + public $width; } ?> diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index 48e3aa567..dfac7149f 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -145,6 +145,8 @@ class FeedItem_Atom extends FeedItem_Common { $enc->type = $enclosure->getAttribute("type"); $enc->link = $enclosure->getAttribute("url"); $enc->length = $enclosure->getAttribute("length"); + $enc->height = $enclosure->getAttribute("height"); + $enc->width = $enclosure->getAttribute("width"); $desc = $this->xpath->query("media:description", $enclosure)->item(0); if ($desc) $enc->title = strip_tags($desc->nodeValue); @@ -164,6 +166,8 @@ class FeedItem_Atom extends FeedItem_Common { $enc->type = $content->getAttribute("type"); $enc->link = $content->getAttribute("url"); $enc->length = $content->getAttribute("length"); + $enc->height = $content->getAttribute("height"); + $enc->width = $content->getAttribute("width"); $desc = $this->xpath->query("media:description", $content)->item(0); if ($desc) { @@ -184,6 +188,8 @@ class FeedItem_Atom extends FeedItem_Common { $enc->type = "image/generic"; $enc->link = $enclosure->getAttribute("url"); + $enc->height = $enclosure->getAttribute("height"); + $enc->width = $enclosure->getAttribute("width"); array_push($encs, $enc); } diff --git a/classes/feeditem/rss.php b/classes/feeditem/rss.php index bf08a1dfe..c9a7467cd 100644 --- a/classes/feeditem/rss.php +++ b/classes/feeditem/rss.php @@ -113,6 +113,8 @@ class FeedItem_RSS extends FeedItem_Common { $enc->type = $enclosure->getAttribute("type"); $enc->link = $enclosure->getAttribute("url"); $enc->length = $enclosure->getAttribute("length"); + $enc->height = $enclosure->getAttribute("height"); + $enc->width = $enclosure->getAttribute("width"); array_push($encs, $enc); } @@ -125,6 +127,8 @@ class FeedItem_RSS extends FeedItem_Common { $enc->type = $enclosure->getAttribute("type"); $enc->link = $enclosure->getAttribute("url"); $enc->length = $enclosure->getAttribute("length"); + $enc->height = $enclosure->getAttribute("height"); + $enc->width = $enclosure->getAttribute("width"); $desc = $this->xpath->query("media:description", $enclosure)->item(0); if ($desc) $enc->title = strip_tags($desc->nodeValue); @@ -144,6 +148,8 @@ class FeedItem_RSS extends FeedItem_Common { $enc->type = $content->getAttribute("type"); $enc->link = $content->getAttribute("url"); $enc->length = $content->getAttribute("length"); + $enc->height = $content->getAttribute("height"); + $enc->width = $content->getAttribute("width"); $desc = $this->xpath->query("media:description", $content)->item(0); if ($desc) { @@ -164,6 +170,8 @@ class FeedItem_RSS extends FeedItem_Common { $enc->type = "image/generic"; $enc->link = $enclosure->getAttribute("url"); + $enc->height = $enclosure->getAttribute("height"); + $enc->width = $enclosure->getAttribute("width"); array_push($encs, $enc); } diff --git a/include/rssfuncs.php b/include/rssfuncs.php index 60cb3b2d2..cdc490cb0 100644 --- a/include/rssfuncs.php +++ b/include/rssfuncs.php @@ -989,7 +989,7 @@ if (is_array($encs)) { foreach ($encs as $e) { $e_item = array( - $e->link, $e->type, $e->length, $e->title); + $e->link, $e->type, $e->length, $e->title, $e->width, $e->height); array_push($enclosures, $e_item); } } @@ -1009,14 +1009,16 @@ $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 WHERE content_url = '$enc_url' AND post_id = '$entry_ref_id'"); if (db_num_rows($result) == 0) { db_query("INSERT INTO ttrss_enclosures - (content_url, content_type, title, duration, post_id) VALUES - ('$enc_url', '$enc_type', '$enc_title', '$enc_dur', '$entry_ref_id')"); + (content_url, content_type, title, duration, post_id, width, height) VALUES + ('$enc_url', '$enc_type', '$enc_title', '$enc_dur', '$entry_ref_id', $enc_width, $enc_height)"); } } -- cgit v1.2.3-54-g00ecf