-
Notifications
You must be signed in to change notification settings - Fork 0
/
flashmp3.php
executable file
·161 lines (133 loc) · 8.79 KB
/
flashmp3.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
159
160
161
<?php
if ( ! defined( 'MEDIAWIKI' ) )
die();
/*******************************************************************************
* *
* FlashMP3 Extension by Matthias Korn to embed a flash player with mp3-files *
* http://www.mediawiki.org/wiki/Extension:FlashMP3 *
* *
* This extension uses the Audio Player Wordpress plugin from 1pixelout *
* Download and unpack files audio-player.js and player.swf to your *
* extensions/FlashMP3 folder *
* *
* http://www.1pixelout.net/code/audio-player-wordpress-plugin/ *
* *
* Tag : *
* <flashmp3>mp3</flashmp3> *
* *
* Example : *
* with a local file *
* <flashmp3>music.mp3</flashmp3> *
* *
* Example : *
* with a remote file *
* <flashmp3>http://www.somedomain.com/mp3/music.mp3</flashmp3> *
* *
********************************************************************************/
$wgExtensionFunctions[] = 'wfFlashMP3';
$wgExtensionCredits['parserhook'][] = array(
'name' => 'FlashMP3',
'description' => 'Plays mp3-files in an embedded Flash-player',
'author' => 'Matthias Korn',
'url' => 'http://www.mediawiki.org/wiki/Extension:FlashMP3',
'version' => 'v0.92'
);
function wfFlashMP3() {
global $wgParser;
$wgParser->setHook('flashmp3', 'renderFlashMP3');
}
// The callback function for converting the input text to HTML output
function renderFlashMP3($input, $args) {
global $wgScriptPath;
$type = '1pixelout';
$id = 1;
$params = explode("|", htmlspecialchars($input));
$files = explode(",", array_shift($params));
$player_path = $wgScriptPath.'/extensions/FlashMP3/';
if (isset($args['type'])) {
$type = $args['type'];
}
switch ($type) {
case 'lastfm':
// concat the parameter string
$typeParameter = array_shift($params); // this is the resourceType
$param_string = implode('&', $params);
if (!empty($param_string)) {
$param_string = '&'.$param_string;
}
// try to figure out the resourceType
$resourceTypes['artist'] = 6;
$resourceTypes['album'] = 8;
$resourceTypes['song'] = 9;
$resourceTypes['playlist'] = 10;
$resourceTypes['label'] = 10;
if (is_numeric($typeParameter)) {
$resourceType = $typeParameter;
} else {
$resourceType = $resourceTypes[$typeParameter];
}
// the resourceID to play (either from an artist, song, playlist, ...)
$resourceID = $files[0];
// setting default title and cover
if (strpos($param_string, 'restTitle=') === false) {
$restTitle = '&restTitle=未设标题'; // TODO: you can set a default title here
}
if (strpos($param_string, 'albumArt=') === false) {
$albumArt = '&albumArt=http://img.moegirl.org/wikilogo.png'; // TODO: you can set a default cover here
}
$output .= '<object width="340" height="123">'
. '<param name="movie" value="http://static.last.fm/webclient/41/defaultEmbedPlayer.swf" />'
. '<param name="FlashVars" value="viral=true&lfmMode=playlist&resourceID='.$resourceID.'&resourceType='.$resourceType.$albumArt.$restTitle.$param_string.'" />'
. '<param name="wmode" value="transparent" />'
. '<embed src="http://static.last.fm/webclient/41/defaultEmbedPlayer.swf" width="340" '
. ' FlashVars="viral=true&lfmMode=playlist&resourceID='.$resourceID.'&resourceType='.$resourceType.$albumArt.$restTitle.$param_string.'"'
. ' height="123" wmode="transparent" type="application/x-shockwave-flash" />'
. '</object>';
break;
case '1pixelout':
default:
if (isset($args['id']) && preg_match('/^[a-z0-9]+$/iD', $args['id'])) {
$id = $args['id'];
}
// concat the file string for all files
$file_string = '';
$j = 0;
foreach ($files as $file) {
// get the intenral path if file is uploaded
if (strpos($file, "http://") !== 0 && strpos($file, "https://") !== 0) {
$title = Title::newFromText($file,NS_IMAGE);
if($title == NULL){
return FlashMP3NotFoundError($file);
}
$img = function_exists( 'wfFindFile' ) ? wfFindFile( $title ) : new Image( $title );
if ( $img ) {
$file = $img->getURL();
} else {
return flashMP3NotFoundError($file);
}
}
$file_string .= $file;
if ($j < count($files)-1) $file_string .= ',';
$j++;
}
// concat the parameter string
$param_string = implode('&', $params);
if (!empty($param_string)) $param_string .= '&';
$output = '<script language="JavaScript" src="'.$player_path.'audio-player.js"></script>'
. '<object type="application/x-shockwave-flash" data="'.$player_path.'player.swf" id="audioplayer'.$id.'" height="24" width="290">'
. '<param name="movie" value="'.$player_path.'player.swf">'
. '<param name="FlashVars" value="playerID='.$id.'&'.$param_string.'soundFile='.$file_string.'">'
. '<param name="quality" value="high">'
. '<param name="menu" value="false">'
. '<param name="wmode" value="transparent">'
. '</object>';
break;
}
return $output;
}
function flashMP3NotFoundError($input) {
return '<div style=\'border: solid red 1px\'>
<p align=center><b>噢噢~出错啦!: 萝莉 <code>'.$input.'</code> 没有被发现的说! </b> </p><br>
</div>';
}
?>