* @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\Factories\HasFactory; 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 $playlist_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\Playlist|null $playlist * @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 wherePlaylistId($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 { use HasFactory; 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) { $this->attributes['content'] = (new 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); } }