From f7a362575408abadbed2afe1b66fd7bd3c1f9aaf Mon Sep 17 00:00:00 2001 From: Paul Kirby Date: Mon, 27 Jan 2020 22:33:59 -0600 Subject: [PATCH 1/2] Save ClaimID as post meta, ability to get Canonical URL --- classes/LBRYPress.php | 3 ++- classes/LBRY_Daemon.php | 30 ++++++++++++++++++++++++++ classes/LBRY_Network_Publisher.php | 9 +++++++- templates/published_on_lbry_banner.php | 12 ++++++----- 4 files changed, 47 insertions(+), 7 deletions(-) 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..3f18a75 100644 --- a/classes/LBRY_Daemon.php +++ b/classes/LBRY_Daemon.php @@ -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 * 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..5254aa3 100644 --- a/templates/published_on_lbry_banner.php +++ b/templates/published_on_lbry_banner.php @@ -1,13 +1,15 @@ post_name; - $url = '@AntiMedia/' . $slug; + $url = get_post_meta(get_the_id(), LBRY_PRETTY_URL, true); + + // Backwards compatible if LBRY_PRETTY_URL wasn't set + if (!$url) { + $url = get_post_meta(get_the_id(), LBRY_PERM_URL, true); + } ?>
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! From f42c3a65cf483de48a1d40da4314665ed97341da Mon Sep 17 00:00:00 2001 From: Paul Kirby Date: Mon, 27 Jan 2020 22:54:40 -0600 Subject: [PATCH 2/2] Get Channel canonical for widget if claimID wasn't set --- classes/LBRY_Daemon.php | 8 +++++--- templates/published_on_lbry_banner.php | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/classes/LBRY_Daemon.php b/classes/LBRY_Daemon.php index 3f18a75..84ccd44 100644 --- a/classes/LBRY_Daemon.php +++ b/classes/LBRY_Daemon.php @@ -149,8 +149,12 @@ class LBRY_Daemon * @param string $claim_id * @return string Canonical URL, null if not found */ - public function canonical_url($claim_id) + public function canonical_url($claim_id = null) { + if (!$claim_id) { + return null; + } + try { $result = $this->request( 'claim_search', @@ -160,8 +164,6 @@ class LBRY_Daemon ) ); - error_log(print_r($result, true)); - $items = $result->result->items; if (!$items) { return null; diff --git a/templates/published_on_lbry_banner.php b/templates/published_on_lbry_banner.php index 5254aa3..8b9eb13 100644 --- a/templates/published_on_lbry_banner.php +++ b/templates/published_on_lbry_banner.php @@ -1,15 +1,24 @@ 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 . + This post is published to LBRY blockchain + + at . + + . +

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