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 if ($use_a4a == true){
202 $a4aExport = new A4aExport($content['content_id']);
203 // $a4aExport->setRelativePath('resources/'.$content['content_path']);
204 $secondary_files = $a4aExport->getAllSecondaryFiles();
205 $a4a_xml_array = $a4aExport->exportA4a();
206 $my_files = array_merge($my_files, $a4aExport->getAllSecondaryFiles());
210 $import_files = get_import_files($content['text']);
212 if (count($import_files) > 0) $my_files = array_merge($my_files, $import_files);
214 foreach ($my_files as $file) {
215 /* filter out full urls */
216 $url_parts = @parse_url($file);
217 if (isset($url_parts['scheme'])) {
221 /* file should be relative to content. let's double check */
222 if ((substr($file, 0, 1) == '/')) {
226 $file_path = realpath(TR_CONTENT_DIR . $course_id . '/' . $content['content_path'] . $file);
228 /* check if this file exists in the content dir, if not don't include it */
229 if (file_exists($file_path) && is_file($file_path) && !in_array($file_path, $zipped_files)) {
230 $zipped_files[] = $file_path;
231 $dir = substr(dirname($file_path), strlen(TR_CONTENT_DIR . $course_id));
233 if (!in_array($dir, $paths) && $dir) {
234 $dir = str_replace('\\', '/', substr($dir, 1));
235 $zipfile->create_dir('resources/' . $dir, time());
240 $file_info = stat( $file_path );
242 //Fixes relative paths, so folder1/folder2/../file.jpg will become just folder1/file.jpg
243 $file_save_path = str_replace(TR_CONTENT_DIR . $course_id . DIRECTORY_SEPARATOR, '', $file_path);
244 $file_save_path = str_replace('\\', '/', $file_save_path);
246 //condition checks if the file has been added, so then the test won't be added to all the subchildren
247 //leads to normal images not capable to be extracted.
248 if ( (empty($test_zipped_files) || (is_array($test_zipped_files) && !in_array($file_path, $test_zipped_files)))
249 && file_exists($file_path)){
250 $zipfile->add_file(@file_get_contents($file_path), 'resources/' . $file_save_path, $file_info['mtime']);
251 // $test_zipped_files[] = $content['content_path'] . $file;
252 $test_zipped_files[] = $file_path;
253 } elseif (!is_array($test_zipped_files) && file_exists($file_path) && !in_array($file_path, $zipped_files)){
254 $zipfile->add_file(@file_get_contents($file_path), 'resources/' . $file_save_path, $file_info['mtime']);
257 //a4a secondary files have mapping, save the ones that we want in order to add the tag in
258 $a4a_secondary_files = array();
259 foreach ($a4a_xml_array as $a4a_filename=>$a4a_filearray){
260 if (preg_match('/(.*)\sto\s(.*)/', $a4a_filename, $matches)){
261 //save the actual file name
262 $a4a_secondary_files[$matches[1]][] = $a4a_filename; //values are holders
266 // If this file has a4a alternatives, link it.
267 if (isset($a4a_xml_array[$file]) || isset($a4a_secondary_files[$file])){
268 //if this is an array, meaning that it has more than 1 alternatives, print all
269 if (is_array($a4a_secondary_files[$file])){
270 $all_secondary_files_md = ''; //reinitialize string to null
271 foreach ($a4a_secondary_files[$file] as $v){
272 foreach($a4a_xml_array[$v] as $v2){
273 $all_secondary_files_md .= $v2; //all the meta data
276 $content_files .= str_replace( array('{FILE}', '{FILE_META_DATA}'),
277 array('resources/'.$file_save_path, $all_secondary_files_md),
278 $ims_template_xml['file_meta']);
280 $content_files .= str_replace( array('{FILE}', '{FILE_META_DATA}'),
281 array('resources/'.$file_save_path, $a4a_xml_array[$file]),
282 $ims_template_xml['file_meta']);
285 //if this file is in the test array, add an extra link to the direct file,
286 if (!empty($test_zipped_files) && in_array($file_path, $test_zipped_files)){
287 $content_files .= str_replace('{FILE}', $file_save_path, $ims_template_xml['file']);
289 $content_files .= str_replace('{FILE}', $file_save_path, $ims_template_xml['file']);
294 /* check if this file is one of the test xml file, if so, we need to add the dependency
295 * Note: The file has already been added to the archieve before this is called.
297 /* taken out as of nov 17th, used dependency instead
298 if (preg_match('/tests\_[0-9]+\.xml$/', $file) && !in_array($file, $test_zipped_files)){
299 $content_files .= str_replace('{FILE}', $file, $ims_template_xml['xml']);
300 $test_zipped_files[] = $file;
305 /******************************/
306 $resources .= str_replace( array('{CONTENT_ID}', '{PATH}', '{FILES}', '{DEPENDENCY}'),
307 array($content['content_id'], $content['content_path'], $content_files, $test_dependency),
308 $ims_template_xml['resource']);
311 for ($i=0; $i<$depth; $i++) {
315 $title = $prefix.$space.'<title>'.$content['title'].'</title>';
317 if ( is_array($_menu[$content['content_id']]) ) {
320 $html_link = '<li>'.$html_link.'<ul>';
321 for ($i=0; $i<$depth; $i++) {
322 if ($children[$i] == 1) {
324 //$html_link = $space.$html_link;
327 //$html_link = $space.$html_link;
332 /* doesn't have children */
334 $html_link = '<li>'.$html_link.'</li>';
335 if ($counter == $num_items) {
336 for ($i=0; $i<$depth; $i++) {
337 if ($children[$i] == 1) {
339 //$html_link = $space.$html_link;
342 //$html_link = $space.$html_link;
346 for ($i=0; $i<$depth; $i++) {
348 //$html_link = $space.$html_link;
351 $title = $space.$title;
358 $string .= $html_link."\n";
361 print_organizations($content['content_id'],
370 for ($i=0; $i<$depth; $i++) {
373 echo $prefix.'</item>';
385 $ims_template_xml['header'] = '<?xml version="1.0" encoding="{COURSE_PRIMARY_LANGUAGE_CHARSET}"?>
386 <!--This is an ATutor SCORM 1.2 Content Package document-->
387 <!--Created from the ATutor Content Package Generator - http://www.atutor.ca-->
388 <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()).'"
389 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"
390 version = "CP 1.1.4">
392 <schema>ADL SCORM</schema>
393 <schemaversion>1.2</schemaversion>
397 <imsmd:langstring xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}">{COURSE_TITLE}</imsmd:langstring>
400 <imsmd:langstring xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}">{COURSE_DESCRIPTION}</imsmd:langstring>
407 <imsmd:langstring xml:lang="x-none">LOMv1.0</imsmd:langstring>
410 <imsmd:langstring xml:lang="x-none">Author</imsmd:langstring>
414 <imsmd:vcard>{VCARD}</imsmd:vcard>
419 <imsmd:learningresourcetype>
421 <imsmd:langstring xml:lang="x-none">ATutor</imsmd:langstring>
424 <imsmd:langstring xml:lang="x-none">Content Module</imsmd:langstring>
426 </imsmd:learningresourcetype>
434 $ims_template_xml['resource'] = ' <resource identifier="MANIFEST01_RESOURCE{CONTENT_ID}" type="webcontent" href="resources/{PATH}{CONTENT_ID}.html" adlcp:scormtype="asset">
436 <file href="resources/{PATH}{CONTENT_ID}.html"/>{FILES}
440 $ims_template_xml['resource_test'] = ' <resource identifier="MANIFEST01_RESOURCE_QTI{TEST_ID}" type="imsqti_xmlv1p2/imscc_xmlv1p0/assessment">
442 <file href="{PATH}"/>{FILES}
446 $ims_template_xml['file'] = ' <file href="resources/{FILE}"/>'."\n";
447 $ims_template_xml['xml'] = ' <file href="{FILE}"/>'."\n";
448 $ims_template_xml['file_meta'] = ' <file href="{FILE}">
453 $ims_template_xml['final'] = '
454 <organizations default="MANIFEST01_ORG1">
455 <organization identifier="MANIFEST01_ORG1" structure="hierarchical">
456 <title>{COURSE_TITLE}</title>
465 $html_template = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
466 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
467 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
469 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
470 <style type="text/css">
471 body { font-family: Verdana, Arial, Helvetica, sans-serif;}
472 a.at-term { font-style: italic; }
474 <title>{TITLE}</title>
475 <meta name="Generator" content="ATutor">
476 <meta name="Keywords" content="{KEYWORDS}">
478 <body>{CONTENT}</body>
481 $html_content_template = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
482 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
483 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
485 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
487 <title>{TITLE}</title>
488 <meta name="Generator" content="ATutor">
489 <meta name="Keywords" content="{KEYWORDS}">
491 <body>{CONTENT}</body>
494 $default_html_style = ' <style type="text/css">
495 body { font-family: Verdana, Arial, Helvetica, sans-serif;}
496 a.at-term { font-style: italic; }
499 //output this as header.html
500 $html_mainheader = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
501 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
502 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
504 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
505 <link rel="stylesheet" type="text/css" href="ims.css"/>
506 <title>{COURSE_TITLE}</title>
508 <body class="headerbody"><h3>{COURSE_TITLE}</h3></body></html>';
511 $html_toc = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
512 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
513 <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 <link rel="stylesheet" type="text/css" href="ims.css" />
519 <body>{TOC}</body></html>';
522 $html_frame = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
523 "http://www.w3.org/TR/html4/frameset.dtd">
524 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
525 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
526 <title>{COURSE_TITLE}</title>
528 <frameset rows="50,*,50">
529 <frame src="header.html" name="header" title="header" scrolling="no">
530 <frameset cols="25%, *" frameborder="1" framespacing="3">
531 <frame frameborder="2" marginwidth="0" marginheight="0" src="toc.html" name="frame" title="TOC">
532 <frame frameborder="2" src="resources/{PATH}{FIRST_ID}.html" name="body" title="{COURSE_TITLE}">
534 <frame src="footer.html" name="footer" title="footer" scrolling="no">
536 <h1>{COURSE_TITLE}</h1>
537 <p><a href="toc.html">Table of Contents</a> | <a href="footer.html">About</a><br />
545 $glossary_xml = '<?xml version="1.0" encoding="{COURSE_PRIMARY_LANGUAGE_CHARSET}"?>
546 <!--This is an ATutor Glossary terms document-->
547 <!--Created from the ATutor Content Package Generator - http://www.atutor.ca-->
550 <!ELEMENT item (term, definition)>
551 <!ELEMENT term (#PCDATA)>
552 <!ELEMENT definition (#PCDATA)>
560 $glossary_term_xml = ' <item>
562 <definition>{DEFINITION}</definition>
565 $glossary_body_html = '<h2>Glossary</h2>
570 $glossary_term_html = ' <li><a name="{ENCODED_TERM}"></a><strong>{TERM}</strong><br />
571 {DEFINITION}<br /><br /></li>';