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 = '',  $opts = array())
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                    
39                     //}
40                 }
41                 if ($mt == 'application/xml') {
42                      //dl('tidy');
43                         
44                 //if (class_exists('Tidy')) {
45                     $tidy = new Tidy();
46                     
47                     
48                     $tidy->parseString($fc, array('indent'=>true,'output-xml' => true,'input-xml' => true), 'utf8');
49                    // $tidy->cleanRepair();
50                     $fc = (string)$tidy;
51                     
52                 }    
53                 echo '<PRE>'. htmlspecialchars($fc) . '</PRE>';
54                 exit;
55                 
56             case 'image/jpeg':
57                 echo '<img src="'. $this->baseURL.'/Ftp/View/'.$v . '">';
58                 exit;
59             
60             
61             default:
62                 // handle download.
63                 require_once 'File/Convert.php';
64                 $f = new File_Convert($fp, $mt);
65                 $f->convert("application/pdf"); // does no conversion (as it's the same.
66
67                 $f->serve('attachment');
68                 
69             
70             
71             
72                 die("Can not handle " . $mt . " yet");
73         }
74         
75         
76         
77         var_dump($fp);
78         
79         die("done");
80         exit;
81     }
82     
83     
84     
85     
86 }