PageRenderTime 137ms CodeModel.GetById 51ms app.highlight 6ms RepoModel.GetById 24ms app.codeStats 0ms

/wp-content/themes/nonus/theme/shortcodes/audio/ctAudioShortcode.class.php

https://github.com/alniko009/magic
PHP | 157 lines | 113 code | 14 blank | 30 comment | 11 complexity | 89cd21556b25d2c1ca22f233ab6736cd MD5 | raw file
  1<?php
  2/**
  3 * Audio shortcode
  4 */
  5class ctAudioShortcode extends ctShortcode {
  6
  7	/**
  8	 * Returns name
  9	 * @return string|void
 10	 */
 11	public function getName() {
 12		return 'Audio';
 13	}
 14
 15	/**
 16	 * Shortcode name
 17	 * @return string
 18	 */
 19	public function getShortcodeName() {
 20		return 'audio';
 21	}
 22
 23	/**
 24	 * Add styles
 25	 */
 26	public function enqueueHeadScripts() {
 27		wp_register_style('ct-jplayer-style', CT_THEME_ASSETS . '/css/jplayer.css');
 28		wp_enqueue_style('ct-jplayer-style');
 29	}
 30
 31	public function enqueueScripts() {
 32		wp_register_script('ct-jplayer', CT_THEME_ASSETS . '/js/jquery.jplayer.min.js', array('jquery'));
 33		wp_enqueue_script('ct-jplayer');
 34	}
 35
 36	/**
 37	 * Handles shortcode
 38	 * @param $atts
 39	 * @param null $content
 40	 * @return string
 41	 */
 42
 43	public function handle($atts, $content = null) {
 44		$attributes = shortcode_atts($this->extractShortcodeAttributes($atts), $atts);
 45		extract($attributes);
 46
 47		$id = rand(100, 1000);
 48		$this->addInlineJS($this->getInlineJS($id, $attributes));
 49		return
 50				'<div id="jquery_jplayer_' . $id . '"  class="jp-jplayer" data-orig-width="' . $width . '" data-orig-height="' . $posterheight . '"></div>
 51		<div class="jp-audio" style="width:' . $width . 'px">
 52		  <div class="jp-type-single">
 53		    <div class="jp-gui jp-interface"  id="jp_interface_' . $id . '" >
 54		      <ul class="jp-controls">
 55		        <li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li>
 56		        <li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>
 57		        <li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li>
 58		        <li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li>
 59		        <li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a></li>
 60		        <li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li>
 61		      </ul>
 62		      <div class="jp-progress">
 63		        <div class="jp-seek-bar">
 64		          <div class="jp-play-bar"></div>
 65		        </div>
 66		      </div>
 67		      <div class="jp-volume-bar">
 68		        <div class="jp-volume-bar-value"></div>
 69		      </div>
 70		      <div class="jp-time-holder">
 71		        <div class="jp-current-time"></div>
 72		        <div class="jp-duration"></div>
 73		        <ul class="jp-toggles">
 74		          <li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a></li>
 75		          <li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat off</a></li>
 76		        </ul>
 77		      </div>
 78		    </div>
 79		    <div class="jp-no-solution">
 80		      <span>Update Required</span>
 81		      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>.
 82		    </div>
 83		  </div>
 84		</div>
 85		';
 86	}
 87
 88	/**
 89	 * returns inline js
 90	 * @param $id
 91	 * @param $attributes
 92	 * @return string
 93	 */
 94	protected function getInlineJS($id, $attributes) {
 95		extract($attributes);
 96
 97		$media = '';
 98		if ($poster != "") {
 99			$media .= 'poster:"' . $poster . '", ';
100		}
101		if ($mp3 != "") {
102			$media .= 'mp3:"' . $mp3 . '", ';
103		}
104		if ($ogg != "") {
105			$media .= 'oga:"' . $ogg . '", ';
106		}
107
108		$size = '';
109		if (!empty($poster)) {
110			$size = 'size:{
111                        width:"' . $width . 'px",
112                        height:"' . $posterheight . 'px"
113                    },';
114		}
115
116		$supplied = '';
117		if ($ogg != "") {
118			$supplied .= 'oga, ';
119		}
120		if ($mp3 != "") {
121			$supplied .= 'mp3, ';
122		}
123
124		return 'jQuery(document).ready(function (jQuery) {
125		            if (jQuery().jPlayer) {
126		                jQuery("#jquery_jplayer_' . $id . '").jPlayer({
127		                    ready:function () {
128		                        jQuery(this).jPlayer("setMedia", {
129									' . $media . '
130		                            end:""
131		                        });
132		                    },
133							' . $size . '
134		                    swfPath:"' . get_template_directory_uri() . '/js",
135		                    cssSelectorAncestor:"#jp_interface_' . $id . '",
136		                    supplied:"' . $supplied . 'all"
137		                });
138		            }
139		        });';
140	}
141
142	/**
143	 * Returns config
144	 * @return null
145	 */
146	public function getAttributes() {
147		return array(
148			'mp3' => array('default' => '', 'type' => 'input', 'label' => __('mp3 file link', 'ct_theme'), 'help' => __('Direct link to .mp3 file', 'ct_theme'), 'example' => "http://www.jplayer.org/audio/mp3/Miaow-07-Bubble.mp3"),
149			'ogg' => array('default' => '', 'type' => 'input', 'label' => __('ogg file link', 'ct_theme'), 'help' => __('Direct link to .ogg, .oga file', 'ct_theme'), 'example' => "http://www.jplayer.org/audio/ogg/Miaow-07-Bubble.ogg"),
150			'poster' => array('default' => '500', 'type' => 'input', 'label' => __('poster link', 'ct_theme')),
151			'posterheight' => array('default' => '', 'type' => 'input', 'label' => __('poster height', 'ct_theme')),
152			'width' => array('default' => '500', 'type' => 'input', 'label' => __('Width', 'ct_theme')),
153		);
154	}
155}
156
157new ctAudioShortcode();