Succesfully creating Speech Media Object
This commit is contained in:
parent
dcc4513f89
commit
b0d35d98ee
3 changed files with 50 additions and 12 deletions
|
@ -64,6 +64,11 @@ class LBRY_Speech
|
||||||
'type' => $media->type
|
'type' => $media->type
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (LBRY_SPEECH_CHANNEL && LBRY_SPEECH_CHANNEL_PASSWORD) {
|
||||||
|
$params['channelName'] = LBRY_SPEECH_CHANNEL;
|
||||||
|
$params['channelPassword'] = LBRY_SPEECH_CHANNEL_PASSWORD;
|
||||||
|
}
|
||||||
|
|
||||||
$result = $this->request('publish', $params);
|
$result = $this->request('publish', $params);
|
||||||
error_log(print_r($result, true));
|
error_log(print_r($result, true));
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
class LBRY_Speech_Media
|
class LBRY_Speech_Media
|
||||||
{
|
{
|
||||||
|
public $id;
|
||||||
|
|
||||||
public $name;
|
public $name;
|
||||||
|
|
||||||
public $file;
|
public $file;
|
||||||
|
@ -32,7 +34,6 @@ class LBRY_Speech_Media
|
||||||
$default = array(
|
$default = array(
|
||||||
'nsfw' => null,
|
'nsfw' => null,
|
||||||
'license' => null,
|
'license' => null,
|
||||||
'title' => null,
|
|
||||||
'description' => null,
|
'description' => null,
|
||||||
'thumbnail' => null
|
'thumbnail' => null
|
||||||
);
|
);
|
||||||
|
@ -43,17 +44,46 @@ class LBRY_Speech_Media
|
||||||
$this->{$key} = $value;
|
$this->{$key} = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Name can't have extension in it.
|
// Get attachment ID, name, file, and type from the URL
|
||||||
// TODO: Get attachment ID... so we can mark postmeta when needed.
|
$url = strtok($url, '?'); // Clean up query params first
|
||||||
// Get name, file, and type from the URL
|
$id = $this->rigid_attachment_url_to_postid($url);
|
||||||
// First, strip of any query params
|
$attachment = get_post($id);
|
||||||
$url = strtok($url, '?');
|
$path = get_attached_file($id);
|
||||||
$path = ABSPATH . str_replace(home_url(), '', $url);
|
$type = $attachment->post_mime_type;
|
||||||
error_log($path);
|
$filename = wp_basename($path);
|
||||||
$type = mime_content_type($path);
|
|
||||||
$name = wp_basename($url);
|
$this->id = $id;
|
||||||
$this->name = $name;
|
// COMBAK: Probably wont need this underscore check with Daemon V3
|
||||||
$this->file = new CURLFile($path, $type, $name);
|
$this->name = str_replace('_', '-', $attachment->post_name);
|
||||||
|
$this->file = new CURLFile($path, $type, $filename);
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
$this->title = $attachment->post_title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks for image crop sizes and filters out query params
|
||||||
|
* Courtesy of this post: http://bordoni.me/get-attachment-id-by-image-url/
|
||||||
|
* @param string $url The url of the attachment you want an ID for
|
||||||
|
* @return int The found post_id
|
||||||
|
*/
|
||||||
|
private function rigid_attachment_url_to_postid($url)
|
||||||
|
{
|
||||||
|
$post_id = attachment_url_to_postid($url);
|
||||||
|
|
||||||
|
if (! $post_id) {
|
||||||
|
$dir = wp_upload_dir();
|
||||||
|
$path = $url;
|
||||||
|
|
||||||
|
if (0 === strpos($path, $dir['baseurl'] . '/')) {
|
||||||
|
$path = substr($path, strlen($dir['baseurl'] . '/'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match('/^(.*)(\-\d*x\d*)(\.\w{1,})/i', $path, $matches)) {
|
||||||
|
$url = $dir['baseurl'] . '/' . $matches[1] . $matches[3];
|
||||||
|
$post_id = attachment_url_to_postid($url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) $post_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,9 @@ function LBRY()
|
||||||
if (! class_exists('LBRYPress')) {
|
if (! class_exists('LBRYPress')) {
|
||||||
require_once(dirname(__FILE__) . '/classes/LBRYPress.php');
|
require_once(dirname(__FILE__) . '/classes/LBRYPress.php');
|
||||||
}
|
}
|
||||||
|
// Bring in configuration requirements
|
||||||
|
// HACK: Will probably be getting rid of configuration once we sort out Spee.ch Implementation
|
||||||
|
require_once(dirname(__FILE__) . '/lbry_config.php');
|
||||||
return LBRYPress::instance();
|
return LBRYPress::instance();
|
||||||
} else {
|
} else {
|
||||||
add_action('admin_notices', 'lbry_requirements_error');
|
add_action('admin_notices', 'lbry_requirements_error');
|
||||||
|
|
Loading…
Reference in a new issue