Claim search method #64
2
.gitignore
vendored
|
@ -4,6 +4,8 @@
|
|||
!*.*
|
||||
|
||||
.DS_Store
|
||||
extensions.json
|
||||
.vscode/*
|
||||
|
||||
tmp/*
|
||||
logs/*
|
||||
|
|
27
README.md
|
@ -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.
|
||||
|
||||
## 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:
|
||||
![](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) 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.**
|
||||
|
||||
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**.
|
||||
|
||||
![](https://spee.ch/8/speech-setup-lbrypress.jpeg)
|
||||
![](/admin/images/settings-tab.jpg)
|
||||
|
||||
## Setting up a 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.
|
||||
## 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 on the **Channels** tab.
|
||||
|
||||
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**.
|
||||
|
||||
![](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
|
||||
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
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
47
admin/css/lbry-admin.css
Normal 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;
|
||||
}
|
BIN
admin/images/add-channel.jpg
Normal file
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
BIN
admin/images/channel-create-success.jpg
Normal file
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
2
admin/images/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
BIN
admin/images/lbry-icon.png
Normal file
Before Width: | Height: | Size: 654 B After Width: | Height: | Size: 654 B |
BIN
admin/images/lbry.png
Normal file
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
BIN
admin/images/new-channel.jpg
Normal file
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
BIN
admin/images/settings-tab.jpg
Normal file
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
BIN
admin/images/speech-tab.jpg
Normal file
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
BIN
admin/images/wallet-address.jpg
Normal file
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
2
admin/js/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
2
bin/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRYPress
|
||||
{
|
||||
|
@ -64,7 +65,7 @@ class LBRYPress
|
|||
*/
|
||||
public static function instance()
|
||||
{
|
||||
if (is_null(self::$_instance)) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self();
|
||||
}
|
||||
return self::$_instance;
|
||||
|
@ -77,7 +78,7 @@ class LBRYPress
|
|||
public function __construct()
|
||||
{
|
||||
$this->define_constants();
|
||||
spl_autoload_register(array($this, 'lbry_autoload_register'));
|
||||
spl_autoload_register( array( $this, 'lbry_autoload_register' ) );
|
||||
$this->init();
|
||||
$this->init_hooks();
|
||||
}
|
||||
|
@ -88,10 +89,10 @@ class LBRYPress
|
|||
* @param string $name Constant name.
|
||||
* @param string|bool $value Constant value.
|
||||
*/
|
||||
private function define($name, $value)
|
||||
private function define( $name, $value )
|
||||
{
|
||||
if (! defined($name)) {
|
||||
define($name, $value);
|
||||
if ( ! defined( $name ) ) {
|
||||
define( $name, $value );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,18 +108,20 @@ class LBRYPress
|
|||
$this->define('LBRY_VERSION', $this->version);
|
||||
|
||||
// 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_SECTION_GENERAL', 'lbry_settings_section_general');
|
||||
$this->define('LBRY_ADMIN_PAGE', 'lbrypress');
|
||||
$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_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_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_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_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
|
||||
|
@ -127,11 +130,11 @@ class LBRYPress
|
|||
/**
|
||||
* Autoloader Registration
|
||||
*/
|
||||
private function lbry_autoload_register($class)
|
||||
private function lbry_autoload_register( $class )
|
||||
{
|
||||
$file_name = LBRY_ABSPATH . 'classes/' . $class . '.php';
|
||||
|
||||
if (file_exists($file_name)) {
|
||||
if ( file_exists( $file_name ) ) {
|
||||
require $file_name;
|
||||
return;
|
||||
}
|
||||
|
@ -146,7 +149,7 @@ class LBRYPress
|
|||
$this->speech = new LBRY_Speech();
|
||||
|
||||
// Admin request
|
||||
if (is_admin()) {
|
||||
if ( is_admin() ) {
|
||||
$this->admin = new LBRY_Admin();
|
||||
$this->notice = new LBRY_Admin_Notice();
|
||||
$this->network = new LBRY_Network();
|
||||
|
@ -158,15 +161,15 @@ class LBRYPress
|
|||
*/
|
||||
private function init_hooks()
|
||||
{
|
||||
register_activation_hook(LBRY_PLUGIN_FILE, array($this, 'activate'));
|
||||
register_deactivation_hook(LBRY_PLUGIN_FILE, array($this, 'deactivate'));
|
||||
register_activation_hook( LBRY_PLUGIN_FILE, array( $this, 'activate' ) );
|
||||
register_deactivation_hook( LBRY_PLUGIN_FILE, array( $this, 'deactivate' ) );
|
||||
|
||||
// Banner output for published posts
|
||||
// NOTE: move this to its own class to reduce clutter?
|
||||
add_action('the_content', array($this, 'published_on_lbry_banner'), 12, 1);
|
||||
add_action( 'the_content', array( $this, 'published_on_lbry_banner' ), 12, 1 );
|
||||
|
||||
add_action('wp_enqueue_scripts', function () {
|
||||
wp_enqueue_style('lbry-css', plugins_url('/frontend/lbry.css', LBRY_PLUGIN_FILE));
|
||||
add_action( 'wp_enqueue_scripts', function () {
|
||||
wp_enqueue_style( 'lbry-css', plugins_url( '/frontend/lbry.css', LBRY_PLUGIN_FILE ) );
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -178,16 +181,28 @@ class LBRYPress
|
|||
// TODO: Make sure errors are thrown if daemon can't be contacted, stop activation
|
||||
|
||||
// Add options to the options table we need
|
||||
if (! get_option(LBRY_SETTINGS)) {
|
||||
if (! get_option( LBRY_SETTINGS ) ) {
|
||||
|
||||
// Default options
|
||||
//Default options
|
||||
$option_defaults = array(
|
||||
LBRY_SPEECH => null,
|
||||
LBRY_LICENSE => $this->licenses[0],
|
||||
LBRY_LBC_PUBLISH => 1
|
||||
LBRY_WALLET => '',
|
||||
'lbry_default_publish_setting' => '',
|
||||
'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.
|
||||
|
@ -208,26 +223,26 @@ class LBRYPress
|
|||
public function deactivate()
|
||||
{
|
||||
// TODO: Stop the daemon
|
||||
error_log('Deactivated LBRYPress');
|
||||
error_log( 'Deactivated LBRYPress' );
|
||||
}
|
||||
|
||||
public function published_on_lbry_banner($content)
|
||||
{
|
||||
if (!is_single() || !in_the_loop() || !is_main_query()) {
|
||||
if ( ! is_single() || ! in_the_loop() || ! is_main_query() ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
global $post;
|
||||
if ($post->post_type != 'post') {
|
||||
if ( $post->post_type != 'post' ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
if (!get_post_meta($post->ID, LBRY_WILL_PUBLISH, true)) {
|
||||
if ( ! get_post_meta( $post->ID, LBRY_WILL_PUBLISH, true ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
require(LBRY_ABSPATH . 'templates/published_on_lbry_banner.php');
|
||||
require( LBRY_ABSPATH . 'templates/published_on_lbry_banner.php' );
|
||||
$banner = ob_get_clean();
|
||||
|
||||
return $content .= $banner;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Admin
|
||||
{
|
||||
|
@ -25,14 +26,56 @@ class LBRY_Admin
|
|||
*/
|
||||
public function create_options_page()
|
||||
{
|
||||
add_menu_page(
|
||||
__('LBRYPress Settings', 'lbrypress'),
|
||||
__('LBRYPress', 'lbrypress'),
|
||||
'manage_options',
|
||||
LBRY_ADMIN_PAGE,
|
||||
array($this, 'options_page_html'),
|
||||
plugin_dir_url(LBRY_PLUGIN_FILE) . '/admin/images/lbry-logo.svg'
|
||||
);
|
||||
|
||||
$hook_suffix = add_menu_page(
|
||||
__( 'LBRYPress Settings', 'lbrypress' ),
|
||||
__( 'LBRYPress', 'lbrypress' ),
|
||||
'manage_options',
|
||||
LBRY_ADMIN_PAGE,
|
||||
array( $this, 'options_page_html' ),
|
||||
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()
|
||||
{
|
||||
// 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_settings_section(
|
||||
LBRY_SETTINGS_SECTION_GENERAL, // ID
|
||||
'General Settings', // Title
|
||||
array( $this, 'general_section_info' ), // Callback
|
||||
array( $this, 'general_section_callback' ), // Callback
|
||||
LBRY_ADMIN_PAGE // Page
|
||||
);
|
||||
|
||||
|
@ -59,35 +106,43 @@ class LBRY_Admin
|
|||
LBRY_ADMIN_PAGE,
|
||||
LBRY_SETTINGS_SECTION_GENERAL
|
||||
);
|
||||
|
||||
// remove from commit:
|
||||
add_settings_field(
|
||||
LBRY_SPEECH,
|
||||
'Spee.ch URL',
|
||||
array( $this, 'speech_callback' ),
|
||||
'lbry_default_publish_setting',
|
||||
'Always Publish to LBRY',
|
||||
array( $this, 'lbry_always_pub_callback' ),
|
||||
LBRY_ADMIN_PAGE,
|
||||
LBRY_SETTINGS_SECTION_GENERAL
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_SPEECH_CHANNEL,
|
||||
'Spee.ch Channel',
|
||||
array( $this, 'speech_channel_callback' ),
|
||||
'lbry_default_publish_setting',
|
||||
'Always Publish to LBRY',
|
||||
array( $this, 'lbry_always_pub_callback' ),
|
||||
LBRY_ADMIN_PAGE,
|
||||
LBRY_SETTINGS_SECTION_GENERAL
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_SPEECH_PW,
|
||||
'Spee.ch Password',
|
||||
array( $this, 'speech_pw_callback' ),
|
||||
'default_lbry_channel',
|
||||
'Default Publish Channel',
|
||||
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_SETTINGS_SECTION_GENERAL
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
LBRY_LICENSE,
|
||||
'LBRY Publishing License',
|
||||
array( $this, 'license_callback' ),
|
||||
'lbry_default_publish_setting',
|
||||
'Always Publish to LBRY',
|
||||
array( $this, 'lbry_always_pub_callback' ),
|
||||
LBRY_ADMIN_PAGE,
|
||||
LBRY_SETTINGS_SECTION_GENERAL
|
||||
);
|
||||
|
@ -95,55 +150,147 @@ class LBRY_Admin
|
|||
add_settings_field(
|
||||
LBRY_LBC_PUBLISH,
|
||||
'LBC Per Publish',
|
||||
array( $this, 'lbc_publish_callback' ),
|
||||
array( $this, 'lbc_per_publish_callback' ),
|
||||
LBRY_ADMIN_PAGE,
|
||||
LBRY_SETTINGS_SECTION_GENERAL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Options Page HTML for the plugin
|
||||
*/
|
||||
public function options_page_html()
|
||||
{
|
||||
// Set class property to be referenced in callbacks
|
||||
$this->options = get_option(LBRY_SETTINGS);
|
||||
require_once(LBRY_ABSPATH . 'templates/options_page.php');
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
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
|
||||
* // 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 = str_replace('@', '', $channel);
|
||||
$input[LBRY_SPEECH_CHANNEL] = $channel;
|
||||
$channel = str_replace( '@', '', $channel );
|
||||
$new_input[LBRY_SPEECH_CHANNEL] = sanitize_user( $channel );
|
||||
}
|
||||
|
||||
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_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 $input;
|
||||
return $new_input;
|
||||
update_option( LBRY_SPEECH_SETTINGS, $new_input );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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:';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -151,52 +298,63 @@ class LBRY_Admin
|
|||
{
|
||||
// Get first available account address from Daemon
|
||||
$address = LBRY()->daemon->address_list();
|
||||
$address = is_array($address) && !empty($address) ? $address[0]->address : '';
|
||||
$address = is_array( $address ) && ! empty( $address ) ? $address[0]->address : '';
|
||||
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_SETTINGS,
|
||||
$address
|
||||
);
|
||||
}
|
||||
|
||||
// remove from commit:
|
||||
/**
|
||||
* Prints Spee.ch input
|
||||
*/
|
||||
public function speech_callback()
|
||||
* 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(
|
||||
'<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]) : ''
|
||||
'<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_default_publish_setting',
|
||||
LBRY_SETTINGS,
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prints Spee.ch channel input
|
||||
*/
|
||||
public function speech_channel_callback()
|
||||
* Prints select to choose a default to publish to channel
|
||||
*/
|
||||
public function default_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]) : ''
|
||||
);
|
||||
}
|
||||
$options = '';
|
||||
$channel_list = LBRY()->daemon->channel_list();
|
||||
|
||||
/**
|
||||
* 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
|
||||
);
|
||||
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(
|
||||
'<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
|
||||
|
@ -207,64 +365,126 @@ class LBRY_Admin
|
|||
$options = '';
|
||||
// Create options list, select current license
|
||||
//
|
||||
foreach (LBRY()->licenses as $value => $name) {
|
||||
foreach ( LBRY()->licenses as $value => $name ) {
|
||||
$selected = $this->options[LBRY_LICENSE] === $value;
|
||||
|
||||
$options .= '<option value="' . $value . '"';
|
||||
if ($selected) {
|
||||
if ( $selected ) {
|
||||
$options .= ' selected';
|
||||
}
|
||||
$options .= '>'. $name . '</option>';
|
||||
}
|
||||
|
||||
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_SETTINGS,
|
||||
$options
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prints LBC per publish input
|
||||
*/
|
||||
public function lbc_publish_callback()
|
||||
public function lbc_per_publish_callback()
|
||||
{
|
||||
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_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
|
||||
*/
|
||||
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
|
||||
if (! isset($_POST['_lbrynonce']) || ! wp_verify_nonce($_POST['_lbrynonce'], 'lbry_add_channel')) {
|
||||
LBRY()->notice->set_notice('error');
|
||||
} elseif (! isset($_POST['new_channel']) || ! isset($_POST['bid_amount'])) {
|
||||
LBRY()->notice->set_notice('error', 'Must supply both channel name and bid amount');
|
||||
} else {
|
||||
$new_channel = $_POST['new_channel'];
|
||||
$bid_amount = $_POST['bid_amount'];
|
||||
if ( isset( $_POST['_lbrynonce'] ) && wp_verify_nonce( $_POST['_lbrynonce'], 'add_channel_nonce' ) ) {
|
||||
if ( empty( $_POST['lbry_new_channel'] ) || empty( $_POST['lbry_channel_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'] ) ) {
|
||||
$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?
|
||||
$channel = trim( $channel );
|
||||
$channel = str_replace( '@', '', $channel );
|
||||
$channel = str_replace( ' ', '-', $channel );
|
||||
$channel = str_replace( '_', '-', $channel );
|
||||
$channel_name = sanitize_user( $channel );
|
||||
|
||||
// Try to add the new channel
|
||||
try {
|
||||
$result = LBRY()->daemon->channel_new($new_channel, $bid_amount);
|
||||
// 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);
|
||||
} catch (\Exception $e) {
|
||||
LBRY()->notice->set_notice('error', $e->getMessage(), false);
|
||||
$bid = $_POST['lbry_channel_bid_amount'];
|
||||
$channel_bid = number_format( floatval( $bid ), 3, '.', '' );
|
||||
|
||||
// Try to add the new channel
|
||||
try {
|
||||
$result = LBRY()->daemon->channel_new( $channel_name, $channel_bid );
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
@ -282,7 +502,7 @@ class LBRY_Admin
|
|||
if (!get_transient('lbry_wallet_warning_email')) {
|
||||
$email = get_option('admin_email');
|
||||
$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);
|
||||
set_transient('lbry_wallet_warning_email', true, DAY_IN_SECONDS);
|
||||
}
|
||||
|
|
|
@ -4,12 +4,13 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Admin_Notice
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
add_action('admin_notices', array($this, 'admin_notices'));
|
||||
|
||||
public function __construct() {
|
||||
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,12 +18,12 @@ class LBRY_Admin_Notice
|
|||
*/
|
||||
public function admin_notices()
|
||||
{
|
||||
if (get_transient('lbry_notices')) {
|
||||
$notices = get_transient('lbry_notices');
|
||||
foreach ($notices as $key => $notice) {
|
||||
$this->create_admin_notice($notice);
|
||||
if ( get_transient( 'lbry_notices' ) ) {
|
||||
$notices = get_transient( 'lbry_notices' );
|
||||
foreach ( $notices as $key => $notice ) {
|
||||
$this->create_admin_notice( $notice );
|
||||
}
|
||||
delete_transient('lbry_notices');
|
||||
delete_transient( 'lbry_notices' );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +31,7 @@ class LBRY_Admin_Notice
|
|||
* Sets transients for admin errors
|
||||
*/
|
||||
// TODO: Make sure we only set one transient at a time per error
|
||||
public function set_notice($status = 'error', $message = 'Something went wrong', $is_dismissible = false)
|
||||
public function set_notice( $status = 'error', $message = 'Something went wrong', $is_dismissible = false )
|
||||
{
|
||||
$notice = array(
|
||||
'status' => $status,
|
||||
|
@ -38,24 +39,24 @@ class LBRY_Admin_Notice
|
|||
'is_dismissible' => $is_dismissible
|
||||
);
|
||||
|
||||
if (! get_transient('lbry_notices')) {
|
||||
set_transient('lbry_notices', array($notice));
|
||||
if (! get_transient( 'lbry_notices' ) ) {
|
||||
set_transient( 'lbry_notices', array( $notice ) );
|
||||
} else {
|
||||
$notices = get_transient('lbry_notices');
|
||||
$notices = get_transient( 'lbry_notices' );
|
||||
$notices[] = $notice;
|
||||
set_transient('lbry_notices', $notices);
|
||||
set_transient( 'lbry_notices', $notices );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints an admin notice
|
||||
*/
|
||||
private function create_admin_notice($notice)
|
||||
private function create_admin_notice( $notice )
|
||||
{
|
||||
$class = 'notice notice-' . $notice['status'];
|
||||
if ($notice['is_dismissible']) {
|
||||
if ( $notice['is_dismissible'] ) {
|
||||
$class .= ' is-dismissible';
|
||||
}
|
||||
printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), esc_html($notice['message']));
|
||||
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $notice['message'] ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Daemon
|
||||
{
|
||||
|
@ -32,14 +33,13 @@ class LBRY_Daemon
|
|||
* https://lbry.tech/api/sdk#address_unused
|
||||
* @return string Unused wallet address in base58
|
||||
*/
|
||||
public function wallet_unused_address()
|
||||
{
|
||||
public function wallet_unused_address() {
|
||||
try {
|
||||
$result = $this->request('address_unused');
|
||||
$result = $this->request( 'address_unused' );
|
||||
return $result->result;
|
||||
} catch (LBRYDaemonException $e) {
|
||||
$this->logger->log('address_unused error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||
LBRY()->notice->set_notice('error', 'Issue getting unused address.');
|
||||
} catch ( LBRYDaemonException $e ) {
|
||||
$this->logger->log( 'address_unused error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||
LBRY()->notice->set_notice( 'error', 'Issue getting unused address.' );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -50,19 +50,18 @@ class LBRY_Daemon
|
|||
* @param int $page Pagination page number
|
||||
* @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
|
||||
$params = array(
|
||||
'page' => $page,
|
||||
'page_size' => 20
|
||||
);
|
||||
try {
|
||||
$result = $this->request('address_list', $params);
|
||||
$result = $this->request( 'address_list', $params );
|
||||
return $result->result->items;
|
||||
} catch (LBRYDaemonException $e) {
|
||||
$this->logger->log('address_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||
LBRY()->notice->set_notice('error', 'Issue getting address list.');
|
||||
} catch ( LBRYDaemonException $e ) {
|
||||
$this->logger->log( 'address_list error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||
LBRY()->notice->set_notice( 'error', 'Issue getting address list.' );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -71,13 +70,14 @@ class LBRY_Daemon
|
|||
* Returns the available balance of a current LBRY account
|
||||
* https://lbry.tech/api/sdk#wallet_balance
|
||||
* @param string $address Wallet Address
|
||||
* @return array $wallet_balance Wallet Balance
|
||||
* @return object $wallet_balance Wallet Balance
|
||||
*
|
||||
*/
|
||||
public function wallet_balance()
|
||||
{
|
||||
|
||||
try { // Convert JSON string to an object
|
||||
$result = $this->request('wallet_balance');
|
||||
$result = $this->request( 'wallet_balance', array() );
|
||||
return $result;
|
||||
} catch (LBRYDaemonException $e) {
|
||||
$this->logger->log('wallet_balance error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||
|
@ -92,7 +92,7 @@ class LBRY_Daemon
|
|||
* @param int $page Pagination page number
|
||||
* @return array claim dictionary or null if empty
|
||||
*/
|
||||
public function channel_list($page = 1)
|
||||
public function channel_list( $page = 1 )
|
||||
{
|
||||
$params = array(
|
||||
'page' => $page,
|
||||
|
@ -100,11 +100,11 @@ class LBRY_Daemon
|
|||
);
|
||||
|
||||
try {
|
||||
$result = $this->request('channel_list', $params)->result->items;
|
||||
return empty($result) ? null : $result;
|
||||
} catch (LBRYDaemonException $e) {
|
||||
$this->logger->log('channel_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||
LBRY()->notice->set_notice('error', 'Issue retrieving channel list.');
|
||||
$result = $this->request( 'channel_list', $params )->result->items;
|
||||
return empty( $result ) ? null : $result;
|
||||
} catch ( LBRYDaemonException $e ) {
|
||||
$this->logger->log( 'channel_list error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||
LBRY()->notice->set_notice( 'error', 'Issue retrieving channel list.' );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -114,19 +114,20 @@ class LBRY_Daemon
|
|||
* https://lbry.tech/api/sdk#channel_create
|
||||
* @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
|
||||
// Make sure no @ sign, as we will add that
|
||||
if (strpos($channel_name, '@')) {
|
||||
throw new \Exception('Illegal character "@" in channel name', 1);
|
||||
if ( strpos( $channel_name, '@' ) ) {
|
||||
throw new \Exception( 'Illegal character "@" in channel name', 1 );
|
||||
}
|
||||
|
||||
|
||||
// No white space allowed
|
||||
if (strpos($channel_name, ' ')) {
|
||||
throw new \Exception("No spaces allowed in channel name", 1);
|
||||
if ( strpos( $channel_name, ' ' ) ) {
|
||||
throw new \Exception( "No spaces allowed in channel name", 1 );
|
||||
}
|
||||
|
||||
|
||||
$channel_name = '@' . $channel_name;
|
||||
|
||||
try {
|
||||
|
@ -134,13 +135,16 @@ class LBRY_Daemon
|
|||
'channel_create',
|
||||
array(
|
||||
'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;
|
||||
|
||||
} catch (LBRYDaemonException $e) {
|
||||
$this->logger->log('channel_new error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||
throw new \Exception('Issue creating new channel.', 1);
|
||||
$this->logger->log( 'channel_new error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||
throw new \Exception( 'Issue creating new channel.', 1 );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -150,9 +154,9 @@ class LBRY_Daemon
|
|||
* @param string $claim_id
|
||||
* @return string Canonical URL, null if not found
|
||||
*/
|
||||
public function canonical_url($claim_id = null)
|
||||
public function canonical_url( $claim_id = null )
|
||||
{
|
||||
if (!$claim_id) {
|
||||
if ( ! $claim_id ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -166,13 +170,13 @@ class LBRY_Daemon
|
|||
);
|
||||
|
||||
$items = $result->result->items;
|
||||
if (!$items) {
|
||||
if ( ! $items ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $items[0]->canonical_url;
|
||||
} catch (LBRYDaemonException $e) {
|
||||
$this->logger->log('canonical_url error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||
} catch ( LBRYDaemonException $e ) {
|
||||
$this->logger->log( 'canonical_url error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -187,18 +191,18 @@ class LBRY_Daemon
|
|||
*
|
||||
* @return object $result
|
||||
*/
|
||||
public function publish($args)
|
||||
public function publish( $args )
|
||||
{
|
||||
try {
|
||||
$result = $this->request(
|
||||
'publish',
|
||||
$args
|
||||
);
|
||||
$this->logger->log('publish success!', 'Successfully published post with result: ' . print_r($result->result, true));
|
||||
$this->logger->log( 'publish success!', 'Successfully published post with result: ' . print_r( $result->result, true ) );
|
||||
return $result->result;
|
||||
} catch (LBRYDaemonException $e) {
|
||||
$this->logger->log('publish error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||
LBRY()->notice->set_notice('error', 'Issue publishing / updating post to LBRY Network.');
|
||||
} catch ( LBRYDaemonException $e ) {
|
||||
$this->logger->log('publish error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||
LBRY()->notice->set_notice( 'error', 'Issue publishing / updating post to LBRY Network.' );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -209,52 +213,52 @@ class LBRY_Daemon
|
|||
* @param array $params The Parameters to send the LBRY API Call
|
||||
* @return string The cURL response
|
||||
*/
|
||||
private function request($method, $params = array())
|
||||
private function request( $method, $params = array() )
|
||||
{
|
||||
// JSONify our request data
|
||||
$data = array(
|
||||
'method' => $method,
|
||||
'params' => $params
|
||||
);
|
||||
$data = json_encode($data);
|
||||
$data = json_encode( $data );
|
||||
|
||||
// Send it via curl
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $this->address);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
||||
curl_setopt($ch, CURLOPT_AUTOREFERER, false);
|
||||
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt( $ch, CURLOPT_URL, $this->address );
|
||||
curl_setopt( $ch, CURLOPT_POST, true );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' ) );
|
||||
curl_setopt( $ch, CURLOPT_AUTOREFERER, false );
|
||||
curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
|
||||
curl_setopt( $ch, CURLOPT_HEADER, 0 );
|
||||
|
||||
$result = curl_exec($ch);
|
||||
$response_code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
|
||||
curl_close($ch);
|
||||
$result = curl_exec( $ch );
|
||||
$response_code = curl_getinfo( $ch, CURLINFO_RESPONSE_CODE );
|
||||
curl_close( $ch );
|
||||
|
||||
if ($response_code != '200') {
|
||||
$this->logger->log("Damon Connection Issue", "Daemon connection returned response code $response_code");
|
||||
throw new LBRYDaemonException("Daemon Connection Issue", $response_code);
|
||||
if ( $response_code != '200' ) {
|
||||
$this->logger->log( "Damon Connection Issue", "Daemon connection returned response code $response_code" );
|
||||
throw new LBRYDaemonException( "Daemon Connection Issue", $response_code );
|
||||
}
|
||||
|
||||
|
||||
$result = json_decode($result);
|
||||
$this->check_for_errors($result);
|
||||
$result = json_decode( $result );
|
||||
$this->check_for_errors( $result );
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
private function check_for_errors($response)
|
||||
private function check_for_errors( $response )
|
||||
{
|
||||
if (property_exists($response, 'error')) {
|
||||
if ( property_exists( $response, 'error' ) ) {
|
||||
$message = $response->error->message;
|
||||
$code = $response->error->code;
|
||||
$this->logger->log("Daemon error code $code", $message);
|
||||
throw new LBRYDaemonException($message, $code);
|
||||
$this->logger->log( "Daemon error code $code", $message );
|
||||
throw new LBRYDaemonException( $message, $code );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,11 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Daemon_Logger
|
||||
{
|
||||
|
||||
/**
|
||||
* The directory to log to
|
||||
* @var string
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Network
|
||||
{
|
||||
|
@ -34,21 +35,25 @@ 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);
|
||||
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
|
||||
*/
|
||||
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
|
||||
|
@ -62,49 +67,90 @@ class LBRY_Network
|
|||
* @param WP_Post $post The Post Object we are saving
|
||||
* @return int Returns post_id if user cannot edit post
|
||||
*/
|
||||
public function save_post_meta($post_id, $post)
|
||||
public function save_post_meta( $post_id, $post )
|
||||
{
|
||||
if ($post->post_type != 'post') {
|
||||
return;
|
||||
if ( $post->post_type != 'post' ) {
|
||||
return $post_id;
|
||||
}
|
||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
// Verify the nonce before proceeding.
|
||||
if (!isset($_POST['_lbrynonce']) || !wp_verify_nonce($_POST['_lbrynonce'], 'lbry_publish_channels')) {
|
||||
if ( ! isset( $_POST['_lbrynonce'] ) || ! wp_verify_nonce( $_POST['_lbrynonce'], 'lbry_publish_post_nonce' ) ) {
|
||||
//LBRY()->notice->set_notice('error', 'Security check failed' );
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
// Check if the current user has permission to edit the post.
|
||||
$post_type = get_post_type_object($post->post_type);
|
||||
if (!current_user_can($post_type->cap->edit_post, $post_id)) {
|
||||
$post_type = get_post_type_object( $post->post_type );
|
||||
if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
$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);
|
||||
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 );
|
||||
}
|
||||
|
||||
$channel = $_POST[LBRY_POST_CHANNEL];
|
||||
$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 ) );
|
||||
$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
|
||||
if (!$will_publish) {
|
||||
update_post_meta($post_id, LBRY_WILL_PUBLISH, 'false');
|
||||
} else {
|
||||
update_post_meta($post_id, LBRY_WILL_PUBLISH, 'true');
|
||||
|
||||
if ( $channel !== $cur_channel ) {
|
||||
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
|
||||
} 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 ($new_channel !== $cur_channel) {
|
||||
update_post_meta($post_id, LBRY_POST_CHANNEL, $new_channel);
|
||||
}
|
||||
|
||||
if ($will_publish && $post->post_status == 'publish') {
|
||||
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, get_post_meta($post_id, LBRY_POST_CHANNEL, true));
|
||||
$this->publisher->publish( $post, $channel, $license );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a checkbox that changes the default setting to always publish to LBRY,
|
||||
* 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 )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML for the LBRY Meta Box
|
||||
* @param WP_POST $post
|
||||
*/
|
||||
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' );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ use League\HTMLToMarkdown\HtmlConverter;
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
|
||||
class LBRY_Network_Parser
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Network_Publisher
|
||||
{
|
||||
|
@ -13,48 +14,49 @@ class LBRY_Network_Publisher
|
|||
* @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
|
||||
public function publish($post, $channel = null)
|
||||
{
|
||||
public function publish( $post, $channel, $license ) {
|
||||
|
||||
$post_id = $post->ID;
|
||||
// Get converted markdown into a file
|
||||
$filepath = LBRY_ABSPATH . 'tmp/' . $post->post_name . time() . '.md';
|
||||
$file = fopen($filepath, 'w');
|
||||
$converted = LBRY()->network->parser->convert_to_markdown($post);
|
||||
$write_status = $file && fwrite($file, $converted);
|
||||
fclose($file);
|
||||
$file = fopen( $filepath, 'w' );
|
||||
$converted = LBRY()->network->parser->convert_to_markdown( $post );
|
||||
$write_status = $file && fwrite( $file, $converted );
|
||||
fclose( $file );
|
||||
|
||||
try {
|
||||
if (!$write_status) {
|
||||
throw new \Exception('Write Status failure', 1);
|
||||
throw new \Exception( 'Write Status failure', 1 );
|
||||
}
|
||||
|
||||
// If everything went well with the conversion, carry on
|
||||
$args = array(
|
||||
'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,
|
||||
'title' => $post->post_title,
|
||||
'languages' => array(substr(get_locale(), 0, 2)),
|
||||
'license' => get_option(LBRY_SETTINGS)[LBRY_LICENSE]
|
||||
'languages' => array( substr( get_locale(), 0, 2 ) ),
|
||||
'license' => $license,
|
||||
);
|
||||
|
||||
// Setup channel
|
||||
if ($channel && $channel != 'null') {
|
||||
if ( $channel && $channel != 'null' ) {
|
||||
$args['channel_id'] = $channel;
|
||||
}
|
||||
|
||||
// Setup featured image
|
||||
$featured_id = get_post_thumbnail_id($post);
|
||||
$featured_image = wp_get_attachment_image_src($featured_id, 'medium');
|
||||
$featured_id = get_post_thumbnail_id( $post );
|
||||
$featured_image = wp_get_attachment_image_src( $featured_id, 'medium' );
|
||||
|
||||
if ($featured_image[0]) {
|
||||
if ( $featured_image[0] ) {
|
||||
$args['thumbnail_url'] = $featured_image[0];
|
||||
}
|
||||
|
||||
// Setup Tags
|
||||
$tags = get_the_terms( $post, 'post_tag' );
|
||||
if ($tags) {
|
||||
if ( $tags ) {
|
||||
$tag_names = [];
|
||||
foreach ($tags as $tag) {
|
||||
foreach ( $tags as $tag ) {
|
||||
$tag_names[] = $tag->name;
|
||||
}
|
||||
$args['tags'] = $tag_names;
|
||||
|
@ -62,35 +64,35 @@ class LBRY_Network_Publisher
|
|||
|
||||
// Build description using Yoast if installed and its used, excerpt/title otherwise
|
||||
$description = false;
|
||||
if (class_exists('WPSEO_META')) {
|
||||
$description = WPSEO_META::get_value('opengraph-description', $post->ID);
|
||||
if ( class_exists( 'WPSEO_META' ) ) {
|
||||
$description = WPSEO_META::get_value( 'opengraph-description', $post->ID );
|
||||
}
|
||||
if (!$description) {
|
||||
$excerpt = get_the_excerpt($post);
|
||||
if ( ! $description ) {
|
||||
$excerpt = get_the_excerpt( $post );
|
||||
$description = $excerpt ? $excerpt : $post->post_title;
|
||||
}
|
||||
$description .= ' | Originally published at ' . get_permalink($post);
|
||||
$description .= ' | Originally published at ' . get_permalink( $post );
|
||||
|
||||
$args['description'] = $description;
|
||||
|
||||
$result = LBRY()->daemon->publish($args);
|
||||
$result = LBRY()->daemon->publish( $args );
|
||||
$outputs = $result->outputs;
|
||||
|
||||
if ($outputs && is_array($outputs)) {
|
||||
if ( $outputs && is_array( $outputs ) ) {
|
||||
$output = $result->outputs[0];
|
||||
$claim_id = $output->claim_id;
|
||||
// Set Claim ID
|
||||
update_post_meta($post->ID, LBRY_CLAIM_ID, $claim_id);
|
||||
update_post_meta( $post->ID, LBRY_CLAIM_ID, $claim_id );
|
||||
|
||||
// Set Canonical URL
|
||||
$canonical_url = LBRY()->daemon->canonical_url($claim_id);
|
||||
update_post_meta($post->ID, LBRY_CANONICAL_URL, $canonical_url);
|
||||
$canonical_url = LBRY()->daemon->canonical_url( $claim_id );
|
||||
update_post_meta( $post->ID, LBRY_CANONICAL_URL, $canonical_url );
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log('Issue publishing post ' . $post->ID . ' to LBRY: ' . $e->getMessage());
|
||||
error_log( 'Issue publishing post ' . $post->ID . ' to LBRY: ' . $e->getMessage() );
|
||||
} finally {
|
||||
//Delete the temporary markdown file
|
||||
unlink($filepath);
|
||||
unlink( $filepath );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Notifier
|
||||
{
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Speech
|
||||
{
|
||||
|
@ -43,7 +44,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 +67,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 +230,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) {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Speech_Media
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Speech_Parser
|
||||
{
|
||||
|
|
2
classes/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
|
@ -5,6 +5,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Post_Handler
|
||||
{
|
||||
|
|
2
frontend/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
2
inc/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
2
templates/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
62
templates/meta-box.php
Normal 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>
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
$unnatributed = (object) array(
|
||||
'name' => 'none (anonymous)',
|
||||
'claim_id' => 'null'
|
||||
|
|
48
templates/options-page.php
Normal 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 -->
|
|
@ -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>
|
71
templates/partials/channel-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
|
||||
}
|
2
templates/partials/index.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
$url = get_post_meta(get_the_id(), LBRY_CANONICAL_URL, true);
|
||||
if (!$url) {
|
||||
// Get channel canonical for backwards compatibility
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
<?php
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
?>
|
||||
<div class="error">
|
||||
<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
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
// if uninstall.php is not called by WordPress, die
|
||||
defined('WP_UNINSTALL_PLUGIN') || die();
|
||||
|
|
2
vendor/index.php
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|