contacts = null;
}
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'notes';
/**
* Mass-assignment.
*
* @var array
*/
protected $fillable = [
'note',
'in_reply_to',
'client_id',
];
/**
* Hide the column used with Laravel Scout.
*
* @var array
*/
protected $hidden = ['searchable'];
/**
* Define the relationship with tags.
*
* @return BelongsToMany
*/
public function tags(): BelongsToMany
{
return $this->belongsToMany(Tag::class);
}
/**
* Define the relationship with clients.
*
* @return BelongsTo
*/
public function client(): BelongsTo
{
return $this->belongsTo(MicropubClient::class, 'client_id', 'client_url');
}
/**
* Define the relationship with webmentions.
*
* @return MorphMany
*/
public function webmentions(): MorphMany
{
return $this->morphMany(WebMention::class, 'commentable');
}
/**
* Define the relationship with places.
*
* @return BelongsTo
*/
public function place(): BelongsTo
{
return $this->belongsTo(Place::class);
}
/**
* Define the relationship with media.
*
* @return HasMany
*/
public function media(): HasMany
{
return $this->hasMany(Media::class);
}
/**
* Set the attributes to be indexed for searching with Scout.
*
* @return array
*/
#[ArrayShape(['note' => "null|string"])]
public function toSearchableArray(): array
{
return [
'note' => $this->note,
];
}
/**
* Normalize the note to Unicode FORM C.
*
* @param string|null $value
*/
public function setNoteAttribute(?string $value): void
{
if ($value !== null) {
$normalized = normalizer_normalize($value, Normalizer::FORM_C);
if ($normalized === '') { //we don’t want to save empty strings to the db
$normalized = null;
}
$this->attributes['note'] = $normalized;
}
}
/**
* Pre-process notes for web-view.
*
* @param string|null $value
* @return string|null
*/
public function getNoteAttribute(?string $value): ?string
{
if ($value === null && $this->place !== null) {
$value = '📍: ' . $this->place->name . '';
}
// if $value is still null, just return null
if ($value === null) {
return null;
}
$hcards = $this->makeHCards($value);
$hashtags = $this->autoLinkHashtag($hcards);
return $this->convertMarkdown($hashtags);
}
/**
* Provide the content_html for JSON feed.
*
* In particular we want to include media links such as images.
*
* @return string
*/
public function getContentAttribute(): string
{
$note = $this->note;
foreach ($this->media as $media) {
if ($media->type === 'image') {
$note .= '
';
}
if ($media->type === 'audio') {
$note .= '