summaryrefslogtreecommitdiff
path: root/lib/exe
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2006-05-19 18:50:23 +0200
committerAndreas Gohr <andi@splitbrain.org>2006-05-19 18:50:23 +0200
commit3df72098bbc205fa4bd4735d52d2626baad93548 (patch)
tree105ca14ca3ff596ad4c7d20a1985aeb02c5f7caa /lib/exe
parenta219c1f00349b720d262939fec3e7baf19a63402 (diff)
downloadrpg-3df72098bbc205fa4bd4735d52d2626baad93548.tar.gz
rpg-3df72098bbc205fa4bd4735d52d2626baad93548.tar.bz2
new mediamanager
This patch adds a completely rewritten media popup. The following noteworthy changes were made: - media manager uses a collapsible namespace tree - media manager uses AJAX if available - media manager popup can be kept open when selecting a media file - only one template is used for the media manager :!: Template - Editable image metadata is configured in conf/mediameta.php now - The JS cookie mechanism was enhanced to store key/value pairs - Language strings can be exported to JS in js.php darcs-hash:20060519165023-7ad00-4932b4553fc919aa4a8b8187958b823acf4f8cee.gz
Diffstat (limited to 'lib/exe')
-rw-r--r--lib/exe/ajax.php36
-rw-r--r--lib/exe/js.php23
-rw-r--r--lib/exe/media.php183
-rw-r--r--lib/exe/mediamanager.php53
4 files changed, 106 insertions, 189 deletions
diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php
index 886e9829d..c9b93a4b8 100644
--- a/lib/exe/ajax.php
+++ b/lib/exe/ajax.php
@@ -97,6 +97,8 @@ function ajax_lock(){
/**
* Delete a draft
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
*/
function ajax_draftdel(){
$id = cleanID($_POST['id']);
@@ -109,5 +111,39 @@ function ajax_draftdel(){
@unlink($cname);
}
+/**
+ * Return subnamespaces for the Mediamanager
+ */
+function ajax_medians(){
+ global $conf;
+ require_once(DOKU_INC.'inc/search.php');
+ require_once(DOKU_INC.'inc/media.php');
+
+ // wanted namespace
+ $ns = cleanID($_POST['ns']);
+ $dir = utf8_encodeFN(str_replace(':','/',$ns));
+
+ $lvl = count(explode(':',$ns));
+
+ $data = array();
+ search($data,$conf['mediadir'],'search_index',array(),$dir);
+ foreach($data as $item){
+ $item['level'] = $lvl+1;
+ echo media_nstree_li($item);
+ echo media_nstree_item($item);
+ echo '</div></li>';
+ }
+}
+
+/**
+ * Return subnamespaces for the Mediamanager
+ */
+function ajax_medialist(){
+ global $conf;
+ require_once(DOKU_INC.'inc/media.php');
+
+ media_filelist($_POST['ns']);
+}
+
//Setup VIM: ex: et ts=2 enc=utf-8 :
?>
diff --git a/lib/exe/js.php b/lib/exe/js.php
index 05effd31a..583faa5ad 100644
--- a/lib/exe/js.php
+++ b/lib/exe/js.php
@@ -12,6 +12,7 @@ if(!defined('NL')) define('NL',"\n");
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/pageutils.php');
require_once(DOKU_INC.'inc/io.php');
+require_once(DOKU_INC.'inc/JSON.php');
// Main (don't run when UNIT test)
if(!defined('SIMPLE_TEST')){
@@ -39,17 +40,21 @@ function js_out(){
// Array of needed files
$files = array(
DOKU_INC.'lib/scripts/events.js',
+ DOKU_INC.'lib/scripts/cookie.js',
DOKU_INC.'lib/scripts/script.js',
DOKU_INC.'lib/scripts/tw-sack.js',
DOKU_INC.'lib/scripts/ajax.js',
DOKU_INC.'lib/scripts/domLib.js',
DOKU_INC.'lib/scripts/domTT.js',
);
- if($edit && $write){
- $files[] = DOKU_INC.'lib/scripts/edit.js';
- if($conf['spellchecker']){
- $files[] = DOKU_INC.'lib/scripts/spellcheck.js';
+ if($edit){
+ if($write){
+ $files[] = DOKU_INC.'lib/scripts/edit.js';
+ if($conf['spellchecker']){
+ $files[] = DOKU_INC.'lib/scripts/spellcheck.js';
+ }
}
+ $files[] = DOKU_INC.'lib/scripts/media.js';
}
$files[] = DOKU_TPLINC.'script.js';
@@ -70,11 +75,17 @@ function js_out(){
// start output buffering and build the script
ob_start();
- // add some translation strings and global variables
+ // add some global variables
+ print "var DOKU_BASE = '".DOKU_BASE."';";
+
+ //FIXME: move thes into LANG
print "var alertText = '".js_escape($lang['qb_alert'])."';";
print "var notSavedYet = '".js_escape($lang['notsavedyet'])."';";
print "var reallyDel = '".js_escape($lang['del_confirm'])."';";
- print "var DOKU_BASE = '".DOKU_BASE."';";
+
+ // load JS specific translations
+ $json = new JSON();
+ echo 'LANG = '.$json->encode($lang['js']).";\n";
// load files
foreach($files as $file){
diff --git a/lib/exe/media.php b/lib/exe/media.php
deleted file mode 100644
index cc78d6b72..000000000
--- a/lib/exe/media.php
+++ /dev/null
@@ -1,183 +0,0 @@
-<?php
- if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
- require_once(DOKU_INC.'inc/init.php');
- require_once(DOKU_INC.'inc/common.php');
- require_once(DOKU_INC.'inc/lang/en/lang.php');
- require_once(DOKU_INC.'inc/lang/'.$conf['lang'].'/lang.php');
- require_once(DOKU_INC.'inc/html.php');
- require_once(DOKU_INC.'inc/JpegMeta.php');
- require_once(DOKU_INC.'inc/search.php');
- require_once(DOKU_INC.'inc/template.php');
- require_once(DOKU_INC.'inc/auth.php');
- //close sesseion
- session_write_close();
-
- //get namespace to display (either direct or from deletion order)
- if($_REQUEST['delete']){
- $DEL = cleanID($_REQUEST['delete']);
- $NS = getNS($DEL);
- }elseif($_REQUEST['edit']){
- $IMG = cleanID($_REQUEST['edit']);
- $SRC = mediaFN($IMG);
- $NS = getNS($IMG);
- }else{
- $NS = $_REQUEST['ns'];
- $NS = cleanID($NS);
- }
-
- //check upload permissions
- $AUTH = auth_quickaclcheck("$NS:*");
- if($AUTH >= 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.php'));
- }
-
-/**********************************************/
-
-/**
- * Deletes mediafiles - Auth is not handled here!
- *
- * @author Andreas Gohr <andi@splitbrain.org>
- */
-function media_delete($delid){
- global $lang;
-
- $file = mediaFN($delid);
- if(@unlink($file)){
- msg(str_replace('%s',noNS($delid),$lang['deletesucc']),1);
- io_sweepNS($delid,'mediadir');
- return true;
- }
- //something went wrong
- msg(str_replace('%s',$file,$lang['deletefail']),-1);
- return false;
-}
-
-/**
- * Handles Mediafile uploads
- *
- * @author Andreas Gohr <andi@splitbrain.org>
- */
-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);
-
- // because a temp file was created already
- 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
- if($conf['fperm']) chmod($fn, $conf['fperm']);
- 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 <andi@splitbrain.org>
- */
-function media_html_list_namespaces($item){
- $ret = '';
- $ret .= '<a href="'.DOKU_BASE.'lib/exe/media.php?ns='.idfilter($item['id']).'" class="idx_dir">';
- $pos = strrpos($item['id'], ':');
- $ret .= substr($item['id'], $pos > 0 ? $pos + 1 : 0);
- $ret .= '</a>';
- return $ret;
-}
-
-/**
- * Saves image meta data
- *
- * @author Andreas Gohr <andi@splitbrain.org>
- */
-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);
- }
-}
-
-?>
diff --git a/lib/exe/mediamanager.php b/lib/exe/mediamanager.php
new file mode 100644
index 000000000..8b645e434
--- /dev/null
+++ b/lib/exe/mediamanager.php
@@ -0,0 +1,53 @@
+<?
+ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
+ define('DOKU_MEDIAMANAGER',1);
+ require_once(DOKU_INC.'inc/init.php');
+ require_once(DOKU_INC.'inc/lang/en/lang.php');
+ require_once(DOKU_INC.'inc/lang/'.$conf['lang'].'/lang.php');
+ require_once(DOKU_INC.'inc/media.php');
+ require_once(DOKU_INC.'inc/common.php');
+ require_once(DOKU_INC.'inc/search.php');
+ require_once(DOKU_INC.'inc/template.php');
+ require_once(DOKU_INC.'inc/auth.php');
+ session_write_close(); //close session
+
+
+ // get namespace to display (either direct or from deletion order)
+ if($_REQUEST['delete']){
+ $DEL = cleanID($_REQUEST['delete']);
+ $NS = getNS($DEL);
+ }elseif($_REQUEST['edit']){
+ $IMG = cleanID($_REQUEST['edit']);
+ $NS = getNS($IMG);
+ }elseif($_REQUEST['img']){
+ $IMG = cleanID($_REQUEST['img']);
+ $NS = getNS($IMG);
+ }else{
+ $NS = $_REQUEST['ns'];
+ $NS = cleanID($NS);
+ }
+
+ // check auth
+ $AUTH = auth_quickaclcheck("$NS:*");
+
+ // create the given namespace (just for beautification)
+ if($AUTH >= AUTH_UPLOAD) io_makeFileDir(mediaFN("$NS:xxx"));
+
+ // handle upload
+ if($_FILES['upload']['tmp_name']){
+ $JUMPTO = media_upload($NS,$AUTH);
+ }
+
+ // handle meta saving
+ if($IMG && $_REQUEST['do']['save']){
+ $JUMPTO = media_metasave($IMG,$AUTH,$_REQUEST['meta']);
+ }
+
+ // handle deletion
+ if($DEL) {
+ $INUSE = media_delete($DEL,$AUTH);
+ }
+
+ // finished - start output
+ header('Content-Type: text/html; charset=utf-8');
+ include(template('mediamanager.php'));