book-template/book-template.php

121 lines
3.7 KiB
PHP
Raw 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.
Version: 2020.0813
2017-12-18 13:05:40 +01:00
Author: Gianluigi Filippelli
Author URI: http://dropseaofulaula.blogspot.it/
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
*/
/* ------------------------------------------------------ */
# 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' );
# Setup metabox
2018-01-25 12:42:10 +01:00
function bookdata_meta_box_setup() {
# 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
}
# 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 }
# 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,
2017-12-18 13:05:40 +01:00
'translator' => null,
'publisher' => null,
'date' => null,
'pages' => null,
'type' => null,
'col' => null,
'price' => null,
'age' => null,
'isbn' => null,
'issn' => null,
'notes' => null,
2017-12-18 13:05:40 +01:00
),
$atts
)
);
$intro = __( 'Abbiamo parlato di:', 'book-template' );
2020-08-13 20:20:40 +02:00
$book = '<p><strong>'.$intro.'</strong><br/><em>'.$title.'</em><br/>'.$author;
2017-12-18 13:05:40 +01:00
if ( $translator <> null )
{$translator = __( 'Traduzione di ', 'book-template' ).$translator;
$book = $book.'<br/>'.$translator;}
2017-12-18 13:05:40 +01:00
else
{$book = $book;}
$pages = $pages.' '.__( 'pagine', 'book-template' );
2017-12-18 13:05:40 +01:00
if ( $col <> null )
2018-03-26 12:52:53 +02:00
{$book = $book.'<br/>'.$publisher.', '.$date.'<br/>'.$pages.', '.$type.', '.$col.' '.$price;}
2017-12-18 13:05:40 +01:00
else
2018-03-26 12:52:53 +02:00
{$book = $book.'<br/>'.$publisher.', '.$date.'<br/>'.$pages.', '.$type.' '.$price;}
2017-12-18 13:05:40 +01:00
if ( $age <> null )
{$book = $book.'<br/>'.__( 'Lettura consigliata per ', 'book-template' ).$age;}
else
{$book = $book;}
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;
}
/* ------------------------------------------------------ */
?>