Default license selector #51

Merged
lemsmyth merged 3 commits from default-license-select into master 2022-02-13 17:39:42 +01:00
8 changed files with 176 additions and 135 deletions

View file

@ -68,7 +68,7 @@ class LBRY_Admin
{ {
// Register the LBRY Setting array // Register the LBRY Setting array
register_setting( register_setting(
LBRY_SETTINGS_GROUP, 'lbry_general_settings',
LBRY_SETTINGS, LBRY_SETTINGS,
array( $this, 'sanitize_general_settings' ) array( $this, 'sanitize_general_settings' )
); );
@ -90,6 +90,13 @@ class LBRY_Admin
LBRY_SETTINGS_SECTION_GENERAL 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( add_settings_field(
LBRY_LICENSE, LBRY_LICENSE,
'LBRY Publishing License', 'LBRY Publishing License',
@ -115,7 +122,6 @@ class LBRY_Admin
/** /**
* Speech Admin Page settings * Speech Admin Page settings
*/ */
@ -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 .= '<option value="' . esc_attr( $channel->claim_id ) . '"';
if ( $selected ) {
$options .= ' selected';
}
$options .= '>' . esc_html( $channel->name ) . '</option>';
}
printf(
'<select id="' . esc_attr('%1$s') . '" name="' . esc_attr('%2$s[%1$s]') . '">' . esc_html('%3$s') . '</select>',
'default_lbry_channel',
LBRY_SETTINGS,
$options
);
} else { ?>
<p>Looks like you haven't added any channels yet, you can do that now on the <a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channels' ), 'options.php' ) ) ); ?>" class="">Channels Tab</a></p>
<?php }
}
/** /**
* Prints License input * Prints License input
*/ */
@ -275,13 +312,14 @@ class LBRY_Admin
} }
printf( printf(
'<select id="%1$s" name="%2$s[%1$s]">%3$s</select>', '<select id="'.esc_attr('%1$s').'" name="'. esc_attr('%2$s[%1$s]') .'">' . esc_html('%3$s') . '</select>',
LBRY_LICENSE, LBRY_LICENSE,
LBRY_SETTINGS, LBRY_SETTINGS,
$options $options
); );
} }
/** /**
* Prints LBC per publish input * Prints LBC per publish input
*/ */
@ -398,7 +436,7 @@ class LBRY_Admin
if (!get_transient('lbry_wallet_warning_email')) { if (!get_transient('lbry_wallet_warning_email')) {
$email = get_option('admin_email'); $email = get_option('admin_email');
$subject = 'Your LBRYPress Wallet Balance is Low!'; $subject = 'Your LBRYPress Wallet Balance is Low!';
$message = "You LBRY Wallet for your wordpress installation at " . site_url() . " is running very low.\r\n\r\nYou currently have " . $balance . ' LBC left in your wallet. In order to keep publishing to the LBRY network, please add some LBC to your account.'; $message = "Your LBRY Wallet for your WordPress installation at " . site_url() . " is running very low.\r\n\r\nYou currently have " . $balance . ' LBC left in your wallet. In order to keep publishing to the LBRY network, please add some LBC to your account.';
wp_mail($email, $subject, $message); wp_mail($email, $subject, $message);
set_transient('lbry_wallet_warning_email', true, DAY_IN_SECONDS); set_transient('lbry_wallet_warning_email', true, DAY_IN_SECONDS);
} }

View file

@ -7,6 +7,7 @@
class LBRY_Admin_Notice class LBRY_Admin_Notice
{ {
public function __construct() public function __construct()
{ {
add_action( 'admin_notices', array( $this, 'admin_notices' ) ); add_action( 'admin_notices', array( $this, 'admin_notices' ) );

View file

@ -50,8 +50,7 @@ class LBRY_Daemon
* @param int $page Pagination page number * @param int $page Pagination page number
* @return array Array of address lists linked to this account * @return array Array of address lists linked to this account
*/ */
public function address_list($page = 1) public function address_list( $page = 1 ) {
{
// Get 20 per page // Get 20 per page
$params = array( $params = array(
'page' => $page, 'page' => $page,
@ -71,7 +70,7 @@ class LBRY_Daemon
* Returns the available balance of a current LBRY account * Returns the available balance of a current LBRY account
* https://lbry.tech/api/sdk#wallet_balance * https://lbry.tech/api/sdk#wallet_balance
* @param string $address Wallet Address * @param string $address Wallet Address
* @return array $wallet_balance Wallet Balance * @return object $wallet_balance Wallet Balance
* *
*/ */
public function wallet_balance() public function wallet_balance()
@ -114,6 +113,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, $channel_bid ) public function channel_new( $channel_name, $channel_bid )
{ {
// TODO: Sanitize channel name and bid // TODO: Sanitize channel name and bid
@ -248,7 +248,7 @@ class LBRY_Daemon
} }
/** /**
* Checks for erros in decoded daemon response and throws an exception if it finds one * Checks for errors in decoded daemon response and throws an exception if it finds one
* @param $response * @param $response
*/ */
private function check_for_errors( $response ) private function check_for_errors( $response )

View file

@ -7,6 +7,7 @@
class LBRY_Daemon_Logger class LBRY_Daemon_Logger
{ {
/** /**
* The directory to log to * The directory to log to
* @var string * @var string

View file

@ -79,9 +79,11 @@ class LBRY_Network
return $post_id; return $post_id;
} }
$will_publish = (isset($_POST[LBRY_WILL_PUBLISH]) ? $_POST[LBRY_WILL_PUBLISH] : false); $channel = $_POST[LBRY_POST_PUB_CHANNEL];
$new_channel = (isset($_POST[LBRY_POST_CHANNEL]) ? $_POST[LBRY_POST_CHANNEL] : null); $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 ) );
$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 );
$will_publish = $_POST[LBRY_WILL_PUBLISH];
// Update meta acordingly // Update meta acordingly
if (!$will_publish) { if (!$will_publish) {

View file

@ -30,7 +30,7 @@ class LBRY_Network_Publisher
// If everything went well with the conversion, carry on // If everything went well with the conversion, carry on
$args = array( $args = array(
'name' => $post->post_name, 'name' => $post->post_name,
'bid' => number_format(floatval(get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH]), 2, '.', ''), 'bid' => number_format( floatval( get_option( LBRY_SETTINGS )[LBRY_LBC_PUBLISH] ), 3, '.', '' ),
'file_path' => $filepath, 'file_path' => $filepath,
'title' => $post->post_title, 'title' => $post->post_title,
'languages' => array( substr( get_locale(), 0, 2 ) ), 'languages' => array( substr( get_locale(), 0, 2 ) ),

View file

@ -45,4 +45,3 @@ $channel_list = $LBRY->daemon->channel_list();
?> ?>
</form> </form>
</div><!-- wrap --> </div><!-- wrap -->