Location: PHPKode > projects > PhpBlock > A9.8/script/message/playermessage.class.php
<?php

class PlayerMessage
{
    protected static $instance = false;

    public static $HELL=-100;
    public static $VERY_BAD=-80;
    public static $BAD=-60;
    public static $NEUTRAL_BAD=-30;
    public static $NEUTRAL=0;
    public static $NEUTRAL_GOOD=30;
    public static $GOOD=60;
    public static $VERY_GOOD=80;
    public static $HEAVEN=100;
    public static $MAX_GRAVITY=100;

    public static $TRASH=0;
    public static $READ=1;
    public static $UNREAD=2;


    public static function getInstance() {
        if(!PlayerMessage::$instance) {
            PlayerMessage::$instance = new PlayerMessage();
        }
        return PlayerMessage::$instance;
    }

    protected function __construct() {
    }

    public function addPlayerInfo($parPlayerId, $parMessage, $parGravity=0, $parZoneId=-1) {
        $this->addPlayerMessage(0, $parPlayerId, $parMessage, $parGravity, $parZoneId);
    }

    public function addPlayerMessage($parFromPlayerId, $parToPlayerId, $parMessage, $parGravity=0, $parZoneId=-1) {
        $locMessage = addslashes($parMessage);
    	$locMessage = str_ireplace("script", "Forbidden_word_script", $locMessage);
    	$locMessage = str_ireplace("<?php", "Forbidden_word_<_?_php", $locMessage);
    	$locMessage = str_ireplace("<?", "Forbidden_word_<_?", $locMessage);
    	$locMessage = str_ireplace("?>", "Forbidden_word_?_>", $locMessage);
    	executer("INSERT INTO playerMessage (fromPlayerId, toPlayerId, gravity, message, zoneId, status, timestamp)
            VALUES($parFromPlayerId, $parToPlayerId, $parGravity, '$locMessage', $parZoneId, ".PlayerMessage::$UNREAD.", ".time().")");
    }

    public function getPlayerInfo($parPlayerId, $parMinGravity=-1, $parStatus=-1) {
        return $this->getPlayerMessagesFrom(0, $parPlayerId, $parMinGravity, $parStatus);
    }

    public function getZoneMessages($parZoneId, $parMinGravity=-1, $parStatus=-1) {
        return executer("SELECT timestamp, fromPlayerId, 0, gravity, message, zoneId
            FROM playerMessage
            WHERE zoneId=$parZoneId
            ".($parMinGravity==-1?"":" AND ABS(gravity) >= $parMinGravity")."
            ".($parStatus==-1?"":" AND status=$parStatus")."
            ORDER BY timestamp DESC, messageId DESC
            LIMIT ".Constante::$MAX_MESSAGE_GET);
    }

    public function getPlayerMessages($parToPlayerId, $parMinGravity=-1, $parStatus=-1) {
        return $this->getPlayerMessagesFrom(-1, $parToPlayerId, $parMinGravity, $parStatus);
    }
    public function getPlayerMessagesFromExclude($parFromPlayerId, $parToPlayerId, $parMinGravity=-1, $parStatus=-1) {
    	return executer("SELECT messageId, timestamp, fromPlayerId, toPlayerId, gravity, message, zoneId
            FROM playerMessage
            WHERE toPlayerId=$parToPlayerId
            ".($parFromPlayerId==-1?"":" AND fromPlayerId<>$parFromPlayerId")."
            ".($parMinGravity==-1?"":" AND ABS(gravity) >= ".abs($parMinGravity))
            .($parStatus==-1?"":" AND status=$parStatus")."
            ORDER BY timestamp DESC, messageId DESC
            LIMIT ".Constante::$MAX_MESSAGE_GET);
    }
    public function getPlayerMessagesFrom($parFromPlayerId, $parToPlayerId, $parMinGravity=-1, $parStatus=-1) {
        return executer("SELECT messageId, timestamp, fromPlayerId, toPlayerId, gravity, message, zoneId
            FROM playerMessage
            WHERE toPlayerId=$parToPlayerId
            ".($parFromPlayerId==-1?"":" AND fromPlayerId=$parFromPlayerId")."
            ".($parMinGravity==-1?"":" AND ABS(gravity) >= ".abs($parMinGravity))
            .($parStatus==-1?"":" AND status=$parStatus")."
            ORDER BY timestamp DESC, messageId DESC
            LIMIT ".Constante::$MAX_MESSAGE_GET);
    }

    public function setAllMessagesStatus($parToPlayerId, $parNewStatus=0) {
        executer("UPDATE playerMessage SET status=$parNewStatus WHERE toPlayerId=$parToPlayerId");
    }

    public function setMessageStatus($parMessageId, $parNewStatus=0) {
        executer("UPDATE playerMessage SET status=$parNewStatus WHERE messageId=$parMessageId");
    }
}
?>
Return current item: PhpBlock