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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 2.0.4
    • 2.0.3
    • Files API
    • MOODLE_20_STABLE
    • MOODLE_20_STABLE
    • wip-MDL-27676-master
    • 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).

      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.

            samhemelryk Sam Hemelryk
            jerome Jérôme Mouneyrac
            Rossiani Wijaya Rossiani Wijaya
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.