Compare commits

..

8 commits

Author SHA1 Message Date
Paul Kirby
89a7c55dfe Automatically try to start the Daemon 2020-02-17 22:18:26 -06:00
Paul Kirby
920591a171 Initial attempt at starting daemon in background 2020-02-17 20:02:27 -06:00
Paul Kirby
94c52bb5eb slightly more info on the help page 2020-02-17 19:24:20 -06:00
Paul Kirby
8ff7ee890e More useful links on help page 2020-02-17 19:15:59 -06:00
Paul Kirby
983e59cd78 Helpful error if daemon isn't running 2020-02-17 19:13:55 -06:00
Paul Kirby
0ceb343be7 Stubbed out test_daemon 2020-02-17 18:17:57 -06:00
Paul Kirby
81306394b7 Added basic template for help page 2020-02-17 16:56:51 -06:00
Paul Kirby
be64d7a523 Added help page, made multi-level menu 2020-02-17 16:40:51 -06:00
49 changed files with 545 additions and 1881 deletions

1
.gitignore vendored
View file

@ -4,7 +4,6 @@
!*.*
.DS_Store
.vscode/*
tmp/*
logs/*

101
README.md
View file

@ -1,100 +1,3 @@
# LBRYPress - Publish from WordPress to LBRY automatically
Wordpress plugin for LBRY - automated posting to markdown files including images.
This plugin and README are in early development. Thank you for your patience.
![](https://spee.ch/c/lbry-press-cover.jpg)
## How it works
The LBRYPress plugin communicates with the LBRY network via a locally installed SDK. This allows you to create a channel and then mirror any published posts to it. If there are images or GIFs in your post, they will be uploaded to spee.ch (our blockchain-based image sharing service) automatically during the publishing process. If you update a post, it will also be updated on LBRY.
## Downloading and installing the WordPress plugin
First, install the LBRYPress plugin on WordPress.
1) Download the [zip file for this repository](https://github.com/lbryio/lbrypress/archive/master.zip).
1) In WordPress, upload and install the plugin zip file from the WordPress admin dashboard. After activating, errors will show until the next steps are completed.
1) LBRYPress is not currently working correctly with the WordPress block editor, try a plugin that reactivates the classic WP Editor screen. LBRYPress may work in the future with Gutenberg block editor.
## Downloading and installing LBRY
This will step you through downloading the LBRY SDK, installing it, and running as a system service.
1) Download the latest LBRY SDK from our [releases page for your OS](https://github.com/lbryio/lbry-sdk/releases): `wget https://github.com/lbryio/lbry-sdk/releases/download/v0.86.1/lbrynet-linux.zip`
1) Make a new directory in /opt named lbry: `mkdir /opt/lbry`
1) You may need to install Unzip: `sudo apt get install unzip`
1) Unzip the file here: `unzip lbrynet-linux.zip -d /opt/lbry`
1) To get started, you can run the SDK manually at first. Open a new terminal, `cd /opt/lbry` and run: `./lbrynet start`
Once you do this, the SDK will startup in the current session and sync with the blockchain. Open a new terminal to issue further commands.
### Install LBRY as system service (can skip this step for now)
1) Create a file called lbrynet.service and insert it into `/etc/systemd/system/`:
```
[Unit]
Description="LBRYnet daemon"
After=network.target
[Service]
ExecStart=/opt/lbry/lbrynet start
User=YOURUSERNAME
Group=YOURUSERGROUP
Restart=on-failure
KillMode=process
[Install]
WantedBy=multi-user.target
```
1) Run `sudo systemctl daemon-reload`
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 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:
![](/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"
1) Go to the LBRYnet Directory `cd /opt/lbry/`
1) Run the command: `./lbrynet account fund --amount=10.0 --outputs=100`
## Setting up publishing
Experimental: republishing of images in blog to LBRY: If images or GIFs are used in your posts, they should be reposted to as thumbnails similar to the upload process in the LBRY apps. This feature may not work correctly at this time.
**Please note: spee.ch channel creation is no longer available and that step can be skiped.**
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**.
![](/admin/images/settings-tab.jpg)
## 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**.
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**.
![](/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).
1) Create your post.
1) At the bottom of the Document menu, find **LBRY Network**, and click **Sync this post on channel**.
1) Select the channel you want to publish it on.
1) Click Publish.
1) The plugin will automatically add a link to content on LBRY.
1) Give it a few minutes to publish and be confirmed on the network (there's currently no feedback for this). Check your content at: https://lbry.tv/@ChannelName.
If you edit a post, it will also create an update on the LBRY network.
## Need help?
Email us at [hello@lbry.com](mailto:hello@lbry.com) if you need assistance setting up the LBRYPress plugin.
This Readme needs love.

View file

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

View file

@ -1,121 +0,0 @@
/**
* Stylesheet for the admin pages LBRYPress uses
* @package LBRYPress
*/
.wallet-icon-lbc {
height: 1.8em;
margin-right: .5em;
margin-bottom: -.5em;
}
.bid-icon-lbc {
height: 1.2em;
margin-bottom: -.2em;
}
.channel-bid-icon-lbc {
height: 1.1em;
margin-right: .1em;
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: 0 .1em 0 0;
}
.lbry-meta-checkbox-wrapper {
padding: .5em .8em .6em;
}
.lbry-meta-wrapper-last {
padding: 0em .8em 1.5em;
}
.lbry-meta-label {
padding: .3em .6em .6em .1em;
/* padding-left: .3em;
padding-right: .6em;
padding-bottom: .5em; */
}
.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;
}
.lbry-hr-meta {
margin-left: 1em;
margin-right: 1em;
}
.post-lbry-display-before {
color: green;
}
.post-lbry-display {
color: #135548;
}
.lbry-pub-metabox {
margin: 0;
font-size: 1em;
}
.lbry-claim-id-metabox {
margin: 0;
padding-top: .3em;
font-size: .85em;
line-height: 1em;
}
.lbry-meta-bx-content {
padding: .2em .8em .6em .1em;
}
.lbry-meta-bx-content-last {
padding: .2em .8em 1em .1em;
}
/*---------------------
Channels Table
-------------------*/
table.lbry-channel-table {
width: 100%;
border-collapse: collapse;
font-family: Georgia;
}
.lbry-channel-table th, .lbry-channel-table td {
padding: .4em 1.6em;
border: 2px solid #fff;
background: #97eb9d;
font-size: 1em;
}
.lbry-channel-table thead th {
padding: .5em 2em;
background: #135548;
text-align: left;
font-weight: normal;
font-size: 1.2em;
color: #fff;
}
.lbry-channel-table tbody tr:nth-child(odd) td {
background: #e1fafa;
}
.lbry-channel-table tfoot th {
padding: .5em 1.8em;
background: #175248;
text-align: left;
font-weight: normal;
font-size: .9em;
color: #fff;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

View file

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 654 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

View file

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

View file

@ -1,56 +0,0 @@
jQuery( document ).ready( function( $ ) {
// Uploading files
var file_frame;
var wp_media_post_id = wp.media.model.settings.post.id; // Store the old id
var set_to_post_id = 10; // Set this
jQuery('#lbry_upload_thumbnail_button').on('click', function( event ){
event.preventDefault();
// If the media frame already exists, reopen it.
if ( file_frame ) {
// Set the post ID to what we want
file_frame.uploader.uploader.param( 'post_id', set_to_post_id );
// Open frame
file_frame.open();
return;
} else {
// Set the wp.media post id so the uploader grabs the ID we want when initialised
wp.media.model.settings.post.id = set_to_post_id;
}
// Create the media frame.
file_frame = wp.media.frames.file_frame = wp.media({
title: jQuery( this ).data( 'uploader_title' ),
button: {
text: jQuery( this ).data( 'uploader_button_text' ),
},
multiple: true // Set to true to allow multiple files to be selected
});
// When an image is selected, run a callback.
file_frame.on( 'select', function() {
// We set multiple to false so only get one image from the uploader
attachment = file_frame.state().get('selection').first().toJSON();
// Do something with attachment.id and/or attachment.url here
$( '#thumbnail-preview' ).attr( 'src', attachment.url ).css( 'width', 'auto' );
$( '#lbry_thumbnail_attachment_id' ).val( attachment.id );
$( '#lbry_upload_thumbnail_button' ).css( 'display', 'none' );
$( '.channel-image-info' ).css( 'display', 'none' );
// Restore the main post ID
wp.media.model.settings.post.id = wp_media_post_id;
});
// Finally, open the modal
file_frame.open();
});
// Restore the main ID when the add media button is pressed
jQuery('a.add_media').on('click', function() {
wp.media.model.settings.post.id = wp_media_post_id;
});
});

View file

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

View file

@ -1,83 +0,0 @@
jQuery(document).ready(function($) {
var compare = {
channel: function(a, b) {
a = a.replace(/^@/i, '') && a.replace(/[-]/gi, '');
b = b.replace(/^@/i, '') && b.replace(/[-]/gi, '');
if (a < b) {
return -1;
} else {
return a > b ? 1 : 0;
}
},
lbryurl: function(a, b) {
a = a.replace(/^lbry:\/\/@/i, '') && a.replace(/#[a-zA-Z0-9]+/, '') && a.replace(/-/g, '');
b = b.replace(/^lbry:\/\/@/i, '') && b.replace(/#[a-zA-Z0-9]+/, '') && b.replace(/-/g, '');
if (a < b) {
return -1;
} else {
return a > b ? 1 : 0;
}
},
claim: function(a, b) {
if (a < b) {
return -1;
} else {
return a > b ? 1 : 0;
}
},
posts: function(a, b) {
a = Number(a);
b = Number(b);
return a - b;
},
support: function(a, b) {
a = a.replace(/,/g, '');
b = b.replace(/,/g, '');
a = Number(a);
b = Number(b);
return a - b;
},
date: function(a, b) {
a = new Date(a);
b = new Date(b);
return a - b;
}
};
$('.lbry-channel-table').each(function() {
var $table = $(this);
var $tbody = $table.find('tbody');
var $controls = $table.find('th');
var rows = $tbody.find('tr').toArray();
$controls.on('click', function() {
var $header = $(this);
var order = $header.data('sort');
var column;
if ($header.is('.ascending') || $header.is('.descending')) {
$header.toggleClass('ascending descending');
$tbody.append(rows.reverse());
} else {
$header.addClass('ascending');
$header.siblings().removeClass('ascending descending');
if (compare.hasOwnProperty(order)) {
column = $controls.index(this);
rows.sort(function(a, b) {
a = $(a).find('td').eq(column).text();
b = $(b).find('td').eq(column).text();
return compare[order](a, b);
});
$tbody.append(rows);
}
}
});
});
});

View file

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

View file

@ -4,7 +4,6 @@
*
* @package LBRYPress
*/
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRYPress
{
@ -65,7 +64,7 @@ class LBRYPress
*/
public static function instance()
{
if ( is_null( self::$_instance ) ) {
if (is_null(self::$_instance)) {
self::$_instance = new self();
}
return self::$_instance;
@ -78,7 +77,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();
}
@ -89,10 +88,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);
}
}
@ -108,12 +107,11 @@ 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
@ -121,21 +119,20 @@ class LBRYPress
$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_PUB_CHANNEL', '_lbry_post_pub_channel'); // The meta key for which channel to publish on
$this->define('LBRY_POST_PUB_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
$this->define('LBRY_DAEMON_PID', 'lbry_daemon_pid');
}
/**
* 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,13 +143,13 @@ class LBRYPress
*/
private function init()
{
$this->notice = new LBRY_Admin_Notice();
$this->daemon = new LBRY_Daemon();
$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();
}
}
@ -162,16 +159,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' ) );
add_filter( 'kses_allowed_protocols' , array( $this, 'lbry_add_additional_protocols' ) );
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));
});
}
@ -183,28 +179,17 @@ 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_WALLET => '',
'lbry_default_publish_setting' => '',
'default_lbry_channel' => '',
LBRY_LICENSE => '',
LBRY_LBC_PUBLISH => 0.001,
LBRY_SPEECH => null,
LBRY_LICENSE => $this->licenses[0],
LBRY_LBC_PUBLISH => 1,
LBRY_DAEMON_PID => 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 );
add_option(LBRY_SETTINGS, $option_defaults, false);
}
// COMBAK: decide if we need to check for missing or corrupt settings. May be unecessary.
@ -225,39 +210,26 @@ class LBRYPress
public function deactivate()
{
// TODO: Stop the daemon
error_log( 'Deactivated LBRYPress' );
}
/**
* Allowing additional URL protocols to list of allowed protocols.
*
* @param array $protocols List of protocols allowed by (default WordPress.)
*
* @return array $protocols Updated list including additional protocols.
*/
public function lbry_add_additional_protocols( $protocols )
{
$protocols[] = 'lbry';
return $protocols;
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;

View file

@ -4,7 +4,6 @@
*
* @package LBRYPress
*/
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Admin
{
@ -15,97 +14,43 @@ class LBRY_Admin
*/
public function __construct()
{
add_action('admin_menu', array($this, 'create_options_page'));
add_action('admin_menu', array($this, 'create_menu_pages'));
add_action('admin_init', array($this, 'page_init'));
add_action('admin_init', array($this, 'wallet_balance_warning'));
add_action('admin_post_lbry_add_channel', array($this, 'add_channel'));
add_action('admin_post_lbry_add_supports', array($this, 'add_supports'));
add_action('admin_post_lbry_edit_channel', array($this, 'edit_channel'));
}
/**
* Creates the options page in the WP admin interface
*/
public function create_options_page()
public function create_menu_pages()
{
add_menu_page(
__( 'LBRYPress Settings', 'lbrypress' ),
__( 'LBRYPress', 'lbrypress' ),
__('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'
'',
plugin_dir_url(LBRY_PLUGIN_FILE) . '/admin/images/lbry-logo.svg'
);
// Admin stylesheet enqueue
function load_admin_stylesheet( $hook ) {
add_submenu_page(
LBRY_ADMIN_PAGE,
__('LBRYPress Settings', 'lbrypress'),
__('Settings', 'lbrypress'),
'manage_options',
LBRY_ADMIN_PAGE,
array($this, 'options_page_html')
);
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 channel sort JS enqueue
function load_channel_sort_script() {
if ( ( $_GET['page'] == 'lbrypress') && ( $_GET['tab'] == 'channels' ) ) {
wp_enqueue_script(
'lbry-table-sort',
plugins_url( '/admin/js/table-sort.js', LBRY_PLUGIN_FILE ),
array('jquery'),
LBRY_VERSION,
true
);
}
}
add_action( 'admin_enqueue_scripts', 'load_channel_sort_script' );
// Admin Media Upload on Edit Channel tab
function load_channel_edit_media_scripts() {
if ( ( $_GET['page'] == 'lbrypress' ) && ( $_GET['tab'] == 'channel-edit' ) ) {
wp_enqueue_media();
wp_enqueue_script(
'lbry-media-upload',
plugins_url( '/admin/js/admin-image-uploader.js', LBRY_PLUGIN_FILE ),
array( 'jquery' ),
LBRY_VERSION,
true
);
}
}
add_action( 'admin_enqueue_scripts', 'load_channel_edit_media_scripts' );
// 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()
{
// Set class properties to be referenced in callbacks
$this->options = get_option( LBRY_SETTINGS );
$this->options_speech = get_option( LBRY_SPEECH_SETTINGS );
require_once( LBRY_ABSPATH . 'templates/options-page.php' );
add_submenu_page(
LBRY_ADMIN_PAGE,
__('LBRYPress Help', 'lbrypress'),
__('Help', 'lbrypress'),
'manage_options',
'lbrypress-help',
array($this, 'help_page_html')
);
}
/**
@ -114,17 +59,13 @@ class LBRY_Admin
public function page_init()
{
// Register the LBRY Setting array
register_setting(
'lbry_general_settings',
LBRY_SETTINGS,
array( $this, 'sanitize_general_settings' )
);
register_setting(LBRY_SETTINGS_GROUP, LBRY_SETTINGS, array('sanitize_callback' => array($this, 'sanitize')));
// Add Required Settings Sections
add_settings_section(
LBRY_SETTINGS_SECTION_GENERAL, // ID
'General Settings', // Title
array( $this, 'general_section_callback' ), // Callback
array( $this, 'general_section_info' ), // Callback
LBRY_ADMIN_PAGE // Page
);
@ -138,17 +79,25 @@ class LBRY_Admin
);
add_settings_field(
'lbry_default_publish_setting',
'Always Publish to LBRY',
array( $this, 'lbry_always_pub_callback' ),
LBRY_SPEECH,
'Spee.ch URL',
array( $this, 'speech_callback' ),
LBRY_ADMIN_PAGE,
LBRY_SETTINGS_SECTION_GENERAL
);
add_settings_field(
'default_lbry_channel',
'Default Publish Channel',
array( $this, 'default_channel_callback' ),
LBRY_SPEECH_CHANNEL,
'Spee.ch Channel',
array( $this, 'speech_channel_callback' ),
LBRY_ADMIN_PAGE,
LBRY_SETTINGS_SECTION_GENERAL
);
add_settings_field(
LBRY_SPEECH_PW,
'Spee.ch Password',
array( $this, 'speech_pw_callback' ),
LBRY_ADMIN_PAGE,
LBRY_SETTINGS_SECTION_GENERAL
);
@ -164,136 +113,63 @@ class LBRY_Admin
add_settings_field(
LBRY_LBC_PUBLISH,
'LBC Per Publish',
array( $this, 'lbc_per_publish_callback' ),
array( $this, 'lbc_publish_callback' ),
LBRY_ADMIN_PAGE,
LBRY_SETTINGS_SECTION_GENERAL
);
}
/**
* 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
*/
/**
* 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');
}
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'
);
/**
* Returns the Help Page HTML for the plugin
*/
public function help_page_html()
{
require_once(LBRY_ABSPATH . 'templates/help_page.php');
}
/**
* Sanitizes setting input
* // COMBAK Potentially sanitize more
*/
public function sanitize_general_settings( $input )
public function sanitize($input)
{
$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] ) ) {
if (!empty($input[LBRY_SPEECH_CHANNEL])) {
$channel = $input[LBRY_SPEECH_CHANNEL];
$channel = str_replace( '@', '', $channel );
$new_input[LBRY_SPEECH_CHANNEL] = sanitize_user( $channel );
$channel = str_replace('@', '', $channel);
$input[LBRY_SPEECH_CHANNEL] = $channel;
}
if ( isset( $input[LBRY_SPEECH_PW] ) ) {
$input[LBRY_SPEECH_PW] = sanitize_text_field( $input[LBRY_SPEECH_PW] );
$encrypted = $this->encrypt( $input[LBRY_SPEECH_PW] );
$new_input[LBRY_SPEECH_PW] = $encrypted;
} else {
// If we have a password and it's empty, keep original password
if ( empty( $input[LBRY_SPEECH_PW] ) )
$new_input[LBRY_SPEECH_PW] = get_option( LBRY_SPEECH_SETTINGS[LBRY_SPEECH_PW] );
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];
}
}
return $new_input;
update_option( LBRY_SPEECH_SETTINGS, $new_input );
return $input;
}
/**
* Section info for the General Section
*/
public function general_section_callback()
public function general_section_info()
{
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()
{
// Moved to channels-page.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
*/
@ -301,9 +177,9 @@ 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="'. esc_attr('%1$s') .'" name="'. esc_attr('%2$s[%1$s]') .'" value="' . esc_attr('%3$s') . '" readonly />',
'<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" readonly />',
LBRY_WALLET,
LBRY_SETTINGS,
$address
@ -311,50 +187,41 @@ class LBRY_Admin
}
/**
* Checkbox to default to always allow publish on LBRY
*/
public function lbry_always_pub_callback()
* Prints Spee.ch input
*/
public function speech_callback()
{
$options = get_option( LBRY_SETTINGS )['lbry_default_publish_setting'];
if ( ! isset( $options ) ) {
$options = 0;
}
$checked = checked( $options, 1, false );
printf(
'<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,
'<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" placeholder="https://your-speech-address.com"/>',
LBRY_SPEECH,
LBRY_SETTINGS,
isset($this->options[LBRY_SPEECH]) ? esc_attr($this->options[LBRY_SPEECH]) : ''
);
}
/**
* Prints select to choose a default to publish to channel
*/
public function default_channel_callback()
* Prints Spee.ch channel input
*/
public function speech_channel_callback()
{
$options = '';
$channel_list = LBRY()->daemon->channel_list();
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]) : ''
);
}
if ( $channel_list ) {
foreach ( $channel_list as $channel ) {
$selected = $this->options['default_lbry_channel'] === $channel->claim_id;
$options .= '<option value="' . esc_attr( $channel->claim_id ) . '"';
if ( $selected ) {
$options .= ' selected';
}
$options .= '>' . esc_html( $channel->name ) . '</option>';
}
printf(
'<select id="' . esc_attr('%1$s') . '" name="' . esc_attr('%2$s[%1$s]') . '">' . esc_html('%3$s') . '</select>',
'default_lbry_channel',
LBRY_SETTINGS,
$options
);
} else { ?>
<p>Looks like you haven't added any channels yet, you can do that now on the <a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channels' ), 'options.php' ) ) ); ?>" class="">Channels Tab</a></p>
<?php }
/**
* Prints 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
);
}
/**
@ -366,223 +233,64 @@ 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="'.esc_attr('%1$s').'" name="'. esc_attr('%2$s[%1$s]') .'">' . esc_html('%3$s') . '</select>',
'<select id="%1$s" name="%2$s[%1$s]">%3$s</select>',
LBRY_LICENSE,
LBRY_SETTINGS,
$options
);
}
/**
* Prints LBC per publish input
*/
public function lbc_per_publish_callback()
public function lbc_publish_callback()
{
printf(
'<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>',
'<input type="number" id="%1$s" name="%2$s[%1$s]" value="%3$s" min="0.01" step="0.01"/>',
LBRY_LBC_PUBLISH,
LBRY_SETTINGS,
$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] : '',
$this->options[LBRY_LBC_PUBLISH]
);
}
/**
* 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'], '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 );
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'];
$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 );
}
// 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);
}
} else {
LBRY()->notice->set_notice('error', 'Security check failed' );
die( __( 'Security check failed', 'lbrypress' ) );
}
wp_safe_redirect( $redirect_url );
exit();
}
/**
* Handles adding supports form submission
*/
public function add_supports()
{
if ( ( $_POST['post_id'] ) && ( absint( $_POST['post_id'] ) ) ) {
$redirect_url = admin_url( add_query_arg( array( 'post' => $_POST['post_id'], 'action' => 'edit' ), 'post.php') );
} else {
$redirect_url = admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channels' ), 'options.php' ) );
}
if ( ( $_POST['lbry_url'] ) ? $lbry_url = urldecode($_POST['lbry_url']) : $lbry_url = $_POST['lbry_supports_add_claim_id']);
if ( ( $_POST['supporting_channel'] ) ? $supporting_channel = $_POST['supporting_channel'] : $supporting_channel = null );
// Check that nonce
if ( isset( $_POST['_lbrynonce'] ) && wp_verify_nonce( $_POST['_lbrynonce'], 'add_supports_nonce' ) ) {
if ( isset( $_POST['lbry_supports_add_claim_id'] ) && isset( $_POST['lbry_supports_add_bid_amount'] ) ) {
$claim_id = $_POST['lbry_supports_add_claim_id']; // TODO: sanitize key() only allows for lowercase chars, dashes, and underscores. maybe remove to allow more characters? and use something else for better control?
$claim_id = sanitize_text_field( $claim_id );
$bid = $_POST['lbry_supports_add_bid_amount'];
$supports_bid = number_format( floatval( $bid ), 3, '.', '' );
// Try to add support to the claim
try {
$result = LBRY()->daemon->supports_add( $claim_id, $supports_bid, $supporting_channel, $lbry_url );
} 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 );
exit();
}
/**
* Handles editing an existing channel form submission
*/
public function edit_channel()
{
$redirect_url = admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channels' ), 'options.php' ) );
$claim = $_POST['claim_id'];
$claim_id = sanitize_text_field( $claim );
$bid = $_POST['lbry_supports_add_bid_amount'];
$channel_bid = number_format( floatval( $bid ), 3, '.', '' );
$title = $_POST['lbry_edit_channel_title'];
$channel_title = sanitize_text_field( $title );
$description = $_POST['lbry_edit_channel_description'];
$channel_description = sanitize_text_field( $description );
$tags = $_POST['lbry_edit_channel_tags'];
$channel_tags = sanitize_text_field( $tags );
$website = $_POST['lbry_new_channel_website'];
$channel_website = sanitize_text_field( $website );
$email = $_POST['lbry_new_channel_email'];
$channel_email = sanitize_text_field( $email );
// $language_array = LBRY()->languages;
// $primlang = $_POST['lbry_new_channel_prim_lang'];
// $primary_language = ( ($primlang) && in_array( $primlang, $language_array ) );
// $seclang = $_POST['lbry_new_channel_sec_lang'];
// $secondary_language = ( ($seclang) && in_array( $seclang, $language_array ) );
// $thumbnail = $_POST[''];
// $thumbnail_url = wp_get_attachment_url( get_option( 'lbry_media_selector_thumbnail_id' ) )
// $header = $_POST[''];
// $header_url = wp_get_attachment_url( get_option( 'lbry_media_selector_header_id' ) );
// Check that nonce
if ( isset( $_POST['_lbrynonce'] ) && wp_verify_nonce( $_POST['_lbrynonce'], 'edit_channel_nonce' ) ) {
$args = array(
'claim_id' => $claim_id,
'bid' => $channel_bid,
'title' => $channel_title,
'description' => $channel_description,
'tags' => $channel_tags,
'website_url' => $channel_website,
'email' => $channel_email,
//'languages' => array( $primary_language, $secondary_language ),
//'thumbnail_url' => $thumbnail_url,
//'cover_url' => $header_url,
);
// Try to add support to the claim
try {
$result = LBRY()->daemon->channel_edit( $args );
} 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();
}
@ -593,21 +301,19 @@ class LBRY_Admin
public static function wallet_balance_warning()
{
// See if we've checked in the past two hours
if ( ! get_transient( 'lbry_wallet_check' ) ) {
$result = LBRY()->daemon->wallet_balance();
$balance = $result->result->available;
$site_url = get_site_url();
if ( $balance < get_option( LBRY_SETTINGS )[LBRY_LBC_PUBLISH] * 20 ) {
if (!get_transient('lbry_wallet_check')) {
$balance = LBRY()->daemon->wallet_balance();
if ($balance < get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH] * 20) {
// If LBRY Balance is low, send email, but only once per day
if ( ! get_transient( 'lbry_wallet_warning_email' ) ) {
$email = get_option( 'admin_email' );
if (!get_transient('lbry_wallet_warning_email')) {
$email = get_option('admin_email');
$subject = 'Your LBRYPress Wallet Balance is Low!';
$message = 'Your LBRY Wallet for your WordPress installation at ' . esc_html_e( $site_url ) . ' is running very low.\r\n\r\nYou currently have ' . esc_html_e( $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 );
$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.';
wp_mail($email, $subject, $message);
set_transient('lbry_wallet_warning_email', true, DAY_IN_SECONDS);
}
}
set_transient( 'lbry_wallet_check', true, 2 * HOUR_IN_SECONDS );
set_transient('lbry_wallet_check', true, 2 * HOUR_IN_SECONDS);
}
}

View file

@ -4,14 +4,12 @@
*
* @package LBRYPress
*/
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Admin_Notice
{
public function __construct()
{
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
add_action('admin_notices', array($this, 'admin_notices'));
}
/**
@ -19,12 +17,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');
}
}
@ -32,7 +30,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,
@ -40,24 +38,35 @@ 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[] = $notice;
set_transient( 'lbry_notices', $notices );
$notices = get_transient('lbry_notices');
if (!in_array($notice, $notices)) {
$notices[] = $notice;
}
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'] ) );
ob_start();
?>
<div class="<?= $class ?>">
<p>
<span style="font-weight:bold">LBRYPress: </span>
<?= $notice['message'] ?>
</p>
</div>
<?php
echo ob_get_clean();
}
}

View file

@ -4,7 +4,6 @@
*
* @package LBRYPress
*/
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Daemon
{
@ -14,6 +13,16 @@ class LBRY_Daemon
*/
private $address = 'localhost:5279';
/**
* The Daemon's Status
*/
private $daemon_running = false;
/**
* The Daemon Notice Handler
*/
private $notice = null;
/**
* The Daemon Logger
* @var LBRY_Daemon_Logger
@ -26,6 +35,82 @@ class LBRY_Daemon
public function __construct()
{
$this->logger = new LBRY_Daemon_Logger();
$this->notice = new LBRY_Admin_Notice();
$this->daemon_running = $this->test_daemon();
if (!$this->daemon_running) {
$this->start_daemon();
$this->notice->set_notice('error', 'Cannot connect to the LBRY Daemon. Attempting to start daemon server. <br /> If you are still having troubles, click <a href="' . admin_url('admin.php?page=lbrypress-help') . '">HERE</a> for help.');
}
}
/**
* Returns a boolean representation of daemon status
* @return bool Whether or not the daemon is running
*/
private function test_daemon()
{
try {
$result = $this->request('status')->result;
return $result->is_running;
} catch (LBRYDaemonException $e) {
$this->logger->log('daemon_status_error', $e->getMessage() . ' | Code: ' . $e->getCode());
return false;
}
}
/**
* Attempts to start the daemon
*/
private function start_daemon()
{
// Check if a daemon start process is already running
$options = get_option(LBRY_SETTINGS);
if ($options[LBRY_DAEMON_PID]) {
if ($this->is_process_running($options[LBRY_DAEMON_PID])) {
return;
}
$options[LBRY_DAEMON_PID] = false;
update_option(LBRY_SETTINGS, $options);
}
// Using proc_open to set up the request
// Again, this is unix only
$cmd = ABSPATH . "lbrynet start";
$command = $cmd . ' > /dev/null 2> /dev/null & echo $!;';
$pid = exec($command);
if ($pid) {
$options = get_option(LBRY_SETTINGS);
$options[LBRY_DAEMON_PID] = $pid;
update_option(LBRY_SETTINGS, $options);
}
}
/**
* Attempts to stop the daemon
*/
private function stop_daemon()
{
exec(ABSPATH . 'lbrynet stop > /dev/null 2> /dev/null &');
}
/**
* Checks to see if a PID is currently running
* @param int $pid
* @return boolean
*/
private function is_process_running($pid)
{
// This is unix specific
$lines_out = array();
exec('ps '.(int)$pid, $lines_out);
if(count($lines_out) >= 2) {
// Process is running
return true;
}
return false;
}
/**
@ -33,13 +118,16 @@ 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()
{
if (!$this->daemon_running) return;
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());
$this->notice->set_notice('error', 'Issue getting unused address.');
return;
}
}
@ -50,61 +138,41 @@ 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)
{
if (!$this->daemon_running) return;
// 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.' );
return;
}
}
/**
* Returns the info about a claim can get supports and initial bid amount when claim created among other information about a claim.
* TODO Can be build out later to accept more params
* @param string $claim_id
* @return object $result
*/
public function claim_search( $claim_id )
{
$params = array(
'claim_id' => $claim_id,
// 'name' => $norm_name,
// 'claim_type' => $claim_type,
);
try {
$result = $this->request( 'claim_search', $params );
$this->logger->log( 'Claim Search Results: ' . print_r( $result->result, true ) );
return $result->result;
} catch ( LBRYDaemonException $e ) {
$this->logger->log( 'claim_search error', $e->getMessage() . ' | Code: ' . $e->getCode() );
LBRY()->notice->set_notice( 'error', 'Issue getting claim search info' );
} catch (LBRYDaemonException $e) {
$this->logger->log('address_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
$this->notice->set_notice('error', 'Issue getting address list.');
return;
}
}
/**
* Returns the available balance of a current LBRY account
* https://lbry.tech/api/sdk#wallet_balance
* @param string $address Wallet Address
* @return object $wallet_balance Wallet Balance
*
* https://lbry.tech/api/sdk#account_balance
* @param string $address Wallet Address
* @return float Wallet Balance
*/
public function wallet_balance()
{
try { // Convert JSON string to an object
$result = $this->request( 'wallet_balance' );
return $result;
{
if (!$this->daemon_running) return;
try {
$result = $this->request('account_balance');
return $result->result->available;
} catch (LBRYDaemonException $e) {
$this->logger->log('wallet_balance error', $e->getMessage() . ' | Code: ' . $e->getCode());
LBRY()->notice->set_notice('error', 'Issue getting wallet balance.');
$this->logger->log('account_balance error', $e->getMessage() . ' | Code: ' . $e->getCode());
$this->notice->set_notice('error', 'Issue getting account balance.');
return;
}
}
@ -115,19 +183,21 @@ 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)
{
if (!$this->daemon_running) return;
$params = array(
'page' => $page,
'page_size' => 20
);
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());
$this->notice->set_notice('error', 'Issue retrieving channel list.');
return;
}
}
@ -137,20 +207,21 @@ class LBRY_Daemon
* https://lbry.tech/api/sdk#channel_create
* @return array dictionary containing result of the request
*/
public function channel_new( $channel_name, $channel_bid )
public function channel_new($channel_name, $bid_amount)
{
if (!$this->daemon_running) return;
// 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 {
@ -158,72 +229,13 @@ class LBRY_Daemon
'channel_create',
array(
'name' => $channel_name,
'bid' => $channel_bid
'bid' => number_format(floatval($bid_amount), 2, '.', '')
)
);
$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 );
return;
}
}
/**
* Edit an existing channel to add missing details
* https://lbry.tech/api/sdk#channel_update
* @return array dictionary containing result of the request
*/
public function channel_edit( $args )
{
try {
$result = $this->request(
'channel_update',
$args
);
$this->logger->log( 'channel_update success!', 'Successfully updated channel with result: ' . print_r( $result->result, true ) );
return $result->result;
} catch (LBRYDaemonException $e) {
$this->logger->log( 'channel_update error', $e->getMessage() . ' | Code: ' . $e->getCode() );
throw new \Exception( 'Issue updating channel.', 1 );
return;
}
}
/**
* Add supports to an existing claim
* https://lbry.tech/api/sdk#
* @return array dictionary containing result of the request
*/
public function supports_add( $claim_id, $supports_bid, $supporting_channel = null, $lbry_url = null )
{
try {
$result = $this->request(
'support_create',
array(
'claim_id' => $claim_id,
'channel_name' => $supporting_channel,
'amount' => $supports_bid
)
);
if ( $result ) {
if ( ( ($lbry_url) && ($lbry_url !== null ) ) ? $lbry_url : $lbry_url = $claim_id );
LBRY()->notice->set_notice(
'success', 'Successfully added supports for claim id: ' . esc_html__( $lbry_url, 'lbrypress' ) . '! Please allow a few minutes for the support to process.', true );
}
$this->logger->log( 'support_create success!', 'Successfully added support with result: ' . print_r( $result->result, true ) );
return $result->result;
} catch (LBRYDaemonException $e) {
$this->logger->log( 'support_create error', $e->getMessage() . ' | Code: ' . $e->getCode() );
throw new \Exception( 'Issue creating new support.', 1 );
$this->logger->log('channel_new error', $e->getMessage() . ' | Code: ' . $e->getCode());
throw new \Exception('Issue creating new channel.', 1);
return;
}
}
@ -233,9 +245,11 @@ 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 (!$this->daemon_running) return;
if (!$claim_id) {
return null;
}
@ -249,13 +263,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;
}
}
@ -270,18 +284,20 @@ class LBRY_Daemon
*
* @return object $result
*/
public function publish( $args )
public function publish($args)
{
if (!$this->daemon_running) return;
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());
$this->notice->set_notice('error', 'Issue publishing / updating post to LBRY Network.');
return;
}
}
@ -292,52 +308,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 errors in decoded daemon response and throws an exception if it finds one
* Checks for erros 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);
}
}

