From 5b6d8a05f427bc0f8a71f0cabf958fce0c6478fa Mon Sep 17 00:00:00 2001 From: Darko Miletic Date: Wed, 8 Feb 2012 16:11:59 -0300 Subject: [PATCH] MDL-31562: Implemented support for exporting labels, minor additional cleanups --- backup/cc/cc_includes.php | 1 + backup/cc/cc_lib/cc_asssesment.php | 2 +- backup/cc/cc_lib/cc_basiclti.php | 8 ++--- backup/cc/cc_lib/cc_converter_label.php | 39 +++++++++++++++++++++++++ backup/cc/cc_lib/cc_forum.php | 4 +-- backup/cc/cc_lib/cc_page.php | 4 +-- backup/cc/cc_lib/cc_weblink.php | 2 +- backup/cc/cc_lib/xmlbase.php | 12 ++++++++ 8 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 backup/cc/cc_lib/cc_converter_label.php diff --git a/backup/cc/cc_includes.php b/backup/cc/cc_includes.php index bd3369c5003..9b1a9bd9349 100644 --- a/backup/cc/cc_includes.php +++ b/backup/cc/cc_includes.php @@ -39,4 +39,5 @@ require_once($CFG->dirroot .'/backup/cc/cc_lib/cc_converter_url.php'); require_once($CFG->dirroot .'/backup/cc/cc_lib/cc_converter_resource.php'); require_once($CFG->dirroot .'/backup/cc/cc_lib/cc_converter_quiz.php'); require_once($CFG->dirroot .'/backup/cc/cc_lib/cc_converter_page.php'); +require_once($CFG->dirroot .'/backup/cc/cc_lib/cc_converter_label.php'); require_once($CFG->dirroot .'/backup/cc/cc_lib/cc_convert_moodle2.php'); diff --git a/backup/cc/cc_lib/cc_asssesment.php b/backup/cc/cc_lib/cc_asssesment.php index d3d7c7b9e1c..3e3af90f296 100644 --- a/backup/cc/cc_lib/cc_asssesment.php +++ b/backup/cc/cc_lib/cc_asssesment.php @@ -1821,7 +1821,7 @@ class assesment1_resurce_file extends general_cc_file { } public function set_title($value) { - $this->assessment_title = $value; + $this->assessment_title = self::safexml($value); } protected function on_save() { diff --git a/backup/cc/cc_lib/cc_basiclti.php b/backup/cc/cc_lib/cc_basiclti.php index 1e2881d7fe2..d31e0b886af 100644 --- a/backup/cc/cc_lib/cc_basiclti.php +++ b/backup/cc/cc_lib/cc_basiclti.php @@ -55,10 +55,10 @@ class basicltil1_resurce_file extends general_cc_file { protected $cartridge_icon = null; public function set_title($title) { - $this->title = $title; + $this->title = self::safexml($title); } public function set_description($description) { - $this->description = $description; + $this->description = self::safexml($description); } public function set_launch_url ($url) { $this->launch_url = $url; @@ -77,11 +77,11 @@ class basicltil1_resurce_file extends general_cc_file { $this->vendor = true; } public function set_vendor_name ($name) { - $this->vendor_name = $name; + $this->vendor_name = self::safexml($name); $this->vendor = true; } public function set_vendor_description ($desc) { - $this->vendor_description = $desc; + $this->vendor_description = self::safexml($desc); $this->vendor = true; } public function set_vendor_url ($url) { diff --git a/backup/cc/cc_lib/cc_converter_label.php b/backup/cc/cc_lib/cc_converter_label.php new file mode 100644 index 00000000000..21a47ae6bbb --- /dev/null +++ b/backup/cc/cc_lib/cc_converter_label.php @@ -0,0 +1,39 @@ +. +/** + * @package backup-convert + * @subpackage cc-library + * @copyright 2012 Darko Miletic + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once 'cc_converters.php'; +require_once 'cc_general.php'; + +class cc_converter_label extends cc_converter { + + public function __construct(cc_i_item &$item, cc_i_manifest &$manifest, $rootpath, $path){ + $this->defaultfile = 'label.xml'; + parent::__construct($item, $manifest, $rootpath, $path); + } + + public function convert($outdir) { + $resitem = new cc_item(); + $resitem->title = $this->doc->nodeValue('/activity/label/name'); + $this->item->add_child_item($resitem); + return true; + } +} \ No newline at end of file diff --git a/backup/cc/cc_lib/cc_forum.php b/backup/cc/cc_lib/cc_forum.php index 27ec08eefa4..81ec9c0aad7 100644 --- a/backup/cc/cc_lib/cc_forum.php +++ b/backup/cc/cc_lib/cc_forum.php @@ -37,11 +37,11 @@ class forum1_resurce_file extends general_cc_file { protected $attachments = array(); public function set_title($title) { - $this->title = $title; + $this->title = self::safexml($title); } public function set_text($text, $type='text/plain') { - $this->text = $text; + $this->text = self::safexml($text); $this->text_type = $type; } diff --git a/backup/cc/cc_lib/cc_page.php b/backup/cc/cc_lib/cc_page.php index 1da15a8b25a..af9fd98bcd2 100644 --- a/backup/cc/cc_lib/cc_page.php +++ b/backup/cc/cc_lib/cc_page.php @@ -35,11 +35,11 @@ class page11_resurce_file extends general_cc_file { } public function set_title($value) { - $this->title = $value; + $this->title = self::safexml($value); } public function set_intro($value) { - $this->intro = htmlspecialchars(strip_tags($value), ENT_COMPAT, 'UTF-8', false); + $this->intro = self::safexml(strip_tags($value)); } protected function on_create() { diff --git a/backup/cc/cc_lib/cc_weblink.php b/backup/cc/cc_lib/cc_weblink.php index db68fa2dd82..c1175665ca3 100644 --- a/backup/cc/cc_lib/cc_weblink.php +++ b/backup/cc/cc_lib/cc_weblink.php @@ -44,7 +44,7 @@ class url1_resurce_file extends general_cc_file { * @param string $title */ public function set_title($title) { - $this->title = htmlentities($title); + $this->title = self::safexml($title); } /** diff --git a/backup/cc/cc_lib/xmlbase.php b/backup/cc/cc_lib/xmlbase.php index 69be6840e8e..c85cbe906bf 100644 --- a/backup/cc/cc_lib/xmlbase.php +++ b/backup/cc/cc_lib/xmlbase.php @@ -41,6 +41,18 @@ class XMLGenericDocument { private $is_html = false; + /** + * @param string $value + * @return string + */ + public static function safexml($value) { + $result = htmlspecialchars(html_entity_decode($value, ENT_QUOTES, 'UTF-8'), + ENT_NOQUOTES, + 'UTF-8', + false); + return $result; + } + function __construct($ch = 'UTF-8',$validatenow=true){ $this->charset = $ch; $this->documentInit();