Changeset 979 in subversion


Ignore:
Timestamp:
Jan 31, 2008 8:09:21 PM (5 years ago)
Author:
till
Message:
  • minor cs
  • some comments and @todo
  • simplified if()'s
Location:
branches/devel-vnext/program/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-vnext/program/include/bootstrap.php

    r978 r979  
    1313 |   any request.                                                        | 
    1414 +-----------------------------------------------------------------------+ 
    15  | Author: Tll Klampaeckel <till@php.net>                                | 
     15 | Author: Till Klampaeckel <till@php.net>                               | 
    1616 |         Thomas Bruederli <roundcube@gmail.com>                        | 
    1717 +-----------------------------------------------------------------------+ 
  • branches/devel-vnext/program/include/globals.php

    r957 r979  
    11<?php 
    2  
    32/* 
    43 +-----------------------------------------------------------------------+ 
     
    6968/** 
    7069 * Send HTTP headers to prevent caching this page 
     70 *  
     71 * @return void 
    7172 */ 
    7273function send_nocacheing_headers() { 
     
    8586 * 
    8687 * @param int Expiration time in seconds 
     88 * @return void 
    8789 */ 
    8890function send_future_expire_header($offset = 2600000) { 
     
    103105 * @param int Modified date as unix timestamp 
    104106 * @param string Etag value for caching 
     107 * @return void 
    105108 */ 
    106109function send_modified_header($mdate, $etag = null) { 
     
    109112    } 
    110113    $iscached = false; 
    111     if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $mdate) { 
     114    if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] 
     115        && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $mdate) { 
    112116        $iscached = true; 
    113117    } 
     
    171175            foreach ($var as $key => $value) { 
    172176                // enclose key with quotes if it is not variable-name conform 
    173                 if (!ereg('^[_a-zA-Z]{1}[_a-zA-Z0-9]*$', $key) /* || is_js_reserved_word($key) */) 
    174                 $key = "'$key'"; 
    175  
     177                if (!ereg('^[_a-zA-Z]{1}[_a-zA-Z0-9]*$', $key) /* || is_js_reserved_word($key) */) { 
     178                    $key = "'$key'"; 
     179                } 
    176180                $pairs[] = sprintf("%s%s", $is_assoc ? $key.':' : '', json_serialize($value)); 
    177181            } 
     
    225229    if(in_array($str, array('false', '0', 'no', 'nein', ''), TRUE)) { 
    226230        return FALSE; 
    227     } else { 
    228         return TRUE; 
    229     } 
     231    } 
     232    return TRUE; 
    230233} 
    231234 
     
    245248        $bytes = floatval($regs[1]); 
    246249        switch (strtolower($regs[2])) { 
    247             case 'g': 
    248                 $bytes *= 1073741824; 
    249                 break; 
    250             case 'm': 
    251                 $bytes *= 1048576; 
    252                 break; 
    253             case 'k': 
    254                 $bytes *= 1024; 
    255                 break; 
     250        case 'g': 
     251            $bytes *= 1073741824; 
     252            break; 
     253        case 'm': 
     254            $bytes *= 1048576; 
     255            break; 
     256        case 'k': 
     257            $bytes *= 1024; 
     258            break; 
    256259        } 
    257260    } 
     
    269272function show_bytes($bytes) { 
    270273    if ($bytes > 1073741824) { 
    271         $gb = $bytes/1073741824; 
     274        $gb  = $bytes/1073741824; 
    272275        $str = sprintf($gb>=10 ? "%d GB" : "%.1f GB", $gb); 
    273276    } else if ($bytes > 1048576) { 
    274         $mb = $bytes/1048576; 
     277        $mb  = $bytes/1048576; 
    275278        $str = sprintf($mb>=10 ? "%d MB" : "%.1f MB", $mb); 
    276279    } else if ($bytes > 1024) { 
     
    327330    if (function_exists('mb_strlen')) { 
    328331        return mb_strlen($str); 
    329     } else { 
    330         return strlen($str); 
    331     } 
     332    } 
     333    return strlen($str); 
    332334} 
    333335 
     
    338340    if (function_exists('mb_strtolower')) { 
    339341        return mb_strtolower($str); 
    340     } else { 
    341         return strtolower($str); 
     342    } 
     343    return strtolower($str); 
    342344    } 
    343345} 
     
    349351    if (function_exists('mb_substr')) { 
    350352        return mb_substr($str, $start, $len); 
    351     } else { 
    352         return substr($str, $start, $len); 
    353     } 
     353    } 
     354    return substr($str, $start, $len); 
    354355} 
    355356 
     
    360361    if (function_exists('mb_strpos')) { 
    361362        return mb_strpos($haystack, $needle, $offset); 
    362     } else { 
    363         return strpos($haystack, $needle, $offset); 
    364     } 
     363    } 
     364        return strpos($haystack, $needle, $offset); 
    365365} 
    366366 
     
    371371    if (function_exists('mb_strrpos')) { 
    372372        return mb_strrpos($haystack, $needle, $offset); 
    373     } else { 
    374         return strrpos($haystack, $needle, $offset); 
    375     } 
     373    } 
     374        return strrpos($haystack, $needle, $offset); 
    376375} 
    377376 
     
    444443 * @param int Factor to multiply with the offset 
    445444 * @return int Unix timestamp 
     445 * @todo Check the switch() - it looks weird. 
    446446 */ 
    447447function get_offset_time($offset_str, $factor = 1) { 
     
    456456    $ts = mktime(); 
    457457    switch ($unit) { 
    458         case 'w': 
    459             $amount *= 7; 
    460         case 'd': 
    461             $amount *= 24; 
    462         case 'h': 
    463             $amount *= 60; 
    464         case 'm': 
    465             $amount *= 60; 
    466         case 's': 
    467             $ts += $amount * $factor; 
     458    case 'w': 
     459        $amount *= 7; 
     460    case 'd': 
     461        $amount *= 24; 
     462    case 'h': 
     463        $amount *= 60; 
     464    case 'm': 
     465        $amount *= 60; 
     466    case 's': 
     467        $ts += $amount * $factor; 
    468468    } 
    469469 
     
    483483    if ($pver[0] >= 5) { 
    484484        return strrpos($haystack, $needle); 
    485     } else { 
    486         $index = strpos(strrev($haystack), strrev($needle)); 
    487         if ($index === false) { 
    488             return false; 
    489         } 
    490         $index = strlen($haystack) - strlen($needle) - $index; 
    491         return $index; 
    492     } 
    493 } 
    494  
    495 ?> 
     485    } 
     486    $index = strpos(strrev($haystack), strrev($needle)); 
     487    if ($index === false) { 
     488        return false; 
     489    } 
     490    $index = strlen($haystack) - strlen($needle) - $index; 
     491    return $index; 
     492} 
Note: See TracChangeset for help on using the changeset viewer.