/** * Shortcode callback function. * * @return string */ protected function do_shortcode() { extract($this->extract()); // Compose final HTML id attribute $final_id = strlen($id) ? $id : 'g1-gmap-counter-' . $this->get_counter(); // Compose final HTML class attribute $final_class = array('g1-gmap'); add_action('wp_footer', array($this, 'enqueue_scripts')); if (!$width) { $width = '100%'; } if (!$height) { return ''; } $inline_style = ' style="width: ' . esc_attr($width) . '; height: ' . esc_attr($height) . ';"'; $config = array('map_type' => !empty($map_type) ? $map_type : 'roadmap', 'invert_lightness' => $invert_lightness, 'latitude' => $latitude, 'longitude' => $longitude, 'zoom' => !empty($zoom) ? $zoom : 15, 'marker' => !empty($marker) ? $marker : 'none', 'marker_icon' => !empty($marker_icon) ? $marker_icon : '', 'type' => $type); if (!empty($color)) { $colorObj = new G1_Color($color); $colorConfig = array('color' => $color, 'color_hue' => '#' . $colorObj->get_hex(), 'color_saturation' => ($colorObj->get_saturation() - 50) * 2, 'color_lightness' => ($colorObj->get_lightness() - 50) * 2); $config = array_merge($config, $colorConfig); } $data_attr = ' data-g1-gmap-config="' . g1_data_capture($config) . '"'; // Compose output $out = '<div class="g1-gmap-wrapper">' . "\n"; $out .= '<div id="' . esc_attr($final_id) . '" class="' . sanitize_html_classes($final_class) . '"' . $data_attr . $inline_style . '>' . "\n"; $out .= '<div class="g1-gmap-content" style="display: none;">'; $out .= $content; $out .= '</div>'; $out .= '</div>'; $out .= '</div>' . "\n"; return $out; }
public function g1_gmaps_plugin_activate() { $migrated_map_id = get_option('g1_gmaps_migrated_map_id', false); if ($migrated_map_id) { return; } $options = get_option(G1_Theme()->get_id()); $color = $options['map_color']; // hex or empty string $invert_lightness = $options['map_invert_lightness'] === '1'; // bool $type = $options['map_type']; // roadmap | satellite | hybrid | terrain $center_lat = $options['map_latitude']; $center_long = $options['map_longitude']; $zoom = (int) $options['map_zoom']; // int $marker = $options['map_marker']; // none | standard | open-bubble $marker_icon = $options['map_marker_icon']; // image path $marker_content = $options['map_marker_content']; $marker_icon_id = null; if ($marker_icon) { $marker_icon_id = $this->get_image_id($marker_icon); } // create new map $defaults = G1_GMaps()->get_default_map_config(); $config = array('width' => '', 'height' => '380', 'full_width' => 'standard', 'parallax' => 'standard', 'street_view_control' => 'none', 'overview_control' => 'none', 'scroll_wheel_to_zoom' => 'none', 'double_click_to_zoom' => 'standard', 'draggable' => 'standard', 'type_control' => 'horizontal', 'pan_control' => 'standard', 'scale_control' => 'none', 'zoom_control' => 'small'); if ($center_lat) { $config['lat'] = $center_lat; } if ($center_long) { $config['long'] = $center_long; } if ($zoom) { $config['zoom'] = $zoom; } if ($type) { $config['type'] = $type; } if ($invert_lightness) { $config['invert_lightness'] = 'standard'; } if ($color) { $c = new G1_Color($color); $config['color_hue'] = $c->get_hue(); $config['color_saturation'] = $c->get_saturation() * 2 - 100; $config['color_lightness'] = $c->get_lightness() * 2 - 100; $config['custom_colors'] = 'standard'; } else { $config['custom_colors'] = 'none'; } $config = wp_parse_args($config, $defaults); $post = array('post_title' => 'Old map', 'post_status' => 'publish', 'post_type' => G1_GMaps()->get_post_type()); $post_id = wp_insert_post($post); if ($post_id > 0) { $data_to_save = array(); foreach ($config as $option_name => $option_value) { $data_to_save['map_' . $option_name] = $option_value; } update_post_meta($post_id, '_g1_gmap_lat', $data_to_save['map_lat']); update_post_meta($post_id, '_g1_gmap_long', $data_to_save['map_long']); update_post_meta($post_id, '_g1_gmap', $data_to_save); // create marker if ($marker !== 'none') { $marker_id = wp_insert_post(array('post_status' => 'publish', 'post_type' => G1_GMaps()->get_map_marker_post_type())); if ($marker_id > 0) { $marker_data_to_save = G1_GMaps()->get_default_map_marker_config(); $marker_data_to_save['lat'] = $data_to_save['map_lat']; $marker_data_to_save['long'] = $data_to_save['map_long']; $marker_data_to_save['label'] = 'Marker'; if ($marker_icon_id) { $marker_data_to_save['icon_id'] = $marker_icon_id; $marker_data_to_save['icon_path'] = $marker_icon; } $marker_data_to_save['info'] = $marker_content; $marker_data_to_save['info_state'] = $marker === 'open-bubble' ? 'standard' : 'none'; $marker_data_to_save['visibility'] = 'standard'; update_post_meta($marker_id, '_g1_gmap_id', $post_id); update_post_meta($marker_id, '_g1_gmap_marker_lat', $marker_data_to_save['lat']); update_post_meta($marker_id, '_g1_gmap_marker_long', $marker_data_to_save['long']); update_post_meta($marker_id, '_g1_gmap_marker', $marker_data_to_save); } } update_option('g1_gmaps_migrated_map_id', $post_id); $global_map_enabled = $options['ta_prefooter_gmap'] === 'standard'; // if map was enabled, we need to set it to new created map if ($global_map_enabled) { $options['ta_prefooter_gmap'] = $post_id; update_option(G1_Theme()->get_id(), $options); } } }