Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-27676

pluginfile always return the big version of the default user profile image

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.3
    • Fix Version/s: 2.0.4
    • Component/s: Files API
    • Labels:
    • Testing Instructions:
      Hide

      Run the following code without a profil image (so the default image gets used):
      $profileimageurl = moodle_url::make_pluginfile_url(get_context_instance(CONTEXT_USER, $USER->id)->id, 'user', 'icon', NULL, '/', 'f2');
      echo "<img src=\"".$profileimageurl->out(false)."\">";

      You should see a small default image (try with 'f1' to see the difference).

      Show
      Run the following code without a profil image (so the default image gets used): $profileimageurl = moodle_url::make_pluginfile_url(get_context_instance(CONTEXT_USER, $USER->id)->id, 'user', 'icon', NULL, '/', 'f2'); echo "<img src=\"".$profileimageurl->out(false)."\">"; You should see a small default image (try with 'f1' to see the difference).
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE
    • Pull Master Branch:
      wip-MDL-27676-master

      Description

      http://jerome.moodle.local/~jerome/Moodle_HEAD/pluginfile.php?file=%2F21%2Fuser%2Ficon%2Ff2 => it should return the small version of the profile image. However it is always converted to http://jerome.moodle.local/~jerome/Moodle_HEAD/theme/image.php?theme=standard&image=u%2Ff1

      It should be converted to http://jerome.moodle.local/~jerome/Moodle_HEAD/theme/image.php?theme=standard&image=u%2Ff2

      Note that it works perfectly if the profile is not the theme default profile image (e.g. the user uploaded his own image).

      I looked very quickly at the code in pluginfile.php it's probably around there:

      } else if ($component === 'user') {
          if ($filearea === 'icon' and $context->contextlevel == CONTEXT_USER) {
              if (!empty($CFG->forcelogin) and !isloggedin()) {
                  // protect images if login required and not logged in;
                  // do not use require_login() because it is expensive and not suitable here anyway
                  redirect($OUTPUT->pix_url('u/f1'));
              }
              $filename = array_pop($args);
              if ($filename !== 'f1' and $filename !== 'f2') {
                  redirect($OUTPUT->pix_url('u/f1'));
              }
              if (!$file = $fs->get_file($context->id, 'user', 'icon', 0, '/', $filename.'/.png')) {
                  if (!$file = $fs->get_file($context->id, 'user', 'icon', 0, '/', $filename.'/.jpg')) {
                      redirect($OUTPUT->pix_url('u/f1'));
                  }
              }
      
              send_stored_file($file, 60*60*24); // enable long caching, there are many images on each page
      
          }
      

      This problem will break the display of every third party applications requesting a small picture by url, most likely mobile apps.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Votes:
                  0 Vote for this issue
                  Watchers:
                  1 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    1/Aug/11