aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-06-04 19:09:05 -0700
committerMario Vavti <mario@mariovavti.com>2017-06-07 09:35:04 +0200
commit36d40866738ca81a31002251d4ca63f1087d8054 (patch)
treed179ef989d7bd7da503bb990cdaba5d779723b4e
parent01b541d8b04e93de8f90c420610c656f6d3e2fb0 (diff)
downloadvolse-hubzilla-36d40866738ca81a31002251d4ca63f1087d8054.tar.gz
volse-hubzilla-36d40866738ca81a31002251d4ca63f1087d8054.tar.bz2
volse-hubzilla-36d40866738ca81a31002251d4ca63f1087d8054.zip
ostatus feeds: extract photo information from posts and convert to enclosures as otherwise OStatus servers will strip them from the HTML in the feed and refuse to render them
-rw-r--r--include/feedutils.php45
1 files changed, 42 insertions, 3 deletions
diff --git a/include/feedutils.php b/include/feedutils.php
index 6c411723a..1563bdb41 100644
--- a/include/feedutils.php
+++ b/include/feedutils.php
@@ -136,7 +136,7 @@ function get_feed_for($channel, $observer_hash, $params) {
continue;
/** @BUG $owner is undefined in this call */
- $atom .= atom_entry($item, $type, null, $owner, true);
+ $atom .= atom_entry($item, $type, null, $owner, true, '', $params['compat']);
}
}
@@ -1306,6 +1306,28 @@ function atom_render_author($tag,$xchan) {
}
+function compat_photos_list($s) {
+
+ $ret = [];
+
+ $found = preg_match_all('/\[[zi]mg(.*?)\](.*?)\[/ism',$s,$matches,PREG_SET_ORDER);
+
+ if($found) {
+ foreach($matches as $match) {
+ $ret[] = [
+ 'href' => $match[2],
+ 'length' => 0,
+ 'type' => guess_image_type($match[2])
+ ];
+
+ }
+ }
+
+ return $ret;
+}
+
+
+
/**
* @brief Create an item for the Atom feed.
*
@@ -1319,7 +1341,8 @@ function atom_render_author($tag,$xchan) {
* @param number $cid default 0
* @return void|string
*/
-function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) {
+function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $compat = false) {
+
if(! $item['parent'])
return;
@@ -1334,6 +1357,13 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) {
else
$body = $item['body'];
+ if($compat) {
+ $compat_photos = compat_photos_list($body);
+ }
+ else {
+ $compat_photos = null;
+ }
+
$o = "\r\n\r\n<entry>\r\n";
if(is_array($author)) {
@@ -1403,10 +1433,19 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) {
. (($enc['href']) ? 'href="' . $enc['href'] . '" ' : '')
. (($enc['length']) ? 'length="' . $enc['length'] . '" ' : '')
. (($enc['type']) ? 'type="' . $enc['type'] . '" ' : '')
- . ' />';
+ . ' />' . "\r\n";
}
}
}
+ if($compat_photos) {
+ foreach($compat_photos as $enc) {
+ $o .= '<link rel="enclosure" '
+ . (($enc['href']) ? 'href="' . $enc['href'] . '" ' : '')
+ . (($enc['length']) ? 'length="' . $enc['length'] . '" ' : '')
+ . (($enc['type']) ? 'type="' . $enc['type'] . '" ' : '')
+ . ' />' . "\r\n";
+ }
+ }
if($item['term']) {
foreach($item['term'] as $term) {