mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-01-24 21:09:54 -06:00
142 lines
4.2 KiB
PHP
142 lines
4.2 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 App\Traits\Auditable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use voku\helper\AntiXSS;
|
|
|
|
/**
|
|
* App\Models\Comment.
|
|
*
|
|
* @property int $id
|
|
* @property string $content
|
|
* @property int $anon
|
|
* @property int|null $torrent_id
|
|
* @property int|null $article_id
|
|
* @property int|null $requests_id
|
|
* @property int|null $user_id
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read \App\Models\Article|null $article
|
|
* @property-read \App\Models\TorrentRequest|null $request
|
|
* @property-read \App\Models\Torrent|null $torrent
|
|
* @property-read \App\Models\User|null $user
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereAnon($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereArticleId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereContent($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereRequestsId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereTorrentId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereUpdatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment whereUserId($value)
|
|
* @mixin \Eloquent
|
|
*
|
|
* @property int|null $playlist_id
|
|
* @property-read \App\Models\Playlist|null $playlist
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Comment wherePlaylistId($value)
|
|
*/
|
|
class Comment extends Model
|
|
{
|
|
use Auditable;
|
|
|
|
/**
|
|
* Belongs To A Torrent.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function torrent()
|
|
{
|
|
return $this->belongsTo(Torrent::class);
|
|
}
|
|
|
|
/**
|
|
* Belongs To A Article.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function article()
|
|
{
|
|
return $this->belongsTo(Article::class);
|
|
}
|
|
|
|
/**
|
|
* Belongs To A Request.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function request()
|
|
{
|
|
return $this->belongsTo(TorrentRequest::class, 'requests_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* Belongs To A Playlist.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function playlist()
|
|
{
|
|
return $this->belongsTo(Playlist::class);
|
|
}
|
|
|
|
/**
|
|
* Belongs To A User.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class)->withDefault([
|
|
'username' => 'System',
|
|
'id' => '1',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Set The Comments Content After Its Been Purified.
|
|
*
|
|
* @param string $value
|
|
*
|
|
* @return void
|
|
*/
|
|
public function setContentAttribute($value)
|
|
{
|
|
$antiXss = new AntiXSS();
|
|
|
|
$this->attributes['content'] = $antiXss->xss_clean($value);
|
|
}
|
|
|
|
/**
|
|
* Parse Content And Return Valid HTML.
|
|
*
|
|
* @return string Parsed BBCODE To HTML
|
|
*/
|
|
public function getContentHtml()
|
|
{
|
|
$bbcode = new Bbcode();
|
|
$linkify = new Linkify();
|
|
|
|
return $bbcode->parse($linkify->linky($this->content), true);
|
|
}
|
|
}
|