-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathXML_Slide.php
More file actions
281 lines (253 loc) · 8.01 KB
/
Copy pathXML_Slide.php
File metadata and controls
281 lines (253 loc) · 8.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?php
// {{{ header
// vim: set tabstop=4 shiftwidth=4 fdm=marker:
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Rasmus Lerdorf <rasmus@php.net> |
// +----------------------------------------------------------------------+
//
// $Id$
// }}}
require_once 'XML/Parser.php';
require_once 'objects.php';
/**
* Slide parser class.
*
* This class is a parser for a made up presentation slide format
*
* @author Rasmus Lerdorf <rasmus@php.net>
* @version $Revision$
* @access public
*/
class XML_Slide extends XML_Parser
{
// {{{ properties
/**
* @var string
*/
var $insideTag = '';
/**
* @var string
*/
var $activeTag = '';
/**
* @var array
*/
var $objects = array();
/**
* @var int
* Current Object Index
*/
var $coid = 0;
var $level = 0;
var $last_handler;
var $stack = array();
// }}}
// {{{ Constructor
/**
* Constructor
*
* @access public
* @param mixed File pointer or name of the slide file.
* @return void
*/
function __construct($handle = '')
{
parent::__construct('UTF-8');
if (@is_resource($handle)) {
$this->setInput($handle);
} elseif ($handle != '') {
$this->setInputFile($handle);
} else {
$this->raiseError('No filename passed.');
}
}
// }}}
// {{{ startHandler()
/**
* Start element handler for XML parser
*
* @access private
* @param object XML parser object
* @param string XML element
* @param array Attributes of XML tag
* @return void
*/
function startHandler($parser, $element, $attribs)
{
switch ($element) {
/* These tags can have other tags inside */
case 'SLIDE':
case 'BLURB':
case 'IMAGE':
case 'MOVIE':
case 'LIST':
case 'BREAK':
case 'EXAMPLE':
case 'LINK':
case 'PHP':
case 'TABLE':
$cl = '_'.strtolower($element);
$this->objects[++$this->coid] = new $cl();
$this->stack[] = $this->coid;
$this->insideTag = $element;
$this->_add_attribs($this->objects[$this->coid], $attribs);
$this->activeTag = 'text';
break;
case 'DIV':
$cl = '_'.strtolower($element);
$this->objects[++$this->coid] = new $cl();
$this->stack[] = $this->coid;
$this->insideTag = $element;
$this->_add_attribs($this->objects[$this->coid], $attribs);
$this->activeTag = 'text';
break;
/* Divider for indicating where to switch areas for layouts */
case 'DIVIDE':
$cl = '_'.strtolower($element);
$this->objects[++$this->coid] = new $cl();
$this->stack[] = $this->coid;
$this->insideTag = $element;
$this->_add_attribs($this->objects[$this->coid], $attribs);
$this->activeTag = 'text';
break;
/* Special case for array properties */
case 'BULLET':
case 'ITEM':
case 'NUM':
case 'LI':
$this->objects[$this->coid]->bullets[] = new _bullet();
$idx = count($this->objects[$this->coid]->bullets) - 1;
$this->_add_attribs($this->objects[$this->coid]->bullets[$idx], $attribs);
$this->objects[$this->coid]->bullets[$idx]->level = $this->level;
if($element=='NUM') {
$this->objects[$this->coid]->bullets[$idx]->type = 'number';
}
$this->activeTag = 'BULLET';
$this->level++;
break;
case 'CELL':
$this->objects[$this->coid]->cells[] = new _cell();
$idx = count($this->objects[$this->coid]->cells) - 1;
$this->_add_attribs($this->objects[$this->coid]->cells[$idx], $attribs);
$this->activeTag = $element;
break;
/* Everything else can't */
default:
$this->activeTag = $element;
$this->_add_attribs($this->objects[$this->coid], $attribs, strtolower($element));
break;
}
$this->last_handler = 'start';
}
// }}}
// {{{ endHandler()
/**
* End element handler for XML parser
*
* @access private
* @param object XML parser object
* @param string
* @return void
*/
function endHandler($parser, $element)
{
if ($element == $this->insideTag) {
$this->insideTag = '';
}
switch ($element) {
case 'SLIDE':
$this->objects[] = new _footer();
/* fall-through */
case 'BLURB':
case 'IMAGE':
case 'LIST':
case 'EXAMPLE':
case 'LINK':
case 'PHP':
case 'DIVIDE':
$this->coid = array_pop($this->stack);
break;
case 'DIV':
$this->objects[++$this->coid] = new _div_end();
$this->coid = array_pop($this->stack);
break;
case 'BULLET':
case 'ITEM':
case 'NUM':
case 'LI':
$this->level--;
break;
}
$this->activeTag = '';
$this->last_handler = 'end';
}
// }}}
// {{{ cdataHandler()
/**
* Handler for character data
*
* @access private
* @param object XML parser object
* @param string CDATA
* @return void
*/
function cdataHandler($parser, $cdata)
{
if(empty($this->activeTag)) return;
$el = strtolower($this->activeTag);
if($el == 'bullet') {
$idx = count($this->objects[$this->coid]->bullets) - 1;
if($this->last_handler == 'cdata')
$this->objects[$this->coid]->bullets[$idx]->text .= $cdata;
else
$this->objects[$this->coid]->bullets[$idx]->text = $cdata;
} elseif($el == 'cell') {
$idx = count($this->objects[$this->coid]->cells) - 1;
if($this->last_handler == 'cdata')
$this->objects[$this->coid]->cells[$idx]->text .= $cdata;
else
$this->objects[$this->coid]->cells[$idx]->text = $cdata;
} else {
if($this->last_handler == 'cdata') {
$this->objects[$this->coid]->$el .= $cdata;
} else {
$this->objects[$this->coid]->$el = $cdata;
}
}
$this->last_handler = 'cdata';
}
// }}}
// {{{ _add_attribs
function _add_attribs(&$object, $attribs, $prefix='') {
foreach($attribs as $attr=>$value) {
$a = empty($prefix) ? strtolower($attr) : $prefix.ucfirst(strtolower($attr));
$object->$a = $value;
}
}
// }}}
// {{{ getObjects()
/**
* Get Slide Objects
*
* @access public
* @return array
*/
function getObjects()
{
return $this->objects;
}
// }}}
}
?>