`uri` is the attribute every other postable model uses for its absolute permalink on this site. Add it to Like, which had none, and rename Bookmark's `local_uri` to match. `url` stays as the thing being liked or bookmarked. Refs #148 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
1.4 KiB
PHP
62 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\FilterHtml;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Arr;
|
|
use Mf2;
|
|
|
|
#[Fillable(['url'])]
|
|
class Like extends Model
|
|
{
|
|
use FilterHtml;
|
|
use HasFactory;
|
|
|
|
protected function uri(): Attribute
|
|
{
|
|
return Attribute::get(
|
|
get: fn () => config('app.url').'/likes/'.$this->id,
|
|
);
|
|
}
|
|
|
|
protected function url(): Attribute
|
|
{
|
|
return Attribute::set(
|
|
set: fn ($value) => normalize_url($value),
|
|
);
|
|
}
|
|
|
|
protected function authorUrl(): Attribute
|
|
{
|
|
return Attribute::set(
|
|
set: fn ($value) => normalize_url($value),
|
|
);
|
|
}
|
|
|
|
protected function content(): Attribute
|
|
{
|
|
return Attribute::get(
|
|
get: function ($value, $attributes) {
|
|
if ($value === null) {
|
|
return null;
|
|
}
|
|
|
|
$mf2 = Mf2\parse($value, $attributes['url']);
|
|
|
|
if (Arr::get($mf2, 'items.0.properties.content.0.html')) {
|
|
return $this->filterHtml(
|
|
$mf2['items'][0]['properties']['content'][0]['html']
|
|
);
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
);
|
|
}
|
|
}
|