| 1 |
<?php |
| 2 |
/** |
| 3 |
* Adds OSM_Widget widget. |
| 4 |
*/ |
| 5 |
class OSM_Tagged_Widget extends WP_Widget { |
| 6 |
|
| 7 |
function __construct() { |
| 8 |
parent::__construct( |
| 9 |
'osm_widget', // Base ID |
| 10 |
__('OSM Widget', 'osm'), // Name |
| 11 |
array( 'description' => __( 'WP OSM Geotag Widget', 'osm' ), ) // Args |
| 12 |
); |
| 13 |
} |
| 14 |
|
| 15 |
public function widget( $args, $instance ) { |
| 16 |
$title = apply_filters( 'widget_title', $instance['title'] ); |
| 17 |
$height = $instance['height']; |
| 18 |
$map_type = $instance['map_type']; |
| 19 |
$ctrl_theme = $instance['ctrl_theme']; |
| 20 |
$marker = $instance['marker']; |
| 21 |
$zoom = $instance['zoom']; |
| 22 |
$border_col = $instance['border_col']; |
| 23 |
|
| 24 |
if ((OSM_isGeotagged()) && (is_singular())){ |
| 25 |
echo wp_kses_post($args['before_widget']); |
| 26 |
if ( ! empty( $title ) ){ |
| 27 |
echo wp_kses_post($args['before_title']) . esc_html($title) . wp_kses_post($args['after_title']); |
| 28 |
} |
| 29 |
echo do_shortcode('[osm_map_v3 type="'.$map_type.'" map_center="0,0" zoom="'.$zoom.'" width="99%" height="'.$height.'" marker_latlon="osm_geotag" map_border="2px solid '.$border_col.'" marker_name="'.$marker.'" theme="'.$ctrl_theme.'"]'); |
| 30 |
echo wp_kses_post($args['after_widget']); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
public function form( $instance ) { |
| 35 |
if ( isset( $instance[ 'title' ] ) ) { |
| 36 |
$title = $instance[ 'title' ]; |
| 37 |
} |
| 38 |
else { |
| 39 |
$title = __( 'New title', 'osm' ); |
| 40 |
} |
| 41 |
if ( isset( $instance[ 'marker' ] ) ) { |
| 42 |
$marker = $instance[ 'marker' ]; |
| 43 |
} |
| 44 |
else { |
| 45 |
$marker = 'wpttemp-red.png'; |
| 46 |
} |
| 47 |
if ( isset( $instance[ 'border_col' ] ) ) { |
| 48 |
$border_col = $instance[ 'border_col' ]; |
| 49 |
} |
| 50 |
else { |
| 51 |
$border_col = 'none'; |
| 52 |
} |
| 53 |
?> |
| 54 |
<p> |
| 55 |
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title:', 'osm'); ?></label> |
| 56 |
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>"> |
| 57 |
</p> |
| 58 |
<p> |
| 59 |
<label for="<?php echo esc_attr($this->get_field_id('height')); ?>"><?php esc_html_e('Height:', 'osm'); ?></label> |
| 60 |
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('height')); ?>" name="<?php echo esc_attr($this->get_field_name('height')); ?>" type="text" value="<?php echo esc_attr($height); ?>"> |
| 61 |
|
| 62 |
<label for="<?php echo esc_attr( $this->get_field_id( 'height' ) ); ?>"><?php esc_html_e( 'Height of map:', 'osm' ); ?></label> |
| 63 |
<input id="<?php echo esc_attr( $this->get_field_id( 'height' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'height' ) ); ?>" value="<?php echo esc_attr( $instance['height'] ); ?>" style="width:100%;" /> |
| 64 |
</p> |
| 65 |
<p> |
| 66 |
<label for="<?php echo esc_attr( $this->get_field_id( 'zoom' ) ); ?>"><?php esc_html_e( 'Zoom', 'osm' ); ?></label> |
| 67 |
<select id="<?php echo esc_attr( $this->get_field_id( 'zoom' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'zoom' ) ); ?>" class="widefat" style="width:100%;"> |
| 68 |
<option <?php if ( '1' == $instance['zoom'] ) echo 'selected="selected"'; ?>>1</option> |
| 69 |
<option <?php if ( '2' == $instance['zoom'] ) echo 'selected="selected"'; ?>>2</option> |
| 70 |
<option <?php if ( '3' == $instance['zoom'] ) echo 'selected="selected"'; ?>>3</option> |
| 71 |
<option <?php if ( '4' == $instance['zoom'] ) echo 'selected="selected"'; ?>>4</option> |
| 72 |
<option <?php if ( '5' == $instance['zoom'] ) echo 'selected="selected"'; ?>>5</option> |
| 73 |
<option <?php if ( '6' == $instance['zoom'] ) echo 'selected="selected"'; ?>>6</option> |
| 74 |
<option <?php if ( '7' == $instance['zoom'] ) echo 'selected="selected"'; ?>>7</option> |
| 75 |
<option <?php if ( '8' == $instance['zoom'] ) echo 'selected="selected"'; ?>>8</option> |
| 76 |
<option <?php if ( '9' == $instance['zoom'] ) echo 'selected="selected"'; ?>>9</option> |
| 77 |
<option <?php if ( '10' == $instance['zoom'] ) echo 'selected="selected"'; ?>>10</option> |
| 78 |
<option <?php if ( '11' == $instance['zoom'] ) echo 'selected="selected"'; ?>>11</option> |
| 79 |
<option <?php if ( '12' == $instance['zoom'] ) echo 'selected="selected"'; ?>>12</option> |
| 80 |
<option <?php if ( '13' == $instance['zoom'] ) echo 'selected="selected"'; ?>>13</option> |
| 81 |
<option <?php if ( '14' == $instance['zoom'] ) echo 'selected="selected"'; ?>>14</option> |
| 82 |
<option <?php if ( '15' == $instance['zoom'] ) echo 'selected="selected"'; ?>>15</option> |
| 83 |
<option <?php if ( '16' == $instance['zoom'] ) echo 'selected="selected"'; ?>>16</option> |
| 84 |
<option <?php if ( '17' == $instance['zoom'] ) echo 'selected="selected"'; ?>>17</option> |
| 85 |
<option <?php if ( '18' == $instance['zoom'] ) echo 'selected="selected"'; ?>>18</option> |
| 86 |
</select> |
| 87 |
</p> |
| 88 |
<p> |
| 89 |
<label for="<?php echo esc_attr( $this->get_field_id( 'ctrl_theme' ) ); ?>"><?php esc_html_e( 'Control Theme', 'osm' ); ?></label> |
| 90 |
<select id="<?php echo esc_attr( $this->get_field_id( 'ctrl_theme' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'ctrl_theme' ) ); ?>" class="widefat" style="width:100%;"> |
| 91 |
<option <?php selected( $instance['ctrl_theme'], 'dark'); ?> value="dark"><?php esc_html_e( 'dark', 'osm' ); ?></option> |
| 92 |
<option <?php selected( $instance['ctrl_theme'], 'ol_orange'); ?> value="ol_orange"><?php esc_html_e( 'orange', 'osm' ); ?></option> |
| 93 |
<option <?php selected( $instance['ctrl_theme'], 'ol'); ?> value="ol"><?php esc_html_e( 'blue', 'osm' ); ?></option> |
| 94 |
|
| 95 |
<!--<option <?php if ( 'blue' == $instance['ctrl_theme'] ) echo 'selected="selected"'; ?>>blue</option> |
| 96 |
<option <?php if ( 'orange' == $instance['ctrl_theme'] ) echo 'selected="selected"'; ?>>orange</option> |
| 97 |
<option <?php if ( 'dark' == $instance['ctrl_theme'] ) echo 'selected="selected"'; ?>>dark</option> ---> |
| 98 |
</select> |
| 99 |
</p> |
| 100 |
<p> |
| 101 |
<label for="<?php echo esc_attr( $this->get_field_id( 'marker' ) ); ?>"><?php esc_html_e( 'marker', 'osm' ); ?></label> |
| 102 |
<select id="<?php echo esc_attr( $this->get_field_id( 'marker' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'marker' ) ); ?>" class="widefat" style="width:100%;"> |
| 103 |
<option <?php selected( $instance['marker'], 'wpttemp-green.png'); ?> value="wpttemp-green.png"><?php esc_html_e( 'Waypoint', 'osm' ); echo ' '; esc_html_e( 'green', 'osm' ); ?></option> |
| 104 |
<option <?php selected( $instance['marker'], 'wpttemp-red.png'); ?> value="wpttemp-red.png"><?php esc_html_e( 'Waypoint', 'osm' ); echo ' '; esc_html_e( 'red', 'osm' ); ?></option> |
| 105 |
<option <?php selected( $instance['marker'], 'wpttemp-yellow.png'); ?> value="wpttemp-yellow.png"><?php esc_html_e( 'Waypoint', 'osm' ); echo ' '; esc_html_e( 'yellow', 'osm' ); ?></option> |
| 106 |
<option <?php selected( $instance['marker'], 'mic_photo_icon.png'); ?> value="mic_photo_icon.png"><?php esc_html_e( 'Camera', 'osm' ); echo ' '; esc_html_e( 'black', 'osm' ); ?></option> |
| 107 |
<option <?php selected( $instance['marker'], 'mic_blue_bridge_old_01.png'); ?> value="mic_blue_bridge_old_01.png"><?php esc_html_e( 'Bridge', 'osm' ); echo ' '; esc_html_e( 'blue', 'osm' ); ?></option> |
| 108 |
<option <?php selected( $instance['marker'], 'mic_orange_hiking_01.png'); ?> value="mic_orange_hiking_01.png"><?php esc_html_e( 'Hiking', 'osm' ); echo ' '; esc_html_e( 'orange', 'osm' ); ?></option> |
| 109 |
</select> |
| 110 |
</p> |
| 111 |
<p> |
| 112 |
<label for="<?php echo esc_attr( $this->get_field_id( 'border_col' ) ); ?>"><?php esc_html_e( 'border', 'osm' ); ?></label> |
| 113 |
<select id="<?php echo esc_attr( $this->get_field_id( 'border_col' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'border_col' ) ); ?>" class="widefat" style="width:100%;"> |
| 114 |
<option <?php selected( $instance['border_col'], 'none'); ?> value="no"><?php esc_html_e( 'none', 'osm' ); ?></option> |
| 115 |
<option <?php selected( $instance['border_col'], 'green'); ?> value="green"><?php esc_html_e( 'green', 'osm' ); ?></option> |
| 116 |
<option <?php selected( $instance['border_col'], 'red'); ?> value="red"><?php esc_html_e( 'red', 'osm' ); ?></option> |
| 117 |
<option <?php selected( $instance['border_col'], 'blue'); ?> value="blue"><?php esc_html_e( 'blue', 'osm' ); ?></option> |
| 118 |
<option <?php selected( $instance['border_col'], 'orange'); ?> value="orange"><?php esc_html_e( 'orange', 'osm' ); ?></option> |
| 119 |
<option <?php selected( $instance['border_col'], 'black'); ?> value="black"><?php esc_html_e( 'black', 'osm' ); ?></option> |
| 120 |
<option <?php selected( $instance['border_col'], 'grey'); ?> value="grey"><?php esc_html_e( 'grey', 'osm' ); ?></option> |
| 121 |
</select> |
| 122 |
</p> |
| 123 |
<p> |
| 124 |
<label for="<?php echo esc_attr( $this->get_field_id( 'map_type' ) ); ?>"><?php esc_html_e( 'Map type', 'osm' ); ?></label> |
| 125 |
<select id="<?php echo esc_attr( $this->get_field_id( 'map_type' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'map_type' ) ); ?>" class="widefat" style="width:100%;"> |
| 126 |
<option <?php selected( $instance['map_type'], 'Mapnik'); ?> value="Mapnik"><?php esc_html_e( 'OpenStreetMap', 'osm' ); ?></option> |
| 127 |
<option <?php selected( $instance['map_type'], 'CycleMap'); ?> value="CycleMap"><?php esc_html_e( 'CycleMap', 'osm' ); ?></option> |
| 128 |
<option <?php selected( $instance['map_type'], 'OpenSeaMap'); ?> value="OpenSeaMap"><?php esc_html_e( 'OpenSeaMap', 'osm' ); ?></option> |
| 129 |
<option <?php selected( $instance['map_type'], 'basemap_at'); ?> value="basemap_at"><?php esc_html_e( 'BaseMap', 'osm' ); ?></option> |
| 130 |
<option <?php selected( $instance['map_type'], 'stamen_watercolor'); ?> value="stamen_watercolor"><?php esc_html_e( 'Stamen Watercolor', 'osm' ); ?></option> |
| 131 |
<option <?php selected( $instance['map_type'], 'stamen_toner'); ?> value="stamen_toner"><?php esc_html_e( 'Stamen Toner', 'osm' ); ?></option> |
| 132 |
</select> |
| 133 |
</p> |
| 134 |
<?php |
| 135 |
|
| 136 |
} |
| 137 |
|
| 138 |
public function update( $new_instance, $old_instance ) { |
| 139 |
$instance = array(); |
| 140 |
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? wp_strip_all_tags( $new_instance['title'] ) : ''; |
| 141 |
$instance['height'] = wp_strip_all_tags( $new_instance['height'] ); |
| 142 |
$instance['marker'] = wp_strip_all_tags( $new_instance['marker'] ); |
| 143 |
$instance['zoom'] = $new_instance['zoom']; |
| 144 |
$instance['map_type'] = $new_instance['map_type']; |
| 145 |
$instance['ctrl_theme'] = $new_instance['ctrl_theme']; |
| 146 |
$instance['border_col'] = wp_strip_all_tags( $new_instance['border_col'] ); |
| 147 |
return $instance; |
| 148 |
} |
| 149 |
|
| 150 |
} // class OSM_Widget |
| 151 |
|