add_action( 'wp_enqueue_scripts', $this, 'maybe_enqueue' );
}
public function maybe_enqueue(): void {
$page_id = (int) get_option( 'academiccrew_publications_archive_page_id', 0 );
if ( $page_id && is_page( $page_id ) ) {
$this->enqueue_assets();
}
}
private function enqueue_assets(): void {
wp_enqueue_script(
'academiccrew-publications-archive',
ACADEMICCREW_URL . 'assets/js/publications-archive.js',
[],
ACADEMICCREW_VERSION,
true
);
wp_localize_script( 'academiccrew-publications-archive', 'ACADEMICCREW_PUBS_ARCHIVE', [
'restUrl' => rest_url( 'academiccrew/v1/publications' ),
'filtersUrl' => rest_url( 'academiccrew/v1/publications/filters' ),
'nonce' => wp_create_nonce( 'wp_rest' ),
'perPage' => 20,
'i18n' => [
'searchPlaceholder' => __( 'Search title, venue, author…', 'academiccrew' ),
'all' => __( 'All', 'academiccrew' ),
'allYears' => __( 'All years', 'academiccrew' ),
'allTypes' => __( 'All types', 'academiccrew' ),
'allAuthors' => __( 'All authors', 'academiccrew' ),
'sortYearDesc' => __( 'Year ↓', 'academiccrew' ),
'sortYearAsc' => __( 'Year ↑', 'academiccrew' ),
'sortCitations' => __( 'Citations ↓', 'academiccrew' ),
'sortCitationsAsc' => __( 'Citations ↑', 'academiccrew' ),
'sortTitle' => __( 'Title A–Z', 'academiccrew' ),
'sortTitleDesc' => __( 'Title Z–A', 'academiccrew' ),
'noResults' => __( 'No publications match your filters.', 'academiccrew' ),
'loading' => __( 'Loading…', 'academiccrew' ),
'publications' => __( 'publications', 'academiccrew' ),
'inPress' => __( 'In press', 'academiccrew' ),
'doi' => 'DOI',
'pdf' => 'PDF',
'etAl' => 'et al.',
'resetFilters' => __( 'Reset filters', 'academiccrew' ),
'copyBibtex' => __( 'Copy BibTeX', 'academiccrew' ),
'bibtexCopied' => __( 'BibTeX copied!', 'academiccrew' ),
'downloadBib' => __( 'Download .bib', 'academiccrew' ),
'yearFrom' => __( 'From', 'academiccrew' ),
'yearTo' => __( 'To', 'academiccrew' ),
'featuredOnly' => __( 'Featured only', 'academiccrew' ),
'allTags' => __( 'All tags', 'academiccrew' ),
],
] );
}
public function render( array $atts ): string {
$this->enqueue_assets();
global $wpdb;
$table = esc_sql( $wpdb->prefix . 'academiccrew_publications' );
$total = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$table}" );
$recent = (int) $wpdb->get_var( $wpdb->prepare(
"SELECT COUNT(*) FROM {$table} WHERE year >= %d",
(int) gmdate( 'Y' ) - 4
) );
$has_citations = (bool) $wpdb->get_var( "SELECT COUNT(*) FROM {$table} WHERE citations > 0" );
$citations = $has_citations
? (int) $wpdb->get_var( "SELECT SUM(citations) FROM {$table}" )
: null;
ob_start();
?>