meta-box-change-after-post-published

This commit is contained in:
Lem Smyth 2022-02-16 12:35:00 -06:00
parent e54b3034d2
commit c65c7bc9a5
4 changed files with 185 additions and 92 deletions

View file

@ -1,47 +1,82 @@
/**
* Stylesheet for the admin options page
* 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;
}
.wallet-icon-lbc {
height: 1.8em;
margin-right: .5em;
margin-bottom: -.5em;
}
.lbry-pub-metabox {
margin: 0 0 0 -.2em;
padding: 0 .2em 0 0 ;
}
.meta-icon-lbry {
height: 1.55em;
margin-bottom: -.4em;
padding-left: .1em;
}
.lbry-meta-checkbox-wrapper {
padding: .5em .8em .6em;
}
.lbry-meta-checkbox-wrapper-last {
padding: .5em .8em 1.5em;
}
.lbry-meta-label {
padding-left: .3em;
padding-right: .6em;
}
.bid-icon-lbc {
height: 1.2em;
margin-bottom: -.2em;
}
.lbry-meta-bx-label {
margin: .5em .8em .6em;
}
.lbry-pub-metabox {
margin: 0 0 0 -.2em;
padding: 0 .2em 0 0 ;
}
.meta-icon-lbry {
height: 1.55em;
margin-bottom: -.4em;
padding-left: .1em;
}
.lbry-meta-checkbox-wrapper {
padding: .5em .8em .6em;
}
.lbry-meta-bx-option {
padding: .5em .8em .6em;
}
.lbry-meta-bx-option-last {
padding: .5em .8em 1.5em;
}
.lbry-meta-wrapper-last {
padding: 0em .8em 1.2em;
}
.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: darkgreen;
}
.post-lbry-display {
color: green;
}
.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;
}

View file

@ -132,17 +132,38 @@ class LBRY_Network
if ( ( $value ) ? $value : 0 );
// nonce set on page meta-box.php
printf (
'<div class="lbry-meta-checkbox-wrapper lbry-meta-checkbox-wrapper-last">
<span class="lbry-pub-metabox"><img src="' . __( '%1$s', '%4$s' ) . '" class="icon icon-lbry meta-icon-lbry"></span><label class="lbry-meta-label">' . esc_html__('%2$s', '%4$s' ) . ' <strong>' . esc_html__('%3$s', '%4$s') . '</strong></label><input type="checkbox" class="lbry-meta-checkbox" value="1"' . esc_attr('%5$s') . ' name="' . esc_attr('%6$s') . '">
</div>',
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png',
'Publish to',
'LBRY',
'lbrypress',
checked( $value, true, false ),
LBRY_WILL_PUBLISH
);
if ( ( $lbry_published ) && ( ( $lbry_url) || ( $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><strong>' . esc_html__('LBRY', 'lbrypress') . '</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( $value, true, false ),
LBRY_WILL_PUBLISH
);
} 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: <strong>' . esc_html__('LBRY', 'lbrypress') . '</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( $value, true, false ),
LBRY_WILL_PUBLISH
);
}
}
/**

View file

@ -84,9 +84,24 @@ class LBRY_Network_Publisher
// 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 ( isset( $published_license ) && ( $published_license !== null ) ) {
update_post_meta( $post->ID, '_lbry_post_published_license', $published_license );
}
// 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 );
}
} catch (Exception $e) {
error_log( 'Issue publishing post ' . $post->ID . ' to LBRY: ' . $e->getMessage() );

View file

@ -12,58 +12,80 @@ $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_url = get_post_meta( $post_id, '_lbry_canonical_url', true );
$lbry_published_channel = get_post_meta( $post_id, '_lbry_post_published_channel', true );
if ( ! ( $lbry_published_channel ) ) {
LBRY()->daemon->claim_search( $lbry_claim_id );
}
$lbry_channel_claim_id = get_post_meta( $post_id, '_lbry_post_pub_channel', true );
//if ( $lbry_channel_claim_id === null ? 'Anonymously' : $lbry_channel_claim_id);
$lbry_published_license = get_post_meta( $post_id, '_lbry_post_pub_license', true );
$channels = LBRY()->daemon->channel_list();
$channels[] = $unnatributed;
$post_id = $post->ID;
$cur_channel = ( get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) ? get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) : get_post_meta( $post_id, '_lbry_channel', true ) );
$default_channel = get_option( LBRY_SETTINGS )['default_lbry_channel'];
$chan_open_url = ( 'open.lbry.com/'. $lbry_published_channel .'#' . $lbry_channel_claim_id . '');
// Sort the channels in a natural way
usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) );
?>
<section>
<input type="hidden" id="_lbrynonce" name="_lbrynonce" value="<?php echo $lbrynonce ?>">
<div><label for="LBRY_POST_PUB_CHANNEL" class="lbry-meta-bx-label lbry-meta-bx-channel"><?php esc_html_e( 'Channel to Publish: ', 'lbrypress' ); ?></label></div><?php
<input type="hidden" id="_lbrynonce" name="_lbrynonce" value="<?php echo $lbrynonce ?>"><?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 ( isset( $cur_channel ) ? $cur_channel : $cur_channel = $default_channel ) {
$options .= selected( $cur_channel, $channel->claim_id, false );
if ( ( ( $lbry_published == true ) || ( $lbry_published_channel ) ) && ( $lbry_published_license != null) ) {
printf(
'<div class="lbry-meta-label lbry-meta-bx-channel"><strong>' . __( 'LBRY channel published at:', 'lbrypress' ) . '</strong> <div class="lbry-meta-bx-content lbry-meta-bx-channel"><a href="' . esc_url( '%2$s', 'lbrypress' ) . '">' . esc_html__( '%1$s', 'lbrypress' ) . '</a></div><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__( '%3$s', 'lbrypress' ) . '</div></div>',
$lbry_published_channel,
$chan_open_url,
$lbry_published_license,
);
} else { ?>
<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>';
}
}
$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 ( isset( $cur_license ) ? $cur_license : $cur_license = $default_license ) {
$options .= selected( $cur_license, $value, false );
}
$options .= '>'. esc_html__( $name, 'lbrypress' ) . '</option>';
}
}
printf(
'<select class="" id="'.esc_attr('%1$s').'" name="'. esc_attr('%1$s') .'">' . esc_html('%2$s') . '</select>',
LBRY_POST_PUB_LICENSE,
$options
);
?>
</section>
printf(
'<select class="" id="'.esc_attr('%1$s').'" name="'. esc_attr('%1$s') .'">' . esc_html('%2$s') . '</select>',
LBRY_POST_PUB_LICENSE,
$options
);
}