<?php
// QuickTalk 2.5 build:20100922
class cPost
{
// --------
var $id = -1;
var $section = -1;
var $topic = -1;
var $type = 'P';
var $icon = '00';
var $title = '';
var $issuedate = '0';
var $text = '';
var $modifdate = '0';
var $modifuser;
var $modifname;
var $attach;
var $userid;
var $username;
var $userrole;
var $userloca;
var $useravat;
var $usersign;
var $num;
// --------
function cPost($aPost=null,$intNum=null)
{
if ( isset($aPost) )
{
if ( is_int($aPost) )
{
if ( $aPost<0 ) die('No post '.$aPost);
global $oDB;
$oDB->Query('SELECT p.*,u.role,u.location,u.picture,u.signature FROM '.TABPOST.' p LEFT JOIN '.TABUSER.' u ON p.userid=u.id WHERE p.id='.$aPost);
$row = $oDB->Getrow();
$this->MakeFromArray($row);
}
elseif ( is_array($aPost) )
{
$this->MakeFromArray($aPost);
}
elseif ( strtolower(get_class($aPost))=='cpost' )
{
$this->id = $aPost->id;
$this->topic = $aPost->topic;
$this->section = $aPost->section;
$this->type = $aPost->type;
$this->icon = $aPost->icon;
$this->title = $aPost->title;
$this->text = $aPost->text;
$this->issuedate= $aPost->issuedate;
$this->userid = $aPost->userid;
$this->username = $aPost->username;
$this->userrole = $aPost->userrole;
$this->userloca = $aPost->userloca;
$this->useravat = $aPost->useravat;
$this->usersign = $aPost->usersign;
$this->modifdate= $aPost->modifdate;
$this->modifuser= $aPost->modifuser;
$this->modifname= $aPost->modifname;
$this->attach = $aPost->attach;
$this->num = $aPost->num;
}
else
{
die('Invalide constructor parameter#1 for class cPost');
}
if ( $this->type=='D' ) $this->title = ' ';
}
if ( isset($intNum) ) $this->num = intval($intNum);
if ( $_SESSION[QT]['viewmode']=='C' ) $this->text = QTcompact($this->text,0);
}
// --------
function MakeFromArray($aPost)
{
if ( !is_array($aPost) ) die('cPost->MakeFromArray: aPost is not an array');
foreach($aPost as $strKey=>$oValue) {
switch ($strKey) {
case 'id': $this->id = intval($oValue); break;
case 'forum': $this->section= intval($oValue); break;
case 'topic': $this->topic = intval($oValue); break;
case 'type': $this->type = $oValue; break;
case 'icon': $this->icon = $oValue; break;
case 'title': $this->title = $oValue; break;
case 'textmsg': $this->text = $oValue; break;
case 'issuedate':$this->issuedate = $oValue; break;
case 'userid': $this->userid = intval($oValue); break;
case 'username': $this->username = $oValue; break;
case 'role': $this->userrole = $oValue; break;
case 'location': $this->userloca = $oValue; break;
case 'picture': $this->useravat = $oValue; break;
case 'signature':$this->usersign = $oValue; break;
case 'modifdate':$this->modifdate = $oValue; break;
case 'modifuser':$this->modifuser = intval($oValue); break;
case 'modifname':$this->modifname = $oValue; break;
case 'attach': $this->attach = $oValue; break;
}}
}
// --------
function FormatTitleForInsert($str)
{
if ( empty($str) ) return $str;
$str = addslashes(QTconv($str,'3',QTF_CONVERT_AMP,false));
$str = str_replace("\r\n",' ',$str);
$str = str_replace("\r",' ',$str);
$str = str_replace("\n",' ',$str);
return trim(str_replace(' ',' ',$str));
}
// --------
function InsertPost($bUserStat=true)
{
global $oDB;
$oDB->Query(
'INSERT INTO '.TABPOST.'
(
id,forum,topic,title,type,icon,userid,username,issuedate,textmsg'.( empty($this->attach) ? '' : ',attach').'
)
VALUES
(
'.$this->id.','.$this->section.','.$this->topic.',"'.$this->FormatTitleForInsert($this->title).'","'.$this->type.'","'.$this->icon.'",'.$this->userid.',"'.addslashes($this->username).'","'.date('Ymd His').'","'.addslashes(QTconv($this->text,'3',QTF_CONVERT_AMP,false)).'"'.( empty($this->attach) ? '': ',"'.$this->attach.'"').'
)'
);
// lastpost
$_SESSION['qtf_usr_lastpost'] = time();
// added for db2
if ( $oDB->type=='db2' )
{
$oDB->Query('UPDATE '.TABPOST.' SET textmsg2="'.addslashes(substr(QTconv($this->text,'3',QTF_CONVERT_AMP,false),0,255)).'" WHERE id='.$this->id);
}
if ( isset($_SESSION['qtf_usr_posts_today']) )
{
if ( $this->type=='P' || $this->type=='R' ) $_SESSION['qtf_usr_posts_today']++;
}
if ( $bUserStat )
{
$oDB->Query('UPDATE '.TABUSER.' SET lastdate="'.date('Ymd His').'", numpost=numpost+1, ip="'.$oDB->ip.'" WHERE id='.$this->userid);
$_SESSION[QT.'_usr_posts']++;
}
}
// --------
function Dropattach()
{
if ( $this->id<0 ) die('Wrong id in post->Dropattach');
global $oDB;
if ( file_exists(QTF_DIR_DOC.$this->attach) ) unlink(QTF_DIR_DOC.$this->attach);
$oDB->Query('UPDATE '.TABPOST.' SET attach="" WHERE id='.$this->id);
$this->attach = NULL;
if ( strstr($this->text,'[img]@[/img]') ) $this->text = str_replace('[img]@[/img]','',$this->text);
return $b;
}
// --------
function Show($oSEC,$oTopic,$bAvatar=true,$strEndLine='',$strSep='',$strSkin='skin/default',$strAlt='r1')
{
if ( !isset($oSEC) ) die('oPost->Show: Missing $oSEC');
if ( !isset($oTopic) ) die('oPost->Show: Missing $oTopic');
global $oVIP,$L;
// prepare icon
if ( $this->type=='P' )
{
if ( strtolower($oTopic->type)=='a' )
{
$strIcon = AsImg($strSkin.'/ico_topic_a_0.gif','T',$L['Ico_topic_a_0'],'ico i_topic');
}
else
{
if ( $oTopic->status=='1' )
{
$strIcon = AsImg($strSkin.'/ico_topic_t_1.gif','T',$L['Ico_topic_t_1'],'ico i_topic');
}
else
{
$strIcon = AsImg($strSkin.'/ico_topic_t_0.gif','T','unknown status','ico i_topic');
}
}
}
else
{
$strIcon = AsImg($strSkin.'/ico_post_'.strtolower($this->type).'.gif','P',$L['Ico_post_'.strtolower($this->type)],'ico ico_p');
}
// prepare title
if ( $this->type=='D' )
{
$strTitle = '<span title="'.$this->text.'">'.$L['Message_deleted'].'</span>';
}
else
{
$strTitle = $this->title;
}
// message container
echo '
<a id="p',$this->id,'"></a>
<div class="post">
<table class="hidden" cellspacing="0" summary="post">
<colgroup span="2"><col style="width:25px"></col><col></col></colgroup>
';
// message title
echo '
<tr class="hidden">
<td class="post_icone ',$strAlt,'">',$strIcon,'</td>
<td class="post_title ',$strAlt,'">
<table class="hidden" cellpadding="0" summary="message title">
<tr class="hidden">
<td class="hidden"><p class="post_title">',$strTitle,'</p></td>
<td class="hidden" style="text-align:right"><p class="post_date">',($_SESSION[QT]['viewmode']=='C' ? '<a href="qtf_user.php?id='.$this->userid.'" class="post_date">'.$this->username.'</a>' : ''),S,QTdatestr($this->issuedate,'$','$',true),( $this->num>=0 ? ' ['.$this->num.']' : ''),'</p>';
// ----------
// module note
if ( isset($_SESSION[QT]['m_note']) )
{
if ( $_SESSION[QT]['m_note']=='1' ) MakeWarningButton($this);
}
// ----------
echo '</td>
</tr>
</table>
</td>
</tr>
';
// message body
if ( $this->type!='D' )
{
echo '<tr class="hidden">',N;
echo '<td class="post_smile ',$strAlt,'">',($this->icon!='00' ? AsImg($strSkin.'/ico_prefix_'.$oSEC->prefix.'_'.$this->icon.'.gif','[o]',$L['Ico_prefix'][$oSEC->prefix.'_'.$this->icon],'ico ico_prefix') : S),'</td>',N;
echo '<td class="post_message ',$strAlt,'">',N;
// useravat
$strAvatar = '';
if ( $_SESSION[QT]['viewmode']!='C' && $bAvatar )
{
if ( empty($this->useravat) )
{
$strAvatar = AsImgBox('','picboxmsg','',$this->username.'<br/>'.($this->userrole!='U' ? $L['Userrole'][$this->userrole] : '').'<br/>'.$this->userloca,'qtf_user.php?id='.$this->userid);
}
else
{
$strAvatar = AsImgBox(AsImg(QTF_DIR_PIC.$this->useravat,'',$this->username,'','','qtf_user.php?id='.$this->userid),'picboxmsg','',$this->username.'<br/>'.($this->userrole!='U' ? $L['Userrole'][$this->userrole] : '').'<br/>'.$this->userloca,'qtf_user.php?id='.$this->userid);
}
}
echo $strAvatar;
// message attachment and signature
echo '<p class="msgbody">';
// format the text
$str = QTbbc($this->text,'<br/>','</p>','<p class="msgbody">');
// show the image (if any)
if ( $_SESSION[QT]['viewmode']!='C' ) {
if ( !empty($this->attach) ) {
if ( in_array(substr($this->attach,-4,4),array('.gif','.jpg','jpeg','.png')) ) {
if ( strstr($str, 'src="@"') ) {
$str = str_replace('src="@"','src="'.QTF_DIR_DOC.$this->attach.'"',$str);
}}}}
echo $str,"</p>\n";
if ( !empty($this->attach) )
{
echo '<p class="attachment">'.AsImg($strSkin.'/ico_attachment.gif','A',$L['Attachment'],'ico i_user');
if ( strstr($this->attach,'/') ) { $str = substr(strrchr($this->attach,'/'),1); } else { $str=$this->attach; }
if ( substr($str,0,strlen($this->id.'_'))==($this->id).'_' ) $str = substr($str,strlen($this->id.'_'));
echo ' <a href="'.QTF_DIR_DOC.$this->attach.'" class="a_attachment" target="_blank">'.$str.'</a></p>',N;
}
if ( $_SESSION[QT]['viewmode']!='C' ){
if ( $this->type!='F' ) {
if ( !empty($this->usersign) ) {
echo '<p class="post_sign">',QTbbc($this->usersign),'</p>',N;
}}}
// command line
echo $strEndLine;
echo '</td>',N,'</tr>',N;
}
// end message container
echo '
</table>
</div>
';
}
// --------
function SetFromPost($bNew=true)
{
$error='';
global $oVIP,$strBehalf;
// Identify the user (can be onbehalf)
$this->modifuser = $oVIP->id;
$this->modifname = $oVIP->username;
if ( isset($_POST['behalf']) )
{
$strBehalf = trim($_POST['behalf']); if ( get_magic_quotes_gpc() ) $strBehalf = stripslashes($strBehalf);
if ( !is_null($strBehalf) && $strBehalf!=='' )
{
// Find behalf id
$strBehalf = htmlspecialchars($strBehalf,ENT_QUOTES);
$intBehalf = current(array_keys(GetUsers('name',$strBehalf) )); // can be FALSE when not found
if ( is_int($intBehalf) ) { $this->modifuser = $intBehalf; $this->modifname = $strBehalf; } else { $error=L('Send_on_behalf').' '.Error(1); }
}
}
// Identify creator as being the user. When editing existing message ($bNew=false) then autor remains unchanged
if ( $bNew )
{
$this->userid = $this->modifuser;
$this->username = $this->modifname;
}
// Read message values
if ( isset($_POST['icon']) ) $this->icon = $_POST['icon'];
if ( isset($_POST['title']) ) $this->title = QTunbbc(trim((get_magic_quotes_gpc() ? stripslashes($_POST['title']) : $_POST['title'])));
if ( isset($_POST['text']) ) $this->text = trim((get_magic_quotes_gpc() ? stripslashes($_POST['text']) : $_POST['text']));
if ( isset($_POST['oldattach']) ) { $this->attach = $_POST['oldattach']; }
return $error;
}
// --------
}
?>