better logic when show selects,

rv daemon call if not needed
This commit is contained in:
Lem Smyth 2022-02-17 13:47:54 -06:00
parent 3626ce993c
commit 099cdc6fdf
3 changed files with 78 additions and 59 deletions

View file

@ -34,7 +34,7 @@
} }
.lbry-meta-wrapper-last { .lbry-meta-wrapper-last {
padding: 0em .8em 1.2em; padding: 0em .8em 1.5em;
} }
.lbry-meta-label { .lbry-meta-label {

View file

@ -90,26 +90,38 @@ class LBRY_Network
} }
$channel = $_POST[LBRY_POST_PUB_CHANNEL]; $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 ) ); $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]; $license = $_POST[LBRY_POST_PUB_LICENSE];
$cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true ); $cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true );
$will_publish = $_POST[LBRY_WILL_PUBLISH]; $will_publish = $_POST[LBRY_WILL_PUBLISH];
// Update meta acordingly // Update meta acordingly
if ( $channel !== $cur_channel ) { if ( ( $channel ) && ( $channel !== $cur_channel ) && ( $channel != null || $channel != '' ) ) {
update_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, $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 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 ) ) ) { } elseif ( $channel === $cur_channel && ( $cur_channel === get_post_meta( $post_id, '_lbry_channel', true ) ) ) {
update_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, $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 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 !== $cur_license ) { 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 ); update_post_meta( $post_id, LBRY_POST_PUB_LICENSE, $license );
} }
if ( ( $will_publish ) && ( $will_publish == 1 ) && $post->post_status == 'publish') { $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 // Publish the post on the LBRY Network
$this->publisher->publish( $post, $channel, $license ); $this->publisher->publish( $post, $pub_channel, $pub_license );
} }
} }
@ -127,32 +139,34 @@ class LBRY_Network
$lbry_claim_id = get_post_meta( $post_id, '_lbry_claim_id', true ); $lbry_claim_id = get_post_meta( $post_id, '_lbry_claim_id', true );
if ( $_GET['action'] === 'edit' ) { 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 ) ) ) { 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 ); $canonical_url = LBRY()->daemon->canonical_url( $lbry_claim_id );
update_post_meta( $post_id, '_lbry_canonical_url', $canonical_url ); 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' );
}
} }
} }
if ( ( get_post_meta( $post_id, '_lbry_will_publish', true ) == true ) && (isset( $lbry_claim_id ) ) ) {
update_post_meta( $post_id, '_lbry_is_published', true );
}
$lbry_published = get_post_meta( $post_id, '_lbry_is_published', true );
$lbry_url = ( get_post_meta( $post_id, '_lbry_canonical_url', true ) );
$lbry_url = ( get_post_meta( $post_id, '_lbry_canonical_url', true ) );
if ($lbry_url) { if ($lbry_url) {
$open_url = str_replace('lbry://', 'open.lbry.com/', $lbry_url ); $open_url = str_replace('lbry://', 'open.lbry.com/', $lbry_url );
} }
$default_value = get_option( LBRY_SETTINGS )['lbry_default_publish_setting']; $lbry_published = get_post_meta( $post_id, '_lbry_is_published', true );
$new_value = get_post_meta( $post_id, LBRY_WILL_PUBLISH, true ); $will_publish = get_post_meta( $post_id, '_lbry_will_publish', true );
if ( ( $new_value ) ? $new_value : $new_value = $default_value ); $lbry_post_pub_channel = get_post_meta( $post_id, '_lbry_post_pub_channel', true );
$value = $new_value; if ( ( $will_publish ) ? $will_publish : $will_publish = get_option( LBRY_SETTINGS )['lbry_default_publish_setting'] );
if ( ( $value ) ? $value : 0 ); if ( ( $_GET['action'] === 'edit' ) ? $value = $lbry_published : $value = $will_publish );
$checked = checked( $value, true, false );
// nonce set on page meta-box.php // nonce set on page meta-box.php
if ( ( $lbry_published ) && ( ( $lbry_url) || ( $lbry_claim_id ) ) ) { if ( ( ( $will_publish == true ) && ( $lbry_post_pub_channel ) ) || ( ( ( $lbry_published ) || ( $lbry_claim_id ) ) && ( ( $lbry_url != null ) || ( $lbry_claim_id ) ) ) ) {
printf( printf(
'<hr class="lbry-hr-meta"> '<hr class="lbry-hr-meta">
<div class="misc-pub-section lbry-meta-published-lbry-wrapper"> <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> <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>
<div class="misc-pub-section lbry-url-meta-wrapper"> <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> <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>
@ -161,22 +175,22 @@ class LBRY_Network
<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> <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>
<div class="misc-pub-section lbry-meta-checkbox-wrapper lbry-meta-wrapper-last"> <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') . '"> <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>', </div>',
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png', plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png',
$open_url, $open_url,
$lbry_url, $lbry_url,
$lbry_claim_id, $lbry_claim_id,
checked( $value, true, false ), $checked,
LBRY_WILL_PUBLISH LBRY_WILL_PUBLISH
); );
} else { } else {
printf ( printf (
'<div class="misc-pub-section lbry-meta-checkbox-wrapper lbry-meta-wrapper-last"> '<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> LBRY </strong></span><input type="checkbox" class="lbry-meta-checkbox" value="1"' . esc_attr('%2$s') . ' name="' . esc_attr('%3$s') . '"> <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>', </div>',
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png', plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png',
checked( $value, true, false ), $checked,
LBRY_WILL_PUBLISH LBRY_WILL_PUBLISH
); );
} }

