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];
51 $crumbs = MTrackSCM::makeBreadcrumbs($this->pi);
55 if (!strlen($this->pi) || $this->pi == '/') {
56 throw new Exception("invalid path /");
58 $this->repo = MTrackSCM::factory($this->pi);
61 throw new Exception("invalid path {$this->pi}");
64 MTrackACL::requireAllRights("repo:{$this->repo->repoid}", 'read');
66 $this->file = isset($_GET['rev']) ?
67 $this->repo->file($this->pi, 'rev', $_GET['rev']) :
68 $this->repo->file($this->pi);
70 //echo '<PRE>'; print_r($this->file); exit;
72 $this->ent = $this->file->getChangeEvent();
75 if (!empty($_GET['raw'])) {
76 //should it add an image header..
77 require_once 'File/MimeType.php';
78 $y = new File_MimeType();
79 $this->mimetype = $y->fromFilename($this->file->name);
81 $filename = basename($this->pi);
82 header("Content-Type: {$this->mimetype}; name=\"{$filename}\"");
83 if ($_GET['raw'] == 'download') {
84 header("Content-Disposition: attachment; filename=\"{$filename}\"");
87 fpassthru($this->file->cat());
91 $this->jump = empty($_GET['jump']) ? '' : $_GET['jump'];
96 $this->crumbs = array();
97 $this->basename = array_pop($crumbs);
99 array_unshift($crumbs, '');
100 foreach($crumbs as $path)
102 if (count($this->crumbs) && !strlen($path)) {
106 $c->name = strlen($path) ? $path : '[root]';
107 $location .= strlen($location) ? '/' : '';
108 $location .= strlen($path) ? urlencode($path) : '';
109 $c->location = $location;
110 $this->crumbs[] = $c;
115 $finfo = pathinfo($this->file->name);
118 $data = $this->file->cat();
119 // echo '<PRE>'. htmlspecialchars(stream_get_contents($data));exit;
121 stream_copy_to_stream($data, $t);
124 // we have copied the data to a file.. $t...
127 $location = stream_get_meta_data($t);
129 $location = $location['uri'];
130 //print_r($location);
132 require_once 'File/MimeType.php';
133 $y = new File_MimeType();
134 $this->mimetype = $y->fromFilename($this->file->name);
137 //$this->mimetype = mtrack_mime_detect($location, $this->file->name);
140 list($major) = explode('/', $this->mimetype, 2);
142 // Obscure-ish special cases for mime types;
143 // some .y files look like old image format data
144 switch ($this->mimetype) {
146 case 'application/xml':
147 case 'application/javascript':
148 case 'application/x-httpd-php':
153 // some special cases:
154 // we would be better to do if octect/stream to use the file tool.
156 switch(basename($this->file->name)) {
166 // simple cases first..
169 $this->majorImage = true;
175 $this->ann = array_values($this->file->annotate());
176 // echo '<PRE>';print_R($this->ann);exit;
177 if ($this->ann === 'DELETED') {
178 $this->deleted = true;
184 $this->nlines = count($this->ann);
185 require_once 'MTrack/SyntaxHighlight.php';
186 $this->data = MTrack_SyntaxHighlight::highlightSource(
187 stream_get_contents($this->tmpfile), null, $this->file->name
189 // var_dump($this->data);
192 break; // download only..
197 //$this->renderEvents();
200 function schemeSelect() // FIXME... we should use JS highligher.. not PHP one...
205 require_once 'MTrack/SyntaxHighlight.php';
206 return MTrack_SyntaxHighlight::getSchemeSelect();