Skip to content

Instantly share code, notes, and snippets.

@mudrd8mz
Created May 3, 2013 09:10
Show Gist options
  • Save mudrd8mz/5508113 to your computer and use it in GitHub Desktop.
Save mudrd8mz/5508113 to your computer and use it in GitHub Desktop.
Proposal for format_text() check in Moodle
diff --git a/lib/weblib.php b/lib/weblib.php
index 647504a..28aef68 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -1174,6 +1174,14 @@ function format_text($text, $format = FORMAT_MOODLE, $options = NULL, $courseid_
// The only potential problem is that somebody might try to format
// the text before storing into database which would be itself big bug.
$text = str_replace("\"$CFG->httpswwwroot/draftfile.php", "\"$CFG->httpswwwroot/brokenfile.php#", $text);
+
+ // Before calling format_text(), the text must be processed with {@link file_rewrite_pluginfile_urls()}
+ // or its equivalent. Inform the developer.
+ if (debugging('', DEBUG_DEVELOPER)) {
+ if (strpos($text, '@@PLUGINFILE@@')) {
+ debugging('Attempting to format a text with non-rewritten pluginfile URL', DEBUG_DEVELOPER);
+ }
+ }
}
// Warn people that we have removed this old mechanism, just in case they
@mudrd8mz
Copy link
Author

mudrd8mz commented May 3, 2013

if (strpos($text, '@@PluginFile@@') !== false) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment