Commits

christiansalazar committed 26a8bc8

acceptMessage must return the filtered message

  • Participants
  • Parent commits 73e27b8

Comments (0)

Files changed (2)

 		return Yii::app()->format->formatDateTime($value);
 	}
 	protected function acceptMessage($message){
-		// return true for accept this message. false reject it.
-		return true;
+		// return the message (you can alterate it). 
+		// return an empty string to reject it.
+		return CHtml::encode($message); // encode to avoid html
 	}
 }
 ?>

File YiiChatDbHandlerBase.php

 		$this->_chat_id = $chat_id;
 		$this->_identity = $identity;
 		$this->_data = $data;
-		if($this->acceptMessage($message)===true){
+		$message_filtered = trim($this->acceptMessage($message));
+		if($message_filtered != ""){
 			$obj = array(
 				"id"=>$this->createPostUniqueId(),
 				"chat_id"=>$chat_id,
 				"post_identity"=>$identity,
 				"owner"=>substr($this->getIdentityName(),0,20),
 				"created"=>time(),
-				"text"=>$message,
+				"text"=>$message_filtered,
 				"data"=>serialize($data),
 			);
 			$this->getDb()->createCommand()->insert(