Files
UNIT3D-Community-Edition/app/Models/Message.php
2020-02-12 14:45:59 -05:00

133 lines
3.8 KiB
PHP

<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Models;
use App\Helpers\Bbcode;
use App\Helpers\Linkify;
use Illuminate\Database\Eloquent\Model;
use voku\helper\AntiXSS;
/**
* App\Models\Message.
*
* @property int $id
* @property int $user_id
* @property int $chatroom_id
* @property int|null $receiver_id
* @property int|null $bot_id
* @property string $message
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\Bot|null $bot
* @property-read \App\Models\Chatroom $chatroom
* @property-read \App\Models\User|null $receiver
* @property-read \App\Models\User $user
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Message newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Message newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Message query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Message whereBotId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Message whereChatroomId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Message whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Message whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Message whereMessage($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Message whereReceiverId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Message whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Message whereUserId($value)
* @mixin \Eloquent
*/
class Message extends Model
{
/**
* The Attributes That Are Mass Assignable.
*
* @var array
*/
protected $fillable = [
'message',
'user_id',
'chatroom_id',
'receiver_id',
'bot_id',
];
/**
* Belongs To A Bot.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function bot()
{
return $this->belongsTo(Bot::class);
}
/**
* Belongs To A User.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}
/**
* A message belongs to a receiver.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function receiver()
{
return $this->belongsTo(User::class, 'receiver_id');
}
/**
* Belongs To A Chat Room.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function chatroom()
{
return $this->belongsTo(Chatroom::class);
}
/**
* Set The Chat Message After Its Been Purified.
*
* @param string $value
*
* @return void
*/
public function setMessageAttribute($value)
{
$antiXss = new AntiXSS();
$this->attributes['message'] = $antiXss->xss_clean($value);
}
/**
* Parse Content And Return Valid HTML.
*
* @param $message
*
* @return string Parsed BBCODE To HTML
*/
public static function getMessageHtml($message)
{
$bbcode = new Bbcode();
$linkify = new Linkify();
return $bbcode->parse($linkify->linky($message), true);
}
}