View file

@ -18,25 +18,25 @@ $lbrynonce = wp_create_nonce( 'lbry_publish_post_nonce' );
$lbry_published = get_post_meta( $post_id, '_lbry_is_published', true ); $lbry_published = get_post_meta( $post_id, '_lbry_is_published', true );
$lbry_claim_id = get_post_meta( $post_id, '_lbry_claim_id', 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 ); $lbry_published_channel = get_post_meta( $post_id, '_lbry_post_published_channel', true );
if ( ! ( $lbry_published_channel ) ) { if ( ( $lbry_published == true ) && ( $lbry_claim_id ) && ( ! ( $lbry_published_channel ) ) ) {
LBRY()->daemon->claim_search( $lbry_claim_id ); $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_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 ); $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 );
}
$channels = LBRY()->daemon->channel_list();
$channels[] = $unnatributed;
$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 ) ); $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']; $default_channel = get_option( LBRY_SETTINGS )['default_lbry_channel'];
$chan_open_url = ( 'open.lbry.com/'. $lbry_published_channel .'#' . $lbry_channel_claim_id . ''); $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' ) );
?> ?>
<input type="hidden" id="_lbrynonce" name="_lbrynonce" value="<?php echo $lbrynonce ?>"><?php <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 ) ) ) { if ( ( ( $will_publish == true ) && ( $lbry_channel_claim_id ) ) || ( ( ( $lbry_published == true ) || ( $lbry_claim_id ) || ( $lbry_published_channel ) ) && ( $lbry_published_license != null ) ) ) {
@ -70,32 +70,37 @@ usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) );
$chan_open_url, $chan_open_url,
$lbry_published_license, $lbry_published_license,
); );
} else { ?> } else {
<div><label for="LBRY_POST_PUB_CHANNEL" class="lbry-meta-bx-label lbry-meta-bx-channel"><?php $channels = LBRY()->daemon->channel_list();
$channels[] = $unnatributed;
// Sort the channels in a natural way
usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) ); ?>
esc_html_e( 'Channel to Publish:', 'lbrypress' ); ?> </label></div><?php <div><label for="LBRY_POST_PUB_CHANNEL" class="lbry-meta-bx-label lbry-meta-bx-channel"><?php
$options = ''; esc_html_e( 'Channel to Publish:', 'lbrypress' ); ?> </label></div><?php
if ( $channels ) {
foreach ( $channels as $index=>$channel ) { $options = '';
$options .= '<option class="lbry-meta-bx-option lbry-meta-option-channel" value="' . esc_attr( $channel->claim_id ) . '"'; if ( $channels ) {
if ( ( $cur_channel ) ? $cur_channel : $cur_channel = $default_channel ) { foreach ( $channels as $index=>$channel ) {
$options .= selected( $cur_channel, $channel->claim_id, false ); $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
);
} }
$options .= '>' . esc_html__( $channel->name, 'lbrypress' ) . '</option>'; ?>
} <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
printf( $licenses = LBRY()->licenses;
'<select id="' . esc_attr('%1$s') . '" name="' . esc_attr('%1$s') . '">' . esc_html('%2$s') . '</select>', $options = '';
LBRY_POST_PUB_CHANNEL, $default_license = get_option(LBRY_SETTINGS)[LBRY_LICENSE];
$options $cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true );
);
}
?>
<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 // Create options list, select current license
if ( $licenses ) { if ( $licenses ) {