From 3d7a9e0a1cba0b173b6b03f5c88a8eb975286cc7 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Fri, 2 Aug 2013 23:13:41 +0100 Subject: 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. --- inc/media.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'inc/media.php') 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 + */ +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: */ -- cgit v1.2.3 From 99f943f68e3a6bd43d9b5b90f39e058ee2acfa9d Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Fri, 2 Aug 2013 23:53:28 +0100 Subject: added poster attribute to video if jpg or png with same file name exists --- inc/media.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'inc/media.php') diff --git a/inc/media.php b/inc/media.php index c1dafe2a3..6d0615a3c 100644 --- a/inc/media.php +++ b/inc/media.php @@ -2136,12 +2136,13 @@ 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. * - * @param string $src - ID of media file - * @param array $exts - alternative extensions to find other files for + * @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 */ -function media_alternativefiles($src, $exts){ +function media_alternativefiles($src, $exts, $onlyone=false){ $files = array(); list($srcExt, $srcMime) = mimetype($src); @@ -2152,10 +2153,13 @@ function media_alternativefiles($src, $exts){ $file = mediaFN($fileid); if(file_exists($file)) { $files[$ext] = $fileid; + if ($onlyone) { + return $files; + } } } // if original wasn't any of $exts, return only original - if (empty($files)) { + if (empty($files) && !$onlyone) { $files[$srcExt] = $src; } return $files; -- cgit v1.2.3 From 79e53fe5a44293a82486c7228deb6d435768bc04 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sat, 3 Aug 2013 14:34:17 +0100 Subject: improved code for videos (restrict to 3 mimetypes, removed codec info from type attribute) --- inc/media.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'inc/media.php') 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 */ -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; } -- cgit v1.2.3 From f50634f0c2d6669655b684449d5a6ef44e5ca3f1 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sun, 4 Aug 2013 10:35:00 +0100 Subject: refactored audio/video code, removed wrong link around audio --- inc/media.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'inc/media.php') 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 */ @@ -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 + */ +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: */ -- cgit v1.2.3 From 77450f4001bc641f7a724ae5e5c2f71b44c022d1 Mon Sep 17 00:00:00 2001 From: lisps Date: Wed, 27 Nov 2013 09:38:06 +0100 Subject: media image can be resized by height (without width) --- inc/media.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/media.php') diff --git a/inc/media.php b/inc/media.php index d69426414..390cd3488 100644 --- a/inc/media.php +++ b/inc/media.php @@ -1800,6 +1800,7 @@ function media_resize_image($file, $ext, $w, $h=0){ if($info == false) return $file; // that's no image - it's a spaceship! if(!$h) $h = round(($w * $info[1]) / $info[0]); + if(!$w) $w = round(($h * $info[0]) / $info[1]); // we wont scale up to infinity if($w > 2000 || $h > 2000) return $file; -- cgit v1.2.3 From e175e163722d806ebf45aa1e9a7843c2391a5b20 Mon Sep 17 00:00:00 2001 From: lisps Date: Wed, 27 Nov 2013 09:42:41 +0100 Subject: fix indent --- inc/media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/media.php') diff --git a/inc/media.php b/inc/media.php index 390cd3488..12db36841 100644 --- a/inc/media.php +++ b/inc/media.php @@ -1800,7 +1800,7 @@ function media_resize_image($file, $ext, $w, $h=0){ if($info == false) return $file; // that's no image - it's a spaceship! if(!$h) $h = round(($w * $info[1]) / $info[0]); - if(!$w) $w = round(($h * $info[0]) / $info[1]); + if(!$w) $w = round(($h * $info[0]) / $info[1]); // we wont scale up to infinity if($w > 2000 || $h > 2000) return $file; -- cgit v1.2.3 From 1253a9dc24315481f9abf698836da72a503d5450 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 7 Jan 2014 18:49:21 +0100 Subject: removed superflous parameter --- inc/media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/media.php') diff --git a/inc/media.php b/inc/media.php index d69426414..6e5ee8fb3 100644 --- a/inc/media.php +++ b/inc/media.php @@ -566,7 +566,7 @@ function media_notify($id,$file,$mime,$old_rev=false){ if(empty($conf['notify'])) return; //notify enabled? $subscription = new Subscription(); - return $subscription->send_media_diff($conf['notify'], 'uploadmail', $id, $old_rev, ''); + return $subscription->send_media_diff($conf['notify'], 'uploadmail', $id, $old_rev); } /** -- cgit v1.2.3 From ebc28e69385bf5596ac1b1de955efb7831621f59 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 7 Jan 2014 20:14:39 +0100 Subject: removed some unused parameters, fixed some docblocks this file makes me cry. there is so much shit going on here. --- inc/media.php | 62 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 29 deletions(-) (limited to 'inc/media.php') diff --git a/inc/media.php b/inc/media.php index 6e5ee8fb3..916be2796 100644 --- a/inc/media.php +++ b/inc/media.php @@ -115,7 +115,7 @@ function media_ispublic($id){ * @author Kate Arzamastseva */ function media_metaform($id,$auth){ - global $lang, $config_cascade; + global $lang; if($auth < AUTH_UPLOAD) { echo '
'.$lang['media_perm_upload'].'
'.NL; @@ -167,6 +167,8 @@ function media_metaform($id,$auth){ $form->addElement(form_makeButton('submit', '', $lang['btn_save'], array('accesskey' => 's', 'name' => 'mediado[save]'))); $form->addElement(''.NL); $form->printForm(); + + return true; } /** @@ -176,7 +178,7 @@ function media_metaform($id,$auth){ */ function media_inuse($id) { global $conf; - $mediareferences = array(); + if($conf['refcheck']){ $mediareferences = ft_mediause($id,true); if(!count($mediareferences)) { @@ -199,7 +201,9 @@ define('DOKU_MEDIA_EMPTY_NS', 8); * * If configured, checks for media references before deletion * - * @author Andreas Gohr + * @author Andreas Gohr + * @param string $id media id + * @param int $auth current auth check result * @return int One of: 0, * DOKU_MEDIA_DELETED, * DOKU_MEDIA_DELETED | DOKU_MEDIA_EMPTY_NS, @@ -248,6 +252,8 @@ function media_delete($id,$auth){ /** * Handle file uploads via XMLHttpRequest * + * @param string $ns target namespace + * @param int $auth current auth check result * @return mixed false on error, id of the new file on success */ function media_upload_xhr($ns,$auth){ @@ -255,7 +261,7 @@ function media_upload_xhr($ns,$auth){ global $INPUT; $id = $INPUT->get->str('qqfile'); - list($ext,$mime,$dl) = mimetype($id); + list($ext,$mime) = mimetype($id); $input = fopen("php://input", "r"); if (!($tmp = io_mktmpdir())) return false; $path = $tmp.'/'.md5($id); @@ -291,6 +297,9 @@ function media_upload_xhr($ns,$auth){ * * @author Andreas Gohr * @author Michael Klier + * @param string $ns target namespace + * @param int $auth current auth check result + * @param bool|array $file $_FILES member, $_FILES['upload'] if false * @return mixed false on error, id of the new file on success */ function media_upload($ns,$auth,$file=false){ @@ -307,8 +316,8 @@ function media_upload($ns,$auth,$file=false){ if($file['error']) return false; // check extensions - list($fext,$fmime,$dl) = mimetype($file['name']); - list($iext,$imime,$dl) = mimetype($id); + list($fext,$fmime) = mimetype($file['name']); + list($iext,$imime) = mimetype($id); if($fext && !$iext){ // no extension specified in id - read original one $id .= '.'.$fext; @@ -563,7 +572,7 @@ function media_contentcheck($file,$mime){ */ function media_notify($id,$file,$mime,$old_rev=false){ global $conf; - if(empty($conf['notify'])) return; //notify enabled? + if(empty($conf['notify'])) return false; //notify enabled? $subscription = new Subscription(); return $subscription->send_media_diff($conf['notify'], 'uploadmail', $id, $old_rev); @@ -640,7 +649,8 @@ function media_tabs_files($selected_tab = ''){ * Prints tabs for files details actions * * @author Kate Arzamastseva - * @param string $selected_tab - opened tab + * @param string $image filename of the current image + * @param string $selected_tab opened tab */ function media_tabs_details($image, $selected_tab = ''){ global $lang, $conf; @@ -649,7 +659,7 @@ function media_tabs_details($image, $selected_tab = ''){ $tabs['view'] = array('href' => media_managerURL(array('tab_details' => 'view'), '&'), 'caption' => $lang['media_viewtab']); - list($ext, $mime) = mimetype($image); + list(, $mime) = mimetype($image); if ($mime == 'image/jpeg' && @file_exists(mediaFN($image))) { $tabs['edit'] = array('href' => media_managerURL(array('tab_details' => 'edit'), '&'), 'caption' => $lang['media_edittab']); @@ -669,7 +679,6 @@ function media_tabs_details($image, $selected_tab = ''){ */ function media_tab_files_options(){ global $lang; - global $NS; global $INPUT; global $ID; $form = new Doku_Form(array('class' => 'options', 'method' => 'get', @@ -776,7 +785,6 @@ function media_tab_upload($ns,$auth=null,$jump='') { * @author Kate Arzamastseva */ function media_tab_search($ns,$auth=null) { - global $lang; global $INPUT; $do = $INPUT->str('mediado'); @@ -796,7 +804,7 @@ function media_tab_search($ns,$auth=null) { * @author Kate Arzamastseva */ function media_tab_view($image, $ns, $auth=null, $rev=false) { - global $lang, $conf; + global $lang; if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); if ($image && $auth >= AUTH_READ) { @@ -816,11 +824,10 @@ function media_tab_view($image, $ns, $auth=null, $rev=false) { * @author Kate Arzamastseva */ function media_tab_edit($image, $ns, $auth=null) { - global $lang; if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); if ($image) { - list($ext, $mime) = mimetype($image); + list(, $mime) = mimetype($image); if ($mime == 'image/jpeg') media_metaform($image,$auth); } } @@ -935,9 +942,10 @@ function media_preview_buttons($image, $auth, $rev=false) { * Returns image width and height for mediamanager preview panel * * @author Kate Arzamastseva - * @param string $image - * @param int $rev + * @param string $image + * @param int $rev * @param JpegMeta $meta + * @param int $size * @return array */ function media_image_preview_size($image, $rev, $meta, $size = 500) { @@ -979,8 +987,6 @@ function media_getTag($tags,$meta,$alt=''){ * @return array */ function media_file_tags($meta) { - global $config_cascade; - // load the field descriptions static $fields = null; if(is_null($fields)){ @@ -1107,13 +1113,12 @@ function _media_file_diff($data) { */ function media_file_diff($image, $l_rev, $r_rev, $ns, $auth, $fromajax){ global $lang; - global $config_cascade; global $INPUT; $l_meta = new JpegMeta(mediaFN($image, $l_rev)); $r_meta = new JpegMeta(mediaFN($image, $r_rev)); - $is_img = preg_match("/\.(jpe?g|gif|png)$/", $image); + $is_img = preg_match('/\.(jpe?g|gif|png)$/', $image); if ($is_img) { $l_size = media_image_preview_size($image, $l_rev, $l_meta); $r_size = media_image_preview_size($image, $r_rev, $r_meta); @@ -1140,7 +1145,7 @@ function media_file_diff($image, $l_rev, $r_rev, $ns, $auth, $fromajax){ if ($difftype == 'opacity' || $difftype == 'portions') { media_image_diff($image, $l_rev, $r_rev, $l_size, $r_size, $difftype); if (!$fromajax) echo ''; - return ''; + return; } } @@ -1274,7 +1279,7 @@ function media_restore($image, $rev, $auth){ $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes'))); if (!$image || (!file_exists(mediaFN($image)) && !$removed)) return false; if (!$rev || !file_exists(mediaFN($image, $rev))) return false; - list($iext,$imime,$dl) = mimetype($image); + list(,$imime,) = mimetype($image); $res = media_upload_finish(mediaFN($image, $rev), mediaFN($image), $image, @@ -1364,7 +1369,7 @@ function media_printfile($item,$auth,$jump,$display_namespace=false){ } // Prepare fileicons - list($ext,$mime,$dl) = mimetype($item['file'],false); + list($ext) = mimetype($item['file'],false); $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); $class = 'select mediafile mf_'.$class; @@ -1420,7 +1425,7 @@ function media_printfile($item,$auth,$jump,$display_namespace=false){ } function media_printicon($filename){ - list($ext,$mime,$dl) = mimetype(mediaFN($filename),false); + list($ext) = mimetype(mediaFN($filename),false); if (@file_exists(DOKU_INC.'lib/images/fileicons/'.$ext.'.png')) { $icon = DOKU_BASE.'lib/images/fileicons/'.$ext.'.png'; @@ -1438,8 +1443,6 @@ function media_printicon($filename){ * @author Kate Arzamastseva */ function media_printfile_thumbs($item,$auth,$jump=false,$display_namespace=false){ - global $lang; - global $conf; // Prepare filename $file = utf8_decodeFN($item['file']); @@ -1552,12 +1555,13 @@ function media_printimgdetail($item, $fullscreen=false){ * parameters * * @author Kate Arzamastseva - * @param array $params - * @param string $amp - separator + * @param array|bool $params + * @param string $amp - separator + * @param bool $abs + * @param bool $params_array * @return string - link */ function media_managerURL($params=false, $amp='&', $abs=false, $params_array=false) { - global $conf; global $ID; global $INPUT; -- cgit v1.2.3 From 815f94e6abb4ada5a977a5506f2814372e7fa571 Mon Sep 17 00:00:00 2001 From: lisps Date: Sat, 15 Feb 2014 12:42:30 +0100 Subject: Mediamanager: rename radio name attributes for sort and list buttons to fix fs#2851 related to http://bugs.jqueryui.com/ticket/8761 --- inc/media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/media.php') diff --git a/inc/media.php b/inc/media.php index 960b96e65..93662ec17 100644 --- a/inc/media.php +++ b/inc/media.php @@ -704,7 +704,7 @@ function media_tab_files_options(){ if ($checked == $option) { $attrs['checked'] = 'checked'; } - $form->addElement(form_makeRadioField($group, $option, + $form->addElement(form_makeRadioField($group . '_dwmedia', $option, $lang['media_' . $group . '_' . $option], $content[0] . '__' . $option, $option, $attrs)); -- cgit v1.2.3 From 900984773e07ba34cbb6f6f7ed394210213153ec Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 15 Feb 2014 15:52:07 +0100 Subject: try to ignore chmod errors FS#2895 --- inc/media.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/media.php') diff --git a/inc/media.php b/inc/media.php index 93662ec17..56fa5d54b 100644 --- a/inc/media.php +++ b/inc/media.php @@ -1819,7 +1819,7 @@ function media_resize_image($file, $ext, $w, $h=0){ if( $mtime > filemtime($file) || media_resize_imageIM($ext,$file,$info[0],$info[1],$local,$w,$h) || media_resize_imageGD($ext,$file,$info[0],$info[1],$local,$w,$h) ){ - if($conf['fperm']) chmod($local, $conf['fperm']); + if($conf['fperm']) @chmod($local, $conf['fperm']); return $local; } //still here? resizing failed @@ -1880,7 +1880,7 @@ function media_crop_image($file, $ext, $w, $h=0){ if( $mtime > @filemtime($file) || media_crop_imageIM($ext,$file,$info[0],$info[1],$local,$cw,$ch,$cx,$cy) || media_resize_imageGD($ext,$file,$cw,$ch,$local,$cw,$ch,$cx,$cy) ){ - if($conf['fperm']) chmod($local, $conf['fperm']); + if($conf['fperm']) @chmod($local, $conf['fperm']); return media_resize_image($local,$ext, $w, $h); } -- cgit v1.2.3