<?php
function add_your_meta_box()
{
add_meta_box('variables', 'Variables disponibles', 'mostrar_variables', 'nicho', 'side', 'default');
add_meta_box('variables', 'Variables disponibles', 'mostrar_variables', 'nichocat', 'side', 'high');
add_meta_box('variables', 'Generar contenido con IA', 'generar_contenido', 'post', 'side', 'high');
add_meta_box('variables', 'Generar contenido con IA', 'generar_contenido', 'page', 'side', 'high');
}

add_action('add_meta_boxes', 'add_your_meta_box'); 
function generar_contenido()
{
global $post;
?>
<div class="contenidoia">
<p><?php _e('Si usas cualquier de estas tres variables, la sustituiremos por contenido generado con OpenAI','nichecreator'); ?></p>
<div class="var"><span id="openai1">%openai1</span><button class="btn" data-clipboard-text="%openai1"><img src="" alt="<?php _e('Párrafo introductorio OpenAI','nichecreator') ?>"></img></button></div>
<div class="var"><span id="openai2">%openai2</span><button class="btn" data-clipboard-text="%openai2"><img src="" alt="<?php _e('Párrafo contenido OpenAI','nichecreator') ?>"></img></button></div>
<div class="var"><span id="openai3">%openai3</span><button class="btn" data-clipboard-text="%openai3"><img src="" alt="<?php _e('Párrafo conclusión OpenAI','nichecreator') ?>"></img></button></div>
<div class="var"><span id="openaitexto">%openaitexto</span><button class="btn" data-clipboard-text="%openaitexto"><img src="" alt="<?php _e('Prompt Propio OpenAI','nichecreator') ?>"></img></button></div>
<div class="var"><span id="geminitexto">%geminitexto</span><button class="btn" data-clipboard-text="%geminitexto"><img src="" alt="<?php _e('Prompt Propio Gemini','nichecreator') ?>"></img></button></div>
<a class="button popup genia" style="margin-top: 10px;margin-left: auto;margin-right: auto;display: block;max-width: 125px;" href="javascript:void(0)" data-name="<?php echo $post->post_title ?>"><?php echo __('Generar contenido','nichecreator'); ?></a>
<?php
$name = $post->post_title;
$id = $post->ID;
wp_register_script( 'carga-genia', plugins_url('../js/openai.js',__FILE__), array('jquery','jquery-ui-dialog','wp-i18n'), '1.1', true );
wp_enqueue_script( 'carga-genia');
$arr = array( 'ajaxurl' => plugins_url('../includes/crearia.php',__FILE__),'name'=>$name,'id'=>$id,'prompt'=>'',
'confirmar' => __('Confirmar','nichecreator'),
'cancelar' => __('Cancelar','nichecreator'),
'cabecera' => __('Confirmación requerida','nichecreator'),
'contenido' => __( 'Vas a lanzar el proceso de generación de contenido. El sistema sustuiturá las variables %opena1, %openai2, %openai3 mediante texto generado mediante IA.<br/>Si usas la variable %openaitexto o %geminitexto rellena el prompt a continuación.', 'nichecreator' ),
'mensaje' => __('Mensaje','nichecreator'),
);
wp_localize_script('carga-genia','gen',$arr ); 
wp_set_script_translations( 'carga-genia', 'nichecreator', plugin_dir_path(__FILE__) . '../languages' );

?>
</div>
<?php
}

