prefix . "ficha_autor";
//Insertar código en los posts para ver la lista de autores
add_shortcode('autores-ficha', 'autor_data_shortcode');
function autor_data_shortcode($atts) {
return author_data();
}
//Insertar código en los posts para ver la lista de links
add_shortcode('autores-links', 'autor_links_shortcode');
function autor_links_shortcode($atts) {
return author_links();
}
add_action('admin_menu', 'author_data_menu');
function author_data_menu() {
add_menu_page(__('Gestión', 'fichas'), __('Autores', 'citas'), 10 , 'author-data/author-data-manage.php', '', plugins_url('author-data/pluma.jpg'));
add_submenu_page('author-data/author-data-manage.php', __('Autores', 'fichas'), __('Gestión', 'fichas'), 10, 'author-data/author-data-manage.php');
add_submenu_page('author-data/author-data-manage.php', __('Autores', 'fichas'), __('Configuración', 'fichas'), 10, 'author-data/author-data.php', 'author_data_settings');
}
function author_data_settings() {
if ($_POST) {
if($_POST["vnombre"] == "")
$_POST["vnombre"] = "si";
if($_POST["vfecha"] == "")
$_POST["vfecha"] = "si";
if($_POST["vlugar"] == "")
$_POST["vlugar"] = "si";
if($_POST["vweb"] == "")
$_POST["vweb"] = "si";
if($_POST["vficha"] == "")
$_POST["vficha"] = "si";
if($_POST["nomtam"] == "")
$_POST["nomtam"] = "+1";
if($_POST["nomcol"] == "")
$_POST["nomcol"] = "";
if($_POST["nomestilo"] == "")
$_POST["nomestilo"] = "";
if($_POST["parrafo"] == "")
$_POST["parrafo"] = "justify";
if($_POST["lista"] == "")
$_POST["lista"] = "ul";
update_option('vnombre', $_POST['vnombre']);
update_option('vfecha', $_POST['vfecha']);
update_option('vlugar', $_POST['vlugar']);
update_option('vweb', $_POST['vweb']);
update_option('vficha', $_POST['vficha']);
update_option('nomtam', $_POST['nomtam']);
update_option('nomestilo', $_POST['nomestilo']);
update_option('nomcol', $_POST['nomcol']);
update_option('parrafo', $_POST['parrafo']);
update_option('lista', $_POST['lista']);
}
// Get options
$vnombre = get_option('vnombre');
$vfecha = get_option('vfecha');
$vlugar = get_option('vlugar');
$vweb = get_option('vweb');
$vficha = get_option('vficha');
$nomtam = get_option('nomtam');
$nomestilo = get_option('nomestilo');
$nomcol = get_option('nomcol');
$parrafo = get_option('parrafo');
$lista = get_option('lista');
?>
';
_e("Opciones actualizadas", 'fichas');
echo '.
';
};
?>
prefix . "ficha_autor";
if($wpdb->get_var("show tables like '$tabla_ficha_autor'") != $tabla_ficha_autor) {
$sql = "CREATE TABLE " . $tabla_ficha_autor . " (
ID int(5) unsigned NOT NULL auto_increment,
user_login varchar(60) NOT NULL default '',
nombre varchar(30) NOT NULL default '',
apellidos varchar(40) NOT NULL default '',
nombre_vis varchar (70) NOT NULL default '',
fecha_nac varchar(4) NOT NULL default '',
lugar_nac varchar(40) NOT NULL default '',
sitio_web varchar(100) NOT NULL default '',
ficha longtext NOT NULL default '',
PRIMARY KEY (ID, user_login) ); ";
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
dbDelta($sql);
}
}
$vnombre = get_option('vnombre');
$vfecha = get_option('vfecha');
$vlugar = get_option('vlugar');
$vweb = get_option('vweb');
$vficha = get_option('vficha');
$nomtam = get_option('nomtam');
$nomestilo = get_option('nomestilo');
$nomcol = get_option('nomcol');
$parrafo = get_option('parrafo');
$lista = get_option('lista');
function author_data() {
global $vnombre;
global $vfecha;
global $vlugar;
global $vweb;
global $vficha;
global $nomtam;
global $nomestilo;
global $nomcol;
global $parrafo;
global $lista;
global $wpdb;
$tabla_ficha_autor = $wpdb->prefix . "ficha_autor";
$consulta = "SELECT ID, user_login, nombre, apellidos, fecha_nac, lugar_nac, sitio_web, ficha FROM " . $tabla_ficha_autor . " ORDER BY apellidos ASC, nombre ASC";
$listado = $wpdb->get_results($consulta);
if ($listado) {
if ($nomestilo == 'strong') {
$peso = 'bold';
$tipo = 'normal';
}
else {
$peso = 'normal';
$tipo = $nomestilo;
}
echo '';
foreach($listado as $fila) {
$ID = $fila->ID;
$usuario = $fila->user_login;
$nombre = $fila->nombre;
$apellidos = $fila->apellidos;
$fecha_nac = $fila->fecha_nac;
$lugar_nac = $fila->lugar_nac;
$sitio_web = $fila->sitio_web;
$ficha = $fila->ficha;
//Comprobar si tiene posts publicados
if ($usuario != 'redal') {
$consulta = "SELECT 1 FROM $wpdb->users WHERE user_login = '$usuario' AND ID IN (SELECT post_author FROM $wpdb->posts WHERE post_status = 'publish')";
$publicado = $wpdb->get_results($consulta);
}
else $publicado[0] = '1';
if ($publicado && $ficha != '') {
//Formatear nombre
if ($vnombre == "si") {
$linea_nombre = ''. $nombre . ' ' . $apellidos . '
';
}
else {
$linea_nombre = '';
}
//Formatear fecha y lugar de nacimiento
$linea_fecha = '';
if ($vlugar == "si") {
$linea_fecha = $linea_fecha . $lugar_nac;
}
if ($vfecha == "si") {
if ($lugar_nac != '') {
$linea_fecha = $linea_fecha . ', ' . $fecha_nac;
}
else {
$linea_fecha = $linea_fecha . $fecha_nac;
}
}
$linea_fecha = $linea_fecha . '
';
//Formatear página web
if ($vweb == "si" && $sitio_web != "") {
$linea_web = '';
}
else {
$linea_web = '';
}
//Formatear ficha biográfica
if ($vficha == "si") {
$linea_ficha = '' . $ficha . '
';
}
else {
$linea_ficha = '';
}
//Visualizar
echo $linea_nombre;
echo $linea_fecha;
echo $linea_web;
echo $linea_ficha;
echo '
';
}
}
};
}
function author_links() {
global $lista;
global $nomtam;
global $nomestilo;
global $nomcol;
$alfabeto = array ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'Ñ', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'X', 'Y', 'Z');
global $wpdb;
$tabla_ficha_autor = $wpdb->prefix . "ficha_autor";
echo '' . __('Los autores', 'fichas') . '
';
echo '<' . $lista . '>';
foreach ($alfabeto as $alfa) {
$letra = $alfa;
$consulta = "SELECT ID, user_login, nombre, apellidos, fecha_nac, lugar_nac, sitio_web, ficha FROM " . $tabla_ficha_autor . " WHERE substr(apellidos, 1, 1) = '" . $letra . "' ORDER BY apellidos ASC, nombre ASC";
$listado = $wpdb->get_results($consulta);
$primero = 's';
$ficha = $listado[0]->ficha;
$cabeceras = 'n';
if ($listado) {
foreach($listado as $fila) {
$ID = $fila->ID;
$usuario = $fila->user_login;
$nombre = $fila->nombre;
$apellidos = $fila->apellidos;
$sitio_web = $fila->sitio_web;
//Comprobar si tiene posts publicados
if ($usuario != 'redal') {
$consulta = "SELECT 1 FROM $wpdb->users WHERE user_login = '$usuario' AND ID IN (SELECT post_author FROM $wpdb->posts WHERE post_status = 'publish')";
$publicado = $wpdb->get_results($consulta);
}
else $publicado[0] = '1';
if (($publicado) && (substr($sitio_web, 8, 1) != ' ')) {
if ($primero == 's') {
if ($lista != 'table') {
echo '' . $letra . '
<'. $lista . '>';
}
else {
echo '' . $letra . ' |
';
}
$primero = 'n';
$cabeceras = 's';
}
if ($lista != 'table') {
echo ''. $nombre . ' ' . $apellidos . '';
}
else {
echo ' | '. $nombre . ' ' . $apellidos . ' |
';
}
}
}
}
if ($cabeceras == 's' && $lista != 'table') {
echo ''. $lista . '>';
}
}
echo '' . $lista . '>';
}
//add_action('template_redirect', 'author_data_actualizar');
register_activation_hook( __FILE__, 'install_author_data' );
?>