Esempio n. 1
0
 public function mail_send_message($rt, $data, $msg_id)
 {
     try {
         if ($data['from_users_id'] === NULL || !$this->notice($data['to_users_id'], 'mail', 'send_message')) {
             //检测是否为系统邮件
             return $rt;
         }
         lib()->load('Markdown');
         $from_user = User::getUser($data['from_users_id']);
         $to_user = User::getUser($data['to_users_id']);
         $mt = new MailTemplate("mail_notice/send_message.html");
         $mt->setUserInfo($to_user->getInfo());
         $mt->setValues(['from_user_name' => $from_user->getName(), 'from_user_aliases' => $from_user->getAliases(), 'from_user_url' => user_link($from_user->getName()), 'msg_title' => $data['msg_title'] ?: "无标题信息", 'msg_content' => Markdown::defaultTransform($data['msg_content']), 'msg_link' => get_url(['Message', 'view'], "?id={$msg_id}"), 'msg_datetime' => $data['msg_datetime']]);
         $mt->mailSend($to_user->getName(), $to_user->getEmail());
     } catch (\Exception $ex) {
         Log::write(_("NoticeApply mail_send_message create a Exception.") . "EX:[" . $ex->getCode() . "]:" . $ex->getMessage(), Log::NOTICE);
     }
     return $rt;
 }
Esempio n. 2
0
    /**
     * @param int $id
     * @param int $uid
     * @return array
     */
    public function read($id, $uid)
    {
        $id = intval($id);
        $uid = intval($uid);
        $sql = <<<EOM
SELECT `id`, `msg_title`, `msg_datetime`, `msg_content`, `is_read`, `from_users_id`, `to_users_id`
FROM `message`
WHERE
`id` = '{$id}'
AND
(
\t(`from_users_id` = '{$uid}' AND `from_del` = 0)
\tOR
\t(`to_users_id` = '{$uid}' AND `to_del` = 0)
)
LIMIT 1;
EOM;
        $stmt = $this->db->getReader()->query($sql);
        $msg = $stmt->fetchAll(\PDO::FETCH_ASSOC);
        if (isset($msg[0])) {
            $msg = $msg[0];
        }
        if (!isset($msg['id']) || $msg['id'] != $id) {
            $this->throwMsg(-12);
        }
        if ($uid == $msg['to_users_id'] && !$msg['is_read']) {
            $msg['is_read'] = 1;
            $msg['read_time'] = date("Y-m-d H:i:s");
            $s = $this->db->update("message", ['is_read' => 1, 'read_time' => $msg['read_time']], ['id' => $id]);
            if ($s === false) {
                Log::write(_("Set "));
            }
        }
        lib()->load('Markdown');
        $msg['msg_content'] = Markdown::defaultTransform($msg['msg_content']);
        return $msg;
    }