wok-6.x diff wikiss/stuff/plugins/wkp_Upload.php @ 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
children 423d8ab737fc
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/wikiss/stuff/plugins/wkp_Upload.php	Wed Jun 01 18:38:36 2011 +0200
     1.3 @@ -0,0 +1,85 @@
     1.4 +<?php # coding: utf-8
     1.5 +
     1.6 +/** Transfert un fichier (images ...) dans pages/data
     1.7 + * Accès via : ?action=upload
     1.8 + */
     1.9 +class Upload
    1.10 +{
    1.11 +   public $description = "Télécharge un fichier dans la base Wiki";
    1.12 +      
    1.13 +   function template()
    1.14 +   {
    1.15 +   	global $html;
    1.16 +   	
    1.17 +	$upload = "Chargement";
    1.18 +   	switch ($_GET["action"]) {
    1.19 +   	case "edit" :
    1.20 +   		$html = preg_replace("/HISTORY/",
    1.21 +  	 		"<a href=\"$urlbase?action=upload\">$upload</a> / HISTORY",
    1.22 +  	 		$html);
    1.23 +  	 	break;
    1.24 +   	case "upload" :
    1.25 +   	case "uploadfile" :
    1.26 +   		$html = preg_replace('/ \/ <a href.*recent.*<\/a>/', '', $html);
    1.27 +   		$html = preg_replace('/.*name="query".*/', '', $html);
    1.28 +  	 	break;
    1.29 +  	default:
    1.30 +  		return 1;
    1.31 +   	}
    1.32 +	return 0;
    1.33 +   }
    1.34 +   
    1.35 +   function action($a)
    1.36 +   {
    1.37 +      global $plugins,$CONTENT,$HELP_BUTTON,$EDIT_BUTTON,$PAGE_TITLE,
    1.38 +      		$PAGE_TITLE_link,$editable;
    1.39 +      
    1.40 +      $upload = "Chargement";
    1.41 +      switch ($a) {
    1.42 +      case "upload" :
    1.43 +         $PAGE_TITLE_link = FALSE; // pas de lien sur le titre
    1.44 +         $editable = FALSE; // non editable
    1.45 +         $PAGE_TITLE = "$upload"; // titre de la page
    1.46 +         $CONTENT = '
    1.47 +<form method="post" enctype="multipart/form-data" action="?action=uploadfile">
    1.48 +<input type="file" name="file" value="file"/>
    1.49 +<input type="submit"/>
    1.50 +</form>
    1.51 +';
    1.52 +         break;
    1.53 +      case "uploadfile" :
    1.54 +	 @mkdir("pages/data");
    1.55 +	 $name = $_FILES["file"]["name"]; $n="";
    1.56 +	 if (is_file("pages/data/".$name)) $n=1;
    1.57 +	 while (is_file("pages/data/".$n.$name)) $n++;
    1.58 +	 move_uploaded_file($_FILES["file"]["tmp_name"], "pages/data/".$n.$name);
    1.59 +	 $url = "pages/data/".$n.$name;
    1.60 +         $PAGE_TITLE_link = FALSE; // pas de lien sur le titre
    1.61 +         $editable = FALSE; // non editable
    1.62 +         $PAGE_TITLE = "$upload"; // titre de la page
    1.63 +         $CONTENT = '<h1><a href="javascript:history.go(-2)">'.
    1.64 +         	$EDIT_BUTTON.'</a></h1>
    1.65 +<p>
    1.66 +Le fichier '.$_FILES["file"]["name"].' ('.$_FILES["file"]["size"].' octets, '.
    1.67 +		$_FILES["file"]["type"].' est plac&eacute; en <a href="'.$url.'">'.
    1.68 +		$url.'</a>.
    1.69 +</p>';
    1.70 +	 switch (substr($_FILES["file"]["type"],0,4)) {
    1.71 +	 case "imag":
    1.72 +	 	$CONTENT .= '
    1.73 +<p>
    1.74 +Vous pouvez inc&eacute;rer cette image avec <b>['.$url.']</b> voir
    1.75 +<a href="?page='.$HELP_BUTTON.'">'.$HELP_BUTTON.'</a> pour plus de d&eacute;tails.
    1.76 +</p>
    1.77 +<img src="'.$url.'" alt="'.$url.'" />';
    1.78 +	 	break;
    1.79 +	 }
    1.80 +         break;
    1.81 +      default:
    1.82 +	return FALSE; // action non traitée
    1.83 +      }
    1.84 +      return TRUE;
    1.85 +   } // action
    1.86 +}
    1.87 +
    1.88 +?>