PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 1ms 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
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Audio shortcode
  4. */
  5. class ctAudioShortcode extends ctShortcode {
  6. /**
  7. * Returns name
  8. * @return string|void
  9. */
  10. public function getName() {
  11. return 'Audio';
  12. }
  13. /**
  14. * Shortcode name
  15. * @return string
  16. */
  17. public function getShortcodeName() {
  18. return 'audio';
  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. $id = rand(100, 1000);
  41. $this->addInlineJS($this->getInlineJS($id, $attributes));
  42. return
  43. '<div id="jquery_jplayer_' . $id . '" class="jp-jplayer" data-orig-width="' . $width . '" data-orig-height="' . $posterheight . '"></div>
  44. <div class="jp-audio" style="width:' . $width . 'px">
  45. <div class="jp-type-single">
  46. <div class="jp-gui jp-interface" id="jp_interface_' . $id . '" >
  47. <ul class="jp-controls">
  48. <li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li>
  49. <li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>
  50. <li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li>
  51. <li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li>
  52. <li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a></li>
  53. <li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li>
  54. </ul>
  55. <div class="jp-progress">
  56. <div class="jp-seek-bar">
  57. <div class="jp-play-bar"></div>
  58. </div>
  59. </div>
  60. <div class="jp-volume-bar">
  61. <div class="jp-volume-bar-value"></div>
  62. </div>
  63. <div class="jp-time-holder">
  64. <div class="jp-current-time"></div>
  65. <div class="jp-duration"></div>
  66. <ul class="jp-toggles">
  67. <li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a></li>
  68. <li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat off</a></li>
  69. </ul>
  70. </div>
  71. </div>
  72. <div class="jp-no-solution">
  73. <span>Update Required</span>
  74. 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>.
  75. </div>
  76. </div>
  77. </div>
  78. ';
  79. }
  80. /**
  81. * returns inline js
  82. * @param $id
  83. * @param $attributes
  84. * @return string
  85. */
  86. protected function getInlineJS($id, $attributes) {
  87. extract($attributes);
  88. $media = '';
  89. if ($poster != "") {
  90. $media .= 'poster:"' . $poster . '", ';
  91. }
  92. if ($mp3 != "") {
  93. $media .= 'mp3:"' . $mp3 . '", ';
  94. }
  95. if ($ogg != "") {
  96. $media .= 'oga:"' . $ogg . '", ';
  97. }
  98. $size = '';
  99. if (!empty($poster)) {
  100. $size = 'size:{
  101. width:"' . $width . 'px",
  102. height:"' . $posterheight . 'px"
  103. },';
  104. }
  105. $supplied = '';
  106. if ($ogg != "") {
  107. $supplied .= 'oga, ';
  108. }
  109. if ($mp3 != "") {
  110. $supplied .= 'mp3, ';
  111. }
  112. return 'jQuery(document).ready(function (jQuery) {
  113. if (jQuery().jPlayer) {
  114. jQuery("#jquery_jplayer_' . $id . '").jPlayer({
  115. ready:function () {
  116. jQuery(this).jPlayer("setMedia", {
  117. ' . $media . '
  118. end:""
  119. });
  120. },
  121. ' . $size . '
  122. swfPath:"' . get_template_directory_uri() . '/js",
  123. cssSelectorAncestor:"#jp_interface_' . $id . '",
  124. supplied:"' . $supplied . 'all"
  125. });
  126. }
  127. });';
  128. }
  129. /**
  130. * Returns config
  131. * @return null
  132. */
  133. public function getAttributes() {
  134. return array(
  135. '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"),
  136. '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"),
  137. 'poster' => array('default' => '500', 'type' => 'input', 'label' => __('poster link', 'ct_theme')),
  138. 'posterheight' => array('default' => '', 'type' => 'input', 'label' => __('poster height', 'ct_theme')),
  139. 'width' => array('default' => '500', 'type' => 'input', 'label' => __('Width', 'ct_theme')),
  140. );
  141. }
  142. }
  143. new ctAudioShortcode();