Location: PHPKode > scripts > XML Weblication > xml-weblication/lib/article.php
<?

/**
  * Article Class for weblication
  * @author Andreas Altendorfer <hide@address.com>
  * @date 2003-12-09
  */
  

class Article
{

   var      $aid;             // Unique Article ID
   var      $htmltemplate;    // HTML-Template
   var      $xml_article;     // the XML-Object defining this Article


   var      $title;
   var      $intro;
   var      $date;
   var      $author;
   var      $author_email;
   var      $text;

   //////////////////////////////////////////////////////////////////////
   //  INTERFACE
   //////////////////////////////////////////////////////////////////////
   // Constructor
   function Article( &$art ) {
     global $cfg;
	 
		 $this->xml_article = $art;
			 
		 $this->aid = $art->getAttr("aid");
		 
		 $title = $art->findElement("title");
		 if( $title ) $this->title = $title->data; else $this->title = "";
		 
		 $intro = $art->findElement("intro");
		 if( $intro ) $this->intro = $intro->data; else $this->intro = "";
		 
		 $date = $art->findElement("date");
		 if( $date ) $this->date = $date->data; else $this->date = "";
		 
		 $author = $art->findElement("author");
		 if( $author ) {
			 $this->author_email = $author->getAttr( "email" );
			 $this->author = $author->data; 
		 } else { $this->author = ""; $this->author_email = ""; }
		 
		 $this->text = $art->data;
		 
		 $this->htmltemplate = $art->findElement( "htmltemplate" );
		 if ( ! $this->htmltemplate ) {
			 $this->htmltemplate .=  "<div class=olc>" .
					 "{h3}TITLE{/h3}" .
					 "{p class=date}DATE AUTHOR{/p} ".
					 "{p class=intro}INTRO{/p}".
					 "{p class=text}ARTICLE{/p}".
					 "{hr size=1 align=center noshade}{/div}";
		 }
		 else {
			 $include = $this->htmltemplate->getAttr("include" );
		 
			 if ( $include != "" && $include != false ) {
				 $fname = $cfg["templates"] . "/". $include;
				 if ( ! file_exists( $fname ) ) {
					 $this->htmltemplate .= "WARNING: TEMPLATE NOT EXISTS OR NOT READABLE " . $fname . "<div class=olc>" .
					 "{h3}TITLE{/h3}" .
					 "{p class=date}DATE AUTHOR{/p} ".
					 "{p class=intro}INTRO{/p}".
					 "{p class=text}ARTICLE{/p}".
					 "{hr size=1 align=center noshade}{/div}";
				 }
				 else {
					 $f = fopen( $fname, "r" );
				 if ( !$f ) {
						 $this->htmltemplate .= "WARNING: TEMPLATE OPEN FAILED " . $fname . "<div class=olc>" .
					 "{h3}TITLE{/h3}" .
					 "{p class=date}DATE AUTHOR{/p} ".
					 "{p class=intro}INTRO{/p}".
					 "{p class=text}ARTICLE{/p}".
					 "{hr size=1 align=center noshade}{/div}";
				 }
				 else {
					 $this->htmltemplate = "";
					 while( $l = fread( $f, 4096 ) ) {
						 $this->htmltemplate .= $l;
					 }
				 }
				 fclose( $f );
			 }
			 }
			 else {
				 $this->htmltemplate = $this->htmltemplate->data;
			 }	   
	   }
   }
  
   function display() {
     
	 $source = $this->htmltemplate;
	 $output = $source;
	 
	 $output = str_replace( "TITLE", $this->title, $source ); $source = $output;
	 $output = str_replace( "AUTHOR", $this->author . " &lt;" . $this->author_email ."&gt;", 
	                        $source ); $source = $output;
	 $output = str_replace( "DATE", $this->date, $source ); $source = $output;
	 $output = str_replace( "INTRO", $this->intro, $source ); $source = $output;
	 $output = str_replace( "ARTICLE", $this->text, $source ); $source = $output;
	 
     return( $output );
   } 
  
} //- class Menu

?>
Return current item: XML Weblication