2018-09-25 07:30:50 -04:00
|
|
|
<?php namespace BookStack\Uploads;
|
|
|
|
|
|
|
|
use BookStack\Entities\Page;
|
|
|
|
use BookStack\Ownable;
|
2016-10-09 13:58:22 -04:00
|
|
|
|
2016-11-12 09:12:26 -05:00
|
|
|
class Attachment extends Ownable
|
2016-10-09 13:58:22 -04:00
|
|
|
{
|
|
|
|
protected $fillable = ['name', 'order'];
|
|
|
|
|
2016-10-23 08:36:45 -04:00
|
|
|
/**
|
|
|
|
* Get the downloadable file name for this upload.
|
|
|
|
* @return mixed|string
|
|
|
|
*/
|
|
|
|
public function getFileName()
|
|
|
|
{
|
2019-09-13 18:58:40 -04:00
|
|
|
if (strpos($this->name, '.') !== false) {
|
2018-01-28 11:58:52 -05:00
|
|
|
return $this->name;
|
|
|
|
}
|
2016-10-23 08:36:45 -04:00
|
|
|
return $this->name . '.' . $this->extension;
|
|
|
|
}
|
|
|
|
|
2016-10-09 13:58:22 -04:00
|
|
|
/**
|
|
|
|
* Get the page this file was uploaded to.
|
2018-09-25 13:00:40 -04:00
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2016-10-09 13:58:22 -04:00
|
|
|
*/
|
|
|
|
public function page()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Page::class, 'uploaded_to');
|
|
|
|
}
|
|
|
|
|
2016-10-10 15:30:27 -04:00
|
|
|
/**
|
|
|
|
* Get the url of this file.
|
|
|
|
*/
|
2020-06-30 17:12:45 -04:00
|
|
|
public function getUrl(): string
|
2016-10-10 15:30:27 -04:00
|
|
|
{
|
2018-05-20 06:06:10 -04:00
|
|
|
if ($this->external && strpos($this->path, 'http') !== 0) {
|
|
|
|
return $this->path;
|
|
|
|
}
|
2019-08-04 09:26:39 -04:00
|
|
|
return url('/attachments/' . $this->id);
|
2016-10-10 15:30:27 -04:00
|
|
|
}
|
2020-07-28 05:45:28 -04:00
|
|
|
|
|
|
|
public function htmlLink(): string
|
|
|
|
{
|
|
|
|
return '<a target="_blank" href="'.e($this->getUrl()).'">'.e($this->name).'</a>';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function markdownLink(): string
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2016-10-09 13:58:22 -04:00
|
|
|
}
|