Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Description of book backup task
  19   *
  20   * @package    mod_book
  21   * @copyright  2010-2011 Petr Skoda {@link http://skodak.org}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die;
  26  
  27  require_once($CFG->dirroot.'/mod/book/backup/moodle2/backup_book_stepslib.php');    // Because it exists (must)
  28  require_once($CFG->dirroot.'/mod/book/backup/moodle2/backup_book_settingslib.php'); // Because it exists (optional)
  29  
  30  class backup_book_activity_task extends backup_activity_task {
  31  
  32      /**
  33       * Define (add) particular settings this activity can have
  34       *
  35       * @return void
  36       */
  37      protected function define_my_settings() {
  38          // No particular settings for this activity
  39      }
  40  
  41      /**
  42       * Define (add) particular steps this activity can have
  43       *
  44       * @return void
  45       */
  46      protected function define_my_steps() {
  47          // book only has one structure step
  48          $this->add_step(new backup_book_activity_structure_step('book_structure', 'book.xml'));
  49      }
  50  
  51      /**
  52       * Code the transformations to perform in the activity in
  53       * order to get transportable (encoded) links
  54       *
  55       * @param string $content
  56       * @return string encoded content
  57       */
  58      static public function encode_content_links($content) {
  59          global $CFG;
  60  
  61          $base = preg_quote($CFG->wwwroot, "/");
  62  
  63          // Link to the list of books
  64          $search  = "/($base\/mod\/book\/index.php\?id=)([0-9]+)/";
  65          $content = preg_replace($search, '$@BOOKINDEX*$2@$', $content);
  66  
  67          // Link to book view by moduleid
  68          $search  = "/($base\/mod\/book\/view.php\?id=)([0-9]+)(&|&amp;)chapterid=([0-9]+)/";
  69          $content = preg_replace($search, '$@BOOKVIEWBYIDCH*$2*$4@$', $content);
  70  
  71          $search  = "/($base\/mod\/book\/view.php\?id=)([0-9]+)/";
  72          $content = preg_replace($search, '$@BOOKVIEWBYID*$2@$', $content);
  73  
  74          // Link to book view by bookid
  75          $search  = "/($base\/mod\/book\/view.php\?b=)([0-9]+)(&|&amp;)chapterid=([0-9]+)/";
  76          $content = preg_replace($search, '$@BOOKVIEWBYBCH*$2*$4@$', $content);
  77  
  78          $search  = "/($base\/mod\/book\/view.php\?b=)([0-9]+)/";
  79          $content = preg_replace($search, '$@BOOKVIEWBYB*$2@$', $content);
  80  
  81          return $content;
  82      }
  83  }