| 1 |
<?php |
| 2 |
/* |
| 3 |
* Slideshare shortcode format: |
| 4 |
* [slideshare id=5342235&doc=camprock-101002163655-phpapp01&w=300&h=200] |
| 5 |
**/ |
| 6 |
|
| 7 |
function slideshare_shortcode( $atts ) { |
| 8 |
global $content_width; |
| 9 |
|
| 10 |
$params = shortcode_new_to_old_params( $atts ); |
| 11 |
parse_str( $params, $arguments ); |
| 12 |
|
| 13 |
if ( empty( $arguments ) ) { |
| 14 |
return '<!-- SlideShare error: no arguments -->'; |
| 15 |
} |
| 16 |
|
| 17 |
extract( $arguments, EXTR_SKIP ); |
| 18 |
|
| 19 |
$pattern = '/[^-_a-zA-Z0-9]/'; |
| 20 |
if ( empty( $id ) || preg_match( $pattern, $id ) ) { |
| 21 |
return '<!-- SlideShare error: id is missing or has illegal characters -->'; |
| 22 |
} |
| 23 |
|
| 24 |
if ( empty( $doc ) || preg_match( $pattern, $doc ) ) { |
| 25 |
return '<!-- SlideShare error: doc is missing or has illegal characters -->'; |
| 26 |
} |
| 27 |
|
| 28 |
if ( empty( $w ) && !empty( $content_width ) ) { |
| 29 |
$w = intval( $content_width ); |
| 30 |
} elseif ( ! ( $w = intval( $w ) ) || $w < 300 || $w > 1600 ) { |
| 31 |
$w = 425; |
| 32 |
} else { |
| 33 |
$w = intval( $w ); |
| 34 |
} |
| 35 |
|
| 36 |
$h = ceil( $w * 348 / 425 ); |
| 37 |
|
| 38 |
$player = "<object type='application/x-shockwave-flash' wmode='opaque' data='http://static.slideshare.net/swf/ssplayer2.swf?id=$id&doc=$doc' width='$w' height='$h'><param name='movie' value='http://static.slideshare.net/swf/ssplayer2.swf?id=$id&doc=$doc' /><param name='allowFullScreen' value='true' /></object>"; |
| 39 |
|
| 40 |
if ( !empty( $type ) && $type == 'd' ) { |
| 41 |
$player = "<object style='margin: 0px;' width='$w' height='$h'><param name='movie' value='http://static.slidesharecdn.com/swf/ssplayerd.swf?doc=$doc' /><param name='allowFullScreen' value='true' /><param name='wmode' value='opaque' /><embed src='http://static.slidesharecdn.com/swf/ssplayerd.swf?doc=$doc' type='application/x-shockwave-flash' allowfullscreen='true' wmode='opaque' width='$w' height='$h'></embed></object>"; |
| 42 |
} |
| 43 |
|
| 44 |
return $player; |
| 45 |
} |
| 46 |
|
| 47 |
add_shortcode( 'slideshare', 'slideshare_shortcode' ); |
| 48 |
|