:!: this isn't yet a plugin, but a quick, unstable hack. Once installed, under the edit box appears a list of media files attached to this page. ===== INVOLVED FILES ===== ==== new files ==== * tpl/*/media_attached.php * lib/exe/media_attached.php ==== editied files ==== * inc/html.php * inc/template.php * tpl/*/layout.css * lib/scripts/script.js ===== PROBLEMS ===== * the java script that inserts the media code automatically in the edit field whenever you click on an image name isn't working ===== INSTALL ===== ==== 1. create new files ==== === tpl/*/media_attached.php === * */ ?> <?php echo hsc($lang['mediaselect'])?> [<?php echo hsc($conf['title'])?>]

Anhänge

Ein Bild anzeigen:
{{:meinbild.jpg}}
Alle angehängten Bilder anzeigen:
{{gallery>}}


=== lib/exe/media_attached.php === = AUTH_UPLOAD){ $UPLOADOK = true; //create the given namespace (just for beautification) $mdir = $conf['mediadir'].'/'.utf8_encodeFN(str_replace(':','/',$NS)); io_makeFileDir("$mdir/xxx"); }else{ $UPLOADOK = false; } //handle deletion $mediareferences = array(); if($DEL && $AUTH >= AUTH_DELETE){ if($conf['refcheck']){ search($mediareferences,$conf['datadir'],'search_reference',array('query' => $DEL)); } if(!count($mediareferences)){ media_delete($DEL); }elseif(!$conf['refshow']){ msg(str_replace('%s',noNS($DEL),$lang['mediainuse']),0); } } //handle metadatasaving if($UPLOADOK && $SRC && $_REQUEST['save']){ media_metasave($SRC,$_REQUEST['meta']); } //handle upload if($_FILES['upload']['tmp_name'] && $UPLOADOK){ media_upload($NS,$AUTH); } //start output and load template header('Content-Type: text/html; charset=utf-8'); if($conf['refshow'] && count($mediareferences)){ include(template('mediaref.php')); }elseif($IMG){ include(template('mediaedit.php')); }else{ include(template('media_attached.php')); } //restore old umask umask($conf['oldumask']); /**********************************************/ /** * Deletes mediafiles - Auth is not handled here! * * @author Andreas Gohr */ function media_delete($delid){ global $lang; $file = mediaFN($delid); if(@unlink($file)){ msg(str_replace('%s',noNS($delid),$lang['deletesucc']),1); return true; } //something went wrong msg(str_replace('%s',$file,$lang['deletefail']),-1); return false; } /** * Handles Mediafile uploads * * @author Andreas Gohr */ function media_upload($NS,$AUTH){ require_once(DOKU_INC.'inc/confutils.php'); global $lang; global $conf; // get file $id = $_POST['id']; $file = $_FILES['upload']; // get id if(empty($id)) $id = $file['name']; $id = cleanID($NS.':'.$id); // get filename $fn = mediaFN($id); // get filetype regexp $types = array_keys(getMimeTypes()); $types = array_map(create_function('$q','return preg_quote($q,"/");'),$types); $regex = join('|',$types); // we set the umask here but this doesn't really help // because a temp file was created already umask($conf['umask']); if(preg_match('/\.('.$regex.')$/i',$fn)){ //check for overwrite if(@file_exists($fn) && (!$_POST['ow'] || $AUTH < AUTH_DELETE)){ msg($lang['uploadexist'],0); return false; } // prepare directory io_makeFileDir($fn); if(move_uploaded_file($file['tmp_name'], $fn)) { // set the correct permission here chmod($fn, 0777 - $conf['umask']); msg($lang['uploadsucc'],1); return true; }else{ msg($lang['uploadfail'],-1); } }else{ msg($lang['uploadwrong'],-1); } return false; } /** * Userfunction for html_buildlist * * Prints available media namespaces * * @author Andreas Gohr */ function media_html_list_namespaces($item){ $ret = ''; $ret .= ''; $pos = strrpos($item['id'], ':'); $ret .= substr($item['id'], $pos > 0 ? $pos + 1 : 0); $ret .= ''; return $ret; } /** * Saves image meta data * * @author Andreas Gohr */ function media_metasave($src,$data){ global $lang; $meta = new JpegMeta($src); $meta->_parseAll(); foreach($data as $key => $val){ $val=trim($val); if(empty($val)){ $meta->deleteField($key); }else{ $meta->setField($key,$val); } } if($meta->save()){ msg($lang['metasaveok'],1); }else{ msg($lang['metasaveerr'],-1); } } ?> ==== 2. edit ==== inc/html.php -- in function html_edit
==== 3a. edit ==== inc/template.php -- after function tpl_mediauploadform() function tpl_mediauploadform_attached(){ global $NS; global $UPLOADOK; global $AUTH; global $lang; if(!$UPLOADOK) return; ptln('
',2); ptln($lang['txt_upload'].':
',4); ptln('',4); ptln('
',4); ptln($lang['txt_filename'].'
',4); ptln('',4); ptln('',4); if($AUTH >= AUTH_DELETE){ ptln('',4); } ptln('
',2); }
==== 3b. edit ==== inc/template.php -- after function tpl_mediafilelist() function tpl_mediafilelist_attached(){ global $conf; global $lang; global $NS; global $AUTH; $dir = utf8_encodeFN(str_replace(':','/',$NS)); $data = array(); search($data,$conf['mediadir'],'search_media',array(),$dir); if(!count($data)){ ptln('
'.$lang['nothingfound'].'
'); return; } ptln('',2); }
==== 4. edit ==== tpl/*/layout.css -- after /* --------------- Media Selection ----------------- */ .mediaselect_attached { border:none; } ==== 5. edit ==== lib/scripts/script.js -- after function mediaSelect(file) function mediaSelect_attached(file){ insertAtCarret_attached(window.parent.document.editform.wikitext,'{{'+file+'}}'); window.close(); } function insertAtCarret_attached(field,value){ //IE support if (document.selection) { field.focus(); sel = window.parent.document.selection.createRange(); sel.text = value; //MOZILLA/NETSCAPE support }else if (field.selectionStart || field.selectionStart == '0') { var startPos = field.selectionStart; var endPos = field.selectionEnd; var scrollTop = field.scrollTop; field.value = field.value.substring(0, startPos) + value + field.value.substring(endPos); field.focus(); var cPos=startPos+(value.length); field.selectionStart=cPos; field.selectionEnd=cPos; field.scrollTop=scrollTop; } else { field.value += "\n"+value; } // reposition cursor if possible if (field.createTextRange) field.caretPos = window.parent.document.selection.createRange().duplicate(); }