PageRenderTime 60ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/nonus/theme/shortcodes/video/ctVideoShortcode.class.php

https://github.com/alniko009/magic
PHP | 205 lines | 152 code | 23 blank | 30 comment | 20 complexity | f25e3444e2c17afa6331e364ca96fff1 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Video shortcode
  4. */
  5. class ctVideoShortcode extends ctShortcode {
  6. /**
  7. * Returns name
  8. * @return string|void
  9. */
  10. public function getName() {
  11. return 'Video';
  12. }
  13. /**
  14. * Shortcode name
  15. * @return string
  16. */
  17. public function getShortcodeName() {
  18. return 'video';
  19. }
  20. /**
  21. * Add styles
  22. */
  23. public function enqueueHeadScripts() {
  24. wp_register_style('ct-jplayer-style', CT_THEME_ASSETS . '/css/jplayer.css');
  25. wp_enqueue_style('ct-jplayer-style');
  26. }
  27. public function enqueueScripts() {
  28. wp_register_script('ct-jplayer', CT_THEME_ASSETS . '/js/jquery.jplayer.min.js', array('jquery'));
  29. wp_enqueue_script('ct-jplayer');
  30. }
  31. /**
  32. * Handles shortcode
  33. * @param $atts
  34. * @param null $content
  35. * @return string
  36. */
  37. public function handle($atts, $content = null) {
  38. $attributes = shortcode_atts($this->extractShortcodeAttributes($atts), $atts);
  39. extract($attributes);
  40. if ($m4v || $ogv) {
  41. $id = rand(100, 1000);
  42. $this->addInlineJS($this->getInlineJS($id, $attributes));
  43. return
  44. '<div id="jquery_jplayer_' . $id . '" class="jp-jplayer" data-orig-width="' . $width . '" data-orig-height="' . $height . '"></div>
  45. <div class="video jp-audio" style="width:' . $width . '">
  46. <div class="jp-type-single">
  47. <div class="jp-gui jp-interface" id="jp_interface_' . $id . '" >
  48. <ul class="jp-controls">
  49. <li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li>
  50. <li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>
  51. <li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li>
  52. <li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li>
  53. <li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a></li>
  54. <li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li>
  55. </ul>
  56. <div class="jp-progress">
  57. <div class="jp-seek-bar">
  58. <div class="jp-play-bar"></div>
  59. </div>
  60. </div>
  61. <div class="jp-volume-bar">
  62. <div class="jp-volume-bar-value"></div>
  63. </div>
  64. <div class="jp-time-holder">
  65. <div class="jp-current-time"></div>
  66. <div class="jp-duration"></div>
  67. <ul class="jp-toggles">
  68. <li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a></li>
  69. <li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat off</a></li>
  70. </ul>
  71. </div>
  72. </div>
  73. <div class="jp-no-solution">
  74. <span>Update Required</span>
  75. To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.
  76. </div>
  77. </div>
  78. </div>
  79. ';
  80. }
  81. if ($link) {
  82. global $wp_embed;
  83. return $wp_embed->run_shortcode('<div class="videoFrameContainer">[embed]' . $link . '[/embed]</div>');
  84. }
  85. if (!$clipid && !$src) {
  86. return '';
  87. }
  88. $url = '';
  89. switch ($type) {
  90. case 'youtube':
  91. $url = 'http://www.youtube.com/embed/' . $clipid;
  92. break;
  93. case 'vimeo':
  94. $url = 'http://player.vimeo.com/video/' . $clipid;
  95. break;
  96. case 'dailymotion':
  97. $url = 'http://www.dailymotion.com/embed/video/' . $clipid;
  98. break;
  99. case 'flash':
  100. return '<div class="videoFrameContainer">
  101. <object class="flash" width="' . $width . '" height="' . $height . '" type="application/x-shockwave-flash" data="' . $src . '">
  102. <param name="movie" value="' . $src . '" />
  103. <param name="allowFullScreen" value="true" />
  104. <param name="allowscriptaccess" value="always" />
  105. <param name="play" value="false"/>
  106. <param name="wmode" value="transparent" />
  107. <embed src="' . $src . '" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" width="' . $width . '" height="' . $height . '" />
  108. </object>
  109. </div>';
  110. }
  111. if ($params) {
  112. $url .= '?' . $params;
  113. }
  114. $style = 'max-height:' . $height . ';max-width:' . $width . ';';
  115. if (isset($atts['fullscreen'])) {
  116. $style = '';
  117. }
  118. return "<iframe src='{$url}' style='{$style}' class='{$type}' width='$width' height='$height' frameborder='0'></iframe>";
  119. }
  120. /**
  121. * returns inline js
  122. * @param $id
  123. * @param $attributes
  124. * @return string
  125. */
  126. protected function getInlineJS($id, $attributes) {
  127. extract($attributes);
  128. $media = '';
  129. if ($m4v != "") {
  130. $media .= 'm4v:"' . $m4v . '", ';
  131. }
  132. if ($ogv != "") {
  133. $media .= 'ogv:"' . $ogv . '", ';
  134. }
  135. $supplied = '';
  136. if ($m4v != "") {
  137. $supplied .= 'm4v, ';
  138. }
  139. if ($ogv != "") {
  140. $supplied .= 'ogv, ';
  141. }
  142. $autoparam = $autoplay == 'false' ? '.jPlayer("pause",0.1)' : '.jPlayer("play")';
  143. return 'jQuery(document).ready(function (jQuery) {
  144. if (jQuery().jPlayer) {
  145. jQuery("#jquery_jplayer_' . $id . '").jPlayer({
  146. ready:function () {
  147. jQuery(this).jPlayer("setMedia", {
  148. ' . $media . '
  149. end:""
  150. })'.$autoparam.';
  151. },
  152. size:{
  153. width:"' . $width . '",
  154. height:"' . $height . '"
  155. },
  156. swfPath:"' . get_template_directory_uri() . '/js",
  157. cssSelectorAncestor:"#jp_interface_' . $id . '",
  158. supplied:"' . $supplied . 'all"
  159. });
  160. }
  161. });';
  162. }
  163. /**
  164. * Returns config
  165. * @return null
  166. */
  167. public function getAttributes() {
  168. return array(
  169. 'link' => array('default' => '', 'type' => 'input', 'label' => __('Link', 'ct_theme'), 'help' => __('Direct movie link', 'ct_theme'), 'example' => "http://www.youtube.com/watch?v=Vpg9yizPP_g"),
  170. 'type' => array('default' => 'youtube', 'type' => 'select', 'choices' => array('youtube' => 'Youtube', 'vimeo' => 'Vimeo', 'dailymotion' => 'Dailymotion', 'flash' => 'Flash'), 'label' => __('Type', 'ct_theme'), 'help' => __('Video type (used only if link not given)', 'ct_theme')),
  171. 'clipid' => array('default' => '', 'type' => 'input', 'label' => __('Clip id', 'ct_theme'), 'help' => __("Used for Youtube, Vimeo and Dailymotion used only if link not given)", "ct_theme")),
  172. 'src' => array('default' => '', 'type' => 'input', 'label' => __('Flash movie source', 'ct_theme'), 'help' => __("Used only for flash movies", "ct_theme")),
  173. 'm4v' => array('default' => '', 'type' => 'input', 'label' => __('M4V URL', 'ct_theme'), 'help' => __(".m4v self hosted video url", "ct_theme")),
  174. 'ogv' => array('default' => '', 'type' => 'input', 'label' => __('OGV URL', 'ct_theme'), 'help' => __(".ogv self hosted video url", "ct_theme")),
  175. 'width' => array('default' => '500px', 'type' => 'input', 'label' => __('Width', 'ct_theme')),
  176. 'height' => array('default' => '300px', 'type' => 'input', 'label' => __('Height', 'ct_theme')),
  177. 'autoplay' => array('label' => __('autoplay', 'ct_theme'), 'type' => "checkbox", 'default' => 'false', 'help' => __('Autoplay video?', 'ct_theme')),
  178. 'params' => array('default' => '', 'type' => "input", 'label' => __("Additional params", 'ct_theme'), 'help' => __("Params which will be added to url like: type=1&full=1"))
  179. );
  180. }
  181. }
  182. new ctVideoShortcode();