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];
48 $this->repo = DB_DataObject::factory('repos');
49 $this->repo->loadFromPath($this->pi);
53 $crumbs = MTrackSCM::makeBreadcrumbs($this->pi);
57 if (!strlen($this->pi) || $this->pi == '/') {
58 throw new Exception("invalid path /");
60 $this->repo = DB_DataObject::factory('repos');
61 $this->repo->parent = $crumbs[1] == 'default' ? '' : 'user:' . $crumbs[0];
62 $this->repo->get('shortname', $crumbs[2]);
64 $dir_pi = implode('/', array_slice($crumbs,3));
68 throw new Exception("invalid path {$this->pi}");
71 MTrackACL::requireAllRights("repo:{$this->repo->repoid}", 'read');
73 $this->file = isset($_GET['rev']) ?
74 $this->repo->file($this->pi, 'rev', $_GET['rev']) :
75 $this->repo->file($this->pi);
77 //echo '<PRE>'; print_r($this->file); exit;
79 $this->ent = $this->file->getChangeEvent();
82 if (!empty($_GET['raw'])) {
83 //should it add an image header..
84 require_once 'File/MimeType.php';
85 $y = new File_MimeType();
86 $this->mimetype = $y->fromFilename($this->file->name);
88 $filename = basename($this->pi);
89 header("Content-Type: {$this->mimetype}; name=\"{$filename}\"");
90 if ($_GET['raw'] == 'download') {
91 header("Content-Disposition: attachment; filename=\"{$filename}\"");
94 fpassthru($this->file->cat());
98 $this->jump = empty($_GET['jump']) ? '' : $_GET['jump'];
103 $this->crumbs = array();
104 $this->basename = array_pop($crumbs);
106 array_unshift($crumbs, '');
107 foreach($crumbs as $path)
109 if (count($this->crumbs) && !strlen($path)) {
113 $c->name = strlen($path) ? $path : '[root]';
114 $location .= strlen($location) ? '/' : '';
115 $location .= strlen($path) ? urlencode($path) : '';
116 $c->location = $location;
117 $this->crumbs[] = $c;
122 $finfo = pathinfo($this->file->name);
125 $data = $this->file->cat();
126 // echo '<PRE>'. htmlspecialchars(stream_get_contents($data));exit;
128 stream_copy_to_stream($data, $t);
131 // we have copied the data to a file.. $t...
134 $location = stream_get_meta_data($t);
136 $location = $location['uri'];
137 //print_r($location);
139 require_once 'File/MimeType.php';
140 $y = new File_MimeType();
141 $this->mimetype = $y->fromFilename($this->file->name);
144 //$this->mimetype = mtrack_mime_detect($location, $this->file->name);
147 list($major) = explode('/', $this->mimetype, 2);
149 // Obscure-ish special cases for mime types;
150 // some .y files look like old image format data
151 switch ($this->mimetype) {
153 case 'application/xml':
154 case 'application/javascript':
155 case 'application/x-httpd-php':
160 // some special cases:
161 // we would be better to do if octect/stream to use the file tool.
163 switch(basename($this->file->name)) {
173 // simple cases first..
176 $this->majorImage = true;
182 $this->ann = array_values($this->file->annotate());
183 // echo '<PRE>';print_R($this->ann);exit;
184 if ($this->ann === 'DELETED') {
185 $this->deleted = true;
191 $this->nlines = count($this->ann);
192 require_once 'MTrack/SyntaxHighlight.php';
193 $this->data = MTrack_SyntaxHighlight::highlightSource(
194 stream_get_contents($this->tmpfile), null, $this->file->name
196 // var_dump($this->data);
199 break; // download only..
204 //$this->renderEvents();
207 function schemeSelect() // FIXME... we should use JS highligher.. not PHP one...
212 require_once 'MTrack/SyntaxHighlight.php';
213 return MTrack_SyntaxHighlight::getSchemeSelect();