      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126:

    <?php
    /**
     * Handles Backwards Compatibility
    */

    add_action('admin_head', 'wpgmza_check_admin_head_backwards_compat_v6');
    /**
     * Runs the head functions if backwards compat is in the motions
    */
    function wpgmza_check_admin_head_backwards_compat_v6(){
        if(wpgmza_check_pro_compat_required_v6()){
            if (isset($_POST['wpgmza_save_circle'])){
                if(function_exists("wpgmaps_head")){
                    wpgmaps_head();
                }
            } else if (isset($_POST['wpgmza_save_rectangle'])){
                if(function_exists("wpgmaps_head")){
                    wpgmaps_head();
                }
            }
        }
    }

    add_action('wpgooglemaps_hook_user_js_after_core', 'wpgmza_check_user_backwards_compat_v6');
    /**
     * Checks if user end needs backwards compat code
    */
    function wpgmza_check_user_backwards_compat_v6(){
        if(wpgmza_check_pro_compat_required_v6()){

            wp_register_script('wpgmaps-user-backwards-compat', plugins_url('js/backwards_compat_user_v6.js', __FILE__), array('jquery'), '1.0', true);

            wp_localize_script('wpgmaps-user-backwards-compat', 'wpgmza_circle_data_array', wpgmza_backwards_compat_get_all_circle_data());
            wp_localize_script('wpgmaps-user-backwards-compat', 'wpgmza_rectangle_data_array', wpgmza_backwards_compat_get_all_rectangle_data());

            wp_enqueue_script('wpgmaps-user-backwards-compat');
        }
    }

    add_action("wpgmza_check_map_editor_backwards_compat", "wpgmza_check_map_editor_backwards_compat_v6");
    /**
     * Checks if the Pro version is less than the last v6
     * Set's up backwards compatibility if this is the case
    */
    function wpgmza_check_map_editor_backwards_compat_v6(){
        if(isset($_GET['action'])){
            if ($_GET['action'] == "edit" && isset($_GET['map_id']) && wpgmza_check_pro_compat_required_v6()) {
                wp_register_script('wpgmaps-admin-backwards-compat', plugins_url('js/backwards_compat_v6.js', __FILE__), array('jquery', "jquery-ui-core"), '1.0', true);

                $tab_heading = "<li><a href=\"#tabs-circles\">".__("Circles","wp-google-maps")."</a></li>
                                <li><a href=\"#tabs-rectangles\">".__("Rectangles","wp-google-maps")."</a></li>";

                $tab_content = "<div id=\"tabs-circles\">
                                    <h2>
                                        " . __('Add a Circle', 'wp-google-maps') . "
                                    </h2>
                                    <span><a class=\"button-primary\" href=\"" . get_option('siteurl') . "/wp-admin/admin.php?page=wp-google-maps-menu&action=add_circle&map_id=" . $_GET['map_id'] . "\">" . __("Add a Circle", "wp-google-maps") . "</a></span>
                                    " . wpgmza_get_circles_table($_GET['map_id']) . "
                                </div>

                                <div id=\"tabs-rectangles\">
                                    <h2>
                                        " . __('Add a Rectangle', 'wp-google-maps') . "
                                    </h2>
                                    <span><a class=\"button-primary\" href=\"" . get_option('siteurl') . "/wp-admin/admin.php?page=wp-google-maps-menu&action=add_rectangle&map_id=" . $_GET['map_id'] . "\">" . __("Add a Rectangle", "wp-google-maps") . "</a></span>
                                    " . wpgmza_get_rectangles_table($_GET['map_id']) . "
                                </div>";

                wp_localize_script('wpgmaps-admin-backwards-compat', 'wpgmza_backwards_compat_v6_marker_tab_headings', $tab_heading);
                wp_localize_script('wpgmaps-admin-backwards-compat', 'wpgmza_backwards_compat_v6_marker_tab_content', $tab_content);

                wp_localize_script('wpgmaps-admin-backwards-compat', 'wpgmza_circle_data_array', wpgmza_get_circle_data($_GET['map_id']));
                wp_localize_script('wpgmaps-admin-backwards-compat', 'wpgmza_rectangle_data_array', wpgmza_get_rectangle_data($_GET['map_id']));

                wp_enqueue_script('wpgmaps-admin-backwards-compat');
            }
        }
    }

    /**
     * Check if backwards compat code is needed for this version
    */
    function wpgmza_check_pro_compat_required_v6(){
        if(function_exists("wpgmza_register_pro_version")){
            global $wpgmza_pro_version;

            if(version_compare($wpgmza_pro_version, '7.0.0', '<')) {
                return true;
            }
        }
        return false;
    }

    function wpgmza_backwards_compat_get_all_circle_data(){
        global $wpdb;
        global $wpgmza_tblname_circles;
        global $wpgmza;

        $stmt = "SELECT *, {$wpgmza->spatialFunctionPrefix}AsText(center) AS center FROM $wpgmza_tblname_circles";
        $results = $wpdb->get_results($stmt);

        $circles = array();
        foreach($results as $obj)
            $circles[$obj->id] = $obj;

        return $circles;
    }

    function wpgmza_backwards_compat_get_all_rectangle_data(){
        global $wpdb;
        global $wpgmza_tblname_rectangles;
        global $wpgmza;

        $stmt = "SELECT *, {$wpgmza->spatialFunctionPrefix}AsText(cornerA) AS cornerA, {$wpgmza->spatialFunctionPrefix}AsText(cornerB) AS cornerB FROM $wpgmza_tblname_rectangles";
        $results = $wpdb->get_results($stmt);

        $rectangles = array();
        foreach($results as $obj)
            $rectangles[$obj->id] = $obj;

        return $rectangles;
    }