summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/media.php31
-rw-r--r--inc/parser/xhtml.php45
2 files changed, 59 insertions, 17 deletions
diff --git a/inc/media.php b/inc/media.php
index 437a8d75f..5c84bed4b 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -2138,6 +2138,7 @@ function media_resize_imageGD($ext,$from,$from_w,$from_h,$to,$to_w,$to_h,$ofs_x=
*
* @param string $src - ID of media file
* @param array $exts - alternative extensions to find other files for
+ * @return array - mime type => file ID
*
* @author Anika Henke <anika@selfthinker.org>
*/
@@ -2158,4 +2159,34 @@ function media_alternativefiles($src, $exts){
return $files;
}
+/**
+ * Check if video/audio is supported to be embedded.
+ *
+ * @param string $src - mimetype of media file
+ * @param string $type - type of media files to check ('video', 'audio', or none)
+ * @return boolean
+ *
+ * @author Anika Henke <anika@selfthinker.org>
+ */
+function media_supportedav($mime, $type=NULL){
+ $supportedAudio = array(
+ 'ogg' => 'audio/ogg',
+ 'mp3' => 'audio/mpeg',
+ 'wav' => 'audio/wav',
+ );
+ $supportedVideo = array(
+ 'webm' => 'video/webm',
+ 'ogv' => 'video/ogg',
+ 'mp4' => 'video/mp4',
+ );
+ if ($type == 'audio') {
+ $supportedAv = $supportedAudio;
+ } elseif ($type == 'video') {
+ $supportedAv = $supportedVideo;
+ } else {
+ $supportedAv = array_merge($supportedAudio, $supportedVideo);
+ }
+ return in_array($mime, $supportedAv);
+}
+
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index 05472db1d..32aa99a1b 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -783,7 +783,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
}
function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
- $height=NULL, $cache=NULL, $linking=NULL) {
+ $height=NULL, $cache=NULL, $linking=NULL, $return=NULL) {
global $ID;
list($src,$hash) = explode('#',$src,2);
resolve_mediaid(getNS($ID),$src, $exists);
@@ -795,7 +795,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
list($ext,$mime,$dl) = mimetype($src,false);
if(substr($mime,0,5) == 'image' && $render){
$link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
- }elseif(($mime == 'application/x-shockwave-flash' || substr($mime,0,5) == 'video') && $render){
+ }elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render){
// don't link movies
$noLink = true;
}else{
@@ -814,8 +814,13 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
}
//output formatted
- if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
- else $this->doc .= $this->_formatLink($link);
+ if ($return) {
+ if ($linking == 'nolink' || $noLink) return $link['name'];
+ else return $this->_formatLink($link);
+ } else {
+ if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
+ else $this->doc .= $this->_formatLink($link);
+ }
}
function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
@@ -831,7 +836,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
if(substr($mime,0,5) == 'image' && $render){
// link only jpeg images
// if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
- }elseif(($mime == 'application/x-shockwave-flash' || substr($mime,0,5) == 'video') && $render){
+ }elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render){
// don't link movies
$noLink = true;
}else{
@@ -1093,7 +1098,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$ret .= ' />';
- }elseif($mime == 'video/webm' || $mime == 'video/ogg' || $mime == 'video/mp4' ){
+ }elseif(media_supportedav($mime, 'video')){
// first get the $title
if (!is_null($title)) {
$title = $this->_xmlEntities($title);
@@ -1114,7 +1119,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
//add video(s)
$ret .= $this->_video($src, $width, $height, $att);
- }elseif($mime == 'audio/ogg' || $mime == 'audio/mpeg' || $mime == 'audio/wav' ){
+ }elseif(media_supportedav($mime, 'audio')){
// first get the $title
if (!is_null($title)) {
$title = $this->_xmlEntities($title);
@@ -1277,6 +1282,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
* @param int $width - width of the video in pixels
* @param int $height - height of the video in pixels
* @param array $atts - additional attributes for the <video> tag
+ * @return string
*/
function _video($src,$width,$height,$atts=null){
@@ -1296,23 +1302,25 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$posterUrl = ml(reset($poster),array('cache'=>$cache),true,'&');
}
+ $out = '';
// open video tag
- $this->doc .= '<video '.buildAttributes($atts).' controls="controls"';
- if ($posterUrl) $this->doc .= ' poster="'.$posterUrl.'"';
- $this->doc .= '>'.NL;
+ $out .= '<video '.buildAttributes($atts).' controls="controls"';
+ if ($posterUrl) $out .= ' poster="'.$posterUrl.'"';
+ $out .= '>'.NL;
// output source for each alternative video format
foreach($alternatives as $mime => $file) {
$url = ml($file,array('cache'=>$cache),true,'&');
$title = $this->_xmlEntities(utf8_basename(noNS($file)));
- $this->doc .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL;
+ $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL;
// alternative content (just a link to the file)
- $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly');
+ $out .= $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly', $return=true);
}
// finish
- $this->doc .= '</video>'.NL;
+ $out .= '</video>'.NL;
+ return $out;
}
/**
@@ -1322,6 +1330,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
*
* @param string $src - ID of audio to embed
* @param array $atts - additional attributes for the <audio> tag
+ * @return string
*/
function _audio($src,$atts=null){
@@ -1329,21 +1338,23 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$extensions = array('ogg', 'mp3', 'wav');
$alternatives = media_alternativefiles($src, $extensions);
+ $out = '';
// open audio tag
- $this->doc .= '<audio '.buildAttributes($atts).' controls="controls">'.NL;
+ $out .= '<audio '.buildAttributes($atts).' controls="controls">'.NL;
// output source for each alternative audio format
foreach($alternatives as $mime => $file) {
$url = ml($file,array('cache'=>$cache),true,'&');
$title = $this->_xmlEntities(utf8_basename(noNS($file)));
- $this->doc .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL;
+ $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL;
// alternative content (just a link to the file)
- $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly');
+ $out .= $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly', $return=true);
}
// finish
- $this->doc .= '</audio>'.NL;
+ $out .= '</audio>'.NL;
+ return $out;
}
}