|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00025 require_once($CFG->dirroot.'/backup/util/xml/parser/processors/grouped_parser_processor.class.php'); 00026 00036 class restore_structure_parser_processor extends grouped_parser_processor { 00037 00038 protected $courseid; // Course->id we are restoring to 00039 protected $step; // @restore_structure_step using this processor 00040 00041 public function __construct($courseid, $step) { 00042 $this->courseid = $courseid; 00043 $this->step = $step; 00044 parent::__construct(); 00045 } 00046 00050 public function process_cdata($cdata) { 00051 global $CFG; 00052 if ($cdata === '$@NULL@$') { // Some cases we know we can skip complete processing 00053 return null; 00054 } else if ($cdata === '') { 00055 return ''; 00056 } else if (is_numeric($cdata)) { 00057 return $cdata; 00058 } else if (strlen($cdata) < 32) { // Impossible to have one link in 32cc 00059 return $cdata; // (http://10.0.0.1/file.php/1/1.jpg, http://10.0.0.1/mod/url/view.php?id=) 00060 } else if (strpos($cdata, '$@FILEPHP@$') === false) { // No $@FILEPHP@$, nothing to convert 00061 return $cdata; 00062 } 00063 // Decode file.php calls 00064 $search = array ("$@FILEPHP@$"); 00065 $replace = array(get_file_url($this->courseid)); 00066 $result = str_replace($search, $replace, $cdata); 00067 // Now $@SLASH@$ and $@FORCEDOWNLOAD@$ MDL-18799 00068 $search = array('$@SLASH@$', '$@FORCEDOWNLOAD@$'); 00069 if ($CFG->slasharguments) { 00070 $replace = array('/', '?forcedownload=1'); 00071 } else { 00072 $replace = array('%2F', '&forcedownload=1'); 00073 } 00074 return str_replace($search, $replace, $result); 00075 } 00076 00084 protected function postprocess_chunk($data) { 00085 00086 // Iterate over all the data tags, if any of them is 00087 // not 'subplugin_XXXX' or has value, then it's a valid chunk, 00088 // pass it to standard (parent) processing of chunks. 00089 foreach ($data['tags'] as $key => $value) { 00090 if (trim($value) !== '' || strpos($key, 'subplugin_') !== 0) { 00091 parent::postprocess_chunk($data); 00092 return; 00093 } 00094 } 00095 // Arrived here, all the tags correspond to sublplugins and are empty, 00096 // skip the chunk, and debug_developer notice 00097 $this->chunks--; // not counted 00098 debugging('Missing support on restore for ' . clean_param($data['path'], PARAM_PATH) . 00099 ' subplugin (' . implode(', ', array_keys($data['tags'])) .')', DEBUG_DEVELOPER); 00100 } 00101 00102 protected function dispatch_chunk($data) { 00103 $this->step->process($data); 00104 } 00105 00106 protected function notify_path_start($path) { 00107 // nothing to do 00108 } 00109 00110 protected function notify_path_end($path) { 00111 // nothing to do 00112 } 00113 }