View file

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

View file

@ -4,7 +4,6 @@
*
* @package LBRYPress
*/
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Network
{
@ -35,31 +34,25 @@ class LBRY_Network
private function post_meta_setup()
{
// Add the meta boxes
add_action( 'add_meta_boxes', array( $this, 'lbry_meta_boxes' ) );
add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
// Save the post meta on 'save_post' hook
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' ) );
add_action('wp_insert_post', array($this, 'save_post_meta'), 11, 2);
}
/**
* Adds the meta boxes to the post editing backend
*/
public function lbry_meta_boxes( $post )
public function add_meta_boxes()
{
// IDEA: Support post types based on user selection
add_meta_box(
'lbry-network-publishing', // Unique ID
__('LBRY Network', 'lbrypress'), // Title
'LBRY Network', // Title
array($this, 'meta_box_html'), // Callback function
'post', // Screen Options (or post type)
'side', // Context
'high', // Priority
array(
'__block_editor_compatible_meta_box' => false,
)
'high' // Priority
);
}
@ -69,133 +62,40 @@ 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 $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_post_nonce' ) ) {
//LBRY()->notice->set_notice('error', 'Security check failed' );
return $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;
}
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 );
if ($post->post_type != 'post') {
return;
}
$channel = $_POST[LBRY_POST_PUB_CHANNEL];
$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 ) );
$license = $_POST[LBRY_POST_PUB_LICENSE];
$cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true );
$will_publish = $_POST[LBRY_WILL_PUBLISH];
// Verify the nonce before proceeding.
if (!isset($_POST['_lbrynonce']) || !wp_verify_nonce($_POST['_lbrynonce'], 'lbry_publish_channels')) {
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)) {
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);
// Update meta acordingly
if ( ( $channel ) && ( $channel !== $cur_channel ) && ( $channel != null || $channel != '' ) ) {
update_post_meta( $post_id, LBRY_POST_PUB_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_PUB_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 ) && ( $license !== $cur_license ) && ( $license != null || $license != '' ) ) {
update_post_meta( $post_id, LBRY_POST_PUB_LICENSE, $license );
} elseif ( $license === $cur_license && ( $cur_license === get_post_meta( $post_id, 'lbry_license', true ) ) ) {
update_post_meta( $post_id, LBRY_POST_PUB_LICENSE, $license );
}
$published = get_post_meta( $post_id, '_lbry_is_published', true );
$will_pub = get_post_meta( $post_id, '_lbry_will_publish', true );
if ( ( $will_pub == 0 ) && ( ! ( $published ) || ( $published ) == 0 ) ) {
// If not publishing to LBRY we want to not save unused values in database
delete_post_meta( $post_id, '_lbry_post_pub_channel' );
delete_post_meta( $post_id, '_lbry_post_pub_license' );
delete_post_meta( $post_id, '_lbry_canonical_url' );
}
$pub_channel = ( $channel ) ? $channel : $cur_channel;
$pub_license = ( $license ) ? $license : $cur_license;
if ( ( $will_publish ) && ( $will_publish == true ) && ( $post->post_status == 'publish' ) && ( $pub_channel ) && ( $pub_license ) && ( $pub_license != null ) ) {
// Publish the post on the LBRY Network
$this->publisher->publish( $post, $pub_channel, $pub_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 )
{
if ( get_post_type( $post_id ) != 'post' ) {
return $post;
}
$post_id = $post->ID;
$lbry_claim_id = get_post_meta( $post_id, '_lbry_claim_id', true );
if ( $_GET['action'] === 'edit' ) {
if ( get_post_meta( $post_id, '_lbry_canonical_url', true ) == null || empty( get_post_meta( $post_id, '_lbry_canonical_url', true ) ) ) {
$canonical_url = LBRY()->daemon->canonical_url( $lbry_claim_id );
if ( $canonical_url != null ) {
update_post_meta( $post_id, '_lbry_canonical_url', $canonical_url );
} elseif ( $canonical_url == null ) {
delete_post_meta( $post_id, '_lbry_canonical_url' );
}
}
}
$lbry_url = ( get_post_meta( $post_id, '_lbry_canonical_url', true ) );
if ($lbry_url) {
$open_url = str_replace('lbry://', 'open.lbry.com/', $lbry_url );
}
$lbry_published = get_post_meta( $post_id, '_lbry_is_published', true );
$will_publish = get_post_meta( $post_id, '_lbry_will_publish', true );
$lbry_post_pub_channel = get_post_meta( $post_id, '_lbry_post_pub_channel', true );
if ( ( $will_publish ) ? $will_publish : $will_publish = get_option( LBRY_SETTINGS )['lbry_default_publish_setting'] );
if ( ( $_GET['action'] === 'edit' ) ? $value = $lbry_published : $value = $will_publish );
$checked = checked( $value, true, false );
// nonce set on page meta-box.php
if ( ( ( $will_publish == true ) && ( $lbry_post_pub_channel ) ) || ( ( ( $lbry_published ) || ( $lbry_claim_id ) ) && ( ( $lbry_url != null ) || ( $lbry_claim_id ) ) ) ) {
printf(
'<hr class="lbry-hr-meta">
<div class="misc-pub-section lbry-meta-published-lbry-wrapper">
<span class="lbry-pub-metabox"><img src="' . __( '%1$s', 'lbrypress' ) . '" class="icon icon-lbry meta-icon-lbry"></span> <span class="post-lbry-display-before">Published on:</span> <span class="post-lbry-display"><strong>LBRY</strong></span>
</div>
<div class="misc-pub-section lbry-url-meta-wrapper">
<span class="lbry-meta-label"><strong> LBRY URL: </strong></span><a href="' . esc_url( '%2$s', 'lbrypress' ) . '" target="_blank">' . esc_html__( '%3$s', 'lbrypress' ) . '</a>
</div>
<div class="misc-pub-section lbry-claim-id-meta-wrapper">
<span class="lbry-meta-label"><strong> LBRY claim ID: </strong></span><span class="lbry-pub-metabox"><p class="lbry-claim-id-metabox">' . esc_html__( '%4$s', 'lbrypress' ) . '</p></span>
</div>
<div class="misc-pub-section lbry-meta-checkbox-wrapper lbry-meta-wrapper-last">
<span class="lbry-meta-label"> Update Post on: <span class="post-lbry-display"><strong>LBRY</strong></span> <input type="checkbox" class="lbry-meta-checkbox" value="1" ' . esc_attr('%5$s') . ' name="' . esc_attr('%6$s') . '">
</div>',
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png',
$open_url,
$lbry_url,
$lbry_claim_id,
$checked,
LBRY_WILL_PUBLISH
);
if (!$will_publish) {
update_post_meta($post_id, LBRY_WILL_PUBLISH, 'false');
} else {
printf (
'<div class="misc-pub-section lbry-meta-checkbox-wrapper lbry-meta-wrapper-last">
<span class="lbry-pub-metabox"><img src="' . __( '%1$s', 'lbrypress' ) . '" class="icon icon-lbry meta-icon-lbry"></span><span class="lbry-meta-label">Publish to: <span class="post-lbry-display"> <strong>LBRY</strong></span> <input type="checkbox" class="lbry-meta-checkbox" value="1" ' . esc_attr('%2$s') . ' name="' . esc_attr('%3$s') . '">
</div>',
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png',
$checked,
LBRY_WILL_PUBLISH
);
update_post_meta($post_id, LBRY_WILL_PUBLISH, 'true');
}
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
$this->publisher->publish($post, get_post_meta($post_id, LBRY_POST_CHANNEL, true));
}
}
@ -203,8 +103,8 @@ class LBRY_Network
* 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');
}
}

