Publishing to Spee.ch Succesfully

This commit is contained in:
Paul Kirby 2018-10-26 11:46:28 -05:00
parent b0d35d98ee
commit 9f62d244ab

View file

@ -18,7 +18,7 @@ class LBRY_Speech
public function __construct() public function __construct()
{ {
$this->parser = new LBRY_Speech_Parser(); $this->parser = new LBRY_Speech_Parser();
add_action('save_post', array($this, 'upload_media')); add_action('save_post', array($this, 'upload_media'), 10, 2);
} }
/** /**
@ -40,8 +40,13 @@ class LBRY_Speech
* @return bool True if successful, false if not or if no Speech URL available * @return bool True if successful, false if not or if no Speech URL available
*/ */
// TODO: set up error reporting // TODO: set up error reporting
public function upload_media($post_id) public function upload_media($post_id, $post)
{ {
// Only check post_type of Post
if ('post' !== $post->post_type) {
return;
}
$speech_url = get_option(LBRY_SETTINGS)[LBRY_SPEECH]; $speech_url = get_option(LBRY_SETTINGS)[LBRY_SPEECH];
// Die if we don't have a spee.ch url // Die if we don't have a spee.ch url
@ -53,25 +58,29 @@ 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));
foreach ($all_media as $media) { foreach ($all_media as $media) {
// TODO: set post meta to see if already uploaded if (! get_post_meta($media->id, 'lbry_speech_uploaded')) {
$params = array(
'name' => $media->name,
'file' => $media->file,
'title' => $media->title,
'type' => $media->type
);
$params = array( if (LBRY_SPEECH_CHANNEL && LBRY_SPEECH_CHANNEL_PASSWORD) {
'name' => $media->name, $params['channelName'] = LBRY_SPEECH_CHANNEL;
'file' => $media->file, $params['channelPassword'] = LBRY_SPEECH_CHANNEL_PASSWORD;
'title' => $media->title, }
'type' => $media->type
);
if (LBRY_SPEECH_CHANNEL && LBRY_SPEECH_CHANNEL_PASSWORD) { $result = $this->request('publish', $params);
$params['channelName'] = LBRY_SPEECH_CHANNEL; error_log(print_r($result, true));
$params['channelPassword'] = LBRY_SPEECH_CHANNEL_PASSWORD;
if ($result->success) {
update_post_meta($media->id, 'lbry_speech_uploaded', true);
update_post_meta($media->id, 'lbry_speech_url', $result->data->serveUrl);
}
} }
$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
} }
} }
@ -88,6 +97,9 @@ class LBRY_Speech
// 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));
if (!$content) {
return $all_media;
}
$DOM = new DOMDocument(); $DOM = new DOMDocument();
// Hide HTML5 Tag warnings // Hide HTML5 Tag warnings
libxml_use_internal_errors(true); libxml_use_internal_errors(true);
@ -148,8 +160,6 @@ class LBRY_Speech
$address = $speech_url . '/api/claim/' . $method; $address = $speech_url . '/api/claim/' . $method;
error_log(print_r($params, true));
// Send it via curl // Send it via curl
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $address); curl_setopt($ch, CURLOPT_URL, $address);