<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class ReadAction extends BaseAction
{
    public function run()
    {
        $id = S::gp('mid', 'G', 2);
        empty($id) && $this->showMessage('非法操作，请返回');
        $mModel = Message::single();
        try
        {
            $message = $mModel->getOne($id);
        }
        catch (Exception $exce)
        {
            $this->showMessage($exce->getMessage());
        }
        
        if ($message['msgtoid'] != $this->uid() && $message['msgfromid'] != 1)
        {
            $this->showMessage('此短信不属于你，不能阅读');
        }
        
        if ($message['isnew'])
        {
            $mModel->isRead($message, $this->uid());
        }
        $mModel->updateNewCount($this->uid());
        
        $permissions = Members::single()->getPermissions($message['msgfromid']);
        $message['message'] = replaceTag($message['message'], 'img', $permissions['ispmimg']);
        $message['message'] = replaceTag($message['message'], 'url', $permissions['ispmurl']);
        $permissions['isfilter'] && $message['message'] = BookPost::filter($message['message']);
        
        $this->getController()->render('read',array('message'=>$message));
    }
}