Ticket #591: diff.patch

File diff.patch, 2.9 kB (added by brettalton, 8 months ago)
  • system/config/mimes.php

    diff -ur trunk-old/system/config/mimes.php trunk/system/config/mimes.php
    old new  
    143143        'pl'    => array('text/x-perl'), 
    144144        'pm'    => array('text/x-perl'), 
    145145        'png'   => array('image/png', 'image/x-png'), 
     146        'po'    => array('text/x-gettext-translation'), 
    146147        'pot'   => array('application/vnd.ms-powerpoint'), 
    147148        'pps'   => array('application/vnd.ms-powerpoint'), 
    148149        'ppt'   => array('application/powerpoint'), 
  • system/helpers/file.php

    diff -ur trunk-old/system/helpers/file.php trunk/system/helpers/file.php
    old new  
    174174                return ($piece - 1); 
    175175        } 
    176176 
    177 } // End file 
    178  No newline at end of file 
     177        /** 
     178         * Return file size using metric prefixes (SI), allow rounding 
     179         * 
     180         * @param   string   path to file 
     181         * @param   integer  integer to round to 
     182         * @return  string   file size with metric prefix 
     183         */ 
     184        public static function size($filename, $round = FALSE) 
     185        { 
     186                // Check that file exists 
     187                if ( ! file_exists($filename) OR ! is_file($filename) OR ! is_readable($filename)) 
     188                        return FALSE; 
     189 
     190                // Find filesize in bytes 
     191                $file_size = sprintf("%u", filesize($filename)); // filesize() has troubles between 2GB and 4GB 
     192 
     193                // Make sure $file_size was calculated 
     194                if (empty($file_size) || $file_size === FALSE) 
     195                        return FALSE; 
     196         
     197                $sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); 
     198                for ($i=0; $file_size > 1024 && $i < count($sizes) - 1; $i++) 
     199                        $file_size /= 1024; 
     200                return round($file_size,$round).' '.$sizes[$i]; // ex: 10 kB 
     201        } 
     202 
     203} // End file 
  • system/helpers/security.php

    diff -ur trunk-old/system/helpers/security.php trunk/system/helpers/security.php
    old new  
    4343        { 
    4444                return str_replace(array('<?', '?>'), array('&lt;?', '?&gt;'), $str); 
    4545        } 
     46         
     47        /** 
     48         * Generate a pseudo-random token between 1-40 characters 
     49         * 
     50         * @param   integar  length of token (min 1, max 40) 
     51         * @param   string   string to hash 
     52         * @return  string   return psuedo-random token 
     53         */ 
     54        public static function generate_token($length = FALSE, $key = uniqid(rand(), TRUE)) 
     55        { 
     56                // sha1 is a 256-bit hex hash and is 40 characters long, thus it can not be longer than 40 
     57                // generate a 40 character long hash if length is greater than 40 or less than 0 (fail safe) 
     58                if ($length == FALSE || $length >= 40 || $length <= 0)  
     59                { 
     60                        return sha1($key); 
     61                } 
     62                else 
     63                { 
     64                        $start = rand(0,40-$length); // random number between 0 and maximum acceptable number before $start + $length > 40 
     65                        return substr(sha1($key),$start,$length); 
     66                } 
     67        } 
    4668 
    47 } // End security 
    48  No newline at end of file 
     69} // End security