PageRenderTime 69ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/shortcodes-ultimate/lib/media.php

https://bitbucket.org/gregbenner/the-league-of-gentlemen-theme
PHP | 66 lines | 38 code | 15 blank | 13 comment | 13 complexity | ff2e05f335ccf530189c3ecc4d2d4613 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * Get media object by url
  4. *
  5. * @param string $media_url Media file url
  6. * @param int $width Media object width
  7. * @param int $height Media object height
  8. * @return string Object markup
  9. */
  10. function su_get_media( $media_url, $width, $height, $jwplayer = false ) {
  11. // Youtube video
  12. $video_url = parse_url( $media_url );
  13. if ( $video_url['host'] == 'youtube.com' || $video_url['host'] == 'www.youtube.com' ) {
  14. parse_str( $video_url['query'], $youtube );
  15. $id = uniqid( '', false );
  16. $return = '
  17. <iframe width="' . $width . '" height="' . $height . '" src="http://www.youtube.com/embed/' . $youtube['v'] . '" frameborder="0" allowfullscreen="true"></iframe>
  18. ';
  19. }
  20. // Vimeo video
  21. $video_url = parse_url( $media_url );
  22. if ( $video_url['host'] == 'vimeo.com' || $video_url['host'] == 'www.vimeo.com' ) {
  23. $vimeo_id = mb_substr( $video_url['path'], 1 );
  24. $return = '<iframe src="http://player.vimeo.com/video/' . $vimeo_id . '?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff" width="' . $width . '" height="' . $height . '" frameborder="0"></iframe>';
  25. }
  26. // Images (bmp/jpg/jpeg/png/gif)
  27. $images = array( '.bmp', '.BMP', '.jpg', '.JPG', '.png', '.PNG', 'jpeg', 'JPEG', '.gif', '.GIF' );
  28. $image_ext = mb_substr( $media_url, -4 );
  29. if ( in_array( $image_ext, $images ) ) {
  30. $return = '<img src="' . su_plugin_url() . '/lib/timthumb.php?src=' . $media_url . '&amp;w=' . $width . '&amp;h=' . $height . '&amp;zc=1&amp;q=100" alt="" width="' . $width . '" height="' . $height . '" />';
  31. }
  32. // Video file (mp4/flv)
  33. $videos = array( '.mp4', '.MP4', '.flv', '.FLV' );
  34. $video_ext = mb_substr( $media_url, -4 );
  35. if ( in_array( $video_ext, $videos ) ) {
  36. $player_id = uniqid( '_', false );
  37. if ( is_array( $jwplayer ) ) {
  38. foreach ( $jwplayer as $jwplayer_option => $jwplayer_value ) {
  39. $jwplayer_options .= ',' . $jwplayer_option . ':"' . $jwplayer_value . '"';
  40. }
  41. }
  42. $return = '<div id="player' . $player_id . '"><script type="text/javascript">jwplayer("player' . $player_id . '").setup({flashplayer:"' . su_plugin_url() . '/lib/player.swf",file:"' . $media_url . '",height:' . $height . ',width:' . $width . $jwplayer_options . '});</script></div>';
  43. }
  44. // Audio file (mp3)
  45. if ( mb_substr( $media_url, -4 ) == '.mp3' ) {
  46. $player_id = uniqid( '_', false );
  47. $return = '<div id="player' . $player_id . '"><script type="text/javascript">jwplayer("player' . $player_id . '").setup({flashplayer:"' . su_plugin_url() . '/lib/player.swf",file:"' . $media_url . '",height: ' . $height . ',width:' . $width . ',controlbar:"bottom",image:"' . su_plugin_url() . '/images/media-audio.jpg",icons:"none",screencolor:"F0F0F0"});</script></div>';
  48. }
  49. return $return;
  50. }
  51. ?>