Skip to content
Browse files

MDL-30435: updated xpath query for CC 1.0 and improved url validity

detection
  • Loading branch information...
1 parent 79b0fec commit adf8f7a172a14a0d625aae00f035a6fccce9ed40 Darko Miletic committed Nov 24, 2011
Showing with 30 additions and 4 deletions.
  1. +16 −3 backup/cc/entity.resource.class.php
  2. +14 −1 backup/cc/entity11.resource.class.php
View
19 backup/cc/entity.resource.class.php
@@ -43,6 +43,9 @@ public function generate_node () {
}
private function create_node_course_modules_mod_resource ($sheet_mod_resource, $instance) {
+ global $CFG;
+
+ require_once($CFG->libdir.'/validateurlsyntax.php');
$link = '';
$mod_alltext = '';
@@ -77,9 +80,19 @@ private function create_node_course_modules_mod_resource ($sheet_mod_resource, $
if (!empty($resource)) {
$xpath = cc2moodle::newx_path($resource, cc2moodle::getresourcens());
- $resource = $xpath->query('/wl:webLink/wl:url/@href');
+ $resource = $xpath->query('//url/@href');
if ($resource->length > 0) {
- $link = $resource->item(0)->nodeValue;
+ $rawlink = $resource->item(0)->nodeValue;
+ if (!validateUrlSyntax($rawlink, 's+')) {
+ $changed = rawurldecode($rawlink);
+ if (validateUrlSyntax($changed, 's+')) {
+ $link = $changed;
+ } else {
+ $link = 'http://invalidurldetected/';
+ }
+ } else {
+ $link = $rawlink;
+ }
}
}
}
@@ -98,7 +111,7 @@ private function create_node_course_modules_mod_resource ($sheet_mod_resource, $
$mod_options = 'objectframe';
$mod_reference = $link;
//detected if we are dealing with html file
- if (!empty($link) && ($instance['common_cartriedge_type'] == cc112moodle::CC_TYPE_WEBCONTENT)) {
+ if (!empty($link) && ($instance['common_cartriedge_type'] == cc2moodle::CC_TYPE_WEBCONTENT)) {
$ext = strtolower(pathinfo($link, PATHINFO_EXTENSION));
if (in_array($ext, array('html', 'htm', 'xhtml'))) {
$mod_type = 'html';
View
15 backup/cc/entity11.resource.class.php
@@ -43,6 +43,9 @@ public function generate_node () {
}
private function create_node_course_modules_mod_resource ($sheet_mod_resource, $instance) {
+ global $CFG;
+
+ require_once($CFG->libdir.'/validateurlsyntax.php');
$link = '';
$mod_alltext = '';
@@ -87,7 +90,17 @@ private function create_node_course_modules_mod_resource ($sheet_mod_resource, $
$xpath = cc112moodle::newx_path($resource, cc112moodle::$resourcens);
$resource = $xpath->query('/wl:webLink/wl:url/@href');
if ($resource->length > 0) {
- $link = $resource->item(0)->nodeValue;
+ $rawlink = $resource->item(0)->nodeValue;
+ if (!validateUrlSyntax($rawlink, 's+')) {
+ $changed = rawurldecode($rawlink);
+ if (validateUrlSyntax($changed, 's+')) {
+ $link = $changed;
+ } else {
+ $link = 'http://invalidurldetected/';
+ }
+ } else {
+ $link = $rawlink;
+ }
}
}
}

0 comments on commit adf8f7a

Please sign in to comment.
Something went wrong with that request. Please try again.