wok rev 10787

wikiss: add upload plugin
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jun 01 18:38:36 2011 +0200 (2011-06-01)
parents c7430e68b5b7
children c2e7c7baed66
files wikiss/receipt wikiss/stuff/plugins/wkp_Upload.php
line diff
     1.1 --- a/wikiss/receipt	Wed Jun 01 14:04:02 2011 +0200
     1.2 +++ b/wikiss/receipt	Wed Jun 01 18:38:36 2011 +0200
     1.3 @@ -26,5 +26,6 @@
     1.4  	mkdir -p $fs/var/www
     1.5  	cp -a $src $fs/var/www/wikiss
     1.6  	rm -f $fs/var/www/wikiss/historique/*/*.bak
     1.7 +	cp -a $stuff/* $fs/var/www/wikiss/
     1.8  	chown -R www.www $fs/var/www/wikiss
     1.9  }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/wikiss/stuff/plugins/wkp_Upload.php	Wed Jun 01 18:38:36 2011 +0200
     2.3 @@ -0,0 +1,85 @@
     2.4 +<?php # coding: utf-8
     2.5 +
     2.6 +/** Transfert un fichier (images ...) dans pages/data
     2.7 + * Accès via : ?action=upload
     2.8 + */
     2.9 +class Upload
    2.10 +{
    2.11 +   public $description = "Télécharge un fichier dans la base Wiki";
    2.12 +      
    2.13 +   function template()
    2.14 +   {
    2.15 +   	global $html;
    2.16 +   	
    2.17 +	$upload = "Chargement";
    2.18 +   	switch ($_GET["action"]) {
    2.19 +   	case "edit" :
    2.20 +   		$html = preg_replace("/HISTORY/",
    2.21 +  	 		"<a href=\"$urlbase?action=upload\">$upload</a> / HISTORY",
    2.22 +  	 		$html);
    2.23 +  	 	break;
    2.24 +   	case "upload" :
    2.25 +   	case "uploadfile" :
    2.26 +   		$html = preg_replace('/ \/ <a href.*recent.*<\/a>/', '', $html);
    2.27 +   		$html = preg_replace('/.*name="query".*/', '', $html);
    2.28 +  	 	break;
    2.29 +  	default:
    2.30 +  		return 1;
    2.31 +   	}
    2.32 +	return 0;
    2.33 +   }
    2.34 +   
    2.35 +   function action($a)
    2.36 +   {
    2.37 +      global $plugins,$CONTENT,$HELP_BUTTON,$EDIT_BUTTON,$PAGE_TITLE,
    2.38 +      		$PAGE_TITLE_link,$editable;
    2.39 +      
    2.40 +      $upload = "Chargement";
    2.41 +      switch ($a) {
    2.42 +      case "upload" :
    2.43 +         $PAGE_TITLE_link = FALSE; // pas de lien sur le titre
    2.44 +         $editable = FALSE; // non editable
    2.45 +         $PAGE_TITLE = "$upload"; // titre de la page
    2.46 +         $CONTENT = '
    2.47 +<form method="post" enctype="multipart/form-data" action="?action=uploadfile">
    2.48 +<input type="file" name="file" value="file"/>
    2.49 +<input type="submit"/>
    2.50 +</form>
    2.51 +';
    2.52 +         break;
    2.53 +      case "uploadfile" :
    2.54 +	 @mkdir("pages/data");
    2.55 +	 $name = $_FILES["file"]["name"]; $n="";
    2.56 +	 if (is_file("pages/data/".$name)) $n=1;
    2.57 +	 while (is_file("pages/data/".$n.$name)) $n++;
    2.58 +	 move_uploaded_file($_FILES["file"]["tmp_name"], "pages/data/".$n.$name);
    2.59 +	 $url = "pages/data/".$n.$name;
    2.60 +         $PAGE_TITLE_link = FALSE; // pas de lien sur le titre
    2.61 +         $editable = FALSE; // non editable
    2.62 +         $PAGE_TITLE = "$upload"; // titre de la page
    2.63 +         $CONTENT = '<h1><a href="javascript:history.go(-2)">'.
    2.64 +         	$EDIT_BUTTON.'</a></h1>
    2.65 +<p>
    2.66 +Le fichier '.$_FILES["file"]["name"].' ('.$_FILES["file"]["size"].' octets, '.
    2.67 +		$_FILES["file"]["type"].' est plac&eacute; en <a href="'.$url.'">'.
    2.68 +		$url.'</a>.
    2.69 +</p>';
    2.70 +	 switch (substr($_FILES["file"]["type"],0,4)) {
    2.71 +	 case "imag":
    2.72 +	 	$CONTENT .= '
    2.73 +<p>
    2.74 +Vous pouvez inc&eacute;rer cette image avec <b>['.$url.']</b> voir
    2.75 +<a href="?page='.$HELP_BUTTON.'">'.$HELP_BUTTON.'</a> pour plus de d&eacute;tails.
    2.76 +</p>
    2.77 +<img src="'.$url.'" alt="'.$url.'" />';
    2.78 +	 	break;
    2.79 +	 }
    2.80 +         break;
    2.81 +      default:
    2.82 +	return FALSE; // action non traitée
    2.83 +      }
    2.84 +      return TRUE;
    2.85 +   } // action
    2.86 +}
    2.87 +
    2.88 +?>