show supports amounts, better logic for when to show select boxes (#67)

This commit is contained in:
Lemuel Smyth 2022-02-19 13:04:38 -06:00 committed by GitHub
parent 9a0a8350ad
commit 9acd398393
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 290 additions and 91 deletions

View file

@ -14,6 +14,12 @@
margin-bottom: -.2em; margin-bottom: -.2em;
} }
.channel-bid-icon-lbc {
height: 1.1em;
margin-right: .1em;
margin-bottom: -.2em;
}
.lbry-pub-metabox { .lbry-pub-metabox {
margin: 0 0 0 -.2em; margin: 0 0 0 -.2em;
padding: 0 .2em 0 0 ; padding: 0 .2em 0 0 ;
@ -21,14 +27,14 @@
.meta-icon-lbry { .meta-icon-lbry {
height: 1.55em; height: 1.55em;
margin-bottom: -.4em; margin-bottom: -.4em;
padding-left: .1em; padding: 0 .1em 0 0;
} }
.lbry-meta-checkbox-wrapper { .lbry-meta-checkbox-wrapper {
padding: .5em .8em .6em; padding: .5em .8em .6em;
} }
.lbry-meta-wrapper-last { .lbry-meta-wrapper-last {
padding: 0em .8em 1.2em; padding: 0em .8em 1.5em;
} }
.lbry-meta-label { .lbry-meta-label {
@ -79,4 +85,39 @@
.lbry-meta-bx-content-last { .lbry-meta-bx-content-last {
padding: .2em .8em 1em .1em; padding: .2em .8em 1em .1em;
}
table.lbry-channel-table {
width: 100%;
border-collapse: collapse;
font-family: Georgia;
}
.lbry-channel-table th, .lbry-channel-table td {
padding: .4em 1.6em;
border: 2px solid #fff;
background: #fbd7b4;
font-size: 1em;
}
.lbry-channel-table thead th {
padding: .5em 2em;
background: #f69546;
text-align: left;
font-weight: normal;
font-size: 1.2em;
color: #fff;
}
.lbry-channel-table tbody tr:nth-child(odd) *:nth-child(even), .lbry-channel-table tbody tr:nth-child(even) *:nth-child(odd) {
background: #f3eddd;
}
.lbry-channel-table tfoot th {
padding: .5em 2em;
background: #f69546;
text-align: left;
font-weight: normal;
font-size: .9em;
color: #fff;
}
.lbry-channel-table tr *:nth-child(3), .lbry-channel-table tr *:nth-child(4) {
/* text-align: right; */
} }

View file

@ -19,6 +19,7 @@ class LBRY_Admin
add_action('admin_init', array($this, 'page_init')); add_action('admin_init', array($this, 'page_init'));
add_action('admin_init', array($this, 'wallet_balance_warning')); add_action('admin_init', array($this, 'wallet_balance_warning'));
add_action('admin_post_lbry_add_channel', array($this, 'add_channel')); add_action('admin_post_lbry_add_channel', array($this, 'add_channel'));
add_action('admin_post_lbry_supports_add', array($this, 'supports_add'));
} }
/** /**
@ -33,7 +34,7 @@ class LBRY_Admin
'manage_options', 'manage_options',
LBRY_ADMIN_PAGE, LBRY_ADMIN_PAGE,
array( $this, 'options_page_html' ), array( $this, 'options_page_html' ),
plugin_dir_url( LBRY_PLUGIN_FILE ) . '/admin/images/lbry-icon.png' plugin_dir_url( LBRY_PLUGIN_FILE ) . '/admin/images/lbry-icon.png'
); );
// Admin stylesheet enqueue // Admin stylesheet enqueue
@ -253,19 +254,56 @@ class LBRY_Admin
public function available_channels_callback() public function available_channels_callback()
{ {
$channel_list = LBRY()->daemon->channel_list(); $channel_list = LBRY()->daemon->channel_list();
if ( $channel_list ) { ?> if ( $channel_list ) { ?>
<ul class="lbry-channel-list"> <table class="lbry-channel-table">
<?php foreach ( $channel_list as $channel ) { ?> <thead>
<li><?php esc_html_e( $channel->name ) ?></li> <tr>
<?php } ?> <th>Channel</th>
</ul> <th>LBRY URL</th>
<?php } else { ?> <th>Posts</th>
<p>Looks like you haven't added any channels yet, feel free to do so below:</p> <th colspan="2">Supports</th>
<?php } </tr>
</thead>
<tbody>
<?php foreach ( $channel_list as $channel ):
$claim_id = $channel->claim_id;
$results = LBRY()->daemon->claim_search( $claim_id );
$lbry_url = $results->items[0]->canonical_url;
if ( $lbry_url ) {
$open_url = str_replace( 'lbry://', 'open.lbry.com/', $lbry_url );
}
$support_amount = $results->items[0]->meta->support_amount;
$claims_published = $results->items[0]->meta->claims_in_channel;
if ( ( $support_amount < 0.001 ) ) {
( $support_amount = '0' );
} elseif ( ( $support_amount < 0.01 ) && ( $support_amount >= 0.001 ) ) {
( $support_amount = '<0.01' );
} elseif ( ( $support_amount <= 0.099 ) && ( $support_amount >= 0.01) ) {
( $support_amount = number_format( floatval( $support_amount ), 2, '.', '' ) );
} elseif ( ( $support_amount <= 0.999 ) && ( $support_amount >= 0.1 ) ) {
( $support_amount = number_format( floatval( $support_amount ), 1, '.', '' ) );
} else {
( $support_amount = number_format( intval( $support_amount ) ) );
}
$init_bid = $results->items[0]->amount; ?>
<tr>
<td><a href="<?php echo esc_url( $open_url, 'lbrypress' ); ?>"><?php esc_html_e( $channel->name, 'lbrypress' ); ?></a></td>
<td><?php esc_html_e( $lbry_url, 'lbrypress' ); ?></td>
<td><?php esc_html_e( $claims_published, 'lbrypress' ); ?></td>
<td><span title="Initial Bid Amount: <?php esc_html_e( $init_bid, 'lbrypress' ); ?>"><img src="<?php echo esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png' ) ?>" class="icon icon-lbc bid-icon-lbc channel-bid-icon-lbc"><?php esc_html_e( $support_amount, 'lbrypress' ); ?></span></td>
<td><a href="#">Add</a></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr><th colspan="5">LBRYPress</th></tr>
</tfoot>
</table>
<?php } else { ?>
<p>Looks like you haven't added any channels yet, feel free to do so below:</p>
<?php }
} }
/** /**
* Section info for the Speech Channel Section * Section info for the Speech Channel Section
*/ */
@ -467,6 +505,43 @@ class LBRY_Admin
exit(); exit();
} }
/**
* Handles adding supports form submission
*/
public function supports_add()
{
$redirect_url = admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channels' ), 'options.php' ) );
// Check that nonce
if ( isset( $_POST['_lbrynonce'] ) && wp_verify_nonce( $_POST['_lbrynonce'], 'add_supports_nonce' ) ) {
if ( empty( $_POST['lbry_supports_add_claim_id'] ) || empty( $_POST['lbry_supports_add_amount'] ) ) {
LBRY()->notice->set_notice( 'error', 'Must supply both channel name and bid amount' );
} elseif ( isset( $_POST['lbry_supports_add_claim_id'] ) && isset( $_POST['lbry_supports_add_amount'] ) ) {
$claim_id = $_POST['lbry_supports_add_claim_id']; // TODO: sanitize key() only allows for lowercase chars, dashes, and underscores. maybe remove to allow more characters? and use something else for better control?
$bid = $_POST['lbry_supports_add_amount'];
$support_bid = number_format( floatval( $bid ), 3, '.', '' );
// Try to add the new channel
try {
// $result = LBRY()->daemon->channel_new( $claim_id, $supports_bid );
// Tell the user it takes some time to go through
LBRY()->notice->set_notice(
'success', 'Successfully added supports for: @' . esc_html( $claim_name ) . '! Please allow a few minutes for the bid to process.', true );
} catch ( \Exception $e ) {
LBRY()->notice->set_notice( 'error', $e->getMessage(), false );
}
}
} else {
LBRY()->notice->set_notice('error', 'Security check failed' );
die( __( 'Security check failed', 'lbrypress' ) );
}
wp_safe_redirect( $redirect_url );
exit();
}
/** /**
* Checks at most once an hour to see if the wallet balance is too low * Checks at most once an hour to see if the wallet balance is too low
*/ */
@ -474,19 +549,21 @@ class LBRY_Admin
public static function wallet_balance_warning() public static function wallet_balance_warning()
{ {
// See if we've checked in the past two hours // See if we've checked in the past two hours
if (!get_transient('lbry_wallet_check')) { if ( ! get_transient( 'lbry_wallet_check' ) ) {
$balance = LBRY()->daemon->wallet_balance(); $result = LBRY()->daemon->wallet_balance();
if ($balance < get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH] * 20) { $balance = $result->result->available;
$site_url = get_site_url();
if ( $balance < get_option( LBRY_SETTINGS )[LBRY_LBC_PUBLISH] * 20 ) {
// If LBRY Balance is low, send email, but only once per day // If LBRY Balance is low, send email, but only once per day
if (!get_transient('lbry_wallet_warning_email')) { if ( ! get_transient( 'lbry_wallet_warning_email' ) ) {
$email = get_option('admin_email'); $email = get_option( 'admin_email' );
$subject = 'Your LBRYPress Wallet Balance is Low!'; $subject = 'Your LBRYPress Wallet Balance is Low!';
$message = "Your LBRY Wallet for your WordPress installation at " . site_url() . " is running very low.\r\n\r\nYou currently have " . $balance . ' LBC left in your wallet. In order to keep publishing to the LBRY network, please add some LBC to your account.'; $message = 'Your LBRY Wallet for your WordPress installation at ' . esc_html_e( $site_url ) . ' is running very low.\r\n\r\nYou currently have ' . esc_html_e( $balance ) . ' LBC left in your wallet. In order to keep publishing to the LBRY network, please add some LBC to your account.';
wp_mail($email, $subject, $message); wp_mail( $email, $subject, $message );
set_transient('lbry_wallet_warning_email', true, DAY_IN_SECONDS); set_transient( 'lbry_wallet_warning_email', true, DAY_IN_SECONDS );
} }
} }
set_transient('lbry_wallet_check', true, 2 * HOUR_IN_SECONDS); set_transient( 'lbry_wallet_check', true, 2 * HOUR_IN_SECONDS );
} }
} }

