Permalink
Browse files

Rewrite srcset in feeds to absolute urls (#585)

  • Loading branch information...
onli committed Feb 9, 2019
1 parent 4445926 commit 1b518e5b46a4532d1e1101494b9bc3a55dfb7a80
Showing with 25 additions and 2 deletions.
  1. +25 −2 plugins/serendipity_event_responsiveimages/serendipity_event_responsiveimages.php
@@ -18,13 +18,20 @@ function introspect(&$propbag)
$propbag->add('description', PLUGIN_EVENT_RESPONSIVE_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Serendipity Team');
$propbag->add('version', '0.4');
$propbag->add('version', '0.5');
$propbag->add('requirements', array(
'serendipity' => '2.2',
));
$propbag->add('cachable_events', array('frontend_display' => true));
$propbag->add('event_hooks', array('frontend_display' => true,
'backend_media_makethumb' => true
'backend_media_makethumb' => true,
'frontend_display:unknown:per-entry' => true,
'frontend_display:opml-1.0:per_entry' => true,
'frontend_display:rss-0.91:per_entry' => true,
'frontend_display:rss-1.0:per_entry' => true,
'frontend_display:rss-2.0:per_entry' => true,
'frontend_display:atom-0.3:per_entry' => true,
'frontend_display:atom-1.0:per_entry' => true,
));
$propbag->add('groups', array('MARKUP'));
@@ -118,6 +125,22 @@ function event_hook($event, &$bag, &$eventData, $addData = null)
}
break;
case 'frontend_display:unknown:per-entry':
case 'frontend_display:opml-1.0:per_entry':
case 'frontend_display:rss-0.91:per_entry':
case 'frontend_display:rss-1.0:per_entry':
case 'frontend_display:rss-2.0:per_entry':
case 'frontend_display:atom-0.3:per_entry':
case 'frontend_display:atom-1.0:per_entry':
// We need to rewrite relative srcsets to absolute urls in the RSS feed, otherwise images won't be shown
$pattern = '@srcset=(["\'][^"\']+)@i';
$eventData['feed_body'] = preg_replace_callback($pattern, function($matches) {
global $serendipity;
$matches[1] = str_ireplace('"' . $serendipity['serendipityHTTPPath'], '"' . $serendipity['baseURL'], $matches[1]);
$matches[1] = str_ireplace(',' . $serendipity['serendipityHTTPPath'], ',' . $serendipity['baseURL'], $matches[1]);
return 'srcset=' . $matches[1];
}, $eventData['feed_body']);
break;
default:
return false;

0 comments on commit 1b518e5

Please sign in to comment.