2018-04-16 01:26:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
2018-06-14 00:52:42 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2018-08-28 03:07:36 +00:00
|
|
|
use Storage;
|
2018-04-16 01:26:48 +00:00
|
|
|
|
|
|
|
class Media extends Model
|
|
|
|
{
|
2018-06-14 00:52:42 +00:00
|
|
|
use SoftDeletes;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be mutated to dates.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $dates = ['deleted_at'];
|
2018-08-28 03:07:36 +00:00
|
|
|
|
2019-01-21 19:18:08 +00:00
|
|
|
public function status()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Status::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function profile()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Profile::class);
|
|
|
|
}
|
|
|
|
|
2018-05-20 02:59:59 +00:00
|
|
|
public function url()
|
|
|
|
{
|
2018-11-04 03:19:22 +00:00
|
|
|
if(!empty($this->remote_media) && $this->remote_url) {
|
|
|
|
$url = $this->remote_url;
|
|
|
|
} else {
|
|
|
|
$path = $this->media_path;
|
2019-01-12 04:28:08 +00:00
|
|
|
$url = $this->cdn_url ?? Storage::url($path);
|
2018-11-04 03:19:22 +00:00
|
|
|
}
|
2018-08-28 03:07:36 +00:00
|
|
|
|
|
|
|
return url($url);
|
2018-05-20 02:59:59 +00:00
|
|
|
}
|
2018-07-12 16:39:55 +00:00
|
|
|
|
|
|
|
public function thumbnailUrl()
|
|
|
|
{
|
2019-03-04 05:39:52 +00:00
|
|
|
$path = $this->thumbnail_path ?? 'public/no-preview.png';
|
|
|
|
return url(Storage::url($path));
|
2018-07-12 16:39:55 +00:00
|
|
|
}
|
2018-10-10 01:24:42 +00:00
|
|
|
|
2019-01-21 19:18:08 +00:00
|
|
|
public function thumb()
|
|
|
|
{
|
|
|
|
return $this->thumbnailUrl();
|
|
|
|
}
|
|
|
|
|
2018-10-10 01:24:42 +00:00
|
|
|
public function mimeType()
|
|
|
|
{
|
|
|
|
return explode('/', $this->mime)[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function activityVerb()
|
|
|
|
{
|
|
|
|
$verb = 'Image';
|
|
|
|
switch ($this->mimeType()) {
|
2018-12-12 21:24:52 +00:00
|
|
|
case 'audio':
|
|
|
|
$verb = 'Audio';
|
|
|
|
break;
|
|
|
|
|
2018-10-10 01:24:42 +00:00
|
|
|
case 'image':
|
2018-12-12 21:24:52 +00:00
|
|
|
$verb = 'Image';
|
2018-10-10 01:24:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'video':
|
|
|
|
$verb = 'Video';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$verb = 'Document';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $verb;
|
|
|
|
}
|
2018-10-16 18:31:29 +00:00
|
|
|
|
|
|
|
public function getMetadata()
|
|
|
|
{
|
|
|
|
return json_decode($this->metadata, true, 3);
|
|
|
|
}
|
2018-11-04 03:19:22 +00:00
|
|
|
|
|
|
|
public function getModel()
|
|
|
|
{
|
|
|
|
if(empty($this->metadata)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$meta = $this->getMetadata();
|
|
|
|
if($meta && isset($meta['Model'])) {
|
|
|
|
return $meta['Model'];
|
|
|
|
}
|
|
|
|
}
|
2018-04-16 01:26:48 +00:00
|
|
|
}
|