Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

eztechgenerator.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: eztechgenerator.php 9328 2002-03-04 12:49:40Z bf $
5 //
6 // Definition of eZTechGenerator class
7 //
8 // Created on: <18-Oct-2000 15:55:16 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
29
32
42 // include_once( "ezxml/classes/ezxml.php" );
43
44 class eZTechGenerator
45 {
49 function __construct( &$contents )
50 {
51 $this->Level = 0;
52 $this->PageCount = 0;
53 $this->Contents = $contents;
54 }
55
59 function &generateXML()
60 {
61 // add the XML header.
62 $newContents = "<?xml version=\"1.0\"?>";
63
64 //add the generator, this is used for rendering.
65 $newContents .= "<article><generator>tech</generator>\n";
66
67 //add the contents
68 // What does strip_tags do? needed anymore?
69 // $newContents .= "<intro>" . strip_tags( $this->Contents[0], "<bold>,<italic>,<strike>,<underline>" ) . "</intro>";
70 $newContents .= "<intro>" . $this->generatePage( $this->Contents[0] ) . "</intro>";
71
72 // get every page in an array
73 $pages = split( "<page>" , $this->Contents[1] );
74
75 $body = "";
76 foreach ( $pages as $page )
77 {
78 $tmpPage = $page;
79
80 $tmpPage = $this->generatePage( $tmpPage );
81
82 $body .= "<page>" . $tmpPage . "</page>";
83 }
84
85 $this->PageCount = count( $pages );
86
87
88 $newContents .= "<body>" . $body . "</body></article>";
89
90 return $newContents;
91 }
92
97 function &generatePage( $tmpPage )
98 {
99 $tmpPage = $this->generateImage( $tmpPage );
100
101 $tmpPage = $this->generateLink( $tmpPage );
102
103 $tmpPage = $this->generateModule( $tmpPage );
104
105 // replace & with &amp; to prevent killing the xml parser..
106 // is that a bug in the xmltree(); function ? answer to bf@ez.no
107 $tmpPage = ereg_replace ( "&", "&amp;", $tmpPage );
108
109 $tmpPage = $this->generateHTML( $tmpPage );
110
111 $tmpPage = $this->generateUnknowns( $tmpPage );
112
113 return $tmpPage;
114 }
115
120 function &generateUnknowns( $tmpPage )
121 {
122 // make unknown tags readable.. look-ahead assertion is used ( ?! )
123 $tmpPage = preg_replace( "/<(?!(page|php|\/|image|cpp|shell|sql|hea|lin|iconlink|per|bol|ita|und|str|pre|ver|lis|ezhtml|html|java|ezanchor|mail|module|bullet))/", "&lt;", $tmpPage );
124
125 // look-behind assertion is used here (?<!)
126 // the expression must be fixed width eg just use the 3 last letters of the tag
127
128 $tmpPage = preg_replace( "#(?<!(age|php|age|cpp|ell|sql|der|erl|old|lic|ine|ike|pre|tim|isp|tml|ava|let))>#", "&gt;", $tmpPage );
129 // make better..
130 $tmpPage = preg_replace( "#/&gt;#", "/>", $tmpPage );
131
132 return $tmpPage;
133 }
134
135 function &generateHTML( $tmpPage )
136 {
137 // Begin html tag replacer
138 // replace all < and > between <ezhtml> and </ezhtml>
139 // and to the same for <php> </php>
140 // ok this is a bit slow code, but it works
141 $startHTMLTag = "<html>";
142 $endHTMLTag = "</html>";
143
144 $starteZHTMLTag = "<ezhtml>";
145 $endeZHTMLTag = "</ezhtml>";
146
147 $startPHPTag = "<php>";
148 $endPHPTag = "</php>";
149
150 $numberBeginHTML = substr_count( $tmpPage, $startHTMLTag );
151 $numEndHTML = substr_count( $tmpPage, $endHTMLTag );
152
153 if ( $numberBeginHTML != $numEndHTML )
154 {
155 print( "Unmatched ezhtml tags, check that you have end tags for all begin tags" );
156 }
157
158 $numberBegineZHTML = substr_count( $tmpPage, $starteZHTMLTag );
159 $numEndeZHTML = substr_count( $tmpPage, $endeZHTMLTag );
160
161 if ( $numberBegineZHTML != $numEndeZHTML )
162 {
163 print( "Unmatched ezhtml tags, check that you have end tags for all begin tags" );
164 }
165
166 $numberBeginPHP = substr_count( $tmpPage, $startPHPTag );
167 $numEndPHP = substr_count( $tmpPage, $endPHPTag );
168
169 if ( $numberBegin != $numEnd )
170 {
171 print( "Unmatched PHP tags, check that you have end tags for all begin tags" );
172 }
173
174 if ( ( $numberBeginPHP > 0 ) || ( $numberBegineZHTML > 0 ) || ( $numberBeginHTML > 0 ) )
175 {
176 $resultPage = "";
177 $isInsideHTML = false;
178 $isInsideeZHTML = false;
179 $isInsidePHP = false;
180 for ( $i=0; $i<strlen( $tmpPage ); $i++ )
181 {
182 if ( substr( $tmpPage, $i - strlen( $startHTMLTag ), strlen( $startHTMLTag ) ) == $startHTMLTag )
183 {
184 $isInsideHTMLTag = true;
185 }
186
187 if ( substr( $tmpPage, $i, strlen( $endHTMLTag ) ) == $endHTMLTag )
188 {
189 $isInsideHTMLTag = false;
190 }
191
192 if ( substr( $tmpPage, $i - strlen( $starteZHTMLTag ), strlen( $starteZHTMLTag ) ) == $starteZHTMLTag )
193 {
194 $isInsideeZHTMLTag = true;
195 }
196
197 if ( substr( $tmpPage, $i, strlen( $endeZHTMLTag ) ) == $endeZHTMLTag )
198 {
199 $isInsideeZHTMLTag = false;
200 }
201
202 if ( substr( $tmpPage, $i - strlen( $startPHPTag ), strlen( $startPHPTag ) ) == $startPHPTag )
203 {
204 $isInsidePHPTag = true;
205 }
206
207 if ( substr( $tmpPage, $i, strlen( $endPHPTag ) ) == $endPHPTag )
208 {
209 $isInsidePHPTag = false;
210 }
211
212 if ( ( $isInsideHTMLTag == true ) || ( $isInsideeZHTMLTag == true ) || ( $isInsidePHPTag == true ) )
213 {
214 switch ( $tmpPage[$i] )
215 {
216 case "<" :
217 {
218 $resultPage .= "&lt;";
219 }
220 break;
221
222 case ">" :
223 {
224 $resultPage .= "&gt;";
225 }
226 break;
227
228 default:
229 {
230 $resultPage .= $tmpPage[$i];
231 }
232 }
233 }
234 else
235 {
236 $resultPage .= $tmpPage[$i];
237 }
238 }
239
240 $tmpPage = $resultPage;
241 }
242 return $tmpPage;
243 }
244
249 function &generateLink( $tmpPage )
250 {
251 // convert <link ez.no ez systems> to valid xml
252 // $tmpPage = "<link ez.no ez systems> <link ez.no ez systems>";
253 $tmpPage = preg_replace( "#(<link\s+?([^ ]+)\s+?([^>]+)>)#", "<link href=\"\\2\" text=\"\\3\" />", $tmpPage );
254
255 $tmpPage = preg_replace( "#(<iconlink\s+?([^ ]+)\s+?([^>]+)>)#", "<iconlink href=\"\\2\" text=\"\\3\" />", $tmpPage );
256
257 // convert <ezanchor anchor> to <ezanchor href="anchor" />
258 $tmpPage = preg_replace( "#<ezanchor\s+?(.*?)>#", "<ezanchor href=\"\\1\" />", $tmpPage );
259
260 // convert <mail adresse@domain.tld subject line, link text>
261 // to valid xml
262 $tmpPage = preg_replace( "#<mail\s+?([^ ]*?)\s+?(.*?),\s+?([^>]*?)>#", "<mail to=\"\\1\" subject=\"\\2\" text=\"\\3\" />", $tmpPage );
263
264 return $tmpPage;
265 }
266
271 function &generateModule( $tmpPage )
272 {
273 // convert <module modulename>
274 // to <module name="modulename" />
275 $tmpPage = preg_replace( "#(<module\s+([^ ]+?)\s*>)#", "<module name=\"\\2\" />", $tmpPage );
276
277 return $tmpPage;
278 }
279
283 function &generateImage( $tmpPage )
284 {
285 // parse the <image id align size> tag and convert it
286 // to <image id="id" align="align" size="size" />
287 $tmpPage = preg_replace( "/(<image\s+?([^ ]+)\s+?([^ ]+)\s+?([^( |>)]+)([^>]*?)>)/", "<image id=\"\\2\" align=\"\\3\" size=\"\\4\" />", $tmpPage );
288
289 $tmpPage = preg_replace( "/(<image\s+?([0-9]+?)>)/", "<image id=\"\\2\" align=\"float\" size=\"medium\" />", $tmpPage );
290
291 return $tmpPage;
292 }
293
294
298 function &decodeXML()
299 {
300 $contentsArray = array();
301
302 $xml =& eZXML::domTree( $this->Contents );
303
304 // $xml =& qdom_tree( $this->Contents );
305
306 if ( !$xml )
307 {
308 print( "<br /><b>Error: eZTechRenderer::docodeXML() could not decode XML</b><br />" );
309 }
310 else
311 {
312 $into = "";
313 $body = "";
314
315 foreach ( $xml->children as $child )
316 {
317 if ( $child->name == "article" )
318 {
319 foreach ( $child->children as $article )
320 {
321 if ( $article->name == "intro" )
322 {
323 $intro = $this->decodePage( $article );
324 }
325
326 if ( $article->name == "body" )
327 {
328 $body = $article->children;
329 }
330
331 }
332 }
333 }
334
335 $contentsArray[] = $intro;
336
337
338 $bodyContents = "";
339 $i=0;
340 // loop on the pages
341 foreach ( $body as $page )
342 {
343 $pageContent = "";
344
345 $pageContent = $this->decodePage( $page );
346
347 if ( $i > 0 )
348 $bodyContents .= "<page>" . $pageContent;
349 else
350 $bodyContents .= $pageContent;
351
352 $i++;
353 }
354
355 $contentsArray[] = $bodyContents;
356 }
357
358 return $contentsArray;
359 }
360
365 function decodePage( $page )
366 {
367 $value = "";
368 if ( count( $page->children ) > 0 )
369 {
370 foreach ( $page->children as $paragraph )
371 {
372 // ordinary text
373 if ( $this->Level == 0 )
374 {
375 if ( $paragraph->name == "text" || $paragraph->name == "#text" )
376 {
377 $value .= $paragraph->content;
378 }
379 }
380
381 // decode sub items
382 $this->Level = $this->Level + 1;
383 $subitem = $this->decodePage( $paragraph );
384 $this->Level = $this->Level - 1;
385
386 // can have sub items
387 $value = $this->decodeStandards( $value, $paragraph, $subitem );
388
389 // can not have sub items
390 $value = $this->decodeImage( $value, $paragraph );
391 $value = $this->decodeLink( $value, $paragraph );
392 $value = $this->decodeModule( $value, $paragraph );
393 $value = $this->decodeCode( $value, $paragraph );
394 }
395 }
396
397 return $value;
398 }
399
400
401 function &decodeCode( $pageContent, $paragraph )
402 {
403 // php code
404 if ( $paragraph->name == "php" )
405 {
406 $pageContent .= "<php>" . $paragraph->children[0]->content . "</php>";
407 }
408
409 // ezhtml code
410 if ( $paragraph->name == "ezhtml" )
411 {
412 $pageContent .= "<ezhtml>" . $paragraph->children[0]->content . "</ezhtml>";
413 }
414
415 // html code
416 if ( $paragraph->name == "html" )
417 {
418 $pageContent .= "<html>" . $paragraph->children[0]->content . "</html>";
419 }
420
421 // java code
422 if ( $paragraph->name == "java" )
423 {
424 $pageContent .= "<java>" . $paragraph->children[0]->content . "</java>";
425 }
426
427 // sql code
428 if ( $paragraph->name == "sql" )
429 {
430 $pageContent .= "<sql>" . $paragraph->children[0]->content . "</sql>";
431 }
432
433 // shell code
434 if ( $paragraph->name == "shell" )
435 {
436 $pageContent .= "<shell>" . $paragraph->children[0]->content . "</shell>";
437 }
438
439 // c++ code
440 if ( $paragraph->name == "cpp" )
441 {
442 $pageContent .= "<cpp>" . $paragraph->children[0]->content . "</cpp>";
443 }
444
445 // perl code
446 if ( $paragraph->name == "perl" )
447 {
448 $pageContent .= "<perl>" . $paragraph->children[0]->content . "</perl>";
449 }
450
451 // lisp code
452 if ( $paragraph->name == "lisp" )
453 {
454 $pageContent .= "<lisp>" . $paragraph->children[0]->content . "</lisp>";
455 }
456
457
458
459 return $pageContent;
460 }
461
466 function &decodeImage( $pageContent, $paragraph )
467 {
468 // image
469 if ( $paragraph->name == "image" )
470 {
471 foreach ( $paragraph->attributes as $imageItem )
472 {
473 switch ( $imageItem->name )
474 {
475
476 case "id" :
477 {
478 $imageID = $imageItem->children[0]->content;
479 }
480 break;
481
482 case "align" :
483 {
484 $imageAlignment = $imageItem->children[0]->content;
485 }
486 break;
487
488 case "size" :
489 {
490 $imageSize = $imageItem->children[0]->content;
491 }
492 break;
493
494 }
495 }
496
497 $pageContent .= "<image $imageID $imageAlignment $imageSize>";
498 }
499 return $pageContent;
500 }
501
505 function &decodeLink( $pageContent, $paragraph )
506 {
507 // link
508 if ( $paragraph->name == "link" )
509 {
510 foreach ( $paragraph->attributes as $imageItem )
511 {
512 // print( $imageItem->name );
513 switch ( $imageItem->name )
514 {
515
516 case "href" :
517 {
518 $href = $imageItem->children[0]->content;
519 }
520 break;
521
522 case "text" :
523 {
524 $text = $imageItem->children[0]->content;
525 }
526 break;
527
528 }
529 }
530
531 $pageContent .= "<link $href $text>";
532 }
533
534 if ( $paragraph->name == "iconlink" )
535 {
536 foreach ( $paragraph->attributes as $imageItem )
537 {
538 // print( $imageItem->name );
539 switch ( $imageItem->name )
540 {
541
542 case "href" :
543 {
544 $href = $imageItem->children[0]->content;
545 }
546 break;
547
548 case "text" :
549 {
550 $text = $imageItem->children[0]->content;
551 }
552 break;
553
554 }
555 }
556
557 $pageContent .= "<iconlink $href $text>";
558 }
559
560
561 // mail
562 if ( $paragraph->name == "mail" )
563 {
564 foreach ( $paragraph->attributes as $mailItem )
565 {
566 switch ( $mailItem->name )
567 {
568 case "to" :
569 {
570 $to = $mailItem->children[0]->content;
571 }
572 break;
573
574 case "subject" :
575 {
576 $subject = $mailItem->children[0]->content;
577 }
578 break;
579
580 case "text" :
581 {
582 $text = $mailItem->children[0]->content;
583 }
584 break;
585 }
586 }
587
588 $pageContent .= "<mail $to $subject, $text>";
589 }
590
591 // ez anchor
592 if ( $paragraph->name == "ezanchor" )
593 {
594 foreach ( $paragraph->attributes as $anchorItem )
595 {
596 switch ( $anchorItem->name )
597 {
598 case "href" :
599 {
600 $href = $anchorItem->children[0]->content;
601 }
602 break;
603 }
604 }
605
606 $pageContent .= "<ezanchor $href>";
607 }
608
609 return $pageContent;
610 }
611
616 function &decodeModule( $pageContent, $paragraph )
617 {
618 // module
619 if ( $paragraph->name == "module" )
620 {
621 foreach ( $paragraph->attributes as $moduleItem )
622 {
623 switch ( $moduleItem->name )
624 {
625 case "name" :
626 {
627 $name = $moduleItem->children[0]->content;
628 }
629 break;
630 }
631 }
632 $pageContent .= "<module $name>";
633 }
634 return $pageContent;
635 }
636
637 function &decodeStandards( $pageContent, $paragraph, $subitem )
638 {
639
640 // header
641 if ( $paragraph->name == "header" )
642 {
643 $pageContent .= "<header>" . $paragraph->children[0]->content . "</header>";
644 }
645
646 // bold text
647 if ( $paragraph->name == "bold" )
648 {
649 $pageContent .= "<bold>" . $paragraph->children[0]->content . "</bold>";
650 }
651
652 // italic text
653 if ( $paragraph->name == "italic" )
654 {
655 $pageContent .= "<italic>" . $paragraph->children[0]->content . "</italic>";
656 }
657
658 // underline text
659 if ( $paragraph->name == "underline" )
660 {
661 $pageContent .= "<underline>" . $paragraph->children[0]->content . "</underline>";
662 }
663
664 // strike text
665 if ( $paragraph->name == "strike" )
666 {
667 $pageContent .= "<strike>" . $paragraph->children[0]->content . "</strike>";
668 }
669
670 // pre defined text
671 if ( $paragraph->name == "pre" )
672 {
673 $pageContent .= "<pre>" . $paragraph->children[0]->content . "</pre>";
674 }
675
676 // verbatim text
677 if ( $paragraph->name == "verbatim" )
678 {
679 $pageContent .= "<verbatim>" . $paragraph->children[0]->content . "</verbatim>";
680 }
681
682 // bullet list
683 if ( $paragraph->name == "bullet" )
684 {
685 $pageContent .= "<bullet>" . $paragraph->children[0]->content . $subitem . "</bullet>";
686 }
687
688 return $pageContent;
689 }
690
694 function pageCount( )
695 {
696 return $this->PageCount;
697 }
698
699 var $Contents;
700 var $PageCount;
701
702 var $Level;
703 }
704
705 ?>
$i
$i
Definition: admin/adlist.php:91
$article
$article
Definition: articlelog.php:45
eZTechGenerator
Definition: eztechgenerator.php:45
eZTechGenerator\generateXML
& generateXML()
Definition: eztechgenerator.php:59
eZTechGenerator\generateUnknowns
& generateUnknowns( $tmpPage)
Definition: eztechgenerator.php:120
eZTechGenerator\decodeLink
& decodeLink( $pageContent, $paragraph)
Definition: eztechgenerator.php:505
eZTechGenerator\decodeXML
& decodeXML()
Definition: eztechgenerator.php:298
eZTechGenerator\generateImage
& generateImage( $tmpPage)
Definition: eztechgenerator.php:283
eZTechGenerator\$Level
$Level
Definition: eztechgenerator.php:702
eZTechGenerator\decodeStandards
& decodeStandards( $pageContent, $paragraph, $subitem)
Definition: eztechgenerator.php:637
eZTechGenerator\generateLink
& generateLink( $tmpPage)
Definition: eztechgenerator.php:249
eZTechGenerator\generateModule
& generateModule( $tmpPage)
Definition: eztechgenerator.php:271
eZTechGenerator\$Contents
$Contents
Definition: eztechgenerator.php:699
eZTechGenerator\decodePage
decodePage( $page)
Definition: eztechgenerator.php:365
eZTechGenerator\generateHTML
& generateHTML( $tmpPage)
Definition: eztechgenerator.php:135
eZTechGenerator\pageCount
pageCount()
Definition: eztechgenerator.php:694
eZTechGenerator\decodeModule
& decodeModule( $pageContent, $paragraph)
Definition: eztechgenerator.php:616
eZTechGenerator\decodeCode
& decodeCode( $pageContent, $paragraph)
Definition: eztechgenerator.php:401
eZTechGenerator\$PageCount
$PageCount
Definition: eztechgenerator.php:700
eZTechGenerator\__construct
__construct(&$contents)
Definition: eztechgenerator.php:49
eZTechGenerator\decodeImage
& decodeImage( $pageContent, $paragraph)
Definition: eztechgenerator.php:466
eZTechGenerator\generatePage
& generatePage( $tmpPage)
Definition: eztechgenerator.php:97
eZXML\domTree
static domTree( $xmlDoc, $params=array())
Definition: ezxml.php:60
$name
$name
Definition: companytypelist.php:194
$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+.