/mod/lesson/backup/moodle2/backup_lesson_activity_task.class.php

https://bitbucket.org/kudutest1/moodlegit · PHP · 111 lines · 42 code · 19 blank · 50 comment · 1 complexity · e8a8e3bba677bce726f7034334da0c22 MD5 · raw file

  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. * This file contains the backup task for the lesson module
  18. *
  19. * @package mod_lesson
  20. * @category backup
  21. * @copyright 2010 Sam Hemelryk
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. require_once($CFG->dirroot . '/mod/lesson/backup/moodle2/backup_lesson_stepslib.php');
  26. /**
  27. * Provides the steps to perform one complete backup of the Lesson instance
  28. *
  29. * @copyright 2010 Sam Hemelryk
  30. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31. */
  32. class backup_lesson_activity_task extends backup_activity_task {
  33. /**
  34. * No specific settings for this activity
  35. */
  36. protected function define_my_settings() {
  37. }
  38. /**
  39. * Defines a backup step to store the instance data in the lesson.xml file
  40. */
  41. protected function define_my_steps() {
  42. $this->add_step(new backup_lesson_activity_structure_step('lesson structure', 'lesson.xml'));
  43. }
  44. /**
  45. * Encodes URLs to various Lesson scripts
  46. *
  47. * @param string $content some HTML text that eventually contains URLs to the activity instance scripts
  48. * @return string the content with the URLs encoded
  49. */
  50. static public function encode_content_links($content) {
  51. global $CFG;
  52. $base = preg_quote($CFG->wwwroot.'/mod/lesson','#');
  53. // Provides the interface for overall authoring of lessons
  54. $pattern = '#'.$base.'/edit\.php\?id=([0-9]+)#';
  55. $replacement = '$@LESSONEDIT*$1@$';
  56. $content = preg_replace($pattern, $replacement, $content);
  57. // Action for adding a question page. Prints an HTML form.
  58. $pattern = '#'.$base.'/editpage\.php\?id=([0-9]+)&(amp;)?pageid=([0-9]+)#';
  59. $replacement = '$@LESSONEDITPAGE*$1*$3@$';
  60. $content = preg_replace($pattern, $replacement, $content);
  61. // Provides the interface for grading essay questions
  62. $pattern = '#'.$base.'/essay\.php\?id=([0-9]+)#';
  63. $replacement = '$@LESSONESSAY*$1@$';
  64. $content = preg_replace($pattern, $replacement, $content);
  65. // Provides the interface for viewing and adding high scores
  66. $pattern = '#'.$base.'/highscores\.php\?id=([0-9]+)#';
  67. $replacement = '$@LESSONHIGHSCORES*$1@$';
  68. $content = preg_replace($pattern, $replacement, $content);
  69. // Provides the interface for viewing the report
  70. $pattern = '#'.$base.'/report\.php\?id=([0-9]+)#';
  71. $replacement = '$@LESSONREPORT*$1@$';
  72. $content = preg_replace($pattern, $replacement, $content);
  73. // This file plays the mediafile set in lesson settings.
  74. $pattern = '#'.$base.'/mediafile\.php\?id=([0-9]+)#';
  75. $replacement = '$@LESSONMEDIAFILE*$1@$';
  76. $content = preg_replace($pattern, $replacement, $content);
  77. // This page lists all the instances of lesson in a particular course
  78. $pattern = '#'.$base.'/index\.php\?id=([0-9]+)#';
  79. $replacement = '$@LESSONINDEX*$1@$';
  80. $content = preg_replace($pattern, $replacement, $content);
  81. // This page prints a particular page of lesson
  82. $pattern = '#'.$base.'/view\.php\?id=([0-9]+)&(amp;)?pageid=([0-9]+)#';
  83. $replacement = '$@LESSONVIEWPAGE*$1*$3@$';
  84. $content = preg_replace($pattern, $replacement, $content);
  85. // Link to one lesson by cmid
  86. $pattern = '#'.$base.'/view\.php\?id=([0-9]+)#';
  87. $replacement = '$@LESSONVIEWBYID*$1@$';
  88. $content = preg_replace($pattern, $replacement, $content);
  89. // Return the now encoded content
  90. return $content;
  91. }
  92. }