View file

@ -8,7 +8,6 @@ use League\HTMLToMarkdown\HtmlConverter;
*
* @package LBRYPress
*/
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Network_Parser
{
@ -19,7 +18,7 @@ class LBRY_Network_Parser
// COMBAK: Composer is not safe in a wordpress environment. May have to write our own package.
require_once LBRY_ABSPATH . 'vendor/autoload.php';
$this->converter = new HtmlConverter(array(
'strip_tags' => true
'strip_tags' => false
));
}

View file

@ -4,7 +4,6 @@
*
* @package LBRYPress
*/
defined('ABSPATH') || die(); // Exit if accessed directly
class LBRY_Network_Publisher
{
@ -14,49 +13,48 @@ 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, $license ) {
$post_id = $post->ID;
public function publish($post, $channel = null)
{
// 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] ), 3, '.', '' ),
'bid' => number_format(floatval(get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH]), 2, '.', ''),
'file_path' => $filepath,
'title' => $post->post_title,
'languages' => array( substr( get_locale(), 0, 2 ) ),
'license' => $license,
'languages' => array(substr(get_locale(), 0, 2)),
'license' => get_option(LBRY_SETTINGS)[LBRY_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;
@ -64,50 +62,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 );
// Set Channel Name Published under
$published_channel = $output->signing_channel->name;
$channel_claim_id = $output->signing_channel->claim_id;
update_post_meta( $post->ID, '_lbry_post_published_channel', $published_channel );
update_post_meta( $post->ID, '_lbry_post_pub_channel_claim_id', $channel_claim_id );
// Set License Published under
$published_license = $output->value->license;
if ( ( $published_license ) && ( $published_license !== null ) ) {
update_post_meta( $post->ID, '_lbry_post_published_license', $published_license );
}
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 );
// Set _lbry_is_published to true
update_post_meta( $post->ID, '_lbry_is_published', true );
$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);
}
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,201 +0,0 @@
<?php
/**
* ============================
* CHANNELS EDIT 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( 'edit_channel_nonce' );
$claim_id = $_GET['claim_id'];
$claim_id = sanitize_text_field( $claim_id );
$lbry_url = $_GET['lbry_url'];
$lbry_url = urldecode($lbry_url);
$init_bid = $_GET['init_bid'];
$init_bid = number_format( floatval( $init_bid ), 3, '.', '' );
$channel = $_GET['channel_name'];
$channel = sanitize_user( $channel );
$support_amount = $_GET['current_support'];
$support_amount = number_format( floatval( $support_amount ), 3, '.', '' );
// Save attachment ID
// if ( isset( $_POST['submit'] ) && isset( $_POST['lbry_header_attachment_id'] ) ) :
// update_option( 'lbry_media_selector_header_id', absint( $_POST['lbry_header_attachment_id'] ) );
// endif;
if ( isset( $_POST['submit'] ) && isset( $_POST['lbry_thumbnail_attachment_id'] ) ) :
update_option( 'lbry_media_selector_thumbnail_id', absint( $_POST['lbry_thumbnail_attachment_id'] ) );
endif;
// Build the page
?>
<img src="">
<img src="">
<form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post" id="lbry_edit_channel_form">
<input type="hidden" name="action" value="lbry_edit_channel">
<input type="hidden" name="_lbrynonce" value="<?php echo $lbrynonce ?>">
<input type="hidden" name="claim_id" value ="<?php echo $claim_id ?>">
<!-- <input type='hidden' name='lbry_header_attachment_id' id='lbry_header_attachment_id' value='<?php //echo get_option( 'lbry_media_selector_header_id' ); ?>'> -->
<input type='hidden' name='lbry_thumbnail_attachment_id' id='lbry_thumbnail_attachment_id' value='<?php echo get_option( 'lbry_media_selector_thumbnail_id' ); ?>'>
<?php if ( $claim_id ) { ?>
<h2><?php echo _e( 'Editing Channel: ' . esc_html__( $channel ), 'lbrypress' ); ?></h2>
<?php printf(
'<h3>' . esc_html__( '%1$s', 'lbrypress' ) . '</h3>
<h4>Claim ID: <code>' . esc_html__( '%2$s', 'lbrypress' ) . '</code></h4>',
$lbry_url,
$claim_id,
);
} ?>
<table class="form-table" role="presentation">
<tbody>
<!-- <tr>
<th scope="row">Header Image</th>
<td>
<div class='image-preview-wrapper'>
<img id='header-preview' src='<?php //echo wp_get_attachment_url( get_option( 'lbry_media_selector_header_id' ) ); ?>' height='100'>
</div>
<input id="lbry_upload_header_button" type="button" class="button" value="<?php //_e( 'Upload Header', 'lbrypress' ); ?>">
<p class="header-image-info">6.25:1 ratio for best result</p>
<td>
</tr> -->
<tr>
<th scope="row">Thumbnail Image</th>
<td>
<div class='image-preview-wrapper'>
<img id="thumbnail-preview" src="'<?php echo wp_get_attachment_url( get_option( 'lbry_media_selector_thumbnail_id' ) ); ?>'" height="100">
</div>
<input id="lbry_upload_thumbnail_button" type="button" class="button" value="<?php _e( 'Upload Thumbnail', 'lbrypress' ); ?>">
<p class="channel-image-info">1:1 ratio for best result</p>
<td>
</tr>
<?php if ( $channel ) { ?>
<tr>
<th scope="row">Channel Name</th>
<td>
<?php printf(
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('%2$s') . '" required readonly>',
'lbry_edit_channel_name',
$channel,
); ?>
<p>If you want to edit another channel, use the link for the specific channel claim found on the <a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channels' ),'options.php' ) ) ); ?>">Channels tab</a>or to create a complete <a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channel-edit' ), 'admin.php' ) ) ); ?>">Channel</a></p>
</td>
</tr>
<?php } else { ?>
<tr>
<th scope="row">Channel Name</th>
<td>
<?php printf(
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="@' . esc_attr('') . '" required>',
'lbry_edit_channel_name',
); ?>
<p>No spaces or special characters in @ Channel Name</p>
</td>
</tr>
<?php } ?>
<tr>
<th scope="row">Title</th>
<td>
<?php printf(
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('') . '">',
'lbry_edit_channel_title',
); ?>
<p></p>
</td>
</tr>
<tr>
<th scope="row">Description</th>
<td>
<?php printf(
'<textarea rows="8" cols="24" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('') . '"></textarea>',
'lbry_edit_channel_description',
); ?>
<p></p>
</td>
</tr>
<tr>
<th scope="row">Tags</th>
<td>
<?php printf(
'<input type="text" rows="10" cols="50" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('') . '">',
'lbry_edit_channel_tags',
); ?>
<p>Add up to five tags (comma separated)</p>
</td>
</tr>
<tr>
<th scope="row">Website</th>
<td>
<?php printf(
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('') . '">',
'lbry_new_channel_website',
); ?>
<p>Default is LBRYPress site channel was created on</p>
</td>
</tr>
<tr>
<th scope="row">Email</th>
<td>
<?php printf(
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('') . '">',
'lbry_new_channel_email',
); ?>
<p>Default is WordPress admin email</p>
</td>
</tr>
<tr>
<th scope="row">Language</th>
<td>
<?php printf(
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('') . '">',
'lbry_new_channel_prim_lang',
); ?>
<p>Primary language of the channel</p>
</td>
</tr>
<tr>
<th scope="row">Second Language</th>
<td>
<?php printf(
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('') . '">',
'lbry_new_channel_sec_lang',
); ?>
<p>Secondary language channel uses (if any)</p>
</td>
</tr>
<?php if ( $channel ) { ?>
<tr>
<th scope="row">Add LBC as Support</th>
<td>
<?php printf(
'<input type="number" step="0.001" min="0.01" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('%2$.3f') . '" required>',
'lbry_supports_add_bid_amount',
$bid_amount,
); ?>
<p>Current minimum support 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.01</p>
</td>
</tr>
<?php } else { ?>
<tr>
<th scope="row">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_add_bid_amount',
$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>
<?php } ?>
</tbody>
</table>
<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="Create New Channel"></p>
</form>
<?php
}

View file

@ -1,129 +0,0 @@
<?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 ( $_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 ( $_POST['lbry_channel_bid_amount'] ) {
$channel_bid = $_POST['lbry_channel_bid_amount'];
$clean_input['lbry_channel_bid_amount'] = number_format( floatval( $channel_bid ), 3, '.', '' );
}
$channel_list = LBRY()->daemon->channel_list();
if ( $channel_list ) { ?>
<table class="lbry-channel-table">
<thead>
<tr>
<th data-sort="channel">Channel</th>
<th data-sort="lbryurl">LBRY URL</th>
<th data-sort="claim">Claim ID</th>
<th data-sort="date">~ Date Created</th>
<th data-sort="posts">Posts</th>
<th data-sort="support" colspan="2">Supports</th>
</tr>
</thead>
<tbody>
<?php foreach ( $channel_list as $channel ):
$claim_id = $channel->claim_id;
$results = LBRY()->daemon->claim_search( $claim_id );
$lbry_url = $results->items[0]->canonical_url;
if ( $lbry_url ) {
$open_url = str_replace( 'lbry://', 'https://open.lbry.com/', $lbry_url );
}
$timestamp = $results->items[0]->meta->creation_timestamp;
$created_date = date( 'm-d-y', $timestamp );
$support_amount = $results->items[0]->meta->support_amount;
$claims_published = $results->items[0]->meta->claims_in_channel;
if ( ( $support_amount < 0.001 ) ) {
( $support_amount = '0' );
} elseif ( ( $support_amount < 0.01 ) && ( $support_amount >= 0.001 ) ) {
( $support_amount = '<0.01' );
} elseif ( ( $support_amount <= 0.099 ) && ( $support_amount >= 0.01) ) {
( $support_amount = number_format( floatval( $support_amount ), 2, '.', '' ) );
} elseif ( ( $support_amount <= 0.999 ) && ( $support_amount >= 0.1 ) ) {
( $support_amount = number_format( floatval( $support_amount ), 1, '.', '' ) );
} else {
( $support_amount = number_format( intval( $support_amount ) ) );
}
$init_bid = $results->items[0]->amount; ?>
<tr>
<td><a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channel-edit', 'claim_id' => urlencode( esc_html__( $claim_id, 'lbrypress' ) ), 'channel_name' => urlencode( esc_html__($channel->name, 'lbrypress' ) ), 'current_support' => urlencode( floatval($support_amount) ), 'init_bid' => urlencode( floatval($init_bid) ), 'lbry_url' => urlencode( esc_url($lbry_url) ) ), 'admin.php' ) ) ); ?>"><?php esc_html_e( $channel->name, 'lbrypress' ); ?></a></td>
<td><a href="<?php echo esc_url( $open_url, 'lbrypress' ); ?>"><?php esc_html_e( esc_url( $lbry_url ), 'lbrypress' ); ?></a></td>
<td><?php esc_html_e( $claim_id, 'lbrypress' ); ?></td>
<td><?php esc_html_e( $created_date, 'lbrypress' ); ?></td>
<td><?php esc_html_e( $claims_published, 'lbrypress' ); ?></td>
<td><span title="Initial Bid Amount: <?php esc_html_e( $init_bid, 'lbrypress' ); ?>"><img src="<?php echo esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png' ) ?>" class="icon icon-lbc bid-icon-lbc channel-bid-icon-lbc"><?php esc_html_e( $support_amount, 'lbrypress' ); ?></span></td>
<td><a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'supports', 'claim_id' => urlencode( esc_html__( $claim_id, 'lbrypress' ) ), 'supporting_channel' => urlencode( esc_html__($channel->name, 'lbrypress' ) ), 'current_support' => urlencode( floatval($support_amount) ), 'init_bid' => urlencode( floatval($init_bid) ), 'lbry_url' => urlencode( esc_url($lbry_url) ) ), 'admin.php' ) ) ); ?>">Add</a></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr><th colspan="7">LBRYPress</th></tr>
</tfoot>
</table>
<?php } else { ?>
<p>Looks like you haven't added any channels yet, feel free to do so below:</p>
<?php }
?>
<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( 'Quick Create a New Channel', 'lbrypress' ); ?></h3>
<p>Create a Channel that can be edited later to add details or set-up a complete <a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channel-edit' ), 'admin.php' ) ) ); ?>">Channel</a> now.</p>
<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.", 'lbrypress' ) ?> </p>
<?php
}

17
templates/help_page.php Normal file
View file

@ -0,0 +1,17 @@
<div class="wrap">
<h1><?= esc_html(get_admin_page_title()); ?></h1>
<h2>Installation</h2>
<p>The current supported release <a href="https://github.com/lbryio/lbry-sdk/releases/tag/v0.54.0" target="_blank">can be found here</a>. It contains pre-built binaries for macOS, Debian-based Linux, and Windows.<br>Simply download the proper daemon for your server's OS, extract it, and copy it to your WordPress installations root directory.</p>
<p>For ease of use, our plugin will automatically try to run and start the daemon if installed at the root of your Wordpress install, so its advised you keep it there.</p>
<p>If you want to have your daemon running at a location other than your Wordpress root, feel free to set up a CRON Job on your server that will start the daemon if its not already running.</p>
<h2>Usage</h2>
<p>By default, <code>lbrynet</code> will provide a JSON-RPC server at <code>http://localhost:5279</code>. This is the address our plugin will be expecting to use.</p>
<p>If curious, The full API is documented <a href="https://lbry.tech/api/sdk" target="_blank">here</a></p>
<p><a href="https://github.com/lbryio/lbry-sdk/blob/master/README.md" target="_blank">SDK Github</a></p>
<p><a href="https://lbry.com/" target="_blank">LBRY Home Page</a></p>
</div>

View file

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

View file

@ -1,137 +0,0 @@
<?php
/**
* ============================
* META BOX FOR POST PAGE
* Prints the post meta box
* @package LBRYPress
* ============================
*/
defined('ABSPATH') || die(); // Exit if accessed directly
$unnatributed = (object) array(
'name' => 'none (anonymous)',
'claim_id' => 'null'
);
$post_id = $post->ID;
// Generate a custom nonce
$lbrynonce = wp_create_nonce( 'lbry_publish_post_nonce' );
$lbry_published = get_post_meta( $post_id, '_lbry_is_published', true );
$lbry_claim_id = get_post_meta( $post_id, '_lbry_claim_id', true );
$lbry_published_channel = get_post_meta( $post_id, '_lbry_post_published_channel', true );
if ( ( $lbry_published == true ) && ( $lbry_claim_id ) && ( ! ( $lbry_published_channel ) ) ) {
$result = LBRY()->daemon->claim_search( $lbry_claim_id );
$name = $result->items[0]->signing_channel->name;
update_post_meta( $post_id, '_lbry_post_published_channel', $name );
}
$lbry_channel_claim_id = get_post_meta( $post_id, '_lbry_post_pub_channel', true );
$lbry_published_license = get_post_meta( $post_id, '_lbry_post_pub_license', true );
if ( ( $lbry_published == true ) && ( ( $lbry_claim_id ) ) && ( ! ( $lbry_published_license ) ) ) {
$result = LBRY()->daemon->claim_search( $lbry_claim_id );
$license = $result->items[0]->value->license;
update_post_meta( $post_id, '_lbry_post_pub_license', $license );
}
$lbry_canonical_url = get_post_meta( $post_id, '_lbry_canonical_url', true );
if ( ! $lbry_canonical_url ) {
$result = LBRY()->daemon->claim_search( $lbry_claim_id );
$lbry_canonical_url = $result->items[0]->canonical_url;
update_post_meta( $post_id, '_lbry_canonical_url', $lbry_canonical_url );
}
$lbry_url = $lbry_canonical_url;
$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'];
$chan_open_url = ( 'open.lbry.com/'. $lbry_published_channel .'#' . $lbry_channel_claim_id . '');
?>
<input type="hidden" id="_lbrynonce" name="_lbrynonce" value="<?php echo $lbrynonce ?>"><?php
if ( ( ( $will_publish == true ) && ( $lbry_channel_claim_id ) ) || ( ( ( $lbry_published == true ) || ( $lbry_claim_id ) || ( $lbry_published_channel ) ) && ( $lbry_published_license != null ) ) ) {
$results = LBRY()->daemon->claim_search( $lbry_claim_id );
$init_bid = $results->items[0]->amount;
$support_amount = $results->items[0]->meta->support_amount;
if ( ( $support_amount < 0.001 ) ) {
( $support_amount = '0' );
} elseif ( ( $support_amount < 0.01 ) && ( $support_amount >= 0.001 ) ) {
( $support_amount = '<0.01' );
} elseif ( ( $support_amount <= 0.099 ) && ( $support_amount >= 0.01) ) {
( $support_amount = number_format( floatval( $support_amount ), 2, '.', '' ) );
} elseif ( ( $support_amount <= 0.999 ) && ( $support_amount >= 0.1 ) ) {
( $support_amount = number_format( floatval( $support_amount ), 1, '.', '' ) );
} else {
( $support_amount = number_format( intval( $support_amount ) ) );
}
printf(
'<div class="lbry-meta-label lbry-meta-bx-channel"><strong>' . __( 'Initial bid amount:', 'lbrypress' ) . ' </strong>
<span class="lbry-meta-bx-content lbry-meta-bx-channel"><img src="' . esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) ) . 'admin/images/lbc.png" class="icon icon-lbc bid-icon-lbc bid-icon-lbc"> ' . esc_html__( '%1$s', 'lbrypress' ) . '</span></div>',
$init_bid
);
printf(
'<div class="lbry-meta-label lbry-meta-bx-channel"><strong>' . __( 'Supports:', 'lbrypress' ) . ' </strong>
<span class="lbry-meta-bx-content lbry-meta-bx-channel"><img src="' . esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) ) . 'admin/images/lbc.png" class="icon icon-lbc bid-icon-lbc bid-icon-lbc"> ' . esc_html__( '%1$s', 'lbrypress' ) . '</span><a href="' . esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'supports', 'post_id' => intval($post_id), 'claim_id' => esc_html__( '%2$s', 'lbrypress' ), 'lbry_url' => '%3$s', 'supporting_channel' => esc_html__( '%4$s', 'lbrypress' ), 'current_support' => '%5$.3f', 'init_bid' => '%6$.3f'), 'admin.php' ) ) ) . '">' . __( 'Add', 'lbrypress' ) . '</a></div>',
$support_amount,
urlencode( $lbry_claim_id ),
urlencode( esc_url( $lbry_url ) ),
urlencode( $lbry_published_channel ),
urlencode( $support_amount ),
urlencode( $init_bid )
);
printf(
'<div class="lbry-meta-label lbry-meta-bx-channel"><strong>' . __( 'LBRY channel published to:', 'lbrypress' ) . '</strong></div>
<div class="lbry-meta-bx-content lbry-meta-bx-channel"><a href="' . esc_url( '%1$s', 'lbrypress' ) . '">' . esc_html__( '%2$s', 'lbrypress' ) . '</a></div>',
$chan_open_url,
$lbry_published_channel,
);
printf(
'<div class="lbry-meta-label lbry-meta-bx-license"><strong>' . __( 'License published under:', 'lbrypress' ) .'</strong> </div>
<div class="lbry-meta-bx-content lbry-meta-bx-license lbry-meta-bx-content-last">' . esc_html__( '%1$s', 'lbrypress' ) . '</div>',
$lbry_published_license,
);
} else {
$channels = LBRY()->daemon->channel_list();
$channels[] = $unnatributed;
// Sort the channels in a natural way
usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) ); ?>
<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
);
}

