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