commit
c4c818b820
5 changed files with 131 additions and 6 deletions
|
@ -7,10 +7,92 @@
|
||||||
|
|
||||||
class LBRY_Network
|
class LBRY_Network
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Publishing Object
|
||||||
|
* @var LBRY_Network_Publisher
|
||||||
|
*/
|
||||||
|
public $publisher = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Parsing Object
|
||||||
|
* @var LBRY_Network_Parser
|
||||||
|
*/
|
||||||
|
public $parser = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [__construct description]
|
* [__construct description]
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
$this->publisher = new LBRY_Network_Publisher();
|
||||||
|
$this->parser = new LBRY_Network_Parser();
|
||||||
|
|
||||||
|
$this->post_meta_setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up everything for the post meta boxes
|
||||||
|
*/
|
||||||
|
private function post_meta_setup()
|
||||||
|
{
|
||||||
|
// Add the meta boxes
|
||||||
|
add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
|
||||||
|
|
||||||
|
// Save the post meta on 'save_post' hook
|
||||||
|
add_action('save_post', array($this, 'save_post_meta'), 10, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the meta boxes to the post editing backend
|
||||||
|
*/
|
||||||
|
public function add_meta_boxes()
|
||||||
|
{
|
||||||
|
add_meta_box(
|
||||||
|
'lbry-network-publishing', // Unique ID
|
||||||
|
'LBRY Network', // Title
|
||||||
|
array($this, 'meta_box_html'), // Callback function
|
||||||
|
'post', // Screen Options (or post type)
|
||||||
|
'side', // Context
|
||||||
|
'high' // Priority
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles saving the post meta that is relative to publishing to the LBRY Network
|
||||||
|
*/
|
||||||
|
public function save_post_meta($post_id, $post)
|
||||||
|
{
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
$meta_key = 'lbry_channels';
|
||||||
|
$new_channels = (isset($_POST[$meta_key]) ? $_POST[$meta_key] : null);
|
||||||
|
$cur_channels = get_post_meta($post_id, $meta_key);
|
||||||
|
|
||||||
|
// COMBAK: Make this a bit more efficent if they have lots of channels
|
||||||
|
// Start with clean meta, then add new channels if there are any
|
||||||
|
delete_post_meta($post_id, $meta_key);
|
||||||
|
if ($new_channels) {
|
||||||
|
foreach ($new_channels as $channel) {
|
||||||
|
add_post_meta($post_id, $meta_key, $channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Publish the post on the LBRY Network
|
||||||
|
$this->publisher->publish($post, $new_channels);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function meta_box_html($post)
|
||||||
|
{
|
||||||
|
require_once(LBRY_ABSPATH . 'templates/meta_box.php');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,16 @@ class LBRY_Network_Publisher
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publish the post to the LBRY Network
|
||||||
|
* @param int $post_id The ID of the post we are publishing
|
||||||
|
* @param array $channels An array of channels we are publishing to
|
||||||
|
*/
|
||||||
|
public function publish($post, $channels)
|
||||||
|
{
|
||||||
|
$name = $post->post_name;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,11 @@ class LBRYPress
|
||||||
*/
|
*/
|
||||||
public $notice = null;
|
public $notice = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Library Network Object
|
||||||
|
*/
|
||||||
|
public $network = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main LBRYPress Instance.
|
* Main LBRYPress Instance.
|
||||||
*
|
*
|
||||||
|
@ -123,7 +128,6 @@ class LBRYPress
|
||||||
{
|
{
|
||||||
$this->daemon = new LBRY_Daemon();
|
$this->daemon = new LBRY_Daemon();
|
||||||
$this->speech = new LBRY_Speech();
|
$this->speech = new LBRY_Speech();
|
||||||
$this->notice = new LBRY_Admin_Notice();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,6 +141,8 @@ class LBRYPress
|
||||||
// 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->network = new LBRY_Network();
|
||||||
} else {
|
} else {
|
||||||
$this->speech->maybe_rewrite_urls();
|
$this->speech->maybe_rewrite_urls();
|
||||||
}
|
}
|
||||||
|
|
29
templates/meta_box.php
Normal file
29
templates/meta_box.php
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
$LBRY = LBRY();
|
||||||
|
$unnatributed = (object) array(
|
||||||
|
'name' => 'Unattributed',
|
||||||
|
'permanent_url' => 'unattributed'
|
||||||
|
);
|
||||||
|
$channels = LBRY()->daemon->channel_list();
|
||||||
|
array_unshift($channels, $unnatributed);
|
||||||
|
$cur_channels = get_post_meta($post->ID, 'lbry_channels');
|
||||||
|
?>
|
||||||
|
<?php wp_nonce_field('lbry_publish_channels', '_lbrynonce'); ?>
|
||||||
|
<h4>Choose which channels you would like to publish this post to:</h4>
|
||||||
|
<ul class="categorychecklist">
|
||||||
|
<?php if ($channels): ?>
|
||||||
|
<?php foreach ($channels as $channel): ?>
|
||||||
|
<li>
|
||||||
|
<label class="selectit">
|
||||||
|
<input type="checkbox" name="lbry_channels[]" value="<?= $channel->permanent_url ?>"
|
||||||
|
<?php if (in_array($channel->permanent_url, $cur_channels)): ?>
|
||||||
|
checked="true"
|
||||||
|
<?php endif; ?>
|
||||||
|
>
|
||||||
|
<?= $channel->name ?>
|
||||||
|
</label>
|
||||||
|
<br />
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</ul>
|
|
@ -2,14 +2,12 @@
|
||||||
$LBRY = LBRY();
|
$LBRY = LBRY();
|
||||||
$wallet_balance = $LBRY->daemon->wallet_balance();
|
$wallet_balance = $LBRY->daemon->wallet_balance();
|
||||||
$channel_list = $LBRY->daemon->channel_list();
|
$channel_list = $LBRY->daemon->channel_list();
|
||||||
|
// TODO: Make this page look cleaner
|
||||||
?>
|
?>
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
|
|
||||||
<h1><?= esc_html(get_admin_page_title()); ?></h1>
|
<h1><?= esc_html(get_admin_page_title()); ?></h1>
|
||||||
|
|
||||||
<h2>Your wallet amount:</h2>
|
<h2>Your wallet amount:</h2>
|
||||||
<code><?= number_format($wallet_balance, 2, '.', ','); ?></code>
|
<code><?= number_format($wallet_balance, 2, '.', ','); ?></code>
|
||||||
|
|
||||||
<form action="options.php" method="post">
|
<form action="options.php" method="post">
|
||||||
<?php
|
<?php
|
||||||
settings_fields(LBRY_SETTINGS_GROUP);
|
settings_fields(LBRY_SETTINGS_GROUP);
|
||||||
|
@ -17,7 +15,6 @@ $channel_list = $LBRY->daemon->channel_list();
|
||||||
submit_button('Save Settings');
|
submit_button('Save Settings');
|
||||||
?>
|
?>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<h2>Your Publishable Channels</h2>
|
<h2>Your Publishable Channels</h2>
|
||||||
<?php if ($channel_list): ?>
|
<?php if ($channel_list): ?>
|
||||||
<ul class="lbry-channel-list">
|
<ul class="lbry-channel-list">
|
||||||
|
@ -28,7 +25,6 @@ $channel_list = $LBRY->daemon->channel_list();
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<p>Looks like you haven't added any channels yet, feel free to do so below:</p>
|
<p>Looks like you haven't added any channels yet, feel free to do so below:</p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<h2>Add a new channel to publish to:</h2>
|
<h2>Add a new channel to publish to:</h2>
|
||||||
<form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post">
|
<form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post">
|
||||||
<?php wp_nonce_field('lbry_add_channel', '_lbrynonce'); ?>
|
<?php wp_nonce_field('lbry_add_channel', '_lbrynonce'); ?>
|
||||||
|
|
Loading…
Reference in a new issue