[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * @package moodlecore 20 * @subpackage backup-helper 21 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 require_once($CFG->dirroot.'/backup/util/xml/parser/processors/grouped_parser_processor.class.php'); 26 27 /** 28 * helper implementation of grouped_parser_processor that will 29 * support the process of all the moodle2 backup files, with 30 * complete specs about what to load (grouped or no), dispatching 31 * to corresponding methods and basic decoding of contents 32 * (NULLs and legacy file.php uses) 33 * 34 * TODO: Complete phpdocs 35 */ 36 class restore_structure_parser_processor extends grouped_parser_processor { 37 38 protected $courseid; // Course->id we are restoring to 39 protected $step; // @restore_structure_step using this processor 40 41 public function __construct($courseid, $step) { 42 $this->courseid = $courseid; 43 $this->step = $step; 44 parent::__construct(); 45 } 46 47 /** 48 * Provide NULL and legacy file.php uses decoding 49 */ 50 public function process_cdata($cdata) { 51 global $CFG; 52 if ($cdata === '$@NULL@$') { // Some cases we know we can skip complete processing 53 return null; 54 } else if ($cdata === '') { 55 return ''; 56 } else if (is_numeric($cdata)) { 57 return $cdata; 58 } else if (strlen($cdata) < 32) { // Impossible to have one link in 32cc 59 return $cdata; // (http://10.0.0.1/file.php/1/1.jpg, http://10.0.0.1/mod/url/view.php?id=) 60 } else if (strpos($cdata, '$@FILEPHP@$') === false) { // No $@FILEPHP@$, nothing to convert 61 return $cdata; 62 } 63 // Decode file.php calls 64 $search = array ("$@FILEPHP@$"); 65 $replace = array(moodle_url::make_legacyfile_url($this->courseid, null)); 66 $result = str_replace($search, $replace, $cdata); 67 // Now $@SLASH@$ and $@FORCEDOWNLOAD@$ MDL-18799 68 $search = array('$@SLASH@$', '$@FORCEDOWNLOAD@$'); 69 if ($CFG->slasharguments) { 70 $replace = array('/', '?forcedownload=1'); 71 } else { 72 $replace = array('%2F', '&forcedownload=1'); 73 } 74 return str_replace($search, $replace, $result); 75 } 76 77 /** 78 * Override this method so we'll be able to skip 79 * dispatching some well-known chunks, like the 80 * ones being 100% part of subplugins stuff. Useful 81 * for allowing development without having all the 82 * possible restore subplugins defined 83 */ 84 protected function postprocess_chunk($data) { 85 86 // Iterate over all the data tags, if any of them is 87 // not 'subplugin_XXXX' or has value, then it's a valid chunk, 88 // pass it to standard (parent) processing of chunks. 89 foreach ($data['tags'] as $key => $value) { 90 if (trim($value) !== '' || strpos($key, 'subplugin_') !== 0) { 91 parent::postprocess_chunk($data); 92 return; 93 } 94 } 95 // Arrived here, all the tags correspond to sublplugins and are empty, 96 // skip the chunk, and debug_developer notice 97 $this->chunks--; // not counted 98 debugging('Missing support on restore for ' . clean_param($data['path'], PARAM_PATH) . 99 ' subplugin (' . implode(', ', array_keys($data['tags'])) .')', DEBUG_DEVELOPER); 100 } 101 102 protected function dispatch_chunk($data) { 103 $this->step->process($data); 104 } 105 106 protected function notify_path_start($path) { 107 // nothing to do 108 } 109 110 protected function notify_path_end($path) { 111 // nothing to do 112 } 113 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |