From 9472f3558792f009acb1b3474ecd2bed2f1c91f2 Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Wed, 16 Feb 2022 15:09:29 -0600 Subject: [PATCH 01/12] init show more info for channels --- admin/css/lbry-admin.css | 10 ++++++++-- classes/LBRY_Admin.php | 14 ++++++++++++-- classes/LBRY_Daemon.php | 24 ++++++++++++++++++++++++ classes/LBRY_Network.php | 2 +- classes/LBRY_Network_Publisher.php | 2 +- 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/admin/css/lbry-admin.css b/admin/css/lbry-admin.css index 5fea468..b397430 100644 --- a/admin/css/lbry-admin.css +++ b/admin/css/lbry-admin.css @@ -14,6 +14,12 @@ margin-bottom: -.2em; } +.channel-bid-icon-lbc { + height: 1.1em; + margin-right: .1em; + margin-bottom: -.2em; +} + .lbry-pub-metabox { margin: 0 0 0 -.2em; padding: 0 .2em 0 0 ; @@ -21,7 +27,7 @@ .meta-icon-lbry { height: 1.55em; margin-bottom: -.4em; - padding-left: .1em; + padding: 0 .1em 0 0; } .lbry-meta-checkbox-wrapper { padding: .5em .8em .6em; @@ -79,4 +85,4 @@ .lbry-meta-bx-content-last { padding: .2em .8em 1em .1em; -} \ No newline at end of file +} diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index e4a7fcb..64343ff 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -256,8 +256,18 @@ class LBRY_Admin if ( $channel_list ) { ?> diff --git a/classes/LBRY_Daemon.php b/classes/LBRY_Daemon.php index 08a1a23..92e6966 100644 --- a/classes/LBRY_Daemon.php +++ b/classes/LBRY_Daemon.php @@ -66,6 +66,30 @@ class LBRY_Daemon } } + /** + * Returns the info about a claim can get supports and initial bid amount when claim created among other information about a claim. + * TODO Can be build out later to accept more params + * @param string $claim_id + * @return object $result + */ + public function claim_search( $claim_id ) + { + $params = array( + 'claim_id' => $claim_id, + // 'name' => $norm_name, + // 'claim_type' => $claim_type, + ); + try { + $result = $this->request( 'claim_search', $params ); + $this->logger->log( 'Claim Search Results: ' . print_r( $result->result, true ) ); + return $result->result; + } catch ( LBRYDaemonException $e ) { + $this->logger->log( 'claim_search error', $e->getMessage() . ' | Code: ' . $e->getCode() ); + LBRY()->notice->set_notice( 'error', 'Issue getting claim search info' ); + return; + } + } + /** * Returns the available balance of a current LBRY account * https://lbry.tech/api/sdk#wallet_balance diff --git a/classes/LBRY_Network.php b/classes/LBRY_Network.php index b64481b..6d8bfa7 100644 --- a/classes/LBRY_Network.php +++ b/classes/LBRY_Network.php @@ -173,7 +173,7 @@ class LBRY_Network } else { printf ( '
- Publish to: ' . esc_html__('LBRY', 'lbrypress') . ' + Publish to: LBRY
', plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png', checked( $value, true, false ), diff --git a/classes/LBRY_Network_Publisher.php b/classes/LBRY_Network_Publisher.php index 1b64e6f..3f8ccda 100644 --- a/classes/LBRY_Network_Publisher.php +++ b/classes/LBRY_Network_Publisher.php @@ -92,7 +92,7 @@ class LBRY_Network_Publisher // Set License Published under $published_license = $output->value->license; - if ( isset( $published_license ) && ( $published_license !== null ) ) { + if ( ( $published_license ) && ( $published_license !== null ) ) { update_post_meta( $post->ID, '_lbry_post_published_license', $published_license ); } From 8d18e00a4926f60da66bbaa3fd1531b31d519d17 Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Thu, 17 Feb 2022 13:13:16 -0600 Subject: [PATCH 02/12] show bid amounts formating --- classes/LBRY_Admin.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index 64343ff..48fdf12 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -264,7 +264,17 @@ class LBRY_Admin $open_url = str_replace( 'lbry://', 'open.lbry.com/', $lbry_url ); } $support_amount = $results->items[0]->meta->support_amount; - if ( ( $support_amount < 1 ) ? $support_amount = '0' : $support_amount = number_format( intval( $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 ) ) ); + } $init_bid = $results->items[0]->amount; ?>
  • name, 'lbrypress' ) ?>
  • From 2df40bee5fd0371b1cef82d7a8bb752c0eaeebac Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Thu, 17 Feb 2022 13:33:54 -0600 Subject: [PATCH 03/12] initial publication bid amount --- templates/meta-box.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/templates/meta-box.php b/templates/meta-box.php index d50abb2..071ae61 100644 --- a/templates/meta-box.php +++ b/templates/meta-box.php @@ -39,9 +39,18 @@ usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) ); daemon->claim_search( $lbry_claim_id ); + $init_bid = $results->items[0]->amount; printf( - '
    ' . __( 'LBRY channel published at:', 'lbrypress' ) . '
    ' . __( 'License published under:', 'lbrypress' ) .'
    ' . esc_html__( '%3$s', 'lbrypress' ) . '
    ', + '
    ' . __( 'Initial bid amount:', 'lbrypress' ) . ' + ' . esc_html__( '%1$s', 'lbrypress' ) . '
    +
    ' . __( 'LBRY channel published at:', 'lbrypress' ) . '
    + +
    ' . __( 'License published under:', 'lbrypress' ) .'
    +
    ' . esc_html__( '%5$s', 'lbrypress' ) . '
    ', + $init_bid, $lbry_published_channel, $chan_open_url, $lbry_published_license, From 3626ce993cc2be6e03483b464602d73d9f1f7192 Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Thu, 17 Feb 2022 13:37:24 -0600 Subject: [PATCH 04/12] show supports on post page --- templates/meta-box.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/templates/meta-box.php b/templates/meta-box.php index 071ae61..5f0e586 100644 --- a/templates/meta-box.php +++ b/templates/meta-box.php @@ -43,14 +43,29 @@ usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) ); $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( '
    ' . __( 'Initial bid amount:', 'lbrypress' ) . ' ' . esc_html__( '%1$s', 'lbrypress' ) . '
    +
    ' . __( 'Supports:', 'lbrypress' ) . ' + ' . esc_html__( '%2$s', 'lbrypress' ) . '' . __( 'Add', 'lbrypress' ) . '
    ' . __( 'LBRY channel published at:', 'lbrypress' ) . '
    ' . __( 'License published under:', 'lbrypress' ) .'
    ' . esc_html__( '%5$s', 'lbrypress' ) . '
    ', $init_bid, + $support_amount, $lbry_published_channel, $chan_open_url, $lbry_published_license, From 099cdc6fdfbb0b5f784a783371821f0ae18f3e3e Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Thu, 17 Feb 2022 13:47:54 -0600 Subject: [PATCH 05/12] better logic when show selects, rv daemon call if not needed --- admin/css/lbry-admin.css | 2 +- classes/LBRY_Network.php | 64 ++++++++++++++++++++++-------------- templates/meta-box.php | 71 +++++++++++++++++++++------------------- 3 files changed, 78 insertions(+), 59 deletions(-) diff --git a/admin/css/lbry-admin.css b/admin/css/lbry-admin.css index b397430..c52f3c3 100644 --- a/admin/css/lbry-admin.css +++ b/admin/css/lbry-admin.css @@ -34,7 +34,7 @@ } .lbry-meta-wrapper-last { - padding: 0em .8em 1.2em; + padding: 0em .8em 1.5em; } .lbry-meta-label { diff --git a/classes/LBRY_Network.php b/classes/LBRY_Network.php index 6d8bfa7..816e9a0 100644 --- a/classes/LBRY_Network.php +++ b/classes/LBRY_Network.php @@ -90,26 +90,38 @@ class LBRY_Network } $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]; $cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true ); $will_publish = $_POST[LBRY_WILL_PUBLISH]; // 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 ); 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 ) ) ) { 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 ); } - 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 - $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 ); 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 ) ) ) { - $canonical_url = LBRY()->daemon->canonical_url( $lbry_claim_id ); - update_post_meta( $post_id, '_lbry_canonical_url', $canonical_url ); + $canonical_url = LBRY()->daemon->canonical_url( $lbry_claim_id ); + 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) { $open_url = str_replace('lbry://', 'open.lbry.com/', $lbry_url ); } - - $default_value = get_option( LBRY_SETTINGS )['lbry_default_publish_setting']; - $new_value = get_post_meta( $post_id, LBRY_WILL_PUBLISH, true ); - if ( ( $new_value ) ? $new_value : $new_value = $default_value ); - $value = $new_value; - if ( ( $value ) ? $value : 0 ); + + $lbry_published = get_post_meta( $post_id, '_lbry_is_published', true ); + $will_publish = get_post_meta( $post_id, '_lbry_will_publish', true ); + $lbry_post_pub_channel = get_post_meta( $post_id, '_lbry_post_pub_channel', true ); + if ( ( $will_publish ) ? $will_publish : $will_publish = get_option( LBRY_SETTINGS )['lbry_default_publish_setting'] ); + if ( ( $_GET['action'] === 'edit' ) ? $value = $lbry_published : $value = $will_publish ); + + $checked = checked( $value, true, false ); // 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( '
    - Published on: LBRY + Published on: LBRY
    LBRY URL: ' . esc_html__( '%3$s', 'lbrypress' ) . ' @@ -161,22 +175,22 @@ class LBRY_Network LBRY claim ID:

    ' . esc_html__( '%4$s', 'lbrypress' ) . '

    - Update Post on: ' . esc_html__('LBRY', 'lbrypress') . ' + Update Post on: LBRY
    ', plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png', $open_url, $lbry_url, $lbry_claim_id, - checked( $value, true, false ), + $checked, LBRY_WILL_PUBLISH ); } else { printf ( '
    - Publish to: LBRY + Publish to: LBRY
    ', plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png', - checked( $value, true, false ), + $checked, LBRY_WILL_PUBLISH ); } diff --git a/templates/meta-box.php b/templates/meta-box.php index 5f0e586..2d3e9f0 100644 --- a/templates/meta-box.php +++ b/templates/meta-box.php @@ -18,25 +18,25 @@ $lbrynonce = wp_create_nonce( 'lbry_publish_post_nonce' ); $lbry_published = get_post_meta( $post_id, '_lbry_is_published', 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 ); -if ( ! ( $lbry_published_channel ) ) { - LBRY()->daemon->claim_search( $lbry_claim_id ); +if ( ( $lbry_published == true ) && ( $lbry_claim_id ) && ( ! ( $lbry_published_channel ) ) ) { + $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 ); -//if ( $lbry_channel_claim_id === null ? 'Anonymously' : $lbry_channel_claim_id); $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 ) ); $default_channel = get_option( LBRY_SETTINGS )['default_lbry_channel']; $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' ) ); ?> - -
    $channel ) { - $options .= ''; - } - printf( - '', - LBRY_POST_PUB_CHANNEL, - $options - ); - } - ?> -
    licenses; - $options = ''; - $default_license = get_option(LBRY_SETTINGS)[LBRY_LICENSE]; - $cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true ); + $options = ''; + if ( $channels ) { + foreach ( $channels as $index=>$channel ) { + $options .= ''; + } + printf( + '', + LBRY_POST_PUB_CHANNEL, + $options + ); + } + ?> +
    licenses; + $options = ''; + $default_license = get_option(LBRY_SETTINGS)[LBRY_LICENSE]; + $cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true ); // Create options list, select current license if ( $licenses ) { From 12251aed05d0b7645a9e217fef661a731d754a86 Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Thu, 17 Feb 2022 17:27:06 -0600 Subject: [PATCH 06/12] use lbry: for display, http: for opening url --- templates/meta-box.php | 2 +- templates/published_on_lbry_banner.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/templates/meta-box.php b/templates/meta-box.php index 2d3e9f0..6e92560 100644 --- a/templates/meta-box.php +++ b/templates/meta-box.php @@ -60,7 +60,7 @@ $chan_open_url = ( 'open.lbry.com/'. $lbry_published_channel .'#' . $lbry_channe ' . esc_html__( '%1$s', 'lbrypress' ) . '
    ' . __( 'Supports:', 'lbrypress' ) . ' ' . esc_html__( '%2$s', 'lbrypress' ) . '' . __( 'Add', 'lbrypress' ) . '
    -
    ' . __( 'LBRY channel published at:', 'lbrypress' ) . '
    +
    ' . __( 'LBRY channel published to:', 'lbrypress' ) . '
    ' . __( 'License published under:', 'lbrypress' ) .'
    ' . esc_html__( '%5$s', 'lbrypress' ) . '
    ', diff --git a/templates/published_on_lbry_banner.php b/templates/published_on_lbry_banner.php index 8873b63..c32933e 100644 --- a/templates/published_on_lbry_banner.php +++ b/templates/published_on_lbry_banner.php @@ -1,23 +1,23 @@ daemon->canonical_url($channel_id); + $lbry_url = LBRY()->daemon->canonical_url( $channel_id ); } - if ($url) { - $url = str_replace('lbry://', 'open.lbry.com/', $url); + if ( $lbry_url ) { + $open_url = str_replace( 'lbry://', 'open.lbry.com/', $lbry_url ); } ?>
    Stored Safely on Blockchain

    - This post is published to LBRY blockchain - - at . + This post is published to the LBRY blockchain + + at: . . From a1c0ac76a398e79aaf92d5af0b96a8d0a5a3f4e4 Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Thu, 17 Feb 2022 19:18:09 -0600 Subject: [PATCH 07/12] wallet balance email --- classes/LBRY_Admin.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index 48fdf12..2ce5fd7 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -494,19 +494,19 @@ class LBRY_Admin public static function wallet_balance_warning() { // 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(); - if ($balance < get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH] * 20) { + if ( $balance < get_option( LBRY_SETTINGS )[LBRY_LBC_PUBLISH] * 20 ) { // If LBRY Balance is low, send email, but only once per day - if (!get_transient('lbry_wallet_warning_email')) { - $email = get_option('admin_email'); + if ( ! get_transient( 'lbry_wallet_warning_email' ) ) { + $email = get_option( 'admin_email' ); $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.'; - wp_mail($email, $subject, $message); - set_transient('lbry_wallet_warning_email', true, DAY_IN_SECONDS); + $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.'; + wp_mail( $email, $subject, $message ); + 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 ); } } From 28da08d8c65bc15de38d0538a0360e4b60fcc70e Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Thu, 17 Feb 2022 22:23:08 -0600 Subject: [PATCH 08/12] channel list to table --- admin/css/lbry-admin.css | 35 ++++++++++++++++++ classes/LBRY_Admin.php | 77 ++++++++++++++++++++++++---------------- 2 files changed, 82 insertions(+), 30 deletions(-) diff --git a/admin/css/lbry-admin.css b/admin/css/lbry-admin.css index c52f3c3..3591f74 100644 --- a/admin/css/lbry-admin.css +++ b/admin/css/lbry-admin.css @@ -86,3 +86,38 @@ .lbry-meta-bx-content-last { 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: 1em 2em; + border: 2px solid #fff; + background: #fbd7b4; + font-size: 1.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; */ +} \ No newline at end of file diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index 2ce5fd7..6a34e77 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -253,39 +253,56 @@ class LBRY_Admin public function available_channels_callback() { $channel_list = LBRY()->daemon->channel_list(); - if ( $channel_list ) { ?> -

      - 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; - 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; ?> -
    • name, 'lbrypress' ) ?>
    • - - -
    - -

    Looks like you haven't added any channels yet, feel free to do so below:

    - + + + Channel + LBRY URL + Posts + Supports + + + + 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; ?> + + name, 'lbrypress' ); ?> + + + + Add + + + + + LBRYPress + + + +

    Looks like you haven't added any channels yet, feel free to do so below:

    + Date: Fri, 18 Feb 2022 09:39:04 -0600 Subject: [PATCH 09/12] css --- admin/css/lbry-admin.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/css/lbry-admin.css b/admin/css/lbry-admin.css index 3591f74..7763519 100644 --- a/admin/css/lbry-admin.css +++ b/admin/css/lbry-admin.css @@ -94,10 +94,10 @@ table.lbry-channel-table { } .lbry-channel-table th, .lbry-channel-table td { - padding: 1em 2em; + padding: .4em 1.6em; border: 2px solid #fff; background: #fbd7b4; - font-size: 1.1em; + font-size: 1em; } .lbry-channel-table thead th { padding: .5em 2em; From 1464afec1e2d543ea7809b2b0734172e6efab183 Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Fri, 18 Feb 2022 09:40:43 -0600 Subject: [PATCH 10/12] get wallet balance --- classes/LBRY_Admin.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index 2ce5fd7..000c155 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -495,13 +495,15 @@ class LBRY_Admin { // See if we've checked in the past two hours if ( ! get_transient( 'lbry_wallet_check' ) ) { - $balance = LBRY()->daemon->wallet_balance(); + $result = LBRY()->daemon->wallet_balance(); + $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 ( ! get_transient( 'lbry_wallet_warning_email' ) ) { $email = get_option( 'admin_email' ); $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 ); set_transient( 'lbry_wallet_warning_email', true, DAY_IN_SECONDS ); } From 83874b53318da4ca35b45012f6a61b3d58aff45a Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Fri, 18 Feb 2022 18:01:45 -0600 Subject: [PATCH 11/12] basic outline for add supports --- classes/LBRY_Admin.php | 40 ++++++++++++++++++++++++++++++++- templates/options-page.php | 14 +++++++++++- templates/supports-add-form.php | 26 +++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 templates/supports-add-form.php diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index 2ce5fd7..65a3eef 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -19,6 +19,7 @@ class LBRY_Admin add_action('admin_init', array($this, 'page_init')); 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_supports_add', array($this, 'supports_add')); } /** @@ -33,7 +34,7 @@ class LBRY_Admin 'manage_options', LBRY_ADMIN_PAGE, 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 @@ -487,6 +488,43 @@ class LBRY_Admin 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 */ diff --git a/templates/options-page.php b/templates/options-page.php index a4648f1..29b4480 100644 --- a/templates/options-page.php +++ b/templates/options-page.php @@ -19,9 +19,19 @@ $lbry_active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general'; + ' . esc_html__( 'Supports', 'lbrypress') . '', + $admin_url, + ); + } ?>
    @@ -32,7 +42,9 @@ $lbry_active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general'; do_settings_sections( LBRY_ADMIN_PAGE ); submit_button(); } 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' ) { settings_fields( LBRY_SPEECH_SETTINGS ); do_settings_sections( 'lbrypress-speech' ); diff --git a/templates/supports-add-form.php b/templates/supports-add-form.php new file mode 100644 index 0000000..5a58a0d --- /dev/null +++ b/templates/supports-add-form.php @@ -0,0 +1,26 @@ + +

    + + + + + + +
    + Date: Sat, 19 Feb 2022 16:15:44 -0600 Subject: [PATCH 12/12] links to add supports --- classes/LBRY_Admin.php | 2 +- templates/meta-box.php | 2 +- templates/options-page.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index 3b521e2..88aabc0 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -291,7 +291,7 @@ class LBRY_Admin - Add + Add diff --git a/templates/meta-box.php b/templates/meta-box.php index 6e92560..23e39a8 100644 --- a/templates/meta-box.php +++ b/templates/meta-box.php @@ -59,7 +59,7 @@ $chan_open_url = ( 'open.lbry.com/'. $lbry_published_channel .'#' . $lbry_channe '
    ' . __( 'Initial bid amount:', 'lbrypress' ) . ' ' . esc_html__( '%1$s', 'lbrypress' ) . '
    ' . __( 'Supports:', 'lbrypress' ) . ' - ' . esc_html__( '%2$s', 'lbrypress' ) . '' . __( 'Add', 'lbrypress' ) . '
    + ' . esc_html__( '%2$s', 'lbrypress' ) . '' . __( 'Add', 'lbrypress' ) . '
    ' . __( 'LBRY channel published to:', 'lbrypress' ) . '
    ' . __( 'License published under:', 'lbrypress' ) .'
    diff --git a/templates/options-page.php b/templates/options-page.php index 29b4480..2224e06 100644 --- a/templates/options-page.php +++ b/templates/options-page.php @@ -21,7 +21,7 @@ $lbry_active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general'; ' . esc_html__( 'Supports', 'lbrypress') . '', $admin_url, @@ -44,7 +44,7 @@ $lbry_active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general'; } elseif ( $lbry_active_tab == 'channels' ) { //include_once( 'channels-page.php' ); } elseif ( $lbry_active_tab == 'supports' ) { - // include_once( 'supports-add-form.php' ); + //include_once( 'supports-add-form.php' ); } elseif ( $lbry_active_tab == 'speech' ) { settings_fields( LBRY_SPEECH_SETTINGS ); do_settings_sections( 'lbrypress-speech' );