Prechádzať zdrojové kódy

Merge branch 'trunk'

Andy 5 rokov pred
rodič
commit
7372f05c34

+ 7 - 0
config/config_local.example.php

@@ -193,4 +193,11 @@
  * traffic from a proxy so the normal $PHP_SELF does not resolve
  * to what it should be for the real client.
  *
+ * $upload_filesize_divisor allows the administrator to specify
+ * the divisor used when converting the size of an uploaded file
+ * as given by PHP's filesize() and converted to human-digestable
+ * form.  By default, 1000 is used, but 1024 may be necessary in
+ * some environments.
+ * $upload_filesize_divisor = 1024;
+ *
  */

+ 2 - 0
doc/ChangeLog

@@ -441,6 +441,8 @@ Version 1.5.2 - SVN
     regular expression including the delimiters. This may be helpful
     when the web server sees traffic from a proxy so the normal
     $PHP_SELF does not resolve to what it should be for the real client.
+  - Show more accurate filesize for uploaded files and base64-encoded
+    attachments (when reading a message)
 
 Version 1.5.1 (branched on 2006-02-12)
 --------------------------------------

+ 7 - 1
functions/mime.php

@@ -639,7 +639,13 @@ function buildAttachmentArray($message, $exclude_id, $mailbox, $id) {
         $this_attachment['DefaultHREF'] = $defaultlink;
         $this_attachment['DownloadHREF'] = $links['download link']['href'];
         $this_attachment['ViewHREF'] = isset($links['attachment_common']) ? $links['attachment_common']['href'] : '';
-        $this_attachment['Size'] = $header->size;
+
+        // base64 encoded file sizes are misleading, so approximate real size
+        if (!empty($header->encoding) && strtolower($header->encoding) == 'base64')
+            $this_attachment['Size'] = $header->size / 4 * 3;
+        else
+            $this_attachment['Size'] = $header->size;
+
         $this_attachment['ContentType'] = sm_encode_html_special_chars($type0 .'/'. $type1);
         $this_attachment['OtherLinks'] = array();
         foreach ($links as $val) {

+ 5 - 4
functions/strings.php

@@ -654,18 +654,19 @@ function OneTimePadCreate ($length=100) {
   * a more easily digested (readable) format
   *
   * @param int $bytes the size in bytes
+  * @param int $filesize_divisor the divisor we'll use (OPTIONAL; default 1024)
   *
   * @return string The size in human readable format
   *
   * @since 1.0
   *
   */
-function show_readable_size($bytes) {
-    $bytes /= 1024;
+function show_readable_size($bytes, $filesize_divisor) {
+    $bytes /= $filesize_divisor;
     $type = _("KiB");
 
-    if ($bytes / 1024 > 1) {
-        $bytes /= 1024;
+    if ($bytes / $filesize_divisor > 1) {
+        $bytes /= $filesize_divisor;
         $type = _("MiB");
     }
 

+ 3 - 2
functions/template/general_util.php

@@ -169,9 +169,10 @@ function displayErrors () {
 //FIXME: I think this is needless since there is no reason templates cannot just call directly to show_readable_size
  *
  * @param int size to be converted to human-readable
+ * @param int filesize_divisor the divisor we'll use (OPTIONAL; default 1024)
  * @return string human-readable form
  * @since 1.5.2
  **/
-function humanReadableSize ($size) {
-    return show_readable_size($size);
+function humanReadableSize ($size, $filesize_divisor=1024) {
+    return show_readable_size($size, $filesize_divisor);
 }

+ 4 - 1
src/compose.php

@@ -1484,7 +1484,9 @@ function showInputForm ($session, $values=false) {
         }
 
         $attach = array();
-        global $username, $attachment_dir;
+        global $username, $attachment_dir, $upload_filesize_divisor;
+        if (empty($upload_filesize_divisor))
+            $upload_filesize_divisor = 1000; // *not* 1024 -- does this break for some users?
         $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
         if (!empty($attach_array)) {
             foreach ($attach_array as $key => $attachment) {
@@ -1507,6 +1509,7 @@ function showInputForm ($session, $values=false) {
         $max = min($sizes);
         $oTemplate->assign('max_file_size', empty($max) ? -1 : $max);
         $oTemplate->assign('attachments', $attach);
+        $oTemplate->assign('upload_filesize_divisor', $upload_filesize_divisor);
 
         // access keys...
         //

+ 1 - 1
templates/default/compose_attachments.tpl

@@ -55,7 +55,7 @@ extract($t);
    <input type="checkbox" name="delete[]" id="delete<?php echo $attachment_count; ?>" accesskey="<?php echo ($attachment_count % 10); ?>" value="<?php echo $attach['Key']; ?>" />
   </td>
   <td class="fieldValue"><label for="delete<?php echo $attachment_count; ?>">
-   <?php echo $attach['FileName']; ?> - <?php echo $attach['ContentType']; ?> (<?php echo humanReadableSize($attach['Size']); ?>)
+   <?php echo $attach['FileName']; ?> - <?php echo $attach['ContentType']; ?> (<?php echo humanReadableSize($attach['Size'], $upload_filesize_divisor); ?>)
   </label></td>
  </tr>
         <?php