View file

@ -90,26 +90,38 @@ class LBRY_Network
} }
$channel = $_POST[LBRY_POST_PUB_CHANNEL]; $channel = $_POST[LBRY_POST_PUB_CHANNEL];
$cur_channel = ( get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) ? get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) : get_post_meta( $post_id, '_lbry_channel', true ) ); $cur_channel = ( get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) ? get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) : get_post_meta( $post_id, '_lbry_channel', true ) );
$license = $_POST[LBRY_POST_PUB_LICENSE]; $license = $_POST[LBRY_POST_PUB_LICENSE];
$cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true ); $cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true );
$will_publish = $_POST[LBRY_WILL_PUBLISH]; $will_publish = $_POST[LBRY_WILL_PUBLISH];
// Update meta acordingly // Update meta acordingly
if ( $channel !== $cur_channel ) { if ( ( $channel ) && ( $channel !== $cur_channel ) && ( $channel != null || $channel != '' ) ) {
update_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, $channel ); update_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, $channel );
delete_post_meta( $post_id, '_lbry_channel'); // remove the _lbry_channel if already set from the post and replaces with _lbry_post_pub_channel to avoid confusion delete_post_meta( $post_id, '_lbry_channel'); // remove the _lbry_channel if already set from the post and replaces with _lbry_post_pub_channel to avoid confusion
} elseif ( $channel === $cur_channel && ( $cur_channel === get_post_meta( $post_id, '_lbry_channel', true ) ) ) { } elseif ( $channel === $cur_channel && ( $cur_channel === get_post_meta( $post_id, '_lbry_channel', true ) ) ) {
update_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, $channel ); update_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, $channel );
delete_post_meta( $post_id, '_lbry_channel'); // remove the _lbry_channel if already set from the post and replaces with _lbry_post_pub_channel to avoid confusion delete_post_meta( $post_id, '_lbry_channel' ); // remove the _lbry_channel if already set from the post and replaces with _lbry_post_pub_channel to avoid confusion
} }
if ( $license !== $cur_license ) { if ( ( $license ) && ( $license !== $cur_license ) && ( $license != null || $license != '' ) ) {
update_post_meta( $post_id, LBRY_POST_PUB_LICENSE, $license );
} elseif ( $license === $cur_license && ( $cur_license === get_post_meta( $post_id, 'lbry_license', true ) ) ) {
update_post_meta( $post_id, LBRY_POST_PUB_LICENSE, $license ); update_post_meta( $post_id, LBRY_POST_PUB_LICENSE, $license );
} }
if ( ( $will_publish ) && ( $will_publish == 1 ) && $post->post_status == 'publish') { $published = get_post_meta( $post_id, '_lbry_is_published', true );
$will_pub = get_post_meta( $post_id, '_lbry_will_publish', true );
if ( ( $will_pub == 0 ) && ( ! ( $published ) || ( $published ) == 0 ) ) {
// If not publishing to LBRY we want to not save unused values in database
delete_post_meta( $post_id, '_lbry_post_pub_channel' );
delete_post_meta( $post_id, '_lbry_post_pub_license' );
delete_post_meta( $post_id, '_lbry_canonical_url' );
}
$pub_channel = ( $channel ) ? $channel : $cur_channel;
$pub_license = ( $license ) ? $license : $cur_license;
if ( ( $will_publish ) && ( $will_publish == true ) && ( $post->post_status == 'publish' ) && ( $pub_channel ) && ( $pub_license ) && ( $pub_license != null ) ) {
// Publish the post on the LBRY Network // Publish the post on the LBRY Network
$this->publisher->publish( $post, $channel, $license ); $this->publisher->publish( $post, $pub_channel, $pub_license );
} }
} }
@ -127,32 +139,34 @@ class LBRY_Network
$lbry_claim_id = get_post_meta( $post_id, '_lbry_claim_id', true ); $lbry_claim_id = get_post_meta( $post_id, '_lbry_claim_id', true );
if ( $_GET['action'] === 'edit' ) { if ( $_GET['action'] === 'edit' ) {
if ( get_post_meta( $post_id, '_lbry_canonical_url', true ) == null || empty( get_post_meta( $post_id, '_lbry_canonical_url', true ) ) ) { if ( get_post_meta( $post_id, '_lbry_canonical_url', true ) == null || empty( get_post_meta( $post_id, '_lbry_canonical_url', true ) ) ) {
$canonical_url = LBRY()->daemon->canonical_url( $lbry_claim_id ); $canonical_url = LBRY()->daemon->canonical_url( $lbry_claim_id );
update_post_meta( $post_id, '_lbry_canonical_url', $canonical_url ); if ( $canonical_url != null ) {
update_post_meta( $post_id, '_lbry_canonical_url', $canonical_url );
} elseif ( $canonical_url == null ) {
delete_post_meta( $post_id, '_lbry_canonical_url' );
}
} }
} }
if ( ( get_post_meta( $post_id, '_lbry_will_publish', true ) == true ) && (isset( $lbry_claim_id ) ) ) {
update_post_meta( $post_id, '_lbry_is_published', true );
}
$lbry_published = get_post_meta( $post_id, '_lbry_is_published', true );
$lbry_url = ( get_post_meta( $post_id, '_lbry_canonical_url', true ) );
$lbry_url = ( get_post_meta( $post_id, '_lbry_canonical_url', true ) );
if ($lbry_url) { if ($lbry_url) {
$open_url = str_replace('lbry://', 'open.lbry.com/', $lbry_url ); $open_url = str_replace('lbry://', 'open.lbry.com/', $lbry_url );
} }
$default_value = get_option( LBRY_SETTINGS )['lbry_default_publish_setting']; $lbry_published = get_post_meta( $post_id, '_lbry_is_published', true );
$new_value = get_post_meta( $post_id, LBRY_WILL_PUBLISH, true ); $will_publish = get_post_meta( $post_id, '_lbry_will_publish', true );
if ( ( $new_value ) ? $new_value : $new_value = $default_value ); $lbry_post_pub_channel = get_post_meta( $post_id, '_lbry_post_pub_channel', true );
$value = $new_value; if ( ( $will_publish ) ? $will_publish : $will_publish = get_option( LBRY_SETTINGS )['lbry_default_publish_setting'] );
if ( ( $value ) ? $value : 0 ); if ( ( $_GET['action'] === 'edit' ) ? $value = $lbry_published : $value = $will_publish );
$checked = checked( $value, true, false );
// nonce set on page meta-box.php // nonce set on page meta-box.php
if ( ( $lbry_published ) && ( ( $lbry_url) || ( $lbry_claim_id ) ) ) { if ( ( ( $will_publish == true ) && ( $lbry_post_pub_channel ) ) || ( ( ( $lbry_published ) || ( $lbry_claim_id ) ) && ( ( $lbry_url != null ) || ( $lbry_claim_id ) ) ) ) {
printf( printf(
'<hr class="lbry-hr-meta"> '<hr class="lbry-hr-meta">
<div class="misc-pub-section lbry-meta-published-lbry-wrapper"> <div class="misc-pub-section lbry-meta-published-lbry-wrapper">
<span class="lbry-pub-metabox"><img src="' . __( '%1$s', 'lbrypress' ) . '" class="icon icon-lbry meta-icon-lbry"></span> <span class="post-lbry-display-before">Published on:</span> <span class="post-lbry-display"><strong> LBRY</strong></span> <span class="lbry-pub-metabox"><img src="' . __( '%1$s', 'lbrypress' ) . '" class="icon icon-lbry meta-icon-lbry"></span> <span class="post-lbry-display-before">Published on:</span> <span class="post-lbry-display"><strong>LBRY</strong></span>
</div> </div>
<div class="misc-pub-section lbry-url-meta-wrapper"> <div class="misc-pub-section lbry-url-meta-wrapper">
<span class="lbry-meta-label"><strong> LBRY URL: </strong></span><a href="' . esc_url( '%2$s', 'lbrypress' ) . '" target="_blank">' . esc_html__( '%3$s', 'lbrypress' ) . '</a> <span class="lbry-meta-label"><strong> LBRY URL: </strong></span><a href="' . esc_url( '%2$s', 'lbrypress' ) . '" target="_blank">' . esc_html__( '%3$s', 'lbrypress' ) . '</a>
@ -161,22 +175,22 @@ class LBRY_Network
<span class="lbry-meta-label"><strong> LBRY claim ID: </strong></span><span class="lbry-pub-metabox"><p class="lbry-claim-id-metabox">' . esc_html__( '%4$s', 'lbrypress' ) . '</p></span> <span class="lbry-meta-label"><strong> LBRY claim ID: </strong></span><span class="lbry-pub-metabox"><p class="lbry-claim-id-metabox">' . esc_html__( '%4$s', 'lbrypress' ) . '</p></span>
</div> </div>
<div class="misc-pub-section lbry-meta-checkbox-wrapper lbry-meta-wrapper-last"> <div class="misc-pub-section lbry-meta-checkbox-wrapper lbry-meta-wrapper-last">
<span class="lbry-meta-label"> Update Post on: <span><strong>' . esc_html__('LBRY', 'lbrypress') . '</strong></span> <input type="checkbox" class="lbry-meta-checkbox" value="1"' . esc_attr('%5$s') . ' name="' . esc_attr('%6$s') . '"> <span class="lbry-meta-label"> Update Post on: <span class="post-lbry-display"><strong>LBRY</strong></span> <input type="checkbox" class="lbry-meta-checkbox" value="1" ' . esc_attr('%5$s') . ' name="' . esc_attr('%6$s') . '">
</div>', </div>',
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png', plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png',
$open_url, $open_url,
$lbry_url, $lbry_url,
$lbry_claim_id, $lbry_claim_id,
checked( $value, true, false ), $checked,
LBRY_WILL_PUBLISH LBRY_WILL_PUBLISH
); );
} else { } else {
printf ( printf (
'<div class="misc-pub-section lbry-meta-checkbox-wrapper lbry-meta-wrapper-last"> '<div class="misc-pub-section lbry-meta-checkbox-wrapper lbry-meta-wrapper-last">
<span class="lbry-pub-metabox"><img src="' . __( '%1$s', 'lbrypress' ) . '" class="icon icon-lbry meta-icon-lbry"></span><span class="lbry-meta-label"> Publish to: <strong>' . esc_html__('LBRY', 'lbrypress') . '</strong></span><input type="checkbox" class="lbry-meta-checkbox" value="1"' . esc_attr('%2$s') . ' name="' . esc_attr('%3$s') . '"> <span class="lbry-pub-metabox"><img src="' . __( '%1$s', 'lbrypress' ) . '" class="icon icon-lbry meta-icon-lbry"></span><span class="lbry-meta-label">Publish to: <span class="post-lbry-display"> <strong>LBRY</strong></span> <input type="checkbox" class="lbry-meta-checkbox" value="1" ' . esc_attr('%2$s') . ' name="' . esc_attr('%3$s') . '">
</div>', </div>',
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png', plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png',
checked( $value, true, false ), $checked,
LBRY_WILL_PUBLISH LBRY_WILL_PUBLISH
); );
} }

