Skip to content

Commit

Permalink
Merge branch 'develop' into feature/comment-sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt authored Aug 16, 2024
2 parents c630648 + b182421 commit e7eaca8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/Models/Comment/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,37 @@ public function getEndOfThreadAttribute() {
return $this;
}
}

/**
* Returns the comment contents but with links in clickable format.
*
* @return string
*/
public function getCommentAttribute() {
if (config('lorekeeper.settings.wysiwyg_comments')) {
return preg_replace_callback(
'/(?<!\()(https?:\/\/[^\s]+)/',
function ($matches) {
$url = $matches[1];
$parsedUrl = parse_url($url);
$domain = $parsedUrl['host'];

return '<a href="'.$url.'" target="_blank">'.$domain.'</a>';
},
$this->attributes['comment']
);
}

return preg_replace_callback(
'/(?<!\()(https?:\/\/[^\s]+)/',
function ($matches) {
$url = $matches[1];
$parsedUrl = parse_url($url);
$domain = $parsedUrl['host'];

return '['.$domain.']('.$url.')';
},
$this->attributes['comment']
);
}
}

0 comments on commit e7eaca8

Please sign in to comment.