PageRenderTime 33ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 41 lines | 15 code | 5 blank | 21 comment | 6 complexity | 0fd073ae75d6b5608fb8774f7de26ed1 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 Download Code
  4. *
  5. * Create code to allow a YouTube video to be downloaded
  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 $target Link target
  16. * @param string $nofollow Use rel="nofollow" ?
  17. * @param string $text Text to add link to
  18. * @return string URL
  19. */
  20. function ye_generate_download_code( $id ) {
  21. if ( $id == '' ) { return ye_error( 'No YouTube ID was found.' ); }
  22. // Extract the ID if a full URL has been specified
  23. $id = ye_extract_id( $id );
  24. // Check what type of video it is and whether it's valid
  25. $embed_type = ye_validate_id( $id );
  26. if ( $embed_type != 'v' ) {
  27. if ( strlen( $embed_type ) > 1 ) {
  28. return ye_error( $embed_type );
  29. } else {
  30. return ye_error( 'The YouTube ID of ' . $id . ' is invalid.' );
  31. }
  32. }
  33. // Create the link
  34. return 'http://www.savevid.com/?url=http://www.youtube.com/watch?' . $embed_type . '=' . $id;
  35. }
  36. ?>