wok-6.x annotate 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
rev   line source
pascal@10787 1 <?php # coding: utf-8
pascal@10787 2
pascal@10787 3 /** Transfert un fichier (images ...) dans pages/data
pascal@10787 4 * Accès via : ?action=upload
pascal@10787 5 */
pascal@10787 6 class Upload
pascal@10787 7 {
pascal@10787 8 public $description = "Télécharge un fichier dans la base Wiki";
pascal@10787 9
pascal@10787 10 function template()
pascal@10787 11 {
pascal@10787 12 global $html;
pascal@10787 13
pascal@10787 14 $upload = "Chargement";
pascal@10787 15 switch ($_GET["action"]) {
pascal@10787 16 case "edit" :
pascal@10787 17 $html = preg_replace("/HISTORY/",
pascal@10787 18 "<a href=\"$urlbase?action=upload\">$upload</a> / HISTORY",
pascal@10787 19 $html);
pascal@10787 20 break;
pascal@10787 21 case "upload" :
pascal@10787 22 case "uploadfile" :
pascal@10787 23 $html = preg_replace('/ \/ <a href.*recent.*<\/a>/', '', $html);
pascal@10787 24 $html = preg_replace('/.*name="query".*/', '', $html);
pascal@10787 25 break;
pascal@10787 26 default:
pascal@10787 27 return 1;
pascal@10787 28 }
pascal@10787 29 return 0;
pascal@10787 30 }
pascal@10787 31
pascal@10787 32 function action($a)
pascal@10787 33 {
pascal@10787 34 global $plugins,$CONTENT,$HELP_BUTTON,$EDIT_BUTTON,$PAGE_TITLE,
pascal@10787 35 $PAGE_TITLE_link,$editable;
pascal@10787 36
pascal@10787 37 $upload = "Chargement";
pascal@10787 38 switch ($a) {
pascal@10787 39 case "upload" :
pascal@10787 40 $PAGE_TITLE_link = FALSE; // pas de lien sur le titre
pascal@10787 41 $editable = FALSE; // non editable
pascal@10787 42 $PAGE_TITLE = "$upload"; // titre de la page
pascal@10787 43 $CONTENT = '
pascal@10787 44 <form method="post" enctype="multipart/form-data" action="?action=uploadfile">
pascal@10787 45 <input type="file" name="file" value="file"/>
pascal@10787 46 <input type="submit"/>
pascal@10787 47 </form>
pascal@10787 48 ';
pascal@10787 49 break;
pascal@10787 50 case "uploadfile" :
pascal@10787 51 @mkdir("pages/data");
pascal@10787 52 $name = $_FILES["file"]["name"]; $n="";
pascal@10787 53 if (is_file("pages/data/".$name)) $n=1;
pascal@10787 54 while (is_file("pages/data/".$n.$name)) $n++;
pascal@10787 55 move_uploaded_file($_FILES["file"]["tmp_name"], "pages/data/".$n.$name);
pascal@10787 56 $url = "pages/data/".$n.$name;
pascal@10787 57 $PAGE_TITLE_link = FALSE; // pas de lien sur le titre
pascal@10787 58 $editable = FALSE; // non editable
pascal@10787 59 $PAGE_TITLE = "$upload"; // titre de la page
pascal@10787 60 $CONTENT = '<h1><a href="javascript:history.go(-2)">'.
pascal@10787 61 $EDIT_BUTTON.'</a></h1>
pascal@10787 62 <p>
pascal@10787 63 Le fichier '.$_FILES["file"]["name"].' ('.$_FILES["file"]["size"].' octets, '.
pascal@10787 64 $_FILES["file"]["type"].' est plac&eacute; en <a href="'.$url.'">'.
pascal@10787 65 $url.'</a>.
pascal@10787 66 </p>';
pascal@10787 67 switch (substr($_FILES["file"]["type"],0,4)) {
pascal@10787 68 case "imag":
pascal@10787 69 $CONTENT .= '
pascal@10787 70 <p>
pascal@10787 71 Vous pouvez inc&eacute;rer cette image avec <b>['.$url.']</b> voir
pascal@10787 72 <a href="?page='.$HELP_BUTTON.'">'.$HELP_BUTTON.'</a> pour plus de d&eacute;tails.
pascal@10787 73 </p>
pascal@10787 74 <img src="'.$url.'" alt="'.$url.'" />';
pascal@10787 75 break;
pascal@10787 76 }
pascal@10787 77 break;
pascal@10787 78 default:
pascal@10787 79 return FALSE; // action non traitée
pascal@10787 80 }
pascal@10787 81 return TRUE;
pascal@10787 82 } // action
pascal@10787 83 }
pascal@10787 84
pascal@10787 85 ?>