You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.9 KiB
94 lines
2.9 KiB
<?php |
|
/** |
|
* @package Aldine |
|
*/ |
|
|
|
namespace Aldine\Admin; |
|
|
|
use PressbooksMix\Assets; |
|
use Pressbooks\DataCollector\Book as BookDataCollector; |
|
use Pressbooks\BookDirectory; |
|
use Pressbooks\Admin\Network\SharingAndPrivacyOptions; |
|
|
|
/** |
|
* Uses old option to provide a simpler upgrade path from pressbooks-publisher theme |
|
*/ |
|
const BLOG_OPTION = 'pressbooks_publisher_in_catalog'; |
|
|
|
/** |
|
* @param string $hook |
|
*/ |
|
function admin_scripts( $hook ) { |
|
if ( 'sites.php' !== $hook ) { |
|
return; |
|
} |
|
|
|
$assets = new Assets( 'pressbooks-aldine', 'theme' ); |
|
$assets->setSrcDirectory( 'assets' )->setDistDirectory( 'dist' ); |
|
wp_enqueue_script( 'pressbooks-aldine-admin', $assets->getPath( 'scripts/catalog-admin.js' ), [ 'jquery' ] ); |
|
|
|
wp_localize_script( |
|
'pressbooks-aldine-admin', 'PB_Aldine_Admin', [ |
|
'aldineAdminNonce' => wp_create_nonce( 'pressbooks-aldine-admin' ), |
|
'catalog_updated' => __( 'Catalog updated.', 'pressbooks-aldine' ), |
|
'catalog_not_updated' => __( 'Sorry, but your catalog was not updated. Please try again.', 'pressbooks-aldine' ), |
|
'dismiss_notice' => __( 'Dismiss this notice.', 'pressbooks-aldine' ), |
|
] |
|
); |
|
} |
|
|
|
/** |
|
* |
|
*/ |
|
function update_catalog() { |
|
if ( ! current_user_can( 'manage_network' ) || ! check_ajax_referer( 'pressbooks-aldine-admin' ) ) { |
|
return; |
|
} |
|
|
|
$blog_id = absint( $_POST['book_id'] ); |
|
$in_catalog = $_POST['in_catalog']; |
|
|
|
if ( $in_catalog === 'true' ) { |
|
update_blog_option( $blog_id, \Aldine\Admin\BLOG_OPTION, 1 ); |
|
update_site_meta( $blog_id, BookDataCollector::IN_CATALOG, 1 ); |
|
} else { |
|
delete_blog_option( $blog_id, \Aldine\Admin\BLOG_OPTION ); |
|
update_site_meta( $blog_id, BookDataCollector::IN_CATALOG, 0 ); |
|
// Exclude book when network option book directory non-catalog exclude is enabled |
|
$option = get_site_option( pressbooks_sharingandprivacy_options, [], true ); |
|
if ( |
|
isset( $option[ SharingAndPrivacyOptions::NETWORK_DIRECTORY_EXCLUDED ] ) && |
|
( (bool) $option[ SharingAndPrivacyOptions::NETWORK_DIRECTORY_EXCLUDED ] === true ) |
|
) { |
|
BookDirectory::init()->deleteBookFromDirectory( [ $blog_id ] ); |
|
} |
|
} |
|
update_blog_details( $blog_id, [ 'last_updated' => current_time( 'mysql', true ) ] ); |
|
} |
|
|
|
/** |
|
* @param array $columns |
|
* |
|
* @return array |
|
*/ |
|
function catalog_columns( $columns ) { |
|
$columns['in_catalog'] = __( 'In Catalog', 'pressbooks-aldine' ); |
|
return $columns; |
|
} |
|
|
|
/** |
|
* @param string $column |
|
* @param int $blog_id |
|
*/ |
|
function catalog_column( $column, $blog_id ) { |
|
|
|
if ( 'in_catalog' === $column && ! is_main_site( $blog_id ) ) { ?> |
|
<input class="in-catalog" type="checkbox" name="in_catalog" value="1" aria-label="<?php echo esc_attr_x( 'Show in Catalog', 'pressbooks-aldine' ); ?>" <?php checked( get_blog_option( $blog_id, \Aldine\Admin\BLOG_OPTION ), 1 ); ?> <?php |
|
if ( ! get_blog_option( $blog_id, 'blog_public' ) ) { |
|
|
|
?> |
|
disabled="disabled" title="<?php echo esc_attr_x( 'This book is private, so you can’t display it in your catalog.', 'pressbooks-aldine' ); ?>"<?php } ?> /> |
|
<?php |
|
} |
|
|
|
}
|
|
|