remove old readme
[atutor.git] / docs / mods / _core / themes / classes / ThemeListParser.class.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
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
15 /**
16 * ThemeListParser
17 * Class for parsing XML theme list info
18 * @access       public
19 * @author       Cindy Qi Li
20 * @package Admin Theme
21 */
22 class ThemeListParser {
23
24         // all private
25         var $parser; // the XML handler
26         var $theme_rows = array(); // the theme data
27         var $character_data; // tmp variable for storing the data
28         var $element_path; // array of element paths (basically a stack)
29         var $row_num;
30         var $history_num;
31
32         function ThemeListParser() {
33                 $this->parser = xml_parser_create(''); 
34
35                 xml_set_object($this->parser, $this);
36                 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); /* conform to W3C specs */
37                 xml_set_element_handler($this->parser, 'startElement', 'endElement');
38                 xml_set_character_data_handler($this->parser, 'characterData');
39         }
40
41         // public
42         function parse($xml_data) {
43                 $this->element_path   = array();
44                 $this->theme_rows  = array();
45                 $this->character_data = '';
46                 $this->row_num        = 0;
47                 $this->history_num    = 0;
48                 xml_parse($this->parser, $xml_data, TRUE);
49         }
50
51         // private
52         function startElement($parser, $name, $attributes) 
53         {
54                 array_push($this->element_path, $name);
55    }
56
57         // private
58         /* called when an element ends */
59         /* removed the current element from the $path */
60         function endElement($parser, $name) {
61                 if ($this->element_path == array('theme_list', 'theme', 'name')) 
62                 {
63                         $this->theme_rows[$this->row_num]['name'] = trim($this->character_data);
64                 } 
65                 else if ($this->element_path === array('theme_list', 'theme', 'atutor_version')) 
66                 {
67                         $this->theme_rows[$this->row_num]['atutor_version'] = trim($this->character_data);
68                 } 
69                 else if ($this->element_path === array('theme_list', 'theme', 'description')) 
70                 {
71                         $this->theme_rows[$this->row_num]['description'] = trim($this->character_data);
72                 } 
73                 else if ($this->element_path === array('theme_list', 'theme', 'history')) 
74                 {
75                         $this->history_num = 0;
76                 } 
77                 else if ($this->element_path === array('theme_list', 'theme', 'history', 'release')) 
78                 {
79                         $this->history_num++;
80                 } 
81                 else if ($this->element_path === array('theme_list', 'theme', 'history', 'release', 'version')) 
82                 {
83                         $this->theme_rows[$this->row_num]['history'][$this->history_num]['version'] = trim($this->character_data);
84                 } 
85                 else if ($this->element_path === array('theme_list', 'theme', 'history', 'release', 'atutor_version')) 
86                 {
87                         $this->theme_rows[$this->row_num]['history'][$this->history_num]['atutor_version'] = trim($this->character_data);
88                 } 
89                 else if ($this->element_path === array('theme_list', 'theme', 'history', 'release', 'filename')) 
90                 {
91                         $this->theme_rows[$this->row_num]['history'][$this->history_num]['filename'] = trim($this->character_data);
92                 } 
93                 else if ($this->element_path === array('theme_list', 'theme', 'history', 'release', 'location')) 
94                 {
95                         $this->theme_rows[$this->row_num]['history'][$this->history_num]['location'] = trim($this->character_data);
96                 } 
97                 else if ($this->element_path === array('theme_list', 'theme', 'history', 'release', 'screenshot_file')) 
98                 {
99                         $this->theme_rows[$this->row_num]['history'][$this->history_num]['screenshot_file'] = trim($this->character_data);
100                 } 
101                 else if ($this->element_path === array('theme_list', 'theme', 'history', 'release', 'install_folder')) 
102                 {
103                         $this->theme_rows[$this->row_num]['history'][$this->history_num]['install_folder'] = trim($this->character_data);
104                 } 
105                 else if ($this->element_path === array('theme_list', 'theme', 'history', 'release', 'date')) 
106                 {
107                         $this->theme_rows[$this->row_num]['history'][$this->history_num]['date'] = trim($this->character_data);
108                 } 
109                 else if ($this->element_path === array('theme_list', 'theme', 'history', 'release', 'state')) 
110                 {
111                         $this->theme_rows[$this->row_num]['history'][$this->history_num]['state'] = trim($this->character_data);
112                 } 
113                 else if ($this->element_path === array('theme_list', 'theme', 'history', 'release', 'maintainer')) 
114                 {
115                         $this->theme_rows[$this->row_num]['history'][$this->history_num]['maintainer'] = trim($this->character_data);
116                 } 
117                 else if ($this->element_path === array('theme_list', 'theme', 'history', 'release', 'notes')) 
118                 {
119                         $this->theme_rows[$this->row_num]['history'][$this->history_num]['notes'] = trim($this->character_data);
120                 } 
121                 else if ($this->element_path === array('theme_list', 'theme')) 
122                 {
123                         $this->row_num++;
124                 }
125
126                 array_pop($this->element_path);
127                 $this->character_data = '';
128         }
129
130         // private
131         function characterData($parser, $data){
132                 $this->character_data .= $data;
133         }
134
135         // public
136         function getNumOfThemes() 
137         {
138                 return count($this->theme_rows);
139         }
140
141         // public
142         function getParsedArray() 
143         {
144                 return $this->theme_rows;
145         }
146 }
147
148 ?>