forked from argoproject/argo-audio-player
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathargo-audio-player.php
executable file
·158 lines (136 loc) · 4.75 KB
/
argo-audio-player.php
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
158
<?php
/**
* @package Argo_Audio_Player
* @version 1.1
*/
/*
Plugin Name: Argo Audio Player
Plugin URI: https://github.com/argoproject/argo-audio-player
Description: The Argo Audio Player Plugin.
Author: Project Argo, Mission Data
Version: 1.1
Author URI:
License: GPLv2
*/
/* The Argo Audio Player Plugin class - so we don't have function naming conflicts */
class ArgoAudioPlayer {
/* Initialize the plugin */
function init() {
/**
* Add the "audio" shortcode for use in posts
* We call all other functions from within the argo_audio_shortcode function
* so that we only load the plugin assets if they are needed
* ie the shortcode is used on a page
*/
/* Override the default add audio link to post action*/
add_filter( 'audio_send_to_editor_url', array(__CLASS__, 'argo_audio_editor_shortcode'), 10, 3 );
add_filter( 'media_send_to_editor', array(__CLASS__, 'argo_audio_editor_media_gallery_shortcode'), 10, 3 );
/* Add action to enqueue the jquery file for loading (this is called before the header loads)*/
add_action('get_header', array(__CLASS__,'ArgoGetWPHeader'));
add_action('wp_print_styles' ,array(__CLASS__, 'add_styles'));
add_action('init',array(__CLASS__, 'add_audio_shortcode'));
}
function add_audio_shortcode() {
add_shortcode( 'audio', array(__CLASS__,'argo_audio_shortcode'));
}
/* Make sure the jQuery is queued up to be loaded, because we need it! */
function ArgoGetWPHeader() {
wp_enqueue_script("jquery");
}
/* Always load the css into the wp header, the only way it works right*/
function add_styles() {
$css = plugins_url('css/argo-audio-player.css', __FILE__);
wp_enqueue_style('argo-audio-player', $css, array(), 1);
}
/* Inserts the needed code into the themes footer */
function ArgoWPFooter() {
/* Load up the SoundManager 2 javascript files into the footer */
echo "<script src='".plugins_url(null,__FILE__)."/js/sm.min.js'></script>";
echo "<script src='".plugins_url(null, __FILE__)."/js/sm.playlist.js'></script>";
/* Setup the SoundManager 2 swf directories*/
echo "<script>
soundManager.url = '".plugins_url(null,__FILE__)."/swf/';
function setTheme(sTheme) {
var o = document.getElementsByTagName('ul')[0];
o.className = 'playlist'+(sTheme?' '+sTheme:'');
return false;
}
soundManager.onready(function() {
// SM2 is ready to play audio!
});
</script>";
}
/*
* DISABLE DEFAULT FUNCTIONALITY
*/
function disable_builtin_caption( $shcode, $html ) {
return $html;
}
//add_filter( 'image_add_caption_shortcode', 'disable_builtin_caption', 15, 2 );
/*
* END DISABLE DEFAULT FUNCTIONALITY
*/
/*
* AUDIO EDITOR MARKUP CUSTOMIZATIONS
*/
function argo_audio_editor_markup( $href, $title, $caption ) {
$out = sprintf( '<ul class="%s"><li>', 'playlist' );
$out .= sprintf( '<a href="%s" class="%s" title="%s">%s', $href, 'inline', $title, $title );
if ( $caption ) {
$out .= sprintf( '<span class="%s">%s</span></a>', 'caption', $caption );
}
$out .= sprintf( '<a href="%s" class="%s">%s</a>', $href, 'exclude', 'Download' );
$out .= "</li></ul>";
return $out;
}
/*
* SHORTCODES
*/
function argo_audio_shortcode( $atts, $content ) {
extract( $atts );
/* Insert needed code into the footer */
add_action('wp_footer',array(__CLASS__,'ArgoWPFooter'));
$html = ArgoAudioPlayer::argo_audio_editor_markup( $href, $title, $content );
return $html;
}
// construct shortcode for audio embeds
function argo_audio_editor_shortcode( $html, $href, $title ) {
return sprintf( '[audio href="%s" title="%s"]Insert caption here[/audio]', $href, $title );
}
// construct shortcode for audio embeds
function argo_audio_editor_media_gallery_shortcode( $html, $send_id, $attachment ) {
$title = '';
$href = '';
if (preg_match("/\.mp3|\.ogg|\.mp4|\.wav|\.m4a/",$html)) {
/* Get the title from the html */
preg_match("/\>.+\</",$html,$title);
$title = $title[0];
$title = preg_replace("/\>|\</","",$title);
$title = preg_replace("/_/"," ",$title);
/* Get the url of the file from the html */
preg_match("/\'.+\'/",$html,$href);
$href = $href[0];
$href = preg_replace("/\'/","",$href);
return sprintf( '[audio href="%s" title="%s"]Insert caption here[/audio]', $href, $title );
} else {
return $html;
}
}
/*
* ADMIN PRESENTATION CUSTOMIZATIONS
*/
function argo_tweak_upload_tabs( $defaults ) {
if ( array_key_exists( 'gallery', $defaults ) ) {
unset( $defaults[ 'gallery' ] );
}
return $defaults;
}
// XXX: it does more harm than good to comment this out.
//add_filter( 'media_upload_tabs', 'argo_tweak_upload_tabs', 12, 1 );
/*
* END ADMIN PRESENTATION CUSTOMIZATIONS
*/
}
/* Initialize the plugin using it's init() function */
ArgoAudioPlayer::init();
?>