Published post to lbry network
This commit is contained in:
parent
c4c818b820
commit
8bc336952d
5 changed files with 84 additions and 18 deletions
|
@ -80,6 +80,35 @@ class LBRY_Daemon
|
||||||
return $result->result;
|
return $result->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publishes a post to the LBRY Network
|
||||||
|
* @param [type] $name [description]
|
||||||
|
* @param [type] $bid [description]
|
||||||
|
* @param [type] $filepath [description]
|
||||||
|
* @param [type] $title [description]
|
||||||
|
* @param [type] $description [description]
|
||||||
|
* @param [type] $language [description]
|
||||||
|
* @return [type] [description]
|
||||||
|
*/
|
||||||
|
public function publish($name, $bid, $filepath, $title, $description, $language, $channel)
|
||||||
|
{
|
||||||
|
// TODO: Bring thumbnails into the mix
|
||||||
|
$result = $this->request(
|
||||||
|
'publish',
|
||||||
|
array(
|
||||||
|
'name' => $name,
|
||||||
|
'bid' => $bid,
|
||||||
|
'file_path' => $filepath,
|
||||||
|
'title' => $title,
|
||||||
|
'description' => $description,
|
||||||
|
'language' => $language,
|
||||||
|
'channel_name' => $channel
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->check_for_errors($result);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a cURL request to the LBRY Daemon
|
* Sends a cURL request to the LBRY Daemon
|
||||||
* @param string $method The method to call on the LBRY API
|
* @param string $method The method to call on the LBRY API
|
||||||
|
|
|
@ -22,18 +22,22 @@ class LBRY_Network_Parser
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function convert_to_markdown($post_id)
|
/**
|
||||||
|
* Converts a post into markdown.
|
||||||
|
* @param WP_Post $post The post to be converted
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function convert_to_markdown($post)
|
||||||
{
|
{
|
||||||
$post = get_post($post_id);
|
// $title = '<h1>' . $post->post_title . '</h1>';
|
||||||
$title = '<h1>' . $post->post_title . '</h1>';
|
//
|
||||||
|
// $featured_image = get_the_post_thumbnail($post);
|
||||||
$featured_image = get_the_post_thumbnail($post);
|
//
|
||||||
|
// $content = $title;
|
||||||
$content = $title;
|
// if ($featured_image) {
|
||||||
if ($featured_image) {
|
// $content .= $featured_image . '<br />';
|
||||||
$content .= $featured_image . '<br />';
|
// }
|
||||||
}
|
$content = apply_filters('the_content', $post->post_content);
|
||||||
$content .= apply_filters('the_content', get_post($post_id)->post_content);
|
|
||||||
$converted = $this->converter->convert($content);
|
$converted = $this->converter->convert($content);
|
||||||
|
|
||||||
return $converted;
|
return $converted;
|
||||||
|
|
|
@ -21,8 +21,41 @@ class LBRY_Network_Publisher
|
||||||
*/
|
*/
|
||||||
public function publish($post, $channels)
|
public function publish($post, $channels)
|
||||||
{
|
{
|
||||||
$name = $post->post_name;
|
// Leave if nothing to publish to
|
||||||
|
if (!$channels) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
// Get converted markdown into a file
|
||||||
|
$filepath = LBRY_ABSPATH . 'tmp/' . $post->post_name . time() . '.md';
|
||||||
|
$file = fopen($filepath, 'w');
|
||||||
|
$converted = LBRY()->network->parser->convert_to_markdown($post);
|
||||||
|
$write_status = $file && fwrite($file, $converted);
|
||||||
|
fclose($file);
|
||||||
|
|
||||||
|
// TODO: Catch relative exceptions if necessary
|
||||||
|
try {
|
||||||
|
// If everything went well with the conversion, carry on
|
||||||
|
if ($write_status) {
|
||||||
|
$featured_image = get_the_post_thumbnail($post);
|
||||||
|
|
||||||
|
$name = $post->post_name;
|
||||||
|
$bid = get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH];
|
||||||
|
$title = $post->post_title;
|
||||||
|
$language = substr(get_locale(), 0, 2);
|
||||||
|
$license = get_option(LBRY_SETTINGS)[LBRY_LICENSE];
|
||||||
|
// TODO: See if we can grab from yoast or a default?
|
||||||
|
$description = $post->post_title;
|
||||||
|
// TODO: Bring thumbnails into the mix
|
||||||
|
// $thumbnail = $featured_image ? $featured_image : null;
|
||||||
|
|
||||||
|
foreach ($channels as $channel) {
|
||||||
|
LBRY()->daemon->publish($name, $bid, $filepath, $title, $description, $language, $channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
// Delete the temporary markdown file
|
||||||
|
unlink($filepath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,7 @@ class LBRYPress
|
||||||
spl_autoload_register(array($this, 'lbry_autoload_register'));
|
spl_autoload_register(array($this, 'lbry_autoload_register'));
|
||||||
$this->init();
|
$this->init();
|
||||||
$this->init_hooks();
|
$this->init_hooks();
|
||||||
|
error_log("language: " . get_locale());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
$LBRY = LBRY();
|
$LBRY = LBRY();
|
||||||
$unnatributed = (object) array(
|
$unnatributed = (object) array(
|
||||||
'name' => 'Unattributed',
|
'name' => 'unattributed',
|
||||||
'permanent_url' => 'unattributed'
|
|
||||||
);
|
);
|
||||||
$channels = LBRY()->daemon->channel_list();
|
$channels = LBRY()->daemon->channel_list();
|
||||||
array_unshift($channels, $unnatributed);
|
array_unshift($channels, $unnatributed);
|
||||||
|
@ -15,8 +14,8 @@ $cur_channels = get_post_meta($post->ID, 'lbry_channels');
|
||||||
<?php foreach ($channels as $channel): ?>
|
<?php foreach ($channels as $channel): ?>
|
||||||
<li>
|
<li>
|
||||||
<label class="selectit">
|
<label class="selectit">
|
||||||
<input type="checkbox" name="lbry_channels[]" value="<?= $channel->permanent_url ?>"
|
<input type="checkbox" name="lbry_channels[]" value="<?= $channel->name ?>"
|
||||||
<?php if (in_array($channel->permanent_url, $cur_channels)): ?>
|
<?php if (in_array($channel->name, $cur_channels)): ?>
|
||||||
checked="true"
|
checked="true"
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in a new issue