42
templates/meta_box.php Normal file
View file

@ -0,0 +1,42 @@
<?php
$unnatributed = (object) array(
'name' => 'none (anonymous)',
'claim_id' => 'null'
);
$channels = LBRY()->daemon->channel_list();
$channels[] = $unnatributed;
// Sort the channels in a natural way
usort($channels, array('LBRYPress', 'channel_name_comp'));
$cur_channel = get_post_meta($post->ID, LBRY_POST_CHANNEL, true);
$will_publish = get_post_meta($post->ID, LBRY_WILL_PUBLISH, true);
?>
<?php wp_nonce_field('lbry_publish_channels', '_lbrynonce'); ?>
<div class="lbry-meta-checkbox-wrapper">
<label class="lbry-meta-label">
<input type="checkbox" class="lbry-meta-checkbox" name="<?= LBRY_WILL_PUBLISH ?>" value="true"
<?php
if ($will_publish === 'true' || $will_publish === '') {
echo 'checked';
}
?>
>
Sync this post on channel:
</label>
</div>
<select class="lbry-meta-select" name="<?= LBRY_POST_CHANNEL ?>">
<?php foreach ($channels as $index=>$channel): ?>
<option value="<?= $channel->claim_id ?>"
<?php
if ($cur_channel) {
if ($cur_channel === $channel->claim_id) {
echo 'selected';
}
} elseif ($index === 0) {
echo 'selected';
}
?>
>
<?= $channel->name ?>
</option>
<?php endforeach; ?>
</select>

