googlevideo.php 1.4 KB

1234567891011121314151617181920212223242526272829
  1. <?php
  2. /**
  3. * google video is replaced by youtube, but its embeds will probably continue working indefinitely.
  4. * [googlevideo=http://video.google.com/googleplayer.swf?docId=-6006084025483872237]
  5. */
  6. function googlevideo_shortcode( $atts ) {
  7. if ( !isset( $atts[0] ) )
  8. return '';
  9. $src = ltrim( $atts[0], '=' );
  10. if ( 0 !== strpos( $src, 'http://video.google.com/googleplayer.swf' ) ) {
  11. if ( !preg_match( '|^http://(video\.google\.[a-z]{2,3}(?:.[a-z]{2})?)/|', $src ) || !preg_match( '|.*docid=([0-9-]+).*|i', $src, $match ) || !is_numeric( $match[1] ) )
  12. return '<!--Google Video Error: bad URL entered-->';
  13. $src = 'http://video.google.com/googleplayer.swf?docId=' . $match[1];
  14. }
  15. // default width should be 400 unless the theme's content width is smaller than that
  16. global $content_width;
  17. $default_width = intval( !empty( $content_width ) ? min( $content_width, 400 ) : 400 );
  18. $height = intval( 0.825 * $default_width );
  19. $src = esc_attr( $src );
  20. return "<span style='text-align:center;display:block;'><object width='{$default_width}' height='{$height}' type='application/x-shockwave-flash' data='{$src}'><param name='allowScriptAccess' value='never' /><param name='movie' value='$src'/><param name='quality' value='best'/><param name='bgcolor' value='#ffffff' /><param name='scale' value='noScale' /><param name='wmode' value='opaque' /></object></span>";
  21. }
  22. add_shortcode( 'googlevideo', 'googlevideo_shortcode' );