Jetpack_VideoPress_Shortcode

VideoPress Shortcode Handler.

Defined (1)

The class is defined in the following location(s).

/modules/videopress/shortcode.php  
  1. class Jetpack_VideoPress_Shortcode { 
  2. public $min_width = 60; 
  3.  
  4. /** 
  5. * Singleton 
  6. */ 
  7. public static function init() { 
  8. static $instance = false; 
  9.  
  10. if ( ! $instance ) 
  11. $instance = new Jetpack_VideoPress_Shortcode; 
  12.  
  13. return $instance; 
  14.  
  15. function __construct() { 
  16. add_shortcode( 'videopress', array( $this, 'shortcode_callback' ) ); 
  17. add_shortcode( 'wpvideo', array( $this, 'shortcode_callback' ) ); 
  18.  
  19. /** 
  20. * Translate a 'videopress' or 'wpvideo' shortcode and arguments into a video player display. 
  21. * @link http://codex.wordpress.org/Shortcode_API Shortcode API 
  22. * @param array $attr shortcode attributes 
  23. * @return string HTML markup or blank string on fail 
  24. */ 
  25. public function shortcode_callback( $attr, $content = '' ) { 
  26. global $content_width; 
  27.  
  28. $guid = $attr[0]; 
  29. if ( ! $this->is_valid_guid( $guid ) ) 
  30. return ''; 
  31.  
  32. $attr = shortcode_atts( array( 
  33. 'w' => 0,  
  34. 'h' => 0,  
  35. 'freedom' => false,  
  36. 'flashonly' => false,  
  37. 'autoplay' => false,  
  38. 'hd' => false,  
  39. 'permalink' => true,  
  40. 'loop' => false,  
  41. 'at' => 0,  
  42. 'defaultlangcode' => false,  
  43. ), $attr ); 
  44.  
  45. $attr['forcestatic'] = false; 
  46.  
  47. $attr['freedom'] = (bool) $attr['freedom']; 
  48. $attr['hd'] = (bool) $attr['hd']; 
  49. $attr['width'] = absint( $attr['w'] ); 
  50.  
  51. if ( $attr['width'] < $this->min_width ) 
  52. $attr['width'] = 0; 
  53. elseif ( isset( $content_width ) && $content_width > $this->min_width && $attr['width'] > $content_width ) 
  54. $attr['width'] = 0; 
  55.  
  56. if ( $attr['width'] === 0 && isset( $content_width ) && $content_width > $this->min_width ) 
  57. $attr['width'] = $content_width; 
  58.  
  59. if ( ( $attr['width'] % 2 ) === 1 ) 
  60. $attr['width']--; 
  61.  
  62. /** 
  63. * Filter the default VideoPress shortcode options. 
  64. * @module videopress 
  65. * @since 2.5.0 
  66. * @param array $args Array of VideoPress shortcode options. 
  67. */ 
  68. $options = apply_filters( 'videopress_shortcode_options', array( 
  69. 'freedom' => $attr['freedom'],  
  70. 'force_flash' => (bool) $attr['flashonly'],  
  71. 'autoplay' => $attr['autoplay'],  
  72. 'forcestatic' => $attr['forcestatic'],  
  73. 'hd' => $attr['hd'],  
  74. 'permalink' => $attr['permalink'],  
  75. 'loop' => $attr['autoplay'],  
  76. 'at' => (int) $attr['at'],  
  77. 'defaultlangcode' => $attr['defaultlangcode'] 
  78. ) ); 
  79.  
  80. // Enqueue VideoPress scripts 
  81. self::register_scripts(); 
  82.  
  83. require_once( dirname( __FILE__ ) . '/class.videopress-video.php' ); 
  84. require_once( dirname( __FILE__ ) . '/class.videopress-player.php' ); 
  85.  
  86. $player = new VideoPress_Player( $guid, $attr['width'], $options ); 
  87.  
  88. if ( is_feed() ) 
  89. return $player->asXML(); 
  90. else 
  91. return $player->asHTML(); 
  92.  
  93. /** 
  94. * Validate user-supplied guid values against expected inputs 
  95. * @since 1.1 
  96. * @param string $guid video identifier 
  97. * @return bool true if passes validation test 
  98. */ 
  99. public function is_valid_guid( $guid ) { 
  100. if ( ! empty( $guid ) && strlen( $guid ) === 8 && ctype_alnum( $guid ) ) 
  101. return true; 
  102. else 
  103. return false; 
  104.  
  105. /** 
  106. * Register scripts needed to play VideoPress videos. One of the player methods will 
  107. * enqueue thoe script if needed. 
  108. * @uses is_ssl() 
  109. * @uses wp_register_script() 
  110. * @return null 
  111. */ 
  112. public static function register_scripts() { 
  113. $js_url = ( is_ssl() ) ? 'https://v0.wordpress.com/js/videopress.js' : 'http://s0.videopress.com/js/videopress.js'; 
  114. wp_register_script( 'videopress', $js_url, array( 'jquery', 'swfobject' ), '1.09' ); 
  115.  
  116. /** 
  117. * Adds a `for` query parameter to the oembed provider request URL. 
  118. * @param String $oembed_provider 
  119. * @return String $ehnanced_oembed_provider 
  120. */ 
  121. public static function add_oembed_parameter( $oembed_provider ) { 
  122. if ( false === stripos( $oembed_provider, 'videopress.com' ) ) { 
  123. return $oembed_provider; 
  124. return add_query_arg( 'for', parse_url( home_url(), PHP_URL_HOST ), $oembed_provider );