Skip to content

Instantly share code, notes, and snippets.

@jenstornell
Created May 9, 2012 13:43
Show Gist options
  • Save jenstornell/2644588 to your computer and use it in GitHub Desktop.
Save jenstornell/2644588 to your computer and use it in GitHub Desktop.
Regexp slideshare
<?php
/*
Plugin Name: MA Slideshare
Description: MA Slideshare
Version: 1.0
Author: MediaAnalys
Plugin URI: http://www.mediaanalys.se
Author URI: http://www.mediaanalys.se
*/
add_filter('the_content', 'ma_slideshare_filter_content');
$ma_slider_callback = function($input) {
$url = $input[0];
$remoteUrl = sprintf('http://www.slideshare.net/api/oembed/2?format=json&url=%s', urlencode($url));
$json = file_get_contents($remoteUrl);
$response = json_decode($json);
var_dump($response);
$id = $response->slideshow_id;
return sprintf('<iframe src="http://www.slideshare.net/slideshow/embed_code/%d" width="670" height="800"></iframe>', $id);
};
function ma_slideshare_filter_content($content) {
$regex = '~(http://www\.slideshare\.net/[^\.\s\<]+)~';
$content = preg_replace_callback($regex, $ma_slider_callback, $content);
return $content;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment