Files
UNIT3D-Community-Edition/app/Models/Comment.php
HDVinnie a3efd98e84 (Security Update) HTMLPurifier 🔐
- closes #875
- Fixes HTML Tags Not Being Contained / Elevated within user-generated bodies like (posts, comments, signature, etc.)
2019-10-11 11:57:17 -04:00

126 lines
3.7 KiB
PHP
Executable File

<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D
*
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
* @author HDVinnie
*/
namespace App\Models;
use App\Helpers\Bbcode;
use Illuminate\Database\Eloquent\Model;
/**
* @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
*/
class Comment extends Model
{
/**
* 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)
{
$this->attributes['content'] = clean($value);
}
/**
* Parse Content And Return Valid HTML.
*
* @return string Parsed BBCODE To HTML
*/
public function getContentHtml()
{
$bbcode = new Bbcode();
return $bbcode->parse($this->content, true);
}
}