View.php
[Pman.Ftp] / View.php
1 <?php
2
3 require_once 'Pman/Ftp/List.php';
4
5 class Pman_Ftp_View extends Pman_Ftp_List
6 {
7     //getAuth = covered by list
8     
9     function get($v)
10     {
11         
12         $ext = pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION);
13         $v .= '.'. $ext;
14         
15         $v = urldecode($v);
16         $fp = $this->clean($v);
17         
18         require_once 'File/MimeType.php';
19         $fm = new File_MimeType();
20         $mt = $fm->fromExt($ext);
21         
22         if (!isset($_REQUEST['html'])) {
23             header("Content-type: $mt");
24             $fh = fopen($fp,'r');
25             fpassthru($fh);
26             fclose($fh);
27             exit;
28         }
29         
30         
31         switch($mt) {
32             case 'text/plain':
33             case 'application/xml':
34                 $fc = file_get_contents($fp);
35                 $matches = array();
36                 if (preg_match('#^\s*<\?xml.*encoding="([^"]+)"#mi', $fc, $matches)) {
37                     $fc = iconv($matches[1], "UTF8//IGNORE", $fc);
38                     @dl('tidy');
39                     //if (class_exists('Tidy')) {
40                         $tidy = new Tidy();
41                         $tidy->parseString($fc, array('indent'=>true), 'utf8');
42                         $tidy->cleanRepair();
43                         $fc = $tidy->toString();
44                     //}
45                 }
46
47             
48             
49                 echo '<PRE>'. htmlspecialchars($fc) . '</PRE>';
50                 exit;
51                 
52             case 'image/jpeg':
53                 echo '<img src="'. $this->baseURL.'/Ftp/View/'.$v . '">';
54                 exit;
55             
56             
57             default:
58                 // handle download.
59                 require_once 'File/Convert.php';
60                 $f = new File_Convert($fp, $mt);
61                 $f->convert("application/pdf"); // does no conversion (as it's the same.
62
63                 $f->serve('attachment');
64                 
65             
66             
67             
68                 die("Can not handle " . $mt . " yet");
69         }
70         
71         
72         
73         var_dump($fp);
74         
75         die("done");
76         exit;
77     }
78     
79     
80     
81     
82 }