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