summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnika Henke <anika@selfthinker.org>2013-08-03 14:34:17 +0100
committerAnika Henke <anika@selfthinker.org>2013-08-03 14:34:17 +0100
commit79e53fe5a44293a82486c7228deb6d435768bc04 (patch)
tree6ee7bd9d4414d4af8d2ce95e46bca38aa3d5e8c6
parent99f943f68e3a6bd43d9b5b90f39e058ee2acfa9d (diff)
downloadrpg-79e53fe5a44293a82486c7228deb6d435768bc04.tar.gz
rpg-79e53fe5a44293a82486c7228deb6d435768bc04.tar.bz2
improved code for videos (restrict to 3 mimetypes, removed codec info from type attribute)
-rw-r--r--inc/media.php15
-rw-r--r--inc/parser/xhtml.php30
2 files changed, 14 insertions, 31 deletions
diff --git a/inc/media.php b/inc/media.php
index 6d0615a3c..437a8d75f 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -2134,15 +2134,14 @@ function media_resize_imageGD($ext,$from,$from_w,$from_h,$to,$to_w,$to_h,$ofs_x=
/**
* Return other media files with the same base name
- * but a different extension.
+ * but different extensions.
*
* @param string $src - ID of media file
* @param array $exts - alternative extensions to find other files for
- * @param boolean $onlyone - set if only one result should be returned (and not the original)
*
* @author Anika Henke <anika@selfthinker.org>
*/
-function media_alternativefiles($src, $exts, $onlyone=false){
+function media_alternativefiles($src, $exts){
$files = array();
list($srcExt, $srcMime) = mimetype($src);
@@ -2152,16 +2151,10 @@ function media_alternativefiles($src, $exts, $onlyone=false){
$fileid = $filebase.'.'.$ext;
$file = mediaFN($fileid);
if(file_exists($file)) {
- $files[$ext] = $fileid;
- if ($onlyone) {
- return $files;
- }
+ list($fileExt, $fileMime) = mimetype($file);
+ $files[$fileMime] = $fileid;
}
}
- // if original wasn't any of $exts, return only original
- if (empty($files) && !$onlyone) {
- $files[$srcExt] = $src;
- }
return $files;
}
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index 8b7405402..b1bfaae5d 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -1093,13 +1093,10 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$ret .= ' />';
- }elseif(substr($mime,0,5) == 'video'){
-
- $origTitle = '';
+ }elseif($mime == 'video/webm' || $mime == 'video/ogg' || $mime == 'video/mp4' ){
// first get the $title
if (!is_null($title)) {
$title = $this->_xmlEntities($title);
- $origTitle = $title;
}
if (!$title) {
// just show the sourcename
@@ -1115,7 +1112,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$att['class'] = "media$align";
//add video(s)
- $ret .= $this->_video($src, $origTitle, $mime, $width, $height, $att);
+ $ret .= $this->_video($src, $width, $height, $att);
}elseif($mime == 'application/x-shockwave-flash'){
if (!$render) {
@@ -1262,7 +1259,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
* @param int $height - height of the video in pixels
* @param array $atts - additional attributes for the <video> tag
*/
- function _video($src,$title,$mime,$width,$height,$atts=null){
+ function _video($src,$width,$height,$atts=null){
// prepare width and height
if(is_null($atts)) $atts = array();
@@ -1273,10 +1270,6 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
// prepare alternative formats
$extensions = array('webm', 'ogv', 'mp4');
- $types['webm'] = 'video/webm; codecs="vp8, vorbis"';
- $types['ogv'] = 'video/ogg; codecs="theora, vorbis"';
- // mp4 would be 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"', but Android doesn't like it
- $types['mp4'] = '';
$alternatives = media_alternativefiles($src, $extensions);
$poster = media_alternativefiles($src, array('jpg', 'png'), true);
$posterUrl = '';
@@ -1284,21 +1277,18 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$posterUrl = ml(reset($poster),array('cache'=>$cache),true,'&');
}
+ // open video tag
$this->doc .= '<video '.buildAttributes($atts).' controls="controls"';
if ($posterUrl) $this->doc .= ' poster="'.$posterUrl.'"';
$this->doc .= '>'.NL;
- foreach($alternatives as $ext => $file) {
- $url = ml($file,array('cache'=>$cache),true,'&');
- $type = $types[$ext];
- if (!$title) {
- $title = $this->_xmlEntities(utf8_basename(noNS($file)));
- }
- $this->doc .= '<source src="'.hsc($url).'"';
- if (!empty($type)) $this->doc .= ' type=\''.$type.'\'';
- $this->doc .= ' />'.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)));
- // alternative content
+ $this->doc .= '<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');
}