Changed publish call to array of args. Fixed channel sort issue. Fixed anoymous name. LBRY Banner is now in blockquote. Save post perm_url from lbry
This commit is contained in:
parent
a35f857d05
commit
b0e7215427
8 changed files with 76 additions and 104 deletions
|
@ -115,8 +115,10 @@ class LBRYPress
|
|||
$this->define('LBRY_SPEECH', 'lbry_speech'); // the spee.ch address
|
||||
$this->define('LBRY_LICENSE', 'lbry_license'); // the license to publish with to the LBRY network
|
||||
$this->define('LBRY_LBC_PUBLISH', 'lbry_lbc_publish'); // amount of lbc to use per publish
|
||||
$this->define('LBRY_WILL_PUBLISH', 'lbry_will_publish'); // The meta key for if to publish to LBRY Network or not
|
||||
$this->define('LBRY_POST_CHANNEL', 'lbry_channel'); // The meta key for which channel to publish
|
||||
$this->define('LBRY_WILL_PUBLISH', '_lbry_will_publish'); // The meta key for if to publish to LBRY Network or not
|
||||
$this->define('LBRY_POST_CHANNEL', '_lbry_channel'); // The meta key for which channel to publish
|
||||
$this->define('LBRY_PERM_URL', '_lbry_perm_url'); // The meta key for the permanent url of the published lbry post
|
||||
$this->define('LBRY_SPEECH_ASSET_URL', 'speech_asset_url'); // The meta key for an asset's speech url
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,7 +235,7 @@ class LBRYPress
|
|||
return 0;
|
||||
}
|
||||
|
||||
if ($b->name == '(none / unattributed)') {
|
||||
if ($b->claim_id == 'null') {
|
||||
return -1;
|
||||
}
|
||||
return strnatcasecmp($a->name, $b->name);
|
||||
|
|
|
@ -7,8 +7,16 @@
|
|||
|
||||
class LBRY_Daemon
|
||||
{
|
||||
/**
|
||||
* The address of the Lbry Daemon
|
||||
* @var string
|
||||
*/
|
||||
private $address = 'localhost:5279';
|
||||
|
||||
/**
|
||||
* The Daemon Logger
|
||||
* @var LBRY_Daemon_Logger
|
||||
*/
|
||||
private $logger = null;
|
||||
|
||||
/**
|
||||
|
@ -17,17 +25,12 @@ class LBRY_Daemon
|
|||
public function __construct()
|
||||
{
|
||||
$this->logger = new LBRY_Daemon_Logger();
|
||||
$this->init();
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unused address
|
||||
* https://lbry.tech/api/sdk#address_unused
|
||||
* @return string Unused wallet address in base58
|
||||
* @return string Unused wallet address in base58
|
||||
*/
|
||||
public function wallet_unused_address()
|
||||
{
|
||||
|
@ -44,7 +47,7 @@ class LBRY_Daemon
|
|||
/**
|
||||
* Returns an array of Address lists
|
||||
* https://lbry.tech/api/sdk#address_list
|
||||
* @return array Array of address lists linked to this account
|
||||
* @return array Array of address lists linked to this account
|
||||
*/
|
||||
public function address_list()
|
||||
{
|
||||
|
@ -61,8 +64,8 @@ class LBRY_Daemon
|
|||
/**
|
||||
* Returns the balance of a current LBRY account
|
||||
* https://lbry.tech/api/sdk#account_balance
|
||||
* @param string $address Wallet Address
|
||||
* @return float Wallet Balance
|
||||
* @param string $address Wallet Address
|
||||
* @return float Wallet Balance
|
||||
*/
|
||||
public function wallet_balance()
|
||||
{
|
||||
|
@ -79,7 +82,7 @@ class LBRY_Daemon
|
|||
/**
|
||||
* Returns a list of channels for this account
|
||||
* https://lbry.tech/api/sdk#channel_list
|
||||
* @return array claim dictionary or null if empty
|
||||
* @return array claim dictionary or null if empty
|
||||
*/
|
||||
public function channel_list()
|
||||
{
|
||||
|
@ -96,12 +99,11 @@ class LBRY_Daemon
|
|||
/**
|
||||
* Create a claim for a new channel
|
||||
* https://lbry.tech/api/sdk#channel_new
|
||||
* @return array dictionary containing result of the request
|
||||
* @return array dictionary containing result of the request
|
||||
*/
|
||||
public function channel_new($channel_name, $bid_amount)
|
||||
{
|
||||
// TODO: Sanitize channel name and bid
|
||||
|
||||
// Make sure no @ sign, as we will add that
|
||||
if (strpos($channel_name, '@')) {
|
||||
throw new \Exception('Illegal character "@" in channel name', 1);
|
||||
|
@ -133,35 +135,15 @@ class LBRY_Daemon
|
|||
/**
|
||||
* Publishes a post to the LBRY Network
|
||||
* https://lbry.tech/api/sdk#publish
|
||||
* @param string $name The slug for the post
|
||||
* @param float $bid The amount of LBC to bid
|
||||
* @param string $filepath The path of the temporary content file
|
||||
* @param string $title The Title of the post
|
||||
* @param string $description The Description of the Post
|
||||
* @param string $language Two letter ISO Code of the language
|
||||
* @return string $channel The Claim ID of the Channel
|
||||
* @param array $args An array containing necessary data for publish post
|
||||
*
|
||||
* Available params:
|
||||
* ['name', 'bid', 'file_path', 'title', 'description', 'language', 'license', 'channel_id', 'thumbnail']
|
||||
*
|
||||
* @return object $result
|
||||
*/
|
||||
public function publish($name, $bid, $filepath, $title, $description, $language, $license, $channel, $thumbnail = false)
|
||||
public function publish($args)
|
||||
{
|
||||
$args = array(
|
||||
'name' => $name,
|
||||
'bid' => $bid,
|
||||
'file_path' => $filepath,
|
||||
'title' => $title,
|
||||
'description' => $description,
|
||||
'language' => $language,
|
||||
'license' => $license,
|
||||
);
|
||||
|
||||
// Make sure we aren't publishing to unattributed
|
||||
if ($channel != 'null') {
|
||||
$args['channel_id'] = $channel;
|
||||
}
|
||||
|
||||
if ($thumbnail) {
|
||||
$args['thumbnail'] = $thumbnail;
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->request(
|
||||
'publish',
|
||||
|
@ -177,9 +159,9 @@ class LBRY_Daemon
|
|||
|
||||
/**
|
||||
* Sends a cURL request to the LBRY Daemon
|
||||
* @param string $method The method to call on the LBRY API
|
||||
* @param array $params The Parameters to send the LBRY API Call
|
||||
* @return string The cURL response
|
||||
* @param string $method The method to call on the LBRY API
|
||||
* @param array $params The Parameters to send the LBRY API Call
|
||||
* @return string The cURL response
|
||||
*/
|
||||
private function request($method, $params = array())
|
||||
{
|
||||
|
|
|
@ -20,9 +20,6 @@ class LBRY_Network
|
|||
*/
|
||||
public $parser = null;
|
||||
|
||||
/**
|
||||
* [__construct description]
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->publisher = new LBRY_Network_Publisher();
|
||||
|
@ -63,7 +60,7 @@ class LBRY_Network
|
|||
* Handles saving the post meta that is relative to publishing to the LBRY Network
|
||||
* @param int $post_id The ID of the post we are saving
|
||||
* @param WP_Post $post The Post Object we are saving
|
||||
* @return int Returns post_id if user cannot edit post
|
||||
* @return int Returns post_id if user cannot edit post
|
||||
*/
|
||||
public function save_post_meta($post_id, $post)
|
||||
{
|
||||
|
@ -104,7 +101,7 @@ class LBRY_Network
|
|||
|
||||
/**
|
||||
* Returns the HTML for the LBRY Meta Box
|
||||
* @param [type] $post [description]
|
||||
* @param WP_POST $post
|
||||
*/
|
||||
public function meta_box_html($post)
|
||||
{
|
||||
|
|
|
@ -7,28 +7,14 @@
|
|||
|
||||
class LBRY_Network_Publisher
|
||||
{
|
||||
/**
|
||||
* [__construct description]
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish the post to the LBRY Network
|
||||
* @param int $post_id The ID of the post we are publishing
|
||||
* @param string $channel The Claim ID of the channel we are posting to
|
||||
* @param int $post_id The ID of the post we are publishing
|
||||
* @param string $channel The Claim ID of the channel we are posting to
|
||||
*/
|
||||
// NOTE: This is currently sitting at about 150ms, mostly the post parsing
|
||||
public function publish($post, $channel)
|
||||
public function publish($post, $channel = null)
|
||||
{
|
||||
|
||||
// TODO: Handle unnatributed channel
|
||||
// Leave if nothing to publish to
|
||||
if (!$channel) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get converted markdown into a file
|
||||
$filepath = LBRY_ABSPATH . 'tmp/' . $post->post_name . time() . '.md';
|
||||
$file = fopen($filepath, 'w');
|
||||
|
@ -40,16 +26,27 @@ class LBRY_Network_Publisher
|
|||
try {
|
||||
// If everything went well with the conversion, carry on
|
||||
if ($write_status) {
|
||||
$name = $post->post_name;
|
||||
$bid = number_format(floatval(get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH]), 2, '.', '');
|
||||
$title = $post->post_title;
|
||||
$language = substr(get_locale(), 0, 2);
|
||||
$license = get_option(LBRY_SETTINGS)[LBRY_LICENSE];
|
||||
$args = array(
|
||||
'name' => $post->post_name,
|
||||
'bid' => number_format(floatval(get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH]), 2, '.', ''),
|
||||
'file_path' => $filepath,
|
||||
'title' => $post->post_title,
|
||||
'language' => substr(get_locale(), 0, 2),
|
||||
'license' => get_option(LBRY_SETTINGS)[LBRY_LICENSE]
|
||||
);
|
||||
|
||||
// Setup channel
|
||||
if ($channel && $channel != 'null') {
|
||||
$args['channel_id'] = $channel;
|
||||
}
|
||||
|
||||
// Setup featured image
|
||||
$featured_id = get_post_thumbnail_id($post);
|
||||
$featured_image = wp_get_attachment_image_src($featured_id, 'medium');
|
||||
$thumbnail = $featured_image[0] ? $featured_image[0] : false;
|
||||
|
||||
if ($featured_image[0]) {
|
||||
$args['thumbnail'] = $featured_image[0];
|
||||
}
|
||||
|
||||
// Build description using Yoast if installed and its used, excerpt/title otherwise
|
||||
$description = false;
|
||||
|
@ -62,8 +59,12 @@ class LBRY_Network_Publisher
|
|||
}
|
||||
$description .= ' | Originally published at ' . get_permalink($post);
|
||||
|
||||
//TODO: Switch this to an array of args. This is getting out of hand.
|
||||
LBRY()->daemon->publish($name, $bid, $filepath, $title, $description, $language, $license, $channel, $thumbnail);
|
||||
$args['description'] = $description;
|
||||
|
||||
$result = LBRY()->daemon->publish($args);
|
||||
if ($result->success) {
|
||||
update_post_meta($post->ID, LBRY_PERM_URL, $result->output->permanent_url);
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log('Issue publishing post ' . $post->ID . ' to LBRY: ' . $e->getMessage());
|
||||
|
|
|
@ -120,9 +120,9 @@ class LBRY_Speech
|
|||
if ($result && $result->success) {
|
||||
$meta = wp_get_attachment_metadata($media->id);
|
||||
if ($media->image_size) {
|
||||
$meta['sizes'][$media->image_size]['speech_asset_url'] = $result->data->serveUrl;
|
||||
$meta['sizes'][$media->image_size][LBRY_SPEECH_ASSET_URL] = $result->data->serveUrl;
|
||||
} else {
|
||||
$meta['speech_asset_url'] = $result->data->serveUrl;
|
||||
$meta[LBRY_SPEECH_ASSET_URL] = $result->data->serveUrl;
|
||||
}
|
||||
wp_update_attachment_metadata($media->id, $meta);
|
||||
} else { // Something unhandled happened here
|
||||
|
@ -219,7 +219,7 @@ class LBRY_Speech
|
|||
*/
|
||||
public function is_published($meta)
|
||||
{
|
||||
if (key_exists('speech_asset_url', $meta) && $meta['speech_asset_url'] !== '') {
|
||||
if (key_exists(LBRY_SPEECH_ASSET_URL, $meta) && $meta[LBRY_SPEECH_ASSET_URL] !== '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ class LBRY_Speech_Parser
|
|||
|
||||
foreach ($sources as $width => $source) {
|
||||
// Check to see if it is using base image first
|
||||
if ($image_src == $source['url'] && key_exists('speech_asset_url', $image_meta)) {
|
||||
$new_sources[$width]['url'] = $image_meta['speech_asset_url'];
|
||||
if ($image_src == $source['url'] && key_exists(LBRY_SPEECH_ASSET_URL, $image_meta)) {
|
||||
$new_sources[$width]['url'] = $image_meta[LBRY_SPEECH_ASSET_URL];
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ class LBRY_Speech_Parser
|
|||
|
||||
// If the image is the same as the base image, return the base spee.ch url
|
||||
if (pathinfo($image[0])['basename'] == pathinfo($image_meta['file'])['basename']) {
|
||||
$new_image[0] = $image_meta['speech_asset_url'];
|
||||
$new_image[0] = $image_meta[LBRY_SPEECH_ASSET_URL];
|
||||
return $new_image;
|
||||
}
|
||||
|
||||
|
@ -65,22 +65,19 @@ class LBRY_Speech_Parser
|
|||
if (is_string($size)) {
|
||||
switch ($size) {
|
||||
case 'full':
|
||||
$new_image[0] = $image_meta['speech_asset_url'];
|
||||
$new_image[0] = $image_meta[LBRY_SPEECH_ASSET_URL];
|
||||
break;
|
||||
case 'post-thumbnail':
|
||||
if (LBRY()->speech->is_published($sizes['thumbnail'])) {
|
||||
$new_image[0] = $sizes['thumbnail']['speech_asset_url'];
|
||||
$new_image[0] = $sizes['thumbnail'][LBRY_SPEECH_ASSET_URL];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (key_exists($size, $sizes) && LBRY()->speech->is_published($sizes[$size])) {
|
||||
$new_image[0] = $sizes[$size]['speech_asset_url'];
|
||||
$new_image[0] = $sizes[$size][LBRY_SPEECH_ASSET_URL];
|
||||
}
|
||||
break;
|
||||
}
|
||||
// $time_end = microtime(true);
|
||||
// $time = ($time_end - $time_start) * 1000;
|
||||
// error_log("attachment image source in $time milliseconds");
|
||||
return $new_image;
|
||||
}
|
||||
|
||||
|
@ -101,7 +98,6 @@ class LBRY_Speech_Parser
|
|||
// COMBAK: Need to make this a bit faster. Sitting between 100 and 300ms currently
|
||||
public function replace_urls_with_speech($content)
|
||||
{
|
||||
// $time_start = microtime(true);
|
||||
$new_content = $content;
|
||||
|
||||
$assets = array();
|
||||
|
@ -131,10 +127,6 @@ class LBRY_Speech_Parser
|
|||
$new_content = str_replace($asset, $speech_url, $new_content);
|
||||
}
|
||||
}
|
||||
|
||||
// $time_end = microtime(true);
|
||||
// $time = ($time_end - $time_start) * 1000;
|
||||
// error_log("replace content urls in $time milliseconds");
|
||||
return $new_content;
|
||||
}
|
||||
|
||||
|
@ -247,8 +239,8 @@ class LBRY_Speech_Parser
|
|||
private function find_speech_url_by_width($sizes, $width)
|
||||
{
|
||||
foreach ($sizes as $key => $size) {
|
||||
if ($size['width'] == $width && key_exists('speech_asset_url', $size)) {
|
||||
return $size['speech_asset_url'];
|
||||
if ($size['width'] == $width && key_exists(LBRY_SPEECH_ASSET_URL, $size)) {
|
||||
return $size[LBRY_SPEECH_ASSET_URL];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -265,7 +257,7 @@ class LBRY_Speech_Parser
|
|||
{
|
||||
// See if this looks like video meta
|
||||
if (!key_exists('file', $meta) && key_exists('mime_type', $meta) && $meta['mime_type'] == 'video/mp4') {
|
||||
return $meta['speech_asset_url'];
|
||||
return $meta[LBRY_SPEECH_ASSET_URL];
|
||||
}
|
||||
|
||||
$pathinfo = pathinfo($url);
|
||||
|
@ -273,15 +265,15 @@ class LBRY_Speech_Parser
|
|||
|
||||
// Check main file or if $meta is just a url (video) first
|
||||
if (key_exists('file', $meta) && $basename == wp_basename($meta['file'])) {
|
||||
return $meta['speech_asset_url'];
|
||||
return $meta[LBRY_SPEECH_ASSET_URL];
|
||||
}
|
||||
|
||||
// Check to see if we have a meta option here
|
||||
if (key_exists('sizes', $meta)) {
|
||||
// Then check sizes
|
||||
foreach ($meta['sizes'] as $size => $meta) {
|
||||
if ($basename == $meta['file'] && key_exists('speech_asset_url', $meta)) {
|
||||
return $meta['speech_asset_url'];
|
||||
if ($basename == $meta['file'] && key_exists(LBRY_SPEECH_ASSET_URL, $meta)) {
|
||||
return $meta[LBRY_SPEECH_ASSET_URL];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -326,7 +318,6 @@ class LBRY_Speech_Parser
|
|||
$post_id = attachment_url_to_postid($url);
|
||||
}
|
||||
}
|
||||
|
||||
return (int) $post_id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
$unnatributed = (object) array(
|
||||
'name' => '(none / unattributed)',
|
||||
'name' => 'none (anonymous)',
|
||||
'claim_id' => 'null'
|
||||
);
|
||||
// TODO: Test what happens with empty channel list, can't remember the return value
|
||||
$channels = LBRY()->daemon->channel_list();
|
||||
$channels[] = $unnatributed;
|
||||
// Sort the channels in a natural way
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<div class="lbry-published-banner">
|
||||
<blockquote class="lbry-published-banner">
|
||||
<h5>This post has also been published to the <a href="https://lbry.io" target="_blank">LBRY blockchain</a> network.</h5>
|
||||
<h5><a href="https://lbry.io/learn" target="_blank">Click Here</a> to learn more about the benefits of content freedom.</h5>
|
||||
</div>
|
||||
</blockquote>
|
||||
|
|
Loading…
Reference in a new issue