X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/919660678bec2b94eaa84ac60d0313f5ef07dfb7..refs/pull/2511/head:/app/Uploads/Attachment.php diff --git a/app/Uploads/Attachment.php b/app/Uploads/Attachment.php index 11c1408eb..d1060477d 100644 --- a/app/Uploads/Attachment.php +++ b/app/Uploads/Attachment.php @@ -1,10 +1,20 @@ name, '.')) { + if (strpos($this->name, '.') !== false) { return $this->name; } return $this->name . '.' . $this->extension; @@ -21,7 +31,7 @@ class Attachment extends Ownable /** * Get the page this file was uploaded to. - * @return Page + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function page() { @@ -30,13 +40,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 baseUrl('/attachments/' . $this->id); + 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() .')'; } }