AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / include / classes / DiscussionTools / DiscussionToolsParser.class.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
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 /************************************************************************/
12
13 include('DiscussionTools.class.php');
14
15 /**
16  * A class for DiscussionToolsParser
17  * based on:
18  *  http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_5/imsdt_v1p0_localised.xsd
19  */
20 class DiscussionToolsParser {
21         //global variables
22         //private
23         var $parser; // the XML handler
24         var $character_data; // tmp variable for storing the data
25         var $element_path; // array of element paths (basically a stack)
26         var $title;     //link's title
27         var $text; //description
28
29         //constructor
30         function DiscussionToolsParser(){
31                 $this->parser = xml_parser_create(); 
32
33                 xml_set_object($this->parser, $this);
34                 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); /* conform to W3C specs */
35                 xml_set_element_handler($this->parser, 'startElement', 'endElement');
36                 xml_set_character_data_handler($this->parser, 'characterData');
37         }
38
39         // public
40         // @return      true if parsed successfully, false otherwise
41         function parse($xml_data) {
42                 $this->element_path   = array();
43                 $this->character_data = '';
44                 xml_parse($this->parser, $xml_data, TRUE);              
45         }
46
47         // private
48         function startElement($parser, $name, $attributes) {
49                 //save attributes.
50                 switch($name) {
51                         case 'text':
52                                 $this->text_type = $attributes['texttype'];
53                                 break;
54                 }
55                 array_push($this->element_path, $name);
56    }
57
58         // private
59         /* called when an element ends */
60         /* removed the current element from the $path */
61         function endElement($parser, $name) {
62                 switch($name) {
63                         case 'title':
64                                 $this->title = $this->character_data;
65                                 break;
66                         case 'text':
67                                 $this->text = $this->character_data;
68                                 break;
69                 }
70
71                 //pop stack and reset character data, o/w it will stack up
72                 array_pop($this->element_path);
73                 $this->character_data = '';
74         }
75
76         // private      
77         function characterData($parser, $data){
78                 global $addslashes;
79                 if (trim($data)!=''){
80                         $this->character_data .= preg_replace('/[\t\0\x0B(\r\n)]*/', '', $data);
81 //                      $this->character_data .= trim($data);
82                 }
83         }
84
85         //public
86         function close(){
87                 //Free the XML parser
88                 xml_parser_free($this->parser);
89         }
90
91         //get title
92         function getDT(){
93                 return new DiscussionTools($this->title, $this->text);
94         }
95 }
96 ?>