<?php
Class ViewNews extends ControllerBase {
private $news;
public function __construct(){
parent::__construct();
$this->news = new News();
}
public function index(){
$this->xml->addText(SITENAME.' -news','title',0);
$temp = $this->news->select(' 1 order by itemid desc');
$field_title = $this->news->getField('title');
$field_content = $this->news->getField('content');
$field_posttime = $this->news->getField('posttime');
$this->xml->addText($this->getContent($this->getName().'/index'),'rightcontent',0);
$this->xml->addBreak('rightcontent',2);
for($i=0;$i<sizeof($temp);$i++){
$this->xml->addBreak('rightcontent',1);
$url = 'javascript:sndReqPOST(\'viewnews/viewNews\',\'id='.$temp[$i]->itemid.'\')';
$this->xml->addURL($temp[$i]->$field_title,$url,'rightcontent',1);
$this->xml->addBreak('rightcontent',2);
$this->xml->addText($temp[$i]->$field_posttime,'rightcontent',1);
$this->xml->addBreak('rightcontent',2);
$this->xml->addText(substr(strip_tags($temp[$i]->$field_content,''),0,120),'rightcontent',1);
$this->xml->addBreak('rightcontent',1);
$this->xml->addURL('read more...',$url,'rightcontent',1);
$this->xml->addBreak('rightcontent',1);
}
//build news
$url = 'javascript:sndReqPOST(\'viewnews/index\')';
$this->xml->flush();
}
public function viewNews(){
$id = $_POST['id'];
$this->xml->addText($this->getContent($this->getName().'/viewnews'),'rightcontent',0);
$this->xml->addBreak('rightcontent',2);
$this->news->selectByID($id);
$this->xml->addText('<h3>'.$this->news->getTitle().'</h3>','rightcontent',1);
$this->xml->addText('Posttime: '.$this->news->getPosttime(),'rightcontent',1);
$this->xml->addBreak('rightcontent',1);
$this->xml->addText('Author: '.$this->news->getUsername(),'rightcontent',1);
$this->xml->addBreak('rightcontent',2);
$this->xml->addText($this->news->getContent(),'rightcontent',1);
$this->xml->flush();
}
public function __destruct(){}
}
?>