From 820fa24b2cc7cd677f9e392f5834e69bc3e46dc5 Mon Sep 17 00:00:00 2001
From: andi <andi@splitbrain.org>
Date: Fri, 11 Mar 2005 15:56:11 +0100
Subject: [PATCH] more template additions - media selection works again

darcs-hash:20050311145611-9977f-6a2987fbe10ba90cf279a3874d8d7510e63294b5.gz
---
 inc/html.php           |   3 +-
 inc/template.php       |  83 +++++++++++++++++++++++++++++
 media.php              | 116 +++++++----------------------------------
 tpl/default/design.css |   5 ++
 tpl/default/media.php  |  62 ++++++++++++++++++++++
 5 files changed, 172 insertions(+), 97 deletions(-)
 create mode 100644 tpl/default/media.php

diff --git a/inc/html.php b/inc/html.php
index 85e3189ea..df3f446b5 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -293,6 +293,7 @@ function html_btn($name,$id,$akey,$params,$method='get'){
 /**
  * Check for the given permission or prints an error
  *
+ * @deprecated
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_acl($perm){
@@ -596,7 +597,7 @@ function html_search(){
       print '</div>';
     }
   }else{
-    print '<div align="center">'.$lang['nothingfound'].'</div>';
+    print '<div class="nothing">'.$lang['nothingfound'].'</div>';
   }
 
   //hide progressbar
diff --git a/inc/template.php b/inc/template.php
index 233ded96b..d52d5c7a0 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -96,6 +96,9 @@ function tpl_content(){
     case 'register':
       html_register();
       break;
+    case 'denied':
+      print parsedLocale('denied');
+			break;
     default:
 			msg("Failed to handle command: ".hsc($ACT),-1); 
   }
@@ -307,4 +310,84 @@ function tpl_pageinfo(){
   }
 }
 
+/**
+ * Print a list of namespaces containing media files
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function tpl_medianamespaces(){
+	global $conf;
+
+  $data = array();
+  search($data,$conf['mediadir'],'search_namespaces',array());
+  print html_buildlist($data,'idx',media_html_list_namespaces);
+}
+
+/**
+ * Print a list of mediafiles in the current namespace
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function tpl_mediafilelist(){
+  global $conf;
+  global $lang;
+  global $NS;
+  $dir = utf8_encodeFN(str_replace(':','/',$NS));
+
+  $data = array();
+  search($data,$conf['mediadir'],'search_media',array(),$dir);
+
+  if(!count($data)){
+    ptln('<div class="nothing">'.$lang['nothingfound'].'<div>');
+    return;
+  }
+
+  ptln('<ul>',2);
+  foreach($data as $item){
+    ptln('<li>',4);
+    ptln('<a href="javascript:mediaSelect(\''.$item['id'].'\')">'.
+         utf8_decodeFN($item['file']).
+         '</a>',6);
+    if($item['isimg']){
+      ptln('('.$item['info'][0].'&#215;'.$item['info'][1].
+           ' '.filesize_h($item['size']).')<br />',6);
+
+      # build thumbnail
+      $link=array();
+      $link['name']=$item['id'];
+      if($item['info'][0]>120) $link['name'] .= '?120';
+      $link = format_link_media($link);
+      ptln($link['name'],6);
+
+    }else{
+      ptln ('('.filesize_h($item['size']).')',6);
+    }
+    ptln('</li>',4);
+  }
+  ptln('</ul>',2);
+}
+
+/**
+ * Print the media upload form if permissions are correct
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function tpl_mediauploadform(){
+  global $NS;
+  global $UPLOADOK;
+  global $lang;
+
+  if(!$UPLOADOK) return;
+
+  ptln('<form action="'.$_SERVER['PHP_SELF'].'" name="upload"'.
+       ' method="post" enctype="multipart/form-data">',2);
+  ptln($lang['txt_upload'].':<br />',4);
+  ptln('<input type="file" name="upload" class="edit" onchange="suggestWikiname();" />',4);
+  ptln('<input type="hidden" name="ns" value="'.hsc($NS).'" /><br />',4);
+  ptln($lang['txt_filename'].'<br />',4);
+  ptln('<input type="text" name="id" class="edit" />',4);
+  ptln('<input type="submit" class="button" value="'.$lang['btn_upload'].'" accesskey="s" />',4);
+  ptln('</form>',2);
+}
+
 ?>
diff --git a/media.php b/media.php
index 7d67f971e..10e0b36b9 100644
--- a/media.php
+++ b/media.php
@@ -7,6 +7,7 @@
   require_once(DOKU_INC.'inc/html.php');
   require_once(DOKU_INC.'inc/search.php');
   require_once(DOKU_INC.'inc/format.php');
+  require_once(DOKU_INC.'inc/template.php');
   require_once(DOKU_INC.'inc/auth.php');
 
   header('Content-Type: text/html; charset='.$lang['encoding']);
@@ -14,48 +15,34 @@
   $NS = $_REQUEST['ns'];
   $NS = cleanID($NS);
 
+  //check upload permissions
   if(auth_quickaclcheck("$NS:*") >= AUTH_UPLOAD){
-    $uploadok = true;
+    $UPLOADOK = true;
     //create the given namespace (just for beautification)
     $mdir = $conf['mediadir'].'/'.utf8_encodeFN(str_replace(':','/',$NS));
     io_makeFileDir("$mdir/xxx");
   }else{
-    $uploadok = false;
+    $UPLOADOK = false;
   }
 
-  if($_FILES['upload']['tmp_name'] && $uploadok){
+  if($_FILES['upload']['tmp_name'] && $UPLOADOK){
     media_upload($NS);
   }
 
-  //start output
-  html_head();
-?>
-<body>
-  <?html_msgarea()?>
-  <h1><?=$lang['mediaselect']?></h1>
-
-  <div class="mediaselect">
-    <div class="mediaselect-left">
-      <?=media_html_namespaces()?>
-    </div>
-    <div class="mediaselect-right">
-      <?
-        print media_html_media($NS);
-        if($uploadok){
-          print media_html_uploadform($NS);
-        }
-      ?>
-    </div>
-  </div>
+  //start output and load template
+  header('Content-Type: text/html; charset=utf-8');
+  include(DOKU_INC.'tpl/'.$conf['template'].'/media.php');
 
-</body>
-</html>
-<?
   //restore old umask
   umask($conf['oldumask']);
 
 /**********************************************/
 
+/**
+ * Handles Mediafile uploads
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
 function media_upload($NS){
   global $conf;
   global $lang;
@@ -86,76 +73,13 @@ function media_upload($NS){
   return false;
 }
 
-function media_html_uploadform($ns){
-  global $lang;
-?>
-  <div class="uploadform">
-  <form action="<?=$_SERVER['PHP_SELF']?>" name="upload" method="post" enctype="multipart/form-data">
-  <?=$lang['txt_upload']?>:<br />
-  <input type="file" name="upload" class="edit" onchange="suggestWikiname();" />
-  <input type="hidden" name="ns" value="<?=htmlspecialchars($ns)?>" /><br />
-  <?=$lang['txt_filename']?>:<br />
-  <input type="text" name="id" class="edit" />
-  <input type="submit" class="button" value="<?=$lang['btn_upload']?>" accesskey="s" />
-  </form>
-  </div>
-<?
-}
-
-function media_html_media($ns){
-  global $conf;
-  global $lang;
-  $dir = utf8_encodeFN(str_replace(':','/',$ns));
-
-  print '<b>'.$lang['mediafiles'].'</b>';
-  print ' <code>'.$ns.':</code>';
-
-  $data = array();
-  search($data,$conf['mediadir'],'search_media',array(),$dir);
-
-  if(!count($data)){
-    print '<div style="text-align:center; margin:2em;">';
-    print $lang['nothingfound'];
-    print '</div>';
-    return;
-  }
-
-  print '<ul>';
-  foreach($data as $item){
-    print '<li>';
-    print '<a href="javascript:mediaSelect(\''.$item['id'].'\')">';
-    print utf8_decodeFN($item['file']);
-    print '</a>';
-    if($item['isimg']){
-      print ' ('.$item['info'][0].'&#215;'.$item['info'][1];
-      print ' '.filesize_h($item['size']).')<br />';
-
-      # build thumbnail
-      $link=array();
-      $link['name']=$item['id'];
-      if($item['info'][0]>120) $link['name'] .= '?120';
-      $link = format_link_media($link);
-      print $link['name'];
-
-    }else{
-      print ' ('.filesize_h($item['size']).')';
-    }
-    print '</li>';
-  }
-  print '</ul>';
-}
-
-function media_html_namespaces(){
-  global $conf;
-  global $lang;
-
-  $data = array();
-  #add default namespace
-  print '<b><a href="'.DOKU_BASE.'media.php?ns=">'.$lang['namespaces'].'</a></b>';
-  search($data,$conf['mediadir'],'search_namespaces',array());
-  print html_buildlist($data,'idx',media_html_list_namespaces);
-}
-
+/**
+ * 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.'media.php?ns='.idfilter($item['id']).'" class="idx_dir">';
diff --git a/tpl/default/design.css b/tpl/default/design.css
index 2a428a1e5..2bf7903ea 100644
--- a/tpl/default/design.css
+++ b/tpl/default/design.css
@@ -42,6 +42,11 @@ hr {
   height: 0px;
 }
 
+div.nothing {
+  text-align:center;
+	margin: 2em;
+}
+
 /* ---------------- forms ------------------------ */
 
 form {
diff --git a/tpl/default/media.php b/tpl/default/media.php
new file mode 100644
index 000000000..6509bdb5a
--- /dev/null
+++ b/tpl/default/media.php
@@ -0,0 +1,62 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<?
+/**
+ * DokuWiki Default Template
+ *
+ * This is the template for the media selection popup.
+ *
+ * You should leave the doctype at the very top - It should
+ * always be the very first line of a document.
+ *
+ * @link   http://wiki.splitbrain.org/wiki:tpl:templates
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+?>
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?=$conf['lang']?>" lang="<?=$conf['lang']?>" dir="ltr">
+<head>
+  <title><?=hsc($lang['mediaselect'])?> [<?=hsc($conf['title'])?>]</title>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+  <?tpl_metaheaders()?>
+
+  <link rel="shortcut icon" href="<?=DOKU_BASE?>images/favicon.ico" />
+  <link rel="stylesheet" media="screen" type="text/css" href="<?=DOKU_TPL?>layout.css" />
+  <link rel="stylesheet" media="screen" type="text/css" href="<?=DOKU_TPL?>design.css" />
+
+  <!--[if gte IE 5]>
+  <style type="text/css">
+    /* that IE 5+ conditional comment makes this only visible in IE 5+ */
+    /* IE bugfix for transparent PNGs */
+    img { behavior: url("<?=DOKU_BASE?>/pngbehavior.htc"); }
+  </style>
+  <![endif]-->
+</head>
+
+<body>
+<div class="dokuwiki">
+  <?html_msgarea()?>
+
+  <h1><?=hsc($lang['mediaselect'])?></h1>
+
+  <div class="mediaselect">
+
+    <div class="mediaselect-left">
+      <b><a href="<?=DOKU_BASE?>/media.php?ns="><?=hsc($lang['namespaces'])?></a></b>
+
+			<?tpl_medianamespaces()?>
+		</div>
+
+    <div class="mediaselect-right">
+      <b>Available files in</b> <code><?=hsc($NS)?>:</code>
+
+      <?tpl_mediafilelist()?>
+
+			<div class="uploadform">
+			<?tpl_mediauploadform()?>
+			</div>
+		</div>
+
+  </div>
+
+</div>
+</body>
-- 
GitLab