private function create_node_course_modules_mod_forum($instance) { $sheet_mod_forum = cc112moodle::loadsheet(SHEET_COURSE_SECTIONS_SECTION_MODS_MOD_FORUM); $topic_data = $this->get_topic_data($instance); $result = ''; if (!empty($topic_data)) { $find_tags = array('[#mod_instance#]', '[#mod_forum_title#]', '[#mod_forum_intro#]', '[#date_now#]'); $replace_values = array($instance['instance'], self::safexml($topic_data['title']), self::safexml($topic_data['description']), time()); $result = str_replace($find_tags, $replace_values, $sheet_mod_forum); } return $result; }
private function create_node_course_modules_mod_basiclti($instance) { $sheet_mod_basiclti = cc112moodle::loadsheet(SHEET_COURSE_SECTIONS_SECTION_MODS_MOD_BASICLTI); $topic_data = $this->get_basiclti_data($instance); $result = ''; if (!empty($topic_data)) { $find_tags = array('[#mod_instance#]', '[#mod_basiclti_name#]', '[#mod_basiclti_intro#]', '[#mod_basiclti_timec#]', '[#mod_basiclti_timem#]', '[#mod_basiclti_toolurl#]', '[#mod_basiclti_orgid#]', '[#mod_basiclti_orgurl#]', '[#mod_basiclti_orgdesc#]'); $replace_values = array($instance['instance'], $topic_data['title'], $topic_data['description'], time(), time(), $topic_data['launchurl'], $topic_data['orgid'], $topic_data['orgurl'], $topic_data['orgdesc']); $result = str_replace($find_tags, $replace_values, $sheet_mod_basiclti); } return $result; }
protected function execute() { global $CFG; $manifest = cc112moodle::get_manifest($this->get_tempdir_path()); if (empty($manifest)) { throw new imscc11_convert_exception('No Manifest detected!'); } $this->log('validating manifest', backup::LOG_DEBUG, null, 1); $validator = new manifest_validator($CFG->dirroot . '/backup/cc/schemas11'); if (!$validator->validate($manifest)) { $this->log('validation error(s): ' . PHP_EOL . error_messages::instance(), backup::LOG_DEBUG, null, 2); throw new imscc11_convert_exception(error_messages::instance()->to_string(true)); } $manifestdir = dirname($manifest); $cc112moodle = new cc112moodle($manifest); if ($cc112moodle->is_auth()) { throw new imscc11_convert_exception('protected_cc_not_supported'); } $status = $cc112moodle->generate_moodle_xml(); //Final cleanup $xml_error = new libxml_errors_mgr(true); $mdoc = new DOMDocument(); $mdoc->preserveWhiteSpace = false; $mdoc->formatOutput = true; $mdoc->validateOnParse = false; $mdoc->strictErrorChecking = false; if ($mdoc->load($manifestdir . '/moodle.xml', LIBXML_NONET)) { $mdoc->save($this->get_workdir_path() . '/moodle.xml', LIBXML_NOEMPTYTAG); } else { $xml_error->collect(); $this->log('validation error(s): ' . PHP_EOL . error_messages::instance(), backup::LOG_DEBUG, null, 2); throw new imscc11_convert_exception(error_messages::instance()->to_string(true)); } //Move the files to the workdir rename($manifestdir . '/course_files', $this->get_workdir_path() . '/course_files'); }
private function create_node_course_modules_mod_resource($sheet_mod_resource, $instance) { global $CFG; require_once $CFG->libdir . '/validateurlsyntax.php'; $link = ''; $mod_alltext = ''; $mod_summary = ''; $xpath = cc112moodle::newx_path(cc112moodle::$manifest, cc112moodle::$namespaces); if ($instance['common_cartriedge_type'] == cc112moodle::CC_TYPE_WEBCONTENT || $instance['common_cartriedge_type'] == cc112moodle::CC_TYPE_ASSOCIATED_CONTENT) { $resource = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@identifier="' . $instance['resource_indentifier'] . '"]/@href'); if ($resource->length > 0) { $resource = !empty($resource->item(0)->nodeValue) ? $resource->item(0)->nodeValue : ''; } else { $resource = ''; } if (empty($resource)) { unset($resource); $resource = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@identifier="' . $instance['resource_indentifier'] . '"]/imscc:file/@href'); if ($resource->length > 0) { $resource = !empty($resource->item(0)->nodeValue) ? $resource->item(0)->nodeValue : ''; } else { $resource = ''; } } if (!empty($resource)) { $link = $resource; } } if ($instance['common_cartriedge_type'] == cc112moodle::CC_TYPE_WEBLINK) { $external_resource = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@identifier="' . $instance['resource_indentifier'] . '"]/imscc:file/@href')->item(0)->nodeValue; if ($external_resource) { $resource = $this->load_xml_resource(cc112moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $external_resource); if (!empty($resource)) { $xpath = cc112moodle::newx_path($resource, cc112moodle::$resourcens); $resource = $xpath->query('/wl:webLink/wl:url/@href'); if ($resource->length > 0) { $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; } } } } } $find_tags = array('[#mod_instance#]', '[#mod_name#]', '[#mod_type#]', '[#mod_reference#]', '[#mod_summary#]', '[#mod_alltext#]', '[#mod_options#]', '[#date_now#]'); $mod_type = 'file'; $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) { $ext = strtolower(pathinfo($link, PATHINFO_EXTENSION)); if (in_array($ext, array('html', 'htm', 'xhtml'))) { $mod_type = 'html'; //extract the content of the file $rootpath = realpath(cc112moodle::$path_to_manifest_folder); $htmlpath = realpath($rootpath . DIRECTORY_SEPARATOR . $link); $dirpath = dirname($htmlpath); if (file_exists($htmlpath)) { $fcontent = file_get_contents($htmlpath); $mod_alltext = clean_param($this->prepare_content($fcontent), PARAM_CLEANHTML); $mod_reference = ''; $mod_options = ''; /** * try to handle embedded resources * images, linked static resources, applets, videos */ $doc = new DOMDocument(); $cdir = getcwd(); chdir($dirpath); try { $doc->loadHTML($mod_alltext); $xpath = new DOMXPath($doc); $attributes = array('href', 'src', 'background', 'archive', 'code'); $qtemplate = "//*[@##][not(contains(@##,'://'))]/@##"; $query = ''; foreach ($attributes as $attrname) { if (!empty($query)) { $query .= " | "; } $query .= str_replace('##', $attrname, $qtemplate); } $list = $xpath->query($query); $searches = array(); $replaces = array(); foreach ($list as $resrc) { $rpath = $resrc->nodeValue; $rtp = realpath($rpath); if ($rtp !== false && is_file($rtp)) { //file is there - we are in business $strip = str_replace("\\", "/", str_ireplace($rootpath, '', $rtp)); $encoded_file = '$@FILEPHP@$' . str_replace('/', '$@SLASH@$', $strip); $searches[] = $resrc->nodeValue; $replaces[] = $encoded_file; } } $mod_alltext = str_replace($searches, $replaces, $mod_alltext); } catch (Exception $e) { //silence the complaints } chdir($cdir); $mod_alltext = self::safexml($mod_alltext); } } } $replace_values = array($instance['instance'], self::safexml($instance['title']), $mod_type, $mod_reference, '', $mod_alltext, $mod_options, time()); return str_replace($find_tags, $replace_values, $sheet_mod_resource); }
private function get_question_type($identifier, $assessment) { $xpath = cc112moodle::newx_path($assessment, cc112moodle::getquizns()); $metadata = $xpath->query('//xmlns:item[@ident="' . $identifier . '"]/xmlns:itemmetadata/xmlns:qtimetadata/xmlns:qtimetadatafield'); foreach ($metadata as $field) { $field_label = $xpath->query('xmlns:fieldlabel', $field); $field_label = !empty($field_label->item(0)->nodeValue) ? $field_label->item(0)->nodeValue : ''; if ($field_label == 'cc_profile') { $field_entry = $xpath->query('xmlns:fieldentry', $field); $type = !empty($field_entry->item(0)->nodeValue) ? $field_entry->item(0)->nodeValue : ''; } } $return_type = array(); $return_type['moodle'] = ''; $return_type['cc'] = $type; if ($type == CC_QUIZ_MULTIPLE_CHOICE) { $return_type['moodle'] = MOODLE_QUIZ_MULTIPLE_CHOICE; } if ($type == CC_QUIZ_MULTIPLE_RESPONSE) { $return_type['moodle'] = MOODLE_QUIZ_MULTIPLE_CHOICE; } if ($type == CC_QUIZ_TRUE_FALSE) { $return_type['moodle'] = MOODLE_QUIZ_TRUE_FALSE; } if ($type == CC_QUIZ_ESSAY) { $return_type['moodle'] = MOODLE_QUIZ_ESSAY; } if ($type == CC_QUIZ_FIB) { $return_type['moodle'] = MOODLE_QUIZ_SHORTANSWER; } if ($type == CC_QUIZ_PATTERN_MACHT) { $return_type['moodle'] = MOODLE_QUIZ_SHORTANSWER; } return $return_type; }