From 34adfa0f5cc75862091660cc77be8b796d8d29bc Mon Sep 17 00:00:00 2001 From: gbateson Date: Tue, 25 Aug 2009 01:28:51 +0000 Subject: [PATCH] add hotpot_encode_content_links() and hotpot_decode_content_links() to HotPot's backuplib.php and restorelib.php respectively --- mod/hotpot/backuplib.php | 10 ++++++++++ mod/hotpot/restorelib.php | 42 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/mod/hotpot/backuplib.php b/mod/hotpot/backuplib.php index 5bd499706ae..d3d9a8af8b9 100644 --- a/mod/hotpot/backuplib.php +++ b/mod/hotpot/backuplib.php @@ -334,4 +334,14 @@ } 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); + } ?> diff --git a/mod/hotpot/restorelib.php b/mod/hotpot/restorelib.php index 5f3fc394b70..6a1aa8c49be 100644 --- a/mod/hotpot/restorelib.php +++ b/mod/hotpot/restorelib.php @@ -484,4 +484,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"; +} ?>