2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002 - 2009 */
6 /* Adaptive Technology Resource Centre / University of Toronto */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
14 if (!defined('AT_INCLUDE_PATH')) { exit; }
16 // This function gets files from html tag @import
17 function get_import_files($text)
19 $text = strtolower($text);
23 while (strpos(strtolower($text), strtolower($tag)) > 0)
25 $start_pos = strpos($text, $tag);
26 if ($start_pos !== false)
28 $text = substr($text, $start_pos);
29 $start_pos = strlen($tag);
30 $len = strpos($text, ';') - strlen($tag);
32 $file = substr(trim($text), $start_pos, $len);
34 // remove these characters from file name: url, (, ), ", '
35 $file = trim(preg_replace('/(\'|\"|url|\(|\))/', '', $file));
37 // strip processed tag
38 $text = substr($text, $start_pos);
39 array_push($files, $file);
47 function print_organizations($parent_id,
54 global $html_content_template, $default_html_style, $zipfile, $resources, $ims_template_xml, $parser, $my_files;
55 global $used_glossary_terms, $course_id, $course_language_charset, $course_language_code;
56 static $paths, $zipped_files;
58 global $test_zipped_files, $use_a4a, $db;
66 $top_level = $_menu[$parent_id];
67 if (!is_array($paths)) {
70 if (!is_array($zipped_files)) {
71 $zipped_files = array();
73 if ( is_array($top_level) ) {
76 $num_items = count($top_level);
78 foreach ($top_level as $garbage => $content) {
81 if ($content['content_path']) {
82 $content['content_path'] .= '/';
84 //if this is a folder, export it without identifierref
85 if ($content['content_type']==CONTENT_TYPE_FOLDER){
86 $link = $prevfix.'<item identifier="MANIFEST01_ITEM'.$content['content_id'].'">'."\n";
88 $link = $prevfix.'<item identifier="MANIFEST01_ITEM'.$content['content_id'].'" identifierref="MANIFEST01_RESOURCE'.$content['content_id'].'" parameters="'.htmlentities($content['test_message'], ENT_QUOTES, 'UTF-8').'">'."\n";
90 $html_link = '<a href="resources/'.$content['content_path'].$content['content_id'].'.html" target="body">'.$content['title'].'</a>';
92 /* save the content as HTML files */
93 /* @See: include/lib/format_content.inc.php */
94 $content['text'] = str_replace('CONTENT_DIR/', '', $content['text']);
95 /* get all the glossary terms used */
96 $terms = find_terms($content['text']);
97 if (is_array($terms)) {
98 foreach ($terms[2] as $term) {
99 $used_glossary_terms[] = $term;
103 /** Test dependency **/
104 $test_dependency = ''; //Template for test
105 $sql = 'SELECT * FROM '.TABLE_PREFIX.'content_tests_assoc WHERE content_id='.$content['content_id'];
106 $result = mysql_query($sql, $db);
107 while ($row = mysql_fetch_assoc($result)){
108 //add test dependency ontop to forums dependency
109 $test_dependency .= $prefix.$space.'<dependency identifierref="MANIFEST01_RESOURCE_QTI'.$row['test_id'].'" />';
112 /* calculate how deep this page is: */
114 if ($content['content_path']) {
115 $depth = substr_count($content['content_path'], '/');
117 $path .= str_repeat('../', $depth);
120 $content['text'] = format_content($content['text'], $content['formatting'], $glossary, $path);
122 /* add HTML header and footers to the files */
124 /* use default style if <style> is not in imported html head */
126 if ($content['use_customized_head'])
128 if (strpos(strtolower($content['head']), '<style') > 0)
130 $head = $content['head'];
134 if (strlen($content['head']) > 0)
135 $head = $content['head'] . $default_html_style;
137 $head = $default_html_style;
141 $content['text'] = str_replace( array('{TITLE}', '{CONTENT}', '{KEYWORDS}', '{COURSE_PRIMARY_LANGUAGE_CHARSET}', '{COURSE_PRIMARY_LANGUAGE_CODE}', '{HEAD}'),
142 array($content['title'], $content['text'], $content['keywords'], $course_language_charset, $course_language_code, $head),
143 $html_content_template);
145 /* duplicate the paths in the content_path field in the zip file */
146 if ($content['content_path']) {
147 if (!in_array($content['content_path'], $paths)) {
148 $zipfile->create_dir('resources/'.$content['content_path'], time());
149 $paths[] = $content['content_path'];
153 $zipfile->add_file($content['text'], 'resources/'.$content['content_path'].$content['content_id'].'.html', $content['u_ts']);
154 $content['title'] = htmlspecialchars($content['title']);
156 /* add the resource dependancies */
157 if ($my_files == null) $my_files = array();
158 $content_files = "\n";
159 $parser->parse($content['text']);
161 /* generate the IMS QTI resource and files */
162 global $contentManager;
163 //check if test export is allowed.
164 if ($contentManager->allowTestExport($content['content_id'])){
165 $content_test_rs = $contentManager->getContentTestsAssoc($content['content_id']);
166 $test_ids = array(); //reset test ids
167 //$my_files = array(); //reset myfiles.
168 while ($content_test_row = mysql_fetch_assoc($content_test_rs)){
170 $test_ids[] = $content_test_row['test_id'];
171 //the 'added_files' is for adding into the manifest file in this zip
172 $added_files = test_qti_export($content_test_row['test_id'], '', $zipfile);
174 //Save all the xml files in this array, and then print_organizations will add it to the manifest file.
175 foreach($added_files as $filename=>$file_array){
176 $my_files[] = $filename;
177 foreach ($file_array as $garbage=>$filename2){
178 if (!in_array($filename2, $my_files)){
179 $my_files[] = $filename2;
184 //Save all the xml files in this array, and then print_organizations will add it to the manifest file.
185 $resources .= str_replace( array('{TEST_ID}', '{PATH}', '{FILES}'),
186 array($content_test_row['test_id'], 'tests_'.$content_test_row['test_id'].'.xml', $added_files_xml),
187 $ims_template_xml['resource_test']);
191 /* generate the a4a files */
192 $a4a_xml_array = array();
193 if ($use_a4a == true){
194 $a4aExport = new A4aExport($content['content_id']);
195 // $a4aExport->setRelativePath('resources/'.$content['content_path']);
196 $secondary_files = $a4aExport->getAllSecondaryFiles();
197 $a4a_xml_array = $a4aExport->exportA4a();
198 $my_files = array_merge($my_files, $a4aExport->getAllSecondaryFiles());
202 $import_files = get_import_files($content['text']);
204 if (count($import_files) > 0) $my_files = array_merge($my_files, $import_files);
206 foreach ($my_files as $file) {
207 /* filter out full urls */
208 $url_parts = @parse_url($file);
209 if (isset($url_parts['scheme'])) {
213 /* file should be relative to content. let's double check */
214 if ((substr($file, 0, 1) == '/')) {
218 $file_path = realpath(AT_CONTENT_DIR . $course_id . '/' . $content['content_path'] . $file);
220 /* check if this file exists in the content dir, if not don't include it */
221 if (file_exists($file_path) && is_file($file_path) && !in_array($file_path, $zipped_files)) {
222 $zipped_files[] = $file_path;
223 $dir = substr(dirname($file_path), strlen(AT_CONTENT_DIR . $course_id));
225 if (!in_array($dir, $paths) && $dir) {
226 $dir = str_replace('\\', '/', substr($dir, 1));
227 $zipfile->create_dir('resources/' . $dir, time());
232 $file_info = stat( $file_path );
234 //Fixes relative paths, so folder1/folder2/../file.jpg will become just folder1/file.jpg
235 $file_save_path = str_replace(AT_CONTENT_DIR . $course_id . DIRECTORY_SEPARATOR, '', $file_path);
236 $file_save_path = str_replace('\\', '/', $file_save_path);
238 //condition checks if the file has been added, so then the test won't be added to all the subchildren
239 //leads to normal images not capable to be extracted.
240 if ( (empty($test_zipped_files) || (is_array($test_zipped_files) && !in_array($file_path, $test_zipped_files)))
241 && file_exists($file_path)){
242 $zipfile->add_file(@file_get_contents($file_path), 'resources/' . $file_save_path, $file_info['mtime']);
243 // $test_zipped_files[] = $content['content_path'] . $file;
244 $test_zipped_files[] = $file_path;
245 } elseif (!is_array($test_zipped_files) && file_exists($file_path) && !in_array($file_path, $zipped_files)){
246 $zipfile->add_file(@file_get_contents($file_path), 'resources/' . $file_save_path, $file_info['mtime']);
249 //a4a secondary files have mapping, save the ones that we want in order to add the tag in
250 $a4a_secondary_files = array();
251 foreach ($a4a_xml_array as $a4a_filename=>$a4a_filearray){
252 if (preg_match('/(.*)\sto\s(.*)/', $a4a_filename, $matches)){
253 //save the actual file name
254 $a4a_secondary_files[$matches[1]][] = $a4a_filename; //values are holders
258 // If this file has a4a alternatives, link it.
259 if (isset($a4a_xml_array[$file]) || isset($a4a_secondary_files[$file])){
260 //if this is an array, meaning that it has more than 1 alternatives, print all
261 if (is_array($a4a_secondary_files[$file])){
262 $all_secondary_files_md = ''; //reinitialize string to null
263 foreach ($a4a_secondary_files[$file] as $v){
264 $all_secondary_files_md .= $a4a_xml_array[$v]; //all the meta data
266 $content_files .= str_replace( array('{FILE}', '{FILE_META_DATA}'),
267 array('resources/'.$file_save_path, $all_secondary_files_md),
268 $ims_template_xml['file_meta']);
270 $content_files .= str_replace( array('{FILE}', '{FILE_META_DATA}'),
271 array('resources/'.$file_save_path, $a4a_xml_array[$file]),
272 $ims_template_xml['file_meta']);
275 //if this file is in the test array, add an extra link to the direct file,
276 if (!empty($test_zipped_files) && in_array($file_path, $test_zipped_files)){
277 $content_files .= str_replace('{FILE}', $file_save_path, $ims_template_xml['file']);
279 $content_files .= str_replace('{FILE}', $file_save_path, $ims_template_xml['file']);
284 /* check if this file is one of the test xml file, if so, we need to add the dependency
285 * Note: The file has already been added to the archieve before this is called.
287 /* taken out as of nov 17th, used dependency instead
288 if (preg_match('/tests\_[0-9]+\.xml$/', $file) && !in_array($file, $test_zipped_files)){
289 $content_files .= str_replace('{FILE}', $file, $ims_template_xml['xml']);
290 $test_zipped_files[] = $file;
295 /******************************/
296 $resources .= str_replace( array('{CONTENT_ID}', '{PATH}', '{FILES}', '{DEPENDENCY}'),
297 array($content['content_id'], $content['content_path'], $content_files, $test_dependency),
298 $ims_template_xml['resource']);
301 for ($i=0; $i<$depth; $i++) {
305 $title = $prefix.$space.'<title>'.$content['title'].'</title>';
307 if ( is_array($_menu[$content['content_id']]) ) {
310 $html_link = '<li>'.$html_link.'<ul>';
311 for ($i=0; $i<$depth; $i++) {
312 if ($children[$i] == 1) {
314 //$html_link = $space.$html_link;
317 //$html_link = $space.$html_link;
322 /* doesn't have children */
324 $html_link = '<li>'.$html_link.'</li>';
325 if ($counter == $num_items) {
326 for ($i=0; $i<$depth; $i++) {
327 if ($children[$i] == 1) {
329 //$html_link = $space.$html_link;
332 //$html_link = $space.$html_link;
336 for ($i=0; $i<$depth; $i++) {
338 //$html_link = $space.$html_link;
341 $title = $space.$title;
348 $string .= $html_link."\n";
351 print_organizations($content['content_id'],
360 for ($i=0; $i<$depth; $i++) {
363 echo $prefix.'</item>';
375 $ims_template_xml['header'] = '<?xml version="1.0" encoding="{COURSE_PRIMARY_LANGUAGE_CHARSET}"?>
376 <!--This is an ATutor SCORM 1.2 Content Package document-->
377 <!--Created from the ATutor Content Package Generator - http://www.atutor.ca-->
378 <manifest xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2" xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_rootv1p2p1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2" identifier="MANIFEST-'.md5(time()).'"
379 xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1 http://www.imsglobal.org/xsd/imscp_v1p1p4.xsd http://www.imsglobal.org/xsd/imsmd_v1p2 http://www.imsglobal.org/xsd/imsmd_v1p2p2.xsd http://www.imsglobal.org/xsd/imsqti_item_v2p0 http://www.imsglobal.org/xsd/imsqti_item_v2p0.xsd"
380 version = "CP 1.1.4">
382 <schema>ADL SCORM</schema>
383 <schemaversion>1.2</schemaversion>
387 <imsmd:langstring xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}">{COURSE_TITLE}</imsmd:langstring>
390 <imsmd:langstring xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}">{COURSE_DESCRIPTION}</imsmd:langstring>
397 <imsmd:langstring xml:lang="x-none">LOMv1.0</imsmd:langstring>
400 <imsmd:langstring xml:lang="x-none">Author</imsmd:langstring>
404 <imsmd:vcard>{VCARD}</imsmd:vcard>
409 <imsmd:learningresourcetype>
411 <imsmd:langstring xml:lang="x-none">ATutor</imsmd:langstring>
414 <imsmd:langstring xml:lang="x-none">Content Module</imsmd:langstring>
416 </imsmd:learningresourcetype>
424 $ims_template_xml['resource'] = ' <resource identifier="MANIFEST01_RESOURCE{CONTENT_ID}" type="webcontent" href="resources/{PATH}{CONTENT_ID}.html" adlcp:scormtype="asset">
426 <file href="resources/{PATH}{CONTENT_ID}.html"/>{FILES}
430 $ims_template_xml['resource_test'] = ' <resource identifier="MANIFEST01_RESOURCE_QTI{TEST_ID}" type="imsqti_xmlv1p2/imscc_xmlv1p0/assessment">
432 <file href="{PATH}"/>{FILES}
436 $ims_template_xml['file'] = ' <file href="resources/{FILE}"/>'."\n";
437 $ims_template_xml['xml'] = ' <file href="{FILE}"/>'."\n";
438 $ims_template_xml['file_meta'] = ' <file href="{FILE}">
443 $ims_template_xml['final'] = '
444 <organizations default="MANIFEST01_ORG1">
445 <organization identifier="MANIFEST01_ORG1" structure="hierarchical">
446 <title>{COURSE_TITLE}</title>
455 $html_template = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
456 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
457 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
459 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
460 <style type="text/css">
461 body { font-family: Verdana, Arial, Helvetica, sans-serif;}
462 a.at-term { font-style: italic; }
464 <title>{TITLE}</title>
465 <meta name="Generator" content="ATutor">
466 <meta name="Keywords" content="{KEYWORDS}">
468 <body>{CONTENT}</body>
471 $html_content_template = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
472 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
473 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
475 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
477 <title>{TITLE}</title>
478 <meta name="Generator" content="ATutor">
479 <meta name="Keywords" content="{KEYWORDS}">
481 <body>{CONTENT}</body>
484 $default_html_style = ' <style type="text/css">
485 body { font-family: Verdana, Arial, Helvetica, sans-serif;}
486 a.at-term { font-style: italic; }
489 //output this as header.html
490 $html_mainheader = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
491 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
492 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
494 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
495 <link rel="stylesheet" type="text/css" href="ims.css"/>
496 <title>{COURSE_TITLE}</title>
498 <body class="headerbody"><h3>{COURSE_TITLE}</h3></body></html>';
501 $html_toc = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
502 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
503 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
505 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
506 <link rel="stylesheet" type="text/css" href="ims.css" />
509 <body>{TOC}</body></html>';
512 $html_frame = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
513 "http://www.w3.org/TR/html4/frameset.dtd">
514 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
515 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
516 <title>{COURSE_TITLE}</title>
518 <frameset rows="50,*,50">
519 <frame src="header.html" name="header" title="header" scrolling="no">
520 <frameset cols="25%, *" frameborder="1" framespacing="3">
521 <frame frameborder="2" marginwidth="0" marginheight="0" src="toc.html" name="frame" title="TOC">
522 <frame frameborder="2" src="resources/{PATH}{FIRST_ID}.html" name="body" title="{COURSE_TITLE}">
524 <frame src="footer.html" name="footer" title="footer" scrolling="no">
526 <h1>{COURSE_TITLE}</h1>
527 <p><a href="toc.html">Table of Contents</a> | <a href="footer.html">About</a><br />
535 $glossary_xml = '<?xml version="1.0" encoding="{COURSE_PRIMARY_LANGUAGE_CHARSET}"?>
536 <!--This is an ATutor Glossary terms document-->
537 <!--Created from the ATutor Content Package Generator - http://www.atutor.ca-->
540 <!ELEMENT item (term, definition)>
541 <!ELEMENT term (#PCDATA)>
542 <!ELEMENT definition (#PCDATA)>
550 $glossary_term_xml = ' <item>
552 <definition>{DEFINITION}</definition>
555 $glossary_body_html = '<h2>Glossary</h2>
560 $glossary_term_html = ' <li><a name="{ENCODED_TERM}"></a><strong>{TERM}</strong><br />
561 {DEFINITION}<br /><br /></li>';