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@10798
|
47 <table>
|
pascal@10798
|
48 ';
|
pascal@10798
|
49 if ($handle = @opendir("pages/data")) {
|
pascal@10798
|
50 while(($item = readdir($handle)) !== false) {
|
pascal@10798
|
51 if ($item == '..' || $item == '.') continue;
|
pascal@10798
|
52 $CONTENT .= '<tr><td><input type=checkbox ';
|
pascal@10798
|
53 exec('grep -qs "pages/data/'.$item.'" pages/*.txt', $tmp, $ret);
|
pascal@10798
|
54 if ($ret == 0) $CONTENT .= 'checked=checked ';
|
pascal@10798
|
55 $CONTENT .= 'disabled=disabled /><a href="pages/data/'.
|
pascal@10798
|
56 $item.'">'.$item.'</a></td></tr>';
|
pascal@10798
|
57 }
|
pascal@10798
|
58 }
|
pascal@10798
|
59 $CONTENT .= '
|
pascal@10798
|
60 </table>
|
pascal@10787
|
61 </form>
|
pascal@10787
|
62 ';
|
pascal@10787
|
63 break;
|
pascal@10787
|
64 case "uploadfile" :
|
pascal@10787
|
65 @mkdir("pages/data");
|
pascal@10787
|
66 $name = $_FILES["file"]["name"]; $n="";
|
pascal@10787
|
67 if (is_file("pages/data/".$name)) $n=1;
|
pascal@10787
|
68 while (is_file("pages/data/".$n.$name)) $n++;
|
pascal@10787
|
69 move_uploaded_file($_FILES["file"]["tmp_name"], "pages/data/".$n.$name);
|
pascal@10787
|
70 $url = "pages/data/".$n.$name;
|
pascal@10787
|
71 $PAGE_TITLE_link = FALSE; // pas de lien sur le titre
|
pascal@10787
|
72 $editable = FALSE; // non editable
|
pascal@10787
|
73 $PAGE_TITLE = "$upload"; // titre de la page
|
pascal@10787
|
74 $CONTENT = '<h1><a href="javascript:history.go(-2)">'.
|
pascal@10787
|
75 $EDIT_BUTTON.'</a></h1>
|
pascal@10787
|
76 <p>
|
pascal@10787
|
77 Le fichier '.$_FILES["file"]["name"].' ('.$_FILES["file"]["size"].' octets, '.
|
pascal@10787
|
78 $_FILES["file"]["type"].' est placé en <a href="'.$url.'">'.
|
pascal@10787
|
79 $url.'</a>.
|
pascal@10787
|
80 </p>';
|
pascal@10787
|
81 switch (substr($_FILES["file"]["type"],0,4)) {
|
pascal@10787
|
82 case "imag":
|
pascal@10787
|
83 $CONTENT .= '
|
pascal@10787
|
84 <p>
|
pascal@10787
|
85 Vous pouvez incérer cette image avec <b>['.$url.']</b> voir
|
pascal@10787
|
86 <a href="?page='.$HELP_BUTTON.'">'.$HELP_BUTTON.'</a> pour plus de détails.
|
pascal@10787
|
87 </p>
|
pascal@10787
|
88 <img src="'.$url.'" alt="'.$url.'" />';
|
pascal@10787
|
89 break;
|
pascal@10787
|
90 }
|
pascal@10787
|
91 break;
|
pascal@10787
|
92 default:
|
pascal@10787
|
93 return FALSE; // action non traitée
|
pascal@10787
|
94 }
|
pascal@10787
|
95 return TRUE;
|
pascal@10787
|
96 } // action
|
pascal@10924
|
97
|
pascal@10924
|
98 function formatEnd()
|
pascal@10924
|
99 {
|
pascal@10924
|
100 global $CONTENT;
|
pascal@10924
|
101 $CONTENT = preg_replace('#\[(.*)|(pages/.*)\]#','<a href="$1">$2</a>',$CONTENT);
|
pascal@10924
|
102 $CONTENT = preg_replace('#\[(pages/.*)\]#','<a href="$1">$1</a>',$CONTENT);
|
pascal@10924
|
103 }
|
pascal@10787
|
104 }
|
pascal@10787
|
105
|
pascal@10787
|
106 ?>
|