2017-12-18 13:05:40 +01:00
< ? php
/*
2018-02-13 14:00:09 +01:00
Plugin Name : Book template
2018-02-05 12:15:23 +01:00
Description : Plugin in italiano che aggiunge uno shortcode per la creazione di un box con i dati editoriali di un libro o di un fumetto .
2018-02-15 09:45:29 +01:00
Version : 2018.0213 . 2
2017-12-18 13:05:40 +01:00
Author : Gianluigi Filippelli
Author URI : http :// dropseaofulaula . blogspot . it /
2018-02-13 13:02:31 +01:00
Plugin URI : https :// ulaulaman . github . io / book - template /
2018-01-25 12:42:10 +01:00
License : GPLv2 or later
2017-12-18 13:05:40 +01:00
*/
/* ------------------------------------------------------ */
2018-02-13 13:02:31 +01:00
# Load translations
add_action ( 'plugins_loaded' , 'bt_load_translations' );
function bt_load_translations () {
load_plugin_textdomain ( 'book-template' , false , dirname ( plugin_basename ( __FILE__ ) ) . '/lang/' );
}
2017-12-18 13:05:40 +01:00
# Aggiunta 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' );
2018-02-13 13:02:31 +01:00
# Setup metabox
2018-01-25 12:42:10 +01:00
function bookdata_meta_box_setup () {
2018-02-13 13:02:31 +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
2018-02-13 13:02:31 +01:00
$intro = __ ( 'Inserimento dati editoriali' , 'book-template' );
2018-01-25 12:42:10 +01:00
add_meta_box (
2018-02-13 13:02:31 +01:00
'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
}
2018-02-13 13:02:31 +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 >
2018-02-14 16:53:13 +01:00
< 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"] ed eventuali note aggiuntive [dati_editoriali ... 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 }
2018-02-13 13:02:31 +01:00
# creazione shortcode dati editoriali
add_shortcode ( 'bookdata' , 'bookdata' );
2017-12-18 13:05:40 +01:00
function bookdata ( $atts , $content = null ) {
extract (
shortcode_atts (
array (
'title' => null ,
'author' => null ,
'translator' => null ,
'publisher' => null ,
'date' => null ,
'pages' => null ,
'type' => null ,
'col' => null ,
'price' => null ,
'isbn' => null ,
'issn' => null ,
'notes' => null ,
),
$atts
)
);
2018-02-13 13:02:31 +01:00
$intro = __ ( 'Abbiamo parlato di' , 'book-template' );
$book = '<p><strong>' . $intro . '</strong>:<br/><em>' . $title . '</em><br/>' . $author ;
2017-12-18 13:05:40 +01:00
if ( $translator <> null )
2018-02-13 13:02:31 +01:00
{ $translator = __ ( 'Traduzione di ' , 'book-template' ) . $translator ;
$book = $book . '<br/>' . $translator ;}
2017-12-18 13:05:40 +01:00
else
{ $book = $book ;}
2018-02-13 13:02:31 +01:00
$pages = $pages . ' ' . __ ( 'pagine' , 'book-template' );
2017-12-18 13:05:40 +01:00
if ( $col <> null )
2018-02-14 16:53:13 +01:00
{ $book = $book . '<br/>' . $publisher . ', ' . $date . '<br/>' . $pages . ' pagine, ' . $type . ', ' . $col . ' – ' . $price ;}
2017-12-18 13:05:40 +01:00
else
2018-02-14 16:53:13 +01:00
{ $book = $book . '<br/>' . $publisher . ', ' . $date . '<br/>' . $pages . ' pagine, ' . $type . ' – ' . $price ;}
2017-12-18 13:05:40 +01:00
if ( $isbn <> null )
{ $book = $book . '<br/>ISBN: ' . $isbn ;}
else
{
if ( $issn <> null )
{ $book = $book . '<br/>ISSN: ' . $issn ;}
else
{ $book = $book ;}
}
if ( $notes <> null )
{ $book = $book . '<br/>' . $notes ;}
else
{ $book = $book ;}
$text = $book ;
return $text ;
}
/* ------------------------------------------------------ */
?>