Whitespace & typos
This commit is contained in:
parent
9d2f01a37b
commit
bf183aac5a
8 changed files with 130 additions and 129 deletions
|
@ -64,7 +64,7 @@ class LBRYPress
|
||||||
*/
|
*/
|
||||||
public static function instance()
|
public static function instance()
|
||||||
{
|
{
|
||||||
if (is_null(self::$_instance)) {
|
if ( is_null( self::$_instance ) ) {
|
||||||
self::$_instance = new self();
|
self::$_instance = new self();
|
||||||
}
|
}
|
||||||
return self::$_instance;
|
return self::$_instance;
|
||||||
|
@ -77,7 +77,7 @@ class LBRYPress
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->define_constants();
|
$this->define_constants();
|
||||||
spl_autoload_register(array($this, 'lbry_autoload_register'));
|
spl_autoload_register( array( $this, 'lbry_autoload_register' ) );
|
||||||
$this->init();
|
$this->init();
|
||||||
$this->init_hooks();
|
$this->init_hooks();
|
||||||
}
|
}
|
||||||
|
@ -88,10 +88,10 @@ class LBRYPress
|
||||||
* @param string $name Constant name.
|
* @param string $name Constant name.
|
||||||
* @param string|bool $value Constant value.
|
* @param string|bool $value Constant value.
|
||||||
*/
|
*/
|
||||||
private function define($name, $value)
|
private function define( $name, $value )
|
||||||
{
|
{
|
||||||
if (! defined($name)) {
|
if ( ! defined( $name ) ) {
|
||||||
define($name, $value);
|
define( $name, $value );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,11 +130,11 @@ class LBRYPress
|
||||||
/**
|
/**
|
||||||
* Autoloader Registration
|
* Autoloader Registration
|
||||||
*/
|
*/
|
||||||
private function lbry_autoload_register($class)
|
private function lbry_autoload_register( $class )
|
||||||
{
|
{
|
||||||
$file_name = LBRY_ABSPATH . 'classes/' . $class . '.php';
|
$file_name = LBRY_ABSPATH . 'classes/' . $class . '.php';
|
||||||
|
|
||||||
if (file_exists($file_name)) {
|
if ( file_exists( $file_name ) ) {
|
||||||
require $file_name;
|
require $file_name;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ class LBRYPress
|
||||||
$this->speech = new LBRY_Speech();
|
$this->speech = new LBRY_Speech();
|
||||||
|
|
||||||
// Admin request
|
// Admin request
|
||||||
if (is_admin()) {
|
if ( is_admin() ) {
|
||||||
$this->admin = new LBRY_Admin();
|
$this->admin = new LBRY_Admin();
|
||||||
$this->notice = new LBRY_Admin_Notice();
|
$this->notice = new LBRY_Admin_Notice();
|
||||||
$this->network = new LBRY_Network();
|
$this->network = new LBRY_Network();
|
||||||
|
@ -161,15 +161,15 @@ class LBRYPress
|
||||||
*/
|
*/
|
||||||
private function init_hooks()
|
private function init_hooks()
|
||||||
{
|
{
|
||||||
register_activation_hook(LBRY_PLUGIN_FILE, array($this, 'activate'));
|
register_activation_hook( LBRY_PLUGIN_FILE, array( $this, 'activate' ) );
|
||||||
register_deactivation_hook(LBRY_PLUGIN_FILE, array($this, 'deactivate'));
|
register_deactivation_hook( LBRY_PLUGIN_FILE, array( $this, 'deactivate' ) );
|
||||||
|
|
||||||
// Banner output for published posts
|
// Banner output for published posts
|
||||||
// NOTE: move this to its own class to reduce clutter?
|
// 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 () {
|
add_action( 'wp_enqueue_scripts', function () {
|
||||||
wp_enqueue_style('lbry-css', plugins_url('/frontend/lbry.css', LBRY_PLUGIN_FILE));
|
wp_enqueue_style( 'lbry-css', plugins_url( '/frontend/lbry.css', LBRY_PLUGIN_FILE ) );
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,16 +181,16 @@ class LBRYPress
|
||||||
// TODO: Make sure errors are thrown if daemon can't be contacted, stop activation
|
// TODO: Make sure errors are thrown if daemon can't be contacted, stop activation
|
||||||
|
|
||||||
// Add options to the options table we need
|
// 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(
|
$option_defaults = array(
|
||||||
|
|
||||||
LBRY_LICENSE => $this->licenses[0],
|
LBRY_LICENSE => $this->licenses[0],
|
||||||
LBRY_LBC_PUBLISH => 1
|
LBRY_LBC_PUBLISH => 1
|
||||||
);
|
);
|
||||||
|
|
||||||
add_option(LBRY_SETTINGS, $option_defaults, false);
|
add_option( LBRY_SETTINGS, $option_defaults, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! get_option( LBRY_SPEECH_SETTINGS ) ) {
|
if ( ! get_option( LBRY_SPEECH_SETTINGS ) ) {
|
||||||
|
@ -221,26 +221,26 @@ class LBRYPress
|
||||||
public function deactivate()
|
public function deactivate()
|
||||||
{
|
{
|
||||||
// TODO: Stop the daemon
|
// TODO: Stop the daemon
|
||||||
error_log('Deactivated LBRYPress');
|
error_log( 'Deactivated LBRYPress' );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function published_on_lbry_banner($content)
|
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;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
global $post;
|
global $post;
|
||||||
if ($post->post_type != 'post') {
|
if ( $post->post_type != 'post' ) {
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!get_post_meta($post->ID, LBRY_WILL_PUBLISH, true)) {
|
if ( ! get_post_meta( $post->ID, LBRY_WILL_PUBLISH, true ) ) {
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
require(LBRY_ABSPATH . 'templates/published_on_lbry_banner.php');
|
require( LBRY_ABSPATH . 'templates/published_on_lbry_banner.php' );
|
||||||
$banner = ob_get_clean();
|
$banner = ob_get_clean();
|
||||||
|
|
||||||
return $content .= $banner;
|
return $content .= $banner;
|
||||||
|
|
|
@ -26,11 +26,11 @@ class LBRY_Admin
|
||||||
public function create_options_page()
|
public function create_options_page()
|
||||||
{
|
{
|
||||||
add_menu_page(
|
add_menu_page(
|
||||||
__('LBRYPress Settings', 'lbrypress'),
|
__( 'LBRYPress Settings', 'lbrypress' ),
|
||||||
__('LBRYPress', 'lbrypress'),
|
__( 'LBRYPress', 'lbrypress' ),
|
||||||
'manage_options',
|
'manage_options',
|
||||||
LBRY_ADMIN_PAGE,
|
LBRY_ADMIN_PAGE,
|
||||||
array($this, 'options_page_html'),
|
array( $this, 'options_page_html' ),
|
||||||
plugin_dir_url(LBRY_PLUGIN_FILE) . '/admin/images/lbry-logo.svg'
|
plugin_dir_url(LBRY_PLUGIN_FILE) . '/admin/images/lbry-logo.svg'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ class LBRY_Admin
|
||||||
{
|
{
|
||||||
// Get first available account address from Daemon
|
// Get first available account address from Daemon
|
||||||
$address = LBRY()->daemon->address_list();
|
$address = LBRY()->daemon->address_list();
|
||||||
$address = is_array($address) && !empty($address) ? $address[0]->address : '';
|
$address = is_array( $address ) && ! empty( $address ) ? $address[0]->address : '';
|
||||||
printf(
|
printf(
|
||||||
'<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" readonly />',
|
'<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" readonly />',
|
||||||
LBRY_WALLET,
|
LBRY_WALLET,
|
||||||
|
@ -264,11 +264,11 @@ class LBRY_Admin
|
||||||
$options = '';
|
$options = '';
|
||||||
// Create options list, select current license
|
// Create options list, select current license
|
||||||
//
|
//
|
||||||
foreach (LBRY()->licenses as $value => $name) {
|
foreach ( LBRY()->licenses as $value => $name ) {
|
||||||
$selected = $this->options[LBRY_LICENSE] === $value;
|
$selected = $this->options[LBRY_LICENSE] === $value;
|
||||||
|
|
||||||
$options .= '<option value="' . $value . '"';
|
$options .= '<option value="' . $value . '"';
|
||||||
if ($selected) {
|
if ( $selected ) {
|
||||||
$options .= ' selected';
|
$options .= ' selected';
|
||||||
}
|
}
|
||||||
$options .= '>'. $name . '</option>';
|
$options .= '>'. $name . '</option>';
|
||||||
|
@ -398,7 +398,7 @@ class LBRY_Admin
|
||||||
if (!get_transient('lbry_wallet_warning_email')) {
|
if (!get_transient('lbry_wallet_warning_email')) {
|
||||||
$email = get_option('admin_email');
|
$email = get_option('admin_email');
|
||||||
$subject = 'Your LBRYPress Wallet Balance is Low!';
|
$subject = 'Your LBRYPress Wallet Balance is Low!';
|
||||||
$message = "You LBRY Wallet for your wordpress installation at " . site_url() . " is running very low.\r\n\r\nYou currently have " . $balance . ' LBC left in your wallet. In order to keep publishing to the LBRY network, please add some LBC to your account.';
|
$message = "Your LBRY Wallet for your WordPress installation at " . site_url() . " is running very low.\r\n\r\nYou currently have " . $balance . ' LBC left in your wallet. In order to keep publishing to the LBRY network, please add some LBC to your account.';
|
||||||
wp_mail($email, $subject, $message);
|
wp_mail($email, $subject, $message);
|
||||||
set_transient('lbry_wallet_warning_email', true, DAY_IN_SECONDS);
|
set_transient('lbry_wallet_warning_email', true, DAY_IN_SECONDS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,10 @@
|
||||||
|
|
||||||
class LBRY_Admin_Notice
|
class LBRY_Admin_Notice
|
||||||
{
|
{
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
add_action('admin_notices', array($this, 'admin_notices'));
|
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,12 +18,12 @@ class LBRY_Admin_Notice
|
||||||
*/
|
*/
|
||||||
public function admin_notices()
|
public function admin_notices()
|
||||||
{
|
{
|
||||||
if (get_transient('lbry_notices')) {
|
if ( get_transient( 'lbry_notices' ) ) {
|
||||||
$notices = get_transient('lbry_notices');
|
$notices = get_transient( 'lbry_notices' );
|
||||||
foreach ($notices as $key => $notice) {
|
foreach ( $notices as $key => $notice ) {
|
||||||
$this->create_admin_notice($notice);
|
$this->create_admin_notice( $notice );
|
||||||
}
|
}
|
||||||
delete_transient('lbry_notices');
|
delete_transient( 'lbry_notices' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ class LBRY_Admin_Notice
|
||||||
* Sets transients for admin errors
|
* Sets transients for admin errors
|
||||||
*/
|
*/
|
||||||
// TODO: Make sure we only set one transient at a time per error
|
// 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(
|
$notice = array(
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
|
@ -38,24 +39,24 @@ class LBRY_Admin_Notice
|
||||||
'is_dismissible' => $is_dismissible
|
'is_dismissible' => $is_dismissible
|
||||||
);
|
);
|
||||||
|
|
||||||
if (! get_transient('lbry_notices')) {
|
if (! get_transient( 'lbry_notices' ) ) {
|
||||||
set_transient('lbry_notices', array($notice));
|
set_transient( 'lbry_notices', array( $notice ) );
|
||||||
} else {
|
} else {
|
||||||
$notices = get_transient('lbry_notices');
|
$notices = get_transient( 'lbry_notices' );
|
||||||
$notices[] = $notice;
|
$notices[] = $notice;
|
||||||
set_transient('lbry_notices', $notices);
|
set_transient( 'lbry_notices', $notices );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints an admin notice
|
* Prints an admin notice
|
||||||
*/
|
*/
|
||||||
private function create_admin_notice($notice)
|
private function create_admin_notice( $notice )
|
||||||
{
|
{
|
||||||
$class = 'notice notice-' . $notice['status'];
|
$class = 'notice notice-' . $notice['status'];
|
||||||
if ($notice['is_dismissible']) {
|
if ( $notice['is_dismissible'] ) {
|
||||||
$class .= ' is-dismissible';
|
$class .= ' is-dismissible';
|
||||||
}
|
}
|
||||||
printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), esc_html($notice['message']));
|
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $notice['message'] ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,11 @@ class LBRY_Daemon
|
||||||
public function wallet_unused_address()
|
public function wallet_unused_address()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$result = $this->request('address_unused');
|
$result = $this->request( 'address_unused' );
|
||||||
return $result->result;
|
return $result->result;
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch ( LBRYDaemonException $e ) {
|
||||||
$this->logger->log('address_unused error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log( 'address_unused error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||||
LBRY()->notice->set_notice('error', 'Issue getting unused address.');
|
LBRY()->notice->set_notice( 'error', 'Issue getting unused address.' );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,19 +50,18 @@ class LBRY_Daemon
|
||||||
* @param int $page Pagination page number
|
* @param int $page Pagination page number
|
||||||
* @return array Array of address lists linked to this account
|
* @return array Array of address lists linked to this account
|
||||||
*/
|
*/
|
||||||
public function address_list($page = 1)
|
public function address_list( $page = 1 ) {
|
||||||
{
|
|
||||||
// Get 20 per page
|
// Get 20 per page
|
||||||
$params = array(
|
$params = array(
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
'page_size' => 20
|
'page_size' => 20
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
$result = $this->request('address_list', $params);
|
$result = $this->request( 'address_list', $params );
|
||||||
return $result->result->items;
|
return $result->result->items;
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch ( LBRYDaemonException $e ) {
|
||||||
$this->logger->log('address_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log( 'address_list error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||||
LBRY()->notice->set_notice('error', 'Issue getting address list.');
|
LBRY()->notice->set_notice( 'error', 'Issue getting address list.' );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,13 +70,13 @@ class LBRY_Daemon
|
||||||
* Returns the available balance of a current LBRY account
|
* Returns the available balance of a current LBRY account
|
||||||
* https://lbry.tech/api/sdk#wallet_balance
|
* https://lbry.tech/api/sdk#wallet_balance
|
||||||
* @param string $address Wallet Address
|
* @param string $address Wallet Address
|
||||||
* @return array $wallet_balance Wallet Balance
|
* @return object $wallet_balance Wallet Balance
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function wallet_balance()
|
public function wallet_balance()
|
||||||
{
|
{
|
||||||
try { // Convert JSON string to an object
|
try { // Convert JSON string to an object
|
||||||
$result = $this->request('wallet_balance');
|
$result = $this->request( 'wallet_balance' );
|
||||||
return $result;
|
return $result;
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch (LBRYDaemonException $e) {
|
||||||
$this->logger->log('wallet_balance error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log('wallet_balance error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||||
|
@ -92,7 +91,7 @@ class LBRY_Daemon
|
||||||
* @param int $page Pagination page number
|
* @param int $page Pagination page number
|
||||||
* @return array claim dictionary or null if empty
|
* @return array claim dictionary or null if empty
|
||||||
*/
|
*/
|
||||||
public function channel_list($page = 1)
|
public function channel_list( $page = 1 )
|
||||||
{
|
{
|
||||||
$params = array(
|
$params = array(
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
|
@ -100,11 +99,11 @@ class LBRY_Daemon
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = $this->request('channel_list', $params)->result->items;
|
$result = $this->request( 'channel_list', $params )->result->items;
|
||||||
return empty($result) ? null : $result;
|
return empty( $result ) ? null : $result;
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch ( LBRYDaemonException $e ) {
|
||||||
$this->logger->log('channel_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log( 'channel_list error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||||
LBRY()->notice->set_notice('error', 'Issue retrieving channel list.');
|
LBRY()->notice->set_notice( 'error', 'Issue retrieving channel list.' );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,17 +113,18 @@ class LBRY_Daemon
|
||||||
* https://lbry.tech/api/sdk#channel_create
|
* https://lbry.tech/api/sdk#channel_create
|
||||||
* @return array dictionary containing result of the request
|
* @return array dictionary containing result of the request
|
||||||
*/
|
*/
|
||||||
public function channel_new($channel_name, $channel_bid)
|
|
||||||
|
public function channel_new( $channel_name, $channel_bid )
|
||||||
{
|
{
|
||||||
// TODO: Sanitize channel name and bid
|
// TODO: Sanitize channel name and bid
|
||||||
// Make sure no @ sign, as we will add that
|
// Make sure no @ sign, as we will add that
|
||||||
if (strpos($channel_name, '@')) {
|
if ( strpos( $channel_name, '@' ) ) {
|
||||||
throw new \Exception('Illegal character "@" in channel name', 1);
|
throw new \Exception( 'Illegal character "@" in channel name', 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// No white space allowed
|
// No white space allowed
|
||||||
if (strpos($channel_name, ' ')) {
|
if ( strpos( $channel_name, ' ' ) ) {
|
||||||
throw new \Exception("No spaces allowed in channel name", 1);
|
throw new \Exception( "No spaces allowed in channel name", 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
$channel_name = '@' . $channel_name;
|
$channel_name = '@' . $channel_name;
|
||||||
|
@ -142,8 +142,8 @@ class LBRY_Daemon
|
||||||
return $result->result;
|
return $result->result;
|
||||||
|
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch (LBRYDaemonException $e) {
|
||||||
$this->logger->log('channel_new error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log( 'channel_new error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||||
throw new \Exception('Issue creating new channel.', 1);
|
throw new \Exception( 'Issue creating new channel.', 1 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,9 +153,9 @@ class LBRY_Daemon
|
||||||
* @param string $claim_id
|
* @param string $claim_id
|
||||||
* @return string Canonical URL, null if not found
|
* @return string Canonical URL, null if not found
|
||||||
*/
|
*/
|
||||||
public function canonical_url($claim_id = null)
|
public function canonical_url( $claim_id = null )
|
||||||
{
|
{
|
||||||
if (!$claim_id) {
|
if ( ! $claim_id ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,13 +169,13 @@ class LBRY_Daemon
|
||||||
);
|
);
|
||||||
|
|
||||||
$items = $result->result->items;
|
$items = $result->result->items;
|
||||||
if (!$items) {
|
if ( ! $items ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $items[0]->canonical_url;
|
return $items[0]->canonical_url;
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch ( LBRYDaemonException $e ) {
|
||||||
$this->logger->log('canonical_url error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log( 'canonical_url error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,18 +190,18 @@ class LBRY_Daemon
|
||||||
*
|
*
|
||||||
* @return object $result
|
* @return object $result
|
||||||
*/
|
*/
|
||||||
public function publish($args)
|
public function publish( $args )
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$result = $this->request(
|
$result = $this->request(
|
||||||
'publish',
|
'publish',
|
||||||
$args
|
$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;
|
return $result->result;
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch ( LBRYDaemonException $e ) {
|
||||||
$this->logger->log('publish error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log('publish error', $e->getMessage() . ' | Code: ' . $e->getCode() );
|
||||||
LBRY()->notice->set_notice('error', 'Issue publishing / updating post to LBRY Network.');
|
LBRY()->notice->set_notice( 'error', 'Issue publishing / updating post to LBRY Network.' );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,52 +212,52 @@ class LBRY_Daemon
|
||||||
* @param array $params The Parameters to send the LBRY API Call
|
* @param array $params The Parameters to send the LBRY API Call
|
||||||
* @return string The cURL response
|
* @return string The cURL response
|
||||||
*/
|
*/
|
||||||
private function request($method, $params = array())
|
private function request( $method, $params = array() )
|
||||||
{
|
{
|
||||||
// JSONify our request data
|
// JSONify our request data
|
||||||
$data = array(
|
$data = array(
|
||||||
'method' => $method,
|
'method' => $method,
|
||||||
'params' => $params
|
'params' => $params
|
||||||
);
|
);
|
||||||
$data = json_encode($data);
|
$data = json_encode( $data );
|
||||||
|
|
||||||
// Send it via curl
|
// Send it via curl
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, $this->address);
|
curl_setopt( $ch, CURLOPT_URL, $this->address );
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt( $ch, CURLOPT_POST, true );
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' ) );
|
||||||
curl_setopt($ch, CURLOPT_AUTOREFERER, false);
|
curl_setopt( $ch, CURLOPT_AUTOREFERER, false );
|
||||||
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
|
||||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
curl_setopt( $ch, CURLOPT_HEADER, 0 );
|
||||||
|
|
||||||
$result = curl_exec($ch);
|
$result = curl_exec( $ch );
|
||||||
$response_code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
|
$response_code = curl_getinfo( $ch, CURLINFO_RESPONSE_CODE );
|
||||||
curl_close($ch);
|
curl_close( $ch );
|
||||||
|
|
||||||
if ($response_code != '200') {
|
if ( $response_code != '200' ) {
|
||||||
$this->logger->log("Damon Connection Issue", "Daemon connection returned response code $response_code");
|
$this->logger->log( "Damon Connection Issue", "Daemon connection returned response code $response_code" );
|
||||||
throw new LBRYDaemonException("Daemon Connection Issue", $response_code);
|
throw new LBRYDaemonException( "Daemon Connection Issue", $response_code );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$result = json_decode($result);
|
$result = json_decode( $result );
|
||||||
$this->check_for_errors($result);
|
$this->check_for_errors( $result );
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks for erros in decoded daemon response and throws an exception if it finds one
|
* Checks for errors in decoded daemon response and throws an exception if it finds one
|
||||||
* @param $response
|
* @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;
|
$message = $response->error->message;
|
||||||
$code = $response->error->code;
|
$code = $response->error->code;
|
||||||
$this->logger->log("Daemon error code $code", $message);
|
$this->logger->log( "Daemon error code $code", $message );
|
||||||
throw new LBRYDaemonException($message, $code);
|
throw new LBRYDaemonException( $message, $code );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
class LBRY_Daemon_Logger
|
class LBRY_Daemon_Logger
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The directory to log to
|
* The directory to log to
|
||||||
* @var string
|
* @var string
|
||||||
|
|
|
@ -62,7 +62,7 @@ class LBRY_Network
|
||||||
* @param WP_Post $post The Post Object we are saving
|
* @param WP_Post $post The Post Object we are saving
|
||||||
* @return int Returns post_id if user cannot edit post
|
* @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') {
|
if ($post->post_type != 'post') {
|
||||||
return;
|
return;
|
||||||
|
@ -103,7 +103,7 @@ class LBRY_Network
|
||||||
* Returns the HTML for the LBRY Meta Box
|
* Returns the HTML for the LBRY Meta Box
|
||||||
* @param WP_POST $post
|
* @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');
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,44 +17,44 @@ class LBRY_Network_Publisher
|
||||||
{
|
{
|
||||||
// Get converted markdown into a file
|
// Get converted markdown into a file
|
||||||
$filepath = LBRY_ABSPATH . 'tmp/' . $post->post_name . time() . '.md';
|
$filepath = LBRY_ABSPATH . 'tmp/' . $post->post_name . time() . '.md';
|
||||||
$file = fopen($filepath, 'w');
|
$file = fopen( $filepath, 'w' );
|
||||||
$converted = LBRY()->network->parser->convert_to_markdown($post);
|
$converted = LBRY()->network->parser->convert_to_markdown( $post );
|
||||||
$write_status = $file && fwrite($file, $converted);
|
$write_status = $file && fwrite( $file, $converted );
|
||||||
fclose($file);
|
fclose( $file );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!$write_status) {
|
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
|
// If everything went well with the conversion, carry on
|
||||||
$args = array(
|
$args = array(
|
||||||
'name' => $post->post_name,
|
'name' => $post->post_name,
|
||||||
'bid' => number_format(floatval(get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH]), 2, '.', ''),
|
'bid' => number_format( floatval( get_option( LBRY_SETTINGS )[LBRY_LBC_PUBLISH] ), 3, '.', '' ),
|
||||||
'file_path' => $filepath,
|
'file_path' => $filepath,
|
||||||
'title' => $post->post_title,
|
'title' => $post->post_title,
|
||||||
'languages' => array(substr(get_locale(), 0, 2)),
|
'languages' => array( substr( get_locale(), 0, 2 ) ),
|
||||||
'license' => get_option(LBRY_SETTINGS)[LBRY_LICENSE]
|
'license' => get_option(LBRY_SETTINGS)[LBRY_LICENSE]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Setup channel
|
// Setup channel
|
||||||
if ($channel && $channel != 'null') {
|
if ( $channel && $channel != 'null' ) {
|
||||||
$args['channel_id'] = $channel;
|
$args['channel_id'] = $channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup featured image
|
// Setup featured image
|
||||||
$featured_id = get_post_thumbnail_id($post);
|
$featured_id = get_post_thumbnail_id( $post );
|
||||||
$featured_image = wp_get_attachment_image_src($featured_id, 'medium');
|
$featured_image = wp_get_attachment_image_src( $featured_id, 'medium' );
|
||||||
|
|
||||||
if ($featured_image[0]) {
|
if ( $featured_image[0] ) {
|
||||||
$args['thumbnail_url'] = $featured_image[0];
|
$args['thumbnail_url'] = $featured_image[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup Tags
|
// Setup Tags
|
||||||
$tags = get_the_terms( $post, 'post_tag' );
|
$tags = get_the_terms( $post, 'post_tag' );
|
||||||
if ($tags) {
|
if ( $tags ) {
|
||||||
$tag_names = [];
|
$tag_names = [];
|
||||||
foreach ($tags as $tag) {
|
foreach ( $tags as $tag ) {
|
||||||
$tag_names[] = $tag->name;
|
$tag_names[] = $tag->name;
|
||||||
}
|
}
|
||||||
$args['tags'] = $tag_names;
|
$args['tags'] = $tag_names;
|
||||||
|
@ -62,35 +62,35 @@ class LBRY_Network_Publisher
|
||||||
|
|
||||||
// Build description using Yoast if installed and its used, excerpt/title otherwise
|
// Build description using Yoast if installed and its used, excerpt/title otherwise
|
||||||
$description = false;
|
$description = false;
|
||||||
if (class_exists('WPSEO_META')) {
|
if ( class_exists( 'WPSEO_META' ) ) {
|
||||||
$description = WPSEO_META::get_value('opengraph-description', $post->ID);
|
$description = WPSEO_META::get_value( 'opengraph-description', $post->ID );
|
||||||
}
|
}
|
||||||
if (!$description) {
|
if ( ! $description ) {
|
||||||
$excerpt = get_the_excerpt($post);
|
$excerpt = get_the_excerpt( $post );
|
||||||
$description = $excerpt ? $excerpt : $post->post_title;
|
$description = $excerpt ? $excerpt : $post->post_title;
|
||||||
}
|
}
|
||||||
$description .= ' | Originally published at ' . get_permalink($post);
|
$description .= ' | Originally published at ' . get_permalink( $post );
|
||||||
|
|
||||||
$args['description'] = $description;
|
$args['description'] = $description;
|
||||||
|
|
||||||
$result = LBRY()->daemon->publish($args);
|
$result = LBRY()->daemon->publish( $args );
|
||||||
$outputs = $result->outputs;
|
$outputs = $result->outputs;
|
||||||
|
|
||||||
if ($outputs && is_array($outputs)) {
|
if ( $outputs && is_array( $outputs ) ) {
|
||||||
$output = $result->outputs[0];
|
$output = $result->outputs[0];
|
||||||
$claim_id = $output->claim_id;
|
$claim_id = $output->claim_id;
|
||||||
// Set Claim ID
|
// Set Claim ID
|
||||||
update_post_meta($post->ID, LBRY_CLAIM_ID, $claim_id);
|
update_post_meta( $post->ID, LBRY_CLAIM_ID, $claim_id );
|
||||||
|
|
||||||
// Set Canonical URL
|
// Set Canonical URL
|
||||||
$canonical_url = LBRY()->daemon->canonical_url($claim_id);
|
$canonical_url = LBRY()->daemon->canonical_url( $claim_id );
|
||||||
update_post_meta($post->ID, LBRY_CANONICAL_URL, $canonical_url);
|
update_post_meta( $post->ID, LBRY_CANONICAL_URL, $canonical_url );
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} 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 {
|
} finally {
|
||||||
//Delete the temporary markdown file
|
//Delete the temporary markdown file
|
||||||
unlink($filepath);
|
unlink( $filepath );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,4 +45,3 @@ $channel_list = $LBRY->daemon->channel_list();
|
||||||
?>
|
?>
|
||||||
</form>
|
</form>
|
||||||
</div><!-- wrap -->
|
</div><!-- wrap -->
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue