php8
[web.mtrack] / MTrackWeb / File.php
index fce7fca..443f926 100644 (file)
@@ -10,8 +10,7 @@ require_once 'MTrackWeb.php';
 class MTrackWeb_File extends MTrackWeb
 {
     
-    var $template = 'file.html';
+    
     var $object;
     var $ident;
     var $filename;
@@ -20,8 +19,7 @@ class MTrackWeb_File extends MTrackWeb
     function getAuth() 
     {
         parent::getAuth();
-        require_once 'MTrack/ACL.php';
-        MTrackACL::requireAllRights('Browser', 'read');
+         
         return true;
   
     }
@@ -31,35 +29,35 @@ class MTrackWeb_File extends MTrackWeb
  
     function get($pi = '')
     {
-        
-        if (!empty($_REQUEST['embed'])) {
-            $this->masterTemplate = $this->template;
-        }
-        
-        $this->pi =  $pi . $this->bootLoader->ext;
-
-        // very svn;y...
-        $data = explode('@', $this->pi);
-        $this->pi = $data[0];
-        if (isset($data[1])) {
-            // do not do this ... ;)
-            $_GET['rev'] = $data[1];
+        if (!isset($_REQUEST['ajax_body'])) {
+            return;
         }
+        $this->masterTemplate = 'file.html';
+         
+        $this->pi =  $pi . (strlen($pi) ? $this->bootLoader->ext : '');
+    
+        //var_dump($pi);
         
          
         $this->repo = DB_DataObject::factory('mtrack_repos');
         $this->filename = $this->repo->loadFromPath($this->pi);
+        if (!$this->repo->id) {
+            throw new Exception("invalid path {$this->pi}");
+        }
+         
+        if (!$this->projectPerm($this->repo->project_id, 'MTrack.Repos', 'S')) {
+            return HTML_FlexyFramework::run('Noperm');  // noperm = loggedin -> need more perms / not.. try loggin in..
+        }
         
-        if (empty($this->filename) || !$this->repo->repoid) {
+          
+        if (empty($this->filename) || !$this->repo->id) {
             throw new Exception("invalid path " . htmlspecialchars($this->pi) );
         }
  
         if (!$this->repo) {
           throw new Exception("invalid path {$this->pi}");
         }
-        
-        MTrackACL::requireAllRights("repo:{$this->repo->repoid}", 'read');
-
+         
         $this->file =  isset($_GET['rev']) ? 
             $this->repo->file($this->filename, 'rev', $_GET['rev']) :  
             $this->repo->file($this->filename);
@@ -93,8 +91,10 @@ class MTrackWeb_File extends MTrackWeb
         $this->crumbs = array();
         $this->basename  = basename($this->filename);
         $location = '';
-        $crumbs = explode('/', dirname($this->filename));
-        array_unshift($crumbs, ''); // add empty at front..
+        $crumbs = dirname($this->filename) == '.' ? array() :  explode('/', dirname($this->filename));
+         
+        
+        
         
         foreach($crumbs as $path) 
         {
@@ -102,14 +102,13 @@ class MTrackWeb_File extends MTrackWeb
                 continue;
             }
             $c = new StdClass;
-            $c->name = strlen($path) ? $path : '[root]';
+            $c->name =   $path  ;
             $location .=  strlen($location) ? '/' : '';
             $location .=  strlen($path)  ?  urlencode($path)  : '';
             $c->location = $location;
             $this->crumbs[] = $c;
         }
-
-        
+         
                 
         $finfo = pathinfo($this->file->name);
         $t = tmpfile();
@@ -131,13 +130,21 @@ class MTrackWeb_File extends MTrackWeb
         require_once 'File/MimeType.php';
         $y = new File_MimeType();
         $this->mimetype = $y->fromFilename($this->file->name);
-
+        $ext = strtolower(array_pop(explode('.', $this->file->name)));
         
         //$this->mimetype = mtrack_mime_detect($location, $this->file->name);
-        
+        // special cases..
         
         list($major) = explode('/', $this->mimetype, 2);
 
+        switch ($ext) {
+            case 'sql':
+                $major = 'text';
+                break;
+            
+            
+        }
+
         // Obscure-ish special cases for mime types;
         // some .y files look like old image format data
         switch ($this->mimetype) {
@@ -171,8 +178,16 @@ class MTrackWeb_File extends MTrackWeb
             case 'text':
                 fseek($t, 0);
                 
-                $this->ann = array_values($this->file->annotate());
+                // this should be a json query..
+                //$this->ann = array_values($this->file->annotate());
                // echo '<PRE>';print_R($this->ann);exit;
+                if (!empty($_REQUEST['annotate'])) {
+                    
+                    $ann = array_values($this->file->annotate());
+                    $this->jdata($ann);
+                }
+                
+                $this->ann = array();
                 if ($this->ann === 'DELETED') {
                     $this->deleted = true;
                     $this->ann = false;
@@ -180,17 +195,42 @@ class MTrackWeb_File extends MTrackWeb
                 }
                 $this->tmpfile = $t; 
                 
-                $this->nlines = count($this->ann);
+               
                 require_once 'MTrack/SyntaxHighlight.php';
-                $this->data =  MTrack_SyntaxHighlight::highlightSource(
-                        stream_get_contents($this->tmpfile), null, $this->file->name
+                $contents = stream_get_contents($this->tmpfile);
+                $this->nlines = count(explode("\n", $contents));
+                
+                if (!empty($_REQUEST['markup'])) {
+                    // we do a late version call for markup.. 
+                    echo MTrack_SyntaxHighlight::highlightSource(
+                        $contents , null, $this->file->name
+                    );
+                    exit;
+                                       
+                }
+                
+                
+                $this->data =  htmlspecialchars($contents); /* MTrack_SyntaxHighlight::highlightSource(
+                        $contents , null, $this->file->name
+                   );
+                                          */
+                    //var_dump($this->data);
+                for ($i =0; $i < $this->nlines; $i++ ) {
+                    $this->ann[] = (object) array(
+                        'rev' => '',
+                        'lineno' => ($i + 1)
                     );
-                   // var_dump($this->data);
+                }
+                
+                   
+
     
             default:
                 break; // download only..
         }
-      
+        if (!empty($_REQUEST['markup'])) {
+           $this->jerr("invalid request");
+        }
        
       // 
         //$this->renderEvents();