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

Bug (with FIX) with pix folder in modules not in mod folder

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • 2.5.6, 2.7.2
    • Authentication
    • None
    • MOODLE_25_STABLE, MOODLE_27_STABLE

      Hi, guys!
      Just resolved a bug in moodle that makes me angry. So i did auth module and wanted to make css with background and write like this: background-image: url('[[pix:auth_myplugin|myicon]]'); so it located at /auth/myplugin/pix/myicon.png BUT IT NOT WORKS, because Moodle makes path like this /theme/image.php/standard/core/1411564078/auth_myplugin/myicon
      But it wrong, its not a core, its auth_myplugin. So i started to look for a bug, so file lib/outputlib.php in function resolve_image_location checks for $component at this place:
      if (strpos($component, '_') === false)

      { $component = 'mod_'.$component; }

      its OK, but if it not mod_XXX = bug
      so i resolved it:
      file lib/outputlib.php -> function post_process(): 1298
      look at 1307 and 1308:
      $imagename = $match[2];
      $component = rtrim($match[1], '|');
      here is bug, because $match[1] is empty in our case!
      FIX:
      if ( !empty( $match[1] ) )

      { $imagename = $match[2]; $component = rtrim($match[1], '|'); } else {
      if ( !empty( $match[2] ) ) { $tmp_array = explode( '|' , $match[2]); $component = $tmp_array[0]; $imagename = $tmp_array[1]; }
      }

      so function post_process must be like this:
      public function post_process($css) {
      // now resolve all image locations
      if (preg_match_all('/[[pix[a-z_]|)?([^\]])]]/', $css, $matches, PREG_SET_ORDER)) {
      $replaced = array();
      foreach ($matches as $match) {//print_r($match);die;
      if (isset($replaced[$match[0]])) { continue; }
      $replaced[$match[0]] = true;
      if ( !empty( $match[1] ) ) { $imagename = $match[2]; $component = rtrim($match[1], '|'); }

      else {
      if ( !empty( $match[2] ) )

      { $tmp_array = explode( '|' , $match[2]); $component = $tmp_array[0]; $imagename = $tmp_array[1]; }

      }

      $imageurl = $this->pix_url($imagename, $component)->out(false);
      // we do not need full url because the image.php is always in the same dir
      $imageurl = preg_replace('|^http.?://[^/]+|', '', $imageurl);
      $css = str_replace($match[0], $imageurl, $css);
      }
      }

      // now resolve all theme settings or do any other postprocessing
      $csspostprocess = $this->csspostprocess;
      if (function_exists($csspostprocess))

      { $css = $csspostprocess($css, $this); }

      return $css;
      }

      hope i will help moodle))

            Unassigned Unassigned
            tigusigalpa Igor Sazonov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

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