function mostrar_variables()
{
global $post;
?>
<div class="variablesdisponibles">
<p><strong><?php _e('Puedes usar las siguientes variables','nichecreator') ?></strong></p>
<p class="cabeceras">Párrafos de contenido</p>
<div class="var"><span id="parrafo1">%parrafo1</span><button class="btn" data-clipboard-text="%parrafo1"><p><?php _e('Párrafo 1','nichecreator') ?></p></button></div>
<?php
if ( get_post_type() == 'nicho')
{
?>
<div class="var"><span id="parrafo2">%parrafo2</span><button class="btn" data-clipboard-text="%parrafo2"><p><?php _e('Párrafo 2','nichecreator') ?></p></button></div>
<div class="var"><span id="parrafo3">%parrafo3</span><button class="btn" data-clipboard-text="%parrafo3"><p><?php _e('Párrafo 3','nichecreator') ?></p></button></div>
<?php
}
if ( get_post_type() == 'nichocat')
{
?>
<div class="var"><span id="parrafoconc">%parrafoconc</span><button class="btn" data-clipboard-text="%parrafoconc"><p><?php _e('Párrafo Conclusión','nichecreator') ?></p></button></div>
<?php } ?>
<div class="var"><span id="openai1">%openai1</span><button class="btn" data-clipboard-text="%openai1"><p><?php _e('Par. Intro OpenAI','nichecreator') ?></p></button></div>
<div class="var"><span id="openai2">%openai2</span><button class="btn" data-clipboard-text="%openai2"><p><?php _e('Par. Contenido OpenAI','nichecreator') ?></p></button></div>
<div class="var"><span id="openai3">%openai3</span><button class="btn" data-clipboard-text="%openai3"><p><?php _e('Par. Conclusión OpenAI','nichecreator') ?></p></button></div>
<div class="var"><span id="openaitexto">%openaitexto</span><button class="btn" data-clipboard-text="%openaitexto"><p><?php _e('Prompt Propio OpenAI','nichecreator') ?></p></button></div>
<div class="var"><span id="geminitexto">%geminitexto</span><button class="btn" data-clipboard-text="%geminitexto"><p><?php _e('Prompt Propio Gemini','nichecreator') ?></p></button></div>
<p class="cabeceras"><?php _e('Variables escrapeadas','nichecreator') ?></p>
<div class="var"><span id="nombre">%nombre</span><button class="btn" data-clipboard-text="%nombre"><p><?php _e('Nombre','nichecreator') ?></p></button></div>
<div class="var"><span id="h1">%h1</span><button class="btn" data-clipboard-text="%h1"><p><?php _e('Etiqueta H1','nichecreator') ?></p></button></div>
<div class="var"><span id="direccion">%direccion</span><button class="btn" data-clipboard-text="%direccion"><p><?php _e('Dirección','nichecreator') ?></p></button></div>
<div class="var"><span id="municipio">%municipio</span><button class="btn" data-clipboard-text="%municipio"><p><?php _e('Municipio','nichecreator') ?></p></button></div>
<div class="var"><span id="provincia">%provincia</span><button class="btn" data-clipboard-text="%provincia"><p><?php _e('Provincia','nichecreator') ?></p></button></div>
<div class="var"><span id="cp">%cp</span><button class="btn" data-clipboard-text="%cp"><p><?php _e('Código Postal','nichecreator') ?></p></button></div>
<div class="var"><span id="pais">%pais</span><button class="btn" data-clipboard-text="%pais"><p><?php _e('País','nichecreator') ?></p></button></div>
<div class="var"><span id="telefono">%telefono</span><button class="btn" data-clipboard-text="%telefono"><p><?php _e('Teléfono','nichecreator') ?></p></button></div>
<div class="var"><span id="horario">%horario</span><button class="btn" data-clipboard-text="%horario"><p><?php _e('Horario (1 línea)','nichecreator') ?></p></button></div>
<div class="var"><span id="lunes">%lunes</span><button class="btn" data-clipboard-text="%lunes"><p><?php _e('Horario (día)','nichecreator') ?></p></button></div>
<div class="var"><span id="martes">%martes</span><button class="btn" data-clipboard-text="%martes"><p><?php _e('Horario (día)','nichecreator') ?></p></button></div>
<div class="var"><span id="miercoles">%miercoles</span><button class="btn" data-clipboard-text="%miercoles"><p><?php _e('Horario (día)','nichecreator') ?></p></button></div>
<div class="var"><span id="jueves">%jueves</span><button class="btn" data-clipboard-text="%jueves"><p><?php _e('Horario (día)','nichecreator') ?></p></button></div>
<div class="var"><span id="viernes">%viernes</span><button class="btn" data-clipboard-text="%viernes"><p><?php _e('Horario (día)','nichecreator') ?></p></button></div>
<div class="var"><span id="sabado">%sabado</span><button class="btn" data-clipboard-text="%sabado"><p><?php _e('Horario (día)','nichecreator') ?></p></button></div>
<div class="var"><span id="domingo">%domingo</span><button class="btn" data-clipboard-text="%domingo"><p><?php _e('Horario (día)','nichecreator') ?></p></button></div>
<div class="var"><span id="email">%email</span><button class="btn" data-clipboard-text="%email"><p><?php _e('Email','nichecreator') ?></p></button></div>
<div class="var"><span id="website">%website</span><button class="btn" data-clipboard-text="%website"><p><?php _e('Sitio web','nichecreator') ?></p></button></div>
<div class="var"><span id="valoracion">%valoracion</span><button class="btn" data-clipboard-text="%valoracion"><p><?php _e('Valoración','nichecreator') ?></p></button></div>
<div class="var"><span id="reviews">%reviews</span><button class="btn" data-clipboard-text="%reviews"><p><?php _e('Número reseñas','nichecreator') ?></p></button></div>
<div class="var"><span id="foto">%foto</span><button class="btn" data-clipboard-text="%foto"><p><?php _e('Foto Principal (URL)','nichecreator') ?></p></button></div>
<!-- <div class="var"><span id="fotos">%fotos</span><button class="btn" data-clipboard-text="%fotos"><p><?php _e('Fotos separadas por comas','nichecreator') ?></p></button></div> -->


<div class="var"><span id="urlmaps">%urlmaps</span><button class="btn" data-clipboard-text="%urlmaps"><p><?php _e('URL Link (Maps)','nichecreator') ?></p></button></div>
<div class="var"><span id="iframe">%iframe</span><button class="btn" data-clipboard-text="%iframe"><p><?php _e('Iframe mapa (Google)','nichecreator') ?></p></button></div>

<div class="var"><span id="latitud">%latitud</span><button class="btn" data-clipboard-text="%latitud"><p><?php _e('Latitud GPS','nichecreator') ?></p></button></div>
<div class="var"><span id="longitud">%longitud</span><button class="btn" data-clipboard-text="%longitud"><p><?php _e('Longitud GPS','nichecreator') ?></p></button></div>

<div class="var"><span id="categoriapadre">%categoriapadre</span><button class="btn" data-clipboard-text="%categoriapadre"><p><?php _e('Categoría Padre','nichecreator') ?></p></button></div>
<div class="var"><span id="categoria">%categoria</span><button class="btn" data-clipboard-text="%categoria"><p><?php _e('Categoría','nichecreator') ?></p></button></div>
<div class="var"><span id="etiqueta">%etiqueta</span><button class="btn" data-clipboard-text="%etiqueta"><p><?php _e('Etiqueta','nichecreator') ?></p></button></div>


<div class="var"><span id="var1">%var1</span><button class="btn" data-clipboard-text="%var1"><p><?php _e('Var 1','nichecreator') ?></p></button></div>
<div class="var"><span id="var2">%var2</span><button class="btn" data-clipboard-text="%var2"><p><?php _e('Var 2','nichecreator') ?></p></button></div>
<div class="var"><span id="var3">%var3</span><button class="btn" data-clipboard-text="%var3"><p><?php _e('Var 3','nichecreator') ?></p></button></div>
<div class="var"><span id="var4">%var4</span><button class="btn" data-clipboard-text="%var4"><p><?php _e('Var 4','nichecreator') ?></p></button></div>
<div class="var"><span id="var5">%var5</span><button class="btn" data-clipboard-text="%var5"><p><?php _e('Var 5','nichecreator') ?></p></button></div>
<div class="var"><span id="var6">%var6</span><button class="btn" data-clipboard-text="%var6"><p><?php _e('Var 6','nichecreator') ?></p></button></div>
<div class="var"><span id="var7">%var7</span><button class="btn" data-clipboard-text="%var7"><p><?php _e('Var 7','nichecreator') ?></p></button></div>
<div class="var"><span id="var8">%var8</span><button class="btn" data-clipboard-text="%var8"><p><?php _e('Var 8','nichecreator') ?></p></button></div>
<div class="var"><span id="var9">%var9</span><button class="btn" data-clipboard-text="%var9"><p><?php _e('Var 9','nichecreator') ?></p></button></div>
<div class="var"><span id="var10">%var10</span><button class="btn" data-clipboard-text="%var10"><p><?php _e('Var 10','nichecreator') ?></p></button></div>

<p class="cabeceras"><?php _e('Metas y migas','nichecreator') ?></p>
<div class="var"><span id="slug">%slug</span><button class="btn" data-clipboard-text="%slug"><p><?php _e('Slug','nichecreator') ?></p></button></div>
<div class="var"><span id="metatitle">%metatitle</span><button class="btn" data-clipboard-text="%metatitle"><p><?php _e('Etiqueta Title','nichecreator') ?></p></button></div>
<div class="var"><span id="metadesc">%metadesc</span><button class="btn" data-clipboard-text="%metadesc"><p><?php _e('Etiqueta Meta Desc.','nichecreator') ?></p></button></div>
<div class="var"><span id="migapan">%migapan</span><button class="btn" data-clipboard-text="%migapan"><p><?php _e('Miga de Pan','nichecreator') ?></p></button></div>




</div>
<?php 
}

