Пример #1
0
/**
 * Handle the WPGMZA shortcode
 * The shortcode attributes are identified and the relevant data is localized and the JS file enqueued
 * @param  array    $atts   array of shortcode attributes
 * @return void
 */
function wpgmaps_tag_basic($atts)
{
    global $wpgmza_current_map_id;
    global $wpgmza_version;
    global $short_code_active;
    global $wpgmza_override;
    extract(shortcode_atts(array('id' => '1'), $atts));
    $ret_msg = "";
    $wpgmza_current_map_id = $atts['id'];
    $res = wpgmza_get_map_data($atts['id']);
    if (!isset($res)) {
        echo __("Error: The map ID", "wp-google-maps") . " (" . $wpgmza_current_map_id . ") " . __("does not exist", "wp-google-maps");
        return;
    }
    $user_api_key = get_option('wpgmza_google_maps_api_key');
    if (!$user_api_key || $user_api_key == "") {
        $adminurl = admin_url('admin.php?page=wp-google-maps-menu-settings#tabs-4');
        $link = sprintf(__("In order for your map to display, please make sure you insert your Google Maps JavaScript API key in the <a href='%s' target='_BLANK'>Maps->Settings->Advanced tab</a>.", 'wp-google-maps'), $adminurl);
        echo "<div class='wpgmza_error' style='background-image:url(" . plugins_url('images/map-bg.jpg', __FILE__) . "); display:block; padding:15px; border:1px solid #eee; overflow:auto;'>";
        echo "<h3>" . __("WP Google Maps Error", "wp-google-maps") . "</h3>";
        echo "<p style='color:#333;'><strong>" . $link . "</strong></p>";
        echo "</div>";
        return;
    }
    if (!function_exists('wpgmaps_admin_styles_pro')) {
        wp_register_style('wpgmaps-style', plugins_url('css/wpgmza_style.css', __FILE__), array(), $wpgmza_version);
        wp_enqueue_style('wpgmaps-style');
    }
    if (isset($atts['zoom'])) {
        $zoom_override = $atts['zoom'];
        $wpgmza_override['zoom'] = $zoom_override;
    }
    $map_align = $res->alignment;
    $wpgmza_settings = get_option("WPGMZA_OTHER_SETTINGS");
    if (isset($wpgmza_settings['wpgmza_settings_marker_pull']) && $wpgmza_settings['wpgmza_settings_marker_pull'] == '0') {
    } else {
        /* only check if marker file exists if they are using the XML method */
        wpgmza_check_if_marker_file_exists($wpgmza_current_map_id);
    }
    $map_width_type = stripslashes($res->map_width_type);
    $map_height_type = stripslashes($res->map_height_type);
    if (!isset($map_width_type)) {
        $map_width_type == "px";
    }
    if (!isset($map_height_type)) {
        $map_height_type == "px";
    }
    if ($map_width_type == "%" && intval($res->map_width) > 100) {
        $res->map_width = 100;
    }
    if ($map_height_type == "%" && intval($res->map_height) > 100) {
        $res->map_height = 100;
    }
    if (!$map_align || $map_align == "" || $map_align == "1") {
        $map_align = "float:left;";
    } else {
        if ($map_align == "2") {
            $map_align = "margin-left:auto !important; margin-right:auto; !important; align:center;";
        } else {
            if ($map_align == "3") {
                $map_align = "float:right;";
            } else {
                if ($map_align == "4") {
                    $map_align = "";
                }
            }
        }
    }
    $map_style = "style=\"display:block; overflow:auto; width:" . $res->map_width . "" . $map_width_type . "; height:" . $res->map_height . "" . $map_height_type . "; {$map_align}\"";
    $map_other_settings = maybe_unserialize($res->other_settings);
    $sl_data = "";
    if (isset($map_other_settings['store_locator_enabled']) && $map_other_settings['store_locator_enabled'] == 1) {
        $sl_data = wpgmaps_sl_user_output_basic($wpgmza_current_map_id);
    } else {
        $sl_data = "";
    }
    $ret_msg .= "\n            <style>\n            #wpgmza_map img { max-width:none !important; }\n            .wpgmza_widget { overflow: auto; }\n            </style>\n            \n            {$sl_data}    \n            <div id=\"wpgmza_map\" {$map_style}>\n            </div>\n        ";
    if (isset($wpgmza_main_settings['wpgmza_custom_css']) && $wpgmza_main_settings['wpgmza_custom_css'] != "") {
        $ret_msg = "\n            <!-- WP Google Maps Custom CSS -->\n            <style type=\"text/css\">" . $wpgmza_main_settings['wpgmza_custom_css'] . "</style>\n            " . $ret_msg;
    }
    $wpgmza_locale = get_locale();
    $wpgmza_suffix = ".com";
    /* Hebrew correction */
    if ($wpgmza_locale == "he_IL") {
        $wpgmza_locale = "iw";
    }
    /* Chinese integration */
    if ($wpgmza_locale == "zh_CN") {
        $wpgmza_suffix = ".cn";
    } else {
        $wpgmza_suffix = ".com";
    }
    $wpgmza_settings = get_option("WPGMZA_OTHER_SETTINGS");
    /**
     * Only register the below scrips so that they are available on demand. 
     */
    if (isset($wpgmza_settings['wpgmza_settings_remove_api']) && $wpgmza_settings['wpgmza_settings_remove_api'] == "yes") {
        $wpgaps_core_dependancy = array();
    } else {
        if (isset($wpgmza_settings['wpgmza_api_version']) && $wpgmza_settings['wpgmza_api_version'] != "") {
            $api_version_string = "v=" . $wpgmza_settings['wpgmza_api_version'] . "&";
        } else {
            $api_version_string = "v=3.exp&";
        }
        $wpgmza_api_key = get_option('wpgmza_google_maps_api_key');
        if ($wpgmza_api_key) {
            wp_enqueue_script('wpgmza_api_call', '//maps.google' . $wpgmza_suffix . '/maps/api/js?' . $api_version_string . 'key=' . $wpgmza_api_key . '&language=' . $wpgmza_locale, array(), null);
        } else {
            wp_enqueue_script('wpgmza_api_call', '//maps.google' . $wpgmza_suffix . '/maps/api/js?' . $api_version_string . 'language=' . $wpgmza_locale, array(), null);
        }
        $wpgaps_core_dependancy = array('wpgmza_api_call');
    }
    wp_enqueue_script('wpgmaps_core', plugins_url('/js/wpgmaps.min.js', __FILE__), $wpgaps_core_dependancy, $wpgmza_version . 'b', false);
    $res = array();
    $res[0] = wpgmza_get_map_data($wpgmza_current_map_id);
    $wpgmza_settings = get_option("WPGMZA_OTHER_SETTINGS");
    if (isset($wpgmza_settings['wpgmza_api_version'])) {
        $api_version = $wpgmza_settings['wpgmza_api_version'];
        if (isset($api_version) && $api_version != "") {
            $api_version_string = "v={$api_version}&";
        } else {
            $api_version_string = "v=3.exp&";
        }
    } else {
        $api_version_string = "v=3.exp&";
    }
    $map_other_settings = maybe_unserialize($res[0]->other_settings);
    $res[0]->other_settings = $map_other_settings;
    $res[0]->map_width_type = stripslashes($res[0]->map_width_type);
    if (isset($res[0]->other_settings['wpgmza_theme_data']) && $res[0]->other_settings['wpgmza_theme_data'] != '') {
        $res[0]->other_settings['wpgmza_theme_data'] = html_entity_decode(stripslashes($res[0]->other_settings['wpgmza_theme_data']));
    }
    $polygonoptions = array();
    $total_poly_array = wpgmza_b_return_polygon_id_array($wpgmza_current_map_id);
    if ($total_poly_array > 0) {
        foreach ($total_poly_array as $poly_id) {
            $polygonoptions[$poly_id] = wpgmza_b_return_poly_options($poly_id);
            $tmp_poly_array = wpgmza_b_return_polygon_array($poly_id);
            $poly_data_raw_array = array();
            foreach ($tmp_poly_array as $single_poly) {
                $poly_data_raw = str_replace(" ", "", $single_poly);
                $poly_data_raw = explode(",", $poly_data_raw);
                $lat = $poly_data_raw[0];
                $lng = $poly_data_raw[1];
                $poly_data_raw_array[] = $poly_data_raw;
            }
            $polygonoptions[$poly_id]->polydata = $poly_data_raw_array;
            $linecolor = $polygonoptions[$poly_id]->linecolor;
            $fillcolor = $polygonoptions[$poly_id]->fillcolor;
            $fillopacity = $polygonoptions[$poly_id]->opacity;
            if (!$linecolor) {
                $polygonoptions[$poly_id]->linecolor = "000000";
            }
            if (!$fillcolor) {
                $polygonoptions[$poly_id]->fillcolor = "66FF00";
            }
            if (!$fillopacity) {
                $polygonoptions[$poly_id]->opacity = "0.5";
            }
        }
    } else {
        $polygonoptions = array();
    }
    $polylineoptions = array();
    $total_poly_array = wpgmza_b_return_polyline_id_array($wpgmza_current_map_id);
    if ($total_poly_array > 0) {
        foreach ($total_poly_array as $poly_id) {
            $polylineoptions[$poly_id] = wpgmza_b_return_polyline_options($poly_id);
            $tmp_poly_array = wpgmza_b_return_polyline_array($poly_id);
            $poly_data_raw_array = array();
            foreach ($tmp_poly_array as $single_poly) {
                $poly_data_raw = str_replace(" ", "", $single_poly);
                $poly_data_raw = str_replace(")", "", $poly_data_raw);
                $poly_data_raw = str_replace("(", "", $poly_data_raw);
                $poly_data_raw = explode(",", $poly_data_raw);
                $lat = $poly_data_raw[0];
                $lng = $poly_data_raw[1];
                $poly_data_raw_array[] = $poly_data_raw;
            }
            $polylineoptions[$poly_id]->polydata = $poly_data_raw_array;
            if (isset($polylineoptions[$poly_id]->linecolor)) {
                $linecolor = $polylineoptions[$poly_id]->linecolor;
            } else {
                $linecolor = false;
            }
            if (isset($polylineoptions[$poly_id]->fillcolor)) {
                $fillcolor = $polylineoptions[$poly_id]->fillcolor;
            } else {
                $fillcolor = false;
            }
            if (isset($polylineoptions[$poly_id]->opacity)) {
                $fillopacity = $polylineoptions[$poly_id]->opacity;
            } else {
                $fillopacity = false;
            }
            if (!$linecolor) {
                $polylineoptions[$poly_id]->linecolor = "000000";
            }
            if (!$fillcolor) {
                $polylineoptions[$poly_id]->fillcolor = "66FF00";
            }
            if (!$fillopacity) {
                $polylineoptions[$poly_id]->opacity = "0.5";
            }
        }
    } else {
        $polylineoptions = array();
    }
    if (isset($wpgmza_settings['wpgmza_settings_marker_pull']) && $wpgmza_settings['wpgmza_settings_marker_pull'] == "0") {
        $markers = wpgmaps_return_markers($wpgmza_current_map_id);
    }
    do_action("wpgooglemaps_basic_hook_user_js_after_core");
    wp_localize_script('wpgmaps_core', 'wpgmaps_localize', $res);
    wp_localize_script('wpgmaps_core', 'wpgmaps_localize_polygon_settings', $polygonoptions);
    wp_localize_script('wpgmaps_core', 'wpgmaps_localize_polyline_settings', $polylineoptions);
    wp_localize_script('wpgmaps_core', 'wpgmaps_markerurl', wpgmaps_get_marker_url($wpgmza_current_map_id));
    if ($wpgmza_settings['wpgmza_settings_marker_pull'] == "0") {
        wp_localize_script('wpgmaps_core', 'wpgmaps_localize_marker_data', $markers);
    }
    $wpgmza_settings = apply_filters("wpgmza_basic_filter_localize_settings", $wpgmza_settings);
    wp_localize_script('wpgmaps_core', 'wpgmaps_localize_global_settings', $wpgmza_settings);
    wp_localize_script('wpgmaps_core', 'wpgmaps_lang_km_away', __("km away", "wp-google-maps"));
    wp_localize_script('wpgmaps_core', 'wpgmaps_lang_m_away', __("miles away", "wp-google-maps"));
    return $ret_msg;
}
Пример #2
0
function wpgmaps_tag_basic($atts)
{
    global $wpgmza_current_map_id;
    extract(shortcode_atts(array('id' => '1'), $atts));
    $ret_msg = "";
    global $short_code_active;
    $wpgmza_current_map_id = $atts['id'];
    $res = wpgmza_get_map_data($atts['id']);
    if (!isset($res)) {
        echo __("Error: The map ID", "wp-google-maps") . " (" . $wpgmza_current_map_id . ") " . __("does not exist", "wp-google-maps");
        return;
    }
    $short_code_active = true;
    //$wpgmza_data = get_option('WPGMZA');
    $map_align = $res->alignment;
    wpgmza_check_if_marker_file_exists($wpgmza_current_map_id);
    $map_width_type = stripslashes($res->map_width_type);
    $map_height_type = stripslashes($res->map_height_type);
    if (!isset($map_width_type)) {
        $map_width_type == "px";
    }
    if (!isset($map_height_type)) {
        $map_height_type == "px";
    }
    if ($map_width_type == "%" && intval($res->map_width) > 100) {
        $res->map_width = 100;
    }
    if ($map_height_type == "%" && intval($res->map_height) > 100) {
        $res->map_height = 100;
    }
    if (!$map_align || $map_align == "" || $map_align == "1") {
        $map_align = "float:left;";
    } else {
        if ($map_align == "2") {
            $map_align = "margin-left:auto !important; margin-right:auto; !important; align:center;";
        } else {
            if ($map_align == "3") {
                $map_align = "float:right;";
            } else {
                if ($map_align == "4") {
                    $map_align = "";
                }
            }
        }
    }
    $map_style = "style=\"display:block; overflow:auto; width:" . $res->map_width . "" . $map_width_type . "; height:" . $res->map_height . "" . $map_height_type . "; {$map_align}\"";
    $map_other_settings = maybe_unserialize($res->other_settings);
    $sl_data = "";
    if (isset($map_other_settings['store_locator_enabled']) && $map_other_settings['store_locator_enabled'] == 1) {
        $sl_data = wpgmaps_sl_user_output_basic($wpgmza_current_map_id);
    } else {
        $sl_data = "";
    }
    $ret_msg .= "\r\n            <style>\r\n            #wpgmza_map img { max-width:none !important; }\r\n            </style>\r\n            \r\n            {$sl_data}    \r\n            <div id=\"wpgmza_map\" {$map_style}>\r\n            </div>\r\n        ";
    $wpgmza_main_settings = get_option("WPGMZA_OTHER_SETTINGS");
    if (isset($wpgmza_main_settings['wpgmza_custom_css']) && $wpgmza_main_settings['wpgmza_custom_css'] != "") {
        $ret_msg = "\r\n            <!-- WP Google Maps Custom CSS -->\r\n            <style type=\"text/css\">" . $wpgmza_main_settings['wpgmza_custom_css'] . "</style>\r\n            " . $ret_msg;
    }
    return $ret_msg;
}
Пример #3
0
function wpgmaps_tag_basic($atts)
{
    global $wpgmza_current_map_id;
    extract(shortcode_atts(array('id' => '1'), $atts));
    $ret_msg = "";
    global $short_code_active;
    $wpgmza_current_map_id = $atts['id'];
    $res = wpgmza_get_map_data($atts['id']);
    $short_code_active = true;
    //$wpgmza_data = get_option('WPGMZA');
    $map_align = $res->alignment;
    wpgmza_check_if_marker_file_exists($wpgmza_current_map_id);
    $map_width_type = stripslashes($res->map_width_type);
    $map_height_type = stripslashes($res->map_height_type);
    if (!isset($map_width_type)) {
        $map_width_type == "px";
    }
    if (!isset($map_height_type)) {
        $map_height_type == "px";
    }
    if ($map_width_type == "%" && intval($res->map_width) > 100) {
        $res->map_width = 100;
    }
    if ($map_height_type == "%" && intval($res->map_height) > 100) {
        $res->map_height = 100;
    }
    if (!$map_align || $map_align == "" || $map_align == "1") {
        $map_align = "float:left;";
    } else {
        if ($map_align == "2") {
            $map_align = "margin-left:auto !important; margin-right:auto; !important; align:center;";
        } else {
            if ($map_align == "3") {
                $map_align = "float:right;";
            } else {
                if ($map_align == "4") {
                    $map_align = "";
                }
            }
        }
    }
    $map_style = "style=\"display:block; overflow:auto; width:" . $res->map_width . "" . $map_width_type . "; height:" . $res->map_height . "" . $map_height_type . "; {$map_align}\"";
    $map_other_settings = maybe_unserialize($res->other_settings);
    $sl_data = "";
    if ($map_other_settings['store_locator_enabled'] == 1) {
        $sl_data = wpgmaps_sl_user_output_basic($wpgmza_current_map_id);
    } else {
        $sl_data = "";
    }
    $ret_msg .= "\n            <style>\n            #wpgmza_map img { max-width:none !important; }\n            </style>\n            \n            {$sl_data}    \n            <div id=\"wpgmza_map\" {$map_style}>\n                <div style='text-align:center; width:90%;'>\n                        <small><strong>" . __("The map could not load.", "wp-google-maps") . "</strong><br />" . __("This is normally caused by a conflict with another plugin or a JavaScript error that is preventing our plugin's Javascript from executing. Please try disable all plugins one by one and see if this problem persists. If it persists, please contact nick@wpgmaps.com for support.", "wp-google-maps") . "</small>\n                    \n                </div>\n            </div>\n        ";
    return $ret_msg;
}