better sanitize supports page #78

Merged
lemsmyth merged 14 commits from master into master 2022-02-27 20:30:08 +01:00
2 changed files with 86 additions and 0 deletions
Showing only changes of commit eedf789ec5 - Show all commits

View file

@ -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
*/

View file

@ -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#