PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/youtube-embed/includes/generate-thumbnail-code.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 62 lines | 30 code | 7 blank | 25 comment | 36 complexity | 7e2d03192753b4de2a2b25cfd6033454 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. /**
  3. * Generate Thumbnail Code
  4. *
  5. * Generate XHTML compatible YouTube video thumbnail
  6. *
  7. * @package YouTubeEmbed
  8. * @since 2.0
  9. *
  10. * @uses ye_extract_id Extract an ID from a string
  11. * @uses ye_validate_id Confirm the type of video
  12. * @uses ye_error Display an error
  13. *
  14. * @param string $id YouTube video ID
  15. * @param string $style Link STYLE
  16. * @param string $class Link CLASS
  17. * @param string $rel Link REL
  18. * @param string $target Link target
  19. * @param string $width Width
  20. * @param string $height Height
  21. * @param string $alt ALT text
  22. * @return string $youtube_code Code
  23. */
  24. function ye_generate_thumbnail_code( $id, $style, $class, $rel, $target, $width, $height, $alt, $version ) {
  25. // Extract the ID if a full URL has been specified
  26. $id = ye_extract_id( $id );
  27. // Check what type of video it is and whether it's valid
  28. $embed_type = ye_validate_id( $id );
  29. if ( $embed_type != 'v' ) {
  30. if ( strlen( $embed_type ) > 1 ) {
  31. return ye_error( $embed_type );
  32. } else {
  33. return ye_error( 'The YouTube ID of ' . $id . ' is invalid.' );
  34. }
  35. }
  36. $version = strtolower( $version );
  37. if ( ( $version != 'default' ) && ( $version != 'hq' ) && ( $version != 'start' ) && ( $version != 'middle' ) && ( $version != 'end' ) ) { $version = 'default'; }
  38. if ( $version == 'hq' ) { $version = 'hqdefault'; }
  39. if ( $version == 'start' ) { $version = 1; }
  40. if ( $version == 'middle' ) { $version = 2; }
  41. if ( $version == 'end' ) { $version = 3; }
  42. // Now create the required code
  43. if ( $alt == '' ) { $alt = 'YouTube Video ' . $id; }
  44. $youtube_code = '<a href="http://www.youtube.com/watch?v=' . $id . '"';
  45. if ( $style != '' ) { $youtube_code .= ' style="' . $style . '"'; }
  46. if ( $class != '' ) { $youtube_code .= ' class="' . $class . '"'; }
  47. if ( $rel != '' ) { $youtube_code .= ' rel="' . $rel . '"'; }
  48. if ( $target != '' ) { $youtube_code .= ' target="' . $target . '"'; }
  49. $youtube_code .= '><img src="http://img.youtube.com/vi/' . $id . '/' . $version . '.jpg"';
  50. if ( $width != '' ) { $youtube_code .= ' width="' . $width . 'px"'; }
  51. if ( $height != '' ) { $youtube_code .= ' height="' . $height . 'px"'; }
  52. $youtube_code .= ' alt="' . $alt . '"/></a>';
  53. return $youtube_code;
  54. }
  55. ?>