| 1 |
<?php |
| 2 |
/** |
| 3 |
* Function to add the shortcodes for wp-forecast. |
| 4 |
* |
| 5 |
* @author Hans Matzen |
| 6 |
* @copyright 2009-2024 |
| 7 |
* @since 2.4 |
| 8 |
* @description wp-forecast using WordPress shortcode for more features |
| 9 |
* @Docs http://codex.wordpress.org/Shortcode_API |
| 10 |
* |
| 11 |
* @package wp-forecast |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! function_exists( 'wpforecast' ) ) { |
| 15 |
/** |
| 16 |
* Function which adds the wp-forecast weather widget as shortcode. |
| 17 |
* |
| 18 |
* @param array $atts Parameters for the widget. |
| 19 |
*/ |
| 20 |
function wpforecast( $atts ) { |
| 21 |
$lang = ''; |
| 22 |
$width = ''; |
| 23 |
$height = ''; |
| 24 |
$id = ''; |
| 25 |
|
| 26 |
// parameter einlesen. |
| 27 |
if ( is_array( $atts ) ) { |
| 28 |
$lang = ( isset( $atts['lang'] ) ? sanitize_key( $atts['lang'] ) : '' ); |
| 29 |
$width = ( isset( $atts['width'] ) ? intval( $atts['width'] ) : '' ); |
| 30 |
$height = ( isset( $atts['height'] ) ? intval( $atts['height'] ) : '' ); |
| 31 |
$id = ( isset( $atts['id'] ) ? sanitize_key( $atts['id'] ) : 'A' ); |
| 32 |
} |
| 33 |
|
| 34 |
// iframe tag zusammen bauen. |
| 35 |
$res = '<iframe class="wpf-iframe" src="' . site_url( 'wp-forecast-direct?wpfcid=' . $id . '&header=1', __FILE__ ); |
| 36 |
|
| 37 |
// falls eine sprache angegeben wurde haengen wir sie hinten dran. |
| 38 |
if ( '' != $lang ) { |
| 39 |
$res .= '&language_override=' . $lang; |
| 40 |
} |
| 41 |
|
| 42 |
$res .= '" '; |
| 43 |
|
| 44 |
// falls eine breite angegeben wurde haengen wir sie hinten dran. |
| 45 |
if ( '' != $width && 0 != $width ) { |
| 46 |
$res .= "width='$width' "; |
| 47 |
} |
| 48 |
|
| 49 |
// falls eine sprache angegeben wurde haengen wir sie hinten dran. |
| 50 |
if ( '' != $height && 0 != $height ) { |
| 51 |
$res .= "height='$height' "; |
| 52 |
} |
| 53 |
|
| 54 |
$res .= '>' . __( 'wp-forecast shortcode: This browser does not support iframes.', 'wp-forecast' ) . '</iframe>'; |
| 55 |
|
| 56 |
return $res; |
| 57 |
} |
| 58 |
} |
| 59 |
// shortcode bei wp anmelden. |
| 60 |
if ( function_exists( 'add_shortcode' ) ) { |
| 61 |
add_shortcode( 'wpforecast', 'wpforecast' ); |
| 62 |
add_filter( 'widget_text', 'do_shortcode' ); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|