','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
$xmlStr=str_replace("," ,"," ,$xmlStr);
return $xmlStr;
}
/*-----------------*/
function initialize_variables() {
global $height, $width, $width_units, $height_units, $radii;
global $icon, $icon2, $google_map_domain, $google_map_country, $theme, $sl_base, $sl_upload_base, $location_table_view;
global $search_label, $zoom_level, $sl_use_city_search, $sl_use_name_search, $sl_default_map;
global $sl_radius_label, $sl_website_label, $sl_num_initial_displayed, $sl_load_locations_default;
global $sl_distance_unit, $sl_map_overview_control, $sl_admin_locations_per_page, $sl_instruction_message;
global $sl_map_character_encoding;
$sl_map_character_encoding=get_option('sl_map_character_encoding');
if (empty($sl_map_character_encoding)) {
$sl_map_character_encoding="";
add_option('sl_map_character_encoding', $sl_map_character_encoding);
}
$sl_instruction_message=get_option('sl_instruction_message');
if (empty($sl_instruction_message)) {
$sl_instruction_message="Enter Your Address or Zip Code Above.";
add_option('sl_instruction_message', $sl_instruction_message);
}
$sl_admin_locations_per_page=get_option('sl_admin_locations_per_page');
if (empty($sl_admin_locations_per_page)) {
$sl_admin_locations_per_page="100";
add_option('sl_admin_locations_per_page', $sl_admin_locations_per_page);
}
$sl_map_overview_control=get_option('sl_map_overview_control');
if (empty($sl_map_overview_control)) {
$sl_map_overview_control="0";
add_option('sl_map_overview_control', $sl_map_overview_control);
}
$sl_distance_unit=get_option('sl_distance_unit');
if (empty($sl_distance_unit)) {
$sl_distance_unit="miles";
add_option('sl_distance_unit', $sl_distance_unit);
}
$sl_load_locations_default=get_option('sl_load_locations_default');
if (empty($sl_load_locations_default)) {
$sl_load_locations_default="1";
add_option('sl_load_locations_default', $sl_load_locations_default);
}
$sl_num_initial_displayed=get_option('sl_num_initial_displayed');
if (empty($sl_num_initial_displayed)) {
$sl_num_initial_displayed="25";
add_option('sl_num_initial_displayed', $sl_num_initial_displayed);
}
$sl_website_label=get_option('sl_website_label');
if (empty($sl_website_label)) {
$sl_website_label="Website";
add_option('sl_website_label', $sl_website_label);
}
$sl_radius_label=get_option('sl_radius_label');
if (empty($sl_radius_label)) {
$sl_radius_label="Radius";
add_option('sl_radius_label', $sl_radius_label);
}
$sl_map_type=get_option('sl_map_type');
if (empty($sl_map_type)) {
$sl_map_type=G_NORMAL_MAP;
add_option('sl_map_type', $sl_map_type);
}
$sl_remove_credits=get_option('sl_remove_credits');
if (empty($sl_remove_credits)) {
$sl_remove_credits="0";
add_option('sl_remove_credits', $sl_remove_credits);
}
$sl_use_name_search=get_option('sl_use_name_search');
if (empty($sl_use_name_search)) {
$sl_use_name_search="0";
add_option('sl_use_name_search', $sl_use_name_search);
}
$sl_use_city_search=get_option('sl_use_city_search');
if (empty($sl_use_city_search)) {
$sl_use_city_search="1";
add_option('sl_use_city_search', $sl_use_city_search);
}
$zoom_level=get_option('sl_zoom_level');
if (empty($zoom_level)) {
$zoom_level="4";
add_option('sl_zoom_level', $zoom_level);
}
$search_label=get_option('sl_search_label');
if (empty($search_label)) {
$search_label="Address";
add_option('sl_search_label', $search_label);
}
$location_table_view=get_option('sl_location_table_view');
if (empty($location_table_view)) {
$location_table_view="Normal";
add_option('sl_location_table_view', $location_table_view);
}
$theme=get_option('sl_map_theme');
if (empty($theme)) {
$theme="";
add_option('sl_map_theme', $theme);
}
$google_map_country=get_option('sl_google_map_country');
if (empty($google_map_country)) {
$google_map_country="United States";
add_option('sl_google_map_country', $google_map_country);
}
$google_map_domain=get_option('sl_google_map_domain');
if (empty($google_map_domain)) {
$google_map_domain="maps.google.com";
add_option('sl_google_map_domain', $google_map_domain);
}
$icon2=get_option('sl_map_end_icon');
if (empty($icon2)) {
add_option('sl_map_end_icon', $sl_base.'/icons/marker.png');
$icon2=get_option('sl_map_end_icon');
}
$icon=get_option('sl_map_home_icon');
if (empty($icon)) {
add_option('sl_map_home_icon', $sl_base.'/icons/arrow.png');
$icon=get_option('sl_map_home_icon');
}
$height=get_option('sl_map_height');
if (empty($height)) {
add_option('sl_map_height', '350');
$height=get_option('sl_map_height');
}
$height_units=get_option('sl_map_height_units');
if (empty($height_units)) {
add_option('sl_map_height_units', "px");
$height_units=get_option('sl_map_height_units');
}
$width=get_option('sl_map_width');
if (empty($width)) {
add_option('sl_map_width', "100");
$width=get_option('sl_map_width');
}
$width_units=get_option('sl_map_width_units');
if (empty($width_units)) {
add_option('sl_map_width_units', "%");
$width_units=get_option('sl_map_width_units');
}
$radii=get_option('sl_map_radii');
if (empty($radii)) {
add_option('sl_map_radii', "1,5,10,25,(50),100,200,500");
$radii=get_option('sl_map_radii');
}
}
/*--------------------------*/
function choose_units($unit, $input_name) {
$unit_arr[]="%";$unit_arr[]="px";$unit_arr[]="em";$unit_arr[]="pt";
$select_field.="";
return $select_field;
}
/*----------------------------*/
function do_geocoding($address,$sl_id="") {
global $wpdb, $text_domain;
define("MAPS_HOST", get_option('sl_google_map_domain'));
$api_key=get_option('store_locator_api_key');
define("KEY", "$api_key");
// Initialize delay in geocode speed
$delay = 0;
$base_url = "http://" . MAPS_HOST . "/maps/geo?output=csv&key=" . KEY;
//Adding ccTLD (Top Level Domain) to help perform more accurate geocoding according to selected Google Maps Domain - 12/16/09
$ccTLD_arr=explode(".", MAPS_HOST);
$ccTLD=$ccTLD_arr[count($ccTLD_arr)-1];
if ($ccTLD!="com") {
$base_url .= "&gl=".$ccTLD;
//die($base_url);
}
//Map Character Encoding
if (get_option("sl_map_character_encoding")!="") {
$base_url .= "&oe=".get_option("sl_map_character_encoding");
}
// Iterate through the rows, geocoding each address
$request_url = $base_url . "&q=" . urlencode($address);
//New code to accomdate those without 'file_get_contents' functionality for their server - added 3/27/09 8:56am - provided by Daniel C. - thank you
if (extension_loaded("curl") && function_exists("curl_init")) {
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $request_url);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
$csv = curl_exec($cURL);
curl_close($cURL);
}else{
$csv = file_get_contents($request_url) or die("url not loading");
}
//End of new code
$csvSplit = split(",", $csv);
$status = $csvSplit[0];
$lat = $csvSplit[2];
$lng = $csvSplit[3];
if (strcmp($status, "200") == 0) {
// successful geocode
$geocode_pending = false;
$lat = $csvSplit[2];
$lng = $csvSplit[3];
if ($sl_id=="") {
$query = sprintf("UPDATE " . $wpdb->prefix ."store_locator SET sl_latitude = '%s', sl_longitude = '%s' WHERE sl_id = ".mysql_insert_id()." LIMIT 1;", mysql_real_escape_string($lat), mysql_real_escape_string($lng));
}
else {
$query = sprintf("UPDATE " . $wpdb->prefix ."store_locator SET sl_latitude = '%s', sl_longitude = '%s' WHERE sl_id = $sl_id LIMIT 1;", mysql_real_escape_string($lat), mysql_real_escape_string($lng));
}
$update_result = mysql_query($query);
if (!$update_result) {
die("Invalid query: " . mysql_error());
}
} else if (strcmp($status, "620") == 0) {
// sent geocodes too fast
$delay += 100000;
} else {
// failure to geocode
$geocode_pending = false;
echo __("Address " . $address . " failed to geocode. ", $text_domain);
echo __("Received status " . $status , $text_domain)."\n
";
}
usleep($delay);
}
/*-------------------------------*/
function install_table() {
global $wpdb, $sl_db_version, $sl_path, $sl_upload_path;
$table_name = $wpdb->prefix . "store_locator";
$sql = "CREATE TABLE " . $table_name . " (
sl_id mediumint(8) unsigned NOT NULL auto_increment,
sl_store varchar(255) NULL,
sl_address varchar(255) NULL,
sl_address2 varchar(255) NULL,
sl_city varchar(255) NULL,
sl_state varchar(255) NULL,
sl_zip varchar(255) NULL,
sl_latitude varchar(255) NULL,
sl_longitude varchar(255) NULL,
sl_tags mediumtext NULL,
sl_description varchar(255) NULL,
sl_url varchar(255) NULL,
sl_hours varchar(255) NULL,
sl_phone varchar(255) NULL,
sl_image varchar(255) NULL,
sl_private varchar(1) NULL,
sl_neat_title varchar(255) NULL,
PRIMARY KEY (sl_id)
) ENGINE=innoDB DEFAULT CHARACTER SET=utf8 DEFAULT COLLATE=utf8_unicode_ci;";
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
add_option("sl_db_version", $sl_db_version);
}
$installed_ver = get_option( "sl_db_version" );
if( $installed_ver != $sl_db_version ) {
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
update_option("sl_db_version", $sl_db_version);
}
move_upload_directories();
}
/*-------------------------------*/
function head_scripts() {
global $sl_dir, $sl_base, $sl_upload_base, $sl_path, $sl_upload_path, $wpdb, $sl_version, $pagename, $map_character_encoding;
print "\n\n";
//print "\n";
//Check if currently on page with shortcode
$on_sl_page=$wpdb->get_results("SELECT post_name FROM ".$wpdb->prefix."posts WHERE post_content LIKE '%[STORE-LOCATOR%' AND post_status IN ('publish', 'draft') AND (post_name='$pagename' OR ID='$_GET[p]' OR ID='$_GET[page_id]')", ARRAY_A);
//Checking if code used in posts
$sl_code_is_used_in_posts=$wpdb->get_results("SELECT post_name FROM ".$wpdb->prefix."posts WHERE post_content LIKE '%[STORE-LOCATOR%' AND post_type='post'");
//If shortcode used in posts, get post IDs, and put into array of numbers
if ($sl_code_is_used_in_posts) {
$sl_post_ids=$wpdb->get_results("SELECT ID FROM ".$wpdb->prefix."posts WHERE post_content LIKE '%[STORE-LOCATOR%' AND post_type='post'", ARRAY_A);
foreach ($sl_post_ids as $val) { $post_ids_array[]=$val[ID];}
}
else {
$post_ids_array=array(9999999999999999999999999999999999999); //post number that'll never be reached
}
//print_r($post_ids_array);
//If on page with store locator shortcode, on an archive, search, or 404 page while shortcode has been used in a post, on the front page, or a specific post with shortcode, display code, otherwise, don't
if ($on_sl_page || is_search() || ((is_archive() || is_404()) && $sl_code_is_used_in_posts) || is_front_page() || is_single($post_ids_array)) {
$api_key=get_option('store_locator_api_key');
$google_map_domain=(get_option('sl_google_map_domain')!="")? get_option('sl_google_map_domain') : "maps.google.com";
print "\n";
//print "";
//dynamic js
//find_wp_config();
print "\n";
//end dynamic js
print "
\n";
//print "\n"; //merged into store-locator.css 12/31/09 (v1.2.37)
//if store-locator.css exists in custom-css/ folder in uploads/ dir it takes precedence over, store-locator.css in store-locator plugin directory to allow for css customizations to be preserved after updates
$has_custom_css=(file_exists($sl_upload_path."/custom-css/store-locator.css"))? $sl_upload_base."/custom-css" : $sl_base;
print "";
$theme=get_option('sl_map_theme');
if ($theme!="") {print "\n";}
$zl=(trim(get_option('sl_zoom_level'))!="")? get_option('sl_zoom_level') : 4;
//print "";
move_upload_directories();
}
else {
$sl_page_ids=$wpdb->get_results("SELECT ID FROM ".$wpdb->prefix."posts WHERE post_content LIKE '%[STORE-LOCATOR%' AND post_status='publish'", ARRAY_A);
print "";
}
print "\n\n\n";
}
/*-------------------------------*/
function foot_scripts() {
//print "";
}
/*-------------------------------*/
function ajax_map($content) {
global $sl_dir, $sl_base, $sl_upload_base, $sl_path, $sl_upload_path, $text_domain, $wpdb;
if(! preg_match('|\[STORE-LOCATOR|', $content)) {
return $content;
}
else {
$height=(get_option('sl_map_height'))? get_option('sl_map_height') : "500" ;
$width=(get_option('sl_map_width'))? get_option('sl_map_width') : "100" ;
$radii=(get_option('sl_map_radii'))? get_option('sl_map_radii') : "1,5,10,(25),50,100,200,500" ;
$height_units=(get_option('sl_map_height_units'))? get_option('sl_map_height_units') : "px";
$width_units=(get_option('sl_map_width_units'))? get_option('sl_map_width_units') : "%";
$sl_instruction_message=(get_option('sl_instruction_message'))? get_option('sl_instruction_message') : "Enter Your Address or Zip Code Above.";
$r_array=explode(",", $radii);
$search_label=(get_option('sl_search_label'))? get_option('sl_search_label') : "Address" ;
$unit_display=(get_option('sl_distance_unit')=="km")? "km" : "mi";
foreach ($r_array as $value) {
$s=(ereg("\(.*\)", $value))? " selected='selected' " : "" ;
$value=ereg_replace("[^0-9]", "", $value);
$r_options.="";
}
if (get_option('sl_use_city_search')==1) {
$cs_array=$wpdb->get_results("SELECT CONCAT(TRIM(sl_city), ', ', TRIM(sl_state)) as city_state FROM ".$wpdb->prefix."store_locator WHERE sl_city<>'' AND sl_state<>'' AND sl_latitude<>'' AND sl_longitude<>'' GROUP BY city_state ORDER BY city_state ASC", ARRAY_A);
//var_dump($cs_array); die();
if ($cs_array) {
foreach($cs_array as $value) {
$cs_options.="";
}
}
}
/*if (get_option('sl_use_name_search')==1) {
$name_array=$wpdb->get_results("SELECT sl_store FROM ".$wpdb->prefix."store_locator WHERE sl_store<>'' ORDER BY sl_store ASC", ARRAY_A);
//var_dump($cs_array); die();
if ($name_array) {
foreach($name_array as $value) {
$name_options.="";
}
}
}*/
if (get_option('sl_map_theme')!="") {
$theme_base=$sl_upload_base."/themes/".get_option('sl_map_theme');
$theme_path=$sl_upload_path."/themes/".get_option('sl_map_theme');
}
else {
$theme_base=$sl_upload_base."/images";
$theme_path=$sl_upload_path."/images";
}
if (!file_exists($theme_path."/search_button.png")) {
$theme_base=$sl_base."/images";
$theme_path=$sl_path."/images";
}
$sub_img=$theme_base."/search_button.png";
$mousedown=(file_exists($theme_path."/search_button_down.png"))? "onmousedown=\"this.src='$theme_base/search_button_down.png'\" onmouseup=\"this.src='$theme_base/search_button.png'\"" : "";
$mouseover=(file_exists($theme_path."/search_button_over.png"))? "onmouseover=\"this.src='$theme_base/search_button_over.png'\" onmouseout=\"this.src='$theme_base/search_button.png'\"" : "";
$button_style=(file_exists($theme_path."/search_button.png"))? "type='image' src='$sub_img' $mousedown $mouseover" : "type='submit'";
//print "$sub_img | ".$sl_upload_path."/themes/".get_option('sl_map_theme')."/search_button.png";
$hide=(get_option('sl_remove_credits')==1)? "style='display:none;'" : "";
$form="