From 1762e002566f477b14fef823d237fb2c628fd684 Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Sun, 27 Feb 2022 11:35:02 -0600 Subject: [PATCH] edit channel method and daemon channel edit method --- classes/LBRY_Admin.php | 61 +++++++++++++++++++++++++++++++++++++++++ classes/LBRY_Daemon.php | 25 +++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index 651ee34..03e0854 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -525,6 +525,67 @@ class LBRY_Admin exit(); } + /** + * Handles editing an existing channel form submission + */ + public function edit_channel() + { + $redirect_url = admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channels' ), 'options.php' ) ); + + $claim = $_POST['claim_id']; + $claim_id = sanitize_text_field( $claim ); + $bid = $_POST['lbry_supports_add_bid_amount']; + $channel_bid = number_format( floatval( $bid ), 3, '.', '' ); + $title = $_POST['lbry_edit_channel_title']; + $channel_title = sanitize_text_field( $title ); + $description = $_POST['lbry_edit_channel_description']; + $channel_description = sanitize_text_field( $description ); + $tags = $_POST['lbry_edit_channel_tags']; + $channel_tags = sanitize_text_field( $tags ); + $website = $_POST['lbry_new_channel_website']; + $channel_website = sanitize_text_field( $website ); + $email = $_POST['lbry_new_channel_email']; + $channel_email = sanitize_text_field( $email ); + // $language_array = LBRY()->languages; + // $primlang = $_POST['lbry_new_channel_prim_lang']; + // $primary_language = ( ($primlang) && in_array( $primlang, $language_array ) ); + // $seclang = $_POST['lbry_new_channel_sec_lang']; + // $secondary_language = ( ($seclang) && in_array( $seclang, $language_array ) ); + // $thumbnail = $_POST['']; + // $thumbnail_url = wp_get_attachment_url( get_option( 'lbry_media_selector_thumbnail_id' ) ) + // $header = $_POST['']; + // $header_url = wp_get_attachment_url( get_option( 'lbry_media_selector_header_id' ) ); + + // Check that nonce + if ( isset( $_POST['_lbrynonce'] ) && wp_verify_nonce( $_POST['_lbrynonce'], 'edit_channel_nonce' ) ) { + $args = array( + 'claim_id' => $claim_id, + 'bid' => $channel_bid, + 'title' => $channel_title, + 'description' => $channel_description, + 'tags' => $channel_tags, + 'website_url' => $channel_website, + 'email' => $channel_email, + //'languages' => array( $primary_language, $secondary_language ), + //'thumbnail_url' => $thumbnail_url, + //'cover_url' => $header_url, + ); + // Try to add support to the claim + try { + $result = LBRY()->daemon->channel_edit( $args ); + + } 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/classes/LBRY_Daemon.php b/classes/LBRY_Daemon.php index b4c0fec..ffd1ae9 100644 --- a/classes/LBRY_Daemon.php +++ b/classes/LBRY_Daemon.php @@ -171,6 +171,31 @@ class LBRY_Daemon return; } } + + /** + * Edit an existing channel to add missing details + * https://lbry.tech/api/sdk#channel_update + * @return array dictionary containing result of the request + */ + + public function channel_edit( $args ) + { + try { + $result = $this->request( + 'channel_update', + $args + ); + + $this->logger->log( 'channel_update success!', 'Successfully updated channel with result: ' . print_r( $result->result, true ) ); + return $result->result; + + } catch (LBRYDaemonException $e) { + $this->logger->log( 'channel_update error', $e->getMessage() . ' | Code: ' . $e->getCode() ); + throw new \Exception( 'Issue updating channel.', 1 ); + return; + } + } + /** * Add supports to an existing claim * https://lbry.tech/api/sdk#