Files
Josep Piguillem 9a6bcd56e5 Tema: nuevos botones, campos, casillas, tarjetas, selector, interruptor, cabecera y pie
- Botones: borde que se dibuja al pasar el ratón o con el teclado (color según variante) y sombra.
- Campos: subrayados con etiqueta flotante y degradado principal → acento al enfocar; flecha
  propia en los desplegables. Formularios de contacto, cuestionario y finales felices adaptados.
- Casillas: marca «a mano» que se dibuja al marcarlas (ga_checkmark()), accesibles con teclado.
- Tarjetas de animales y finales felices: marco de 2 px con resplandor de acento en la esquina.
- Selector segmentado (.ga-segmented) con píldora deslizante; se usa en las pestañas Perros / Gatos
  y sirve también para grupos de radios.
- Interruptor (.ga-toggle, ga_toggle_ui()) listo para usar.
- Cabecera translúcida con borde al hacer scroll, enlaces en píldora, desplegable animado con
  descripción de cada elemento y fondo oscurecido mientras está abierto.
- Pie: nombre gigante en bajorrelieve que se descubre al final de la página (opción en el
  personalizador, «Bilagun» por defecto).
- Versión del tema 2.3.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 15:11:17 +02:00

125 lines
6.6 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Cuestionario de adopción online [ga_cuestionario]. Las preguntas se editan en
* Personalizar → Adopción y colabora → Cuestionario. La página no se indexa.
*/
defined( 'ABSPATH' ) || exit;
function ga_questionnaire_questions() {
return array_values( array_filter( array_map( 'trim', explode( "\n", (string) ga_setting( 'cuestionario', 'questions', '' ) ) ) ) );
}
add_shortcode( 'ga_cuestionario', function () {
$status = sanitize_key( $_GET['cuestionario'] ?? '' );
$animal_id = absint( $_GET['adoptar'] ?? 0 );
$animal = $animal_id && 'animal' === get_post_type( $animal_id ) ? get_the_title( $animal_id ) : '';
$questions = ga_questionnaire_questions();
$privacy = ga_page_url( 'politica-de-privacidad' );
ob_start();
if ( 'ok' === $status ) {
echo '<div class="ga-notice ga-notice--ok" role="status" data-ga-clear-draft>' . esc_html( ga_setting( 'cuestionario', 'confirm', '' ) ) . '</div>';
return ob_get_clean();
}
if ( 'error' === $status ) {
echo '<div class="ga-notice ga-notice--error" role="alert">' . esc_html( ga__( 'Falta algún dato obligatorio. Revisa el formulario: lo que habías escrito se ha guardado.', 'Derrigorrezko daturen bat falta da. Berrikusi formularioa: idatzitakoa gorde da.' ) ) . '</div>';
}
?>
<form class="ga-form ga-questionnaire" method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" data-ga-draft="ga-cuestionario-<?php echo esc_attr( ga_lang() ); ?>">
<input type="hidden" name="action" value="ga_cuestionario">
<input type="hidden" name="idioma" value="<?php echo esc_attr( ga_lang() ); ?>">
<input type="hidden" name="redirect" value="<?php echo esc_url( get_permalink() ); ?>">
<?php wp_nonce_field( 'ga_cuestionario', 'ga_nonce' ); ?>
<div class="ga-hp" aria-hidden="true"><label>No rellenar <input type="text" name="web" tabindex="-1" autocomplete="off"></label></div>
<fieldset>
<legend><?php ga_e( 'Tus datos', 'Zure datuak' ); ?></legend>
<div class="ga-form__row">
<label class="ga-field"><input type="text" name="nombre" required autocomplete="name" placeholder=" "><span><?php ga_e( 'Nombre y apellidos', 'Izen-abizenak' ); ?> *</span></label>
<label class="ga-field"><input type="email" name="email" required autocomplete="email" placeholder=" "><span><?php ga_e( 'Correo electrónico', 'Posta elektronikoa' ); ?> *</span></label>
</div>
<div class="ga-form__row">
<label class="ga-field"><input type="tel" name="telefono" required autocomplete="tel" placeholder=" "><span><?php ga_e( 'Teléfono', 'Telefonoa' ); ?> *</span></label>
<label class="ga-field"><input type="text" name="localidad" autocomplete="address-level2" placeholder=" "><span><?php ga_e( 'Localidad', 'Herria' ); ?></span></label>
</div>
<label class="ga-field"><input type="text" name="animal" value="<?php echo esc_attr( $animal ); ?>" placeholder=" "><span><?php ga_e( 'Animal por el que te interesas', 'Interesatzen zaizun animalia' ); ?></span></label>
</fieldset>
<fieldset>
<legend><?php ga_e( 'Sobre ti y tu hogar', 'Zuri eta zure etxeari buruz' ); ?></legend>
<?php foreach ( $questions as $i => $question ) : ?>
<label><?php echo esc_html( $question ); ?> *
<textarea name="respuestas[<?php echo (int) $i; ?>]" rows="3" required></textarea>
</label>
<?php endforeach; ?>
</fieldset>
<label class="ga-form__check">
<input type="checkbox" name="privacidad" value="1" required><?php echo ga_checkmark(); // SVG estático. ?>
<span><?php printf( wp_kses( ga__( 'He leído y acepto la <a href="%s" target="_blank">política de privacidad</a>. *', '<a href="%s" target="_blank">Pribatutasun-politika</a> irakurri eta onartzen dut. *' ), array( 'a' => array( 'href' => array(), 'target' => array() ) ) ), esc_url( $privacy ) ); ?></span>
</label>
<p class="ga-form__hint"><?php ga_e( 'Lo que escribes se guarda en este navegador hasta que lo envíes.', 'Idazten duzuna nabigatzaile honetan gordetzen da bidali arte.' ); ?></p>
<button type="submit" class="ga-btn"><?php ga_e( 'Enviar cuestionario', 'Galdetegia bidali' ); ?></button>
</form>
<?php
return ob_get_clean();
} );
add_action( 'admin_post_nopriv_ga_cuestionario', 'ga_handle_questionnaire' );
add_action( 'admin_post_ga_cuestionario', 'ga_handle_questionnaire' );
function ga_handle_questionnaire() {
$redirect = wp_validate_redirect( esc_url_raw( wp_unslash( $_POST['redirect'] ?? '' ) ), home_url( '/' ) );
$go = function ( $status ) use ( $redirect ) {
wp_safe_redirect( add_query_arg( 'cuestionario', $status, $redirect ) );
exit;
};
if ( ! isset( $_POST['ga_nonce'] ) || ! wp_verify_nonce( $_POST['ga_nonce'], 'ga_cuestionario' ) ) {
$go( 'error' );
}
if ( ! empty( $_POST['web'] ) ) {
$go( 'ok' );
}
$lang = 'eu' === ( $_POST['idioma'] ?? '' ) ? 'eu' : 'es';
$questions = ga_with_lang( $lang, 'ga_questionnaire_questions' );
$answers = array_map( fn( $a ) => sanitize_textarea_field( wp_unslash( $a ) ), (array) ( $_POST['respuestas'] ?? array() ) );
$data = array(
'nombre' => sanitize_text_field( wp_unslash( $_POST['nombre'] ?? '' ) ),
'email' => sanitize_email( wp_unslash( $_POST['email'] ?? '' ) ),
'telefono' => sanitize_text_field( wp_unslash( $_POST['telefono'] ?? '' ) ),
'localidad' => sanitize_text_field( wp_unslash( $_POST['localidad'] ?? '' ) ),
'animal' => sanitize_text_field( wp_unslash( $_POST['animal'] ?? '' ) ),
);
if ( ! $data['nombre'] || ! is_email( $data['email'] ) || ! $data['telefono'] || empty( $_POST['privacidad'] ) ) {
$go( 'error' );
}
foreach ( array_keys( $questions ) as $i ) {
if ( '' === trim( $answers[ $i ] ?? '' ) ) {
$go( 'error' );
}
}
$subject = sprintf( '[Web] Cuestionario de adopción – %s%s', $data['nombre'], $data['animal'] ? ' (' . $data['animal'] . ')' : '' );
$body = sprintf(
"Nombre: %s\nEmail: %s\nTeléfono: %s\nLocalidad: %s\nAnimal: %s\nIdioma: %s\n",
$data['nombre'], $data['email'], $data['telefono'], $data['localidad'] ?: '-', $data['animal'] ?: '-', 'eu' === $lang ? 'Euskera' : 'Castellano'
);
foreach ( $questions as $i => $question ) {
$body .= "\n" . $question . "\n" . ( $answers[ $i ] ?? '' ) . "\n";
}
wp_insert_post( array( 'post_type' => 'ga_mensaje', 'post_status' => 'private', 'post_title' => $subject, 'post_content' => $body ) );
wp_mail( ga_contact_email(), $subject, $body, array( 'Reply-To: ' . $data['nombre'] . ' <' . $data['email'] . '>' ) );
$go( 'ok' );
}
/* La página del cuestionario no aparece en buscadores (el enlace lo envía el equipo). */
add_filter( 'wp_robots', function ( $robots ) {
if ( is_page( array( 'cuestionario-adopcion', 'adopzio-galdetegia' ) ) ) {
$robots['noindex'] = true;
$robots['nofollow'] = true;
}
return $robots;
} );