summaryrefslogtreecommitdiff
path: root/inc/media.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/media.php')
-rw-r--r--inc/media.php128
1 files changed, 95 insertions, 33 deletions
diff --git a/inc/media.php b/inc/media.php
index 3bdaa8ef7..1d6d9f4fc 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -115,7 +115,7 @@ function media_ispublic($id){
* @author Kate Arzamastseva <pshns@ukr.net>
*/
function media_metaform($id,$auth){
- global $lang, $config_cascade;
+ global $lang;
if($auth < AUTH_UPLOAD) {
echo '<div class="nothing">'.$lang['media_perm_upload'].'</div>'.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('</div>'.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 <andi@splitbrain.org>
+ * @author Andreas Gohr <andi@splitbrain.org>
+ * @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 <andi@splitbrain.org>
* @author Michael Klier <chi@chimeric.de>
+ * @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;
@@ -564,10 +573,10 @@ 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, '');
+ return $subscription->send_media_diff($conf['notify'], 'uploadmail', $id, $old_rev);
}
/**
@@ -641,7 +650,8 @@ function media_tabs_files($selected_tab = ''){
* Prints tabs for files details actions
*
* @author Kate Arzamastseva <pshns@ukr.net>
- * @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;
@@ -650,7 +660,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']);
@@ -670,7 +680,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',
@@ -696,7 +705,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));
@@ -777,7 +786,6 @@ function media_tab_upload($ns,$auth=null,$jump='') {
* @author Kate Arzamastseva <pshns@ukr.net>
*/
function media_tab_search($ns,$auth=null) {
- global $lang;
global $INPUT;
$do = $INPUT->str('mediado');
@@ -797,7 +805,7 @@ function media_tab_search($ns,$auth=null) {
* @author Kate Arzamastseva <pshns@ukr.net>
*/
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) {
@@ -817,11 +825,10 @@ function media_tab_view($image, $ns, $auth=null, $rev=false) {
* @author Kate Arzamastseva <pshns@ukr.net>
*/
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);
}
}
@@ -936,9 +943,10 @@ function media_preview_buttons($image, $auth, $rev=false) {
* Returns image width and height for mediamanager preview panel
*
* @author Kate Arzamastseva <pshns@ukr.net>
- * @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) {
@@ -980,8 +988,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)){
@@ -1109,13 +1115,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);
@@ -1142,7 +1147,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 '</div>';
- return '';
+ return;
}
}
@@ -1276,7 +1281,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,
@@ -1366,7 +1371,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;
@@ -1422,7 +1427,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';
@@ -1440,8 +1445,6 @@ function media_printicon($filename){
* @author Kate Arzamastseva <pshns@ukr.net>
*/
function media_printfile_thumbs($item,$auth,$jump=false,$display_namespace=false){
- global $lang;
- global $conf;
// Prepare filename
$file = utf8_decodeFN($item['file']);
@@ -1554,12 +1557,13 @@ function media_printimgdetail($item, $fullscreen=false){
* parameters
*
* @author Kate Arzamastseva <pshns@ukr.net>
- * @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='&amp;', $abs=false, $params_array=false) {
- global $conf;
global $ID;
global $INPUT;
@@ -1802,6 +1806,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;
@@ -1816,7 +1821,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
@@ -1877,7 +1882,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);
}
@@ -2131,4 +2136,61 @@ 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 different extensions.
+ *
+ * @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>
+ */
+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)) {
+ list($fileExt, $fileMime) = mimetype($file);
+ $files[$fileMime] = $fileid;
+ }
+ }
+ 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: */