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

Language PHP Lines 157
MD5 Hash 89cd21556b25d2c1ca22f233ab6736cd
Repository https://github.com/alniko009/magic.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
 * Audio shortcode
 */
class ctAudioShortcode extends ctShortcode {

	/**
	 * Returns name
	 * @return string|void
	 */
	public function getName() {
		return 'Audio';
	}

	/**
	 * Shortcode name
	 * @return string
	 */
	public function getShortcodeName() {
		return 'audio';
	}

	/**
	 * Add styles
	 */
	public function enqueueHeadScripts() {
		wp_register_style('ct-jplayer-style', CT_THEME_ASSETS . '/css/jplayer.css');
		wp_enqueue_style('ct-jplayer-style');
	}

	public function enqueueScripts() {
		wp_register_script('ct-jplayer', CT_THEME_ASSETS . '/js/jquery.jplayer.min.js', array('jquery'));
		wp_enqueue_script('ct-jplayer');
	}

	/**
	 * Handles shortcode
	 * @param $atts
	 * @param null $content
	 * @return string
	 */

	public function handle($atts, $content = null) {
		$attributes = shortcode_atts($this->extractShortcodeAttributes($atts), $atts);
		extract($attributes);

		$id = rand(100, 1000);
		$this->addInlineJS($this->getInlineJS($id, $attributes));
		return
				'<div id="jquery_jplayer_' . $id . '"  class="jp-jplayer" data-orig-width="' . $width . '" data-orig-height="' . $posterheight . '"></div>
		<div class="jp-audio" style="width:' . $width . 'px">
		  <div class="jp-type-single">
		    <div class="jp-gui jp-interface"  id="jp_interface_' . $id . '" >
		      <ul class="jp-controls">
		        <li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li>
		        <li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>
		        <li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li>
		        <li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li>
		        <li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a></li>
		        <li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li>
		      </ul>
		      <div class="jp-progress">
		        <div class="jp-seek-bar">
		          <div class="jp-play-bar"></div>
		        </div>
		      </div>
		      <div class="jp-volume-bar">
		        <div class="jp-volume-bar-value"></div>
		      </div>
		      <div class="jp-time-holder">
		        <div class="jp-current-time"></div>
		        <div class="jp-duration"></div>
		        <ul class="jp-toggles">
		          <li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a></li>
		          <li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat off</a></li>
		        </ul>
		      </div>
		    </div>
		    <div class="jp-no-solution">
		      <span>Update Required</span>
		      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>.
		    </div>
		  </div>
		</div>
		';
	}

	/**
	 * returns inline js
	 * @param $id
	 * @param $attributes
	 * @return string
	 */
	protected function getInlineJS($id, $attributes) {
		extract($attributes);

		$media = '';
		if ($poster != "") {
			$media .= 'poster:"' . $poster . '", ';
		}
		if ($mp3 != "") {
			$media .= 'mp3:"' . $mp3 . '", ';
		}
		if ($ogg != "") {
			$media .= 'oga:"' . $ogg . '", ';
		}

		$size = '';
		if (!empty($poster)) {
			$size = 'size:{
                        width:"' . $width . 'px",
                        height:"' . $posterheight . 'px"
                    },';
		}

		$supplied = '';
		if ($ogg != "") {
			$supplied .= 'oga, ';
		}
		if ($mp3 != "") {
			$supplied .= 'mp3, ';
		}

		return 'jQuery(document).ready(function (jQuery) {
		            if (jQuery().jPlayer) {
		                jQuery("#jquery_jplayer_' . $id . '").jPlayer({
		                    ready:function () {
		                        jQuery(this).jPlayer("setMedia", {
									' . $media . '
		                            end:""
		                        });
		                    },
							' . $size . '
		                    swfPath:"' . get_template_directory_uri() . '/js",
		                    cssSelectorAncestor:"#jp_interface_' . $id . '",
		                    supplied:"' . $supplied . 'all"
		                });
		            }
		        });';
	}

	/**
	 * Returns config
	 * @return null
	 */
	public function getAttributes() {
		return array(
			'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"),
			'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"),
			'poster' => array('default' => '500', 'type' => 'input', 'label' => __('poster link', 'ct_theme')),
			'posterheight' => array('default' => '', 'type' => 'input', 'label' => __('poster height', 'ct_theme')),
			'width' => array('default' => '500', 'type' => 'input', 'label' => __('Width', 'ct_theme')),
		);
	}
}

new ctAudioShortcode();
Back to Top