Updated the way the post meta box publishes, using select and checkbox instead of checkbox array
This commit is contained in:
parent
8bc336952d
commit
c9a156bb9b
5 changed files with 105 additions and 58 deletions
|
@ -82,29 +82,36 @@ class LBRY_Daemon
|
|||
|
||||
/**
|
||||
* Publishes a post to the LBRY Network
|
||||
* @param [type] $name [description]
|
||||
* @param [type] $bid [description]
|
||||
* @param [type] $filepath [description]
|
||||
* @param [type] $title [description]
|
||||
* @param [type] $description [description]
|
||||
* @param [type] $language [description]
|
||||
* @return [type] [description]
|
||||
* @param string $name The slug for the post
|
||||
* @param float $bid The amount of LBC to bid
|
||||
* @param string $filepath The path of the temporary content file
|
||||
* @param string $title The Title of the post
|
||||
* @param string $description The Description of the Post
|
||||
* @param string $language Two letter ISO Code of the language
|
||||
* @return string $channel The Claim ID of the Channel
|
||||
*/
|
||||
public function publish($name, $bid, $filepath, $title, $description, $language, $channel)
|
||||
{
|
||||
$args = array(
|
||||
'name' => $name,
|
||||
'bid' => $bid,
|
||||
'file_path' => $filepath,
|
||||
'title' => $title,
|
||||
'description' => $description,
|
||||
'language' => $language,
|
||||
);
|
||||
|
||||
// Make sure we aren't publishing to unattributed
|
||||
if ($channel != 'null') {
|
||||
$args['channel_id'] = $channel;
|
||||
}
|
||||
|
||||
// TODO: Bring thumbnails into the mix
|
||||
$result = $this->request(
|
||||
'publish',
|
||||
array(
|
||||
'name' => $name,
|
||||
'bid' => $bid,
|
||||
'file_path' => $filepath,
|
||||
'title' => $title,
|
||||
'description' => $description,
|
||||
'language' => $language,
|
||||
'channel_name' => $channel
|
||||
)
|
||||
$args
|
||||
);
|
||||
|
||||
$this->check_for_errors($result);
|
||||
return $result;
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ class LBRY_Network
|
|||
*/
|
||||
public function add_meta_boxes()
|
||||
{
|
||||
// TODO: Support post types based on user selection
|
||||
add_meta_box(
|
||||
'lbry-network-publishing', // Unique ID
|
||||
'LBRY Network', // Title
|
||||
|
@ -60,6 +61,9 @@ class LBRY_Network
|
|||
|
||||
/**
|
||||
* Handles saving the post meta that is relative to publishing to the LBRY Network
|
||||
* @param int $post_id The ID of the post we are saving
|
||||
* @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)
|
||||
{
|
||||
|
@ -74,23 +78,30 @@ class LBRY_Network
|
|||
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);
|
||||
$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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
// Update meta acordingly
|
||||
if (!$will_publish) {
|
||||
update_post_meta($post_id, LBRY_WILL_PUBLISH, 'false');
|
||||
} else {
|
||||
update_post_meta($post_id, LBRY_WILL_PUBLISH, 'true');
|
||||
}
|
||||
if ($new_channel !== $cur_channel) {
|
||||
update_post_meta($post_id, LBRY_POST_CHANNEL, $new_channel);
|
||||
}
|
||||
|
||||
// Publish the post on the LBRY Network
|
||||
$this->publisher->publish($post, $new_channels);
|
||||
if ($will_publish) {
|
||||
// Publish the post on the LBRY Network
|
||||
$this->publisher->publish($post, get_post_meta($post_id, LBRY_POST_CHANNEL, true));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML for the LBRY Meta Box
|
||||
* @param [type] $post [description]
|
||||
*/
|
||||
public function meta_box_html($post)
|
||||
{
|
||||
require_once(LBRY_ABSPATH . 'templates/meta_box.php');
|
||||
|
|
|
@ -17,12 +17,12 @@ class LBRY_Network_Publisher
|
|||
/**
|
||||
* 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
|
||||
* @param string $channel The Claim ID of the channel we are posting to
|
||||
*/
|
||||
public function publish($post, $channels)
|
||||
public function publish($post, $channel)
|
||||
{
|
||||
// Leave if nothing to publish to
|
||||
if (!$channels) {
|
||||
if (!$channel) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ class LBRY_Network_Publisher
|
|||
$featured_image = get_the_post_thumbnail($post);
|
||||
|
||||
$name = $post->post_name;
|
||||
$bid = get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH];
|
||||
$bid = floatval(get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH]);
|
||||
$title = $post->post_title;
|
||||
$language = substr(get_locale(), 0, 2);
|
||||
$license = get_option(LBRY_SETTINGS)[LBRY_LICENSE];
|
||||
|
@ -49,9 +49,7 @@ class LBRY_Network_Publisher
|
|||
// TODO: Bring thumbnails into the mix
|
||||
// $thumbnail = $featured_image ? $featured_image : null;
|
||||
|
||||
foreach ($channels as $channel) {
|
||||
LBRY()->daemon->publish($name, $bid, $filepath, $title, $description, $language, $channel);
|
||||
}
|
||||
LBRY()->daemon->publish($name, $bid, $filepath, $title, $description, $language, $channel);
|
||||
}
|
||||
} finally {
|
||||
// Delete the temporary markdown file
|
||||
|
|
|
@ -66,7 +66,6 @@ class LBRYPress
|
|||
spl_autoload_register(array($this, 'lbry_autoload_register'));
|
||||
$this->init();
|
||||
$this->init_hooks();
|
||||
error_log("language: " . get_locale());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,6 +101,8 @@ class LBRYPress
|
|||
$this->define('LBRY_SPEECH', 'lbry_speech'); // the spee.ch address
|
||||
$this->define('LBRY_LICENSE', 'lbry_license'); // the license to publish with to the LBRY network
|
||||
$this->define('LBRY_LBC_PUBLISH', 'lbry_lbc_publish'); // amount of lbc to use per publish
|
||||
$this->define('LBRY_WILL_PUBLISH', 'lbry_will_publish'); // The meta key for if to publish to LBRY Network or not
|
||||
$this->define('LBRY_POST_CHANNEL', 'lbry_channel'); // The meta key for which channel to publish
|
||||
$this->define('LBRY_AVAILABLE_LICENSES', array(
|
||||
'mit' => 'MIT',
|
||||
'license2' => 'License 2',
|
||||
|
@ -192,4 +193,19 @@ class LBRYPress
|
|||
{
|
||||
error_log('Deactivated');
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility Functions
|
||||
*/
|
||||
public static function channel_name_comp($a, $b)
|
||||
{
|
||||
if ($a->name === $b->name) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($b->name == '(none / unattributed)') {
|
||||
return -1;
|
||||
}
|
||||
return strnatcasecmp($a->name, $b->name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,43 @@
|
|||
<?php
|
||||
$LBRY = LBRY();
|
||||
$unnatributed = (object) array(
|
||||
'name' => 'unattributed',
|
||||
'name' => '(none / unattributed)',
|
||||
'claim_id' => 'null'
|
||||
);
|
||||
// TODO: Test what happens with empty channel list, can't remember the return value
|
||||
$channels = LBRY()->daemon->channel_list();
|
||||
array_unshift($channels, $unnatributed);
|
||||
$cur_channels = get_post_meta($post->ID, 'lbry_channels');
|
||||
$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'); ?>
|
||||
<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->name ?>"
|
||||
<?php if (in_array($channel->name, $cur_channels)): ?>
|
||||
checked="true"
|
||||
<?php endif; ?>
|
||||
>
|
||||
<?= $channel->name ?>
|
||||
</label>
|
||||
<br />
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
<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>
|
||||
|
|
Loading…
Reference in a new issue