2018-10-26 08:34:13 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Data container for necessary Speech api media uploaduploads
|
|
|
|
*
|
|
|
|
* Visit https://github.com/lbryio/spee.ch for more info
|
|
|
|
*
|
|
|
|
* @package LBRYPress
|
|
|
|
*/
|
2022-02-14 02:34:20 +01:00
|
|
|
defined('ABSPATH') || die(); // Exit if accessed directly
|
2018-10-26 08:34:13 +02:00
|
|
|
|
|
|
|
class LBRY_Speech_Media
|
|
|
|
{
|
2018-10-26 18:13:24 +02:00
|
|
|
public $id;
|
|
|
|
|
2018-10-26 08:34:13 +02:00
|
|
|
public $name;
|
|
|
|
|
|
|
|
public $file;
|
|
|
|
|
|
|
|
public $type;
|
|
|
|
|
|
|
|
public $nsfw;
|
|
|
|
|
|
|
|
public $license;
|
|
|
|
|
|
|
|
public $title;
|
|
|
|
|
|
|
|
public $description;
|
|
|
|
|
|
|
|
public $thumbnail;
|
|
|
|
|
2019-01-28 23:32:15 +01:00
|
|
|
// public $image_size = false;
|
2018-10-27 21:28:20 +02:00
|
|
|
|
2018-10-27 23:49:44 +02:00
|
|
|
public function __construct(int $attachment_id, $args = array())
|
2018-10-26 08:34:13 +02:00
|
|
|
{
|
2018-10-26 09:43:34 +02:00
|
|
|
|
|
|
|
// Set supplied arguments
|
|
|
|
$default = array(
|
|
|
|
'nsfw' => null,
|
|
|
|
'license' => null,
|
|
|
|
'description' => null,
|
2018-10-27 23:49:44 +02:00
|
|
|
'thumbnail' => null,
|
2019-01-28 23:32:15 +01:00
|
|
|
// 'image_size' => false,
|
2018-10-26 09:43:34 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$settings = array_merge($default, array_intersect_key($args, $default));
|
|
|
|
|
|
|
|
foreach ($settings as $key => $value) {
|
|
|
|
$this->{$key} = $value;
|
|
|
|
}
|
|
|
|
|
2018-10-26 18:13:24 +02:00
|
|
|
|
2018-10-27 23:49:44 +02:00
|
|
|
// Get attachment ID, name, file, and type from the URL
|
|
|
|
$this->id = $attachment_id;
|
|
|
|
|
|
|
|
|
|
|
|
$path = get_attached_file($this->id);
|
|
|
|
|
|
|
|
// Apply data dependent on whether this is an image 'size' or not
|
2019-01-28 23:32:15 +01:00
|
|
|
// if ($this->image_size) {
|
|
|
|
// $meta = wp_get_attachment_metadata($this->id)['sizes'][$this->image_size];
|
|
|
|
// $pathinfo = pathinfo($meta['file']);
|
|
|
|
// $ext = '.' . $pathinfo['extension'];
|
|
|
|
// $new_ext = '-' . $meta['width'] . 'x' . $meta['height'] . $ext;
|
|
|
|
// $path = str_replace($ext, $new_ext, $path);
|
|
|
|
// $filename = $pathinfo['basename'];
|
|
|
|
// // COMBAK: Probably wont need this underscore check with Daemon V3
|
|
|
|
// $this->name = str_replace('_', '-', $pathinfo['filename']);
|
|
|
|
// $this->type = $meta['mime-type'];
|
|
|
|
// $this->title = $pathinfo['filename'];
|
|
|
|
// } else {
|
|
|
|
$attachment = get_post($this->id);
|
|
|
|
$filename = wp_basename($path);
|
|
|
|
$this->name = str_replace('_', '-', $attachment->post_name);
|
|
|
|
$this->type = $attachment->post_mime_type;
|
|
|
|
$this->title = $attachment->post_title;
|
|
|
|
// }
|
2018-10-26 18:13:24 +02:00
|
|
|
|
2018-10-27 23:49:44 +02:00
|
|
|
$this->file = new CURLFile($path, $this->type, $filename);
|
2018-10-26 08:34:13 +02:00
|
|
|
}
|
|
|
|
}
|