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->repoid) {
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($file);
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 = basename($file);
96 $crumbs = explode('/', dirname($file));
97 array_unshift($crumbs, ''); // add empty at front..
99 foreach($crumbs as $path)
101 if (count($this->crumbs) && !strlen($path)) {
105 $c->name = strlen($path) ? $path : '[root]';
106 $location .= strlen($location) ? '/' : '';
107 $location .= strlen($path) ? urlencode($path) : '';
108 $c->location = $location;
109 $this->crumbs[] = $c;
114 $finfo = pathinfo($this->file->name);
117 $data = $this->file->cat();
118 // echo '<PRE>'. htmlspecialchars(stream_get_contents($data));exit;
120 stream_copy_to_stream($data, $t);
123 // we have copied the data to a file.. $t...
126 $location = stream_get_meta_data($t);
128 $location = $location['uri'];
129 //print_r($location);
131 require_once 'File/MimeType.php';
132 $y = new File_MimeType();
133 $this->mimetype = $y->fromFilename($this->file->name);
136 //$this->mimetype = mtrack_mime_detect($location, $this->file->name);
139 list($major) = explode('/', $this->mimetype, 2);
141 // Obscure-ish special cases for mime types;
142 // some .y files look like old image format data
143 switch ($this->mimetype) {
145 case 'application/xml':
146 case 'application/javascript':
147 case 'application/x-httpd-php':
152 // some special cases:
153 // we would be better to do if octect/stream to use the file tool.
155 switch(basename($this->file->name)) {
165 // simple cases first..
168 $this->majorImage = true;
174 $this->ann = array_values($this->file->annotate());
175 // echo '<PRE>';print_R($this->ann);exit;
176 if ($this->ann === 'DELETED') {
177 $this->deleted = true;
183 $this->nlines = count($this->ann);
184 require_once 'MTrack/SyntaxHighlight.php';
185 $this->data = MTrack_SyntaxHighlight::highlightSource(
186 stream_get_contents($this->tmpfile), null, $this->file->name
188 // var_dump($this->data);
191 break; // download only..
196 //$this->renderEvents();
199 function schemeSelect() // FIXME... we should use JS highligher.. not PHP one...
204 require_once 'MTrack/SyntaxHighlight.php';
205 return MTrack_SyntaxHighlight::getSchemeSelect();