added get_filetype method to Tools.class.php
[phpgitweb.git] / htdocs / lib / Tools.class.php
index 8ae07171cbdfaa089203f111a6c75dd3925dc0b5..6f28961d8d1612e9c11df2c074e386807b07283d 100644 (file)
  */
 
 class Tools {
+       const S_IFMT      = 170000;
+       const S_IFGITLINK = 160000;
+       const S_IFLNK     = 120000;
+       const S_IFREG     = 100000;
+       const S_IFDIR     =  40000;
+       const S_IFINVALID =  30000;
+       const S_IXUSR     =    100;
+       
+       public static function get_filetype($mode, $exec = false) {
+               if(!preg_match('/^[0-7]+$/', $mode))
+                       return $mode;
+               
+               if(($mode & self::S_IFMT) == S_IFGITLINK)
+                       return 'submodule';
+               else if(($mode & self::S_IFMT) == S_IFDIR)
+                       return 'directory';
+               else if(($mode & self::S_IFMT) == S_IFLNK)
+                       return 'symlink';
+               else if(($mode & self::S_IFMT) == S_IFREG) {
+                       if($exec && ($mode & self::S_IXUSR))
+                               return 'executable';
+                       return 'file';
+               } else
+                       return 'unknown';
+       }
        
        public static function age_calculate($last_change) {
                $result = array();
@@ -26,6 +51,7 @@ class Tools {
                if ($age > 60*60*24*365*2) {
                        $age_str = floor($age/60/60/24/365);
                        $age_str .= " years ago";
+                       $max_cache = (60*60*24*365) - ($age % (60*60*24*365));
                } else if ($age > 60*60*24*(365/12)*2) {
                        $age_str = floor($age/60/60/24/(365/12));
                        $age_str .= " months ago";
@@ -82,6 +108,13 @@ class Tools {
                return $ctext;
        }
        
+       public static function parseTimeZone($timezone) {
+               if(!preg_match("/^([+-])([0-9]{2})([0-9]{2})$/i", $timezone, $treffer))
+                       return 0;
+               $offset = ($treffer[1] == '-' ? -1 : 1) * (($treffer[2] * 3600) + ($treffer[3] * 60));
+               return $offset;
+       }
+       
 }
 
 ?>
\ No newline at end of file