Created
March 3, 2015 03:44
-
-
Save Illvili/99cc1d3a7722d96ee663 to your computer and use it in GitHub Desktop.
MW mp3 resolve file url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! defined( 'MEDIAWIKI' ) ) | |
die(); | |
/******************************************************************************* | |
* * | |
* HTML5MP3 Extension is base on FlashMP3 * | |
* * | |
* FlashMP3 Extension by Matthias Korn to embed a flash player with mp3-files * | |
* https://www.mediawiki.org/wiki/Extension:FlashMP3 * | |
* * | |
* * | |
* 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[] = 'wfHTML5MP3'; | |
$wgExtensionCredits['parserhook'][] = array( | |
'name' => 'HTML5MP3', | |
'description' => 'Plays mp3-files in browser default player', | |
'author' => 'Illvili edit base on FlashMP3(Matthias Korn)', | |
'url' => 'https://www.mediawiki.org/wiki/Extension:FlashMP3', | |
'version' => 'v0.1' | |
); | |
function wfHTML5MP3() { | |
global $wgParser; | |
$wgParser->setHook('flashmp3', 'renderHTML5MP3'); | |
} | |
// The callback function for converting the input text to HTML output | |
function renderHTML5MP3($input, $args) { | |
global $wgScriptPath; | |
$params = explode("|", htmlspecialchars($input)); | |
$files = explode(",", array_shift($params)); | |
// 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++; | |
//} | |
if (empty($files)) return FlashMP3NotFoundError($file); | |
$file = $files[0]; | |
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; | |
// concat the parameter string | |
$param_string = implode('&', $params); | |
if (!empty($param_string)) $param_string .= '&'; | |
$output = '<audio class="html5mp3" src="' . $file_string . '" controls="yes" preload="none">您的浏览器可能不支持HTML5播放器</audio>'; | |
return $output; | |
} | |
function flashMP3NotFoundError($input) { | |
return '<div style=\'border: solid red 1px\'> | |
<p align=center><b>Error: file <code>'.$input.'</code> not found </b> </p><br> | |
</div>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment