Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   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_url_activity_task class
  20   *
  21   * @package     mod_url
  22   * @category    backup
  23   * @copyright   2010 onwards Andrew Davis
  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/url/backup/moodle2/backup_url_stepslib.php');
  30  
  31  /**
  32   * Provides all the settings and steps to perform one complete backup of the activity
  33   */
  34  class backup_url_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 url.xml file
  44       */
  45      protected function define_my_steps() {
  46          $this->add_step(new backup_url_activity_structure_step('url_structure', 'url.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      static public function encode_content_links($content) {
  56          global $CFG;
  57  
  58          $base = preg_quote($CFG->wwwroot.'/mod/url','#');
  59  
  60          //Access a list of all links in a course
  61          $pattern = '#('.$base.'/index\.php\?id=)([0-9]+)#';
  62          $replacement = '$@URLINDEX*$2@$';
  63          $content = preg_replace($pattern, $replacement, $content);
  64  
  65          //Access the link supplying a course module id
  66          $pattern = '#('.$base.'/view\.php\?id=)([0-9]+)#';
  67          $replacement = '$@URLVIEWBYID*$2@$';
  68          $content = preg_replace($pattern, $replacement, $content);
  69  
  70          //Access the link supplying an instance id
  71          $pattern = '#('.$base.'/view\.php\?u=)([0-9]+)#';
  72          $replacement = '$@URLVIEWBYU*$2@$';
  73          $content = preg_replace($pattern, $replacement, $content);
  74  
  75          return $content;
  76      }
  77  }