Claim search method #64

Merged
lemsmyth merged 31 commits from claim-search-method into master 2022-02-16 21:42:48 +01:00
43 changed files with 844 additions and 328 deletions
Showing only changes of commit 056ee42d62 - Show all commits

2
.gitignore vendored
View file

@ -4,6 +4,8 @@
!*.* !*.*
.DS_Store .DS_Store
extensions.json
.vscode/*
tmp/* tmp/*
logs/* logs/*

View file

@ -43,10 +43,11 @@ WantedBy=multi-user.target
1) Start it with: `sudo service lbrynet start`. If you are already running LBRY in the background, issue a `lbrynet stop` command first. 1) Start it with: `sudo service lbrynet start`. If you are already running LBRY in the background, issue a `lbrynet stop` command first.
## Funding and preparing your wallet ## Funding and preparing your wallet
LBRY will require LBRY Credits (LBC) for the channel creation and publishing process. You can send LBC to this instance from your LBRY app / lbry.tv using the Wallet page > Send Credits. If you need LBC, sign up for a [lbry.tv account](https://lbry.tv) or [email us](mailto:hello@lbry.com). After you send credits, they will be split into smaller amounts to facilatate the publishing process. You can also use an existing LBRY Desktop wallet/ channel by copying the default_wallet file into `~/.local/shared/lbry/lbryum/wallets`. LBRY will require LBRY Credits (LBC) for the channel creation and publishing process. You can send LBC to this instance from your LBRY app / lbry.tv using the Wallet page > Send Credits. If you need LBC, sign up for a [lbry.tv account](https://lbry.tv) or [email us](mailto:hello@lbry.com). After you send credits, they will be split into smaller amounts to facilitate the publishing process. You can also use an existing LBRY Desktop wallet/ channel by copying the default_wallet file into `~/.local/shared/lbry/lbryum/wallets`.
1) Go to the LBRYPress plugin page and find your wallet address: 1) Go to the LBRYPress plugin page and find your wallet address:
![](https://spee.ch/d/address.jpg)
![](/admin/images/wallet-address.jpg)
1) Copy this address and send at least a few credits to it. From the Desktop app/lbry.tv, go to the Wallet page > Send Credits. 1) Copy this address and send at least a few credits to it. From the Desktop app/lbry.tv, go to the Wallet page > Send Credits.
1) We will take the amount you deposited and split it up by a factor of 10. So if you deposited 10 LBC, you'd split it into 100: The decimal point is important, it will throw back an error without the structure of "10.0" 1) We will take the amount you deposited and split it up by a factor of 10. So if you deposited 10 LBC, you'd split it into 100: The decimal point is important, it will throw back an error without the structure of "10.0"
@ -58,19 +59,29 @@ Experimental: republishing of images in blog to LBRY: If images or GIFs are used
**Please note: spee.ch channel creation is no longer available and that step can be skiped.** **Please note: spee.ch channel creation is no longer available and that step can be skiped.**
1) Enter 0.1 for **LBC per Publish**. 1) Select the channel you wish as a **Default Publish Channel**. Can change later on a per-post basis.
1) Select the **Default Publish License** you wish to use as your default.
1) Enter 0.001 for **LBC per Publish** (later you can add more as a support if needed).
1) Click **Save Settings**. 1) Click **Save Settings**.
![](https://spee.ch/8/speech-setup-lbrypress.jpeg) ![](/admin/images/settings-tab.jpg)
## Setting up a your blog publishing channel ## Setting up your blog publishing channel
If you don't already have a channel, this process will create a channel in your local wallet where your blog posts will be published to. Any available channels will be listed at the top of the **Your Publishable Channels** section. If you don't already have a channel, this process will create a channel in your local wallet where your blog posts will be published to. Any available channels will be listed at the top of the **Your Publishable Channels** section on the **Channels** tab.
1) Enter the channel you wish to create and publish under in **New Channel Name**. 1) Enter the channel you wish to create and publish under in **New Channel Name**.
1) Enter a bid of 0.01 (this can be increased later). Your channel will be created with a single @ prefix and all spaces and underscores are changed to a dash. Uppercase characters are allowed. Most special characters are removed.
1) Enter an **Amount of LBC to Bid** of 0.001 (current minimum, you can increase the amount or use supports later).
By adding as a support you push your content higher in the search but also keep your LBC fluid and easily moved without needing to abandon your claim.
1) Click **Add New Channel**. 1) Click **Add New Channel**.
![](https://spee.ch/7/channel-lbrypress.jpg) ![](/admin/images/add-channel.jpg)
![](/admin/images/channel-create-success.jpg)
Wait a few minutes and do a page refresh, your new channel should now be in the list.
![](/admin/images/new-channel.jpg)
## Publishing blog posts ## Publishing blog posts
When creating a new post (or editing an existing one), you can choose to publish it on LBRY as well. If you do this for an existing post, it will not retain the original date (known issue). When creating a new post (or editing an existing one), you can choose to publish it on LBRY as well. If you do this for an existing post, it will not retain the original date (known issue).

2
admin/css/index.php Normal file
View file

@ -0,0 +1,2 @@
<?php
// Silence is golden

47
admin/css/lbry-admin.css Normal file
View file

@ -0,0 +1,47 @@
/**
* Stylesheet for the admin options page
* @package LBRYPress
*/
.wallet-icon-lbc {
height: 1.8em;
margin-right: .5em;
margin-bottom: -.5em;
}
.bid-icon-lbc {
height: 1.2em;
margin-bottom: -.2em;
}
.lbry-pub-metabox {
margin: 0 0 0 -.2em;
padding: 0 .2em 0 0 ;
}
.meta-icon-lbry {
height: 1.55em;
margin-bottom: -.4em;
padding-left: .1em;
}
.lbry-meta-checkbox-wrapper {
padding: .5em .8em .6em;
}
.lbry-meta-checkbox-wrapper-last {
padding: .5em .8em 1.5em;
}
.lbry-meta-label {
padding-left: .3em;
padding-right: .6em;
}
.lbry-meta-bx-label {
margin: .5em .8em .6em;
}
.lbry-meta-bx-option {
padding: .5em .8em .6em;
}
.lbry-meta-bx-option-last {
padding: .5em .8em 1.5em;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

2
admin/images/index.php Normal file
View file

@ -0,0 +1,2 @@
<?php
// Silence is golden

BIN
admin/images/lbry-icon.png Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 654 B

After

Width:  |  Height:  |  Size: 654 B

BIN
admin/images/lbry.png Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

BIN
admin/images/speech-tab.jpg Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

2
admin/js/index.php Normal file
View file

@ -0,0 +1,2 @@
<?php
// Silence is golden

2
bin/index.php Normal file
View file

@ -0,0 +1,2 @@
<?php
// Silence is golden

View file

@ -4,6 +4,7 @@
* *
* @package LBRYPress * @package LBRYPress
*/ */
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRYPress class LBRYPress
{ {
@ -107,18 +108,20 @@ class LBRYPress
$this->define('LBRY_VERSION', $this->version); $this->define('LBRY_VERSION', $this->version);
// Library Options Names // Library Options Names
$this->define('LBRY_SETTINGS_GROUP', 'lbry_settings_group'); //$this->define('LBRY_SETTINGS_GROUP', 'lbry_settings_group');
$this->define('LBRY_SETTINGS', 'lbry_settings'); $this->define('LBRY_SETTINGS', 'lbry_settings');
$this->define('LBRY_SETTINGS_SECTION_GENERAL', 'lbry_settings_section_general'); $this->define('LBRY_SETTINGS_SECTION_GENERAL', 'lbry_settings_section_general');
$this->define('LBRY_ADMIN_PAGE', 'lbrypress'); $this->define('LBRY_ADMIN_PAGE', 'lbrypress');
$this->define('LBRY_WALLET', 'lbry_wallet'); // the wallet address $this->define('LBRY_WALLET', 'lbry_wallet'); // the wallet address
$this->define('LBRY_SPEECH_SETTINGS', 'lbry_speech_settings');
$this->define('LBRY_SPEECH', 'lbry_speech'); // the spee.ch address $this->define('LBRY_SPEECH', 'lbry_speech'); // the spee.ch address
$this->define('LBRY_SPEECH_CHANNEL', 'lbry_speech_channel'); // The spee.ch channel $this->define('LBRY_SPEECH_CHANNEL', 'lbry_speech_channel'); // The spee.ch channel
$this->define('LBRY_SPEECH_PW', 'lbry_speech_pw'); // The password for the spee.ch channel $this->define('LBRY_SPEECH_PW', 'lbry_speech_pw'); // The password for the spee.ch channel
$this->define('LBRY_LICENSE', 'lbry_license'); // the license to publish with to the LBRY network $this->define('LBRY_LICENSE', 'lbry_license'); // the license to publish with to the LBRY network
$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_post_pub_channel'); // The meta key for which channel to publish
$this->define('LBRY_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
@ -182,14 +185,26 @@ class LBRYPress
//Default options //Default options
$option_defaults = array( $option_defaults = array(
LBRY_SPEECH => null, LBRY_WALLET => '',
LBRY_LICENSE => $this->licenses[0], 'lbry_default_publish_setting' => '',
LBRY_LBC_PUBLISH => 1 'default_lbry_channel' => '',
LBRY_LICENSE => '',
LBRY_LBC_PUBLISH => 0.001,
); );
add_option( LBRY_SETTINGS, $option_defaults, false ); 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. // 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 // Double check we have all settings, if not, update with default
// $current_settings = get_option(LBRY_SETTINGS); // $current_settings = get_option(LBRY_SETTINGS);

View file

@ -4,6 +4,7 @@
* *
* @package LBRYPress * @package LBRYPress
*/ */
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Admin class LBRY_Admin
{ {
@ -25,14 +26,56 @@ 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',
LBRY_ADMIN_PAGE, LBRY_ADMIN_PAGE,
array( $this, 'options_page_html' ), array( $this, 'options_page_html' ),
plugin_dir_url(LBRY_PLUGIN_FILE) . '/admin/images/lbry-logo.svg' plugin_dir_url( LBRY_PLUGIN_FILE ) . '/admin/images/lbry-icon.png'
); );
// Admin stylesheet enqueue
function load_admin_stylesheet( $hook ) {
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 ),
array(),
LBRY_VERSION,
'all'
);
}
}
add_action( 'admin_enqueue_scripts', 'load_admin_stylesheet' );
// Admin Error Notices
function lbry_plugin_not_configured_notice() {
echo "<div id='notice' class='updated fade'><p>LBRYPress plugin is not configured yet. Please do it now.</p></div>\n";
}
$lbry_wallet = get_option('lbry_wallet');
if ( ! isset($lbry_wallet) ) {
add_action( 'admin_notices', 'lbry_plugin_not_configured_notice' );
}
function admin_permission_check() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
}
}
/**
* Returns the Options Page HTML for the plugin
*/
public function options_page_html() {
//$LBRY = LBRY();
// Set class properties to be referenced in callbacks
$this->options = get_option( LBRY_SETTINGS );
//$this->options_channel = get_option( 'lbry_channel_settings' );
$this->options_speech = get_option( LBRY_SPEECH_SETTINGS );
require_once( LBRY_ABSPATH . 'templates/options-page.php' );
} }
/** /**
@ -41,13 +84,17 @@ class LBRY_Admin
public function page_init() public function page_init()
{ {
// Register the LBRY Setting array // Register the LBRY Setting array
register_setting(LBRY_SETTINGS_GROUP, LBRY_SETTINGS, array('sanitize_callback' => array($this, 'sanitize'))); register_setting(
'lbry_general_settings',
LBRY_SETTINGS,
array( $this, 'sanitize_general_settings' )
);
// Add Required Settings Sections // Add Required Settings Sections
add_settings_section( add_settings_section(
LBRY_SETTINGS_SECTION_GENERAL, // ID LBRY_SETTINGS_SECTION_GENERAL, // ID
'General Settings', // Title 'General Settings', // Title
array( $this, 'general_section_info' ), // Callback array( $this, 'general_section_callback' ), // Callback
LBRY_ADMIN_PAGE // Page LBRY_ADMIN_PAGE // Page
); );
@ -59,35 +106,43 @@ class LBRY_Admin
LBRY_ADMIN_PAGE, LBRY_ADMIN_PAGE,
LBRY_SETTINGS_SECTION_GENERAL LBRY_SETTINGS_SECTION_GENERAL
); );
// remove from commit:
add_settings_field( add_settings_field(
LBRY_SPEECH, 'lbry_default_publish_setting',
'Spee.ch URL', 'Always Publish to LBRY',
array( $this, 'speech_callback' ), array( $this, 'lbry_always_pub_callback' ),
LBRY_ADMIN_PAGE, LBRY_ADMIN_PAGE,
LBRY_SETTINGS_SECTION_GENERAL LBRY_SETTINGS_SECTION_GENERAL
); );
add_settings_field( add_settings_field(
LBRY_SPEECH_CHANNEL, 'lbry_default_publish_setting',
'Spee.ch Channel', 'Always Publish to LBRY',
array( $this, 'speech_channel_callback' ), array( $this, 'lbry_always_pub_callback' ),
LBRY_ADMIN_PAGE, LBRY_ADMIN_PAGE,
LBRY_SETTINGS_SECTION_GENERAL LBRY_SETTINGS_SECTION_GENERAL
); );
add_settings_field( add_settings_field(
LBRY_SPEECH_PW, 'default_lbry_channel',
'Spee.ch Password', 'Default Publish Channel',
array( $this, 'speech_pw_callback' ), array( $this, 'default_channel_callback' ),
LBRY_ADMIN_PAGE,
LBRY_SETTINGS_SECTION_GENERAL
);
// remove from commit:
add_settings_field(
'lbry_default_publish_setting',
'Always Publish to LBRY',
array( $this, 'lbry_always_pub_callback' ),
LBRY_ADMIN_PAGE, LBRY_ADMIN_PAGE,
LBRY_SETTINGS_SECTION_GENERAL LBRY_SETTINGS_SECTION_GENERAL
); );
add_settings_field( add_settings_field(
LBRY_LICENSE, 'lbry_default_publish_setting',
'LBRY Publishing License', 'Always Publish to LBRY',
array( $this, 'license_callback' ), array( $this, 'lbry_always_pub_callback' ),
LBRY_ADMIN_PAGE, LBRY_ADMIN_PAGE,
LBRY_SETTINGS_SECTION_GENERAL LBRY_SETTINGS_SECTION_GENERAL
); );
@ -95,55 +150,147 @@ class LBRY_Admin
add_settings_field( add_settings_field(
LBRY_LBC_PUBLISH, LBRY_LBC_PUBLISH,
'LBC Per Publish', 'LBC Per Publish',
array( $this, 'lbc_publish_callback' ), array( $this, 'lbc_per_publish_callback' ),
LBRY_ADMIN_PAGE, LBRY_ADMIN_PAGE,
LBRY_SETTINGS_SECTION_GENERAL LBRY_SETTINGS_SECTION_GENERAL
); );
}
/** /**
* Returns the Options Page HTML for the plugin * 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.
*/ */
public function options_page_html()
{
// Set class property to be referenced in callbacks /**
$this->options = get_option(LBRY_SETTINGS); * Speech Admin Page settings
require_once(LBRY_ABSPATH . 'templates/options_page.php'); */
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'
);
} }
/** /**
* Sanitizes setting input * Sanitizes setting input
* // COMBAK Potentially sanitize more * // COMBAK Potentially sanitize more
*/ */
public function sanitize($input)
public function sanitize_general_settings( $input )
{ {
if (!empty($input[LBRY_SPEECH_CHANNEL])) { $new_input = get_option( LBRY_SETTINGS ); // get saved data
if ( isset( $input[LBRY_WALLET] ) ) {
$new_input[LBRY_WALLET] = sanitize_text_field( $input[LBRY_WALLET] );
}
$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 )
{
$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 = $input[LBRY_SPEECH_CHANNEL];
$channel = str_replace( '@', '', $channel ); $channel = str_replace( '@', '', $channel );
$input[LBRY_SPEECH_CHANNEL] = $channel; $new_input[LBRY_SPEECH_CHANNEL] = sanitize_user( $channel );
} }
if ( isset( $input[LBRY_SPEECH_PW] ) ) {
if (!empty($input[LBRY_SPEECH_PW])) { $input[LBRY_SPEECH_PW] = sanitize_text_field( $input[LBRY_SPEECH_PW] );
$encrypted = $this->encrypt($input['lbry_speech_pw']); $encrypted = $this->encrypt( $input[LBRY_SPEECH_PW] );
$input[LBRY_SPEECH_PW] = $encrypted; $new_input[LBRY_SPEECH_PW] = $encrypted;
} else { } else {
// If we have a password and its empty, keep orginal password // If we have a password and it's empty, keep original password
if (!empty(get_option(LBRY_SETTINGS)[LBRY_SPEECH_PW])) { if ( empty( $input[LBRY_SPEECH_PW] ) )
$input[LBRY_SPEECH_PW] = get_option(LBRY_SETTINGS)[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 );
return $input;
} }
/** /**
* Section info for the General Section * Section info for the General Section
*/ */
public function general_section_info() public function general_section_callback()
{ {
print 'This is where you can configure how LBRYPress will distribute your content:'; print 'This is where you can configure how LBRYPress will distribute your content:';
} }
/**
* 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
*/ */
@ -153,50 +300,61 @@ class LBRY_Admin
$address = LBRY()->daemon->address_list(); $address = LBRY()->daemon->address_list();
$address = is_array( $address ) && ! empty( $address ) ? $address[0]->address : ''; $address = is_array( $address ) && ! empty( $address ) ? $address[0]->address : '';
printf( printf(
'<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" readonly />', '<input type="text" id="'. esc_attr('%1$s') .'" name="'. esc_attr('%2$s[%1$s]') .'" value="' . esc_attr('%3$s') . '" readonly />',
LBRY_WALLET, LBRY_WALLET,
LBRY_SETTINGS, LBRY_SETTINGS,
$address $address
); );
} }
// remove from commit:
/** /**
* Prints Spee.ch input * Checkbox to default to always allow publish on LBRY
*/ */
public function speech_callback() 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( printf(
'<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" placeholder="https://your-speech-address.com"/>', '<input type="checkbox" id="lbry_default_publish_setting" name="' . esc_attr('%2$s[%1$s]') . '" value="1" ' . esc_attr( $checked ) . '><p>Set Default to always Publish to <strong>LBRY</strong>, this can be adjusted when publishing a New Post.</p>',
LBRY_SPEECH, 'lbry_default_publish_setting',
LBRY_SETTINGS, LBRY_SETTINGS,
isset($this->options[LBRY_SPEECH]) ? esc_attr($this->options[LBRY_SPEECH]) : ''
); );
} }
/** /**
* Prints Spee.ch channel input * Prints select to choose a default to publish to channel
*/ */
public function speech_channel_callback() 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->name;
$options .= '<option value="' . esc_attr( $channel->claim_id ) . '"';
if ( $selected ) {
$options .= ' selected';
}
$options .= '>' . esc_html( $channel->name ) . '</option>';
}
printf( printf(
'<span>@</span><input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" placeholder="your-channel"/>', '<select id="' . esc_attr('%1$s') . '" name="' . esc_attr('%2$s[%1$s]') . '">' . esc_html('%3$s') . '</select>',
LBRY_SPEECH_CHANNEL, 'default_lbry_channel',
LBRY_SETTINGS, LBRY_SETTINGS,
isset($this->options[LBRY_SPEECH_CHANNEL]) ? esc_attr($this->options[LBRY_SPEECH_CHANNEL]) : '' $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 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 * Prints License input
@ -218,51 +376,113 @@ 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
*/ */
public function lbc_publish_callback() public function lbc_per_publish_callback()
{ {
printf( printf(
'<input type="number" id="%1$s" name="%2$s[%1$s]" value="%3$s" min="0.01" step="0.01"/>', '<input type="number" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%2$s[%1$s]') . '" value="' . esc_attr('%3$.3f') . '" min="0.001" step="0.001"><p>Current minimum bid <img src="' . esc_attr('%4$s ') . '" class="icon icon-lbc bid-icon-lbc"> 0.001</p>',
LBRY_LBC_PUBLISH, LBRY_LBC_PUBLISH,
LBRY_SETTINGS, LBRY_SETTINGS,
$this->options[LBRY_LBC_PUBLISH] $this->options[LBRY_LBC_PUBLISH],
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png'
);
}
/**
* 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' );
} else { } elseif ( isset( $_POST['lbry_new_channel'] ) && isset( $_POST['lbry_channel_bid_amount'] ) ) {
$new_channel = $_POST['new_channel']; $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?
$bid_amount = $_POST['bid_amount']; $channel = trim( $channel );
$channel = str_replace( '@', '', $channel );
$channel = str_replace( ' ', '-', $channel );
$channel = str_replace( '_', '-', $channel );
$channel_name = sanitize_user( $channel );
$bid = $_POST['lbry_channel_bid_amount'];
$channel_bid = number_format( floatval( $bid ), 3, '.', '' );
// Try to add the new channel // Try to add the new channel
try { try {
$result = LBRY()->daemon->channel_new($new_channel, $bid_amount); $result = LBRY()->daemon->channel_new( $channel_name, $channel_bid );
// Tell the user it takes some time to go through // Tell the user it takes some time to go through
LBRY()->notice->set_notice('success', 'Successfully added a new channel! Please wait a few minutes for the bid to process.', true); 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 ) { } catch ( \Exception $e ) {
LBRY()->notice->set_notice( 'error', $e->getMessage(), false ); 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();
@ -282,7 +502,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

@ -4,11 +4,12 @@
* *
* @package LBRYPress * @package LBRYPress
*/ */
defined('ABSPATH') || die(); // Exit if accessed directly
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

@ -4,6 +4,7 @@
* *
* @package LBRYPress * @package LBRYPress
*/ */
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Daemon class LBRY_Daemon
{ {
@ -32,8 +33,7 @@ class LBRY_Daemon
* https://lbry.tech/api/sdk#address_unused * https://lbry.tech/api/sdk#address_unused
* @return string Unused wallet address in base58 * @return string Unused wallet address in base58
*/ */
public function wallet_unused_address() public function wallet_unused_address() {
{
try { try {
$result = $this->request( 'address_unused' ); $result = $this->request( 'address_unused' );
return $result->result; return $result->result;
@ -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,13 +70,14 @@ 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()
{ {
try { // Convert JSON string to an object try { // Convert JSON string to an object
$result = $this->request('wallet_balance'); $result = $this->request( 'wallet_balance', array() );
return $result; return $result;
} catch (LBRYDaemonException $e) { } catch (LBRYDaemonException $e) {
$this->logger->log('wallet_balance error', $e->getMessage() . ' | Code: ' . $e->getCode()); $this->logger->log('wallet_balance error', $e->getMessage() . ' | Code: ' . $e->getCode());
@ -114,7 +114,8 @@ 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 +135,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 );
@ -245,7 +249,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

@ -4,9 +4,11 @@
* *
* @package LBRYPress * @package LBRYPress
*/ */
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Daemon_Logger class LBRY_Daemon_Logger
{ {
/** /**
* The directory to log to * The directory to log to
* @var string * @var string

View file

@ -4,6 +4,7 @@
* *
* @package LBRYPress * @package LBRYPress
*/ */
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Network class LBRY_Network
{ {
@ -34,21 +35,25 @@ class LBRY_Network
private function post_meta_setup() private function post_meta_setup()
{ {
// Add the meta boxes // 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 // Save the post meta on 'save_post' hook
add_action( 'wp_insert_post', array( $this, 'save_post_meta' ), 11, 2 ); add_action( 'wp_insert_post', array( $this, 'save_post_meta' ), 11, 2 );
// Checkbox inside the WordPres meta box near "Publish" button
add_action( 'post_submitbox_misc_actions', array( $this, 'publish_to_lbry_checkbox' ) );
} }
/** /**
* Adds the meta boxes to the post editing backend * 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 // IDEA: Support post types based on user selection
add_meta_box( add_meta_box(
'lbry-network-publishing', // Unique ID 'lbry-network-publishing', // Unique ID
'LBRY Network', // Title __('LBRY Network', 'lbrypress'), // Title
array($this, 'meta_box_html'), // Callback function array($this, 'meta_box_html'), // Callback function
'post', // Screen Options (or post type) 'post', // Screen Options (or post type)
'side', // Context 'side', // Context
@ -65,38 +70,79 @@ class LBRY_Network
public function save_post_meta( $post_id, $post ) public function save_post_meta( $post_id, $post )
{ {
if ( $post->post_type != 'post' ) { if ( $post->post_type != 'post' ) {
return;
}
// Verify the nonce before proceeding.
if (!isset($_POST['_lbrynonce']) || !wp_verify_nonce($_POST['_lbrynonce'], 'lbry_publish_channels')) {
return $post_id; return $post_id;
} }
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
// Check if the current user has permission to edit the post. return $post_id;
}
// Verify the nonce before proceeding.
if ( ! isset( $_POST['_lbrynonce'] ) || ! wp_verify_nonce( $_POST['_lbrynonce'], 'lbry_publish_post_nonce' ) ) {
//LBRY()->notice->set_notice('error', 'Security check failed' );
return $post_id;
}
$post_type = get_post_type_object( $post->post_type ); $post_type = get_post_type_object( $post->post_type );
if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) { if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
return $post_id; return $post_id;
} }
if ( ( $_POST['_lbry_will_publish'] ) && $_POST['_lbry_will_publish'] != get_post_meta( $post_id, '_lbry_will_publish', true ) ) {
update_post_meta( $post_id, '_lbry_will_publish', $_POST['_lbry_will_publish'] );
} elseif ( ! isset( $_POST['_lbry_will_publish'] ) ) {
update_post_meta( $post_id, '_lbry_will_publish', 0 );
}
$will_publish = (isset($_POST[LBRY_WILL_PUBLISH]) ? $_POST[LBRY_WILL_PUBLISH] : false); $channel = $_POST[LBRY_POST_CHANNEL];
$new_channel = (isset($_POST[LBRY_POST_CHANNEL]) ? $_POST[LBRY_POST_CHANNEL] : null); $cur_channel = ( get_post_meta( $post_id, LBRY_POST_CHANNEL, true ) ? get_post_meta( $post_id,LBRY_POST_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) {
update_post_meta($post_id, LBRY_WILL_PUBLISH, 'false'); if ( $channel !== $cur_channel ) {
} else { update_post_meta( $post_id, LBRY_POST_CHANNEL, $channel );
update_post_meta($post_id, LBRY_WILL_PUBLISH, 'true'); delete_post_meta( $post_id, '_lbry_channel'); // remove the _lbry_channel if already set from the post and replaces with _lbry_post_pub_channel to avoid confusion
} elseif ( $channel === $cur_channel && ( $cur_channel === get_post_meta( $post_id, '_lbry_channel', true ) ) ) {
update_post_meta( $post_id, LBRY_POST_CHANNEL, $channel );
delete_post_meta( $post_id, '_lbry_channel'); // remove the _lbry_channel if already set from the post and replaces with _lbry_post_pub_channel to avoid confusion
}
if ( $license !== $cur_license ) {
update_post_meta( $post_id, '_lbry_post_pub_license', $license );
}
if ( ( $will_publish ) && ( $will_publish == 1 ) && $post->post_status == 'publish') {
// Publish the post on the LBRY Network
$this->publisher->publish( $post, $channel, $license );
} }
if ($new_channel !== $cur_channel) {
update_post_meta($post_id, LBRY_POST_CHANNEL, $new_channel);
} }
if ($will_publish && $post->post_status == 'publish') { /**
// Publish the post on the LBRY Network * Creates a checkbox that changes the default setting to always publish to LBRY,
$this->publisher->publish($post, get_post_meta($post_id, LBRY_POST_CHANNEL, true)); * can be reverted individually to not publish on a per post basis. Saves to options table.
*/
public function publish_to_lbry_checkbox( $post )
{
$post_id = $post->ID;
if ( get_post_type( $post_id ) != 'post' ) {
return $post;
} }
$default_value = get_option( LBRY_SETTINGS )['lbry_default_publish_setting'];
$new_value = get_post_meta( $post_id, '_lbry_will_publish', true );
if ( ( $new_value ) ? $new_value : $new_value = $default_value );
$value = $new_value;
if ( ( $value ) ? $value : 0 );
// nonce set on page meta-box.php
printf (
'<div class="lbry-meta-checkbox-wrapper lbry-meta-checkbox-wrapper-last">
<span class="lbry-pub-metabox"><img src="' . __( '%1$s', '%4$s' ) . '" class="icon icon-lbry meta-icon-lbry"></span><label class="lbry-meta-label">' . esc_html__('%2$s', '%4$s' ) . ' <strong>' . esc_html__('%3$s', '%4$s') . '</strong></label><input type="checkbox" class="lbry-meta-checkbox" value="1"' . esc_attr('%5$s') . ' name="_lbry_will_publish">
</div>',
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png',
'Publish to',
'LBRY',
'lbrypress',
checked( $value, true, false )
);
} }
/** /**
@ -105,6 +151,6 @@ class LBRY_Network
*/ */
public function meta_box_html( $post ) public function meta_box_html( $post )
{ {
require_once(LBRY_ABSPATH . 'templates/meta_box.php'); require_once( LBRY_ABSPATH . 'templates/meta-box.php' );
} }
} }

View file

@ -8,6 +8,8 @@ use League\HTMLToMarkdown\HtmlConverter;
* *
* @package LBRYPress * @package LBRYPress
*/ */
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Network_Parser class LBRY_Network_Parser
{ {

View file

@ -4,6 +4,7 @@
* *
* @package LBRYPress * @package LBRYPress
*/ */
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Network_Publisher class LBRY_Network_Publisher
{ {
@ -13,8 +14,9 @@ class LBRY_Network_Publisher
* @param string $channel The Claim ID of the channel we are posting to * @param string $channel The Claim ID of the channel we are posting to
*/ */
// NOTE: This is currently sitting at about 150ms, mostly the post parsing // NOTE: This is currently sitting at about 150ms, mostly the post parsing
public function publish($post, $channel = null) public function publish( $post, $channel, $license ) {
{
$post_id = $post->ID;
// Get converted markdown into a file // Get converted markdown into a file
$filepath = LBRY_ABSPATH . 'tmp/' . $post->post_name . time() . '.md'; $filepath = LBRY_ABSPATH . 'tmp/' . $post->post_name . time() . '.md';
$file = fopen( $filepath, 'w' ); $file = fopen( $filepath, 'w' );
@ -30,11 +32,11 @@ 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 ) ),
'license' => get_option(LBRY_SETTINGS)[LBRY_LICENSE] 'license' => $license,
); );
// Setup channel // Setup channel

View file

@ -4,6 +4,7 @@
* *
* @package LBRYPress * @package LBRYPress
*/ */
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Notifier class LBRY_Notifier
{ {

View file

@ -6,6 +6,7 @@
* *
* @package LBRYPress * @package LBRYPress
*/ */
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Speech class LBRY_Speech
{ {
@ -43,7 +44,7 @@ class LBRY_Speech
return false; 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 // Die if we don't have a spee.ch url
if (!$speech_url || $speech_url === '') { if (!$speech_url || $speech_url === '') {
@ -66,7 +67,7 @@ class LBRY_Speech
); );
// Pull Channel and Password from config file for now // 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(); $speech_pw = LBRY()->admin->get_speech_pw();
if (!empty($speech_channel) && !empty($speech_pw)) { if (!empty($speech_channel) && !empty($speech_pw)) {
$params['channelName'] = '@' . $speech_channel; $params['channelName'] = '@' . $speech_channel;
@ -229,7 +230,7 @@ class LBRY_Speech
*/ */
private function build_request($method, $params = array()) 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 // Die if no URL
if (!$speech_url) { if (!$speech_url) {

View file

@ -6,6 +6,7 @@
* *
* @package LBRYPress * @package LBRYPress
*/ */
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Speech_Media class LBRY_Speech_Media
{ {

View file

@ -4,6 +4,7 @@
* *
* @package LBRYPress * @package LBRYPress
*/ */
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Speech_Parser class LBRY_Speech_Parser
{ {

2
classes/index.php Normal file
View file

@ -0,0 +1,2 @@
<?php
// Silence is golden

View file

@ -5,6 +5,7 @@
* *
* @package LBRYPress * @package LBRYPress
*/ */
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Post_Handler class LBRY_Post_Handler
{ {

2
frontend/index.php Normal file
View file

@ -0,0 +1,2 @@
<?php
// Silence is golden

2
inc/index.php Normal file
View file

@ -0,0 +1,2 @@
<?php
// Silence is golden

2
templates/index.php Normal file
View file

@ -0,0 +1,2 @@
<?php
// Silence is golden

62
templates/meta-box.php Normal file
View file

@ -0,0 +1,62 @@
<?php
defined('ABSPATH') || die(); // Exit if accessed directly
$unnatributed = (object) array(
'name' => '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' ) );
?>
<section>
<input type="hidden" id="_lbrynonce" name="_lbrynonce" value="<?php echo $lbrynonce ?>">
<div><label for="_lbry_post_pub_channel" class="lbry-meta-bx-label lbry-meta-bx-channel"><?php esc_html_e( 'Channel to Publish: ', 'lbrypress' ); ?></label></div><?php
$options = '';
if ( $channels ) {
foreach ( $channels as $index=>$channel ) {
$options .= '<option class="lbry-meta-bx-option lbry-meta-option-channel" value="' . esc_attr( $channel->claim_id ) . '"';
if ( ( $cur_channel ) ? $cur_channel : $cur_channel = $default_channel ) {
$options .= selected( $cur_channel, $channel->claim_id, false );
}
$options .= '>' . esc_html__( $channel->name, 'lbrypress' ) . '</option>';
}
printf(
'<select id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '">' . esc_html('%2$s') . '</select>',
'_lbry_post_pub_channel',
$options
);
} ?>
<div><label for="_lbry_post_pub_license" class="lbry-meta-bx-label lbry-meta-bx-license"><?php esc_html_e( 'Publish License: ', 'lbrypress' ); ?></label></div><?php
$licenses = LBRY()->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 .= '<option class="lbry-meta-bx-option lbry-meta-bx-option-last lbry-meta-option-license" value="' . esc_attr( $value ) . '"';
if ( ( $cur_license ) ? $cur_license : $cur_license = $default_license ) {
$options .= selected( $cur_license, $value, false );
}
$options .= '>'. esc_html__( $name, 'lbrypress' ) . '</option>';
}
}
printf(
'<select class="" id="'.esc_attr('%1$s').'" name="'. esc_attr('%1$s') .'">' . esc_html('%2$s') . '</select>',
'_lbry_post_pub_license',
$options
);
?>
</section>

View file

@ -1,4 +1,6 @@
<?php <?php
defined('ABSPATH') || die(); // Exit if accessed directly
$unnatributed = (object) array( $unnatributed = (object) array(
'name' => 'none (anonymous)', 'name' => 'none (anonymous)',
'claim_id' => 'null' 'claim_id' => 'null'

View file

@ -0,0 +1,48 @@
<?php
/**
* The Options Page with tabs
* @package LBRYPress
*/
defined('ABSPATH') || die(); // Exit if accessed directly
$LBRY = LBRY();
$wallet_balance = $LBRY->daemon->wallet_balance();
$available_balance = $wallet_balance->result->available;
$total_balance = $wallet_balance->result->total;
$lbry_active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general';
?>
<div class="wrap">
<h1><?php esc_html_e( get_admin_page_title(), 'lbrypress' ); ?></h1>
<h2 title="<?php echo esc_attr( number_format( $total_balance, 3, '.', ',' ) ); ?> Wallet Total Balance"><img src="<?php echo esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png' ) ?>" class="icon icon-lbc wallet-icon-lbc"><code><?php esc_html_e( number_format( $available_balance, 3, '.', ',' ) ); ?></code> Wallet Available Balance</h2>
<nav class="nav-tab-wrapper">
<a href="<?php echo esc_url( admin_url( 'options.php?page=lbrypress&tab=general' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'general' || '' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Settings' ); ?></a>
<a href="<?php echo esc_url( admin_url( 'admin.php?page=lbrypress&tab=channels' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'channels' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Channels' ); ?></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>
<?php if ( $lbry_active_tab == 'channels' ) {
include_once( 'partials/channel-page.php' );
} else {
?>
<form class="form-table" action="<?php echo esc_url( admin_url( 'options.php' ) ); ?>" method="post">
<?php
}
if ( $lbry_active_tab == 'general' ) {
settings_fields( 'lbry_general_settings' );
do_settings_sections( LBRY_ADMIN_PAGE );
submit_button();
} elseif ( $lbry_active_tab == 'channels' ) {
include_once( 'partials/channel-page.php' );
} elseif ( $lbry_active_tab == 'speech' ) {
settings_fields( LBRY_SPEECH_SETTINGS );
do_settings_sections( 'lbrypress-speech' );
submit_button();
} else {
settings_fields( 'lbry_general_settings' );
do_settings_sections( LBRY_ADMIN_PAGE );
submit_button();
}
?>
</form>
</div><!-- wrap -->

View file

@ -1,52 +0,0 @@
<?php
$LBRY = LBRY();
$wallet_balance = $LBRY->daemon->wallet_balance();
$available_balance = $wallet_balance->result->available;
$channel_list = $LBRY->daemon->channel_list();
// TODO: Make this page look cleaner
?>
<div class="wrap">
<h1><?= esc_html(get_admin_page_title()); ?></h1>
<h2>Your wallet amount:</h2>
<img src="<?php echo esc_url( plugin_dir_url(LBRY_PLUGIN_FILE) . 'admin/images/lbc.png') ?>" class="icon icon-lbc wallet-icon-lbc" style="height: 1.8em; margin-right: .5em; margin-bottom: -.5em;"><code><?= number_format($available_balance, 2, '.', ','); ?></code>
<form action="options.php" method="post">
<?php
settings_fields(LBRY_SETTINGS_GROUP);
do_settings_sections(LBRY_ADMIN_PAGE);
submit_button('Save Settings');
?>
</form>
<h2>Your Publishable Channels</h2>
<?php if ($channel_list): ?>
<ul class="lbry-channel-list">
<?php foreach ($channel_list as $channel): ?>
<li><?= $channel->name ?></li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p>Looks like you haven't added any channels yet, feel free to do so below:</p>
<?php endif; ?>
<h2>Add a new channel to publish to:</h2>
<form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post">
<?php wp_nonce_field('lbry_add_channel', '_lbrynonce'); ?>
<input type="hidden" name="action" value="lbry_add_channel">
<table class="form-table">
<tbody>
<tr>
<th scope="row">New Channel Name</th>
<td>
<span>@</span>
<input type="text" name="new_channel" value="" placeholder="your-new-channel" required>
</td>
</tr>
<tr>
<th scope="row">Amount of LBC to Bid</th>
<td>
<input type="number" step="0.1" min="0.1" name="bid_amount" value="10" required>
</td>
</tr>
</tbody>
</table>
<?php submit_button('Add New Channel'); ?>
</form>
</div>

View 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
}

View file

@ -0,0 +1,2 @@
<?php
// Silence is golden

View file

@ -1,4 +1,6 @@
<?php <?php
defined('ABSPATH') || die(); // Exit if accessed directly
$url = get_post_meta(get_the_id(), LBRY_CANONICAL_URL, true); $url = get_post_meta(get_the_id(), LBRY_CANONICAL_URL, true);
if (!$url) { if (!$url) {
// Get channel canonical for backwards compatibility // Get channel canonical for backwards compatibility

View file

@ -1,3 +1,6 @@
<?php
defined('ABSPATH') || die(); // Exit if accessed directly
?>
<div class="error"> <div class="error">
<p><?php echo LBRY_NAME; ?> error: Your environment doesn't meet all of the system requirements listed below.</p> <p><?php echo LBRY_NAME; ?> error: Your environment doesn't meet all of the system requirements listed below.</p>

2
tests/index.php Normal file
View file

@ -0,0 +1,2 @@
<?php
// Silence is golden

View file

@ -4,6 +4,7 @@
* *
* @package LBRYPress * @package LBRYPress
*/ */
defined('ABSPATH') || die(); // Exit if accessed directly
// if uninstall.php is not called by WordPress, die // if uninstall.php is not called by WordPress, die
defined('WP_UNINSTALL_PLUGIN') || die(); defined('WP_UNINSTALL_PLUGIN') || die();

2
vendor/index.php vendored Normal file
View file

@ -0,0 +1,2 @@
<?php
// Silence is golden