<?php
//
// $Id: eztechrenderer.php,v 1.38 2000/11/09 15:01:46 bf-cvs Exp $
//
// Definition of eZTechRenderer class
//
// B�rd Farstad <bf@ez.no>
// Created on: <18-Oct-2000 17:45:32 bf>
//
// This source file is part of eZ publish, publishing software.
// Copyright (C) 1999-2000 eZ systems as
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
//
//!! eZArticle
//! eZTechRenderer renders XML contents into html articles.
/*!
This class wil decode the tech articles generated by eZTechGenerator.
Supported tags:
\code
<page> - pagebreak
<header>
Header text
</header>
<link ez.no text to the link> - anchor
<mail adresse@domain.tld?subject="subject line" link text> - anchor to email address with subject
<image 42 align size> - image tag, 42 is the id, alignment (left|center|right), size (small|medium|large)
<ezanchor anchorname>
<cpp>
cpp code
</cpp>
<php>
php code
</php>
<java>
java code
</java>
<ezhtml>
html code
</ezhtml>
<shell>
shell code
</shell>
<sql>
sql code
</sql>
<perl>
perl code
</perl>
<lisp>
lisp code
</lisp>
<bold>
bold text
</bold>
<italic>
italic text
</italic>
<underline>
underlined text
</underline>
<strike>
strike text
</strike>
<pre>
predefined text
</pre>
<verbatim>
predefined text
</verbatim>
\endcode
\sa eZTechGenerator
*/
/*!TODO
Add better syntax highlighting.
*/
include_once( "classes/eztexttool.php" );
include_once( "classes/ezlog.php" );
class eZTechRenderer
{
/*!
Creates a new eZTechGenerator object.
*/
function eZTechRenderer( &$article )
{
$this->Article = $article;
}
/*!
Returns the XHTML contents of the introduction of the article.
*/
function &renderIntro()
{
$xml = xmltree( $this->Article->contents() );
if ( !$xml )
{
print( "<br /><b>Error: eZTechRenderer::docodeXML() could not decode XML</b><br />" );
}
else
{
$intro = "";
$body = "";
$articleImages = $this->Article->images();
$articleID = $this->Article->id();
$i=0;
$this->$PrevTag = "";
foreach ( $xml->root->children as $child )
{
if ( $child->name == "intro" )
{
if ( count( $child->children ) > 0 )
foreach ( $child->children as $paragraph )
{
$intro = $this->renderPlain( $intro, $paragraph );
$intro = $this->renderCode( $intro, $paragraph );
$intro = $this->renderStandards( $intro, $paragraph );
$intro = $this->renderLink( $intro, $paragraph );
$intro = $this->renderImage( $intro, $paragraph, $articleImages );
$this->PrevTag = $paragraph->name;
}
}
}
// $newArticle = eZTextTool::nl2br( $intro );
$newArticle = $intro;
}
return $newArticle;
}
/*!
Returns the XHTML article of the article.
*/
function &renderPage( $pageNumber=0 )
{
$xml = xmltree( $this->Article->contents() );
if ( !$xml )
{
print( "<br /><b>Error: eZTechRenderer::docodeXML() could not decode XML</b><br />" );
}
else
{
$intro = "";
$body = "";
$this->$PrevTag = "";
$articleImages = $this->Article->images();
$articleID = $this->Article->id();
foreach ( $xml->root->children as $child )
{
if ( $child->name == "intro" )
{
if ( count( $child->children ) > 0 )
foreach ( $child->children as $paragraph )
{
$intro = $this->renderPlain( $intro, $paragraph );
$intro = $this->renderCode( $intro, $paragraph );
$intro = $this->renderStandards( $intro, $paragraph );
$intro = $this->renderLink( $intro, $paragraph );
$intro = $this->renderImage( $intro, $paragraph, $articleImages );
$this->PrevTag = $paragraph->name;
}
}
if ( $child->name == "body" )
{
$body = $child->children;
}
}
$pageArray = array();
// loop on the pages
foreach ( $body as $page )
{
$pageContent = "";
$this->$PrevTag = "";
// loop on the contents of the pages
if ( count( $page->children ) > 0 )
foreach ( $page->children as $paragraph )
{
$pageContent = $this->renderPlain( $pageContent, $paragraph );
$pageContent = $this->renderCode( $pageContent, $paragraph );
$pageContent = $this->renderStandards( $pageContent, $paragraph );
$pageContent = $this->renderLink( $pageContent, $paragraph );
$pageContent = $this->renderImage( $pageContent, $paragraph, $articleImages );
$this->PrevTag = $paragraph->name;
}
$pageArray[] = $pageContent;
}
if ( $pageNumber == -1 )
{
$newArticle = $intro . "\n</p><p>\n";
if ( count( $pageArray ) > 0 )
foreach ( $pageArray as $page )
{
$newArticle .= $page;
}
}
else if ( $pageNumber != 0 )
{
$newArticle = $pageArray[$pageNumber];
}
else
{
// $newArticle = eZTextTool::nl2br( $intro ) . "</p><p>". $pageArray[$pageNumber];
$newArticle = $intro . "\n</p><p>\n". $pageArray[$pageNumber];
}
}
return $newArticle;
}
function &renderPlain( $pageContent, $paragraph )
{
// ordinary text
if ( $paragraph->name == "text" )
{
$paragraph_text = $paragraph->content;
if ( $paragraph_text[0] == "\n" )
{
if ( $this->PrevTag != "link" )
$paragraph_text[0] = " ";
}
$pageContent .= eZTextTool::nl2br( $paragraph_text );
}
return $pageContent;
}
function &renderLink( $pageContent, $paragraph )
{
// link
if ( $paragraph->name == "link" )
{
foreach ( $paragraph->attributes as $imageItem )
{
switch ( $imageItem->name )
{
case "href" :
{
$href = $imageItem->children[0]->content;
}
break;
case "text" :