From 3368ffdfd78ab2ff5ecc41f80baff00c385a3858 Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Sat, 12 Feb 2022 15:46:20 -0600 Subject: [PATCH 1/4] default license select option --- classes/LBRY_Admin.php | 6 +++--- classes/LBRY_Network.php | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index 8578b91..2fb5031 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -25,6 +25,7 @@ class LBRY_Admin */ public function create_options_page() { + add_menu_page( __( 'LBRYPress Settings', 'lbrypress' ), __( 'LBRYPress', 'lbrypress' ), @@ -68,7 +69,7 @@ class LBRY_Admin { // Register the LBRY Setting array register_setting( - LBRY_SETTINGS_GROUP, + 'lbry_general_settings', LBRY_SETTINGS, array( $this, 'sanitize_general_settings' ) ); @@ -115,7 +116,6 @@ class LBRY_Admin /** - * Speech Admin Page settings */ @@ -275,7 +275,7 @@ class LBRY_Admin } printf( - '', + '', LBRY_LICENSE, LBRY_SETTINGS, $options diff --git a/classes/LBRY_Network.php b/classes/LBRY_Network.php index a32db37..cb83950 100644 --- a/classes/LBRY_Network.php +++ b/classes/LBRY_Network.php @@ -82,6 +82,8 @@ class LBRY_Network $will_publish = (isset($_POST[LBRY_WILL_PUBLISH]) ? $_POST[LBRY_WILL_PUBLISH] : false); $new_channel = (isset($_POST[LBRY_POST_CHANNEL]) ? $_POST[LBRY_POST_CHANNEL] : null); $cur_channel = get_post_meta($post_id, LBRY_POST_CHANNEL, true); + $license = $_POST[LBRY_POST_PUB_LICENSE]; + $cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true ); // Update meta acordingly if (!$will_publish) { -- 2.45.3 From 1245d0d9fb17f83ed4dd1634a5046dd8843f17ba Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Sat, 12 Feb 2022 15:59:23 -0600 Subject: [PATCH 2/4] default channel selector --- classes/LBRY_Admin.php | 40 +++++++++++++++++++++++++++++++++++++++- classes/LBRY_Network.php | 8 ++++---- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index 2fb5031..7cb8b03 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -25,7 +25,6 @@ class LBRY_Admin */ public function create_options_page() { - add_menu_page( __( 'LBRYPress Settings', 'lbrypress' ), __( 'LBRYPress', 'lbrypress' ), @@ -91,6 +90,13 @@ class LBRY_Admin LBRY_SETTINGS_SECTION_GENERAL ); + add_settings_field( + 'default_lbry_channel', + 'Default Publish Channel', + array( $this, 'default_channel_callback' ), + LBRY_ADMIN_PAGE, + LBRY_SETTINGS_SECTION_GENERAL + ); add_settings_field( LBRY_LICENSE, 'LBRY Publishing License', @@ -255,6 +261,37 @@ class LBRY_Admin ); } + /** + * Prints select to choose a default to publish to channel + */ + public function default_channel_callback() + { + $options = ''; + $channel_list = LBRY()->daemon->channel_list(); + + if ( $channel_list ) { + foreach ( $channel_list as $channel ) { + $selected = $this->options['default_lbry_channel'] === $channel->claim_id; + + $options .= ''; + } + + printf( + '', + 'default_lbry_channel', + LBRY_SETTINGS, + $options + ); + } else { ?> +

Looks like you haven't added any channels yet, you can do that now on the Channels Tab

+ Date: Sat, 12 Feb 2022 16:05:04 -0600 Subject: [PATCH 3/4] checkbox to set default publish --- classes/LBRY_Admin.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index 7cb8b03..219d615 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -90,6 +90,14 @@ class LBRY_Admin LBRY_SETTINGS_SECTION_GENERAL ); + add_settings_field( + 'lbry_default_publish_setting', + 'Always Publish to LBRY', + array( $this, 'lbry_always_pub_callback' ), + LBRY_ADMIN_PAGE, + LBRY_SETTINGS_SECTION_GENERAL + ); + add_settings_field( 'default_lbry_channel', 'Default Publish Channel', @@ -97,6 +105,7 @@ class LBRY_Admin LBRY_ADMIN_PAGE, LBRY_SETTINGS_SECTION_GENERAL ); + add_settings_field( LBRY_LICENSE, 'LBRY Publishing License', @@ -261,6 +270,24 @@ class LBRY_Admin ); } + /** + * Checkbox to default to always allow publish on LBRY + */ + public function lbry_always_pub_callback() + { + $options = get_option( LBRY_SETTINGS )['lbry_default_publish_setting']; + if ( ! isset( $options ) ) { + $options = 0; + } + $checked = checked( $options, 1, false ); + printf( + '

Set Default to always Publish to LBRY, this can be adjusted when publishing a New Post.

', + 'lbry_default_publish_setting', + LBRY_SETTINGS, + + ); + } + /** * Prints select to choose a default to publish to channel */ -- 2.45.3 From cc6b82ac9fcc3527c1235cf101ffacf04e2a00b7 Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Sat, 12 Feb 2022 16:36:29 -0600 Subject: [PATCH 4/4] sanitize option callbacks --- classes/LBRY_Admin.php | 48 +++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index 219d615..93550c3 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -179,22 +179,24 @@ class LBRY_Admin public function sanitize_general_settings( $input ) { - if (!empty($input[LBRY_SPEECH_CHANNEL])) { - $channel = $input[LBRY_SPEECH_CHANNEL]; - $channel = str_replace('@', '', $channel); - $input[LBRY_SPEECH_CHANNEL] = $channel; - } + $new_input = get_option( LBRY_SETTINGS ); // get saved data - if (!empty($input[LBRY_SPEECH_PW])) { - $encrypted = $this->encrypt($input['lbry_speech_pw']); - $input[LBRY_SPEECH_PW] = $encrypted; - } else { - // If we have a password and its empty, keep orginal password - if (!empty(get_option(LBRY_SETTINGS)[LBRY_SPEECH_PW])) { - $input[LBRY_SPEECH_PW] = get_option(LBRY_SETTINGS)[LBRY_SPEECH_PW]; - } + if ( isset( $input[LBRY_WALLET] ) ) { + $new_input[LBRY_WALLET] = sanitize_text_field( $input[LBRY_WALLET] ); } - return $input; + $new_input['lbry_default_publish_setting'] = $input['lbry_default_publish_setting']; + + if ( isset( $input['default_lbry_channel'] ) ) { + $new_input['default_lbry_channel'] = sanitize_text_field( $input['default_lbry_channel'] ); + } + $license_array = LBRY()->licenses; + if ( isset( $input[LBRY_LICENSE] ) && ( in_array( $input[LBRY_LICENSE], $license_array ) ) ) { + $new_input[LBRY_LICENSE] = sanitize_text_field( $input[LBRY_LICENSE] ); + } + if ( isset( $input[LBRY_LBC_PUBLISH] ) ) { + $new_input[LBRY_LBC_PUBLISH] = number_format( floatval( $input[LBRY_LBC_PUBLISH] ), 3, '.', '' ); + } + return $new_input; } public function sanitize_speech_settings( $input ) @@ -228,13 +230,6 @@ class LBRY_Admin { print 'This is where you can configure how LBRYPress will distribute your content:'; } - /** - * Section info for the Speech Channel Section - */ - public function speech_section_callback() - { - print 'If you have a Spee.ch account, you can enter your account details here, if you don\'t already have a Spee.ch account, no need to enter anything here.'; - } /** * Section info for the Available Channel(s) Section @@ -254,6 +249,15 @@ class LBRY_Admin options[LBRY_LBC_PUBLISH] ); - } + } /** * Channels Page -- 2.45.3