Media object in working order
This commit is contained in:
parent
b82ab89d59
commit
dcc4513f89
2 changed files with 62 additions and 28 deletions
|
@ -53,26 +53,19 @@ class LBRY_Speech
|
||||||
|
|
||||||
// IDEA: Notify user if post save time will take a while, may be a concern for request timeouts
|
// IDEA: Notify user if post save time will take a while, may be a concern for request timeouts
|
||||||
if ($all_media) {
|
if ($all_media) {
|
||||||
// error_log(print_r($all_media, true));
|
error_log(print_r($all_media, true));
|
||||||
foreach ($all_media as $media) {
|
foreach ($all_media as $media) {
|
||||||
// TODO: set post meta to see if already uploaded
|
// TODO: set post meta to see if already uploaded
|
||||||
|
|
||||||
|
$params = array(
|
||||||
|
'name' => $media->name,
|
||||||
|
'file' => $media->file,
|
||||||
|
'title' => $media->title,
|
||||||
|
'type' => $media->type
|
||||||
|
);
|
||||||
|
|
||||||
// Create a CURLFile object to pass our attachments to the spee.ch instance
|
$result = $this->request('publish', $params);
|
||||||
// $file_url = get_attached_file($attachment->ID);
|
error_log(print_r($result, true));
|
||||||
// $file_name = wp_basename($file_url);
|
|
||||||
// $file_type = $attachment->post_mime_type;
|
|
||||||
// $cfile = new CURLFile($file_url, $file_type, $file_name);
|
|
||||||
//
|
|
||||||
// $params = array(
|
|
||||||
// 'name' => $attachment->post_name,
|
|
||||||
// 'file' => $cfile,
|
|
||||||
// 'title' => $attachment->post_title,
|
|
||||||
// 'type' => $file_type
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// $result = $this->request('publish', $params);
|
|
||||||
// error_log(print_r($result, true));
|
|
||||||
|
|
||||||
// TODO: Make sure to warn if image name is already taken on channel
|
// TODO: Make sure to warn if image name is already taken on channel
|
||||||
}
|
}
|
||||||
|
@ -86,6 +79,8 @@ class LBRY_Speech
|
||||||
*/
|
*/
|
||||||
protected function find_media($post_id)
|
protected function find_media($post_id)
|
||||||
{
|
{
|
||||||
|
$all_media = array();
|
||||||
|
|
||||||
// Get content and put into a DOMDocument
|
// Get content and put into a DOMDocument
|
||||||
$content = apply_filters('the_content', get_post_field('post_content', $post_id));
|
$content = apply_filters('the_content', get_post_field('post_content', $post_id));
|
||||||
$DOM = new DOMDocument();
|
$DOM = new DOMDocument();
|
||||||
|
@ -98,7 +93,10 @@ class LBRY_Speech
|
||||||
|
|
||||||
// Get each image attribute
|
// Get each image attribute
|
||||||
foreach ($images as $image) {
|
foreach ($images as $image) {
|
||||||
error_log($image->getAttribute('src'));
|
$src = $image->getAttribute('src');
|
||||||
|
if ($this->is_local($src)) {
|
||||||
|
$all_media[] = new LBRY_Speech_Media($src);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse video tags based on wordpress output for local embedds
|
// Parse video tags based on wordpress output for local embedds
|
||||||
|
@ -106,10 +104,26 @@ class LBRY_Speech
|
||||||
foreach ($videos as $video) {
|
foreach ($videos as $video) {
|
||||||
$source = $video->getElementsByTagName('source');
|
$source = $video->getElementsByTagName('source');
|
||||||
$src = $source[0]->attributes->getNamedItem('src')->value;
|
$src = $source[0]->attributes->getNamedItem('src')->value;
|
||||||
error_log($src);
|
if ($this->is_local($src)) {
|
||||||
|
$all_media[] = new LBRY_Speech_Media($src);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return $all_media;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to see if a url is local to this installation
|
||||||
|
* @param string $url
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
private function is_local($url)
|
||||||
|
{
|
||||||
|
if (strpos($url, home_url()) !== false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,15 +25,35 @@ class LBRY_Speech_Media
|
||||||
|
|
||||||
public $thumbnail;
|
public $thumbnail;
|
||||||
|
|
||||||
public function __construct($name, $file, $type, $nsfw = null, $license = null, $title = null, $description = null, $thumbnail = null)
|
public function __construct($url, $args = array())
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
|
||||||
$this->file = $file;
|
// Set supplied arguments
|
||||||
$this->type = $type;
|
$default = array(
|
||||||
$this->nsfw = $nsfw;
|
'nsfw' => null,
|
||||||
$this->license = $license;
|
'license' => null,
|
||||||
$this->title = $title;
|
'title' => null,
|
||||||
$this->description = $description;
|
'description' => null,
|
||||||
$this->thumbnail = $thumbnail;
|
'thumbnail' => null
|
||||||
|
);
|
||||||
|
|
||||||
|
$settings = array_merge($default, array_intersect_key($args, $default));
|
||||||
|
|
||||||
|
foreach ($settings as $key => $value) {
|
||||||
|
$this->{$key} = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Name can't have extension in it.
|
||||||
|
// TODO: Get attachment ID... so we can mark postmeta when needed.
|
||||||
|
// Get name, file, and type from the URL
|
||||||
|
// First, strip of any query params
|
||||||
|
$url = strtok($url, '?');
|
||||||
|
$path = ABSPATH . str_replace(home_url(), '', $url);
|
||||||
|
error_log($path);
|
||||||
|
$type = mime_content_type($path);
|
||||||
|
$name = wp_basename($url);
|
||||||
|
$this->name = $name;
|
||||||
|
$this->file = new CURLFile($path, $type, $name);
|
||||||
|
$this->type = $type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue