This commit is contained in:
Javier Casares 2026-10-12 11:55:23 +00:00
commit 06153e387d
47 changed files with 5116 additions and 0 deletions

View file

@ -0,0 +1,156 @@
<?php
/**
* Settings page view: Settings → Font del Bosc Temps.
*
* @package FontdelboscEltemps
*/
defined( 'ABSPATH' ) || exit;
$fontdelbosc_options = Fontdelbosc_Plugin::get_options();
?>
<div class="wrap">
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<form method="post" action="options.php">
<?php
settings_fields( 'fdb_settings' );
do_settings_sections( 'fontdelbosc-eltemps' );
submit_button();
?>
</form>
<section>
<h2><?php esc_html_e( 'Usage', 'fontdelbosc-eltemps' ); ?></h2>
<ul class="fdb-usage">
<li><code>[fontdelbosc_eltemps]</code> — <?php esc_html_e( 'Current conditions (default view).', 'fontdelbosc-eltemps' ); ?></li>
<li><code>[fontdelbosc_eltemps view="hourly" hours="24"]</code> — <?php esc_html_e( 'Hourly forecast for the following hours. Attribute hours: 1-48 (24 by default).', 'fontdelbosc-eltemps' ); ?></li>
<li><code>[fontdelbosc_eltemps view="daily" days="7"]</code> — <?php esc_html_e( 'Daily forecast. Attribute days: 1-7 (7 by default).', 'fontdelbosc-eltemps' ); ?></li>
<li><code>[fontdelbosc_eltemps view="historical" year="2024" month="6"]</code> — <?php esc_html_e( 'Historical data for one month. Attributes year and month; by default the last completed month.', 'fontdelbosc-eltemps' ); ?></li>
</ul>
<p class="description"><?php esc_html_e( 'In the block editor, add a Shortcode block and paste the code. This version ships no dedicated blocks; the shortcode works anywhere shortcodes are supported, including the Shortcode block and text widgets.', 'fontdelbosc-eltemps' ); ?></p>
</section>
<section>
<h2><?php esc_html_e( 'Status', 'fontdelbosc-eltemps' ); ?></h2>
<table class="form-table" role="presentation">
<tr>
<th scope="row">AEMET</th>
<td>
<button type="button" class="button" data-fdb-test="aemet"><?php esc_html_e( 'Test connection', 'fontdelbosc-eltemps' ); ?></button>
<span id="fdb-test-aemet"></span>
</td>
</tr>
<tr>
<th scope="row">Meteocat</th>
<td>
<button type="button" class="button" data-fdb-test="meteocat"><?php esc_html_e( 'Test connection', 'fontdelbosc-eltemps' ); ?></button>
<span id="fdb-test-meteocat"></span>
</td>
</tr>
<tr>
<th scope="row">Open-Meteo</th>
<td>
<button type="button" class="button" data-fdb-test="open-meteo"><?php esc_html_e( 'Test connection', 'fontdelbosc-eltemps' ); ?></button>
<span id="fdb-test-open-meteo"></span>
</td>
</tr>
<?php if ( '' !== $fontdelbosc_options['meteocat_api_key'] ) : ?>
<tr>
<th scope="row"><?php esc_html_e( 'Nearest station', 'fontdelbosc-eltemps' ); ?></th>
<td>
<?php if ( '' !== $fontdelbosc_options['meteocat_station_code'] ) : ?>
<?php
/* translators: %s: XEMA station code. */
printf( esc_html__( 'Nearest station: %s', 'fontdelbosc-eltemps' ), esc_html( $fontdelbosc_options['meteocat_station_code'] ) );
?>
<?php endif; ?>
<button type="button" class="button" id="fdb-find-station"><?php esc_html_e( 'Find nearest station', 'fontdelbosc-eltemps' ); ?></button>
<span id="fdb-station-result"></span>
</td>
</tr>
<?php endif; ?>
</table>
</section>
</div>
<script>
window.fontdelboscAdmin =
<?php
echo wp_json_encode(
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'fontdelbosc_admin' ),
'ok' => __( 'Connection successful.', 'fontdelbosc-eltemps' ),
'fail' => __( 'Connection failed.', 'fontdelbosc-eltemps' ),
)
);
?>
;
( function () {
'use strict';
var cfg = window.fontdelboscAdmin || {};
function post( action, data ) {
var body = new URLSearchParams();
body.set( 'action', action );
body.set( 'nonce', cfg.nonce || '' );
Object.keys( data || {} ).forEach( function ( key ) {
body.set( key, data[ key ] );
} );
return fetch( cfg.ajaxurl, {
method: 'POST',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
body: body.toString()
} ).then( function ( response ) {
return response.json();
} );
}
document.querySelectorAll( '[data-fdb-test]' ).forEach( function ( button ) {
button.addEventListener( 'click', function () {
var source = button.getAttribute( 'data-fdb-test' );
var output = document.getElementById( 'fdb-test-' + source );
if ( output ) {
output.textContent = '…';
}
post( 'fontdelbosc_test_api', { source: source } ).then( function ( result ) {
if ( output ) {
output.textContent = result && result.success ? cfg.ok : cfg.fail;
}
} ).catch( function () {
if ( output ) {
output.textContent = cfg.fail;
}
} );
} );
} );
var find = document.getElementById( 'fdb-find-station' );
if ( find ) {
find.addEventListener( 'click', function () {
var output = document.getElementById( 'fdb-station-result' );
if ( output ) {
output.textContent = '…';
}
post( 'fontdelbosc_find_station', {} ).then( function ( result ) {
if ( output ) {
output.textContent = result && result.success && result.data ? result.data.codi : cfg.fail;
}
} ).catch( function () {
if ( output ) {
output.textContent = cfg.fail;
}
} );
} );
}
} )();
</script>