3 require_once(dirname(__FILE__) . '/../Media_base.php');
5 class Media_slideshare implements MediaBase {
7 private static $base_url = 'http://slideshare.net/';
9 private static $default_width = 425;
10 private static $default_height = 355;
12 private static $scrape_sources = array(
14 'match' => '@.*https?://(www\.)?slideshare\.net/([^/]+)/([^/?&#]+).*@',
15 'url' => 'http://www.slideshare.net/$2/$3',
19 private static $iframe_sources = array(
21 'match' => '#.*https?://(www\.)?slideshare\.net/slideshow/embed_code/([0-9]+).*#',
22 'url' => 'http://www.slideshare.net/slideshow/embed_code/$2',
26 public function process_url($input, $width=0, $height=0) {
31 $width = $width ? (int)$width : self::$default_width;
32 $height = $height ? (int)$height : self::$default_height;
34 foreach (self::$iframe_sources as $source) {
35 if (preg_match($source['match'], $input)) {
36 $output = preg_replace($source['match'], $source['url'], $input);
47 foreach (self::$scrape_sources as $source) {
48 if (preg_match($source['match'], $input)) {
49 $output = preg_replace($source['match'], $source['url'], $input);
50 return $this->process_url(self::scrape_url($output), $width, $height);
56 public function validate_url($input) {
57 foreach (self::$scrape_sources as $source) {
58 if (preg_match($source['match'], $input)) {
63 foreach (self::$iframe_sources as $source) {
64 if (preg_match($source['match'], $input)) {
71 public function get_base_url() {
72 return self::$base_url;
75 private static function scrape_url($url) {
80 static $scrape_regex = '#.*?https?://(www\.)?slideshare\.net/share/(tweet|facebook|linkedin)/([0-9]+)/.*#';
82 $data = mahara_http_request($config);
83 if (preg_match($scrape_regex, $data->data, $matches)) {
84 $slideid = $matches[3];
85 return 'http://www.slideshare.net/slideshow/embed_code/' . $slideid;