add hotpot_encode_content_links() and hotpot_decode_content_links() to HotPot's backu...
authorgbateson <gbateson>
Tue, 25 Aug 2009 01:28:51 +0000 (01:28 +0000)
committergbateson <gbateson>
Tue, 25 Aug 2009 01:28:51 +0000 (01:28 +0000)
mod/hotpot/backuplib.php
mod/hotpot/restorelib.php

index 5bd499706ae620e218a1d58d3112ce9d491a7b21..d3d9a8af8b9ebd403b69c279b180aa805cced1b6 100644 (file)
         }
         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);
+    }
 ?>
index 5f3fc394b702a9dde396435e83860a0cb7ae365f..6a1aa8c49bee2c848ea00cdc7e93a25ad29422a0 100644 (file)
@@ -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";
+}
 ?>