commit
aa0c368fc6
3 changed files with 65 additions and 51 deletions
|
@ -148,9 +148,9 @@ class LBRY_Admin
|
||||||
*/
|
*/
|
||||||
public function wallet_callback()
|
public function wallet_callback()
|
||||||
{
|
{
|
||||||
// Get first available address from Daemon
|
// Get first available account address from Daemon
|
||||||
$address = LBRY()->daemon->address_list();
|
$address = LBRY()->daemon->address_list();
|
||||||
$address = is_array($address) && !empty($address) ? $address[0] : '';
|
$address = is_array($address) && !empty($address) ? $address[0]->address : '';
|
||||||
printf(
|
printf(
|
||||||
'<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" readonly />',
|
'<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" readonly />',
|
||||||
LBRY_WALLET,
|
LBRY_WALLET,
|
||||||
|
|
|
@ -45,15 +45,21 @@ class LBRY_Daemon
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of Address lists
|
* Returns an paginated array of Address lists
|
||||||
* https://lbry.tech/api/sdk#address_list
|
* https://lbry.tech/api/sdk#address_list
|
||||||
|
* @param int $page Pagination page number
|
||||||
* @return array Array of address lists linked to this account
|
* @return array Array of address lists linked to this account
|
||||||
*/
|
*/
|
||||||
public function address_list()
|
public function address_list($page = 1)
|
||||||
{
|
{
|
||||||
|
// Get 20 per page
|
||||||
|
$params = array(
|
||||||
|
'page' => $page,
|
||||||
|
'page_size' => 20
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
$result = $this->request('address_list');
|
$result = $this->request('address_list', $params);
|
||||||
return $result->result;
|
return $result->result->items;
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch (LBRYDaemonException $e) {
|
||||||
$this->logger->log('address_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log('address_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||||
LBRY()->notice->set_notice('error', 'Issue getting address list.');
|
LBRY()->notice->set_notice('error', 'Issue getting address list.');
|
||||||
|
@ -62,7 +68,7 @@ class LBRY_Daemon
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the balance of a current LBRY account
|
* Returns the available balance of a current LBRY account
|
||||||
* https://lbry.tech/api/sdk#account_balance
|
* https://lbry.tech/api/sdk#account_balance
|
||||||
* @param string $address Wallet Address
|
* @param string $address Wallet Address
|
||||||
* @return float Wallet Balance
|
* @return float Wallet Balance
|
||||||
|
@ -71,7 +77,7 @@ class LBRY_Daemon
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$result = $this->request('account_balance');
|
$result = $this->request('account_balance');
|
||||||
return $result->result;
|
return $result->result->available;
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch (LBRYDaemonException $e) {
|
||||||
$this->logger->log('account_balance error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log('account_balance error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||||
LBRY()->notice->set_notice('error', 'Issue getting account balance.');
|
LBRY()->notice->set_notice('error', 'Issue getting account balance.');
|
||||||
|
@ -82,12 +88,18 @@ class LBRY_Daemon
|
||||||
/**
|
/**
|
||||||
* Returns a list of channels for this account
|
* Returns a list of channels for this account
|
||||||
* https://lbry.tech/api/sdk#channel_list
|
* https://lbry.tech/api/sdk#channel_list
|
||||||
|
* @param int $page Pagination page number
|
||||||
* @return array claim dictionary or null if empty
|
* @return array claim dictionary or null if empty
|
||||||
*/
|
*/
|
||||||
public function channel_list()
|
public function channel_list($page = 1)
|
||||||
{
|
{
|
||||||
|
$params = array(
|
||||||
|
'page' => $page,
|
||||||
|
'page_size' => 20
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = $this->request('channel_list')->result;
|
$result = $this->request('channel_list', $params)->result->items;
|
||||||
return empty($result) ? null : $result;
|
return empty($result) ? null : $result;
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch (LBRYDaemonException $e) {
|
||||||
$this->logger->log('channel_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log('channel_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||||
|
@ -98,7 +110,7 @@ class LBRY_Daemon
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a claim for a new channel
|
* Create a claim for a new channel
|
||||||
* https://lbry.tech/api/sdk#channel_new
|
* https://lbry.tech/api/sdk#channel_create
|
||||||
* @return array dictionary containing result of the request
|
* @return array dictionary containing result of the request
|
||||||
*/
|
*/
|
||||||
public function channel_new($channel_name, $bid_amount)
|
public function channel_new($channel_name, $bid_amount)
|
||||||
|
@ -118,16 +130,16 @@ class LBRY_Daemon
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = $this->request(
|
$result = $this->request(
|
||||||
'channel_new',
|
'channel_create',
|
||||||
array(
|
array(
|
||||||
'channel_name' => $channel_name,
|
'name' => $channel_name,
|
||||||
'amount' => number_format(floatval($bid_amount), 2, '.', '')
|
'bid' => number_format(floatval($bid_amount), 2, '.', '')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return $result->result;
|
return $result->result;
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch (LBRYDaemonException $e) {
|
||||||
$this->logger->log('channel_new error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log('channel_new error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||||
LBRY()->notice->set_notice('error', 'Issue creating new channel.');
|
throw new \Exception('Issue creating new channel.', 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,51 +21,53 @@ class LBRY_Network_Publisher
|
||||||
$converted = LBRY()->network->parser->convert_to_markdown($post);
|
$converted = LBRY()->network->parser->convert_to_markdown($post);
|
||||||
$write_status = $file && fwrite($file, $converted);
|
$write_status = $file && fwrite($file, $converted);
|
||||||
fclose($file);
|
fclose($file);
|
||||||
$endtime = microtime(true);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!$write_status) {
|
||||||
|
throw new \Exception('Write Status failure', 1);
|
||||||
|
}
|
||||||
|
|
||||||
// If everything went well with the conversion, carry on
|
// If everything went well with the conversion, carry on
|
||||||
if ($write_status) {
|
$args = array(
|
||||||
$args = array(
|
'name' => $post->post_name,
|
||||||
'name' => $post->post_name,
|
'bid' => number_format(floatval(get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH]), 2, '.', ''),
|
||||||
'bid' => number_format(floatval(get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH]), 2, '.', ''),
|
'file_path' => $filepath,
|
||||||
'file_path' => $filepath,
|
'title' => $post->post_title,
|
||||||
'title' => $post->post_title,
|
'languages' => array(substr(get_locale(), 0, 2)),
|
||||||
'language' => substr(get_locale(), 0, 2),
|
'license' => get_option(LBRY_SETTINGS)[LBRY_LICENSE]
|
||||||
'license' => get_option(LBRY_SETTINGS)[LBRY_LICENSE]
|
);
|
||||||
);
|
|
||||||
|
|
||||||
// Setup channel
|
// Setup channel
|
||||||
if ($channel && $channel != 'null') {
|
if ($channel && $channel != 'null') {
|
||||||
$args['channel_id'] = $channel;
|
$args['channel_id'] = $channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup featured image
|
// Setup featured image
|
||||||
$featured_id = get_post_thumbnail_id($post);
|
$featured_id = get_post_thumbnail_id($post);
|
||||||
$featured_image = wp_get_attachment_image_src($featured_id, 'medium');
|
$featured_image = wp_get_attachment_image_src($featured_id, 'medium');
|
||||||
|
|
||||||
if ($featured_image[0]) {
|
if ($featured_image[0]) {
|
||||||
$args['thumbnail'] = $featured_image[0];
|
$args['thumbnail_url'] = $featured_image[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build description using Yoast if installed and its used, excerpt/title otherwise
|
// Build description using Yoast if installed and its used, excerpt/title otherwise
|
||||||
$description = false;
|
$description = false;
|
||||||
if (class_exists('WPSEO_META')) {
|
if (class_exists('WPSEO_META')) {
|
||||||
$description = WPSEO_META::get_value('opengraph-description', $post->ID);
|
$description = WPSEO_META::get_value('opengraph-description', $post->ID);
|
||||||
}
|
}
|
||||||
if (!$description) {
|
if (!$description) {
|
||||||
$excerpt = get_the_excerpt($post);
|
$excerpt = get_the_excerpt($post);
|
||||||
$description = $excerpt ? $excerpt : $post->post_title;
|
$description = $excerpt ? $excerpt : $post->post_title;
|
||||||
}
|
}
|
||||||
$description .= ' | Originally published at ' . get_permalink($post);
|
$description .= ' | Originally published at ' . get_permalink($post);
|
||||||
|
|
||||||
$args['description'] = $description;
|
$args['description'] = $description;
|
||||||
|
|
||||||
$result = LBRY()->daemon->publish($args);
|
$result = LBRY()->daemon->publish($args);
|
||||||
if ($result->success) {
|
$outputs = $result->outputs;
|
||||||
error_log(print_r($result, true));
|
|
||||||
update_post_meta($post->ID, LBRY_PERM_URL, $result->output->permanent_url);
|
if ($outputs && is_array($outputs)) {
|
||||||
}
|
update_post_meta($post->ID, LBRY_PERM_URL, $result->outputs[0]->permanent_url);
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
error_log('Issue publishing post ' . $post->ID . ' to LBRY: ' . $e->getMessage());
|
error_log('Issue publishing post ' . $post->ID . ' to LBRY: ' . $e->getMessage());
|
||||||
|
|
Loading…
Reference in a new issue