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
30 function get($pi = '')
32 if (!isset($_REQUEST['ajax_body'])) {
35 $this->masterTemplate = 'file.html';
37 $this->pi = $pi . (strlen($pi) ? $this->bootLoader->ext : '');
42 $this->repo = DB_DataObject::factory('mtrack_repos');
43 $this->filename = $this->repo->loadFromPath($this->pi);
44 if (!$this->repo->id) {
45 throw new Exception("invalid path {$this->pi}");
48 if (!$this->projectPerm($this->repo->project_id, 'MTrack.Repos', 'S')) {
49 return HTML_FlexyFramework::run('Noperm'); // noperm = loggedin -> need more perms / not.. try loggin in..
53 if (empty($this->filename) || !$this->repo->id) {
54 throw new Exception("invalid path " . htmlspecialchars($this->pi) );
58 throw new Exception("invalid path {$this->pi}");
61 $this->file = isset($_GET['rev']) ?
62 $this->repo->file($this->filename, 'rev', $_GET['rev']) :
63 $this->repo->file($this->filename);
65 //echo '<PRE>'; print_r($this->file); exit;
67 $this->ent = $this->file->getChangeEvent();
70 if (!empty($_GET['raw'])) {
71 //should it add an image header..
72 require_once 'File/MimeType.php';
73 $y = new File_MimeType();
74 $this->mimetype = $y->fromFilename($this->file->name);
76 $filename = basename($this->filename);
77 header("Content-Type: {$this->mimetype}; name=\"{$filename}\"");
78 if ($_GET['raw'] == 'download') {
79 header("Content-Disposition: attachment; filename=\"{$filename}\"");
82 fpassthru($this->file->cat());
86 $this->jump = empty($_GET['jump']) ? '' : $_GET['jump'];
91 $this->crumbs = array();
92 $this->basename = basename($this->filename);
94 $crumbs = dirname($this->filename) == '.' ? array() : explode('/', dirname($this->filename));
99 foreach($crumbs as $path)
101 if (count($this->crumbs) && !strlen($path)) {
106 $location .= strlen($location) ? '/' : '';
107 $location .= strlen($path) ? urlencode($path) : '';
108 $c->location = $location;
109 $this->crumbs[] = $c;
113 $finfo = pathinfo($this->file->name);
116 $data = $this->file->cat();
117 // echo '<PRE>'. htmlspecialchars(stream_get_contents($data));exit;
119 stream_copy_to_stream($data, $t);
122 // we have copied the data to a file.. $t...
125 $location = stream_get_meta_data($t);
127 $location = $location['uri'];
128 //print_r($location);
130 require_once 'File/MimeType.php';
131 $y = new File_MimeType();
132 $this->mimetype = $y->fromFilename($this->file->name);
135 //$this->mimetype = mtrack_mime_detect($location, $this->file->name);
138 list($major) = explode('/', $this->mimetype, 2);
140 // Obscure-ish special cases for mime types;
141 // some .y files look like old image format data
142 switch ($this->mimetype) {
144 case 'application/xml':
145 case 'application/javascript':
146 case 'application/x-httpd-php':
151 // some special cases:
152 // we would be better to do if octect/stream to use the file tool.
154 switch(basename($this->file->name)) {
164 // simple cases first..
167 $this->majorImage = true;
173 // this should be a json query..
174 //$this->ann = array_values($this->file->annotate());
175 // echo '<PRE>';print_R($this->ann);exit;
176 if (!empty($_REQUEST['annotate'])) {
178 $ann = array_values($this->file->annotate());
182 $this->ann = array();
183 if ($this->ann === 'DELETED') {
184 $this->deleted = true;
191 require_once 'MTrack/SyntaxHighlight.php';
192 $contents = stream_get_contents($this->tmpfile);
193 $this->nlines = count(explode("\n", $contents));
194 $this->data = MTrack_SyntaxHighlight::highlightSource(
195 $contents , null, $this->file->name
197 //var_dump($this->data);
198 for ($i =0; $i < $this->nlines; $i++ ) {
199 $this->ann[] = (object) array(
209 break; // download only..
214 //$this->renderEvents();
217 function schemeSelect() // FIXME... we should use JS highligher.. not PHP one...
222 require_once 'MTrack/SyntaxHighlight.php';
223 return MTrack_SyntaxHighlight::getSchemeSelect();