예제 #1
0
 public function get_topic_data($instance)
 {
     $topic_data = '';
     $namespaces = array('dt' => 'http://www.imsglobal.org/xsd/imsdt_v1p0');
     $topic_file = $this->get_external_xml($instance['resource_indentifier']);
     if (!empty($topic_file)) {
         $topic = $this->load_xml_resource(cc2moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $topic_file);
         if (!empty($topic)) {
             $xpath = cc2moodle::newx_path($topic, $namespaces);
             $topic_title = $xpath->query('/dt:topic/title');
             $topic_title = !empty($topic_title->item(0)->nodeValue) ? $topic_title->item(0)->nodeValue : '';
             $topic_text = $xpath->query('/dt:topic/text');
             $topic_text = !empty($topic_text->item(0)->nodeValue) ? $this->update_sources($topic_text->item(0)->nodeValue, dirname($topic_file)) : '';
             $topic_text = !empty($topic_text) ? str_replace("%24", "\$", $this->include_titles($topic_text)) : '';
             if (!empty($topic_title)) {
                 $topic_data['title'] = $topic_title;
                 $topic_data['description'] = $topic_text;
             }
         }
         $topic_attachments = $xpath->query('/dt:topic/attachments/attachment/@href');
         if ($topic_attachments->length > 0) {
             $attachment_html = '';
             foreach ($topic_attachments as $file) {
                 $attachment_html .= $this->generate_attachment_html($file->nodeValue);
             }
             $topic_data['description'] = !empty($attachment_html) ? $topic_text . '<p>Attachments:</p>' . $attachment_html : $topic_text;
         }
     }
     return $topic_data;
 }
 private function create_node_course_modules_mod_resource($sheet_mod_resource, $instance)
 {
     $link = '';
     $xpath = cc2moodle::newx_path(CC2Moodle::$manifest, CC2Moodle::$namespaces);
     if ($instance['common_cartriedge_type'] == CC_TYPE_WEBCONTENT || $instance['common_cartriedge_type'] == CC_TYPE_ASSOCIATED_CONTENT) {
         $resource = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@identifier="' . $instance['resource_indentifier'] . '"]/@href');
         $resource = !empty($resource->item(0)->nodeValue) ? $resource->item(0)->nodeValue : '';
         if (empty($resource)) {
             unset($resource);
             $resource = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@identifier="' . $instance['resource_indentifier'] . '"]/imscc:file/@href');
             $resource = !empty($resource->item(0)->nodeValue) ? $resource->item(0)->nodeValue : '';
         }
         if (!empty($resource)) {
             $link = $resource;
         }
     }
     if ($instance['common_cartriedge_type'] == 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(cc2moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $external_resource);
             if (!empty($resource)) {
                 $xpath = cc2moodle::newx_path($resource, $this->namespaces);
                 $resource = $xpath->query('/wl:webLink/url/@href');
                 $link = $resource->item(0)->nodeValue;
             }
         }
     }
     $find_tags = array('[#mod_instance#]', '[#mod_name#]', '[#mod_type#]', '[#mod_reference#]', '[#mod_summary#]', '[#mod_alltext#]', '[#date_now#]');
     $replace_values = array($instance['instance'], $instance['title'], 'file', $link, '', '', time());
     return str_replace($find_tags, $replace_values, $sheet_mod_resource);
 }
예제 #3
0
 public function get_basiclti_data($instance)
 {
     $topic_data = '';
     $basiclti_file = $this->get_external_xml($instance['resource_indentifier']);
     if (!empty($basiclti_file)) {
         $basiclti_file_path = cc2moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $basiclti_file;
         $basiclti_file_dir = dirname($basiclti_file_path);
         $basiclti = $this->load_xml_resource($basiclti_file_path);
         if (!empty($basiclti)) {
             $xpath = cc2moodle::newx_path($basiclti, cc112moodle::$basicltins);
             $topic_title = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:title'), 'Untitled');
             $blti_description = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:description'));
             $launch_url = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:launch_url'));
             $tool_raw = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:vendor/lticp:code'), null);
             $tool_url = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:vendor/lticp:url'), null);
             $tool_desc = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:vendor/lticp:description'), null);
             $topic_data['title'] = $topic_title;
             $topic_data['description'] = $blti_description;
             $topic_data['launchurl'] = $launch_url;
             $topic_data['orgid'] = $tool_raw;
             $topic_data['orgurl'] = $tool_url;
             $topic_data['orgdesc'] = $tool_desc;
         }
     }
     return $topic_data;
 }
예제 #4
0
 protected function get_all_files()
 {
     global $CFG;
     $all_files = array();
     $xpath = cc2moodle::newx_path(cc112moodle::$manifest, cc112moodle::$namespaces);
     foreach (cc112moodle::$restypes as $type) {
         $files = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@type="' . $type . '"]/imscc:file/@href');
         if (empty($files) || $files->length == 0) {
             continue;
         }
         foreach ($files as $file) {
             //omit html files
             //this is a bit too simplistic
             $ext = strtolower(pathinfo($file->nodeValue, PATHINFO_EXTENSION));
             if (in_array($ext, array('html', 'htm', 'xhtml'))) {
                 continue;
             }
             $all_files[] = $file;
         }
         unset($files);
     }
     //are there any labels?
     $xquery = "//imscc:item/imscc:item/imscc:item[imscc:title][not(@identifierref)]";
     $labels = $xpath->query($xquery);
     if (!empty($labels) && $labels->length > 0) {
         $tname = 'course_files';
         $dpath = cc2moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $tname;
         $fpath = $dpath . DIRECTORY_SEPARATOR . 'folder.gif';
         $rfpath = $tname . '/folder.gif';
         if (!file_exists($dpath)) {
             mkdir($dpath);
         }
         //copy the folder.gif file
         $folder_gif = "{$CFG->dirroot}/pix/f/folder.gif";
         copy($folder_gif, $fpath);
         $all_files[] = $rfpath;
     }
     $all_files = empty($all_files) ? '' : $all_files;
     return $all_files;
 }
