Bladeren bron

Changed size display:
- Change to megs if over 1024 k
- if x < 10, show first digit after decimal point
Created new function (in strings.php) in case sizes should be shown elsewhere.

Tyler Akins 25 jaren geleden
bovenliggende
commit
73f6370ab5
4 gewijzigde bestanden met toevoegingen van 30 en 8 verwijderingen
  1. 1 2
      functions/imap_messages.php
  2. 1 1
      functions/mailbox_display.php
  3. 2 3
      functions/mime.php
  4. 26 2
      functions/strings.php

+ 1 - 2
functions/imap_messages.php

@@ -95,8 +95,7 @@
       fputs ($imap_stream, "a003 FETCH $id RFC822.SIZE\r\n");
       $read = sqimap_read_data($imap_stream, "a003", true, $r, $m);
       preg_match("/([0-9]+)\)\s*$/i", $read[0], $regs);
-      $size = $regs[1] / 1024;
-      settype($size, "integer");
+      $size = $regs[1];
       
       $header = new small_header;
       if ($sent == true)

+ 1 - 1
functions/mailbox_display.php

@@ -71,7 +71,7 @@
                else    echo "   <td bgcolor=$hlt_color width=1%>&nbsp;</td>\n";
                break;
             case 6: # size   
-               echo "   <td bgcolor=$hlt_color width=1%>$bold".$msg["SIZE"]."k$bold_end</td>\n";
+               echo "   <td bgcolor=$hlt_color width=1%>$bold".show_readable_size($msg['SIZE'])."$bold_end</td>\n";
                break;
          }
       }

+ 2 - 3
functions/mime.php

@@ -528,9 +528,8 @@
 
                $body .= '<TR><TD>&nbsp;&nbsp;</TD><TD>';
                $body .= "<A HREF=\"$DefaultLink\">$display_filename</A>&nbsp;</TD>";
-               $size = $message->header->size / 1024;
-               settype($size, "integer");
-               $body .= "<TD><SMALL><b>" . $size . "k</b>&nbsp;&nbsp;</small></TD>";
+               $body .= '<TD><SMALL><b>' . show_readable_size($message->header->size) . 
+                   '</b>&nbsp;&nbsp;</small></TD>';
                $body .= "<TD><SMALL>[ $type0/$type1 ]&nbsp;</SMALL></TD>";
                $body .= '<TD><SMALL>';
                if ($message->header->description)

+ 26 - 2
functions/strings.php

@@ -59,14 +59,14 @@
       if (count($words) > 1) {
          while ($i < count($words)) {
             // Force one word to be on a line (minimum)
-            $line .= $words[$i] . ' ';
+            $line .= $words[$i];
             $line_len = strlen($beginning_spaces) + strlen($words[$i]) +
                 strlen($words[$i + 1]) + 2;
             $i ++;
             
             // Add more words (as long as they fit)
             while ($line_len < $wrap && $i < count($words)) {
-               $line .= $words[$i] . ' ';
+               $line .= ' ' . $words[$i];
                $i++;
                $line_len += strlen($words[$i]) + 1;
             }
@@ -392,5 +392,29 @@
       
       return true;
    }
+   
+   /* Returns a string showing the size of the message/attachment */
+   function show_readable_size($bytes)
+   {
+       $bytes /= 1024;
+       $type = 'k';
+       
+       if ($bytes / 1024 > 1)
+       {
+           $bytes /= 1024;
+           $type = 'm';
+       }
+       
+       if ($bytes < 10)
+       {
+           $bytes *= 10;
+           settype($bytes, "integer");
+           $bytes /= 10;
+       }
+       else
+           settype($bytes, "integer");
+       
+       return $bytes . '<small>&nbsp;' . $type . '</small>';
+   }
 
 ?>