| 1 | efrain | 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 |  * Defines backup_data_activity_task
 | 
        
           |  |  | 20 |  *
 | 
        
           |  |  | 21 |  * @package     mod_data
 | 
        
           |  |  | 22 |  * @category    backup
 | 
        
           |  |  | 23 |  * @copyright   2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
 | 
        
           |  |  | 24 |  * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 25 |  */
 | 
        
           |  |  | 26 |   | 
        
           |  |  | 27 | defined('MOODLE_INTERNAL') || die();
 | 
        
           |  |  | 28 |   | 
        
           |  |  | 29 | require_once($CFG->dirroot . '/mod/data/backup/moodle2/backup_data_stepslib.php');
 | 
        
           |  |  | 30 |   | 
        
           |  |  | 31 | /**
 | 
        
           |  |  | 32 |  * Provides the steps to perform one complete backup of the Database instance
 | 
        
           |  |  | 33 |  */
 | 
        
           |  |  | 34 | class backup_data_activity_task extends backup_activity_task {
 | 
        
           |  |  | 35 |   | 
        
           |  |  | 36 |     /**
 | 
        
           |  |  | 37 |      * No specific settings for this activity
 | 
        
           |  |  | 38 |      */
 | 
        
           |  |  | 39 |     protected function define_my_settings() {
 | 
        
           |  |  | 40 |     }
 | 
        
           |  |  | 41 |   | 
        
           |  |  | 42 |     /**
 | 
        
           |  |  | 43 |      * Defines a backup step to store the instance data in the data.xml file
 | 
        
           |  |  | 44 |      */
 | 
        
           |  |  | 45 |     protected function define_my_steps() {
 | 
        
           |  |  | 46 |         $this->add_step(new backup_data_activity_structure_step('data_structure', 'data.xml'));
 | 
        
           |  |  | 47 |     }
 | 
        
           |  |  | 48 |   | 
        
           |  |  | 49 |     /**
 | 
        
           |  |  | 50 |      * Encodes URLs to the index.php and view.php scripts
 | 
        
           |  |  | 51 |      *
 | 
        
           |  |  | 52 |      * @param string $content some HTML text that eventually contains URLs to the activity instance scripts
 | 
        
           |  |  | 53 |      * @return string the content with the URLs encoded
 | 
        
           |  |  | 54 |      */
 | 
        
           |  |  | 55 |     public static function encode_content_links($content) {
 | 
        
           |  |  | 56 |         global $CFG;
 | 
        
           |  |  | 57 |   | 
        
           |  |  | 58 |         $base = preg_quote($CFG->wwwroot,"/");
 | 
        
           | 1441 | ariadna | 59 |         $baseunquoted = $CFG->wwwroot;
 | 
        
           | 1 | efrain | 60 |   | 
        
           | 1441 | ariadna | 61 |         // Link to the list of datas.
 | 
        
           |  |  | 62 |         $search = '/(' . $base . '\/mod\/data\/index.php\?id\=)([0-9]+)/';
 | 
        
           |  |  | 63 |         $content = preg_replace($search, '$@DATAINDEX*$2@$', $content);
 | 
        
           | 1 | efrain | 64 |   | 
        
           | 1441 | ariadna | 65 |         // Link to the list of datas, urlencoded.
 | 
        
           |  |  | 66 |         $search = '/(' . urlencode($baseunquoted . '/mod/data/index.php?id=') . ')([0-9]+)/';
 | 
        
           |  |  | 67 |         $content = preg_replace($search, '$@DATAINDEXURLENCODED*$2@$', $content);
 | 
        
           | 1 | efrain | 68 |   | 
        
           | 1441 | ariadna | 69 |         // Link to data view by moduleid.
 | 
        
           |  |  | 70 |         $search = '/(' . $base . '\/mod\/data\/view.php\?id\=)([0-9]+)/';
 | 
        
           |  |  | 71 |         $content = preg_replace($search, '$@DATAVIEWBYID*$2@$', $content);
 | 
        
           | 1 | efrain | 72 |   | 
        
           | 1441 | ariadna | 73 |         // Link to data view by moduleid, urlencoded.
 | 
        
           |  |  | 74 |         $search = '/(' . urlencode($baseunquoted . '/mod/data/view.php?id=') . ')([0-9]+)/';
 | 
        
           |  |  | 75 |         $content = preg_replace($search, '$@DATAVIEWBYIDURLENCODED*$2@$', $content);
 | 
        
           | 1 | efrain | 76 |   | 
        
           | 1441 | ariadna | 77 |         // Link to one "record" of the database.
 | 
        
           |  |  | 78 |         $search = '/(' . $base . '\/mod\/data\/view.php\?d\=)([0-9]+)\&(amp;)rid\=([0-9]+)/';
 | 
        
           |  |  | 79 |         $content = preg_replace($search, '$@DATAVIEWRECORD*$2*$4@$', $content);
 | 
        
           |  |  | 80 |   | 
        
           |  |  | 81 |         // Link to one "record" of the database, urlencoded.
 | 
        
           |  |  | 82 |         $search = '/(' . urlencode($baseunquoted . '/mod/data/view.php?d=') . ')([0-9]+)%26rid%3D([0-9]+)/';
 | 
        
           |  |  | 83 |         $content = preg_replace($search, '$@DATAVIEWRECORDURLENCODED*$2*$3@$', $content);
 | 
        
           |  |  | 84 |   | 
        
           |  |  | 85 |         // Link to database view by databaseid.
 | 
        
           |  |  | 86 |         $search = '/(' . $base . '\/mod\/data\/view.php\?d\=)([0-9]+)/';
 | 
        
           |  |  | 87 |         $content = preg_replace($search, '$@DATAVIEWBYD*$2@$', $content);
 | 
        
           |  |  | 88 |   | 
        
           |  |  | 89 |         // Link to database view by databaseid, urlencoded.
 | 
        
           |  |  | 90 |         $search = '/(' . urlencode($baseunquoted . '/mod/data/view.php?d=') . ')([0-9]+)/';
 | 
        
           |  |  | 91 |         $content = preg_replace($search, '$@DATAVIEWBYDURLENCODED*$2@$', $content);
 | 
        
           |  |  | 92 |   | 
        
           |  |  | 93 |         // Link to the edit page.
 | 
        
           |  |  | 94 |         $search = '/(' . $base . '\/mod\/data\/edit.php\?id\=)([0-9]+)/';
 | 
        
           |  |  | 95 |         $content = preg_replace($search, '$@DATAEDITBYID*$2@$', $content);
 | 
        
           |  |  | 96 |   | 
        
           |  |  | 97 |         // Link to the edit page, urlencoded.
 | 
        
           |  |  | 98 |         $search = '/(' . urlencode($baseunquoted . '/mod/data/edit.php?id=') . ')([0-9]+)/';
 | 
        
           |  |  | 99 |         $content = preg_replace($search, '$@DATAEDITBYIDURLENCODED*$2@$', $content);
 | 
        
           |  |  | 100 |   | 
        
           |  |  | 101 |         // Link to the edit page by databaseid.
 | 
        
           |  |  | 102 |         $search = '/(' . $base . '\/mod\/data\/edit.php\?d\=)([0-9]+)/';
 | 
        
           |  |  | 103 |         $content = preg_replace($search, '$@DATAEDITBYD*$2@$', $content);
 | 
        
           |  |  | 104 |   | 
        
           |  |  | 105 |         // Link to the edit page by databaseid, urlencoded.
 | 
        
           |  |  | 106 |         $search = '/(' . urlencode($baseunquoted . '/mod/data/edit.php?d=') . ')([0-9]+)/';
 | 
        
           |  |  | 107 |         $content = preg_replace($search, '$@DATAEDITBYDURLENCODED*$2@$', $content);
 | 
        
           |  |  | 108 |   | 
        
           | 1 | efrain | 109 |         return $content;
 | 
        
           |  |  | 110 |     }
 | 
        
           |  |  | 111 | }
 |