remove old readme
[atutor.git] / mods / _core / themes / classes / ThemeParser.class.php
1 <?php\r
2 /************************************************************************/\r
3 /* ATutor                                                                                                                               */\r
4 /************************************************************************/\r
5 /* Copyright (c) 2002-2010                                              */\r
6 /* Inclusive Design Institute                                           */\r
7 /* http://atutor.ca                                                                                                             */\r
8 /*                                                                                                                                              */\r
9 /* This program is free software. You can redistribute it and/or        */\r
10 /* modify it under the terms of the GNU General Public License          */\r
11 /* as published by the Free Software Foundation.                        */\r
12 /************************************************************************/\r
13 \r
14 /**\r
15 * ThemeParser\r
16 * Class for parsing XML language info and returning a Theme Object\r
17 * @access       public\r
18 * @author       Shozub Qureshi\r
19 * @package      Themes\r
20 */\r
21 class ThemeParser {\r
22 \r
23         // all private\r
24         var $parser; // the XML handler\r
25         var $theme_rows = array(); // the language data used for creating the Language Object\r
26         var $character_data; // tmp variable for storing the data\r
27         var $element_path; // array of element paths (basically a stack)\r
28         var $row_num;\r
29 \r
30         function ThemeParser() {\r
31                 $this->parser = xml_parser_create(); \r
32 \r
33                 xml_set_object($this->parser, $this);\r
34                 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); /* conform to W3C specs */\r
35                 xml_set_element_handler($this->parser, 'startElement', 'endElement');\r
36                 xml_set_character_data_handler($this->parser, 'characterData');\r
37         }\r
38 \r
39         // public\r
40         function parse($xml_data) {\r
41                 $this->element_path   = array();\r
42                 $this->theme_rows  = array();\r
43                 $this->character_data = '';\r
44                 xml_parse($this->parser, $xml_data, TRUE);\r
45         }\r
46 \r
47         // private\r
48         function startElement($parser, $name, $attributes) {\r
49                 array_push($this->element_path, $name);\r
50    }\r
51 \r
52         // private\r
53         /* called when an element ends */\r
54         /* removed the current element from the $path */\r
55         function endElement($parser, $name) {\r
56                 if ($this->element_path == array('theme', 'dir_name')) {\r
57                         $this->theme_rows['dir_name'] = trim($this->character_data);\r
58 \r
59                 } else if ($this->element_path == array('theme', 'title')) {\r
60                         $this->theme_rows['title'] = trim($this->character_data);\r
61 \r
62                 } else if ($this->element_path == array('theme', 'version')) {\r
63                         $this->theme_rows['version'] = trim($this->character_data);\r
64 \r
65                 } else if ($this->element_path == array('theme', 'type')) {\r
66                         $this->theme_rows['type'] = trim($this->character_data);\r
67 \r
68                 } else if ($this->element_path == array('theme', 'last_updated')) {\r
69                         $this->theme_rows['last_updated'] = trim($this->character_data);\r
70 \r
71                 } else if ($this->element_path == array('theme', 'extra_info')) {\r
72                         $this->theme_rows['extra_info'] = trim($this->character_data);\r
73 \r
74                 }\r
75 \r
76                 array_pop($this->element_path);\r
77                 $this->character_data = '';\r
78         }\r
79 \r
80         // private\r
81         function characterData($parser, $data){\r
82                 $this->character_data .= $data;\r
83         }\r
84 \r
85 }\r
86 \r
87 ?>