View file

@ -18,60 +18,89 @@ $lbrynonce = wp_create_nonce( 'lbry_publish_post_nonce' );
$lbry_published = get_post_meta( $post_id, '_lbry_is_published', true ); $lbry_published = get_post_meta( $post_id, '_lbry_is_published', true );
$lbry_claim_id = get_post_meta( $post_id, '_lbry_claim_id', true ); $lbry_claim_id = get_post_meta( $post_id, '_lbry_claim_id', true );
// $lbry_url = get_post_meta( $post_id, '_lbry_canonical_url', true );
$lbry_published_channel = get_post_meta( $post_id, '_lbry_post_published_channel', true ); $lbry_published_channel = get_post_meta( $post_id, '_lbry_post_published_channel', true );
if ( ! ( $lbry_published_channel ) ) { if ( ( $lbry_published == true ) && ( $lbry_claim_id ) && ( ! ( $lbry_published_channel ) ) ) {
LBRY()->daemon->claim_search( $lbry_claim_id ); $result = LBRY()->daemon->claim_search( $lbry_claim_id );
$name = $result->items[0]->signing_channel->name;
update_post_meta( $post_id, '_lbry_post_published_channel', $name );
} }
$lbry_channel_claim_id = get_post_meta( $post_id, '_lbry_post_pub_channel', true ); $lbry_channel_claim_id = get_post_meta( $post_id, '_lbry_post_pub_channel', true );
//if ( $lbry_channel_claim_id === null ? 'Anonymously' : $lbry_channel_claim_id);
$lbry_published_license = get_post_meta( $post_id, '_lbry_post_pub_license', true ); $lbry_published_license = get_post_meta( $post_id, '_lbry_post_pub_license', true );
if ( ( $lbry_published == true ) && ( ( $lbry_claim_id ) ) && ( ! ( $lbry_published_license ) ) ) {
$result = LBRY()->daemon->claim_search( $lbry_claim_id );
$license = $result->items[0]->value->license;
update_post_meta( $post_id, '_lbry_post_pub_license', $license );
}
$channels = LBRY()->daemon->channel_list();
$channels[] = $unnatributed;
$cur_channel = ( get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) ? get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) : get_post_meta( $post_id, '_lbry_channel', true ) ); $cur_channel = ( get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) ? get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) : get_post_meta( $post_id, '_lbry_channel', true ) );
$default_channel = get_option( LBRY_SETTINGS )['default_lbry_channel']; $default_channel = get_option( LBRY_SETTINGS )['default_lbry_channel'];
$chan_open_url = ( 'open.lbry.com/'. $lbry_published_channel .'#' . $lbry_channel_claim_id . ''); $chan_open_url = ( 'open.lbry.com/'. $lbry_published_channel .'#' . $lbry_channel_claim_id . '');
// Sort the channels in a natural way
usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) );
?> ?>
<input type="hidden" id="_lbrynonce" name="_lbrynonce" value="<?php echo $lbrynonce ?>"><?php <input type="hidden" id="_lbrynonce" name="_lbrynonce" value="<?php echo $lbrynonce ?>"><?php
if ( ( ( $lbry_published == true ) || ( $lbry_published_channel ) ) && ( $lbry_published_license != null) ) { if ( ( ( $will_publish == true ) && ( $lbry_channel_claim_id ) ) || ( ( ( $lbry_published == true ) || ( $lbry_claim_id ) || ( $lbry_published_channel ) ) && ( $lbry_published_license != null ) ) ) {
$results = LBRY()->daemon->claim_search( $lbry_claim_id );
$init_bid = $results->items[0]->amount;
$support_amount = $results->items[0]->meta->support_amount;
if ( ( $support_amount < 0.001 ) ) {
( $support_amount = '0' );
} elseif ( ( $support_amount < 0.01 ) && ( $support_amount >= 0.001 ) ) {
( $support_amount = '<0.01' );
} elseif ( ( $support_amount <= 0.099 ) && ( $support_amount >= 0.01) ) {
( $support_amount = number_format( floatval( $support_amount ), 2, '.', '' ) );
} elseif ( ( $support_amount <= 0.999 ) && ( $support_amount >= 0.1 ) ) {
( $support_amount = number_format( floatval( $support_amount ), 1, '.', '' ) );
} else {
( $support_amount = number_format( intval( $support_amount ) ) );
}
printf( printf(
'<div class="lbry-meta-label lbry-meta-bx-channel"><strong>' . __( 'LBRY channel published at:', 'lbrypress' ) . '</strong> <div class="lbry-meta-bx-content lbry-meta-bx-channel"><a href="' . esc_url( '%2$s', 'lbrypress' ) . '">' . esc_html__( '%1$s', 'lbrypress' ) . '</a></div><div class="lbry-meta-label lbry-meta-bx-license"><strong>' . __( 'License published under:', 'lbrypress' ) .'</strong> </div><div class="lbry-meta-bx-content lbry-meta-bx-license lbry-meta-bx-content-last">' . esc_html__( '%3$s', 'lbrypress' ) . '</div></div>', '<div class="lbry-meta-label lbry-meta-bx-channel"><strong>' . __( 'Initial bid amount:', 'lbrypress' ) . ' </strong>
<span class="lbry-meta-bx-content lbry-meta-bx-channel"><img src="' . esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) ) . 'admin/images/lbc.png" class="icon icon-lbc bid-icon-lbc bid-icon-lbc"> ' . esc_html__( '%1$s', 'lbrypress' ) . '</span></div>
<div class="lbry-meta-label lbry-meta-bx-channel"><strong>' . __( 'Supports:', 'lbrypress' ) . ' </strong>
<span class="lbry-meta-bx-content lbry-meta-bx-channel"><img src="' . esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) ) . 'admin/images/lbc.png" class="icon icon-lbc bid-icon-lbc bid-icon-lbc"> ' . esc_html__( '%2$s', 'lbrypress' ) . '</span><a href="#">' . __( 'Add', 'lbrypress' ) . '</a></div>
<div class="lbry-meta-label lbry-meta-bx-channel"><strong>' . __( 'LBRY channel published to:', 'lbrypress' ) . '</strong></div>
<div class="lbry-meta-bx-content lbry-meta-bx-channel"><a href="' . esc_url( '%4$s', 'lbrypress' ) . '">' . esc_html__( '%3$s', 'lbrypress' ) . '</a></div>
<div class="lbry-meta-label lbry-meta-bx-license"><strong>' . __( 'License published under:', 'lbrypress' ) .'</strong> </div>
<div class="lbry-meta-bx-content lbry-meta-bx-license lbry-meta-bx-content-last">' . esc_html__( '%5$s', 'lbrypress' ) . '</div>',
$init_bid,
$support_amount,
$lbry_published_channel, $lbry_published_channel,
$chan_open_url, $chan_open_url,
$lbry_published_license, $lbry_published_license,
); );
} else { ?> } else {
<div><label for="LBRY_POST_PUB_CHANNEL" class="lbry-meta-bx-label lbry-meta-bx-channel"><?php $channels = LBRY()->daemon->channel_list();
$channels[] = $unnatributed;
// Sort the channels in a natural way
usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) ); ?>
<div><label for="LBRY_POST_PUB_CHANNEL" class="lbry-meta-bx-label lbry-meta-bx-channel"><?php
esc_html_e( 'Channel to Publish:', 'lbrypress' ); ?> </label></div><?php esc_html_e( 'Channel to Publish:', 'lbrypress' ); ?> </label></div><?php
$options = ''; $options = '';
if ( $channels ) { if ( $channels ) {
foreach ( $channels as $index=>$channel ) { foreach ( $channels as $index=>$channel ) {
$options .= '<option class="lbry-meta-bx-option lbry-meta-option-channel" value="' . esc_attr( $channel->claim_id ) . '"'; $options .= '<option class="lbry-meta-bx-option lbry-meta-option-channel" value="' . esc_attr( $channel->claim_id ) . '"';
if ( ( $cur_channel ) ? $cur_channel : $cur_channel = $default_channel ) { if ( ( $cur_channel ) ? $cur_channel : $cur_channel = $default_channel ) {
$options .= selected( $cur_channel, $channel->claim_id, false ); $options .= selected( $cur_channel, $channel->claim_id, false );
} }
$options .= '>' . esc_html__( $channel->name, 'lbrypress' ) . '</option>'; $options .= '>' . esc_html__( $channel->name, 'lbrypress' ) . '</option>';
} }
printf( printf(
'<select id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '">' . esc_html('%2$s') . '</select>', '<select id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '">' . esc_html('%2$s') . '</select>',
LBRY_POST_PUB_CHANNEL, LBRY_POST_PUB_CHANNEL,
$options $options
); );
} }
?> ?>
<div><label for="LBRY_POST_PUB_LICENSE" class="lbry-meta-bx-label lbry-meta-bx-license"><?php esc_html_e( 'Publish License:', 'lbrypress' ); ?> </label></div><?php <div><label for="LBRY_POST_PUB_LICENSE" class="lbry-meta-bx-label lbry-meta-bx-license"><?php esc_html_e( 'Publish License:', 'lbrypress' ); ?> </label></div><?php
$licenses = LBRY()->licenses; $licenses = LBRY()->licenses;
$options = ''; $options = '';
$default_license = get_option(LBRY_SETTINGS)[LBRY_LICENSE]; $default_license = get_option(LBRY_SETTINGS)[LBRY_LICENSE];
$cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true ); $cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true );
// Create options list, select current license // Create options list, select current license
if ( $licenses ) { if ( $licenses ) {

View file

@ -19,9 +19,19 @@ $lbry_active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general';
<a href="<?php echo esc_url( admin_url( 'options.php?page=lbrypress&tab=general' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'general' || '' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Settings' ); ?></a> <a href="<?php echo esc_url( admin_url( 'options.php?page=lbrypress&tab=general' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'general' || '' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Settings' ); ?></a>
<a href="<?php echo esc_url( admin_url( 'admin.php?page=lbrypress&tab=channels' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'channels' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Channels' ); ?></a> <a href="<?php echo esc_url( admin_url( 'admin.php?page=lbrypress&tab=channels' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'channels' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Channels' ); ?></a>
<a href="<?php echo esc_url( admin_url( 'options.php?page=lbrypress&tab=speech' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'speech' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Spee.ch' ); ?></a> <a href="<?php echo esc_url( admin_url( 'options.php?page=lbrypress&tab=speech' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'speech' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Spee.ch' ); ?></a>
<?php
if ( $lbry_active_tab == 'supports' ) {
$admin_url = admin_url( 'options.php?page=lbrypress&tab=supports' );
printf(
'<a href="' . esc_url( $admin_url ) . '" class="nav-tab nav-tab-active">' . esc_html__( 'Supports', 'lbrypress') . '</a>',
$admin_url,
);
} ?>
</nav> </nav>
<?php if ( $lbry_active_tab == 'channels' ) { <?php if ( $lbry_active_tab == 'channels' ) {
include_once( 'channels-page.php' ); include_once( 'channels-page.php' );
} elseif ( $lbry_active_tab == 'supports' ) {
include_once( 'supports-add-form.php' );
} else { } else {
?> ?>
<form class="form-table" action="<?php echo esc_url( admin_url( 'options.php' ) ); ?>" method="post"> <form class="form-table" action="<?php echo esc_url( admin_url( 'options.php' ) ); ?>" method="post">
@ -32,7 +42,9 @@ $lbry_active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general';
do_settings_sections( LBRY_ADMIN_PAGE ); do_settings_sections( LBRY_ADMIN_PAGE );
submit_button(); submit_button();
} elseif ( $lbry_active_tab == 'channels' ) { } elseif ( $lbry_active_tab == 'channels' ) {
include_once( 'channels-page.php' ); //include_once( 'channels-page.php' );
} elseif ( $lbry_active_tab == 'supports' ) {
// include_once( 'supports-add-form.php' );
} elseif ( $lbry_active_tab == 'speech' ) { } elseif ( $lbry_active_tab == 'speech' ) {
settings_fields( LBRY_SPEECH_SETTINGS ); settings_fields( LBRY_SPEECH_SETTINGS );
do_settings_sections( 'lbrypress-speech' ); do_settings_sections( 'lbrypress-speech' );

View file

@ -1,23 +1,23 @@
<?php <?php
defined('ABSPATH') || die(); // Exit if accessed directly defined('ABSPATH') || die(); // Exit if accessed directly
$url = get_post_meta(get_the_id(), LBRY_CANONICAL_URL, true); $lbry_url = get_post_meta( get_the_id(), LBRY_CANONICAL_URL, true );
if (!$url) { if ( ! $lbry_url ) {
// Get channel canonical for backwards compatibility // Get channel canonical for backwards compatibility
$channel_id = ( get_post_meta( get_the_id(), LBRY_POST_PUB_CHANNEL, true ) ? get_post_meta( get_the_id(), LBRY_POST_PUB_CHANNEL, true ) : get_post_meta( get_the_id(), '_lbry_channel', true ) ); $channel_id = ( get_post_meta( get_the_id(), LBRY_POST_PUB_CHANNEL, true ) ? get_post_meta( get_the_id(), LBRY_POST_PUB_CHANNEL, true ) : get_post_meta( get_the_id(), '_lbry_channel', true ) );
$url = LBRY()->daemon->canonical_url($channel_id); $lbry_url = LBRY()->daemon->canonical_url( $channel_id );
} }
if ($url) { if ( $lbry_url ) {
$url = str_replace('lbry://', 'open.lbry.com/', $url); $open_url = str_replace( 'lbry://', 'open.lbry.com/', $lbry_url );
} }
?> ?>
<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.com/get">LBRY</a> blockchain This post is published to the <a href="https://lbry.com/get">LBRY</a> blockchain
<?php if($url): ?> <?php if( $lbry_url ) : ?>
at <a href="https://<?= $url ?>"><?= $url ?></a>. at: <a href="<?php echo esc_url( $open_url ); ?>"><?php esc_html_e( $lbry_url, 'lbrypress' ); ?></a>.
<?php else: ?> <?php else: ?>
. .
<?php endif; ?> <?php endif; ?>

View file

@ -0,0 +1,26 @@
<?php
/**
* ============================
* ADD SUPPORTS FORM ADMIN PAGE
* Uses the post-admin action and the $_POST global variable to build our cURL request
* @package LBRYPress
* ============================
*/
defined('ABSPATH') || die(); // Exit if accessed directly
if ( current_user_can( 'manage_options' ) ) {
// Generate a custom nonce
$lbrynonce = wp_create_nonce( 'add_supports_nonce' );
// Build the page ?>
<h3><?php _e( 'Add Supports to a Claim', 'lbrypress' ); ?></h3>
<form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post" id="lbry_supports_add_form">
<input type="hidden" name="action" value="lbry_supports_add">
<input type="hidden" name="_lbrynonce" value="<?php echo $lbrynonce ?>">
</form>
<?php
}