Permalink
Browse files

MDL-26329 fix incorrect draft url rewriting when slasharguments off

tinymce editor encodes '/' in the ?file= parameter, we have to decode %2F before doing our standard @@PLUGINFILE@@ processing.
  • Loading branch information...
skodak committed Feb 11, 2011
1 parent d911c72 commit 9337cf32ca48d4142bb9e9901585fb7b723452fc
Showing with 16 additions and 8 deletions.
  1. +16 −8 lib/filelib.php
View
@@ -719,18 +719,26 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea
return null;
}
- // relink embedded files if text submitted - no absolute links allowed in database!
- if ($CFG->slasharguments) {
- $draftbase = "$CFG->wwwroot/draftfile.php/$usercontext->id/user/draft/$draftitemid/";
- } else {
- $draftbase = "$CFG->wwwroot/draftfile.php?file=/$usercontext->id/user/draft/$draftitemid/";
+ $wwwroot = $CFG->wwwroot;
+ if ($forcehttps) {
+ $wwwroot = str_replace('http://', 'https://', $wwwroot);
}
- if ($forcehttps) {
- $draftbase = str_replace('http://', 'https://', $draftbase);
+ // relink embedded files if text submitted - no absolute links allowed in database!
+ $text = str_ireplace("$wwwroot/draftfile.php/$usercontext->id/user/draft/$draftitemid/", '@@PLUGINFILE@@/', $text);
+
+ if (strpos($text, 'draftfile.php?file=') !== false) {
+ $matches = array();
+ preg_match_all("!$wwwroot/draftfile.php\?file=%2F{$usercontext->id}%2Fuser%2Fdraft%2F{$draftitemid}%2F[^'\",&<>|`\s:\\\\]+!iu", $text, $matches);
+ if ($matches) {
+ foreach ($matches[0] as $match) {
+ $replace = str_ireplace('%2F', '/', $match);
+ $text = str_replace($match, $replace, $text);
+ }
+ }
+ $text = str_ireplace("$wwwroot/draftfile.php?file=/$usercontext->id/user/draft/$draftitemid/", '@@PLUGINFILE@@/', $text);
}
- $text = str_ireplace($draftbase, '@@PLUGINFILE@@/', $text);
return $text;
}

0 comments on commit 9337cf3

Please sign in to comment.