Esempio n. 1
0
 public function widget($args, $instance)
 {
     if (is_admin() || is_feed()) {
         return;
     }
     wp_enqueue_script('cgmp-google-map-jsapi');
     wp_enqueue_script('cgmp-google-map-orchestrator-framework');
     extract($args);
     $map_data_properties = array();
     $not_map_data_properties = array("title", "width", "height", "mapalign", "directionhint", "latitude", "longitude", "addresscontent", "addmarkerlisthidden", "addmarkermashuphidden", "enablegeolocationmarkerhidden", "addmarkerinput", "showmarker", "animation", "infobubblecontent", "markerdirections", "locationaddmarkerinput", "bubbletextaddmarkerinput");
     $json_default_values = cgmp_fetch_json_data_file(CGMP_JSON_DATA_DEFAULT_WIDGET_PARAM_VALUES);
     foreach ($instance as $key => $value) {
         $value = trim($value);
         $value = !isset($value) || empty($value) ? isset($json_default_values[$key]) ? $json_default_values[$key] : esc_attr(strip_tags($value)) : esc_attr(strip_tags($value));
         $instance[$key] = $value;
         if (!in_array($key, $not_map_data_properties)) {
             $key = str_replace("hidden", "", $key);
             $key = str_replace("_", "", $key);
             $map_data_properties[$key] = $value;
         }
     }
     extract($instance);
     echo $before_widget;
     if (isset($title)) {
         echo $before_title . $title . $after_title;
     }
     $addmarkermashuphidden = isset($addmarkermashuphidden) ? $addmarkermashuphidden : "false";
     $enablegeolocationmarkerhidden = isset($enablegeolocationmarkerhidden) ? $enablegeolocationmarkerhidden : "false";
     $enablemarkerclusteringhidden = isset($enablemarkerclusteringhidden) ? $enablemarkerclusteringhidden : "false";
     if ($addmarkermashuphidden == "true") {
         $json_data_arr = make_marker_geo_mashup_2();
         $addmarkerlisthidden = $json_data_arr["data"];
         $map_data_properties['debug'] = $json_data_arr["debug"];
     } else {
         if ($addmarkermashuphidden == "false") {
             $latitude = isset($latitude) && trim($latitude) != "" ? $latitude : "";
             $longitude = isset($longitude) && trim($longitude) != "" ? $longitude : "";
             $addresscontent = isset($addresscontent) && trim($addresscontent) != "" ? $addresscontent : "";
             $addmarkerlisthidden = update_markerlist_from_legacy_locations($latitude, $longitude, $addresscontent, $addmarkerlisthidden);
             $addmarkerlisthidden = htmlspecialchars($addmarkerlisthidden);
         }
     }
     $bad_entities = array(""", "'");
     $addmarkerlisthidden = str_replace($bad_entities, "", $addmarkerlisthidden);
     $addmarkerlisthidden = cgmp_parse_wiki_style_links($addmarkerlisthidden);
     if ($addmarkermashuphidden == 'false' && trim($addmarkerlisthidden) != "") {
         $cached_marker_data_json = get_option(CGMP_MAP_CACHE_WIDGET_PREFIX . $this->id);
         if (isset($cached_marker_data_json) && trim($cached_marker_data_json) != "") {
             $addmarkerlisthidden = $cached_marker_data_json;
             $cache_time = get_option(CGMP_MAP_CACHE_WIDGET_TIME_PREFIX . $this->id);
             $map_data_properties['debug'] = array("widget_id" => $this->id, "state" => "cached", "since" => $cache_time);
         } else {
             $addmarkerlisthidden = cgmp_do_serverside_address_validation_2($addmarkerlisthidden);
             $map_data_properties['debug'] = array("widget_id" => $this->id, "state" => "fresh", "since" => time());
             update_option(CGMP_MAP_CACHE_WIDGET_PREFIX . $this->id, $addmarkerlisthidden);
             update_option(CGMP_MAP_CACHE_WIDGET_TIME_PREFIX . $this->id, time());
         }
     }
     $id = md5(time() . ' ' . rand());
     $map_data_properties['id'] = $id;
     $map_data_properties['markerlist'] = $addmarkerlisthidden;
     $map_data_properties['addmarkermashup'] = $addmarkermashuphidden;
     $map_data_properties['enablegeolocationmarker'] = $enablegeolocationmarkerhidden;
     $map_data_properties['enablemarkerclustering'] = $enablemarkerclusteringhidden;
     $map_data_properties['kml'] = cgmp_clean_kml($map_data_properties['kml']);
     $map_data_properties['panoramiouid'] = cgmp_clean_panoramiouid($map_data_properties['panoramiouid']);
     //When widget was saved and untouched for a long time, the new added config options were not initialized
     $map_data_properties['distanceunits'] = isset($map_data_properties['distanceunits']) ? $map_data_properties['distanceunits'] : "miles";
     $map_data_properties['scrollwheelcontrol'] = isset($map_data_properties['scrollwheelcontrol']) ? $map_data_properties['scrollwheelcontrol'] : "false";
     $map_data_properties['enablemarkerclustering'] = isset($map_data_properties['enablemarkerclustering']) ? $map_data_properties['enablemarkerclustering'] : "false";
     $map_data_properties['tiltfourtyfive'] = isset($map_data_properties['tiltfourtyfive']) ? $map_data_properties['tiltfourtyfive'] : "false";
     $map_data_properties['draggable'] = isset($map_data_properties['draggable']) ? $map_data_properties['draggable'] : "true";
     $map_data_properties['styles'] = isset($map_data_properties['styles']) ? cgmp_clean_styles($map_data_properties['styles']) : "";
     $map_data_properties['styles'] = trim($map_data_properties['styles']) != "" ? base64_encode($map_data_properties['styles']) : $map_data_properties['styles'];
     $poweredby = isset($poweredby) ? $poweredby : "false";
     $language = isset($language) ? $language : "en";
     echo cgmp_draw_map_placeholder($id, $width, $height, $mapalign, $directionhint, $poweredby);
     cgmp_set_google_map_language($language);
     cgmp_map_data_injector(json_encode($map_data_properties), $id);
     echo $after_widget;
 }
Esempio n. 2
0
 function make_marker_geo_mashup_2()
 {
     $cached_geomashup_json = get_option(CGMP_DB_GEOMASHUP_DATA_CACHE);
     if (isset($cached_geomashup_json) && trim($cached_geomashup_json) != "") {
         $cached_geomashup_json = str_replace("\\\"", "\"", $cached_geomashup_json);
         $cache_time = get_option(CGMP_DB_GEOMASHUP_DATA_CACHE_TIME);
         return array("data" => $cached_geomashup_json, "debug" => array("state" => "cached", "since" => $cache_time));
     }
     $query_debug_data = array();
     $post_data = extract_published_content_containing_shortcode("post");
     $query_debug_data["post"] = $post_data["query"];
     $page_data = extract_published_content_containing_shortcode("page");
     $query_debug_data["page"] = $page_data["query"];
     $custom_data = array();
     $custom_data["extracted"] = array();
     $custom_data["query"] = array();
     $custom_post_types = get_option(CGMP_DB_SETTINGS_CUSTOM_POST_TYPES);
     if (isset($custom_post_types) && trim($custom_post_types) != "") {
         $custom_post_types_arr = explode(",", $custom_post_types);
         array_walk($custom_post_types_arr, 'trim_to_lower_value');
         $custom_post_types = implode("','", $custom_post_types_arr);
         $custom_data = extract_published_content_containing_shortcode($custom_post_types);
         $query_debug_data["custom"] = $custom_data["query"];
     }
     $extracted_published_markers = array_merge(process_collection_of_contents($post_data["extracted"]), process_collection_of_contents($page_data["extracted"]), process_collection_of_contents($custom_data["extracted"]));
     if (is_array($extracted_published_markers) && count($extracted_published_markers) > 0) {
         $filtered = array();
         $duplicates = array();
         foreach ($extracted_published_markers as $post_data) {
             $title = $post_data['title'];
             $permalink = $post_data['permalink'];
             $markers = $post_data['markers'];
             $excerpt = $post_data['excerpt'];
             $bad_entities = array(""", "'", "'", "\"");
             $bad_characters = array("\r\n", "\r", "\n", "<br>", "<BR>", "<br />", "<BR />");
             foreach ($markers as $full_loc) {
                 $tobe_filtered_loc = $full_loc;
                 if (strpos($full_loc, CGMP_SEP) !== false) {
                     $loc_arr = explode(CGMP_SEP, $full_loc);
                     $tobe_filtered_loc = $loc_arr[0];
                 }
                 $tobe_filtered_loc = str_replace($bad_entities, "", str_replace($bad_characters, " ", $tobe_filtered_loc));
                 if (!isset($filtered[$tobe_filtered_loc])) {
                     $validated_addresses = cgmp_do_serverside_address_validation_2($full_loc);
                     $filtered[$tobe_filtered_loc]['validated_address_csv_data'] = $validated_addresses;
                     $filtered[$tobe_filtered_loc]['permalink'] = $permalink;
                     if (isset($title) && trim($title) != "") {
                         $title = str_replace($bad_entities, "", $title);
                         $title = trim($title);
                     }
                     $filtered[$tobe_filtered_loc]['title'] = $title;
                     if (isset($excerpt) && trim($excerpt) != "") {
                         $excerpt = str_replace($bad_entities, "", str_replace($bad_characters, " ", $excerpt));
                         $excerpt = trim($excerpt);
                     }
                     $filtered[$tobe_filtered_loc]['excerpt'] = $excerpt;
                 } else {
                     if (isset($duplicates[$tobe_filtered_loc]) && is_numeric($duplicates[$tobe_filtered_loc])) {
                         $duplicates[$tobe_filtered_loc]++;
                     } else {
                         $duplicates[$tobe_filtered_loc] = 1;
                     }
                 }
             }
         }
         $debug_data = array("since" => time(), "query" => $query_debug_data, "duplicate_addresses_extracted" => $duplicates);
         $filtered["live_debug"] = $debug_data;
         $geomashup_json = json_encode($filtered);
         update_option(CGMP_DB_GEOMASHUP_DATA_CACHE, $geomashup_json);
         update_option(CGMP_DB_GEOMASHUP_DATA_CACHE_TIME, time());
         $debug_data["state"] = "fresh";
         return array("data" => $geomashup_json, "debug" => $debug_data);
     }
 }