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; }
17 define('TR_INCLUDE_PATH', '../include/');
18 include_once(TR_INCLUDE_PATH.'../home/classes/ContentUtility.class.php');
20 $body_text = htmlspecialchars($stripslashes($_POST['body_text']));
21 $body = html_entity_decode($body_text);
23 require(TR_INCLUDE_PATH.'classes/XML/XML_HTMLSax/XML_HTMLSax.php'); /* for XML_HTMLSax */
24 require(TR_INCLUDE_PATH.'../home/imscc/include/ims_template.inc.php'); /* for ims templates + print_organizations() */
27 the following resources are to be identified:
28 even if some of these can't be images, they can still be files in the content dir.
29 theoretically the only urls we wouldn't deal with would be for a <!DOCTYPE and <form>
32 a => href // ignore if href doesn't exist (ie. <a name>)
33 object => data | classid // probably only want data
34 applet => classid | archive // whatever these two are should double check to see if it's a valid file (not a dir)
41 function MyHandler(){}
42 function openHandler(& $parser,$name,$attrs) {
45 $name = strtolower($name);
46 $attrs = array_change_key_case($attrs, CASE_LOWER);
48 $elements = array( 'img' => 'src',
50 'object' => array('data', 'classid'),
51 'applet' => array('classid', 'archive'),
58 /* check if this attribute specifies the files in different ways: (ie. java) */
59 if (is_array($elements[$name])) {
60 $items = $elements[$name];
62 foreach ($items as $item) {
63 if ($attrs[$item] != '') {
65 /* some attributes allow a listing of files to include seperated by commas (ie. applet->archive). */
66 if (strpos($attrs[$item], ',') !== false) {
67 $files = explode(',', $attrs[$item]);
68 foreach ($files as $file) {
69 $my_files[] = trim($file);
72 $my_files[] = $attrs[$item];
76 } else if (isset($elements[$name]) && ($attrs[$elements[$name]] != '')) {
77 /* we know exactly which attribute contains the reference to the file. */
78 $my_files[] = $attrs[$elements[$name]];
81 function closeHandler(& $parser,$name) { }
84 /* get all the content */
85 $handler=new MyHandler();
86 $parser = new XML_HTMLSax();
87 $parser->set_object($handler);
88 $parser->set_element_handler('openHandler','closeHandler');
90 /* generate the resources and save the HTML files */
92 global $parser, $my_files;
95 /* add the resource dependancies */
97 $content_files = "\n";
99 //in order to control if some [media] is in the body_text
100 //$body = ContentUtility::embedMedia($body_t);
102 $parser->parse($body);
104 // find all [media] resources
105 preg_match_all("/\[media[0-9a-z\|]*\](.*)\[\/media\]/i",$body,$media_matches);
106 $my_files = array_merge($media_matches[1], $my_files);
109 // This resolves the problem introduced by [media] tag: when [media] is
110 // parsed into <object>, same resource appears a few times in <object> with different
111 // format to cater for different browsers or players. This way creates problem that different
112 // formats in <object> are all parsed and considered as different resource. array_unique()
113 // call solves this problem. But, it introduces the new problem that when a same resource
114 // appears at different places in the content and users do want to have them with different
115 // alternatives. With this solution, this same resource only shows up once at "adapt content"
116 // and only can have one alternative associated with. Table and scripts need to be re-designed
117 // to solve this problem, for example, include line number in table.
118 $my_files = array_unique($my_files);
121 $import_files = get_import_files($body);
123 if (count($import_files) > 0) $my_files = array_merge($my_files, $import_files);
127 foreach ($my_files as $file) {
128 /* filter out full urls */
129 $url_parts = @parse_url($file);
130 // if (isset($url_parts['scheme']) && substr($file, 0, strlen(TR_BASE_HREF)) != TR_BASE_HREF) {
134 /* file should be relative to content. let's double check */
135 if ((substr($file, 0, 1) == '/')) {
139 $resources[$i] = $file;