Save ClaimID as post meta, ability to get Canonical URL

This commit is contained in:
Paul Kirby 2020-01-27 22:33:59 -06:00
parent 298bbf43c6
commit f7a3625754
4 changed files with 47 additions and 7 deletions

View file

@ -119,7 +119,8 @@ class LBRYPress
$this->define('LBRY_LBC_PUBLISH', 'lbry_lbc_publish'); // amount of lbc to use per publish $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_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_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_CLAIM_ID', '_lbry_claim_id'); // The Claim ID for the post as it was published on LBRY
$this->define('LBRY_CANONICAL_URL', '_lbry_canonical_url'); // The canonical url for the published lbry post
$this->define('LBRY_SPEECH_ASSET_URL', 'speech_asset_url'); // The meta key for an asset's speech url $this->define('LBRY_SPEECH_ASSET_URL', 'speech_asset_url'); // The meta key for an asset's speech url
} }

View file

@ -144,6 +144,36 @@ class LBRY_Daemon
} }
} }
/**
* Returns the canonical URL for the supplied claim ID, null otherwise
* @param string $claim_id
* @return string Canonical URL, null if not found
*/
public function canonical_url($claim_id)
{
try {
$result = $this->request(
'claim_search',
array(
'claim_id' => $claim_id,
'no_totals' => true
)
);
error_log(print_r($result, true));
$items = $result->result->items;
if (!$items) {
return null;
}
return $items[0]->canonical_url;
} catch (LBRYDaemonException $e) {
$this->logger->log('canonical_url error', $e->getMessage() . ' | Code: ' . $e->getCode());
return;
}
}
/** /**
* Publishes a post to the LBRY Network * Publishes a post to the LBRY Network
* https://lbry.tech/api/sdk#publish * https://lbry.tech/api/sdk#publish

View file

@ -77,7 +77,14 @@ class LBRY_Network_Publisher
$outputs = $result->outputs; $outputs = $result->outputs;
if ($outputs && is_array($outputs)) { if ($outputs && is_array($outputs)) {
update_post_meta($post->ID, LBRY_PERM_URL, $result->outputs[0]->permanent_url); $output = $result->outputs[0];
$claim_id = $output->claim_id;
// Set Claim ID
update_post_meta($post->ID, LBRY_CLAIM_ID, $claim_id);
// Set Canonical URL
$canonical_url = LBRY()->daemon->canonical_url($claim_id);
update_post_meta($post->ID, LBRY_CANONICAL_URL, $canonical_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());

View file

@ -1,13 +1,15 @@
<?php <?php
// HACK: Fix this so its not TAM specific $url = get_post_meta(get_the_id(), LBRY_PRETTY_URL, true);
global $post;
$slug = $post->post_name; // Backwards compatible if LBRY_PRETTY_URL wasn't set
$url = '@AntiMedia/' . $slug; if (!$url) {
$url = get_post_meta(get_the_id(), LBRY_PERM_URL, true);
}
?> ?>
<div class="lbry-published-banner"> <div class="lbry-published-banner">
<h5>Stored Safely on Blockchain</h5> <h5>Stored Safely on Blockchain</h5>
<p> <p>
This post is published to <a href="https://lbry.io/get">LBRY</a> blockchain at <a href="https://open.lbry.io/<?= $url ?>">lbry://<?= $url ?></a>. This post is published to <a href="https://lbry.io/get">LBRY</a> blockchain at <a href="<?= $url ?>"><?= $url ?></a>.
</p> </p>
<p> <p>
<a href="https://lbry.io/get" target="_blank">Try LBRY</a> to experience content freedom, earn crypto, and support The Anti-Media! <a href="https://lbry.io/get" target="_blank">Try LBRY</a> to experience content freedom, earn crypto, and support The Anti-Media!