Permalink
Browse files

add hotpot_encode_content_links() and hotpot_decode_content_links() t…

…o HotPot's backuplib.php and restorelib.php respectively
  • Loading branch information...
1 parent a21aa86 commit ff2294aa8ca41deafbe6b8c9e2a371d7ab94866f gbateson committed Aug 25, 2009
Showing with 52 additions and 0 deletions.
  1. +10 −0 mod/hotpot/backuplib.php
  2. +42 −0 mod/hotpot/restorelib.php
View
@@ -324,4 +324,14 @@ function hotpot_check_backup_mods_instances($instance,$backup_unique_code) {
}
return $info;
}
+
+ // Return content encoded to support interactivities linking.
+ // Called by "backup_encode_absolute_links()" in backup/backuplib.php
+ // Content will be decoded by "hotpot_decode_content_links()"
+ function hotpot_encode_content_links ($content, $preferences) {
+ global $CFG;
+ $base = preg_quote("$CFG->wwwroot/mod/hotpot/", '/');
+ $search = "/($base)([a-z]+).php\?([a-z]+)\=([0-9]+)/";
+ return preg_replace($search, '$@HOTPOT*$2*$3*$4@$', $content);
+ }
?>
View
@@ -480,4 +480,46 @@ function hotpot_restore_logs($restore, $log) {
} // end switch
return $status ? $log : false;
}
+
+function hotpot_decode_content_links($content, $restore) {
+ $search = '/\$@(HOTPOT)\*([a-z]+)\*([a-z]+)\*([0-9]+)@\$/ise';
+ $replace = 'hotpot_decode_content_link("$2", "$3", "$4", $restore)';
+ return preg_replace($search, $replace, $content);
+}
+
+function hotpot_decode_content_link($scriptname, $paramname, $paramvalue, &$restore) {
+ global $CFG;
+
+ $table = '';
+ switch ($paramname) {
+ case 'id':
+ switch ($scriptname) {
+ case 'index':
+ $table = 'course';
+ break;
+ case 'report':
+ case 'review':
+ case 'view':
+ $table = 'course_modules';
+ break;
+ case 'attempt':
+ $table = 'hotpot_attempts';
+ break;
+ }
+ break;
+ case 'hp':
+ case 'hotpotid':
+ $table = 'hotpot';
+ break;
+ }
+
+ $new_id = 0;
+ if ($table) {
+ if ($rec = backup_getid($restore->backup_unique_code, $table, $paramvalue)) {
+ $new_id = $rec->new_id;
+ }
+ }
+
+ return "$CFG->wwwroot/mod/hotpot/$scriptname.php?$paramname=$new_id";
+}
?>

0 comments on commit ff2294a

Please sign in to comment.