• Resolved FernandoOrtegaOjeda

    (@fernandoortegaojeda)


    Hi,

    I’m using your nice piece of software. Thanks for that.

    However, I’m trying to change the way it presents the file sizes.

    Your current ‘borrowed’ code:

    {
    $sz = ‘BKMGTP’;
    $factor = floor((strlen($bytes) – 1) / 3);
    return sprintf(“%.{$decimals}f”, $bytes / pow(1024, $factor)) . @$sz[$factor];
    }

    shows for example: (45M), (21K), etc. This was not natural/automatic to read for us (university research group).

    I mean, according to the International System I’m using, it’s not ok to show ‘’BKMGTP’’ instead of ‘BytesKbMbGbTbPb, and after the number, there should be a space and then the measure unit:

    For example:
    (12.54 Mb)
    (5 Gb)
    (23 Kb)
    Etc.

    It could be a silly thing, but we’d like to have it like I describe.

    I’m not a PHP programmer, and thus I was not able to change your borrowed code, but I found (in the same page where you borrowed yours) a larger piece of code belonging to a Russian-like named guy (sorry for stereotyping him):

    {
    $bytes = floatval($bytes);
    $arBytes = array(
    0 => array(
    “UNIT” => ” Tb”,
    “VALUE” => pow(1024, 4)
    ),
    1 => array(
    “UNIT” => ” Gb”,
    “VALUE” => pow(1024, 3)
    ),
    2 => array(
    “UNIT” => ” Mb”,
    “VALUE” => pow(1024, 2)
    ),
    3 => array(
    “UNIT” => ” Kb”,
    “VALUE” => 1024
    ),
    4 => array(
    “UNIT” => ” Bytes”,
    “VALUE” => 1
    ),
    );

    foreach($arBytes as $arItem)
    {
    if($bytes >= $arItem[“VALUE”])
    {
    $result = $bytes / $arItem[“VALUE”];
    $result = str_replace(“.”, “,” , strval(round($result, $decimals))).” “.$arItem[“UNIT”];
    break;
    }
    }
    return $result;
    }

    The thing is, your plugin seems to reset itself, trashing my inserted code.

    That’s certainly good for your code but not for my humble intentions… 🙂

    Could you please do something about the units?

    One more extra thing. Could you please add a way to target the links to pop-up windows?

    Thanks a lot for your help and understanding.

    Best regards,

    Fernando.

    https://wordpress.org/plugins/mmm-file-list/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Adam Bissonnette

    (@mmanifesto)

    Hey Fernando,

    Thanks for the input. I’ve updated the code to version 1.3 which includes a slightly modified version of that code from our friend Arseny Mogilev (https://www.youtube.com/watch?v=6lGyH7jkebY).

    My modifications include the addition of PB and I removed the 1 => array(), 2 => array() key value typing since those keys were redundant.

    The url target can be set using the target parameter in the shortcode like this:
    [MMFileList folder=”/cats/” format=”li” target=”_blank” /]

    Alternatively you can look at the templating guide I wrote in the description to create a custom output format.

    As for the plugin trashing the inserted code – I think you must have automatic updates on because that shouldn’t be happening normally. If you want to make a change and never have my code overwrite what you’ve changed then you should modify the plugin name and version number at the top of the mm_filelist_plugin.php file like this:

    /*
    Plugin Name: Mmm Better Simple File List
    Plugin URI: http://www.differentcode.com
    Description: Plugin to list files in a given directory using this shortcode [MMFileList folder=”optional starting from base uploads path” format=”li (unordered list) or table (tabular) or img (unordered list of images) or comma (plain text, comma, delimited) types=”optional file-extension e.g. pdf,doc” class=”optional css class for html list”]
    Version: 99999
    Author: Fernando
    Author URI: http://www.different.com
    */

    Let me know if this resolves your issues. If you like the plugin please rate it 5++ stars so my ego is satisfied 🙂

    Hi MManifesto,

    Thank you for making this very useful plugin available on WordPress.org. I really appreciate your efforts.

    Please update the plugin to use the correct units of measure for file sizes in accordance with International Standards.

    One international standard is the 1284.1-1997 IEEE Standard for Information Technology which says that the unit MB, with an uppercase “B”, stands for megabytes while Mb, with a lowercase “b”, stands for megabits.

    The JEDEC Memory Standard, the specification for the semiconductor memory circuits and similar storage devices promulgated by the Joint Electron Device Engineering Council (JEDEC) Solid State Technology Association, a semiconductor trade and engineering standardization organization, seems to agree. Their JEDEC Standard 100B.01 defines the two common units of information as follows:

    • The bit (b) is the smallest unit of information in the binary numeration system and is represented by the digits 0 and 1.
    • The byte (B) is a binary character string typically operated upon as one unit. It is usually shorter than a computer word.

    It’s been like that for years (I’ve been programming for 35 years).

    If you want to use the lowercase “b”, you will need to multiply file size values by 1024 before assigning them a unit of measure. That said, I really hope you don’t as it would really confuse people who have become accustomed to file size measurements in bytes, not bits.

    FIY: It isn’t actually like that in every language. It is possible that the small “b” requested by Fernando was for a non-English international standard. I noticed that he is located in Spanish speaking Madrid. I don’t speak Spanish so I can’t comment on it. However in French for example, I happen to know that the correct unit for KB is ko (for kilo octet), MB is mo (for mega octet), etc, with small “o”s.

    The correct solution would be to put these strings in a po/mo language file so that they could easily be translated into any language in the world.

    Best regards,

    Michael Milette

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Size units…’ is closed to new replies.