1 |
<?php |
---|
2 |
include_once(COMMON."/xml_utils/XMLObject.php" ); |
---|
3 |
|
---|
4 |
class ThemeParser |
---|
5 |
{ |
---|
6 |
var $maVals = array(); |
---|
7 |
|
---|
8 |
var $maGlobals = array(); |
---|
9 |
var $maThemes = array(); |
---|
10 |
var $maThemeIndex = array(); |
---|
11 |
var $maLayers = array(); |
---|
12 |
var $mnThemes = 0; |
---|
13 |
|
---|
14 |
function ThemeParser( $szThemeFile ) |
---|
15 |
{ |
---|
16 |
/* ==================================================================== */ |
---|
17 |
/* Used implode(file instead of file_get_contents which is only */ |
---|
18 |
/* defined if php >= 4.3.0. */ |
---|
19 |
/* ==================================================================== */ |
---|
20 |
if (function_exists("file_get_contents")) |
---|
21 |
{ |
---|
22 |
$szXML = file_get_contents( $szThemeFile ); |
---|
23 |
} |
---|
24 |
else |
---|
25 |
{ |
---|
26 |
$szXML = implode('',file($szThemeFile)); |
---|
27 |
} |
---|
28 |
$this->Parse( $szXML ); |
---|
29 |
} |
---|
30 |
|
---|
31 |
function Parse( $szXML ) |
---|
32 |
{ |
---|
33 |
|
---|
34 |
$oXML = new XMLObject( $szXML ); |
---|
35 |
$oThemes = $oXML->getNextChild( "themes" ); |
---|
36 |
|
---|
37 |
$oGlobal = $oThemes->getNextChild( "global" ); |
---|
38 |
|
---|
39 |
$this->maGlobals["gThemeBold"] = "false"; |
---|
40 |
$this->maGlobals["gThemeFont"] = ""; |
---|
41 |
$this->maGlobals["gThemeFontSize"] = ""; |
---|
42 |
$this->maGlobals["gThemeIcon"] = ""; |
---|
43 |
$this->maGlobals["gThemeExtendAbstract"] = "false"; |
---|
44 |
$this->maGlobals["gThemeExtendContext"] = "false"; |
---|
45 |
$this->maGlobals["gThemeExtraLayers"] = -1; |
---|
46 |
|
---|
47 |
$this->maGlobals["gGroupBold"] = "false"; |
---|
48 |
$this->maGlobals["gGroupFont"] = ""; |
---|
49 |
$this->maGlobals["gGroupFontSize"] = ""; |
---|
50 |
$this->maGlobals["gGroupIcon"] = ""; |
---|
51 |
$this->maGlobals["gGroupExtendAbstract"] = "false"; |
---|
52 |
$this->maGlobals["gGroupVisible"] = "true"; |
---|
53 |
|
---|
54 |
if ($oGlobal != "") |
---|
55 |
{ |
---|
56 |
$ogTheme = $oGlobal->getNextChild( "themeParams" ); |
---|
57 |
$this->maGlobals["gThemeBold"] = (isset($ogTheme->bold)) ? $ogTheme->bold : $this->maGlobals["gThemeBold"]; |
---|
58 |
$this->maGlobals["gThemeFont"] = (isset($ogTheme->font)) ? $ogTheme->font : $this->maGlobals["gThemeFont"]; |
---|
59 |
$this->maGlobals["gThemeFontSize"] = (isset($ogTheme->fontsize)) ? $ogTheme->fontsize : $this->maGlobals["gThemeFontSize"]; |
---|
60 |
$this->maGlobals["gThemeIcon"] = (isset($ogTheme->icon)) ? $ogTheme->icon : $this->maGlobals["gThemeIcon"]; |
---|
61 |
$this->maGlobals["gThemeExtendAbstract"] = (isset($ogTheme->extendabstract)) ? $ogTheme->extendabstract : $this->maGlobals["gThemeExtendAbstract"]; |
---|
62 |
$this->maGlobals["gThemeExtendContext"] = (isset($ogTheme->extendcontext)) ? $ogTheme->extendcontext : $this->maGlobals["gThemeExtendContext"]; |
---|
63 |
|
---|
64 |
$ogGroup = $oGlobal->getNextChild( "groupParams" ); |
---|
65 |
$this->maGlobals["gGroupBold"] = (isset($ogGroup->bold)) ? $ogGroup->bold : $this->maGlobals["gGroupBold"]; |
---|
66 |
$this->maGlobals["gGroupFont"] = (isset($ogGroup->font)) ? $ogGroup->font : $this->maGlobals["gGroupFont"]; |
---|
67 |
$this->maGlobals["gGroupFontSize"] = (isset($ogGroup->fontsize)) ? $ogGroup->fontsize : $this->maGlobals["gGroupFontSize"]; |
---|
68 |
$this->maGlobals["gGroupIcon"] = (isset($ogGroup->icon)) ? $ogGroup->icon : $this->maGlobals["gGroupIcon"]; |
---|
69 |
$this->maGlobals["gGroupExtendAbstract"] = (isset($ogGroup->extendabstract)) ? $ogGroup->extendabstract : $this->maGlobals["gGroupExtendAbstract"]; |
---|
70 |
$this->maGlobals["gGroupVisible"] = (isset($ogGroup->visible)) ? $ogGroup->visible : $this->maGlobals["gGroupVisible"]; |
---|
71 |
} |
---|
72 |
|
---|
73 |
$this->maVals = array(); |
---|
74 |
|
---|
75 |
while( ($oTheme = $oThemes->getNextChild( "" )) != "" ) |
---|
76 |
{ |
---|
77 |
if ($oTheme->_type == "theme") |
---|
78 |
{ |
---|
79 |
if (!isset($this->maVals["theme"])) |
---|
80 |
$this->maVals["theme"] = array(); |
---|
81 |
|
---|
82 |
$aTheme = array(); |
---|
83 |
|
---|
84 |
$aTheme["theme_type"] = isset($oTheme->type) ? $oTheme->type : "checkbox"; |
---|
85 |
$aTheme["theme_abstract"] = isset($oTheme->abstract) ? $oTheme->abstract : ""; |
---|
86 |
$aTheme["theme_name"] = isset($oTheme->name) ? $oTheme->name : "theme"; |
---|
87 |
$aTheme["theme_bold"] = isset($oTheme->bold) ? $oTheme->bold : $this->maGlobals["gThemeBold"]; |
---|
88 |
$aTheme["theme_font"] = isset($oTheme->font) ? $oTheme->font : $this->maGlobals["gThemeFont"]; |
---|
89 |
$aTheme["theme_fontsize"] = isset($oTheme->fontsize) ? $oTheme->fontsize : $this->maGlobals["gThemeFontSize"]; |
---|
90 |
$aTheme["theme_icon"] = isset($oTheme->icon) ? $oTheme->icon : $this->maGlobals["gThemeIcon"]; |
---|
91 |
$aTheme["theme_extendabstract"] = isset($oTheme->extendabstract) ? $oTheme->extendabstract : $this->maGlobals["gThemeExtendAbstract"]; |
---|
92 |
$aTheme["theme_extralayers"] = isset($oTheme->extralayers) ? $oTheme->extralayers : "false"; |
---|
93 |
$aTheme["theme_numlayers"] = "0"; |
---|
94 |
//calculated values |
---|
95 |
$aTheme["theme_id"] = count( $this->maVals["theme"] ); |
---|
96 |
$aTheme["theme_input"] = ""; |
---|
97 |
$aTheme["theme_url"] = ""; |
---|
98 |
|
---|
99 |
if ($aTheme["theme_extralayers"] == "true") |
---|
100 |
{ |
---|
101 |
$this->maGlobals["gThemeExtraLayers"] = $aTheme["theme_id"]; |
---|
102 |
} |
---|
103 |
array_push( $this->maVals["theme"], $aTheme ); |
---|
104 |
|
---|
105 |
$this->maThemes[ $aTheme["theme_name"] ] = array(); |
---|
106 |
array_push( $this->maThemeIndex, $aTheme["theme_name"] ); |
---|
107 |
|
---|
108 |
while ( ($oGroup = $oTheme->getNextChild("")) != "" ) |
---|
109 |
{ |
---|
110 |
if ($oGroup->_type == "group") |
---|
111 |
{ |
---|
112 |
if (!isset($this->maVals["group"])) |
---|
113 |
$this->maVals["group"] = array(); |
---|
114 |
|
---|
115 |
$aGroup = array(); |
---|
116 |
|
---|
117 |
$aGroup["group_abstract"] = isset($oGroup->abstract) ? $oGroup->abstract : ""; |
---|
118 |
$aGroup["group_name"] = isset($oGroup->name) ? $oGroup->name : "group"; |
---|
119 |
$aGroup["group_bold"] = isset($oGroup->bold) ? $oGroup->bold : $this->maGlobals["gGroupBold"]; |
---|
120 |
$aGroup["group_font"] = isset($oGroup->font) ? $oGroup->font : $this->maGlobals["gGroupFont"]; |
---|
121 |
$aGroup["group_fontsize"] = isset($oGroup->fontsize) ? $oGroup->fontsize : $this->maGlobals["gGroupFontSize"]; |
---|
122 |
$aGroup["group_icon"] = isset($oGroup->icon) ? $oGroup->icon : $this->maGlobals["gGroupIcon"]; |
---|
123 |
$aGroup["group_extendabstract"] = isset($oGroup->extendabstract) ? $oGroup->extendabstract : $this->maGlobals["gGroupExtendAbstract"]; |
---|
124 |
$aGroup["group_visible"] = isset($oGroup->visible) ? $oGroup->visible : $this->maGlobals["gGroupVisible"]; |
---|
125 |
|
---|
126 |
//calculated values |
---|
127 |
$aGroup["group_id"] = count( $this->maVals["group"] ); |
---|
128 |
$aGroup["group_theme_id"] = $aTheme["theme_id"]; |
---|
129 |
$aGroup["group_input"] = ""; |
---|
130 |
$aGroup["group_url"] = ""; |
---|
131 |
|
---|
132 |
array_push( $this->maVals["group"], $aGroup ); |
---|
133 |
|
---|
134 |
$this->maThemes[ $aTheme["theme_name"] ][ $aGroup["group_name"] ] = array(); |
---|
135 |
|
---|
136 |
while ( ($oLayer = $oGroup->getNextChild("")) != "" ) |
---|
137 |
{ |
---|
138 |
if ($oLayer->_type == "layer" && isset( $oLayer->name )) |
---|
139 |
{ |
---|
140 |
$this->maThemes[ $aTheme["theme_name"] ][ $aGroup["group_name"] ][] = $oLayer->name; |
---|
141 |
$this->maLayers[ $oLayer->name ] = array(); |
---|
142 |
$this->maLayers[ $oLayer->name ]['theme'] = $aTheme["theme_name"]; |
---|
143 |
$this->maLayers[ $oLayer->name ]['group'] = $aGroup["group_name"]; |
---|
144 |
|
---|
145 |
} |
---|
146 |
} |
---|
147 |
} |
---|
148 |
} |
---|
149 |
} |
---|
150 |
} |
---|
151 |
$this->mnThemes = count($this->maThemes); |
---|
152 |
} |
---|
153 |
|
---|
154 |
/* ==================================================================== */ |
---|
155 |
/* ProcessExtraLayers adds layers in the mapfile but not in the */ |
---|
156 |
/* themefile to the legend. If there is a theme with */ |
---|
157 |
/* extralayers=true, they are added there, otherwise each layer */ |
---|
158 |
/* gets its own theme. */ |
---|
159 |
/* ==================================================================== */ |
---|
160 |
function ProcessExtraLayers($oMap) |
---|
161 |
{ |
---|
162 |
|
---|
163 |
$nLayers = $oMap->numlayers; |
---|
164 |
|
---|
165 |
for( $i=0; $i<$oMap->numlayers;$i++) |
---|
166 |
{ |
---|
167 |
$oLayer = $oMap->getlayer($i); |
---|
168 |
|
---|
169 |
$szLayerName = $oLayer->getmetadata( "WMS_NAME" ); |
---|
170 |
if ($szLayerName == "" ) |
---|
171 |
$szLayerName = $oLayer->name; |
---|
172 |
|
---|
173 |
//find layers not in themefile. |
---|
174 |
if (!isset($this->maLayers[$szLayerName])) |
---|
175 |
{ |
---|
176 |
//get extra layers theme id |
---|
177 |
$nExtraLayersTheme = $this->maGlobals["gThemeExtraLayers"]; |
---|
178 |
|
---|
179 |
//if extra layers is set, we add this layer to that theme as a |
---|
180 |
//group with a single layer. |
---|
181 |
//otherwise, add a theme and a group for the layer |
---|
182 |
if ($nExtraLayersTheme > -1) |
---|
183 |
{ |
---|
184 |
$aGroup = array(); |
---|
185 |
|
---|
186 |
$aGroup["group_abstract"] = isset($oGroup->abstract) ? $oGroup->abstract : ""; |
---|
187 |
$aGroup["group_name"] = $szLayerName; |
---|
188 |
$aGroup["group_bold"] = $this->maGlobals["gGroupBold"]; |
---|
189 |
$aGroup["group_font"] = $this->maGlobals["gGroupFont"]; |
---|
190 |
$aGroup["group_fontsize"] = $this->maGlobals["gGroupFontSize"]; |
---|
191 |
$aGroup["group_icon"] = $this->maGlobals["gGroupIcon"]; |
---|
192 |
$aGroup["group_extendabstract"] = $this->maGlobals["gGroupExtendAbstract"]; |
---|
193 |
$aGroup["group_visible"] = $this->maGlobals["gGroupVisible"]; |
---|
194 |
$aGroup['group_numlayers'] = "1"; |
---|
195 |
|
---|
196 |
//calculated values |
---|
197 |
$aGroup["group_id"] = count( $this->maVals["group"] ); |
---|
198 |
$aGroup["group_theme_id"] = $nExtraLayersTheme; |
---|
199 |
$aGroup["group_input"] = ""; |
---|
200 |
$aGroup["group_url"] = ""; |
---|
201 |
|
---|
202 |
$szThemeName = $this->GetTheme($nExtraLayersTheme); |
---|
203 |
|
---|
204 |
$this->maThemes[ "$szThemeName" ][ $aGroup["group_name"] ] = array(); |
---|
205 |
|
---|
206 |
$this->maThemes[ "$szThemeName" ][ $aGroup["group_name"] ][] = $szLayerName; |
---|
207 |
$this->maLayers[ $szLayerName ] = array(); |
---|
208 |
$this->maLayers[ $szLayerName ]['theme'] = $nExtraLayersTheme; |
---|
209 |
$this->maLayers[ $szLayerName ]['group'] = $aGroup["group_name"]; |
---|
210 |
array_push( $this->maVals["group"], $aGroup ); |
---|
211 |
|
---|
212 |
} |
---|
213 |
else |
---|
214 |
{ |
---|
215 |
$aTheme = array(); |
---|
216 |
$aTheme["theme_type"] = "checkbox"; |
---|
217 |
$aTheme["theme_abstract"] = ""; |
---|
218 |
$aTheme["theme_name"] = $szLayerName; |
---|
219 |
$aTheme["theme_bold"] = $this->maGlobals["gThemeBold"]; |
---|
220 |
$aTheme["theme_font"] = $this->maGlobals["gThemeFont"]; |
---|
221 |
$aTheme["theme_fontsize"] = $this->maGlobals["gThemeFontSize"]; |
---|
222 |
$aTheme["theme_icon"] = $this->maGlobals["gThemeIcon"]; |
---|
223 |
$aTheme["theme_extendabstract"] = $this->maGlobals["gThemeExtendAbstract"]; |
---|
224 |
$aTheme["theme_extralayers"] = "false"; |
---|
225 |
$aTheme['theme_numlayers'] = "1"; |
---|
226 |
|
---|
227 |
//calculated values |
---|
228 |
$aTheme["theme_id"] = count( $this->maVals["theme"] ); |
---|
229 |
$aTheme["theme_input"] = ""; |
---|
230 |
$aTheme["theme_url"] = ""; |
---|
231 |
|
---|
232 |
array_push( $this->maVals["theme"], $aTheme ); |
---|
233 |
|
---|
234 |
$this->maThemes[ $aTheme["theme_name"] ] = array(); |
---|
235 |
array_push( $this->maThemeIndex, $aTheme["theme_name"] ); |
---|
236 |
|
---|
237 |
$aGroup = array(); |
---|
238 |
|
---|
239 |
$aGroup["group_abstract"] = isset($oGroup->abstract) ? $oGroup->abstract : ""; |
---|
240 |
$aGroup["group_name"] = $szLayerName; |
---|
241 |
$aGroup["group_bold"] = $this->maGlobals["gGroupBold"]; |
---|
242 |
$aGroup["group_font"] = $this->maGlobals["gGroupFont"]; |
---|
243 |
$aGroup["group_fontsize"] = $this->maGlobals["gGroupFontSize"]; |
---|
244 |
$aGroup["group_icon"] = $this->maGlobals["gGroupIcon"]; |
---|
245 |
$aGroup["group_extendabstract"] = $this->maGlobals["gGroupExtendAbstract"]; |
---|
246 |
$aGroup["group_visible"] = "false"; |
---|
247 |
$aGroup['group_numlayers'] = "1"; |
---|
248 |
|
---|
249 |
//calculated values |
---|
250 |
$aGroup["group_id"] = count( $this->maVals["group"] ); |
---|
251 |
$aGroup["group_theme_id"] = $aTheme["theme_id"]; |
---|
252 |
$aGroup["group_input"] = ""; |
---|
253 |
$aGroup["group_url"] = ""; |
---|
254 |
|
---|
255 |
$this->maThemes[ $aTheme["theme_name"] ][ $aGroup["group_name"] ][] = $szLayerName; |
---|
256 |
$this->maLayers[ $szLayerName ] = array(); |
---|
257 |
$this->maLayers[ $szLayerName ]['theme'] = $aTheme["theme_name"]; |
---|
258 |
$this->maLayers[ $szLayerName ]['group'] = $aGroup["group_name"]; |
---|
259 |
|
---|
260 |
array_push( $this->maVals["group"], $aGroup ); |
---|
261 |
|
---|
262 |
} |
---|
263 |
|
---|
264 |
} |
---|
265 |
} |
---|
266 |
} |
---|
267 |
|
---|
268 |
function GetNumberOfThemes() |
---|
269 |
{ |
---|
270 |
return $this->mnThemes; |
---|
271 |
} |
---|
272 |
|
---|
273 |
function GetTheme($i) |
---|
274 |
{ |
---|
275 |
if ($i>=0 && $i<$this->mnThemes) |
---|
276 |
{ |
---|
277 |
return $this->maThemeIndex[$i]; |
---|
278 |
} |
---|
279 |
} |
---|
280 |
|
---|
281 |
function GetThemeIndex( $szTheme ) |
---|
282 |
{ |
---|
283 |
return array_search( $szTheme, $this->maThemeIndex ); |
---|
284 |
} |
---|
285 |
|
---|
286 |
function GetThemeAttribute( $szTheme, $szAttribute ) |
---|
287 |
{ |
---|
288 |
$idx = $this->GetThemeIndex( $szTheme ); |
---|
289 |
if( isset( $this->maVals["theme"][$idx][$szAttribute] ) ) |
---|
290 |
return $this->maVals["theme"][$idx][$szAttribute]; |
---|
291 |
else |
---|
292 |
return ""; |
---|
293 |
} |
---|
294 |
|
---|
295 |
function GetGroupIndex( $szTheme, $szGroup ) |
---|
296 |
{ |
---|
297 |
$theme_id = $this->GetThemeIndex( $szTheme ); |
---|
298 |
|
---|
299 |
foreach( $this->maVals["group"] as $idx => $aGroup ) |
---|
300 |
{ |
---|
301 |
if ($aGroup["group_theme_id"] == $theme_id && $aGroup["group_name"] == $szGroup ) |
---|
302 |
return $idx; |
---|
303 |
} |
---|
304 |
} |
---|
305 |
|
---|
306 |
function GetGroupAttribute( $szTheme, $szGroup, $szAttribute ) |
---|
307 |
{ |
---|
308 |
$idx = $this->GetGroupIndex( $szTheme, $szGroup ); |
---|
309 |
if( isset( $this->maVals["group"][$idx][$szAttribute] ) ) |
---|
310 |
return $this->maVals["group"][$idx][$szAttribute]; |
---|
311 |
else |
---|
312 |
return ""; |
---|
313 |
} |
---|
314 |
|
---|
315 |
function GetNumGroups($szTheme) |
---|
316 |
{ |
---|
317 |
if (isset($this->maThemes[trim($szTheme)])) |
---|
318 |
{ |
---|
319 |
$idx = $this->GetThemeIndex( $szTheme ); |
---|
320 |
if ($this->maVals["theme"][$idx]["theme_type"] == "radio") |
---|
321 |
$result = 1; |
---|
322 |
else |
---|
323 |
$result = count($this->maThemes[trim($szTheme)]); |
---|
324 |
return $result; |
---|
325 |
} |
---|
326 |
|
---|
327 |
return 0; |
---|
328 |
} |
---|
329 |
|
---|
330 |
function GetGroups( $szTheme ) |
---|
331 |
{ |
---|
332 |
if (isset($this->maThemes[trim($szTheme)])) |
---|
333 |
return $this->maThemes[trim($szTheme)]; |
---|
334 |
else |
---|
335 |
return array(); |
---|
336 |
} |
---|
337 |
} |
---|
338 |
|
---|
339 |
?> |
---|