<?php
// Xinfeng Chen, 2002.11.07
// require_once('base_memo_file.php');
// require_once('class_forum_base.php');

class CTopic extends CBaseMemoFile {
 var $_mask=array('COLLECTED'=>0x01,'TOPPED'=>0x02,'NOCODE'=>0x04,'NOSMILE'=>0x08);
 var $id, $refid, $replyid, $flag, $ip, $user, $time, $emotion, $title, $body;
 var $locked, $numreply, $lastname, $lasttime, $hits;
 var $bodysize=0;

 function _explodeRecord($a_line){
  if($a_line==''){
   unset($this->id, $this->refid, $this->replyid, $this->flag, $this->ip, 
    $this->user, $this->time, $this->emotion, $this->title, $this->body,
    $this->locked, $this->numreply, $this->lastname, $this->lasttime,
    $this->hits);
  }else{
   list($this->id, $this->refid, $this->replyid, $this->flag, $this->ip, 
    $this->user, $this->time, $this->emotion, $this->title, $this->body,
    $this->locked, $this->numreply, $this->lastname, $this->lasttime,
    $this->hits)=explode(SP, $a_line);
  }
 }

 function _composeRecord($a_line){
  $a_line=$this->id.SP.$this->refid.SP.$this->replyid.SP.$this->flag
   .SP.$this->ip.SP.$this->user.SP.$this->time.SP.$this->emotion
   .SP.$this->title.SP.$this->body.SP.$this->locked.SP.$this->numreply
   .SP.$this->lastname.SP.$this->lasttime.SP.$this->hits;
 }

 function load($a_bid, $a_tid){
  $fname=CForumBase::getFilePath('TOPIC',$a_bid,$a_tid);
  return $this->readFile($fname);
 }

 function store($a_bid, $a_tid){
  $fname=CForumBase::getFilePath('TOPIC',$a_bid,$a_tid);
  return $this->writeFile($fname);
 }

 function destroy($a_bid, $a_tid){
  $fname=CForumBase::getFilePath('TOPIC',$a_bid,$a_tid);
  return $this->destroyFile($fname);
 }

 function _strBrief($a_str,$a_size){
  if(strlen($a_str)>$a_size){$a_str=substr($a_str,0,$a_size-3).'...';}
  return $a_str;
 }

 function getBrief(){
  $this->bodysize=strlen($this->body);
  $title=$this->_strBrief($this->title,40);
  $body=$this->_strBrief($this->body,80);
  $brief=$title.SP.$body.SP.$this->emotion.SP.$this->time.SP.$this->user
   .SP.$this->ip.SP.$this->flag.SP.$this->locked.SP.$this->numreply
   .SP.$this->lastname.SP.$this->lasttime.SP.$this->hits.SP.$this->bodysize.SP;
  return $brief;
 }

 function setBrief($a_brief){
  list($this->title,$this->body,$this->emotion,$this->time,$this->user,
   $this->ip,$this->flag,$this->locked,$this->numreply,
   $this->lastname,$this->lasttime,$this->hits,$this->bodysize)=explode(SP,$a_brief);
 }

 function getFlag($a_flag){
  return (boolean)($this->flag & $this->_mask[$a_flag]);
 }

 function setFlag($a_flag, $a_set=true){
  $mask=$this->_mask[$a_flag];
  $this->flag=($a_set)?($this->flag|$mask):($this->flag&(~$mask));
 }
}
?>