]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18799 backup of file.php links - now using unicode modifiers if allowed in the...
authorstronk7 <stronk7>
Tue, 5 May 2009 09:26:47 +0000 (09:26 +0000)
committerstronk7 <stronk7>
Tue, 5 May 2009 09:26:47 +0000 (09:26 +0000)
backup/backuplib.php

index 43234c692754f47ecb4fa85da7ee990bcad62054..d11e5096007c0cca99072f7b4475fa801accee0a 100644 (file)
             $includedfiles = array();
         }
 
+        //Check if we support unicode modifiers in regular expressions. Cache it.
+        static $unicoderegexp;
+        if (!isset($unicoderegexp)) {
+            $unicoderegexp = @preg_match('/\pL/u', 'a'); // This will fail silenty, returning false,
+        }                                                // if regexp libraries don't support unicode
+
         //Check if preferences is ok. If it isn't set, we are
         //in a scheduled_backup to we are able to get a copy
         //from CFG->backup_preferences
         //     - slashes and %2F by $@SLASH@$
         //     - &forcedownload=1 &amp;forcedownload=1 and ?forcedownload=1 by $@FORCEDOWNLOAD@$
         // This way, backup contents will be neutral and independent of slasharguments configuration. MDL-18799
-        $search = '/(\$@FILEPHP@\$)((?:(?:\/|%2f|%2F))(?:(?:\([-;:@#&=\pL0-9\$~_.+!*\',]*?\))|[-;:@#&=\pL0-9\$~_.+!*\',]|%[a-fA-F0-9]{2}|\/)*)?(\?(?:(?:(?:\([-;:@#&=\pL0-9\$~_.+!*\',]*?\))|[-;:@#&=?\pL0-9\$~_.+!*\',]|%[a-fA-F0-9]{2}|\/)*))?(?<![,.;])/';
+        // Based in $unicoderegexp, decide the regular expression to use
+        if ($unicoderegexp) { //We can use unicode modifiers
+            $search = '/(\$@FILEPHP@\$)((?:(?:\/|%2f|%2F))(?:(?:\([-;:@#&=\pL0-9\$~_.+!*\',]*?\))|[-;:@#&=\pL0-9\$~_.+!*\',]|%[a-fA-F0-9]{2}|\/)*)?(\?(?:(?:(?:\([-;:@#&=\pL0-9\$~_.+!*\',]*?\))|[-;:@#&=?\pL0-9\$~_.+!*\',]|%[a-fA-F0-9]{2}|\/)*))?(?<![,.;])/';
+        } else { //We cannot ue unicode modifiers
+            $search = '/(\$@FILEPHP@\$)((?:(?:\/|%2f|%2F))(?:(?:\([-;:@#&=a-zA-Z0-9\$~_.+!*\',]*?\))|[-;:@#&=a-zA-Z0-9\$~_.+!*\',]|%[a-fA-F0-9]{2}|\/)*)?(\?(?:(?:(?:\([-;:@#&=a-zA-Z0-9\$~_.+!*\',]*?\))|[-;:@#&=?a-zA-Z0-9\$~_.+!*\',]|%[a-fA-F0-9]{2}|\/)*))?(?<![,.;])/';
+        }
         $result = preg_replace_callback($search, 'backup_process_filephp_uses', $result);
 
         foreach ($mypreferences->mods as $name => $info) {