If published meta box (#65)

Meta box changed to show lbry canonical url for published post,
Change option selects for channel and license to static once post is published.

removed isset check from _lbry_post_published_license
This commit is contained in:
Lemuel Smyth 2022-02-16 14:52:43 -06:00 committed by GitHub
parent 623ff37c6e
commit bc23888458
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 203 additions and 94 deletions

View file

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

@ -120,11 +120,27 @@ class LBRY_Network
public function publish_to_lbry_checkbox( $post ) public function publish_to_lbry_checkbox( $post )
{ {
$post_id = $post->ID;
if ( get_post_type( $post_id ) != 'post' ) { if ( get_post_type( $post_id ) != 'post' ) {
return $post; return $post;
} }
$post_id = $post->ID;
$lbry_claim_id = get_post_meta( $post_id, '_lbry_claim_id', true );
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 ) ) ) {
$canonical_url = LBRY()->daemon->canonical_url( $lbry_claim_id );
update_post_meta( $post_id, '_lbry_canonical_url', $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 ) );
if ($lbry_url) {
$open_url = str_replace('lbry://', 'open.lbry.com/', $lbry_url );
}
$default_value = get_option( LBRY_SETTINGS )['lbry_default_publish_setting']; $default_value = get_option( LBRY_SETTINGS )['lbry_default_publish_setting'];
$new_value = get_post_meta( $post_id, LBRY_WILL_PUBLISH, true ); $new_value = get_post_meta( $post_id, LBRY_WILL_PUBLISH, true );
if ( ( $new_value ) ? $new_value : $new_value = $default_value ); if ( ( $new_value ) ? $new_value : $new_value = $default_value );
@ -132,17 +148,38 @@ class LBRY_Network
if ( ( $value ) ? $value : 0 ); if ( ( $value ) ? $value : 0 );
// nonce set on page meta-box.php // nonce set on page meta-box.php
printf ( if ( ( $lbry_published ) && ( ( $lbry_url) || ( $lbry_claim_id ) ) ) {
'<div class="lbry-meta-checkbox-wrapper lbry-meta-checkbox-wrapper-last"> printf(
<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') . '"> '<hr class="lbry-hr-meta">
</div>', <div class="misc-pub-section lbry-meta-published-lbry-wrapper">
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png', <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>
'Publish to', </div>
'LBRY', <div class="misc-pub-section lbry-url-meta-wrapper">
'lbrypress', <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>
checked( $value, true, false ), </div>
LBRY_WILL_PUBLISH <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 // Set Claim ID
update_post_meta( $post->ID, LBRY_CLAIM_ID, $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 ( ( $published_license ) && ( $published_license !== null ) ) {
update_post_meta( $post->ID, '_lbry_post_published_license', $published_license );
}
// 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 );
// Set _lbry_is_published to true
update_post_meta( $post->ID, '_lbry_is_published', true );
} }
} 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() );

View file

@ -12,58 +12,80 @@ $unnatributed = (object) array(
'name' => 'none (anonymous)', 'name' => 'none (anonymous)',
'claim_id' => 'null' 'claim_id' => 'null'
); );
$post_id = $post->ID;
// Generate a custom nonce // Generate a custom nonce
$lbrynonce = wp_create_nonce( 'lbry_publish_post_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 = LBRY()->daemon->channel_list();
$channels[] = $unnatributed; $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 ) ); $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 . '');
// Sort the channels in a natural way // Sort the channels in a natural way
usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) ); usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) );
?> ?>
<section> <input type="hidden" id="_lbrynonce" name="_lbrynonce" value="<?php echo $lbrynonce ?>"><?php
<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
$options = ''; if ( ( ( $lbry_published == true ) || ( $lbry_published_channel ) ) && ( $lbry_published_license != null) ) {
if ( $channels ) { printf(
foreach ( $channels as $index=>$channel ) { '<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>',
$options .= '<option class="lbry-meta-bx-option lbry-meta-option-channel" value="' . esc_attr( $channel->claim_id ) . '"'; $lbry_published_channel,
if ( isset( $cur_channel ) ? $cur_channel : $cur_channel = $default_channel ) { $chan_open_url,
$options .= selected( $cur_channel, $channel->claim_id, false ); $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
);
} }
$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
$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 );
} }
printf( $options .= '>'. esc_html__( $name, 'lbrypress' ) . '</option>';
'<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(
printf( '<select class="" id="'.esc_attr('%1$s').'" name="'. esc_attr('%1$s') .'">' . esc_html('%2$s') . '</select>',
'<select class="" id="'.esc_attr('%1$s').'" name="'. esc_attr('%1$s') .'">' . esc_html('%2$s') . '</select>', LBRY_POST_PUB_LICENSE,
LBRY_POST_PUB_LICENSE, $options
$options );
); }
?>
</section>