Widget slug proper dynamic URLS #20

Merged
prkirby merged 2 commits from widget-slug into master 2020-01-28 05:58:14 +01:00
4 changed files with 58 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,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 * 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,24 @@
<?php <?php
// HACK: Fix this so its not TAM specific $url = get_post_meta(get_the_id(), LBRY_CANONICAL_URL, true);
global $post; if (!$url) {
$slug = $post->post_name; // Get channel canonical for backwards compatibility
$url = '@AntiMedia/' . $slug; $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);
}
?> ?>
<div class="lbry-published-banner"> <div class="lbry-published-banner">
<h5>Stored Safely on Blockchain</h5> <h5>Stored Safely on Blockchain</h5>
kauffj commented 2020-01-28 15:26:05 +01:00 (Migrated from github.com)
Review

str_replace(['lbry://', '#'], ['open.lbry.com/', ':'], $url);

`str_replace(['lbry://', '#'], ['open.lbry.com/', ':'], $url);`
<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
<?php if($url): ?>
at <a href="https://<?= $url ?>"><?= $url ?></a>.
<?php else: ?>
.
<?php endif; ?>
</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!