| 1 |
<?php |
| 2 |
/* |
| 3 |
* Google Maps Widget |
| 4 |
* Widget definition, admin GUI and front-end functions |
| 5 |
* (c) Web factory Ltd, 2012 - 2015 |
| 6 |
*/ |
| 7 |
|
| 8 |
|
| 9 |
// this is an include only file |
| 10 |
if (!defined('ABSPATH')) { |
| 11 |
die(); |
| 12 |
} |
| 13 |
|
| 14 |
|
| 15 |
// main widget class, extends WP widget interface/class |
| 16 |
class GoogleMapsWidget extends WP_Widget { |
| 17 |
static $widgets = array(); |
| 18 |
|
| 19 |
|
| 20 |
// constructor method |
| 21 |
function GoogleMapsWidget() { |
| 22 |
$widget_ops = array('classname' => 'google-maps-widget', 'description' => __('Displays a map image thumbnail with a larger map available in a lightbox.', 'google-maps-widget')); |
| 23 |
$control_ops = array('width' => 450, 'height' => 350); |
| 24 |
parent::__construct('GoogleMapsWidget', __('Google Maps Widget', 'google-maps-widget'), $widget_ops, $control_ops); |
| 25 |
} // GoogleMapsWidget |
| 26 |
|
| 27 |
|
| 28 |
// widget edit form HTML |
| 29 |
function form($instance) { |
| 30 |
$instance = wp_parse_args((array) $instance, |
| 31 |
array('title' => __('Map', 'google-maps-widget'), |
| 32 |
'address' => __('New York, USA', 'google-maps-widget'), |
| 33 |
'thumb_pin_color' => 'red', |
| 34 |
'thumb_pin_type' => 'predefined', |
| 35 |
'thumb_pin_size' => 'default', |
| 36 |
'thumb_pin_img' => '', |
| 37 |
'thumb_width' => '250', |
| 38 |
'thumb_height' => '250', |
| 39 |
'thumb_type' => 'roadmap', |
| 40 |
'thumb_zoom' => '13', |
| 41 |
'thumb_header' => '', |
| 42 |
'thumb_footer' => 'Powered by Google Maps Widget', |
| 43 |
'thumb_color_scheme' => '', |
| 44 |
'thumb_link_type' => 'lightbox', |
| 45 |
'thumb_link' => '', |
| 46 |
'lightbox_width' => '550', |
| 47 |
'lightbox_height' => '550', |
| 48 |
'lightbox_type' => 'roadmap', |
| 49 |
'lightbox_zoom' => '14', |
| 50 |
'lightbox_bubble' => '1', |
| 51 |
'lightbox_skin' => 'light', |
| 52 |
'lightbox_title' => '1', |
| 53 |
'lightbox_header' => '', |
| 54 |
'lightbox_footer' => '')); |
| 55 |
|
| 56 |
extract($instance, EXTR_SKIP); |
| 57 |
|
| 58 |
// legacy fixes for older versions; it's auto-fixed on first widget save but has to be here |
| 59 |
if(!$thumb_pin_type) { |
| 60 |
$thumb_pin_type = 'predefined'; |
| 61 |
} |
| 62 |
if(!$thumb_link_type) { |
| 63 |
$thumb_link_type = 'lightbox'; |
| 64 |
} |
| 65 |
if(!$lightbox_skin) { |
| 66 |
$lightbox_skin = 'light'; |
| 67 |
} |
| 68 |
|
| 69 |
$map_types_thumb = array(array('val' => 'roadmap', 'label' => __('Road (default)', 'google-maps-widget')), |
| 70 |
array('val' => 'satellite', 'label' => __('Satellite', 'google-maps-widget')), |
| 71 |
array('val' => 'terrain', 'label' => __('Terrain', 'google-maps-widget')), |
| 72 |
array('val' => 'hybrid', 'label' => __('Hybrid', 'google-maps-widget'))); |
| 73 |
|
| 74 |
$map_types_lightbox = array(array('val' => 'm', 'label' => __('Road (default)', 'google-maps-widget')), |
| 75 |
array('val' => 'k', 'label' => __('Satellite', 'google-maps-widget')), |
| 76 |
array('val' => 'p', 'label' => __('Terrain', 'google-maps-widget')), |
| 77 |
array('val' => 'h', 'label' => __('Hybrid', 'google-maps-widget'))); |
| 78 |
|
| 79 |
$pin_colors = array(array('val' => 'black', 'label' => __('Black', 'google-maps-widget')), |
| 80 |
array('val' => 'brown', 'label' => __('Brown', 'google-maps-widget')), |
| 81 |
array('val' => 'green', 'label' => __('Green', 'google-maps-widget')), |
| 82 |
array('val' => 'purple', 'label' => __('Purple', 'google-maps-widget')), |
| 83 |
array('val' => 'yellow', 'label' => __('Yellow', 'google-maps-widget')), |
| 84 |
array('val' => 'blue', 'label' => __('Blue', 'google-maps-widget')), |
| 85 |
array('val' => 'gray', 'label' => __('Gray', 'google-maps-widget')), |
| 86 |
array('val' => 'orange', 'label' => __('Orange', 'google-maps-widget')), |
| 87 |
array('val' => 'red', 'label' => __('Red (default)', 'google-maps-widget')), |
| 88 |
array('val' => 'white', 'label' => __('White', 'google-maps-widget'))); |
| 89 |
|
| 90 |
$pin_sizes = array(array('val' => 'tiny', 'label' => __('Tiny', 'google-maps-widget')), |
| 91 |
array('val' => 'small', 'label' => __('Small', 'google-maps-widget')), |
| 92 |
array('val' => 'mid', 'label' => __('Medium', 'google-maps-widget')), |
| 93 |
array('val' => 'default', 'label' => __('Large (default)', 'google-maps-widget'))); |
| 94 |
|
| 95 |
$zoom_levels = array(array('val' => '0', 'label' => __('0 - entire world', 'google-maps-widget'))); |
| 96 |
for ($tmp = 1; $tmp <= 21; $tmp++) { |
| 97 |
$zoom_levels[] = array('val' => $tmp, 'label' => $tmp); |
| 98 |
} |
| 99 |
|
| 100 |
$lightbox_skins = array(array('val' => 'light', 'label' => __('Light (default)', 'google-maps-widget')), |
| 101 |
array('val' => 'dark', 'label' => __('Dark', 'google-maps-widget'))); |
| 102 |
|
| 103 |
$lightbox_bubbles = array(array('val' => '0', 'label' => __('Hide', 'google-maps-widget')), |
| 104 |
array('val' => '1', 'label' => __('Show (default)', 'google-maps-widget'))); |
| 105 |
|
| 106 |
$lightbox_titles = array(array('val' => '0', 'label' => __('Do not show map title on lightbox', 'google-maps-widget')), |
| 107 |
array('val' => '1', 'label' => __('Show map title on lightbox (default)', 'google-maps-widget'))); |
| 108 |
|
| 109 |
$thumb_pin_types = array(array('val' => 'predefined', 'label' => __('Predefined (default)', 'google-maps-widget')), |
| 110 |
array('val' => 'custom', 'label' => __('Custom', 'google-maps-widget'))); |
| 111 |
|
| 112 |
$thumb_link_types = array(array('val' => 'lightbox', 'label' => __('Lightbox (default)', 'google-maps-widget')), |
| 113 |
array('val' => 'custom', 'label' => __('Custom URL', 'google-maps-widget')), |
| 114 |
array('val' => 'nolink', 'label' => __('Disable link', 'google-maps-widget'))); |
| 115 |
|
| 116 |
$thumb_color_schemes = array(array('val' => 'default', 'label' => __('Default', 'gmw')), |
| 117 |
array('val' => 'new', 'label' => __('Refreshed by Google', 'gmw'))); |
| 118 |
|
| 119 |
if (GMW::is_activated()) { |
| 120 |
array_push($thumb_color_schemes, array('val' => 'apple', 'label' => __('Apple', 'google-maps-widget')), |
| 121 |
array('val' => 'gray', 'label' => __('Gray', 'google-maps-widget')), |
| 122 |
array('val' => 'paper', 'label' => __('Paper', 'google-maps-widget'))); |
| 123 |
array_push($lightbox_skins, array('val' => 'noimage-blue', 'label' => __('Blue', 'google-maps-widget')), |
| 124 |
array('val' => 'noimage-rounded', 'label' => __('Rounded', 'google-maps-widget'))); |
| 125 |
} |
| 126 |
|
| 127 |
echo '<p><label for="' . $this->get_field_id('title') . '">' . __('Title', 'google-maps-widget') . ':</label><input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . esc_attr($title) . '" /></p>'; |
| 128 |
echo '<p><label for="' . $this->get_field_id('address') . '">' . __('Address', 'google-maps-widget') . ':</label><input class="widefat" id="' . $this->get_field_id('address') . '" name="' . $this->get_field_name('address') . '" type="text" value="' . esc_attr($address) . '" /></p>'; |
| 129 |
|
| 130 |
echo '<div class="gmw-tabs" id="tab-' . $this->id . '"><ul><li><a href="#gmw-thumb">' . __('Thumbnail map', 'google-maps-widget') . '</a></li><li><a href="#gmw-lightbox">' . __('Lightbox map', 'google-maps-widget') . '</a></li><li><a href="#gmw-shortcode">' . __('Shortcode', 'google-maps-widget') . '</a></li><li><a href="#gmw-info">' . __('Info & Support', 'google-maps-widget') . '</a></li></ul>'; |
| 131 |
echo '<div id="gmw-thumb">'; |
| 132 |
|
| 133 |
echo '<p><label class="gmw-label" for="' . $this->get_field_id('thumb_width') . '">' . __('Map Size', 'google-maps-widget') . ':</label>'; |
| 134 |
echo '<input class="small-text" id="' . $this->get_field_id('thumb_width') . '" name="' . $this->get_field_name('thumb_width') . '" type="text" value="' . esc_attr($thumb_width) . '" /> x '; |
| 135 |
echo '<input class="small-text" id="' . $this->get_field_id('thumb_height') . '" name="' . $this->get_field_name('thumb_height') . '" type="text" value="' . esc_attr($thumb_height) . '" />'; |
| 136 |
echo ' px</p>'; |
| 137 |
|
| 138 |
echo '<p><label class="gmw-label" for="' . $this->get_field_id('thumb_type') . '">' . __('Map Type', 'google-maps-widget') . ':</label>'; |
| 139 |
echo '<select id="' . $this->get_field_id('thumb_type') . '" name="' . $this->get_field_name('thumb_type') . '">'; |
| 140 |
GMW::create_select_options($map_types_thumb, $thumb_type); |
| 141 |
echo '</select></p>'; |
| 142 |
|
| 143 |
echo '<p><label class="gmw-label" for="' . $this->get_field_id('thumb_pin_type') . '">' . __('Pin Type', 'google-maps-widget') . ':</label>'; |
| 144 |
echo '<select class="gmw_thumb_pin_type" id="' . $this->get_field_id('thumb_pin_type') . '" name="' . $this->get_field_name('thumb_pin_type') . '">'; |
| 145 |
GMW::create_select_options($thumb_pin_types, $thumb_pin_type); |
| 146 |
echo '</select></p>'; |
| 147 |
|
| 148 |
echo '<p class="gmw_thumb_pin_type_predefined_section"><label class="gmw-label" for="' . $this->get_field_id('thumb_pin_color') . '">' . __('Pin Color', 'google-maps-widget') . ':</label>'; |
| 149 |
echo '<select id="' . $this->get_field_id('thumb_pin_color') . '" name="' . $this->get_field_name('thumb_pin_color') . '">'; |
| 150 |
GMW::create_select_options($pin_colors, $thumb_pin_color); |
| 151 |
echo '</select></p>'; |
| 152 |
|
| 153 |
echo '<p class="gmw_thumb_pin_type_predefined_section"><label class="gmw-label" for="' . $this->get_field_id('thumb_pin_size') . '">' . __('Pin Size', 'google-maps-widget') . ':</label>'; |
| 154 |
echo '<select id="' . $this->get_field_id('thumb_pin_size') . '" name="' . $this->get_field_name('thumb_pin_size') . '">'; |
| 155 |
GMW::create_select_options($pin_sizes, $thumb_pin_size); |
| 156 |
echo '</select></p>'; |
| 157 |
|
| 158 |
echo '<p class="gmw_thumb_pin_type_custom_section"><label class="gmw-label" for="' . $this->get_field_id('thumb_pin_img') . '">' . __('Pin Image URL', 'google-maps-widget') . ':</label>'; |
| 159 |
echo '<input type="text" class="regular-text" id="' . $this->get_field_id('thumb_pin_img') . '" name="' . $this->get_field_name('thumb_pin_img') . '" value="' . esc_attr($thumb_pin_img) . '">'; |
| 160 |
|
| 161 |
echo '<p><label class="gmw-label" for="' . $this->get_field_id('thumb_zoom') . '">' . __('Zoom Level', 'google-maps-widget') . ':</label>'; |
| 162 |
echo '<select id="' . $this->get_field_id('thumb_zoom') . '" name="' . $this->get_field_name('thumb_zoom') . '">'; |
| 163 |
GMW::create_select_options($zoom_levels, $thumb_zoom); |
| 164 |
echo '</select></p>'; |
| 165 |
|
| 166 |
echo '<p><label class="gmw-label" for="' . $this->get_field_id('thumb_link_type') . '">' . __('Link To', 'google-maps-widget') . ':</label>'; |
| 167 |
echo '<select class="gmw_thumb_link_type" id="' . $this->get_field_id('thumb_link_type') . '" name="' . $this->get_field_name('thumb_link_type') . '">'; |
| 168 |
GMW::create_select_options($thumb_link_types, $thumb_link_type); |
| 169 |
echo '</select></p>'; |
| 170 |
|
| 171 |
echo '<p class="gmw_thumb_link_section"><label class="gmw-label" for="' . $this->get_field_id('thumb_link') . '">' . __('Custom URL', 'google-maps-widget') . ':</label>'; |
| 172 |
echo '<input class="regular-text" id="' . $this->get_field_id('thumb_link') . '" name="' . $this->get_field_name('thumb_link') . '" type="text" value="' . esc_attr($thumb_link) . '" /></p>'; |
| 173 |
|
| 174 |
echo '<p><label class="gmw-label" for="' . $this->get_field_id('thumb_color_scheme') . '">' . __('Color Scheme', 'google-maps-widget') . ':</label>'; |
| 175 |
echo '<select class="gmw_thumb_color_scheme" id="' . $this->get_field_id('thumb_color_scheme') . '" name="' . $this->get_field_name('thumb_color_scheme') . '">'; |
| 176 |
GMW::create_select_options($thumb_color_schemes, $thumb_color_scheme); |
| 177 |
if (!GMW::is_activated()) { |
| 178 |
echo '<option class="promo" value="-1">' . __('Add more schemes for FREE', 'google-maps-widget') . '</option>'; |
| 179 |
} |
| 180 |
echo '</select></p>'; |
| 181 |
|
| 182 |
echo '<p><label for="' . $this->get_field_id('thumb_header') . '">' . __('Text Above Map', 'google-maps-widget') . ':</label>'; |
| 183 |
echo '<textarea class="widefat" rows="3" cols="20" id="' . $this->get_field_id('thumb_header') . '" name="' . $this->get_field_name('thumb_header') . '">'. esc_textarea($thumb_header) . '</textarea></p>'; |
| 184 |
|
| 185 |
echo '<p><label for="' . $this->get_field_id('thumb_footer') . '">' . __('Text Below Map', 'google-maps-widget') . ':</label>'; |
| 186 |
echo '<textarea class="widefat" rows="3" cols="20" id="' . $this->get_field_id('thumb_footer') . '" name="' . $this->get_field_name('thumb_footer') . '">'. esc_textarea($thumb_footer) . '</textarea></p>'; |
| 187 |
|
| 188 |
echo '</div>'; // thumbnail tab |
| 189 |
echo '<div id="gmw-lightbox">'; |
| 190 |
|
| 191 |
echo '<p><label class="gmw-label" for="' . $this->get_field_id('lightbox_width') . '">' . __('Map Size', 'google-maps-widget') . ':</label>'; |
| 192 |
echo '<input class="small-text" id="' . $this->get_field_id('lightbox_width') . '" name="' . $this->get_field_name('lightbox_width') . '" type="text" value="' . esc_attr($lightbox_width) . '" /> x '; |
| 193 |
echo '<input class="small-text" id="' . $this->get_field_id('lightbox_height') . '" name="' . $this->get_field_name('lightbox_height') . '" type="text" value="' . esc_attr($lightbox_height) . '" />'; |
| 194 |
echo ' px</p>'; |
| 195 |
|
| 196 |
echo '<p><label class="gmw-label" for="' . $this->get_field_id('lightbox_type') . '">' . __('Map Type', 'google-maps-widget') . ':</label>'; |
| 197 |
echo '<select id="' . $this->get_field_id('lightbox_type') . '" name="' . $this->get_field_name('lightbox_type') . '">'; |
| 198 |
GMW::create_select_options($map_types_lightbox, $lightbox_type); |
| 199 |
echo '</select></p>'; |
| 200 |
|
| 201 |
echo '<p><label class="gmw-label" for="' . $this->get_field_id('lightbox_zoom') . '">' . __('Zoom Level', 'google-maps-widget') . ':</label>'; |
| 202 |
echo '<select id="' . $this->get_field_id('lightbox_zoom') . '" name="' . $this->get_field_name('lightbox_zoom') . '">'; |
| 203 |
GMW::create_select_options($zoom_levels, $lightbox_zoom); |
| 204 |
echo '</select></p>'; |
| 205 |
|
| 206 |
echo '<p><label class="gmw-label" for="' . $this->get_field_id('lightbox_skin') . '">' . __('Lightbox Skin', 'google-maps-widget') . ':</label>'; |
| 207 |
echo '<select class="gmw_lightbox_skin" id="' . $this->get_field_id('lightbox_skin') . '" name="' . $this->get_field_name('lightbox_skin') . '">'; |
| 208 |
GMW::create_select_options($lightbox_skins, $lightbox_skin); |
| 209 |
if (!GMW::is_activated()) { |
| 210 |
echo '<option class="promo" value="-1">' . __('Add more skins for FREE', 'google-maps-widget') . '</option>'; |
| 211 |
} |
| 212 |
echo '</select></p>'; |
| 213 |
|
| 214 |
echo '<p><label class="gmw-label" for="' . $this->get_field_id('lightbox_bubble') . '">' . __('Address Bubble', 'google-maps-widget') . ':</label>'; |
| 215 |
echo '<select id="' . $this->get_field_id('lightbox_bubble') . '" name="' . $this->get_field_name('lightbox_bubble') . '">'; |
| 216 |
GMW::create_select_options($lightbox_bubbles, $lightbox_bubble); |
| 217 |
echo '</select></p>'; |
| 218 |
|
| 219 |
echo '<p><label class="gmw-label" for="' . $this->get_field_id('lightbox_title') . '">' . __('Map Title', 'google-maps-widget') . ': </label>'; |
| 220 |
echo '<select id="' . $this->get_field_id('lightbox_title') . '" name="' . $this->get_field_name('lightbox_title') . '">'; |
| 221 |
GMW::create_select_options($lightbox_titles, $lightbox_title); |
| 222 |
echo '</select></p>'; |
| 223 |
|
| 224 |
echo '<p><label for="' . $this->get_field_id('lightbox_header') . '">' . __('Header Text', 'google-maps-widget') . ':</label>'; |
| 225 |
echo '<textarea class="widefat" rows="3" cols="20" id="' . $this->get_field_id('lightbox_header') . '" name="' . $this->get_field_name('lightbox_header') . '">'. esc_textarea($lightbox_header) . '</textarea></p>'; |
| 226 |
|
| 227 |
echo '<p><label for="' . $this->get_field_id('lightbox_footer') . '">' . __('Footer Text', 'google-maps-widget') . ':</label>'; |
| 228 |
echo '<textarea class="widefat" rows="3" cols="20" id="' . $this->get_field_id('lightbox_footer') . '" name="' . $this->get_field_name('lightbox_footer') . '">'. esc_textarea($lightbox_footer) . '</textarea></p>'; |
| 229 |
|
| 230 |
echo '</div>'; // lightbox tab |
| 231 |
|
| 232 |
// shortcode tab |
| 233 |
echo '<div id="gmw-shortcode">'; |
| 234 |
if (GMW::is_activated()) { |
| 235 |
$id = str_replace('googlemapswidget-', '', $this->id); |
| 236 |
|
| 237 |
if (!$id || !is_numeric($id)) { |
| 238 |
echo '<p>' . __('Please save the widget so that the shortcode can be generated.', 'google-maps-widget') . '</p>'; |
| 239 |
} else { |
| 240 |
echo '<p><code>[gmw id="' . $id . '"]</code><br></p>'; |
| 241 |
echo '<p>' . __('Use the above shortcode to display this Google Maps Widget instance in any page or post. <br>Please note that your theme might style the widget in the post as if it is placed in a sidebar. In that case use the <code>span.gmw-shortcode-widget</code> class to target the shortcode and make necessary changes via CSS.', 'google-maps-widget') . '</p>'; |
| 242 |
} |
| 243 |
} else { |
| 244 |
echo '<p>Shortcode support is an extra feature. You can activate it <b>for free</b> and get more features & options for free as well.<br><br><a class="button open_promo_dialog" href="#">Activate extra features</a></p>'; |
| 245 |
} |
| 246 |
echo '</div>'; // shortcode tab |
| 247 |
|
| 248 |
echo '<div id="gmw-info">'; |
| 249 |
echo '<h4>' . __('Support', 'google-maps-widget') . '</h4>'; |
| 250 |
echo '<p>If you have any problems, questions or would like a new feature added post it on the <a href="https://wordpress.org/support/plugin/google-maps-widget" target="_blank">official support forum</a>. It\'s the only place to get support. Since it\'s free and community powered please be patient. <a target="_blank" href="https://www.paypal.com/cgi-bin/webscr?business=gordan@webfactoryltd.com&cmd=_xclick¤cy_code=USD&amount=19&item_name=Premium%20support%20for%20Google%20Maps%20Widget">Premium support</a> is available for $19.</p>'; |
| 251 |
echo '<h4>' . __('Activate extra features & options', 'google-maps-widget') . '</h4>'; |
| 252 |
echo '<p>' . __('If you subscribe to our mailing list we\'ll instantly activate additional features in the plugin! At the moment those features are: shortcode support, 3 additional thumbnail map skins and 2 additional lightbox skins. More <i>activate by subscribing</i> features will be available soon!', 'google-maps-widget') . '<br>'; |
| 253 |
if (GMW::is_activated()) { |
| 254 |
echo __('You\'ve already subscribed and activated extra features. Thank you!', 'google-maps-widget'); |
| 255 |
} else { |
| 256 |
echo __('Subscribe and <a class="open_promo_dialog" href="#">activate extra features</a>.', 'google-maps-widget'); |
| 257 |
} |
| 258 |
echo '</p>'; |
| 259 |
echo '<h4>' . __('Rate the plugin & spread the word', 'google-maps-widget') . '</h4>'; |
| 260 |
echo '<p>It won\'t take you more than a minute but it will help us immensely. So please - <a href="https://wordpress.org/support/view/plugin-reviews/google-maps-widget" target="_blank">rate the plugin</a>. Or spread the word by <a href="https://twitter.com/intent/tweet?via=WebFactoryLtd&text=' . urlencode('I\'m using the #free Google Maps Widget for #wordpress. You can grab it too at http://goo.gl/2qcbbf') . '" target="_blank">tweeting about it</a>. Thank you!</p>'; |
| 261 |
echo '</div>'; // info tab |
| 262 |
|
| 263 |
echo '</div><p></p>'; // tabs |
| 264 |
|
| 265 |
if (!GMW::is_activated()) { |
| 266 |
echo '<p>' . __('Click to <a href="#" class="open_promo_dialog">get extra premium features</a> for Google Maps Widget! For <b><span style="color: #d54e21;">FREE</span></b>.', 'google-maps-widget') . '</p>'; |
| 267 |
} |
| 268 |
} // form |
| 269 |
|
| 270 |
|
| 271 |
// update/save widget options |
| 272 |
function update($new_instance, $old_instance) { |
| 273 |
$instance = $old_instance; |
| 274 |
|
| 275 |
$instance['title'] = $new_instance['title']; |
| 276 |
$instance['address'] = $new_instance['address']; |
| 277 |
$instance['thumb_pin_type'] = $new_instance['thumb_pin_type']; |
| 278 |
$instance['thumb_pin_color'] = $new_instance['thumb_pin_color']; |
| 279 |
$instance['thumb_pin_size'] = $new_instance['thumb_pin_size']; |
| 280 |
$instance['thumb_pin_img'] = trim($new_instance['thumb_pin_img']); |
| 281 |
$instance['thumb_width'] = (int) $new_instance['thumb_width']; |
| 282 |
$instance['thumb_height'] = (int) $new_instance['thumb_height']; |
| 283 |
$instance['thumb_zoom'] = $new_instance['thumb_zoom']; |
| 284 |
$instance['thumb_type'] = $new_instance['thumb_type']; |
| 285 |
$instance['thumb_link_type'] = $new_instance['thumb_link_type']; |
| 286 |
$instance['thumb_link'] = trim($new_instance['thumb_link']); |
| 287 |
$instance['thumb_header'] = trim($new_instance['thumb_header']); |
| 288 |
$instance['thumb_footer'] = trim($new_instance['thumb_footer']); |
| 289 |
$instance['thumb_color_scheme'] = $new_instance['thumb_color_scheme']; |
| 290 |
$instance['lightbox_width'] = (int) $new_instance['lightbox_width']; |
| 291 |
$instance['lightbox_height'] = (int) $new_instance['lightbox_height']; |
| 292 |
$instance['lightbox_type'] = $new_instance['lightbox_type']; |
| 293 |
$instance['lightbox_zoom'] = $new_instance['lightbox_zoom']; |
| 294 |
$instance['lightbox_bubble'] = $new_instance['lightbox_bubble']; |
| 295 |
$instance['lightbox_title'] = $new_instance['lightbox_title']; |
| 296 |
$instance['lightbox_header'] = trim($new_instance['lightbox_header']); |
| 297 |
$instance['lightbox_footer'] = trim($new_instance['lightbox_footer']); |
| 298 |
$instance['lightbox_skin'] = $new_instance['lightbox_skin']; |
| 299 |
$instance['core_ver'] = GMW::$version; |
| 300 |
|
| 301 |
return $instance; |
| 302 |
} // update |
| 303 |
|
| 304 |
|
| 305 |
// echo widget |
| 306 |
function widget($args, $instance) { |
| 307 |
$out = $tmp = ''; |
| 308 |
|
| 309 |
$thumb_styles = array( |
| 310 |
'apple' => 'style=feature:water|element:geometry|color:0xa2daf2|&style=feature:landscape.man_made|element:geometry|color:0xf7f1df|&style=feature:landscape.natural|element:geometry|color:0xd0e3b4|&style=feature:landscape.natural.terrain|element:geometry|visibility:off|&style=feature:poi.park|element:geometry|color:0xbde6ab|&style=feature:poi|element:labels|visibility:off|&style=feature:poi.medical|element:geometry|color:0xfbd3da|&style=feature:poi.business|element:all|visibility:off|&style=feature:road|element:geometry.stroke|visibility:off|&style=feature:road|element:labels|visibility:off|&style=feature:road.highway|element:geometry.fill|color:0xffe15f|&style=feature:road.highway|element:geometry.stroke|color:0xefd151|&style=feature:road.arterial|element:geometry.fill|color:0xffffff|&style=feature:road.local|element:geometry.fill|color:black|&style=feature:transit.station.airport|element:geometry.fill|color:0xcfb2db|', |
| 311 |
'gray' => 'style=feature:landscape|element:all|saturation:-100|lightness:65|visibility:on|&style=feature:poi|element:all|saturation:-100|lightness:51|visibility:simplified|&style=feature:road.highway|element:all|saturation:-100|visibility:simplified|&style=feature:road.arterial|element:all|saturation:-100|lightness:30|visibility:on|&style=feature:road.local|element:all|saturation:-100|lightness:40|visibility:on|&style=feature:transit|element:all|saturation:-100|visibility:simplified|&style=feature:administrative.province|element:all|visibility:off|&style=feature:water|element:labels|visibility:on|lightness:-25|saturation:-100|&style=feature:water|element:geometry|hue:0xffff00|lightness:-25|saturation:-97|', |
| 312 |
'paper' => 'style=feature:landscape|element:all|hue:0xF1FF00|saturation:-27.4|lightness:9.4|gamma:1|&style=feature:road.highway|element:all|hue:0x0099FF|saturation:-20|lightness:36.4|gamma:1|&style=feature:road.arterial|element:all|hue:0x00FF4F|saturation:0|lightness:0|gamma:1|&style=feature:road.local|element:all|hue:0xFFB300|saturation:-38|lightness:11.2|gamma:1|&style=feature:water|element:all|hue:0x00B6FF|saturation:4.2|lightness:-63.4|gamma:1|&style=feature:poi|element:all|hue:0x9FFF00|saturation:0|lightness:0|gamma:1|'); |
| 313 |
|
| 314 |
extract($args, EXTR_SKIP); |
| 315 |
|
| 316 |
$ll = ''; |
| 317 |
if ($instance['lightbox_zoom'] > 14) { |
| 318 |
$coordinates = GMW::get_coordinates($instance['address']); |
| 319 |
if ($coordinates) { |
| 320 |
$ll = $coordinates['lat'] . ',' . $coordinates['lng']; |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
$lang = substr(@$_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); |
| 325 |
if (!$lang) { |
| 326 |
$lang = 'en'; |
| 327 |
} |
| 328 |
|
| 329 |
// legacy fix for older versions; it's auto-fixed on first widget save but has to be here |
| 330 |
if(!$instance['lightbox_skin']) { |
| 331 |
$instance['lightbox_skin'] = 'light'; |
| 332 |
} |
| 333 |
|
| 334 |
self::$widgets[] = array('title' => ($instance['lightbox_title']? $instance['title']: ''), |
| 335 |
'width' => $instance['lightbox_width'], |
| 336 |
'height' => $instance['lightbox_height'], |
| 337 |
'footer' => $instance['lightbox_footer'], |
| 338 |
'header' => $instance['lightbox_header'], |
| 339 |
'address' => $instance['address'], |
| 340 |
'zoom' => $instance['lightbox_zoom'], |
| 341 |
'type' => $instance['lightbox_type'], |
| 342 |
'skin' => $instance['lightbox_skin'], |
| 343 |
'bubble' => $instance['lightbox_bubble'], |
| 344 |
'll' => $ll, |
| 345 |
'id' => $widget_id); |
| 346 |
|
| 347 |
$out .= $before_widget; |
| 348 |
|
| 349 |
if (!isset($instance['thumb_pin_type']) || empty($instance['thumb_pin_type'])) { |
| 350 |
$instance['thumb_pin_type'] = 'predefined'; |
| 351 |
} |
| 352 |
|
| 353 |
if (!isset($instance['thumb_link_type']) || empty($instance['thumb_link_type'])) { |
| 354 |
$instance['thumb_link_type'] = 'lightbox'; |
| 355 |
} |
| 356 |
|
| 357 |
$title = empty($instance['title'])? ' ' : apply_filters('widget_title', $instance['title']); |
| 358 |
if (!empty($title)) { |
| 359 |
$out .= $before_title . $title . $after_title; |
| 360 |
} |
| 361 |
|
| 362 |
if (isset($instance['thumb_header']) && $instance['thumb_header']) { |
| 363 |
$tmp .= wpautop(do_shortcode($instance['thumb_header'])); |
| 364 |
} |
| 365 |
$tmp .= '<p>'; |
| 366 |
|
| 367 |
if ($instance['thumb_link_type'] == 'lightbox') { |
| 368 |
$alt = __('Click to open larger map', 'google-maps-widget'); |
| 369 |
} else { |
| 370 |
$alt = esc_attr($instance['address']); |
| 371 |
} |
| 372 |
|
| 373 |
if ($instance['thumb_link_type'] == 'lightbox') { |
| 374 |
$tmp .= '<a class="gmw-thumbnail-map gmw-lightbox-enabled" href="#gmw-dialog-' . $widget_id . '" title="' . __('Click to open larger map', 'google-maps-widget') . '">'; |
| 375 |
} elseif ($instance['thumb_link_type'] == 'custom') { |
| 376 |
$tmp .= '<a class="gmw-thumbnail-map" title="' . esc_attr($instance['address']) . '" href="' . $instance['thumb_link'] . '">'; |
| 377 |
} |
| 378 |
$tmp .= '<img alt="' . $alt . '" title="' . $alt . '" src="//maps.googleapis.com/maps/api/staticmap?center=' . |
| 379 |
urlencode($instance['address']) . '&zoom=' . $instance['thumb_zoom'] . |
| 380 |
'&size=' . $instance['thumb_width'] . 'x' . $instance['thumb_height'] . '&maptype=' . $instance['thumb_type'] . |
| 381 |
'&scale=1&'; |
| 382 |
if ($instance['thumb_pin_type'] != 'custom') { |
| 383 |
$tmp .= 'markers=size:' . $instance['thumb_pin_size'] . '%7Ccolor:' . $instance['thumb_pin_color']; |
| 384 |
} else { |
| 385 |
$tmp .= 'markers=icon:' . urlencode($instance['thumb_pin_img']); |
| 386 |
} |
| 387 |
$tmp .= '%7Clabel:A%7C' . urlencode($instance['address']) . '&language=' . $lang; |
| 388 |
if (!isset($instance['thumb_color_scheme']) || $instance['thumb_color_scheme'] == 'default') { |
| 389 |
$tmp .= '&visual_refresh=false'; |
| 390 |
} elseif ($instance['thumb_color_scheme'] == 'new') { |
| 391 |
$tmp .= '&visual_refresh=true'; |
| 392 |
} elseif (GMW::is_activated()) { |
| 393 |
$tmp .= '&' . str_replace('&', '&', $thumb_styles[$instance['thumb_color_scheme']]); |
| 394 |
} |
| 395 |
$tmp .= '">'; |
| 396 |
if ($instance['thumb_link_type'] == 'lightbox' || $instance['thumb_link_type'] == 'custom') { |
| 397 |
$tmp .= '</a>'; |
| 398 |
} |
| 399 |
$tmp .= '</p>'; |
| 400 |
if (isset($instance['thumb_footer']) && $instance['thumb_footer']) { |
| 401 |
if ($instance['thumb_footer'] == 'Powered by Google Maps Widget') { |
| 402 |
$tmp .= '<span class="gmw-powered-by">Powered by <a title="Powered by free Google Maps Widget plugin for WordPress" href="http://www.googlemapswidget.com" target="_blank">Google Maps Widget</a></span>'; |
| 403 |
} else { |
| 404 |
$tmp .= wpautop(do_shortcode($instance['thumb_footer'])); |
| 405 |
} |
| 406 |
} |
| 407 |
$out .= apply_filters('google_maps_widget_content', $tmp); |
| 408 |
|
| 409 |
$out .= $after_widget; |
| 410 |
|
| 411 |
echo $out; |
| 412 |
} // widget |
| 413 |
} // class GoogleMapsWidget |