Squashed commit of the following: commit 8ff29a8ab51ee5057ef786614ab95b005bf8918c Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Fri Feb 1 18:42:05 2019 +0000 Replace deprecated global helpers with their facade equivalents
60 lines
1.3 KiB
PHP
60 lines
1.3 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Models;
|
||
|
||
use Mf2;
|
||
use App\Traits\FilterHtml;
|
||
use Illuminate\Support\Arr;
|
||
use Illuminate\Database\Eloquent\Model;
|
||
|
||
class Like extends Model
|
||
{
|
||
use FilterHtml;
|
||
|
||
protected $fillable = ['url'];
|
||
|
||
/**
|
||
* Normalize the URL of a Like.
|
||
*
|
||
* @param string $value The provided URL
|
||
*/
|
||
public function setUrlAttribute(string $value)
|
||
{
|
||
$this->attributes['url'] = normalize_url($value);
|
||
}
|
||
|
||
/**
|
||
* Normalize the URL of the author of the like.
|
||
*
|
||
* @param string $value The author’s url
|
||
*/
|
||
public function setAuthorUrlAttribute(?string $value)
|
||
{
|
||
$this->attributes['author_url'] = normalize_url($value);
|
||
}
|
||
|
||
/**
|
||
* If the content contains HTML, filter it.
|
||
*
|
||
* @param string $value The content of the like
|
||
* @return string|null
|
||
*/
|
||
public function getContentAttribute(?string $value): ?string
|
||
{
|
||
if ($value === null) {
|
||
return null;
|
||
}
|
||
|
||
$mf2 = Mf2\parse($value, $this->url);
|
||
|
||
if (Arr::get($mf2, 'items.0.properties.content.0.html')) {
|
||
return $this->filterHtml(
|
||
$mf2['items'][0]['properties']['content'][0]['html']
|
||
);
|
||
}
|
||
|
||
return $value;
|
||
}
|
||
}
|