summaryrefslogtreecommitdiff
path: root/inc/media.php
diff options
context:
space:
mode:
authorAnika Henke <anika@selfthinker.org>2013-08-02 23:13:41 +0100
committerAnika Henke <anika@selfthinker.org>2013-08-02 23:13:41 +0100
commit3d7a9e0a1cba0b173b6b03f5c88a8eb975286cc7 (patch)
tree9963a34099190a1c9241c0e3d8df8de8c13c8171 /inc/media.php
parent2a2a2ba2f6092b0b68a7de0ccc798062682487f4 (diff)
downloadrpg-3d7a9e0a1cba0b173b6b03f5c88a8eb975286cc7.tar.gz
rpg-3d7a9e0a1cba0b173b6b03f5c88a8eb975286cc7.tar.bz2
Add several alternative formats to video for better browser compatibility
All .webm, .ogv and .mp4 files with the same filename are automatically chosen as alternative sources when only one of them is mentioned in the media syntax.
Diffstat (limited to 'inc/media.php')
-rw-r--r--inc/media.php29
1 files changed, 29 insertions, 0 deletions
diff --git a/inc/media.php b/inc/media.php
index c76f2986c..c1dafe2a3 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -2132,4 +2132,33 @@ function media_resize_imageGD($ext,$from,$from_w,$from_h,$to,$to_w,$to_h,$ofs_x=
return $okay;
}
+/**
+ * Return other media files with the same base name
+ * but a different extension.
+ *
+ * @param string $src - ID of media file
+ * @param array $exts - alternative extensions to find other files for
+ *
+ * @author Anika Henke <anika@selfthinker.org>
+ */
+function media_alternativefiles($src, $exts){
+
+ $files = array();
+ list($srcExt, $srcMime) = mimetype($src);
+ $filebase = substr($src, 0, -1 * (strlen($srcExt)+1));
+
+ foreach($exts as $ext) {
+ $fileid = $filebase.'.'.$ext;
+ $file = mediaFN($fileid);
+ if(file_exists($file)) {
+ $files[$ext] = $fileid;
+ }
+ }
+ // if original wasn't any of $exts, return only original
+ if (empty($files)) {
+ $files[$srcExt] = $src;
+ }
+ return $files;
+}
+
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */