parent
b026f27485
commit
07a060eeaa
6 changed files with 197 additions and 23 deletions
|
@ -7,4 +7,9 @@
|
||||||
height: 1.8em;
|
height: 1.8em;
|
||||||
margin-right: .5em;
|
margin-right: .5em;
|
||||||
margin-bottom: -.5em;
|
margin-bottom: -.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bid-icon-lbc {
|
||||||
|
height: 1.2em;
|
||||||
|
margin-bottom: -.2em;
|
||||||
|
}
|
||||||
|
|
|
@ -120,6 +120,8 @@ class LBRYPress
|
||||||
$this->define('LBRY_LBC_PUBLISH', 'lbry_lbc_publish'); // amount of lbc to use per publish
|
$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_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_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_CLAIM_ID', '_lbry_claim_id'); // The Claim ID for the post as it was published on LBRY
|
$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_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
|
$this->define('LBRY_SPEECH_ASSET_URL', 'speech_asset_url'); // The meta key for an asset's speech url
|
||||||
|
|
|
@ -25,7 +25,7 @@ class LBRY_Admin
|
||||||
*/
|
*/
|
||||||
public function create_options_page()
|
public function create_options_page()
|
||||||
{
|
{
|
||||||
add_menu_page(
|
$hook_suffix = add_menu_page(
|
||||||
__('LBRYPress Settings', 'lbrypress'),
|
__('LBRYPress Settings', 'lbrypress'),
|
||||||
__('LBRYPress', 'lbrypress'),
|
__('LBRYPress', 'lbrypress'),
|
||||||
'manage_options',
|
'manage_options',
|
||||||
|
@ -96,6 +96,15 @@ class LBRY_Admin
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Channel Page Settings
|
||||||
|
* We are using a custom page so that we can use the admin-post action and retrieve the $_POST
|
||||||
|
* global variable to populate the cURL request to create_channel, not saving the inputs to
|
||||||
|
* our database.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
* Speech Admin Page settings
|
* Speech Admin Page settings
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -212,6 +221,32 @@ class LBRY_Admin
|
||||||
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.';
|
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
|
||||||
|
*/
|
||||||
|
public function available_channels_callback()
|
||||||
|
{
|
||||||
|
$channel_list = LBRY()->daemon->channel_list();
|
||||||
|
|
||||||
|
if ( $channel_list ) { ?>
|
||||||
|
<ul class="lbry-channel-list">
|
||||||
|
<?php foreach ( $channel_list as $channel ) { ?>
|
||||||
|
<li><?php esc_html_e( $channel->name ) ?></li>
|
||||||
|
<?php } ?>
|
||||||
|
</ul>
|
||||||
|
<?php } else { ?>
|
||||||
|
<p>Looks like you haven't added any channels yet, feel free to do so below:</p>
|
||||||
|
<?php }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Prints Wallet input
|
||||||
*/
|
*/
|
||||||
|
@ -228,7 +263,6 @@ class LBRY_Admin
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints License input
|
* Prints License input
|
||||||
*/
|
*/
|
||||||
|
@ -310,33 +344,92 @@ class LBRY_Admin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Channels Page
|
||||||
|
* Channels page uses admin.php so we are able to use the admin-post action instead of options.php
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Handles new channel form submission
|
||||||
*/
|
*/
|
||||||
public function add_channel()
|
public function add_channel()
|
||||||
{
|
{
|
||||||
$redirect_url = admin_url('options-general.php?page=' . LBRY_ADMIN_PAGE);
|
|
||||||
|
|
||||||
|
$redirect_url = admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channels' ), 'options.php' ) );
|
||||||
|
|
||||||
// Check that nonce
|
// Check that nonce
|
||||||
if (! isset($_POST['_lbrynonce']) || ! wp_verify_nonce($_POST['_lbrynonce'], 'lbry_add_channel')) {
|
if ( isset( $_POST['_lbrynonce'] ) && wp_verify_nonce( $_POST['_lbrynonce'], 'add_channel_nonce' ) ) {
|
||||||
LBRY()->notice->set_notice('error');
|
if ( empty( $_POST['lbry_new_channel'] ) || empty( $_POST['lbry_channel_bid_amount'] ) ) {
|
||||||
} elseif (! isset($_POST['new_channel']) || ! isset($_POST['bid_amount'])) {
|
LBRY()->notice->set_notice( 'error', 'Must supply both channel name and bid amount' );
|
||||||
LBRY()->notice->set_notice('error', 'Must supply both channel name and bid amount');
|
} elseif ( isset( $_POST['lbry_new_channel'] ) && isset( $_POST['lbry_channel_bid_amount'] ) ) {
|
||||||
} else {
|
$channel = $_POST['lbry_new_channel']; // TODO: sanitize key() only allows for lowercase chars, dashes, and underscores. maybe remove to allow more characters? and use something else for better control?
|
||||||
$new_channel = $_POST['new_channel'];
|
$channel = trim( $channel );
|
||||||
$bid_amount = $_POST['bid_amount'];
|
$channel = str_replace( '@', '', $channel );
|
||||||
|
$channel = str_replace( ' ', '-', $channel );
|
||||||
|
$channel = str_replace( '_', '-', $channel );
|
||||||
|
$channel_name = sanitize_user( $channel );
|
||||||
|
|
||||||
// Try to add the new channel
|
$bid = $_POST['lbry_channel_bid_amount'];
|
||||||
try {
|
$channel_bid = number_format( floatval( $bid ), 3, '.', '' );
|
||||||
$result = LBRY()->daemon->channel_new($new_channel, $bid_amount);
|
|
||||||
// Tell the user it takes some time to go through
|
// Try to add the new channel
|
||||||
LBRY()->notice->set_notice('success', 'Successfully added a new channel! Please wait a few minutes for the bid to process.', true);
|
try {
|
||||||
} catch (\Exception $e) {
|
$result = LBRY()->daemon->channel_new( $channel_name, $channel_bid );
|
||||||
LBRY()->notice->set_notice('error', $e->getMessage(), false);
|
// Tell the user it takes some time to go through
|
||||||
|
LBRY()->notice->set_notice(
|
||||||
|
'success', 'Successfully added a new channel: @' . esc_html( $channel_name ) . '! Please allow a few minutes for the bid to process.', true );
|
||||||
|
|
||||||
|
} 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);
|
wp_safe_redirect( $redirect_url );
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ class LBRY_Daemon
|
||||||
* https://lbry.tech/api/sdk#channel_create
|
* https://lbry.tech/api/sdk#channel_create
|
||||||
* @return array dictionary containing result of the request
|
* @return array dictionary containing result of the request
|
||||||
*/
|
*/
|
||||||
public function channel_new($channel_name, $bid_amount)
|
public function channel_new($channel_name, $channel_bid)
|
||||||
{
|
{
|
||||||
// TODO: Sanitize channel name and bid
|
// TODO: Sanitize channel name and bid
|
||||||
// Make sure no @ sign, as we will add that
|
// Make sure no @ sign, as we will add that
|
||||||
|
@ -134,10 +134,13 @@ class LBRY_Daemon
|
||||||
'channel_create',
|
'channel_create',
|
||||||
array(
|
array(
|
||||||
'name' => $channel_name,
|
'name' => $channel_name,
|
||||||
'bid' => number_format(floatval($bid_amount), 2, '.', '')
|
'bid' => $channel_bid
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->logger->log( 'channel_create success!', 'Successfully created channel with result: ' . print_r( $result->result, true ) );
|
||||||
return $result->result;
|
return $result->result;
|
||||||
|
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch (LBRYDaemonException $e) {
|
||||||
$this->logger->log('channel_new error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log('channel_new error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||||
throw new \Exception('Issue creating new channel.', 1);
|
throw new \Exception('Issue creating new channel.', 1);
|
||||||
|
|
71
templates/channels-page.php
Normal file
71
templates/channels-page.php
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ============================
|
||||||
|
* CHANNELS SETTINGS ADMIN PAGE
|
||||||
|
* Uses the post-admin action so we can use the $_POST global variable to build our cURL request and the settings are not saved to the datbase
|
||||||
|
* @package LBRYPress
|
||||||
|
* ============================
|
||||||
|
*/
|
||||||
|
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||||
|
|
||||||
|
if ( current_user_can( 'manage_options' ) ) {
|
||||||
|
|
||||||
|
// Generate a custom nonce
|
||||||
|
$lbrynonce = wp_create_nonce( 'add_channel_nonce' );
|
||||||
|
|
||||||
|
// Build the page
|
||||||
|
?>
|
||||||
|
|
||||||
|
<h3><?php _e( 'Available Channels To Publish', 'lbrypress' ); ?></h3>
|
||||||
|
<?php LBRY()->admin->available_channels_callback(); ?>
|
||||||
|
<?php if ( isset( $_POST['lbry_new_channel'] ) ) {
|
||||||
|
$channel = $_POST['lbry_new_channel'];
|
||||||
|
$channel = str_replace( '@', '', $channel );
|
||||||
|
$channel = str_replace( ' ', '-', $channel );
|
||||||
|
$clean_input['lbry_new_channel'] = sanitize_user( $channel );
|
||||||
|
}
|
||||||
|
if ( isset( $_POST['lbry_channel_bid_amount'] ) ) {
|
||||||
|
$channel_bid = $_POST['lbry_channel_bid_amount'];
|
||||||
|
$clean_input['lbry_channel_bid_amount'] = number_format( floatval( $channel_bid ), 3, '.', '' );
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post" id="lbry_add_channel_form">
|
||||||
|
|
||||||
|
<input type="hidden" name="action" value="lbry_add_channel">
|
||||||
|
<input type="hidden" name="_lbrynonce" value="<?php echo $lbrynonce ?>">
|
||||||
|
<h3><?php echo _e( 'Create a New Channel', 'lbrypress' ); ?></h3>
|
||||||
|
<table class="form-table" role="presentation">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">New Channel Name</th>
|
||||||
|
<td>
|
||||||
|
<?php printf(
|
||||||
|
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="@' . esc_attr('%2$s') . '" placeholder="your-new-channel" required>',
|
||||||
|
'lbry_new_channel',
|
||||||
|
$clean_input['lbry_new_channel'],
|
||||||
|
); ?>
|
||||||
|
<p>No Spaces in Channel Names</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Amount of LBC to Bid</th>
|
||||||
|
<td>
|
||||||
|
<?php printf(
|
||||||
|
'<input type="number" step="0.001" min="0.001" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('%2$.3f') . '" required>',
|
||||||
|
'lbry_channel_bid_amount',
|
||||||
|
$clean_input['lbry_channel_bid_amount'],
|
||||||
|
); ?>
|
||||||
|
<p>Current minimum bid <img src="<?php echo esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png' ) ?>" class="icon icon-lbc bid-icon-lbc"> 0.001</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="Create New Channel"></p>
|
||||||
|
</form>
|
||||||
|
<?php
|
||||||
|
} else {
|
||||||
|
?>
|
||||||
|
<p> <?php __( "You are not authorized to perform this operation.", $this->plugin_name ) ?> </p>
|
||||||
|
<?php
|
||||||
|
}
|
|
@ -21,7 +21,7 @@ $channel_list = $LBRY->daemon->channel_list();
|
||||||
<a href="<?php echo esc_url( admin_url( 'options.php?page=lbrypress&tab=speech' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'speech' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Spee.ch' ); ?></a>
|
<a href="<?php echo esc_url( admin_url( 'options.php?page=lbrypress&tab=speech' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'speech' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Spee.ch' ); ?></a>
|
||||||
</nav>
|
</nav>
|
||||||
<?php if ( $lbry_active_tab == 'channels' ) {
|
<?php if ( $lbry_active_tab == 'channels' ) {
|
||||||
include_once( 'channel-page.php' );
|
include_once( 'channels-page.php' );
|
||||||
} else {
|
} else {
|
||||||
?>
|
?>
|
||||||
<form class="form-table" action="<?php echo esc_url( admin_url( 'options.php' ) ); ?>" method="post">
|
<form class="form-table" action="<?php echo esc_url( admin_url( 'options.php' ) ); ?>" method="post">
|
||||||
|
@ -32,7 +32,7 @@ $channel_list = $LBRY->daemon->channel_list();
|
||||||
do_settings_sections( LBRY_ADMIN_PAGE );
|
do_settings_sections( LBRY_ADMIN_PAGE );
|
||||||
submit_button();
|
submit_button();
|
||||||
} elseif ( $lbry_active_tab == 'channels' ) {
|
} elseif ( $lbry_active_tab == 'channels' ) {
|
||||||
include_once( 'channel-page.php' );
|
include_once( 'channels-page.php' );
|
||||||
} elseif ( $lbry_active_tab == 'speech' ) {
|
} elseif ( $lbry_active_tab == 'speech' ) {
|
||||||
settings_fields( LBRY_SPEECH_SETTINGS );
|
settings_fields( LBRY_SPEECH_SETTINGS );
|
||||||
do_settings_sections( 'lbrypress-speech' );
|
do_settings_sections( 'lbrypress-speech' );
|
||||||
|
|
Loading…
Reference in a new issue