Print the speech tab inputs
This commit is contained in:
parent
9b6e6bd7f1
commit
33fb30ccc9
3 changed files with 127 additions and 66 deletions
|
@ -183,7 +183,7 @@ class LBRYPress
|
|||
|
||||
// Default options
|
||||
$option_defaults = array(
|
||||
LBRY_SPEECH => null,
|
||||
|
||||
LBRY_LICENSE => $this->licenses[0],
|
||||
LBRY_LBC_PUBLISH => 1
|
||||
);
|
||||
|
@ -191,6 +191,16 @@ class LBRYPress
|
|||
add_option(LBRY_SETTINGS, $option_defaults, false);
|
||||
}
|
||||
|
||||
if ( ! get_option( LBRY_SPEECH_SETTINGS ) ) {
|
||||
// Default Speech Settings
|
||||
$option_defaults = array(
|
||||
LBRY_SPEECH =>'',
|
||||
LBRY_SPEECH_CHANNEL => '',
|
||||
LBRY_SPEECH_PW => '',
|
||||
);
|
||||
add_option( LBRY_SPEECH_SETTINGS, $option_defaults, false );
|
||||
}
|
||||
|
||||
// COMBAK: decide if we need to check for missing or corrupt settings. May be unecessary.
|
||||
// Double check we have all settings, if not, update with default
|
||||
// $current_settings = get_option(LBRY_SETTINGS);
|
||||
|
|
|
@ -79,30 +79,6 @@ class LBRY_Admin
|
|||
LBRY_SETTINGS_SECTION_GENERAL
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_SPEECH,
|
||||
'Spee.ch URL',
|
||||
array( $this, 'speech_callback' ),
|
||||
LBRY_ADMIN_PAGE,
|
||||
LBRY_SETTINGS_SECTION_GENERAL
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_SPEECH_CHANNEL,
|
||||
'Spee.ch Channel',
|
||||
array( $this, 'speech_channel_callback' ),
|
||||
LBRY_ADMIN_PAGE,
|
||||
LBRY_SETTINGS_SECTION_GENERAL
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_SPEECH_PW,
|
||||
'Spee.ch Password',
|
||||
array( $this, 'speech_pw_callback' ),
|
||||
LBRY_ADMIN_PAGE,
|
||||
LBRY_SETTINGS_SECTION_GENERAL
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_LICENSE,
|
||||
'LBRY Publishing License',
|
||||
|
@ -118,6 +94,47 @@ class LBRY_Admin
|
|||
LBRY_ADMIN_PAGE,
|
||||
LBRY_SETTINGS_SECTION_GENERAL
|
||||
);
|
||||
|
||||
/**
|
||||
* Speech Admin Page settings
|
||||
*/
|
||||
|
||||
register_setting(
|
||||
LBRY_SPEECH_SETTINGS,
|
||||
LBRY_SPEECH_SETTINGS,
|
||||
array( $this, 'sanitize_speech_settings' )
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'lbry_settings_section_speech', // ID
|
||||
'Spee.ch Channel Settings', // Title
|
||||
array( $this, 'speech_section_callback' ), // Callback
|
||||
'lbrypress-speech' // Page
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_SPEECH,
|
||||
'Spee.ch URL',
|
||||
array( $this, 'speech_callback' ),
|
||||
'lbrypress-speech',
|
||||
'lbry_settings_section_speech'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_SPEECH_CHANNEL,
|
||||
'Spee.ch Channel',
|
||||
array( $this, 'speech_channel_callback' ),
|
||||
'lbrypress-speech',
|
||||
'lbry_settings_section_speech'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_SPEECH_PW,
|
||||
'Spee.ch Password',
|
||||
array( $this, 'speech_pw_callback' ),
|
||||
'lbrypress-speech',
|
||||
'lbry_settings_section_speech'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -153,10 +170,33 @@ class LBRY_Admin
|
|||
$input[LBRY_SPEECH_PW] = get_option(LBRY_SETTINGS)[LBRY_SPEECH_PW];
|
||||
}
|
||||
}
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function sanitize_speech_settings( $input )
|
||||
{
|
||||
$new_input = get_option( LBRY_SPEECH_SETTINGS );
|
||||
if ( isset( $input[LBRY_SPEECH] ) ) {
|
||||
$new_input[LBRY_SPEECH] = sanitize_text_field( $input[LBRY_SPEECH] );
|
||||
}
|
||||
if ( isset( $input[LBRY_SPEECH_CHANNEL] ) ) {
|
||||
$channel = $input[LBRY_SPEECH_CHANNEL];
|
||||
$channel = str_replace( '@', '', $channel );
|
||||
$new_input[LBRY_SPEECH_CHANNEL] = sanitize_user( $channel );
|
||||
}
|
||||
if ( isset( $input[LBRY_SPEECH_PW] ) ) {
|
||||
$input[LBRY_SPEECH_PW] = sanitize_text_field( $input[LBRY_SPEECH_PW] );
|
||||
$encrypted = $this->encrypt( $input[LBRY_SPEECH_PW] );
|
||||
$new_input[LBRY_SPEECH_PW] = $encrypted;
|
||||
} else {
|
||||
// If we have a password and it's empty, keep original password
|
||||
if ( empty( $input[LBRY_SPEECH_PW] ) )
|
||||
$new_input[LBRY_SPEECH_PW] = get_option( LBRY_SPEECH_SETTINGS[LBRY_SPEECH_PW] );
|
||||
}
|
||||
return $new_input;
|
||||
update_option( LBRY_SPEECH_SETTINGS, $new_input );
|
||||
}
|
||||
|
||||
/**
|
||||
* Section info for the General Section
|
||||
*/
|
||||
|
@ -164,6 +204,13 @@ 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.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints Wallet input
|
||||
|
@ -181,43 +228,6 @@ class LBRY_Admin
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints Spee.ch input
|
||||
*/
|
||||
public function speech_callback()
|
||||
{
|
||||
printf(
|
||||
'<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" placeholder="https://your-speech-address.com"/>',
|
||||
LBRY_SPEECH,
|
||||
LBRY_SETTINGS,
|
||||
isset($this->options[LBRY_SPEECH]) ? esc_attr($this->options[LBRY_SPEECH]) : ''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints Spee.ch channel input
|
||||
*/
|
||||
public function speech_channel_callback()
|
||||
{
|
||||
printf(
|
||||
'<span>@</span><input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" placeholder="your-channel"/>',
|
||||
LBRY_SPEECH_CHANNEL,
|
||||
LBRY_SETTINGS,
|
||||
isset($this->options[LBRY_SPEECH_CHANNEL]) ? esc_attr($this->options[LBRY_SPEECH_CHANNEL]) : ''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints Spee.ch password input
|
||||
*/
|
||||
public function speech_pw_callback()
|
||||
{
|
||||
printf(
|
||||
'<input type="password" id="%1$s" name="%2$s[%1$s]" value="" placeholder="Leave empty for same password"',
|
||||
LBRY_SPEECH_PW,
|
||||
LBRY_SETTINGS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints License input
|
||||
|
@ -259,6 +269,47 @@ class LBRY_Admin
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints Spee.ch input
|
||||
*/
|
||||
public function speech_callback()
|
||||
{
|
||||
$options = get_option( LBRY_SPEECH_SETTINGS );
|
||||
printf(
|
||||
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%2$s[%1$s]') . '" value="' . esc_attr('%3$s') . '" placeholder="https://your-speech-address.com">',
|
||||
LBRY_SPEECH,
|
||||
LBRY_SPEECH_SETTINGS,
|
||||
isset( $options[LBRY_SPEECH] ) ? $options[LBRY_SPEECH] : '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints Spee.ch channel input
|
||||
*/
|
||||
public function speech_channel_callback()
|
||||
{
|
||||
$options = get_option( LBRY_SPEECH_SETTINGS );
|
||||
printf(
|
||||
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%2$s[%1$s]') . '" value="@' . esc_attr('%3$s') . '" placeholder="your-speech-channel">',
|
||||
LBRY_SPEECH_CHANNEL,
|
||||
LBRY_SPEECH_SETTINGS,
|
||||
isset( $options[LBRY_SPEECH_CHANNEL] ) ? $options[LBRY_SPEECH_CHANNEL] : '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints Spee.ch password input
|
||||
*/
|
||||
public function speech_pw_callback()
|
||||
{
|
||||
printf(
|
||||
'<input type="password" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%2$s[%1$s]') . '" placeholder="Leave empty for same password">',
|
||||
LBRY_SPEECH_PW,
|
||||
LBRY_SPEECH_SETTINGS,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles new channel form submission
|
||||
*/
|
||||
|
|
|
@ -43,7 +43,7 @@ class LBRY_Speech
|
|||
return false;
|
||||
}
|
||||
|
||||
$speech_url = get_option(LBRY_SETTINGS)[LBRY_SPEECH];
|
||||
$speech_url = get_option(LBRY_SPEECH_SETTINGS)[LBRY_SPEECH];
|
||||
|
||||
// Die if we don't have a spee.ch url
|
||||
if (!$speech_url || $speech_url === '') {
|
||||
|
@ -66,7 +66,7 @@ class LBRY_Speech
|
|||
);
|
||||
|
||||
// Pull Channel and Password from config file for now
|
||||
$speech_channel = get_option(LBRY_SETTINGS)[LBRY_SPEECH_CHANNEL];
|
||||
$speech_channel = get_option(LBRY_SPEECH_SETTINGS)[LBRY_SPEECH_CHANNEL];
|
||||
$speech_pw = LBRY()->admin->get_speech_pw();
|
||||
if (!empty($speech_channel) && !empty($speech_pw)) {
|
||||
$params['channelName'] = '@' . $speech_channel;
|
||||
|
@ -229,7 +229,7 @@ class LBRY_Speech
|
|||
*/
|
||||
private function build_request($method, $params = array())
|
||||
{
|
||||
$speech_url = get_option(LBRY_SETTINGS)[LBRY_SPEECH];
|
||||
$speech_url = get_option(LBRY_SPEECH_SETTINGS)[LBRY_SPEECH];
|
||||
|
||||
// Die if no URL
|
||||
if (!$speech_url) {
|
||||
|
|
Loading…
Reference in a new issue