View file

@ -1,70 +0,0 @@
<?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><img src="<?php echo esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png' ) ?>" class="icon icon-lbc wallet-icon-lbc" title="<?php echo esc_attr( number_format( $total_balance, 3, '.', ',' ) ); ?> Wallet Total Balance"><code title="<?php echo esc_attr( number_format( $total_balance, 3, '.', ',' ) ); ?> Wallet Total Balance"><?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>
<?php
if ( $lbry_active_tab == 'supports' ) {
$admin_url = admin_url( 'admin.php?page=lbrypress&tab=supports' );
printf(
'<a href="' . esc_url( $admin_url ) . '" class="nav-tab nav-tab-active">' . esc_html__( 'Supports', 'lbrypress') . '</a>',
$admin_url,
);
}
if ( $lbry_active_tab == 'channel-edit' ) {
$admin_url = admin_url( 'admin.php?page=lbrypress&tab=channel-edit' );
printf(
'<a href="' . esc_url( $admin_url ) . '" class="nav-tab nav-tab-active">' . esc_html__( 'Channel', 'lbrypress' ) . '</a>',
$admin_url,
);
} ?>
</nav>
<?php if ( $lbry_active_tab == 'channels' ) {
include_once( 'channels-page.php' );
} elseif ( $lbry_active_tab == 'supports' ) {
include_once( 'supports-add-form.php' );
} elseif ( $lbry_active_tab == 'channel-edit' ) {
include_once( 'channel-edit-page.php' );
} else {
?>
<form class="form-table" action="<?php echo esc_url( admin_url( 'options.php' ) ); ?>" method="post">
<?php // TODO: write this as a switch?
}
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( 'channels-page.php' );
} elseif ( $lbry_active_tab == 'supports' ) {
//include_once( 'supports-add-form.php' );
} elseif ( $lbry_active_tab == 'channel-edit' ) {
//include_once( 'supports-add-form.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

@ -0,0 +1,51 @@
<?php
$LBRY = LBRY();
$wallet_balance = $LBRY->daemon->wallet_balance();
$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>
<code><?= number_format($wallet_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

@ -1,28 +1,26 @@
<?php
defined('ABSPATH') || die(); // Exit if accessed directly
$lbry_url = get_post_meta( get_the_id(), LBRY_CANONICAL_URL, true );
if ( ! $lbry_url ) {
$url = get_post_meta(get_the_id(), LBRY_CANONICAL_URL, true);
if (!$url) {
// Get channel canonical for backwards compatibility
$channel_id = ( get_post_meta( get_the_id(), LBRY_POST_PUB_CHANNEL, true ) ? get_post_meta( get_the_id(), LBRY_POST_PUB_CHANNEL, true ) : get_post_meta( get_the_id(), '_lbry_channel', true ) );
$lbry_url = LBRY()->daemon->canonical_url( $channel_id );
$channel_id = get_post_meta(get_the_id(), LBRY_POST_CHANNEL, true);
$url = LBRY()->daemon->canonical_url($channel_id);
}
if ( $lbry_url ) {
$open_url = str_replace( 'lbry://', 'open.lbry.com/', $lbry_url );
if ($url) {
$url = str_replace('lbry://', 'lbry.tv/', $url);
}
?>
<div class="lbry-published-banner">
<h5>Stored Safely on Blockchain</h5>
<p>
This post is published to the <a href="https://lbry.com/get">LBRY</a> blockchain
<?php if( $lbry_url ) : ?>
at: <a href="<?php echo esc_url( $open_url ); ?>"><?php esc_html_e( $lbry_url, 'lbrypress' ); ?></a>.
This post is published to <a href="https://lbry.io/get">LBRY</a> blockchain
<?php if($url): ?>
at <a href="https://<?= $url ?>"><?= $url ?></a>.
<?php else: ?>
.
<?php endif; ?>
</p>
<p>
<a href="https://lbry.com/get" target="_blank">Try LBRY</a> to experience content freedom, earn crypto, and support us directly!
<a href="https://lbry.io/get" target="_blank">Try LBRY</a> to experience content freedom, earn crypto, and support The Anti-Media!
</p>
</div>

View file

@ -1,6 +1,3 @@
<?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>

View file

@ -1,101 +0,0 @@
<?php
/**
* ============================
* ADD SUPPORTS FORM ADMIN PAGE
* Uses the post-admin action and the $_POST global variable to build our cURL request
* @package LBRYPress
* ============================
*/
defined('ABSPATH') || die(); // Exit if accessed directly
if ( current_user_can( 'manage_options' ) ) {
// Generate a custom nonce
$lbrynonce = wp_create_nonce( 'add_supports_nonce' );
// TODO sanitize more
$claim_id = $_GET['claim_id'];
$claim_id = sanitize_text_field( $claim_id );
$lbry_url = $_GET['lbry_url'];
$lbry_url = urldecode($lbry_url);
$lbry_url = sanitize_text_field($lbry_url);
$init_bid = $_GET['init_bid'];
$init_bid = number_format( floatval( $init_bid ), 3, '.', '' );
$supporting_channel = $_GET['supporting_channel'];
$supporting_channel = sanitize_user( $supporting_channel );
$support_amount = $_GET['current_support'];
$support_amount = number_format( floatval( $support_amount ), 3, '.', '' );
$return_post = $_GET['post_id'];
$return_post = intval( $return_post );
// Build the page ?>
<form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post" id="lbry_add_supports_form">
<input type="hidden" name="action" value="lbry_add_supports">
<input type="hidden" name="_lbrynonce" value="<?php echo esc_attr($lbrynonce); ?>">
<input type="hidden" name="post_id" value="<?php echo esc_attr($return_post); ?>">
<input type="hidden" name="lbry_url" value="<?php echo esc_url($lbry_url); ?>">
<input type="hidden" name="supporting_channel" value="<?php echo esc_attr($supporting_channel); ?>">
<h2><?php echo _e( 'Add Supports to Claim:', 'lbrypress' ); ?></h2>
<?php printf(
'<h3>' . esc_html__( '%1$s', 'lbrypress' ) . '</h3>
<h4>Claim ID: <code>' . esc_html__( '%2$s', 'lbrypress' ) . '</code></h4><p>If you want to add supports to a different channel or post, use the channel or post link that corresponds with that specific claim to add supports.</p>',
$lbry_url,
$claim_id,
); ?>
<table class="form-table" role="presentation">
<tbody>
<tr>
<th scope="row">Claim ID</th>
<td>
<?php printf(
'<input type="text" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('%2$s') . '" required readonly>',
'lbry_supports_add_claim_id',
$claim_id,
); ?>
<p>Claims can be for either Channels or Posts</p>
</td>
</tr>
<tr>
<th scope="row">Add LBC as Support</th>
<td>
<?php printf(
'<input type="number" step="0.001" min="0.01" id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '" value="' . esc_attr('%2$.3f') . '" required>',
'lbry_supports_add_bid_amount',
$bid_amount,
); ?>
<p>Current minimum support 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.01</p>
</td>
</tr>
<tr>
<th scope=""row>Amount Used to Create Claim</th>
<td>
<?php printf(
'<p><img src="' . esc_attr( '%2$s', 'lbrypress' ) . '" class="icon icon-lbc bid-icon-lbc"> ' . esc_html__( '%1$.3f', 'lbrypress' ) . '</p><p>Initial bid that was used to publish the claim.</p>',
$init_bid,
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png',
); ?>
</td>
</tr>
<tr>
<th scope="row">Current Supports</th>
<td>
<?php printf(
'<p><img src="' . esc_attr( '%2$s', 'lbrypress' ) . '" class="icon icon-lbc bid-icon-lbc"> ' . esc_html__('%1$.3f', 'lbrypress' ) . '</p><p>May not include very recently added supports, please be patient as it may take a short while to update.</p>',
$support_amount,
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png',
); ?>
</td>
</tbody>
</table>
<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="Add Supports"></p>
</form>
<?php
} else {
?>
<p> <?php __( "You are not authorized to perform this operation.", 'lbrypress' ); ?> </p>
<?php
}

View file

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

View file

@ -4,7 +4,6 @@
*
* @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
View file

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