mv channel table to channels-page

This commit is contained in:
Lem Smyth 2022-02-20 21:09:40 -06:00
parent 0af8b712eb
commit a1dba8bea7
2 changed files with 61 additions and 58 deletions

View file

@ -267,61 +267,7 @@ class LBRY_Admin
*/
public function available_channels_callback()
{
$channel_list = LBRY()->daemon->channel_list();
if ( $channel_list ) { ?>
<table class="lbry-channel-table">
<thead>
<tr>
<th data-sort="channel">Channel</th>
<th data-sort="lbryurl">LBRY URL</th>
<th data-sort="claim">Claim ID</th>
<th data-sort="date">~ Date Created</th>
<th data-sort="posts">Posts</th>
<th data-sort="support" colspan="2">Supports</th>
</tr>
</thead>
<tbody>
<?php foreach ( $channel_list as $channel ):
$claim_id = $channel->claim_id;
$results = LBRY()->daemon->claim_search( $claim_id );
$lbry_url = $results->items[0]->canonical_url;
if ( $lbry_url ) {
$open_url = str_replace( 'lbry://', 'open.lbry.com/', $lbry_url );
}
$timestamp = $results->items[0]->meta->creation_timestamp;
$created_date = date( 'm-d-y', $timestamp );
$support_amount = $results->items[0]->meta->support_amount;
$claims_published = $results->items[0]->meta->claims_in_channel;
if ( ( $support_amount < 0.001 ) ) {
( $support_amount = '0' );
} elseif ( ( $support_amount < 0.01 ) && ( $support_amount >= 0.001 ) ) {
( $support_amount = '<0.01' );
} elseif ( ( $support_amount <= 0.099 ) && ( $support_amount >= 0.01) ) {
( $support_amount = number_format( floatval( $support_amount ), 2, '.', '' ) );
} elseif ( ( $support_amount <= 0.999 ) && ( $support_amount >= 0.1 ) ) {
( $support_amount = number_format( floatval( $support_amount ), 1, '.', '' ) );
} else {
( $support_amount = number_format( intval( $support_amount ) ) );
}
$init_bid = $results->items[0]->amount; ?>
<tr>
<td><a href="<?php echo esc_url( $open_url, 'lbrypress' ); ?>"><?php esc_html_e( $channel->name, 'lbrypress' ); ?></a></td>
<td><?php esc_html_e( $lbry_url, 'lbrypress' ); ?></td>
<td><?php esc_html_e( $claim_id, 'lbrypress' ); ?></td>
<td><?php esc_html_e( $created_date, 'lbrypress' ); ?></td>
<td><?php esc_html_e( $claims_published, 'lbrypress' ); ?></td>
<td><span title="Initial Bid Amount: <?php esc_html_e( $init_bid, 'lbrypress' ); ?>"><img src="<?php echo esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png' ) ?>" class="icon icon-lbc bid-icon-lbc channel-bid-icon-lbc"><?php esc_html_e( $support_amount, 'lbrypress' ); ?></span></td>
<td><a href="<?php echo admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'supports', 'claim_id' => $claim_id, 'current_support' => $support_amount, 'init_bid' => $init_bid, 'lbry_url' => urlencode($lbry_url), 'return_page' => 'channels' ), 'admin.php' ) ); ?>">Add</a></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr><th colspan="7">LBRYPress</th></tr>
</tfoot>
</table>
<?php } else { ?>
<p>Looks like you haven't added any channels yet, feel free to do so below:</p>
<?php }
// Moved to channels-page.php
}
/**

View file

@ -17,8 +17,9 @@ if ( current_user_can( 'manage_options' ) ) {
?>
<h3><?php _e( 'Available Channels To Publish', 'lbrypress' ); ?></h3>
<?php LBRY()->admin->available_channels_callback(); ?>
<?php if ( isset( $_POST['lbry_new_channel'] ) ) {
<?php //LBRY()->admin->available_channels_callback(); ?>
<?php
if ( isset( $_POST['lbry_new_channel'] ) ) {
$channel = $_POST['lbry_new_channel'];
$channel = str_replace( '@', '', $channel );
$channel = str_replace( ' ', '-', $channel );
@ -28,6 +29,62 @@ if ( current_user_can( 'manage_options' ) ) {
$channel_bid = $_POST['lbry_channel_bid_amount'];
$clean_input['lbry_channel_bid_amount'] = number_format( floatval( $channel_bid ), 3, '.', '' );
}
$channel_list = LBRY()->daemon->channel_list();
if ( $channel_list ) { ?>
<table class="lbry-channel-table">
<thead>
<tr>
<th data-sort="channel">Channel</th>
<th data-sort="lbryurl">LBRY URL</th>
<th data-sort="claim">Claim ID</th>
<th data-sort="date">~ Date Created</th>
<th data-sort="posts">Posts</th>
<th data-sort="support" colspan="2">Supports</th>
</tr>
</thead>
<tbody>
<?php foreach ( $channel_list as $channel ):
$claim_id = $channel->claim_id;
$results = LBRY()->daemon->claim_search( $claim_id );
$lbry_url = $results->items[0]->canonical_url;
if ( $lbry_url ) {
$open_url = str_replace( 'lbry://', 'open.lbry.com/', $lbry_url );
}
$timestamp = $results->items[0]->meta->creation_timestamp;
$created_date = date( 'm-d-y', $timestamp );
$support_amount = $results->items[0]->meta->support_amount;
$claims_published = $results->items[0]->meta->claims_in_channel;
if ( ( $support_amount < 0.001 ) ) {
( $support_amount = '0' );
} elseif ( ( $support_amount < 0.01 ) && ( $support_amount >= 0.001 ) ) {
( $support_amount = '<0.01' );
} elseif ( ( $support_amount <= 0.099 ) && ( $support_amount >= 0.01) ) {
( $support_amount = number_format( floatval( $support_amount ), 2, '.', '' ) );
} elseif ( ( $support_amount <= 0.999 ) && ( $support_amount >= 0.1 ) ) {
( $support_amount = number_format( floatval( $support_amount ), 1, '.', '' ) );
} else {
( $support_amount = number_format( intval( $support_amount ) ) );
}
$init_bid = $results->items[0]->amount; ?>
<tr>
<td><a href="<?php echo esc_url( $open_url, 'lbrypress' ); ?>"><?php esc_html_e( $channel->name, 'lbrypress' ); ?></a></td>
<td><?php esc_html_e( $lbry_url, 'lbrypress' ); ?></td>
<td><?php esc_html_e( $claim_id, 'lbrypress' ); ?></td>
<td><?php esc_html_e( $created_date, 'lbrypress' ); ?></td>
<td><?php esc_html_e( $claims_published, 'lbrypress' ); ?></td>
<td><span title="Initial Bid Amount: <?php esc_html_e( $init_bid, 'lbrypress' ); ?>"><img src="<?php echo esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png' ) ?>" class="icon icon-lbc bid-icon-lbc channel-bid-icon-lbc"><?php esc_html_e( $support_amount, 'lbrypress' ); ?></span></td>
<td><a href="<?php echo admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'supports', 'claim_id' => $claim_id, 'supporting_channel' => $channel->name, 'current_support' => $support_amount, 'init_bid' => $init_bid, 'lbry_url' => urlencode($lbry_url) ), 'admin.php' ) ); ?>">Add</a></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr><th colspan="7">LBRYPress</th></tr>
</tfoot>
</table>
<?php } else { ?>
<p>Looks like you haven't added any channels yet, feel free to do so below:</p>
<?php }
?>
<form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post" id="lbry_add_channel_form">
@ -66,6 +123,6 @@ if ( current_user_can( 'manage_options' ) ) {
<?php
} else {
?>
<p> <?php __( "You are not authorized to perform this operation.", $this->plugin_name ) ?> </p>
<p> <?php __( "You are not authorized to perform this operation.", 'lbrypress' ) ?> </p>
<?php
}