summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-12-09 17:07:17 +0300
committerAndrew Dolgov <[email protected]>2018-12-09 17:07:17 +0300
commit851f62dc4ab9981371bbbe381b6c1b56a41a961e (patch)
tree4310275a5673c2abbf65acec719f00cf4496e690 /classes
parent1b4567a9733c4226704b61437f3ca2535d6dfed5 (diff)
syndicated feeds:
1. properly reset enclosure template variables if there's no enclosures 2. add ARTICLE_OG_IMAGE which sets flavor image for article using common code with article render etc
Diffstat (limited to 'classes')
-rwxr-xr-xclasses/handler/public.php73
1 files changed, 44 insertions, 29 deletions
diff --git a/classes/handler/public.php b/classes/handler/public.php
index f10ce07bd..c38ee9566 100755
--- a/classes/handler/public.php
+++ b/classes/handler/public.php
@@ -139,18 +139,27 @@ class Handler_Public extends Handler {
$enclosures = Article::get_article_enclosures($line["id"]);
- foreach ($enclosures as $e) {
- $type = htmlspecialchars($e['content_type']);
- $url = htmlspecialchars($e['content_url']);
- $length = $e['duration'] ? $e['duration'] : 1;
+ if (count($enclosures) > 0) {
+ foreach ($enclosures as $e) {
+ $type = htmlspecialchars($e['content_type']);
+ $url = htmlspecialchars($e['content_url']);
+ $length = $e['duration'] ? $e['duration'] : 1;
- $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
- $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
- $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
+ $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
+ $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
+ $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
- $tpl->addBlock('enclosure');
+ $tpl->addBlock('enclosure');
+ }
+ } else {
+ $tpl->setVariable('ARTICLE_ENCLOSURE_URL', null, true);
+ $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', null, true);
+ $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', null, true);
}
+ $tpl->setVariable('ARTICLE_OG_IMAGE',
+ $this->get_article_image($enclosures, $line['content'], $feed_site_url));
+
$tpl->addBlock('entry');
}
@@ -309,6 +318,32 @@ class Handler_Public extends Handler {
}
+ private function get_article_image($enclosures, $content, $site_url) {
+ $og_image = false;
+
+ foreach ($enclosures as $enc) {
+ if (strpos($enc["content_type"], "image/") !== FALSE) {
+ $og_image = $enc["content_url"];
+ break;
+ }
+ }
+
+ if (!$og_image) {
+ $tmpdoc = new DOMDocument();
+
+ if (@$tmpdoc->loadHTML(mb_substr($content, 0, 131070))) {
+ $tmpxpath = new DOMXPath($tmpdoc);
+ $first_img = $tmpxpath->query("//img")->item(0);
+
+ if ($first_img) {
+ $og_image = $first_img->getAttribute("src");
+ }
+ }
+ }
+
+ return rewrite_relative_url($site_url, $og_image);
+ }
+
private function format_article($id, $owner_uid) {
$pdo = Db::pdo();
@@ -385,27 +420,7 @@ class Handler_Public extends Handler {
$rv .= "</head>";
- $og_image = false;
-
- foreach ($enclosures as $enc) {
- if (strpos($enc["content_type"], "image/") !== FALSE) {
- $og_image = $enc["content_url"];
- break;
- }
- }
-
- if (!$og_image) {
- $tmpdoc = new DOMDocument();
-
- if (@$tmpdoc->loadHTML(mb_substr($line["content"], 0, 131070))) {
- $tmpxpath = new DOMXPath($tmpdoc);
- $first_img = $tmpxpath->query("//img")->item(0);
-
- if ($first_img) {
- $og_image = $first_img->getAttribute("src");
- }
- }
- }
+ $og_image = $this->get_article_image($enclosures, $line['content'], $line["site_url"]);
if ($og_image) {
$rv .= "<meta property=\"og:image\" content=\"" . htmlspecialchars($og_image) . "\"/>";