954 |
florian |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
attach.class.php
|
|
|
4 |
Code original de ce fichier : Eric FELDSTEIN
|
|
|
5 |
Copyright (c) 2002, Hendrik Mans <hendrik@mans.de>
|
|
|
6 |
Copyright 2002, 2003 David DELON
|
|
|
7 |
Copyright 2002, 2003 Charles NEPOTE
|
|
|
8 |
Copyright 2003,2004 Eric FELDSTEIN
|
|
|
9 |
Copyright 2003 Jean-Pascal MILCENT
|
|
|
10 |
All rights reserved.
|
|
|
11 |
Redistribution and use in source and binary forms, with or without
|
|
|
12 |
modification, are permitted provided that the following conditions
|
|
|
13 |
are met:
|
|
|
14 |
1. Redistributions of source code must retain the above copyright
|
|
|
15 |
notice, this list of conditions and the following disclaimer.
|
|
|
16 |
2. Redistributions in binary form must reproduce the above copyright
|
|
|
17 |
notice, this list of conditions and the following disclaimer in the
|
|
|
18 |
documentation and/or other materials provided with the distribution.
|
|
|
19 |
3. The name of the author may not be used to endorse or promote products
|
|
|
20 |
derived from this software without specific prior written permission.
|
|
|
21 |
|
|
|
22 |
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
23 |
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
24 |
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
25 |
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
26 |
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
27 |
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
28 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
29 |
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
30 |
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
31 |
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
32 |
*/
|
|
|
33 |
# Classe de gestion de l'action {{attach}}
|
|
|
34 |
# voir actions/attach.php ppour la documentation
|
|
|
35 |
# copyrigth Eric Feldstein 2003-2004
|
|
|
36 |
|
|
|
37 |
class attach {
|
|
|
38 |
var $wiki = ''; //objet wiki courant
|
|
|
39 |
var $attachConfig = array(); //configuration de l'action
|
|
|
40 |
var $file = ''; //nom du fichier
|
|
|
41 |
var $desc = ''; //description du fichier
|
|
|
42 |
var $link = ''; //url de lien (image sensible)
|
|
|
43 |
var $isPicture = 0; //indique si c'est une image
|
|
|
44 |
var $isAudio = 0; //indique si c'est un fichier audio
|
|
|
45 |
var $classes = ''; //classe pour afficher une image
|
|
|
46 |
var $attachErr = ''; //message d'erreur
|
|
|
47 |
var $pageId = 0; //identifiant de la page
|
|
|
48 |
var $isSafeMode = false; //indicateur du safe mode de PHP
|
|
|
49 |
/**
|
|
|
50 |
* Constructeur. Met les valeurs par defaut aux paramètres de configuration
|
|
|
51 |
*/
|
|
|
52 |
function attach(&$wiki){
|
|
|
53 |
$this->wiki = $wiki;
|
|
|
54 |
$this->attachConfig = $this->wiki->GetConfigValue("attach_config");
|
|
|
55 |
if (empty($this->attachConfig["ext_images"])) $this->attachConfig["ext_images"] = "gif|jpeg|png|jpg";
|
|
|
56 |
if (empty($this->attachConfig["ext_audio"])) $this->attachConfig["ext_audio"] = "mp3";
|
|
|
57 |
if (empty($this->attachConfig["ext_script"])) $this->attachConfig["ext_script"] = "php|php3|asp|asx|vb|vbs|js";
|
|
|
58 |
if (empty($this->attachConfig['upload_path'])) $this->attachConfig['upload_path'] = 'files';
|
|
|
59 |
if (empty($this->attachConfig['update_symbole'])) $this->attachConfig['update_symbole'] = '*';
|
|
|
60 |
if (empty($this->attachConfig['max_file_size'])) $this->attachConfig['max_file_size'] = 1024*2000; //2000ko max
|
|
|
61 |
if (empty($this->attachConfig['fmDelete_symbole'])) $this->attachConfig['fmDelete_symbole'] = 'Supr';
|
|
|
62 |
if (empty($this->attachConfig['fmRestore_symbole'])) $this->attachConfig['fmRestore_symbole'] = 'Rest';
|
|
|
63 |
if (empty($this->attachConfig['fmTrash_symbole'])) $this->attachConfig['fmTrash_symbole'] = 'Poubelle';
|
|
|
64 |
$this->isSafeMode = ini_get("safe_mode");
|
|
|
65 |
}
|
|
|
66 |
/******************************************************************************
|
|
|
67 |
* FONCTIONS UTILES
|
|
|
68 |
*******************************************************************************/
|
|
|
69 |
/**
|
|
|
70 |
* Création d'une suite de répertoires récursivement
|
|
|
71 |
*/
|
|
|
72 |
function mkdir_recursif ($dir) {
|
|
|
73 |
if (strlen($dir) == 0) return 0;
|
|
|
74 |
if (is_dir($dir)) return 1;
|
|
|
75 |
elseif (dirname($dir) == $dir) return 1;
|
|
|
76 |
return ($this->mkdir_recursif(dirname($dir)) and mkdir($dir,0755));
|
|
|
77 |
}
|
|
|
78 |
/**
|
|
|
79 |
* Renvois le chemin du script
|
|
|
80 |
*/
|
|
|
81 |
function GetScriptPath () {
|
|
|
82 |
if (preg_match("/.(php)$/i",$_SERVER["PHP_SELF"])){
|
|
|
83 |
$a = explode('/',$_SERVER["PHP_SELF"]);
|
|
|
84 |
$a[count($a)-1] = '';
|
|
|
85 |
$path = implode('/',$a);
|
|
|
86 |
}else{
|
|
|
87 |
$path = $_SERVER["PHP_SELF"];
|
|
|
88 |
}
|
|
|
89 |
return !empty($_SERVER["HTTP_HOST"])? 'http://'.$_SERVER["HTTP_HOST"].$path : 'http://'.$_SERVER["SERVER_NAME"].$path ;
|
|
|
90 |
}
|
|
|
91 |
/**
|
|
|
92 |
* Calcul le repertoire d'upload en fonction du safe_mode
|
|
|
93 |
*/
|
|
|
94 |
function GetUploadPath(){
|
|
|
95 |
if ($this->isSafeMode) {
|
|
|
96 |
$path = $this->attachConfig['upload_path'];
|
|
|
97 |
}else{
|
|
|
98 |
$path = $this->attachConfig['upload_path'].'/'.$this->wiki->GetPageTag();
|
|
|
99 |
if (! is_dir($path)) $this->mkdir_recursif($path);
|
|
|
100 |
}
|
|
|
101 |
return $path;
|
|
|
102 |
}
|
|
|
103 |
/**
|
|
|
104 |
* Calcule le nom complet du fichier attaché en fonction du safe_mode, du nom et de la date de
|
|
|
105 |
* revision la page courante.
|
|
|
106 |
* Le nom du fichier "mon fichier.ext" attache à la page "LaPageWiki"sera :
|
|
|
107 |
* mon_fichier_datepage_update.ext
|
|
|
108 |
* update : date de derniere mise a jour du fichier
|
|
|
109 |
* datepage : date de revision de la page à laquelle le fichier a ete lié/mis a jour
|
|
|
110 |
* Si le fichier n'est pas une image un '_' est ajoute : mon_fichier_datepage_update.ext_
|
|
|
111 |
* Selon la valeur de safe_mode :
|
|
|
112 |
* safe_mode = on : LaPageWiki_mon_fichier_datepage_update.ext_
|
|
|
113 |
* safe_mode = off: LaPageWiki/mon_fichier_datepage_update.ext_ avec "LaPageWiki" un sous-repertoire du répertoire upload
|
|
|
114 |
*/
|
|
|
115 |
function GetFullFilename($newName = false){
|
|
|
116 |
$pagedate = $this->convertDate($this->wiki->page['time']);
|
|
|
117 |
//decompose le nom du fichier en nom+extension
|
|
|
118 |
if (preg_match('`^(.*)\.(.*)$`', str_replace(' ','_',$this->file), $match)){
|
|
|
119 |
list(,$file['name'],$file['ext'])=$match;
|
|
|
120 |
if(!$this->isPicture() && !$this->isAudio()) $file['ext'] .= '_';
|
|
|
121 |
}else{
|
|
|
122 |
return false;
|
|
|
123 |
}
|
|
|
124 |
//recuperation du chemin d'upload
|
|
|
125 |
$path = $this->GetUploadPath($this->isSafeMode);
|
|
|
126 |
//generation du nom ou recherche de fichier ?
|
|
|
127 |
if ($newName){
|
|
|
128 |
$full_file_name = $file['name'].'_'.$pagedate.'_'.$this->getDate().'.'.$file['ext'];
|
|
|
129 |
if($this->isSafeMode){
|
|
|
130 |
$full_file_name = $path.'/'.$this->wiki->GetPageTag().'_'.$full_file_name;
|
|
|
131 |
}else{
|
|
|
132 |
$full_file_name = $path.'/'.$full_file_name;
|
|
|
133 |
}
|
|
|
134 |
}else{
|
|
|
135 |
//recherche du fichier
|
|
|
136 |
if($this->isSafeMode){
|
|
|
137 |
//TODO Recherche dans le cas ou safe_mode=on
|
|
|
138 |
$searchPattern = '`^'.$this->wiki->GetPageTag().'_'.$file['name'].'_\d{14}_\d{14}\.'.$file['ext'].'$`';
|
|
|
139 |
}else{
|
|
|
140 |
$searchPattern = '`^'.$file['name'].'_\d{14}_\d{14}\.'.$file['ext'].'$`';
|
|
|
141 |
}
|
|
|
142 |
$files = $this->searchFiles($searchPattern,$path);
|
|
|
143 |
|
|
|
144 |
$unedate = 0;
|
|
|
145 |
foreach ($files as $file){
|
|
|
146 |
//recherche du fichier qui une datepage <= a la date de la page
|
|
|
147 |
if($file['datepage']<=$pagedate){
|
|
|
148 |
//puis qui a une dateupload la plus grande
|
|
|
149 |
if ($file['dateupload']>$unedate){
|
|
|
150 |
$theFile = $file;
|
|
|
151 |
$unedate = $file['dateupload'];
|
|
|
152 |
}
|
|
|
153 |
}
|
|
|
154 |
}
|
|
|
155 |
if (is_array($theFile)){
|
|
|
156 |
$full_file_name = $path.'/'.$theFile['realname'];
|
|
|
157 |
}
|
|
|
158 |
}
|
|
|
159 |
return $full_file_name;
|
|
|
160 |
}
|
|
|
161 |
/**
|
|
|
162 |
* Test si le fichier est une image
|
|
|
163 |
*/
|
|
|
164 |
function isPicture(){
|
|
|
165 |
return preg_match("/.(".$this->attachConfig["ext_images"].")$/i",$this->file)==1;
|
|
|
166 |
}
|
|
|
167 |
/**
|
|
|
168 |
* Test si le fichier est un fichier audio
|
|
|
169 |
*/
|
|
|
170 |
function isAudio(){
|
|
|
171 |
return preg_match("/.(".$this->attachConfig["ext_audio"].")$/i",$this->file)==1;
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
/**
|
|
|
175 |
* Renvoie la date courante au format utilise par les fichiers
|
|
|
176 |
*/
|
|
|
177 |
function getDate(){
|
|
|
178 |
return date('YmdHis');
|
|
|
179 |
}
|
|
|
180 |
/**
|
|
|
181 |
* convertie une date yyyy-mm-dd hh:mm:ss au format yyyymmddhhmmss
|
|
|
182 |
*/
|
|
|
183 |
function convertDate($date){
|
|
|
184 |
$date = str_replace(' ','', $date);
|
|
|
185 |
$date = str_replace(':','', $date);
|
|
|
186 |
return str_replace('-','', $date);
|
|
|
187 |
}
|
|
|
188 |
/**
|
|
|
189 |
* Parse une date au format yyyymmddhhmmss et renvoie un tableau assiatif
|
|
|
190 |
*/
|
|
|
191 |
function parseDate($sDate){
|
|
|
192 |
$pattern = '`^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$`';
|
|
|
193 |
$res = '';
|
|
|
194 |
if (preg_match($pattern, $sDate, $m)){
|
|
|
195 |
//list(,$res['year'],$res['month'],$res['day'],$res['hour'],$res['min'],$res['sec'])=$m;
|
|
|
196 |
$res = $m[1].'-'.$m[2].'-'.$m[3].' '.$m[4].':'.$m[5].':'.$m[6];
|
|
|
197 |
}
|
|
|
198 |
return ($res?$res:false);
|
|
|
199 |
}
|
|
|
200 |
/**
|
|
|
201 |
* Decode un nom long de fichier
|
|
|
202 |
*/
|
|
|
203 |
function decodeLongFilename($filename){
|
|
|
204 |
$afile = array();
|
|
|
205 |
$afile['realname'] = basename($filename);
|
|
|
206 |
$afile['size'] = filesize($filename);
|
|
|
207 |
$afile['path'] = dirname($filename);
|
|
|
208 |
if(preg_match('`^(.*)_(\d{14})_(\d{14})\.(.*)(trash\d{14})?$`', $afile['realname'], $m)){
|
|
|
209 |
$afile['name'] = $m[1];
|
|
|
210 |
//suppression du nom de la page si safe_mode=on
|
|
|
211 |
if ($this->isSafeMode){
|
|
|
212 |
$afile['name'] = preg_replace('`^('.$this->wiki->tag.')_(.*)$`i', '$2', $afile['name']);
|
|
|
213 |
}
|
|
|
214 |
$afile['datepage'] = $m[2];
|
|
|
215 |
$afile['dateupload'] = $m[3];
|
|
|
216 |
$afile['trashdate'] = preg_replace('`(.*)trash(\d{14})`', '$2', $m[4]);
|
|
|
217 |
//suppression de trashxxxxxxxxxxxxxx eventuel
|
|
|
218 |
$afile['ext'] = preg_replace('`^(.*)(trash\d{14})$`', '$1', $m[4]);
|
|
|
219 |
$afile['ext'] = rtrim($afile['ext'],'_');
|
|
|
220 |
//$afile['ext'] = rtrim($m[4],'_');
|
|
|
221 |
}
|
|
|
222 |
return $afile;
|
|
|
223 |
}
|
|
|
224 |
/**
|
|
|
225 |
* Renvois un tableau des fichiers correspondant au pattern. Chaque element du tableau est un
|
|
|
226 |
* tableau associatif contenant les informations sur le fichier
|
|
|
227 |
*/
|
|
|
228 |
function searchFiles($filepattern,$start_dir){
|
|
|
229 |
$files_matched = array();
|
|
|
230 |
$start_dir = rtrim($start_dir,'\/');
|
|
|
231 |
$fh = opendir($start_dir);
|
|
|
232 |
while (($file = readdir($fh)) !== false) {
|
|
|
233 |
if (strcmp($file, '.')==0 || strcmp($file, '..')==0 || is_dir($file)) continue;
|
|
|
234 |
if (preg_match($filepattern, $file)){
|
|
|
235 |
$files_matched[] = $this->decodeLongFilename($start_dir.'/'.$file);
|
|
|
236 |
}
|
|
|
237 |
}
|
|
|
238 |
return $files_matched;
|
|
|
239 |
}
|
|
|
240 |
/******************************************************************************
|
|
|
241 |
* FONCTIONS D'ATTACHEMENTS
|
|
|
242 |
*******************************************************************************/
|
|
|
243 |
/**
|
|
|
244 |
* Test les paramètres passé à l'action
|
|
|
245 |
*/
|
|
|
246 |
function CheckParams(){
|
|
|
247 |
//recuperation des parametres necessaire
|
|
|
248 |
$this->file = $this->wiki->GetParameter("attachfile");
|
|
|
249 |
if (empty($this->file)) $this->file = $this->wiki->GetParameter("file");
|
|
|
250 |
$this->desc = $this->wiki->GetParameter("attachdesc");
|
|
|
251 |
if (empty($this->desc)) $this->desc = $this->wiki->GetParameter("desc");
|
|
|
252 |
$this->link = $this->wiki->GetParameter("attachlink");//url de lien - uniquement si c'est une image
|
|
|
253 |
if (empty($this->link)) $this->link = $this->wiki->GetParameter("link");
|
|
|
254 |
//test de validité des parametres
|
|
|
255 |
if (empty($this->file)){
|
|
|
256 |
$this->attachErr = $this->wiki->Format("//action attach : paramètre **file** manquant//---");
|
|
|
257 |
}
|
|
|
258 |
if ($this->isPicture() && empty($this->desc)){
|
|
|
259 |
$this->attachErr .= $this->wiki->Format("//action attach : paramètre **desc** obligatoire pour une image//---");
|
|
|
260 |
}
|
|
|
261 |
if ($this->wiki->GetParameter("class")) {
|
|
|
262 |
$array_classes = explode(" ", $this->wiki->GetParameter("class"));
|
|
|
263 |
foreach ($array_classes as $c) { $this->classes = $this->classes . "attach_" . $c . " "; }
|
|
|
264 |
$this->classes = trim($this->classes);
|
|
|
265 |
}
|
|
|
266 |
}
|
|
|
267 |
/**
|
|
|
268 |
* Affiche le fichier lié comme une image
|
|
|
269 |
*/
|
|
|
270 |
function showAsImage($fullFilename){
|
|
|
271 |
//c'est une image : balise <IMG..../>
|
|
|
272 |
$img = "<img src=\"".$this->GetScriptPath().$fullFilename."\" ".
|
|
|
273 |
"alt=\"".$this->desc.($this->link?"\nLien vers: $this->link":"")."\" />";
|
|
|
274 |
//test si c'est une image sensible
|
|
|
275 |
if(!empty($this->link)){
|
|
|
276 |
//c'est une image sensible
|
|
|
277 |
//test si le lien est un lien interwiki
|
|
|
278 |
if (preg_match("/^([A-Z][A-Z,a-z]+)[:]([A-Z,a-z,0-9]*)$/s", $this->link, $matches))
|
|
|
279 |
{ //modifie $link pour être un lien vers un autre wiki
|
|
|
280 |
$this->link = $this->wiki->GetInterWikiUrl($matches[1], $matches[2]);
|
|
|
281 |
}
|
|
|
282 |
//calcule du lien
|
|
|
283 |
$output = $this->wiki->Format('[['.$this->link." $this->file]]");
|
|
|
284 |
$output = eregi_replace(">$this->file<",">$img<",$output);//insertion du tag <img...> dans le lien
|
|
|
285 |
}else{
|
|
|
286 |
//ce n'est pas une image sensible
|
|
|
287 |
$output = $img;
|
|
|
288 |
}
|
|
|
289 |
$output = ($this->classes?"<span class=\"$this->classes\">$output</span>":$output);
|
|
|
290 |
echo $output;
|
|
|
291 |
$this->showUpdateLink();
|
|
|
292 |
}
|
|
|
293 |
/**
|
|
|
294 |
* Affiche le fichier lié comme un lien
|
|
|
295 |
*/
|
|
|
296 |
function showAsLink($fullFilename){
|
|
|
297 |
$url = $this->wiki->href("download",$this->wiki->GetPageTag(),"file=$this->file");
|
|
|
298 |
echo '<a href="'.$url.'">'.($this->desc?$this->desc:$this->file)."</a>";
|
|
|
299 |
$this->showUpdateLink();
|
|
|
300 |
}
|
|
|
301 |
// Affiche le fichier liee comme un fichier audio
|
|
|
302 |
function showAsAudio($fullFilename){
|
|
|
303 |
$output = "<object type=\"application/x-shockwave-flash\" data=\"tools/player/dewplayer.swf?son=$fullFilename&bgcolor=FFFFFF\" width=\"200\"
|
|
|
304 |
height=\"20\"><param name=\"movie\" value=\"tools/player/dewplayer.swf?son=$fullFilename&bgcolor=FFFFFF\"/></object>";
|
|
|
305 |
$output .= "<br></br>";
|
|
|
306 |
$output .="[<a href=\"$fullFilename\">mp3</a>]";
|
|
|
307 |
echo $output;
|
|
|
308 |
$this->showUpdateLink();
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
/**
|
|
|
312 |
* Affiche le lien de mise à jour
|
|
|
313 |
*/
|
|
|
314 |
function showUpdateLink(){
|
|
|
315 |
echo " <a href=\"".
|
|
|
316 |
$this->wiki->href("upload",$this->wiki->GetPageTag(),"file=$this->file").
|
|
|
317 |
"\" title='Mise à jour'>".$this->attachConfig['update_symbole']."</a>";
|
|
|
318 |
}
|
|
|
319 |
/**
|
|
|
320 |
* Affiche un liens comme un fichier inexistant
|
|
|
321 |
*/
|
|
|
322 |
function showFileNotExits(){
|
|
|
323 |
echo $this->file."<a href=\"".$this->wiki->href("upload",$this->wiki->GetPageTag(),"file=$this->file")."\">?</a>";
|
|
|
324 |
}
|
|
|
325 |
/**
|
|
|
326 |
* Affiche l'attachement
|
|
|
327 |
*/
|
|
|
328 |
function doAttach(){
|
|
|
329 |
$this->CheckParams();
|
|
|
330 |
if ($this->attachErr) {
|
|
|
331 |
echo $this->attachErr;
|
|
|
332 |
return;
|
|
|
333 |
}
|
|
|
334 |
$fullFilename = $this->GetFullFilename();
|
|
|
335 |
//test d'existance du fichier
|
|
|
336 |
if((!file_exists($fullFilename))||($fullFilename=='')){
|
|
|
337 |
$this->showFileNotExits();
|
|
|
338 |
return;
|
|
|
339 |
}
|
|
|
340 |
//le fichier existe : affichage en fonction du type
|
|
|
341 |
if($this->isPicture()){
|
|
|
342 |
$this->showAsImage($fullFilename);
|
|
|
343 |
}else{
|
|
|
344 |
if($this->isAudio()){
|
|
|
345 |
$this->showAsAudio($fullFilename);
|
|
|
346 |
}
|
|
|
347 |
else {
|
|
|
348 |
$this->showAsLink($fullFilename);
|
|
|
349 |
}
|
|
|
350 |
}
|
|
|
351 |
}
|
|
|
352 |
/******************************************************************************
|
|
|
353 |
* FONTIONS D'UPLOAD DE FICHIERS
|
|
|
354 |
*******************************************************************************/
|
|
|
355 |
/**
|
|
|
356 |
* Traitement des uploads
|
|
|
357 |
*/
|
|
|
358 |
function doUpload(){
|
|
|
359 |
$HasAccessWrite=$this->wiki->HasAccess("write");
|
|
|
360 |
if ($HasAccessWrite){
|
|
|
361 |
switch ($_SERVER["REQUEST_METHOD"]) {
|
|
|
362 |
case 'GET' : $this->showUploadForm(); break;
|
|
|
363 |
case 'POST': $this->performUpload(); break;
|
|
|
364 |
default : echo $this->wiki->Format("//Methode de requete invalide//---");
|
|
|
365 |
}
|
|
|
366 |
}else{
|
|
|
367 |
echo $this->wiki->Format("//Vous n'avez pas l'accès en écriture à cette page//---");
|
|
|
368 |
echo $this->wiki->Format("Retour à la page ".$this->wiki->GetPageTag());
|
|
|
369 |
}
|
|
|
370 |
}
|
|
|
371 |
/**
|
|
|
372 |
* Formulaire d'upload
|
|
|
373 |
*/
|
|
|
374 |
function showUploadForm(){
|
|
|
375 |
echo $this->wiki->Format("====Formulaire d'envois de fichier====\n---");
|
|
|
376 |
$this->file = $_GET['file'];
|
|
|
377 |
echo $this->wiki->Format("**Envois du fichier $this->file :**\n")
|
|
|
378 |
."<form enctype=\"multipart/form-data\" name=\"frmUpload\" method=\"POST\" action=\"".$_SERVER["PHP_SELF"]."\">\n"
|
|
|
379 |
." <input type=\"hidden\" name=\"wiki\" value=\"".$this->wiki->GetPageTag()."/upload\" />\n"
|
|
|
380 |
." <input TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"".$this->attachConfig['max_file_size']."\" />\n"
|
|
|
381 |
." <input type=\"hidden\" name=\"file\" value=\"$this->file\" />\n"
|
|
|
382 |
." <input type=\"file\" name=\"upFile\" size=\"50\" /><br />\n"
|
|
|
383 |
." <input type=\"submit\" value=\"Envoyer\" />\n"
|
|
|
384 |
."</form>\n";
|
|
|
385 |
}
|
|
|
386 |
/**
|
|
|
387 |
* Execute l'upload
|
|
|
388 |
*/
|
|
|
389 |
function performUpload(){
|
|
|
390 |
$this->file = $_POST['file'];
|
|
|
391 |
|
|
|
392 |
$destFile = $this->GetFullFilename(true); //nom du fichier destination
|
|
|
393 |
//test de la taille du fichier recu
|
|
|
394 |
if($_FILES['upFile']['error']==0){
|
|
|
395 |
$size = filesize($_FILES['upFile']['tmp_name']);
|
|
|
396 |
if ($size > $this->attachConfig['max_file_size']){
|
|
|
397 |
$_FILES['upFile']['error']=2;
|
|
|
398 |
}
|
|
|
399 |
}
|
|
|
400 |
switch ($_FILES['upFile']['error']){
|
|
|
401 |
case 0:
|
|
|
402 |
$srcFile = $_FILES['upFile']['tmp_name'];
|
|
|
403 |
if (move_uploaded_file($srcFile,$destFile)){
|
|
|
404 |
chmod($destFile,0644);
|
|
|
405 |
header("Location: ".$this->wiki->href("",$this->wiki->GetPageTag(),""));
|
|
|
406 |
}else{
|
|
|
407 |
echo $this->wiki->Format("//Erreur lors du déplacement du fichier temporaire//---");
|
|
|
408 |
}
|
|
|
409 |
break;
|
|
|
410 |
case 1:
|
|
|
411 |
echo $this->wiki->Format("//Le fichier téléchargé excède la taille de upload_max_filesize, configuré dans le php.ini.//---");
|
|
|
412 |
break;
|
|
|
413 |
case 2:
|
|
|
414 |
echo $this->wiki->Format("//Le fichier téléchargé excède la taille de MAX_FILE_SIZE, qui a été spécifiée dans le formulaire HTML.//---");
|
|
|
415 |
break;
|
|
|
416 |
case 3:
|
|
|
417 |
echo $this->wiki->Format("//Le fichier n'a été que partiellement téléchargé.//---");
|
|
|
418 |
break;
|
|
|
419 |
case 4:
|
|
|
420 |
echo $this->wiki->Format("//Aucun fichier n'a été téléchargé.//---");
|
|
|
421 |
break;
|
|
|
422 |
}
|
|
|
423 |
echo $this->wiki->Format("Retour à la page ".$this->wiki->GetPageTag());
|
|
|
424 |
}
|
|
|
425 |
/******************************************************************************
|
|
|
426 |
* FUNCTIONS DE DOWNLOAD DE FICHIERS
|
|
|
427 |
*******************************************************************************/
|
|
|
428 |
function doDownload(){
|
|
|
429 |
$this->file = $_GET['file'];
|
|
|
430 |
$fullFilename = $this->GetUploadPath().'/'.$this->file;
|
|
|
431 |
if(!file_exists($fullFilename)){
|
|
|
432 |
$fullFilename = $this->GetFullFilename();
|
|
|
433 |
$dlFilename = $this->file;
|
|
|
434 |
$size = filesize($fullFilename);
|
|
|
435 |
}else{
|
|
|
436 |
$file = $this->decodeLongFilename($fullFilename);
|
|
|
437 |
$size = $file['size'];
|
|
|
438 |
$dlFilename =$file['name'].'.'.$file['ext'];
|
|
|
439 |
}
|
|
|
440 |
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
|
441 |
header("Content-type: application/force-download");
|
|
|
442 |
header('Pragma: public');
|
|
|
443 |
header("Pragma: no-cache");// HTTP/1.0
|
|
|
444 |
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
|
|
|
445 |
header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
|
|
|
446 |
header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
|
|
|
447 |
header('Content-Transfer-Encoding: none');
|
|
|
448 |
header('Content-Type: application/octet-stream; name="' . $dlFilename . '"'); //This should work for the rest
|
|
|
449 |
header('Content-Type: application/octetstream; name="' . $dlFilename . '"'); //This should work for IE & Opera
|
|
|
450 |
header('Content-Type: application/download; name="' . $dlFilename . '"'); //This should work for IE & Opera
|
|
|
451 |
header('Content-Disposition: attachment; filename="'.$dlFilename.'"');
|
|
|
452 |
header("Content-Description: File Transfer");
|
|
|
453 |
header("Content-length: $size".'bytes');
|
|
|
454 |
readfile($fullFilename);
|
|
|
455 |
}
|
|
|
456 |
/******************************************************************************
|
|
|
457 |
* FONTIONS DU FILEMANAGER
|
|
|
458 |
*******************************************************************************/
|
|
|
459 |
function doFileManager(){
|
|
|
460 |
$do = $_GET['do']?$_GET['do']:'';
|
|
|
461 |
switch ($do){
|
|
|
462 |
case 'restore' :
|
|
|
463 |
$this->fmRestore();
|
|
|
464 |
$this->fmShow(true);
|
|
|
465 |
break;
|
|
|
466 |
case 'erase' :
|
|
|
467 |
$this->fmErase();
|
|
|
468 |
$this->fmShow(true);
|
|
|
469 |
break;
|
|
|
470 |
case 'del' :
|
|
|
471 |
$this->fmDelete();
|
|
|
472 |
$this->fmShow();
|
|
|
473 |
break;
|
|
|
474 |
case 'trash' :
|
|
|
475 |
$this->fmShow(true); break;
|
|
|
476 |
case 'emptytrash' :
|
|
|
477 |
$this->fmEmptyTrash(); //pas de break car apres un emptytrash => retour au gestionnaire
|
|
|
478 |
default :
|
|
|
479 |
$this->fmShow();
|
|
|
480 |
}
|
|
|
481 |
}
|
|
|
482 |
/**
|
|
|
483 |
* Affiche la liste des fichiers
|
|
|
484 |
*/
|
|
|
485 |
function fmShow($trash=false){
|
|
|
486 |
$fmTitlePage = $this->wiki->Format("====Gestion des fichiers attachés à la page ".$this->wiki->tag."====\n---");
|
|
|
487 |
if($trash){
|
|
|
488 |
//Avertissement
|
|
|
489 |
$fmTitlePage .= '<div class="prev_alert">Les fichiers effacés sur cette page le sont définitivement</div>';
|
|
|
490 |
//Pied du tableau
|
|
|
491 |
$url = $this->wiki->Link($this->wiki->tag,'filemanager','Gestion des fichiers');
|
|
|
492 |
$fmFootTable = ' <tfoot>'."\n".
|
|
|
493 |
' <tr>'."\n".
|
|
|
494 |
' <td colspan="6">'.$url.'</td>'."\n";
|
|
|
495 |
$url = $this->wiki->Link($this->wiki->tag,'filemanager&do=emptytrash','Vider la poubelle');
|
|
|
496 |
$fmFootTable.= ' <td>'.$url.'</td>'."\n".
|
|
|
497 |
' </tr>'."\n".
|
|
|
498 |
' </tfoot>'."\n";
|
|
|
499 |
}else{
|
|
|
500 |
//pied du tableau
|
|
|
501 |
$url = '<a href="'.$this->wiki->href('filemanager',$this->wiki->GetPageTag(),'do=trash').'" title="Poubelle">'.$this->attachConfig['fmTrash_symbole']."</a>";
|
|
|
502 |
$fmFootTable = ' <tfoot>'."\n".
|
|
|
503 |
' <tr>'."\n".
|
|
|
504 |
' <td colspan="6">'.$url.'</td>'."\n".
|
|
|
505 |
' </tr>'."\n".
|
|
|
506 |
' </tfoot>'."\n";
|
|
|
507 |
}
|
|
|
508 |
//entete du tableau
|
|
|
509 |
$fmHeadTable = ' <thead>'."\n".
|
|
|
510 |
' <tr>'."\n".
|
|
|
511 |
' <td> </td>'."\n".
|
|
|
512 |
' <td>Nom du fichier</td>'."\n".
|
|
|
513 |
' <td>Nom réel du fichier</td>'."\n".
|
|
|
514 |
' <td>Taille</td>'."\n".
|
|
|
515 |
' <td>Révision de la page</td>'."\n".
|
|
|
516 |
' <td>Révison du fichier</td>'."\n";
|
|
|
517 |
if($trash){
|
|
|
518 |
$fmHeadTable.= ' <td>Suppression</td>'."\n";
|
|
|
519 |
}
|
|
|
520 |
$fmHeadTable.= ' </tr>'."\n".
|
|
|
521 |
' </thead>'."\n";
|
|
|
522 |
//corps du tableau
|
|
|
523 |
$files = $this->fmGetFiles($trash);
|
|
|
524 |
$files = $this->sortByNameRevFile($files);
|
|
|
525 |
|
|
|
526 |
$fmBodyTable = ' <tbody>'."\n";
|
|
|
527 |
$i = 0;
|
|
|
528 |
foreach ($files as $file){
|
|
|
529 |
$i++;
|
|
|
530 |
$color= ($i%2?"tableFMCol1":"tableFMCol2");
|
|
|
531 |
//lien de suppression
|
|
|
532 |
if ($trash){
|
|
|
533 |
$url = $this->wiki->href('filemanager',$this->wiki->GetPageTag(),'do=erase&file='.$file['realname']);
|
|
|
534 |
}else{
|
|
|
535 |
$url = $this->wiki->href('filemanager',$this->wiki->GetPageTag(),'do=del&file='.$file['realname']);
|
|
|
536 |
}
|
|
|
537 |
$dellink = '<a href="'.$url.'" title="Supprimer">'.$this->attachConfig['fmDelete_symbole']."</a>";
|
|
|
538 |
//lien de restauration
|
|
|
539 |
$restlink = '';
|
|
|
540 |
if ($trash){
|
|
|
541 |
$url = $this->wiki->href('filemanager',$this->wiki->GetPageTag(),'do=restore&file='.$file['realname']);
|
|
|
542 |
$restlink = '<a href="'.$url.'" title="Restaurer">'.$this->attachConfig['fmRestore_symbole']."</a>";
|
|
|
543 |
}
|
|
|
544 |
|
|
|
545 |
//lien pour downloader le fichier
|
|
|
546 |
$url = $this->wiki->href("download",$this->wiki->GetPageTag(),"file=".$file['realname']);
|
|
|
547 |
$dlLink = '<a href="'.$url.'">'.$file['name'].'.'.$file['ext']."</a>";
|
|
|
548 |
$fmBodyTable .= ' <tr class="'.$color.'">'."\n".
|
|
|
549 |
' <td>'.$dellink.' '.$restlink.'</td>'."\n".
|
|
|
550 |
' <td>'.$dlLink.'</td>'."\n".
|
|
|
551 |
' <td>'.$file['realname'].'</td>'."\n".
|
|
|
552 |
' <td>'.$file['size'].'</td>'."\n".
|
|
|
553 |
' <td>'.$this->parseDate($file['datepage']).'</td>'."\n".
|
|
|
554 |
' <td>'.$this->parseDate($file['dateupload']).'</td>'."\n";
|
|
|
555 |
if($trash){
|
|
|
556 |
$fmBodyTable.= ' <td>'.$this->parseDate($file['trashdate']).'</td>'."\n";
|
|
|
557 |
}
|
|
|
558 |
$fmBodyTable .= ' </tr>'."\n";
|
|
|
559 |
}
|
|
|
560 |
$fmBodyTable .= ' </tbody>'."\n";
|
|
|
561 |
//pied de la page
|
|
|
562 |
$fmFooterPage = "---\n-----\n[[".$this->wiki->tag." Retour à la page ".$this->wiki->tag."]]\n";
|
|
|
563 |
//affichage
|
|
|
564 |
echo $fmTitlePage."\n";
|
|
|
565 |
echo '<table class="tableFM" border="0" cellspacing="0">'."\n".$fmHeadTable.$fmFootTable.$fmBodyTable.'</table>'."\n";
|
|
|
566 |
echo $this->wiki->Format($fmFooterPage);
|
|
|
567 |
}
|
|
|
568 |
/**
|
|
|
569 |
* Renvoie la liste des fichiers
|
|
|
570 |
*/
|
|
|
571 |
function fmGetFiles($trash=false){
|
|
|
572 |
$path = $this->GetUploadPath();
|
|
|
573 |
if($this->isSafeMode){
|
|
|
574 |
$filePattern = '^'.$this->wiki->GetPageTag().'_.*_\d{14}_\d{14}\..*';
|
|
|
575 |
}else{
|
|
|
576 |
$filePattern = '^.*_\d{14}_\d{14}\..*';
|
|
|
577 |
}
|
|
|
578 |
if($trash){
|
|
|
579 |
$filePattern .= 'trash\d{14}';
|
|
|
580 |
}else{
|
|
|
581 |
$filePattern .= '[^(trash\d{14})]';
|
|
|
582 |
}
|
|
|
583 |
return $this->searchFiles('`'.$filePattern.'$`', $path);
|
|
|
584 |
}
|
|
|
585 |
/**
|
|
|
586 |
* Vide la poubelle
|
|
|
587 |
*/
|
|
|
588 |
function fmEmptyTrash(){
|
|
|
589 |
$files = $this->fmGetFiles(true);
|
|
|
590 |
foreach ($files as $file){
|
|
|
591 |
$filename = $file['path'].'/'.$file['realname'];
|
|
|
592 |
if(file_exists($filename)){
|
|
|
593 |
unlink($filename);
|
|
|
594 |
}
|
|
|
595 |
}
|
|
|
596 |
}
|
|
|
597 |
/**
|
|
|
598 |
* Effacement d'un fichier dans la poubelle
|
|
|
599 |
*/
|
|
|
600 |
function fmErase(){
|
|
|
601 |
$path = $this->GetUploadPath();
|
|
|
602 |
$filename = $path.'/'.($_GET['file']?$_GET['file']:'');
|
|
|
603 |
if (file_exists($filename)){
|
|
|
604 |
unlink($filename);
|
|
|
605 |
}
|
|
|
606 |
}
|
|
|
607 |
/**
|
|
|
608 |
* Met le fichier a la poubelle
|
|
|
609 |
*/
|
|
|
610 |
function fmDelete(){
|
|
|
611 |
$path = $this->GetUploadPath();
|
|
|
612 |
$filename = $path.'/'.($_GET['file']?$_GET['file']:'');
|
|
|
613 |
if (file_exists($filename)){
|
|
|
614 |
$trash = $filename.'trash'.$this->getDate();
|
|
|
615 |
rename($filename, $trash);
|
|
|
616 |
}
|
|
|
617 |
}
|
|
|
618 |
/**
|
|
|
619 |
* Restauration d'un fichier mis a la poubelle
|
|
|
620 |
*/
|
|
|
621 |
function fmRestore(){
|
|
|
622 |
$path = $this->GetUploadPath();
|
|
|
623 |
$filename = $path.'/'.($_GET['file']?$_GET['file']:'');
|
|
|
624 |
if (file_exists($filename)){
|
|
|
625 |
$restFile = preg_replace('`^(.*\..*)trash\d{14}$`', '$1', $filename);
|
|
|
626 |
rename($filename, $restFile);
|
|
|
627 |
}
|
|
|
628 |
}
|
|
|
629 |
/**
|
|
|
630 |
* Tri tu tableau liste des fichiers par nom puis par date de revision(upload) du fichier, ordre croissant
|
|
|
631 |
*/
|
|
|
632 |
function sortByNameRevFile($files){
|
|
|
633 |
if (!function_exists('ByNameByRevFile')){
|
|
|
634 |
function ByNameByRevFile($f1,$f2){
|
|
|
635 |
$f1Name = $f1['name'].'.'.$f1['ext'];
|
|
|
636 |
$f2Name = $f2['name'].'.'.$f2['ext'];
|
|
|
637 |
$res = strcasecmp($f1Name, $f2Name);
|
|
|
638 |
if($res==0){
|
|
|
639 |
//si meme nom => compare la revision du fichier
|
|
|
640 |
$res = strcasecmp($f1['dateupload'], $f2['dateupload']);
|
|
|
641 |
}
|
|
|
642 |
return $res;
|
|
|
643 |
}
|
|
|
644 |
}
|
|
|
645 |
usort($files,'ByNameByRevFile');
|
|
|
646 |
return $files;
|
|
|
647 |
}
|
|
|
648 |
}
|
|
|
649 |
?>
|