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 \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function tags()
{
return $this->belongsToMany('App\Models\Tag');
}
/**
* Define the relationship with clients.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function client()
{
return $this->belongsTo('App\Models\MicropubClient', 'client_id', 'client_url');
}
/**
* Define the relationship with webmentions.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function webmentions()
{
return $this->morphMany('App\Models\WebMention', 'commentable');
}
/**
* Define the relationship with places.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function place()
{
return $this->belongsTo('App\Models\Place');
}
/**
* Define the relationship with media.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function media()
{
return $this->hasMany('App\Models\Media');
}
/**
* Set the attributes to be indexed for searching with Scout.
*
* @return array
*/
public function toSearchableArray(): array
{
return [
'note' => $this->note,
];
}
/**
* Normalize the note to Unicode FORM C.
*
* @param string|null $value
*/
public function setNoteAttribute(?string $value)
{
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);
$html = $this->convertMarkdown($hashtags);
$modified = resolve(EmojiModifier::class)->makeEmojiAccessible($html);
return $modified;
}
/**
* 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 .= '