X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/1ee3e779e4b9b0a92f701a72f21a72c83cb1ce68..refs/pull/2336/head:/app/Uploads/Attachment.php diff --git a/app/Uploads/Attachment.php b/app/Uploads/Attachment.php index 3f0b447df..66c032be5 100644 --- a/app/Uploads/Attachment.php +++ b/app/Uploads/Attachment.php @@ -3,6 +3,13 @@ use BookStack\Entities\Page; use BookStack\Ownable; +/** + * @property int id + * @property string name + * @property string path + * @property string extension + * @property bool external + */ class Attachment extends Ownable { protected $fillable = ['name', 'order']; @@ -30,13 +37,28 @@ class Attachment extends Ownable /** * Get the url of this file. - * @return string */ - public function getUrl() + public function getUrl(): string { if ($this->external && strpos($this->path, 'http') !== 0) { return $this->path; } return url('/http/source.bookstackapp.com/attachments/' . $this->id); } + + /** + * Generate a HTML link to this attachment. + */ + public function htmlLink(): string + { + return ''.e($this->name).''; + } + + /** + * Generate a markdown link to this attachment. + */ + public function markdownLink(): string + { + return '['. $this->name .']('. $this->getUrl() .')'; + } }