2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay & Joel Kronenberg */
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************/
13 // $Id: resources_parser_inc.inc.php 7208 2008-07-04 16:07:24Z silvia $
15 if (!defined('AT_INCLUDE_PATH')) { exit; }
16 //require(AT_INCLUDE_PATH.'lib/output.inc.php');
20 define('AT_INCLUDE_PATH', '../include/');
23 //echo $_POST['body_text'];
25 $body_text = htmlspecialchars($stripslashes($_POST['body_text']));
26 $body_t = html_entity_decode($body_text);
29 require(AT_INCLUDE_PATH.'classes/XML/XML_HTMLSax/XML_HTMLSax.php'); /* for XML_HTMLSax */
30 require(AT_INCLUDE_PATH.'ims/ims_template.inc.php'); /* for ims templates + print_organizations() */
33 the following resources are to be identified:
34 even if some of these can't be images, they can still be files in the content dir.
35 theoretically the only urls we wouldn't deal with would be for a <!DOCTYPE and <form>
38 a => href // ignore if href doesn't exist (ie. <a name>)
39 object => data | classid // probably only want data
40 applet => classid | archive // whatever these two are should double check to see if it's a valid file (not a dir)
47 function MyHandler(){}
48 function openHandler(& $parser,$name,$attrs) {
51 $name = strtolower($name);
52 $attrs = array_change_key_case($attrs, CASE_LOWER);
54 $elements = array( 'img' => 'src',
56 'object' => array('data', 'classid'),
57 'applet' => array('classid', 'archive'),
64 /* check if this attribute specifies the files in different ways: (ie. java) */
65 if (is_array($elements[$name])) {
66 $items = $elements[$name];
68 foreach ($items as $item) {
69 if ($attrs[$item] != '') {
71 /* some attributes allow a listing of files to include seperated by commas (ie. applet->archive). */
72 if (strpos($attrs[$item], ',') !== false) {
73 $files = explode(',', $attrs[$item]);
74 foreach ($files as $file) {
75 $my_files[] = trim($file);
78 $my_files[] = $attrs[$item];
82 } else if (isset($elements[$name]) && ($attrs[$elements[$name]] != '')) {
83 /* we know exactly which attribute contains the reference to the file. */
84 $my_files[] = $attrs[$elements[$name]];
87 function closeHandler(& $parser,$name) { }
90 /* get all the content */
91 $handler=new MyHandler();
92 $parser = new XML_HTMLSax();
93 $parser->set_object($handler);
94 $parser->set_element_handler('openHandler','closeHandler');
96 /* generate the resources and save the HTML files */
100 global $parser, $my_files;
103 /* add the resource dependancies */
105 $content_files = "\n";
107 //in order to control if some [media] is in the body_text
108 $body = embed_media($body_t);
110 $parser->parse($body);
113 // This resolves the problem introduced by [media] tag: when [media] is
114 // parsed into <object>, same resource appears a few times in <object> with different
115 // format to cater for different browsers or players. This way creates prolem that different
116 // formats in <object> are all parsed and considered as different resource. array_unique()
117 // call solves this problem. But, it introduces the new problem that when a same resource
118 // appears at different places in the content and users do want to have them with different
119 // alternatives. With this solution, this same resource only shows up once at "adapt content"
120 // and only can have one alternative associate with. Table and scripts need to re-design
121 // to solve this problem, for example, include line number in table.
122 $my_files = array_unique($my_files);
125 $import_files = get_import_files($body);
127 if (count($import_files) > 0) $my_files = array_merge($my_files, $import_files);
131 foreach ($my_files as $file) {
132 /* filter out full urls */
133 $url_parts = @parse_url($file);
134 if (isset($url_parts['scheme'])) {
138 /* file should be relative to content. let's double check */
139 if ((substr($file, 0, 1) == '/')) {
143 $resources[$i] = $file;
147 $organizations_str = ob_get_contents();