Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezezgenerator.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezezgenerator.php 6206 2001-07-19 12:19:22Z jakobn $
5 //
6 // Definition of eZEzGenerator class
7 //
8 // Created on: <26-Oct-2000 13:45:54 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
40 class eZEzGenerator
41 {
45 function __construct( &$contents )
46 {
47 $this->PageCount = 0;
48 $this->Contents = $contents;
49 }
50
54 function &generateXML()
55 {
56 // add the XML header.
57 $newContents = "<?xml version=\"1.0\"?>";
58
59 //add the generator, this is used for rendering.
60 $newContents .= "<article><generator>ez</generator>\n";
61
62 //add the contents
63 $newContents .= "<intro>" . strip_tags( $this->Contents[0] ) . "</intro>";
64
65 // get every page in an array
66 $pages = split( "<page>" , $this->Contents[1] );
67
68 $body = "";
69 foreach ( $pages as $page )
70 {
71 $tmpPage = $page;
72
73 // parse the <image id align size> tag and convert it
74 // to <image id="id" align="align" size="size" />
75
76 $tmpPage = preg_replace( "/(<image\s+?([^ ]+)\s+?([^ ]+)\s+?([^( |>)]+)([^>]*?)>)/", "<image id=\"\\2\" align=\"\\3\" size=\"\\4\" />", $tmpPage );
77
78 // convert <link ez.no ez systems> to valid xml
79 // $tmpPage = "<link ez.no ez systems> <link ez.no ez systems>";
80 $tmpPage = preg_replace( "#(<link\s+?([^ ]+)\s+?([^>]+)>)#", "<link href=\"\\2\" text=\"\\3\" />", $tmpPage );
81
82 // same as above for <ezlink ez.no ez systems> a design difference.
83 $tmpPage = preg_replace( "#(<ezlink\s+?([^ ]+)\s+?([^>]+)>)#", "<ezlink href=\"\\2\" text=\"\\3\" />", $tmpPage );
84
85 // convert <ezanchor anchor> to <ezanchor href="anchor" />
86 $tmpPage = preg_replace( "#<ezanchor\s+?(.*?)>#", "<ezanchor href=\"\\1\" />", $tmpPage );
87
88 // convert <mail adresse@domain.tld subject line, link text>
89 // to valid xml
90 $tmpPage = preg_replace( "#<mail\s+?([^ ]*?)\s+?(.*?),\s+?([^>]*?)>#", "<mail to=\"\\1\" subject=\"\\2\" text=\"\\3\" />", $tmpPage );
91
92
93 // replace & with &amp; to prevent killing the xml parser..
94 // is that a bug in the xmltree(); function ? answer to bf@ez.no
95 $tmpPage = ereg_replace ( "&", "&amp;", $tmpPage );
96
97 // make unknown tags readable.. look-ahead assertion is used ( ?! )
98 $tmpPage = preg_replace( "/<(?!(page|php|\/|image|hea|lin|bol|ita|und|str|pre|ver|lis|ezlink|ezanchor|mail))/", "&lt;", $tmpPage );
99
100 // look-behind assertion is used here (?<!)
101 // the expression must be fixed with eg just use the 3 last letters of the tag
102
103 $tmpPage = preg_replace( "#(?<!(age|php|age|der|old|lic|ine|ike|pre|tim|isp))>#", "&gt;", $tmpPage );
104 // make better..
105 $tmpPage = preg_replace( "#/&gt;#", "/>", $tmpPage );
106
107
108 $body .= "<page>" . $tmpPage . "</page>";
109 }
110
111
112 $this->PageCount = count( $pages );
113
114
115 $newContents .= "<body>" . $body . "</body></article>";
116
117 return $newContents;
118 }
119
123 function &decodeXML()
124 {
125 $contentsArray = array();
126
127 $xml = xmltree( $this->Contents );
128
129 if ( !$xml )
130 {
131 print( "<br /><b>Error: eZEzRenderer::docodeXML() could not decode XML</b><br />" );
132 }
133 else
134 {
135 $into = "";
136 $body = "";
137
138 foreach ( $xml->root->children as $child )
139 {
140 if ( $child->name == "intro" )
141 {
142 $intro = $child->children[0]->content;
143 }
144
145
146 if ( $child->name == "body" )
147 {
148 $body = $child->children;
149 }
150 }
151
152 $contentsArray[] = $intro;
153
154 $bodyContents = "";
155 $i=0;
156 // loop on the pages
157 foreach ( $body as $page )
158 {
159 $pageContent = "";
160 // loop on the contents of the pages
161 foreach ( $page->children as $paragraph )
162 {
163 // ordinary text
164 if ( $paragraph->name == "text" )
165 {
166 $pageContent .= $paragraph->content;
167 }
168
169 // header
170 if ( $paragraph->name == "header" )
171 {
172 $pageContent .= "<header>" . $paragraph->children[0]->content . "</header>";
173 }
174
175
176 // php code
177 if ( $paragraph->name == "php" )
178 {
179 $pageContent .= "<php>" . $paragraph->children[0]->content . "</php>";
180 }
181
182 // image
183 if ( $paragraph->name == "image" )
184 {
185 foreach ( $paragraph->attributes as $imageItem )
186 {
187 switch ( $imageItem->name )
188 {
189
190 case "id" :
191 {
192 $imageID = $imageItem->children[0]->content;
193 }
194 break;
195
196 case "align" :
197 {
198 $imageAlignment = $imageItem->children[0]->content;
199 }
200 break;
201
202 case "size" :
203 {
204 $imageSize = $imageItem->children[0]->content;
205 }
206 break;
207
208 }
209 }
210
211 $pageContent .= "<image $imageID $imageAlignment $imageSize>";
212 }
213
214 // link
215 if ( $paragraph->name == "link" )
216 {
217 foreach ( $paragraph->attributes as $imageItem )
218 {
219 // print( $imageItem->name );
220 switch ( $imageItem->name )
221 {
222
223 case "href" :
224 {
225 $href = $imageItem->children[0]->content;
226 }
227 break;
228
229 case "text" :
230 {
231 $text = $imageItem->children[0]->content;
232 }
233 break;
234
235 }
236 }
237
238 $pageContent .= "<link $href $text>";
239 }
240
241 // link
242 if ( $paragraph->name == "ezlink" )
243 {
244 foreach ( $paragraph->attributes as $imageItem )
245 {
246 // print( $imageItem->name );
247 switch ( $imageItem->name )
248 {
249
250 case "href" :
251 {
252 $href = $imageItem->children[0]->content;
253 }
254 break;
255
256 case "text" :
257 {
258 $text = $imageItem->children[0]->content;
259 }
260 break;
261
262 }
263 }
264
265 $pageContent .= "<ezlink $href $text>";
266 }
267
268
269 // mail
270 if ( $paragraph->name == "mail" )
271 {
272 foreach ( $paragraph->attributes as $mailItem )
273 {
274 switch ( $mailItem->name )
275 {
276 case "to" :
277 {
278 $to = $mailItem->children[0]->content;
279 }
280 break;
281
282 case "subject" :
283 {
284 $subject = $mailItem->children[0]->content;
285 }
286 break;
287
288 case "text" :
289 {
290 $text = $mailItem->children[0]->content;
291 }
292 break;
293 }
294 }
295
296 $pageContent .= "<mail $to $subject, $text>";
297 }
298
299 // ez anchor
300 if ( $paragraph->name == "ezanchor" )
301 {
302 foreach ( $paragraph->attributes as $anchorItem )
303 {
304 switch ( $anchorItem->name )
305 {
306 case "href" :
307 {
308 $href = $anchorItem->children[0]->content;
309 }
310 break;
311 }
312 }
313
314 $pageContent .= "<ezanchor $href>";
315 }
316
317
318 // bold text
319 if ( $paragraph->name == "bold" )
320 {
321 $pageContent .= "<bold>" . $paragraph->children[0]->content . "</bold>";
322 }
323
324 // italic text
325 if ( $paragraph->name == "italic" )
326 {
327 $pageContent .= "<italic>" . $paragraph->children[0]->content . "</italic>";
328 }
329
330 // underline text
331 if ( $paragraph->name == "underline" )
332 {
333 $pageContent .= "<underline>" . $paragraph->children[0]->content . "</underline>";
334 }
335
336 // strike text
337 if ( $paragraph->name == "strike" )
338 {
339 $pageContent .= "<strike>" . $paragraph->children[0]->content . "</strike>";
340 }
341
342 // pre defined text
343 if ( $paragraph->name == "pre" )
344 {
345 $pageContent .= "<pre>" . $paragraph->children[0]->content . "</pre>";
346 }
347
348 // verbatim text
349 if ( $paragraph->name == "verbatim" )
350 {
351 $pageContent .= "<verbatim>" . $paragraph->children[0]->content . "</verbatim>";
352 }
353 }
354
355 if ( $i > 0 )
356 $bodyContents .= "<page>" . $pageContent;
357 else
358 $bodyContents .= $pageContent;
359
360 $i++;
361 }
362
363 $contentsArray[] = $bodyContents;
364 }
365
366 return $contentsArray;
367 }
368
372 function pageCount( )
373 {
374 return $this->PageCount;
375 }
376
377 var $Contents;
378 var $PageCount;
379 }
380
381 ?>
$i
$i
Definition: admin/adlist.php:91
eZEzGenerator
Definition: ezezgenerator.php:41
eZEzGenerator\generateXML
& generateXML()
Definition: ezezgenerator.php:54
eZEzGenerator\__construct
__construct(&$contents)
Definition: ezezgenerator.php:45
eZEzGenerator\pageCount
pageCount()
Definition: ezezgenerator.php:372
eZEzGenerator\decodeXML
& decodeXML()
Definition: ezezgenerator.php:123
eZEzGenerator\$PageCount
$PageCount
Definition: ezezgenerator.php:378
eZEzGenerator\$Contents
$Contents
Definition: ezezgenerator.php:377
$page
$page
Definition: ezarticle/modules/content.php:28
$contents
$contents
Definition: ezarticle/user/extendedsearch.php:52
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.