diff --git a/admin/css/lbry-admin.css b/admin/css/lbry-admin.css index 5fea468..7763519 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,14 +27,14 @@ .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; } .lbry-meta-wrapper-last { - padding: 0em .8em 1.2em; + padding: 0em .8em 1.5em; } .lbry-meta-label { @@ -79,4 +85,39 @@ .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: .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; */ } \ No newline at end of file diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index e4a7fcb..3b521e2 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 @@ -253,19 +254,56 @@ class LBRY_Admin public function available_channels_callback() { $channel_list = LBRY()->daemon->channel_list(); - if ( $channel_list ) { ?> -
Looks like you haven't added any channels yet, feel free to do so below:
- + +Looks like you haven't added any channels yet, feel free to do so below:
+ '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 */ @@ -474,19 +549,21 @@ 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')) { - $balance = LBRY()->daemon->wallet_balance(); - if ($balance < get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH] * 20) { + if ( ! get_transient( 'lbry_wallet_check' ) ) { + $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'); + 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 ' . 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 ); } } - set_transient('lbry_wallet_check', true, 2 * HOUR_IN_SECONDS); + set_transient( 'lbry_wallet_check', true, 2 * HOUR_IN_SECONDS ); } } diff --git a/classes/LBRY_Network.php b/classes/LBRY_Network.php index b64481b..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( '