1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
5 // Browse.php - only for rendering the body..
6 // Tree.php - the actually tree..
8 require_once 'MTrackWeb.php';
10 class MTrackWeb_File extends MTrackWeb
13 var $template = 'file.html';
23 require_once 'MTrack/ACL.php';
24 MTrackACL::requireAllRights('Browser', 'read');
32 function get($pi = '')
35 if (!empty($_REQUEST['embed'])) {
36 $this->masterTemplate = $this->template;
39 $this->pi = $pi . $this->bootLoader->ext;
42 $data = explode('@', $this->pi);
44 if (isset($data[1])) {
45 // do not do this ... ;)
46 $_GET['rev'] = $data[1];
50 $this->repo = DB_DataObject::factory('repos');
51 $file = $this->repo->loadFromPath($this->pi);
53 if (empty($file) || $this->repo->id) {
54 throw new Exception("invalid path " . htmlspecialchars($this->pi) );
58 throw new Exception("invalid path {$this->pi}");
61 MTrackACL::requireAllRights("repo:{$this->repo->repoid}", 'read');
63 $this->file = isset($_GET['rev']) ?
64 $this->repo->file($file, 'rev', $_GET['rev']) :
65 $this->repo->file($$file);
67 //echo '<PRE>'; print_r($this->file); exit;
69 $this->ent = $this->file->getChangeEvent();
72 if (!empty($_GET['raw'])) {
73 //should it add an image header..
74 require_once 'File/MimeType.php';
75 $y = new File_MimeType();
76 $this->mimetype = $y->fromFilename($this->file->name);
78 $filename = basename($this->pi);
79 header("Content-Type: {$this->mimetype}; name=\"{$filename}\"");
80 if ($_GET['raw'] == 'download') {
81 header("Content-Disposition: attachment; filename=\"{$filename}\"");
84 fpassthru($this->file->cat());
88 $this->jump = empty($_GET['jump']) ? '' : $_GET['jump'];
93 $this->crumbs = array();
94 $this->basename = array_pop($crumbs);
96 array_unshift($crumbs, '');
97 foreach($crumbs as $path)
99 if (count($this->crumbs) && !strlen($path)) {
103 $c->name = strlen($path) ? $path : '[root]';
104 $location .= strlen($location) ? '/' : '';
105 $location .= strlen($path) ? urlencode($path) : '';
106 $c->location = $location;
107 $this->crumbs[] = $c;
112 $finfo = pathinfo($this->file->name);
115 $data = $this->file->cat();
116 // echo '<PRE>'. htmlspecialchars(stream_get_contents($data));exit;
118 stream_copy_to_stream($data, $t);
121 // we have copied the data to a file.. $t...
124 $location = stream_get_meta_data($t);
126 $location = $location['uri'];
127 //print_r($location);
129 require_once 'File/MimeType.php';
130 $y = new File_MimeType();
131 $this->mimetype = $y->fromFilename($this->file->name);
134 //$this->mimetype = mtrack_mime_detect($location, $this->file->name);
137 list($major) = explode('/', $this->mimetype, 2);
139 // Obscure-ish special cases for mime types;
140 // some .y files look like old image format data
141 switch ($this->mimetype) {
143 case 'application/xml':
144 case 'application/javascript':
145 case 'application/x-httpd-php':
150 // some special cases:
151 // we would be better to do if octect/stream to use the file tool.
153 switch(basename($this->file->name)) {
163 // simple cases first..
166 $this->majorImage = true;
172 $this->ann = array_values($this->file->annotate());
173 // echo '<PRE>';print_R($this->ann);exit;
174 if ($this->ann === 'DELETED') {
175 $this->deleted = true;
181 $this->nlines = count($this->ann);
182 require_once 'MTrack/SyntaxHighlight.php';
183 $this->data = MTrack_SyntaxHighlight::highlightSource(
184 stream_get_contents($this->tmpfile), null, $this->file->name
186 // var_dump($this->data);
189 break; // download only..
194 //$this->renderEvents();
197 function schemeSelect() // FIXME... we should use JS highligher.. not PHP one...
202 require_once 'MTrack/SyntaxHighlight.php';
203 return MTrack_SyntaxHighlight::getSchemeSelect();