Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8654157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:43:01+00:00 2026-06-12T14:43:01+00:00

While browsing Moodle’s source code I stumbled across this: repository/recent/lib.php public function get_listing($encodedpath =

  • 0

While browsing Moodle’s source code I stumbled across this:

repository/recent/lib.php

public function get_listing($encodedpath = '', $page = '') {
    global $OUTPUT;
    $ret = array();
    $ret['dynload'] = true;
    $ret['nosearch'] = true;
    $ret['nologin'] = true;
    $list = array();
    $files = $this->get_recent_files(0, $this->number);

    try {
        foreach ($files as $file) {
            $params = base64_encode(serialize($file));
            // Check that file exists and accessible
            $filesize = $this->get_file_size($params);
            if ($file['filename'] == 'image.png') {
              var_dump($filesize);
            }
            if (!empty($filesize)) {
                $node = array(
                    'title' => $file['filename'],
                    'size' => $filesize,
                    'date' => '',
                    'source'=> $params,
                    'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file['filename'], 32))->out(false),
                );
                $list[] = $node;
            }
        }
    } catch (Exception $e) {
        throw new repository_exception('emptyfilelist', 'repository_recent');
    }
    $ret['list'] = array_filter($list, array($this, 'filter'));
    return $ret;
}

repository/lib.php

public function get_file_size($source) {
    $browser    = get_file_browser();
    $params     = unserialize(base64_decode($source));
    $contextid  = clean_param($params['contextid'], PARAM_INT);
    $fileitemid = clean_param($params['itemid'], PARAM_INT);
    $filename   = clean_param($params['filename'], PARAM_FILE);
    $filepath   = clean_param($params['filepath'], PARAM_PATH);
    $filearea   = clean_param($params['filearea'], PARAM_AREA);
    $component  = clean_param($params['component'], PARAM_COMPONENT);
    $context    = get_context_instance_by_id($contextid);
    $file_info  = $browser->get_file_info($context, $component, $filearea, $fileitemid, $filepath, $filename);
    if (!empty($file_info)) {
        $filesize = $file_info->get_filesize();
    } else {
        $filesize = null;
    }
    return $filesize;
}

My question is what is the purpose of base64 encoding and serializing this when it’s immediately undone once inside the function? Is there a valid reason for doing this or is this just over engineered?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:43:02+00:00Added an answer on June 12, 2026 at 2:43 pm

    A quick click around in their PHPXref reveals that this function is also called in repository_ajax.php

    Passing serialised data around in a query string / form field simply isn’t going to work (potentially), but with base64 encoding this is not an issue.

    So the function was designed to handle requests delivered via ajax, base64 decode, deserialise, and then return the file size. (This is probably linked to the source element of the list node too)

    In essence, the call is verifying that encoded string is valid, for when it is later used in the ajax request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While browsing some source code I came across a function like this: void someFunction(char
I am using this IP Validation Function that I came across while browsing, it
While browsing some code, I came across this line: if False: #shedskin I understand
I found this code for a generic DAO interface while browsing around: public interface
While browsing the source code of the Scala API, I met this package definition
While browsing I came across this blog post about using the Wikipedia API from
While browsing MSDN documentation, you may come across this gem: TextBox.Watermark. Awesome! I've been
While browsing System.Zip (Delphi XE2) to see how it works, I found this function:
While browsing the code of an erlang application, I came across an interesting design
I came across this presentation while browsing SO some time ago, and it relates

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.