diff --git a/classes/LBRYPress.php b/classes/LBRYPress.php index 808cf41..02cb819 100644 --- a/classes/LBRYPress.php +++ b/classes/LBRYPress.php @@ -119,7 +119,8 @@ class LBRYPress $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_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 } diff --git a/classes/LBRY_Daemon.php b/classes/LBRY_Daemon.php index 1e1038a..84ccd44 100644 --- a/classes/LBRY_Daemon.php +++ b/classes/LBRY_Daemon.php @@ -144,6 +144,38 @@ 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 = null) + { + if (!$claim_id) { + return null; + } + + try { + $result = $this->request( + 'claim_search', + array( + 'claim_id' => $claim_id, + 'no_totals' => 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 * https://lbry.tech/api/sdk#publish diff --git a/classes/LBRY_Network_Publisher.php b/classes/LBRY_Network_Publisher.php index 33bc443..89cb9ee 100644 --- a/classes/LBRY_Network_Publisher.php +++ b/classes/LBRY_Network_Publisher.php @@ -77,7 +77,14 @@ class LBRY_Network_Publisher $outputs = $result->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) { error_log('Issue publishing post ' . $post->ID . ' to LBRY: ' . $e->getMessage()); diff --git a/templates/published_on_lbry_banner.php b/templates/published_on_lbry_banner.php index 30b2a3b..8b9eb13 100644 --- a/templates/published_on_lbry_banner.php +++ b/templates/published_on_lbry_banner.php @@ -1,13 +1,24 @@ post_name; - $url = '@AntiMedia/' . $slug; + $url = get_post_meta(get_the_id(), LBRY_CANONICAL_URL, true); + if (!$url) { + // Get channel canonical for backwards compatibility + $channel_id = get_post_meta(get_the_id(), LBRY_POST_CHANNEL, true); + $url = LBRY()->daemon->canonical_url($channel_id); + } + + if ($url) { + $url = str_replace('lbry://', 'lbry.tv/', $url); + } ?>
Stored Safely on Blockchain

- This post is published to LBRY blockchain at lbry://. + This post is published to LBRY blockchain + + at . + + . +

Try LBRY to experience content freedom, earn crypto, and support The Anti-Media!