2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
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 /************************************************************************/
13 if (!defined('TR_INCLUDE_PATH')) { exit; }
15 // This function gets files from html tag @import
16 function get_import_files($text)
18 $text = strtolower($text);
22 while (strpos(strtolower($text), strtolower($tag)) > 0)
24 $start_pos = strpos($text, $tag);
25 if ($start_pos !== false)
27 $text = substr($text, $start_pos);
28 $start_pos = strlen($tag);
29 $len = strpos($text, ';') - strlen($tag);
31 $file = substr(trim($text), $start_pos, $len);
33 // remove these characters from file name: url, (, ), ", '
34 $file = trim(preg_replace('/(\'|\"|url|\(|\))/', '', $file));
36 // strip processed tag
37 $text = substr($text, $start_pos);
38 array_push($files, $file);
46 function print_organizations($parent_id,
53 global $html_content_template, $default_html_style, $zipfile, $resources, $ims_template_xml, $parser, $my_files;
54 global $used_glossary_terms, $course_id, $course_language_charset, $course_language_code;
55 static $paths, $zipped_files;
57 global $test_zipped_files, $use_a4a, $db;
59 require_once(TR_INCLUDE_PATH.'../home/classes/ContentUtility.class.php');
67 $top_level = $_menu[$parent_id];
68 if (!is_array($paths)) {
71 if (!is_array($zipped_files)) {
72 $zipped_files = array();
74 if ( is_array($top_level) ) {
77 $num_items = count($top_level);
79 foreach ($top_level as $garbage => $content) {
82 if ($content['content_path']) {
83 $content['content_path'] .= '/';
85 //if this is a folder, export it without identifierref
86 if ($content['content_type']==CONTENT_TYPE_FOLDER){
87 $link = $prevfix.'<item identifier="MANIFEST01_ITEM'.$content['content_id'].'">'."\n";
89 $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";
91 $html_link = '<a href="resources/'.$content['content_path'].$content['content_id'].'.html" target="body">'.$content['title'].'</a>';
93 /* save the content as HTML files */
94 $content['text'] = str_replace('CONTENT_DIR/', '', $content['text']);
96 /* Commented by Cindy Qi Li on Jan 12, 2010
97 * AContent does not support glossary
98 // get all the glossary terms used
99 $terms = find_terms($content['text']);
100 if (is_array($terms)) {
101 foreach ($terms[2] as $term) {
102 $used_glossary_terms[] = $term;
106 /** Test dependency **/
107 // $test_dependency = ''; //Template for test
108 // $sql = 'SELECT * FROM '.TABLE_PREFIX.'content_tests_assoc WHERE content_id='.$content['content_id'];
109 // $result = mysql_query($sql, $db);
110 // while ($row = mysql_fetch_assoc($result)){
111 require_once(TR_INCLUDE_PATH.'classes/DAO/ContentTestsAssocDAO.class.php');
112 $contentTestsAssocDAO = new ContentTestsAssocDAO();
113 $rows = $contentTestsAssocDAO->getByContent($content['content_id']);
114 if (is_array($rows)) {
115 //add test dependency on top of forum dependency
116 foreach ($rows as $row)
117 $test_dependency .= $prefix.$space.'<dependency identifierref="MANIFEST01_RESOURCE_QTI'.$row['test_id'].'" />';
120 /* calculate how deep this page is: */
122 if ($content['content_path']) {
123 $depth = substr_count($content['content_path'], '/');
125 $path .= str_repeat('../', $depth);
128 $content['text'] = ContentUtility::formatContent($content['text'], $content['formatting']);
130 /* add HTML header and footers to the files */
132 /* use default style if <style> is not in imported html head */
134 if ($content['use_customized_head'])
136 if (strpos(strtolower($content['head']), '<style') > 0)
138 $head = $content['head'];
142 if (strlen($content['head']) > 0)
143 $head = $content['head'] . $default_html_style;
145 $head = $default_html_style;
149 $content['text'] = str_replace( array('{TITLE}', '{CONTENT}', '{KEYWORDS}', '{COURSE_PRIMARY_LANGUAGE_CHARSET}', '{COURSE_PRIMARY_LANGUAGE_CODE}', '{HEAD}'),
150 array($content['title'], $content['text'], $content['keywords'], $course_language_charset, $course_language_code, $head),
151 $html_content_template);
153 /* duplicate the paths in the content_path field in the zip file */
154 if ($content['content_path']) {
155 if (!in_array($content['content_path'], $paths)) {
156 $zipfile->create_dir('resources/'.$content['content_path'], time());
157 $paths[] = $content['content_path'];
161 $zipfile->add_file($content['text'], 'resources/'.$content['content_path'].$content['content_id'].'.html', $content['u_ts']);
162 $content['title'] = htmlspecialchars($content['title']);
164 /* add the resource dependancies */
165 if ($my_files == null) $my_files = array();
166 $content_files = "\n";
167 $parser->parse($content['text']);
169 /* generate the IMS QTI resource and files */
170 global $contentManager;
171 //check if test export is allowed.
172 $content_test_rs = $contentManager->getContentTestsAssoc($content['content_id']);
173 $test_ids = array(); //reset test ids
174 //$my_files = array(); //reset myfiles.
175 if (is_array($content_test_rs)) {
176 foreach ($content_test_rs as $content_test_row){
178 $test_ids[] = $content_test_row['test_id'];
179 //the 'added_files' is for adding into the manifest file in this zip
180 $added_files = test_qti_export($content_test_row['test_id'], '', $zipfile);
182 //Save all the xml files in this array, and then print_organizations will add it to the manifest file.
183 foreach($added_files as $filename=>$file_array){
184 $my_files[] = $filename;
185 foreach ($file_array as $garbage=>$filename2){
186 if (!in_array($filename2, $my_files)){
187 $my_files[] = $filename2;
192 //Save all the xml files in this array, and then print_organizations will add it to the manifest file.
193 $resources .= str_replace( array('{TEST_ID}', '{PATH}', '{FILES}'),
194 array($content_test_row['test_id'], 'tests_'.$content_test_row['test_id'].'.xml', $added_files_xml),
195 $ims_template_xml['resource_test']);
199 /* generate the a4a files */
200 $a4a_xml_array = array();
201 //http://atutor.ca/atutor/mantis/view.php?id=4593
202 if ($content['formatting']===0){
205 if ($use_a4a == true){
206 $a4aExport = new A4aExport($content['content_id']);
207 // $a4aExport->setRelativePath('resources/'.$content['content_path']);
208 $secondary_files = $a4aExport->getAllSecondaryFiles();
209 $a4a_xml_array = $a4aExport->exportA4a();
210 $my_files = array_merge($my_files, $a4aExport->getAllSecondaryFiles());
214 $import_files = get_import_files($content['text']);
216 if (count($import_files) > 0) $my_files = array_merge($my_files, $import_files);
218 foreach ($my_files as $file) {
219 /* filter out full urls */
220 $url_parts = @parse_url($file);
221 if (isset($url_parts['scheme'])) {
225 /* file should be relative to content. let's double check */
226 if ((substr($file, 0, 1) == '/')) {
230 $file_path = realpath(TR_CONTENT_DIR . $course_id . '/' . $content['content_path'] . $file);
232 /* check if this file exists in the content dir, if not don't include it */
233 if (file_exists($file_path) && is_file($file_path) && !in_array($file_path, $zipped_files)) {
234 $zipped_files[] = $file_path;
235 $dir = substr(dirname($file_path), strlen(TR_CONTENT_DIR . $course_id));
237 if (!in_array($dir, $paths) && $dir) {
238 $dir = str_replace('\\', '/', substr($dir, 1));
239 $zipfile->create_dir('resources/' . $dir, time());
244 $file_info = stat( $file_path );
246 //Fixes relative paths, so folder1/folder2/../file.jpg will become just folder1/file.jpg
247 $file_save_path = str_replace(TR_CONTENT_DIR . $course_id . DIRECTORY_SEPARATOR, '', $file_path);
248 $file_save_path = str_replace('\\', '/', $file_save_path);
250 //condition checks if the file has been added, so then the test won't be added to all the subchildren
251 //leads to normal images not capable to be extracted.
252 if ( (empty($test_zipped_files) || (is_array($test_zipped_files) && !in_array($file_path, $test_zipped_files)))
253 && file_exists($file_path)){
254 $zipfile->add_file(@file_get_contents($file_path), 'resources/' . $file_save_path, $file_info['mtime']);
255 // $test_zipped_files[] = $content['content_path'] . $file;
256 $test_zipped_files[] = $file_path;
257 } elseif (!is_array($test_zipped_files) && file_exists($file_path) && !in_array($file_path, $zipped_files)){
258 $zipfile->add_file(@file_get_contents($file_path), 'resources/' . $file_save_path, $file_info['mtime']);
261 //a4a secondary files have mapping, save the ones that we want in order to add the tag in
262 $a4a_secondary_files = array();
263 foreach ($a4a_xml_array as $a4a_filename=>$a4a_filearray){
264 if (preg_match('/(.*)\sto\s(.*)/', $a4a_filename, $matches)){
265 //save the actual file name
266 $a4a_secondary_files[$matches[1]][] = $a4a_filename; //values are holders
270 // If this file has a4a alternatives, link it.
271 if (isset($a4a_xml_array[$file]) || isset($a4a_secondary_files[$file])){
272 //if this is an array, meaning that it has more than 1 alternatives, print all
273 if (is_array($a4a_secondary_files[$file])){
274 $all_secondary_files_md = ''; //reinitialize string to null
275 foreach ($a4a_secondary_files[$file] as $v){
276 foreach($a4a_xml_array[$v] as $v2){
277 $all_secondary_files_md .= $v2; //all the meta data
280 $content_files .= str_replace( array('{FILE}', '{FILE_META_DATA}'),
281 array('resources/'.$file_save_path, $all_secondary_files_md),
282 $ims_template_xml['file_meta']);
284 $content_files .= str_replace( array('{FILE}', '{FILE_META_DATA}'),
285 array('resources/'.$file_save_path, $a4a_xml_array[$file]),
286 $ims_template_xml['file_meta']);
289 //if this file is in the test array, add an extra link to the direct file,
290 if (!empty($test_zipped_files) && in_array($file_path, $test_zipped_files)){
291 $content_files .= str_replace('{FILE}', $file_save_path, $ims_template_xml['file']);
293 $content_files .= str_replace('{FILE}', $file_save_path, $ims_template_xml['file']);
298 /* check if this file is one of the test xml file, if so, we need to add the dependency
299 * Note: The file has already been added to the archieve before this is called.
301 /* taken out as of nov 17th, used dependency instead
302 if (preg_match('/tests\_[0-9]+\.xml$/', $file) && !in_array($file, $test_zipped_files)){
303 $content_files .= str_replace('{FILE}', $file, $ims_template_xml['xml']);
304 $test_zipped_files[] = $file;
309 /******************************/
310 $resources .= str_replace( array('{CONTENT_ID}', '{PATH}', '{FILES}', '{DEPENDENCY}'),
311 array($content['content_id'], $content['content_path'], $content_files, $test_dependency),
312 $ims_template_xml['resource']);
315 for ($i=0; $i<$depth; $i++) {
319 $title = $prefix.$space.'<title>'.$content['title'].'</title>';
321 if ( is_array($_menu[$content['content_id']]) ) {
324 $html_link = '<li>'.$html_link.'<ul>';
325 for ($i=0; $i<$depth; $i++) {
326 if ($children[$i] == 1) {
328 //$html_link = $space.$html_link;
331 //$html_link = $space.$html_link;
336 /* doesn't have children */
338 $html_link = '<li>'.$html_link.'</li>';
339 if ($counter == $num_items) {
340 for ($i=0; $i<$depth; $i++) {
341 if ($children[$i] == 1) {
343 //$html_link = $space.$html_link;
346 //$html_link = $space.$html_link;
350 for ($i=0; $i<$depth; $i++) {
352 //$html_link = $space.$html_link;
355 $title = $space.$title;
362 $string .= $html_link."\n";
365 print_organizations($content['content_id'],
374 for ($i=0; $i<$depth; $i++) {
377 echo $prefix.'</item>';
389 $ims_template_xml['header'] = '<?xml version="1.0" encoding="{COURSE_PRIMARY_LANGUAGE_CHARSET}"?>
390 <!--This is an ATutor SCORM 1.2 Content Package document-->
391 <!--Created from the ATutor Content Package Generator - http://www.atutor.ca-->
392 <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()).'"
393 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"
394 version = "CP 1.1.4">
396 <schema>ADL SCORM</schema>
397 <schemaversion>1.2</schemaversion>
401 <imsmd:langstring xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}">{COURSE_TITLE}</imsmd:langstring>
404 <imsmd:langstring xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}">{COURSE_DESCRIPTION}</imsmd:langstring>
411 <imsmd:langstring xml:lang="x-none">LOMv1.0</imsmd:langstring>
414 <imsmd:langstring xml:lang="x-none">Author</imsmd:langstring>
418 <imsmd:vcard>{VCARD}</imsmd:vcard>
423 <imsmd:learningresourcetype>
425 <imsmd:langstring xml:lang="x-none">ATutor</imsmd:langstring>
428 <imsmd:langstring xml:lang="x-none">Content Module</imsmd:langstring>
430 </imsmd:learningresourcetype>
438 $ims_template_xml['resource'] = ' <resource identifier="MANIFEST01_RESOURCE{CONTENT_ID}" type="webcontent" href="resources/{PATH}{CONTENT_ID}.html" adlcp:scormtype="asset">
440 <file href="resources/{PATH}{CONTENT_ID}.html"/>{FILES}
444 $ims_template_xml['resource_test'] = ' <resource identifier="MANIFEST01_RESOURCE_QTI{TEST_ID}" type="imsqti_xmlv1p2/imscc_xmlv1p0/assessment">
446 <file href="{PATH}"/>{FILES}
450 $ims_template_xml['file'] = ' <file href="resources/{FILE}"/>'."\n";
451 $ims_template_xml['xml'] = ' <file href="{FILE}"/>'."\n";
452 $ims_template_xml['file_meta'] = ' <file href="{FILE}">
457 $ims_template_xml['final'] = '
458 <organizations default="MANIFEST01_ORG1">
459 <organization identifier="MANIFEST01_ORG1" structure="hierarchical">
460 <title>{COURSE_TITLE}</title>
469 $html_template = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
470 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
471 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
473 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
474 <style type="text/css">
475 body { font-family: Verdana, Arial, Helvetica, sans-serif;}
476 a.at-term { font-style: italic; }
478 <title>{TITLE}</title>
479 <meta name="Generator" content="ATutor">
480 <meta name="Keywords" content="{KEYWORDS}">
482 <body>{CONTENT}</body>
485 $html_content_template = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
486 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
487 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
489 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
491 <title>{TITLE}</title>
492 <meta name="Generator" content="ATutor">
493 <meta name="Keywords" content="{KEYWORDS}">
495 <body>{CONTENT}</body>
498 $default_html_style = ' <style type="text/css">
499 body { font-family: Verdana, Arial, Helvetica, sans-serif;}
500 a.at-term { font-style: italic; }
503 //output this as header.html
504 $html_mainheader = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
505 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
506 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
508 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
509 <link rel="stylesheet" type="text/css" href="ims.css"/>
510 <title>{COURSE_TITLE}</title>
512 <body class="headerbody"><h3>{COURSE_TITLE}</h3></body></html>';
515 $html_toc = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
516 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
517 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
519 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
520 <link rel="stylesheet" type="text/css" href="ims.css" />
523 <body>{TOC}</body></html>';
526 $html_frame = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
527 "http://www.w3.org/TR/html4/frameset.dtd">
528 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
529 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
530 <title>{COURSE_TITLE}</title>
532 <frameset rows="50,*,50">
533 <frame src="header.html" name="header" title="header" scrolling="no">
534 <frameset cols="25%, *" frameborder="1" framespacing="3">
535 <frame frameborder="2" marginwidth="0" marginheight="0" src="toc.html" name="frame" title="TOC">
536 <frame frameborder="2" src="resources/{PATH}{FIRST_ID}.html" name="body" title="{COURSE_TITLE}">
538 <frame src="footer.html" name="footer" title="footer" scrolling="no">
540 <h1>{COURSE_TITLE}</h1>
541 <p><a href="toc.html">Table of Contents</a> | <a href="footer.html">About</a><br />
549 $glossary_xml = '<?xml version="1.0" encoding="{COURSE_PRIMARY_LANGUAGE_CHARSET}"?>
550 <!--This is an ATutor Glossary terms document-->
551 <!--Created from the ATutor Content Package Generator - http://www.atutor.ca-->
554 <!ELEMENT item (term, definition)>
555 <!ELEMENT term (#PCDATA)>
556 <!ELEMENT definition (#PCDATA)>
564 $glossary_term_xml = ' <item>
566 <definition>{DEFINITION}</definition>
569 $glossary_body_html = '<h2>Glossary</h2>
574 $glossary_term_html = ' <li><a name="{ENCODED_TERM}"></a><strong>{TERM}</strong><br />
575 {DEFINITION}<br /><br /></li>';