From 3368ffdfd78ab2ff5ecc41f80baff00c385a3858 Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Sat, 12 Feb 2022 15:46:20 -0600 Subject: [PATCH 1/6] 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.2 From 1245d0d9fb17f83ed4dd1634a5046dd8843f17ba Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Sat, 12 Feb 2022 15:59:23 -0600 Subject: [PATCH 2/6] 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/6] 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.2 From cc6b82ac9fcc3527c1235cf101ffacf04e2a00b7 Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Sat, 12 Feb 2022 16:36:29 -0600 Subject: [PATCH 4/6] 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.2 From d8cc3ff96fdf28e0d154a81830321c9aa876cfa0 Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Sat, 12 Feb 2022 17:26:37 -0600 Subject: [PATCH 5/6] creates and prints the meta box --- classes/LBRYPress.php | 4 +-- classes/LBRY_Admin.php | 2 +- classes/LBRY_Network.php | 8 ++--- templates/meta-box.php | 69 ++++++++++++++++++++++++++++++++++++++++ templates/meta_box.php | 42 ------------------------ 5 files changed, 76 insertions(+), 49 deletions(-) create mode 100644 templates/meta-box.php delete mode 100644 templates/meta_box.php diff --git a/classes/LBRYPress.php b/classes/LBRYPress.php index 21706fd..89369d0 100644 --- a/classes/LBRYPress.php +++ b/classes/LBRYPress.php @@ -120,8 +120,8 @@ class LBRYPress $this->define('LBRY_LBC_PUBLISH', 'lbry_lbc_publish'); // amount of lbc to use per publish $this->define('LBRY_WILL_PUBLISH', '_lbry_will_publish'); // The meta key for if to publish to LBRY Network or not $this->define('LBRY_POST_CHANNEL', '_lbry_channel'); // The meta key for which channel to publish - $this->define('LBRY_POST_PUB_CHANNEL', '_lbry_post_pub_channel'); // The meta key for which channel to publish - $this->define('LBRY_POST_POST_LICENSE', '_lbry_post_pub_license'); // The meta key for which license to publish on + $this->define('LBRY_POST_PUB_CHANNEL', '_lbry_post_pub_channel'); // The meta key for which channel to publish on + $this->define('LBRY_POST_PUB_LICENSE', '_lbry_post_pub_license'); // The meta key for which license to publish on $this->define('LBRY_CLAIM_ID', '_lbry_claim_id'); // The Claim ID for the post as it was published on LBRY $this->define('LBRY_CANONICAL_URL', '_lbry_canonical_url'); // The canonical url for the published lbry post $this->define('LBRY_SPEECH_ASSET_URL', 'speech_asset_url'); // The meta key for an asset's speech url diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index 93550c3..1aa235f 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -37,7 +37,7 @@ class LBRY_Admin // Admin stylesheet enqueue function load_admin_stylesheet( $hook ) { - if ( ( $_GET['page'] == 'lbrypress' ) ) { + if ( ( $hook == 'post.php' ) || ( $hook == 'post-new.php' ) || ( $_GET['page'] == 'lbrypress' ) ) { wp_enqueue_style( 'lbry-admin', plugins_url( '/admin/css/lbry-admin.css', LBRY_PLUGIN_FILE ), diff --git a/classes/LBRY_Network.php b/classes/LBRY_Network.php index 4b4de01..5d88d04 100644 --- a/classes/LBRY_Network.php +++ b/classes/LBRY_Network.php @@ -34,7 +34,7 @@ class LBRY_Network private function post_meta_setup() { // Add the meta boxes - add_action('add_meta_boxes', array($this, 'add_meta_boxes')); + add_action( 'add_meta_boxes', array( $this, 'lbry_meta_boxes' ) ); // Save the post meta on 'save_post' hook add_action('wp_insert_post', array($this, 'save_post_meta'), 11, 2); @@ -43,12 +43,12 @@ class LBRY_Network /** * Adds the meta boxes to the post editing backend */ - public function add_meta_boxes() + public function lbry_meta_boxes( $post ) { // IDEA: Support post types based on user selection add_meta_box( 'lbry-network-publishing', // Unique ID - 'LBRY Network', // Title + __('LBRY Network', 'lbrypress'), // Title array($this, 'meta_box_html'), // Callback function 'post', // Screen Options (or post type) 'side', // Context @@ -107,6 +107,6 @@ class LBRY_Network */ public function meta_box_html( $post ) { - require_once(LBRY_ABSPATH . 'templates/meta_box.php'); + require_once( LBRY_ABSPATH . 'templates/meta-box.php' ); } } diff --git a/templates/meta-box.php b/templates/meta-box.php new file mode 100644 index 0000000..0bf75c8 --- /dev/null +++ b/templates/meta-box.php @@ -0,0 +1,69 @@ + 'none (anonymous)', + 'claim_id' => 'null' +); +// Generate a custom nonce +$lbrynonce = wp_create_nonce( 'lbry_publish_post_nonce' ); + +$channels = LBRY()->daemon->channel_list(); +$channels[] = $unnatributed; +$post_id = $post->ID; +$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']; + +// 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 ); + + // Create options list, select current license + if ( $licenses ) { + foreach ( $licenses as $value => $name ) { + $options .= '
diff --git a/templates/meta_box.php b/templates/meta_box.php deleted file mode 100644 index 336469f..0000000 --- a/templates/meta_box.php +++ /dev/null @@ -1,42 +0,0 @@ - 'none (anonymous)', - 'claim_id' => 'null' -); -$channels = LBRY()->daemon->channel_list(); -$channels[] = $unnatributed; -// Sort the channels in a natural way -usort($channels, array('LBRYPress', 'channel_name_comp')); -$cur_channel = get_post_meta($post->ID, LBRY_POST_CHANNEL, true); -$will_publish = get_post_meta($post->ID, LBRY_WILL_PUBLISH, true); -?> - -
- -
- -- 2.45.2 From 558cf08965eae9631b1f0a4a0d24c405aef213bd Mon Sep 17 00:00:00 2001 From: Lem Smyth Date: Sat, 12 Feb 2022 18:10:06 -0600 Subject: [PATCH 6/6] check if post meta is set --- templates/meta-box.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/meta-box.php b/templates/meta-box.php index 0bf75c8..68d51f1 100644 --- a/templates/meta-box.php +++ b/templates/meta-box.php @@ -33,7 +33,7 @@ usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) ); if ( $channels ) { foreach ( $channels as $index=>$channel ) { $options .= ''; @@ -54,7 +54,7 @@ usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) ); if ( $licenses ) { foreach ( $licenses as $value => $name ) { $options .= '