Changeset 86df152 in github for program/include/rcube_shared.inc


Ignore:
Timestamp:
Dec 29, 2006 4:06:39 PM (6 years ago)
Author:
thomascube <thomas@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
e93a2d7
Parents:
3b12aee
Message:

Error handling for attachment uploads; multibyte-safe string functions; XSS improvements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/include/rcube_shared.inc

    r2bca6e1 r86df152  
    66 |                                                                       | 
    77 | This file is part of the RoundCube PHP suite                          | 
    8  | Copyright (C) 2005, RoundCube Dev. - Switzerland                      | 
     8 | Copyright (C) 2005-2006, RoundCube Dev. - Switzerland                 | 
    99 | Licensed under the GNU GPL                                            | 
    1010 |                                                                       | 
     
    130130     
    131131    // set default page title 
    132     if (!strlen($this->title)) 
     132    if (empty($this->title)) 
    133133      $this->title = 'RoundCube Mail'; 
    134134   
     
    159159   } 
    160160 
    161     if (strlen($this->scripts['head'])) 
     161    if (!empty($this->scripts['head'])) 
    162162      $__page_header .= sprintf($this->script_tag, $this->scripts['head']); 
    163163           
     
    168168      } 
    169169 
    170     if (strlen($this->scripts['foot'])) 
     170    if (!empty($this->scripts['foot'])) 
    171171      $__page_footer .= sprintf($this->script_tag, $this->scripts['foot']); 
    172172       
     
    177177   
    178178    // find page header 
    179     if($hpos = strpos(strtolower($output), '</head>')) 
     179    if($hpos = rc_strpos(rc_strtolower($output), '</head>')) 
    180180      $__page_header .= "\n"; 
    181181    else  
    182182      { 
    183183      if (!is_numeric($hpos)) 
    184         $hpos = strpos(strtolower($output), '<body'); 
    185       if (!is_numeric($hpos) && ($hpos = strpos(strtolower($output), '<html'))) 
     184        $hpos = rc_strpos(rc_strtolower($output), '<body'); 
     185      if (!is_numeric($hpos) && ($hpos = rc_strpos(rc_strtolower($output), '<html'))) 
    186186        { 
    187187        while($output[$hpos]!='>') 
     
    195195    // add page hader 
    196196    if($hpos) 
    197       $output = substr($output,0,$hpos) . $__page_header . substr($output,$hpos,strlen($output)); 
     197      $output = rc_substr($output,0,$hpos) . $__page_header . rc_substr($output,$hpos,rc_strlen($output)); 
    198198    else 
    199199      $output = $__page_header . $output; 
     
    201201   
    202202    // find page body 
    203     if($bpos = strpos(strtolower($output), '<body')) 
     203    if($bpos = rc_strpos(rc_strtolower($output), '<body')) 
    204204      { 
    205205      while($output[$bpos]!='>') $bpos++; 
     
    207207      } 
    208208    else 
    209       $bpos = strpos(strtolower($output), '</head>')+7; 
     209      $bpos = rc_strpos(rc_strtolower($output), '</head>')+7; 
    210210   
    211211    // add page body 
    212212    if($bpos && $__page_body) 
    213       $output = substr($output,0,$bpos) . "\n$__page_body\n" . substr($output,$bpos,strlen($output)); 
     213      $output = rc_substr($output,0,$bpos) . "\n$__page_body\n" . rc_substr($output,$bpos,rc_strlen($output)); 
    214214   
    215215   
    216216    // find and add page footer 
    217     $output_lc = strtolower($output); 
     217    $output_lc = rc_strtolower($output); 
    218218    if(($fpos = strrstr($output_lc, '</body>')) || 
    219219       ($fpos = strrstr($output_lc, '</html>'))) 
    220       $output = substr($output,0,$fpos) . "$__page_footer\n" . substr($output,$fpos); 
     220      $output = rc_substr($output,0,$fpos) . "$__page_footer\n" . rc_substr($output,$fpos); 
    221221    else 
    222222      $output .= "\n$__page_footer"; 
     
    879879      unset($this->attrib['value']); 
    880880 
    881     if (strlen($value) && !isset($this->attrib['mce_editable'])) 
     881    if (!empty($value) && !isset($this->attrib['mce_editable'])) 
    882882      $value = Q($value, 'strict', FALSE); 
    883883 
     
    10131013    foreach ($this->options as $option) 
    10141014      { 
    1015       $selected = ((strlen($option['value']) && in_array($option['value'], $select, TRUE)) || 
     1015      $selected = ((!empty($option['value']) && in_array($option['value'], $select, TRUE)) || 
    10161016                   (in_array($option['text'], $select, TRUE))) ? $this->_conv_case(' selected', 'attrib') : ''; 
    10171017                   
    10181018      $options_str .= sprintf("<%s%s%s>%s</%s>\n", 
    10191019                             $this->_conv_case('option', 'tag'), 
    1020                              strlen($option['value']) ? sprintf($value_str, $option['value']) : '', 
     1020                             !empty($option['value']) ? sprintf($value_str, $option['value']) : '', 
    10211021                             $selected,  
    10221022                             Q($option['text'], 'strict', FALSE), 
     
    11051105  $vars = isset($attrib['vars']) ? $attrib['vars'] : ''; 
    11061106 
    1107   $command_name = strlen($attrib['command']) ? $attrib['command'] : NULL; 
     1107  $command_name = !empty($attrib['command']) ? $attrib['command'] : NULL; 
    11081108  $alias = $attrib['name'] ? $attrib['name'] : ($command_name && $command_label_map[$command_name] ? $command_label_map[$command_name] : ''); 
    11091109 
     
    12781278            $value = $value ? "true" : "false"; 
    12791279            } 
    1280           else if ((($type=='mixed' && is_numeric($value)) || $type=='int') && strlen($value)<16)   // js interprets numbers with digits >15 as ...e+...  
     1280          else if ((($type=='mixed' && is_numeric($value)) || $type=='int') && rc_strlen($value)<16)   // js interprets numbers with digits >15 as ...e+...  
    12811281            $is_string = FALSE; 
    12821282          else 
     
    13351335 
    13361336 
     1337// parse a human readable string for a number of bytes 
     1338function parse_bytes($str) 
     1339  { 
     1340  if (is_numeric($str)) 
     1341    return intval($str); 
     1342     
     1343  if (preg_match('/([0-9]+)([a-z])/i', $str, $regs)) 
     1344    { 
     1345      $bytes = floatval($regs[1]); 
     1346      switch (strtolower($regs[2])) 
     1347      { 
     1348        case 'g': 
     1349          $bytes *= 1073741824; 
     1350          break; 
     1351        case 'm': 
     1352          $bytes *= 1048576; 
     1353          break; 
     1354        case 'k': 
     1355          $bytes *= 1024; 
     1356          break; 
     1357      } 
     1358    } 
     1359 
     1360  return intval($bytes); 
     1361  } 
     1362     
    13371363// create a human readable string for a number of bytes 
    13381364function show_bytes($bytes) 
     
    13941420 
    13951421 
     1422// wrapper function for strlen 
     1423function rc_strlen($str) 
     1424  { 
     1425    if (function_exists('mb_strlen')) 
     1426      return mb_strlen($str); 
     1427    else 
     1428      return strlen($str); 
     1429  } 
     1430   
     1431// wrapper function for strtolower 
     1432function rc_strtolower($str) 
     1433  { 
     1434    if (function_exists('mb_strtolower')) 
     1435      return mb_strtolower($str); 
     1436    else 
     1437      return strtolower($str); 
     1438  } 
     1439 
     1440// wrapper function for substr 
     1441function rc_substr($str, $start, $len) 
     1442  { 
     1443  if (function_exists('mb_substr')) 
     1444    return mb_substr($str, $start, $len); 
     1445  else 
     1446    return substr($str, $start, $len); 
     1447  } 
     1448 
     1449// wrapper function for strpos 
     1450function rc_strpos($haystack, $needle, $offset=0) 
     1451  { 
     1452  if (function_exists('mb_strpos')) 
     1453    return mb_strpos($haystack, $needle, $offset); 
     1454  else 
     1455    return strpos($haystack, $needle, $offset); 
     1456  } 
     1457 
     1458// wrapper function for strrpos 
     1459function rc_strrpos($haystack, $needle, $offset=0) 
     1460  { 
     1461  if (function_exists('mb_strrpos')) 
     1462    return mb_strrpos($haystack, $needle, $offset); 
     1463  else 
     1464    return strrpos($haystack, $needle, $offset); 
     1465  } 
     1466 
     1467 
    13961468// replace the middle part of a string with ... 
    13971469// if it is longer than the allowed length 
    13981470function abbrevate_string($str, $maxlength, $place_holder='...') 
    13991471  { 
    1400   $length = strlen($str); 
    1401   $first_part_length = floor($maxlength/2) - strlen($place_holder); 
     1472  $length = rc_strlen($str); 
     1473  $first_part_length = floor($maxlength/2) - rc_strlen($place_holder); 
    14021474   
    14031475  if ($length > $maxlength) 
    14041476    { 
    14051477    $second_starting_location = $length - $maxlength + $first_part_length + 1; 
    1406     $str = substr($str, 0, $first_part_length) . $place_holder . substr($str, $second_starting_location, $length); 
     1478    $str = rc_substr($str, 0, $first_part_length) . $place_holder . rc_substr($str, $second_starting_location, $length); 
    14071479    } 
    14081480 
Note: See TracChangeset for help on using the changeset viewer.