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 /* @See: include/lib/format_content.inc.php */
95 $content['text'] = str_replace('CONTENT_DIR/', '', $content['text']);
97 /* Commented by Cindy Qi Li on Jan 12, 2010
98 * AContent does not support glossary
99 // get all the glossary terms used
100 $terms = find_terms($content['text']);
101 if (is_array($terms)) {
102 foreach ($terms[2] as $term) {
103 $used_glossary_terms[] = $term;
107 /** Test dependency **/
108 // $test_dependency = ''; //Template for test
109 // $sql = 'SELECT * FROM '.TABLE_PREFIX.'content_tests_assoc WHERE content_id='.$content['content_id'];
110 // $result = mysql_query($sql, $db);
111 // while ($row = mysql_fetch_assoc($result)){
112 require_once(TR_INCLUDE_PATH.'classes/DAO/ContentTestsAssocDAO.class.php');
113 $contentTestsAssocDAO = new ContentTestsAssocDAO();
114 $rows = $contentTestsAssocDAO->getByContent($content['content_id']);
115 if (is_array($rows)) {
116 //add test dependency on top of forum dependency
117 foreach ($rows as $row)
118 $test_dependency .= $prefix.$space.'<dependency identifierref="MANIFEST01_RESOURCE_QTI'.$row['test_id'].'" />';
121 /* calculate how deep this page is: */
123 if ($content['content_path']) {
124 $depth = substr_count($content['content_path'], '/');
126 $path .= str_repeat('../', $depth);
129 $content['text'] = ContentUtility::formatContent($content['text'], $content['formatting']);
131 /* add HTML header and footers to the files */
133 /* use default style if <style> is not in imported html head */
135 if ($content['use_customized_head'])
137 if (strpos(strtolower($content['head']), '<style') > 0)
139 $head = $content['head'];
143 if (strlen($content['head']) > 0)
144 $head = $content['head'] . $default_html_style;
146 $head = $default_html_style;
150 $content['text'] = str_replace( array('{TITLE}', '{CONTENT}', '{KEYWORDS}', '{COURSE_PRIMARY_LANGUAGE_CHARSET}', '{COURSE_PRIMARY_LANGUAGE_CODE}', '{HEAD}'),
151 array($content['title'], $content['text'], $content['keywords'], $course_language_charset, $course_language_code, $head),
152 $html_content_template);
154 /* duplicate the paths in the content_path field in the zip file */
155 if ($content['content_path']) {
156 if (!in_array($content['content_path'], $paths)) {
157 $zipfile->create_dir('resources/'.$content['content_path'], time());
158 $paths[] = $content['content_path'];
162 $zipfile->add_file($content['text'], 'resources/'.$content['content_path'].$content['content_id'].'.html', $content['u_ts']);
163 $content['title'] = htmlspecialchars($content['title']);
165 /* add the resource dependancies */
166 if ($my_files == null) $my_files = array();
167 $content_files = "\n";
168 $parser->parse($content['text']);
170 /* generate the IMS QTI resource and files */
171 global $contentManager;
172 //check if test export is allowed.
173 $content_test_rs = $contentManager->getContentTestsAssoc($content['content_id']);
174 $test_ids = array(); //reset test ids
175 //$my_files = array(); //reset myfiles.
176 if (is_array($content_test_rs)) {
177 foreach ($content_test_rs as $content_test_row){
179 $test_ids[] = $content_test_row['test_id'];
180 //the 'added_files' is for adding into the manifest file in this zip
181 $added_files = test_qti_export($content_test_row['test_id'], '', $zipfile);
183 //Save all the xml files in this array, and then print_organizations will add it to the manifest file.
184 foreach($added_files as $filename=>$file_array){
185 $my_files[] = $filename;
186 foreach ($file_array as $garbage=>$filename2){
187 if (!in_array($filename2, $my_files)){
188 $my_files[] = $filename2;
193 //Save all the xml files in this array, and then print_organizations will add it to the manifest file.
194 $resources .= str_replace( array('{TEST_ID}', '{PATH}', '{FILES}'),
195 array($content_test_row['test_id'], 'tests_'.$content_test_row['test_id'].'.xml', $added_files_xml),
196 $ims_template_xml['resource_test']);
200 /* generate the a4a files */
201 $a4a_xml_array = array();
202 if ($use_a4a == true){
203 $a4aExport = new A4aExport($content['content_id']);
204 // $a4aExport->setRelativePath('resources/'.$content['content_path']);
205 $secondary_files = $a4aExport->getAllSecondaryFiles();
206 $a4a_xml_array = $a4aExport->exportA4a();
207 $my_files = array_merge($my_files, $a4aExport->getAllSecondaryFiles());
211 $import_files = get_import_files($content['text']);
213 if (count($import_files) > 0) $my_files = array_merge($my_files, $import_files);
215 foreach ($my_files as $file) {
216 /* filter out full urls */
217 $url_parts = @parse_url($file);
218 if (isset($url_parts['scheme'])) {
222 /* file should be relative to content. let's double check */
223 if ((substr($file, 0, 1) == '/')) {
227 $file_path = realpath(TR_CONTENT_DIR . $course_id . '/' . $content['content_path'] . $file);
229 /* check if this file exists in the content dir, if not don't include it */
230 if (file_exists($file_path) && is_file($file_path) && !in_array($file_path, $zipped_files)) {
231 $zipped_files[] = $file_path;
232 $dir = substr(dirname($file_path), strlen(TR_CONTENT_DIR . $course_id));
234 if (!in_array($dir, $paths) && $dir) {
235 $dir = str_replace('\\', '/', substr($dir, 1));
236 $zipfile->create_dir('resources/' . $dir, time());
241 $file_info = stat( $file_path );
243 //Fixes relative paths, so folder1/folder2/../file.jpg will become just folder1/file.jpg
244 $file_save_path = str_replace(TR_CONTENT_DIR . $course_id . DIRECTORY_SEPARATOR, '', $file_path);
245 $file_save_path = str_replace('\\', '/', $file_save_path);
247 //condition checks if the file has been added, so then the test won't be added to all the subchildren
248 //leads to normal images not capable to be extracted.
249 if ( (empty($test_zipped_files) || (is_array($test_zipped_files) && !in_array($file_path, $test_zipped_files)))
250 && file_exists($file_path)){
251 $zipfile->add_file(@file_get_contents($file_path), 'resources/' . $file_save_path, $file_info['mtime']);
252 // $test_zipped_files[] = $content['content_path'] . $file;
253 $test_zipped_files[] = $file_path;
254 } elseif (!is_array($test_zipped_files) && file_exists($file_path) && !in_array($file_path, $zipped_files)){
255 $zipfile->add_file(@file_get_contents($file_path), 'resources/' . $file_save_path, $file_info['mtime']);
258 //a4a secondary files have mapping, save the ones that we want in order to add the tag in
259 $a4a_secondary_files = array();
260 foreach ($a4a_xml_array as $a4a_filename=>$a4a_filearray){
261 if (preg_match('/(.*)\sto\s(.*)/', $a4a_filename, $matches)){
262 //save the actual file name
263 $a4a_secondary_files[$matches[1]][] = $a4a_filename; //values are holders
267 // If this file has a4a alternatives, link it.
268 if (isset($a4a_xml_array[$file]) || isset($a4a_secondary_files[$file])){
269 //if this is an array, meaning that it has more than 1 alternatives, print all
270 if (is_array($a4a_secondary_files[$file])){
271 $all_secondary_files_md = ''; //reinitialize string to null
272 foreach ($a4a_secondary_files[$file] as $v){
273 foreach($a4a_xml_array[$v] as $v2){
274 $all_secondary_files_md .= $v2; //all the meta data
277 $content_files .= str_replace( array('{FILE}', '{FILE_META_DATA}'),
278 array('resources/'.$file_save_path, $all_secondary_files_md),
279 $ims_template_xml['file_meta']);
281 $content_files .= str_replace( array('{FILE}', '{FILE_META_DATA}'),
282 array('resources/'.$file_save_path, $a4a_xml_array[$file]),
283 $ims_template_xml['file_meta']);
286 //if this file is in the test array, add an extra link to the direct file,
287 if (!empty($test_zipped_files) && in_array($file_path, $test_zipped_files)){
288 $content_files .= str_replace('{FILE}', $file_save_path, $ims_template_xml['file']);
290 $content_files .= str_replace('{FILE}', $file_save_path, $ims_template_xml['file']);
295 /* check if this file is one of the test xml file, if so, we need to add the dependency
296 * Note: The file has already been added to the archieve before this is called.
298 /* taken out as of nov 17th, used dependency instead
299 if (preg_match('/tests\_[0-9]+\.xml$/', $file) && !in_array($file, $test_zipped_files)){
300 $content_files .= str_replace('{FILE}', $file, $ims_template_xml['xml']);
301 $test_zipped_files[] = $file;
306 /******************************/
307 $resources .= str_replace( array('{CONTENT_ID}', '{PATH}', '{FILES}', '{DEPENDENCY}'),
308 array($content['content_id'], $content['content_path'], $content_files, $test_dependency),
309 $ims_template_xml['resource']);
312 for ($i=0; $i<$depth; $i++) {
316 $title = $prefix.$space.'<title>'.$content['title'].'</title>';
318 if ( is_array($_menu[$content['content_id']]) ) {
321 $html_link = '<li>'.$html_link.'<ul>';
322 for ($i=0; $i<$depth; $i++) {
323 if ($children[$i] == 1) {
325 //$html_link = $space.$html_link;
328 //$html_link = $space.$html_link;
333 /* doesn't have children */
335 $html_link = '<li>'.$html_link.'</li>';
336 if ($counter == $num_items) {
337 for ($i=0; $i<$depth; $i++) {
338 if ($children[$i] == 1) {
340 //$html_link = $space.$html_link;
343 //$html_link = $space.$html_link;
347 for ($i=0; $i<$depth; $i++) {
349 //$html_link = $space.$html_link;
352 $title = $space.$title;
359 $string .= $html_link."\n";
362 print_organizations($content['content_id'],
371 for ($i=0; $i<$depth; $i++) {
374 echo $prefix.'</item>';
386 $ims_template_xml['header'] = '<?xml version="1.0" encoding="{COURSE_PRIMARY_LANGUAGE_CHARSET}"?>
387 <!--This is an ATutor SCORM 1.2 Content Package document-->
388 <!--Created from the ATutor Content Package Generator - http://www.atutor.ca-->
389 <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()).'"
390 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"
391 version = "CP 1.1.4">
393 <schema>ADL SCORM</schema>
394 <schemaversion>1.2</schemaversion>
398 <imsmd:langstring xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}">{COURSE_TITLE}</imsmd:langstring>
401 <imsmd:langstring xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}">{COURSE_DESCRIPTION}</imsmd:langstring>
408 <imsmd:langstring xml:lang="x-none">LOMv1.0</imsmd:langstring>
411 <imsmd:langstring xml:lang="x-none">Author</imsmd:langstring>
415 <imsmd:vcard>{VCARD}</imsmd:vcard>
420 <imsmd:learningresourcetype>
422 <imsmd:langstring xml:lang="x-none">ATutor</imsmd:langstring>
425 <imsmd:langstring xml:lang="x-none">Content Module</imsmd:langstring>
427 </imsmd:learningresourcetype>
435 $ims_template_xml['resource'] = ' <resource identifier="MANIFEST01_RESOURCE{CONTENT_ID}" type="webcontent" href="resources/{PATH}{CONTENT_ID}.html" adlcp:scormtype="asset">
437 <file href="resources/{PATH}{CONTENT_ID}.html"/>{FILES}
441 $ims_template_xml['resource_test'] = ' <resource identifier="MANIFEST01_RESOURCE_QTI{TEST_ID}" type="imsqti_xmlv1p2/imscc_xmlv1p0/assessment">
443 <file href="{PATH}"/>{FILES}
447 $ims_template_xml['file'] = ' <file href="resources/{FILE}"/>'."\n";
448 $ims_template_xml['xml'] = ' <file href="{FILE}"/>'."\n";
449 $ims_template_xml['file_meta'] = ' <file href="{FILE}">
454 $ims_template_xml['final'] = '
455 <organizations default="MANIFEST01_ORG1">
456 <organization identifier="MANIFEST01_ORG1" structure="hierarchical">
457 <title>{COURSE_TITLE}</title>
466 $html_template = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
467 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
468 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
470 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
471 <style type="text/css">
472 body { font-family: Verdana, Arial, Helvetica, sans-serif;}
473 a.at-term { font-style: italic; }
475 <title>{TITLE}</title>
476 <meta name="Generator" content="ATutor">
477 <meta name="Keywords" content="{KEYWORDS}">
479 <body>{CONTENT}</body>
482 $html_content_template = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
483 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
484 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
486 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
488 <title>{TITLE}</title>
489 <meta name="Generator" content="ATutor">
490 <meta name="Keywords" content="{KEYWORDS}">
492 <body>{CONTENT}</body>
495 $default_html_style = ' <style type="text/css">
496 body { font-family: Verdana, Arial, Helvetica, sans-serif;}
497 a.at-term { font-style: italic; }
500 //output this as header.html
501 $html_mainheader = '<!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"/>
507 <title>{COURSE_TITLE}</title>
509 <body class="headerbody"><h3>{COURSE_TITLE}</h3></body></html>';
512 $html_toc = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
513 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
514 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
516 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
517 <link rel="stylesheet" type="text/css" href="ims.css" />
520 <body>{TOC}</body></html>';
523 $html_frame = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
524 "http://www.w3.org/TR/html4/frameset.dtd">
525 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
526 <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
527 <title>{COURSE_TITLE}</title>
529 <frameset rows="50,*,50">
530 <frame src="header.html" name="header" title="header" scrolling="no">
531 <frameset cols="25%, *" frameborder="1" framespacing="3">
532 <frame frameborder="2" marginwidth="0" marginheight="0" src="toc.html" name="frame" title="TOC">
533 <frame frameborder="2" src="resources/{PATH}{FIRST_ID}.html" name="body" title="{COURSE_TITLE}">
535 <frame src="footer.html" name="footer" title="footer" scrolling="no">
537 <h1>{COURSE_TITLE}</h1>
538 <p><a href="toc.html">Table of Contents</a> | <a href="footer.html">About</a><br />
546 $glossary_xml = '<?xml version="1.0" encoding="{COURSE_PRIMARY_LANGUAGE_CHARSET}"?>
547 <!--This is an ATutor Glossary terms document-->
548 <!--Created from the ATutor Content Package Generator - http://www.atutor.ca-->
551 <!ELEMENT item (term, definition)>
552 <!ELEMENT term (#PCDATA)>
553 <!ELEMENT definition (#PCDATA)>
561 $glossary_term_xml = ' <item>
563 <definition>{DEFINITION}</definition>
566 $glossary_body_html = '<h2>Glossary</h2>
571 $glossary_term_html = ' <li><a name="{ENCODED_TERM}"></a><strong>{TERM}</strong><br />
572 {DEFINITION}<br /><br /></li>';