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

detection
This commit is contained in:
Darko Miletic
2011-11-24 17:42:16 -03:00
parent 79b0fece1f
commit adf8f7a172
2 changed files with 30 additions and 4 deletions
+16 -3
View File
@@ -43,6 +43,9 @@ class cc_resource extends entities {
}
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 @@ class cc_resource extends entities {
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 @@ class cc_resource extends entities {
$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';
+14 -1
View File
@@ -43,6 +43,9 @@ class cc11_resource extends entities11 {
}
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 @@ class cc11_resource extends entities11 {
$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;
}
}
}
}