예제 #5
0
 public function get_topic_data($instance)
 {
     $topic_data = '';
     $topic_file = $this->get_external_xml($instance['resource_indentifier']);
     if (!empty($topic_file)) {
         $topic_file_path = cc2moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $topic_file;
         $topic_file_dir = dirname($topic_file_path);
         $topic = $this->load_xml_resource($topic_file_path);
         if (!empty($topic)) {
             $xpath = cc2moodle::newx_path($topic, cc112moodle::$forumns);
             $topic_title = $xpath->query('/dt:topic/dt:title');
             if ($topic_title->length > 0 && !empty($topic_title->item(0)->nodeValue)) {
                 $topic_title = $topic_title->item(0)->nodeValue;
             } else {
                 $topic_title = 'Untitled Topic';
             }
             $topic_text = $xpath->query('/dt:topic/dt:text');
             $topic_text = !empty($topic_text->item(0)->nodeValue) ? $this->update_sources($topic_text->item(0)->nodeValue, dirname($topic_file)) : '';
             $topic_text = !empty($topic_text) ? str_replace("%24", "\$", $this->include_titles($topic_text)) : '';
             if (!empty($topic_title)) {
                 $topic_data['title'] = $topic_title;
                 $topic_data['description'] = $topic_text;
             }
         }
         $topic_attachments = $xpath->query('/dt:topic/dt:attachments/dt:attachment/@href');
         if ($topic_attachments->length > 0) {
             $attachment_html = '';
             foreach ($topic_attachments as $file) {
                 $attachment_html .= $this->generate_attachment_html($this->full_path($file->nodeValue, '/'));
             }
             $topic_data['description'] = !empty($attachment_html) ? $topic_text . '<p>Attachments:</p>' . $attachment_html : $topic_text;
         }
     }
     return $topic_data;
 }
예제 #6
0
 private function get_all_files()
 {
     $all_files = array();
     $xpath = cc2moodle::newx_path(cc2moodle::$manifest, cc2moodle::$namespaces);
     $types = array('associatedcontent/imscc_xmlv1p0/learning-application-resource', 'webcontent');
     foreach ($types as $type) {
         $files = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@type="' . $type . '"]/imscc:file/@href');
         if (!empty($files)) {
             foreach ($files as $file) {
                 $all_files[] = $file;
             }
         }
         unset($files);
     }
     $all_files = empty($all_files) ? '' : $all_files;
     return $all_files;
 }
예제 #7
0
 private function get_question_type($identifier, $assessment)
 {
     $xpath = cc2moodle::newx_path($assessment, cc2moodle::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;
 }
예제 #8
0
 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 = cc2moodle::newx_path(cc2moodle::$manifest, cc2moodle::$namespaces);
     if ($instance['common_cartriedge_type'] == cc2moodle::CC_TYPE_WEBCONTENT || $instance['common_cartriedge_type'] == cc2moodle::CC_TYPE_ASSOCIATED_CONTENT) {
         $resource = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@identifier="' . $instance['resource_indentifier'] . '"]/@href');
         $resource = !empty($resource->item(0)->nodeValue) ? $resource->item(0)->nodeValue : '';
         if (empty($resource)) {
             unset($resource);
             $resource = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@identifier="' . $instance['resource_indentifier'] . '"]/imscc:file/@href');
             $resource = !empty($resource->item(0)->nodeValue) ? $resource->item(0)->nodeValue : '';
         }
         if (!empty($resource)) {
             $link = $resource;
         }
     }
     if ($instance['common_cartriedge_type'] == cc2moodle::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(cc2moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $external_resource);
             if (!empty($resource)) {
                 $xpath = cc2moodle::newx_path($resource, cc2moodle::getresourcens());
                 $resource = $xpath->query('//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'] == cc2moodle::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 = '';
                 //TODO: try to handle embedded resources
                 /**
                  * images, linked static resources, applets, videos
                  */
                 $doc = new DOMDocument();
                 $cdir = getcwd();
                 chdir($dirpath);
                 try {
                     if (!empty($mod_alltext) && $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_defaultgrade($assessment, $question_identifier)
 {
     $result = 1;
     $xpath = cc2moodle::newx_path($assessment, cc2moodle::getquizns());
     $query = '//xmlns:item[@ident="' . $question_identifier . '"]';
     $query .= '//xmlns:qtimetadatafield[xmlns:fieldlabel="cc_weighting"]/xmlns:fieldentry';
     $defgrade = $xpath->query($query);
     if (!empty($defgrade) && $defgrade->length > 0) {
         $resp = (int) $defgrade->item(0)->nodeValue;
         if ($resp >= 0 && $resp <= 99) {
             $result = $resp;
         }
     }
     return $result;
 }