book-template/book-template.php

129 lines
3.9 KiB
PHP
Raw Permalink Normal View History

2017-12-18 13:05:40 +01:00
<?php
/*
Plugin Name: Book Template
Description: Plugin che aggiunge uno shortcode per la creazione di un box con i dati editoriali di un libro o di un fumetto.
2021-10-21 17:37:44 +02:00
Version: 2021.1021
2017-12-18 13:05:40 +01:00
Author: Gianluigi Filippelli
Author URI: http://dropseaofulaula.blogspot.it/
2021-10-16 00:56:32 +02:00
Plugin URI: https://ulaulaman.github.io/#BookTemplate
GitHub Plugin URI: https://github.com/ulaulaman/book-template
2018-01-25 12:42:10 +01:00
License: GPLv2 or later
2017-12-18 13:05:40 +01:00
*/
2021-10-16 00:56:32 +02:00
2020-11-20 01:33:32 +01:00
# Caricamento traduzioni
add_action('plugins_loaded', 'bt_load_translations');
function bt_load_translations() {
load_plugin_textdomain( 'book-template', false, dirname( plugin_basename(__FILE__) ) . '/lang/' );
}
2020-11-20 01:33:32 +01:00
# Caricamento metabox
2018-01-25 12:42:10 +01:00
add_action( 'load-post.php', 'bookdata_meta_box_setup' );
add_action( 'load-post-new.php', 'bookdata_meta_box_setup' );
# Setup metabox
2018-01-25 12:42:10 +01:00
function bookdata_meta_box_setup() {
2020-11-20 01:33:32 +01:00
# Aggiunta del metabox
2018-01-25 12:42:10 +01:00
add_action( 'add_meta_boxes', 'bookdata_meta_box' );
}
2017-12-18 13:05:40 +01:00
function bookdata_meta_box() {
2018-01-25 12:42:10 +01:00
$intro = __( 'Inserimento dati editoriali', 'book-template' );
2018-01-25 12:42:10 +01:00
add_meta_box(
'bookdata-post-class', // ID unico
esc_html__( $intro, 'example' ), // Titolo
'bookdata_class_meta_box', // funzione
'post', // associato a
'side', // contesto
'high' // priorità
2018-01-25 12:42:10 +01:00
);
2017-12-18 13:05:40 +01:00
}
2020-11-20 01:33:32 +01:00
# Mostra il metabox
2018-01-25 12:42:10 +01:00
function bookdata_class_meta_box( $post ) { ?>
<?php wp_nonce_field( basename( __FILE__ ), 'bookdata_class_nonce' ); ?>
<p>
<label for="bookdata-post-class"><?php _e( 'Esempio generico [bookdata title="Titolo" author="Autore/i" publisher="Editore" date="Data" pages="numero pagine" type="brossurato,cartonato,digitale/on-line" price="prezzo/gratuito"]', 'book-template' ); ?><br/><?php _e(' In caso di fumetto o libro illustrato, inserire il colore [bookdata ... col="colore,b/n"]', 'book-template' ); ?><br/><?php _e( 'Possono essere inseriti opzionalmente ISBN [bookdata ... isbn="codice"] o ISSN [bookdata ... issn="codice"], il traduttore [bookdata ... translator="Traduttore"], l\'età consigliata [bookdata ... age="età consigliata"] ed eventuali note aggiuntive [bookdata ... notes="Note aggiuntive"]', 'book-template' ); ?><br/><?php _e( 'I dati possono essere inseriti anche in maniera disordinata: ci penserà il plugin a riordinarli.', 'book-template' ); ?></label></p>
2018-01-25 12:42:10 +01:00
<?php }
2020-11-20 01:33:32 +01:00
# Creazione shortcode dati editoriali
add_shortcode( 'bookdata', 'bookdata' );
2017-12-18 13:05:40 +01:00
2021-10-16 00:56:32 +02:00
function bookdata ( $atts, $content = null ) {
extract(
shortcode_atts(
array(
'intro' => null,
'title' => null,
'url' => null,
'author' => null,
'translator' => null,
'publisher' => null,
'date' => null,
'pages' => null,
'type' => null,
'col' => null,
'price' => null,
'age' => null,
'isbn' => null,
'issn' => null,
'notes' => null,
),
$atts
)
);
$book='<p>';
if ( $intro <> null ) {
$book = $book.'<strong>'.$intro.'</strong>';
} else {
$book = $book.'<strong>'.__( 'Abbiamo parlato di:', 'book-template' ).'</strong>';
}
if ( $url <> null ) {
2021-10-21 17:37:44 +02:00
$book = $book.'<br/><a href="'.$url.'" target="book"><wm>'.$title.'</em></a><br/>'.$author;
2021-10-16 00:56:32 +02:00
} else {
$book = $book.'<br/><em>'.$title.'</em><br/>'.$author;
}
if ( $translator <> null ) {
$book = $book.'<br/>'.__( 'Traduzione di ', 'book-template' ).$translator;
}
$pages = $pages.' '.__( 'pagine', 'book-template' );
if ( $col <> null ) {
$book = $book.'<br/>'.$publisher.', '.$date.'<br/>'.$pages.', '.$type.', '.$col.' '.$price;
} else {
$book = $book.'<br/>'.$publisher.', '.$date.'<br/>'.$pages.', '.$type.' '.$price;
}
if ( $age <> null ) {
$book = $book.'<br/>'.__( 'Lettura consigliata ', 'book-template' ).$age;
}
if ( $isbn <> null ) {
$book = $book.'<br/>ISBN: '.$isbn;
} else {
if ( $issn <> null ) {
$book = $book.'<br/>ISSN: '.$issn;
}
}
if ( $notes <> null ) {
$book = $book.'<br/>'.$notes;
}
$book = $book.'</p>';
return $book;
2017-12-18 13:05:40 +01:00
}
?>