This repository has been archived by the owner on Jun 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
GMapDataRetriever.class.php
134 lines (117 loc) · 3.38 KB
/
GMapDataRetriever.class.php
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
127
128
129
130
131
132
133
134
<?php
/**
* Stores the GMapDataRetriever class definition
*/
/**
* Retrieves GMaps data for the gmap.js integration
* @author etessore
* @version 1.0
* @package classes
*/
class GMapDataRetriever {
/**
* @var array stores some map data
*/
private $map_data;
/**
* Set the map data to the given set
* @param array $map_data the map data
* @return GMapDataRetriever $this for chainability
*/
public function set_map_data($map_data){
$this->map_data = $map_data;
return $this;
}
/**
* Set the class to get map datas from the Simple fields plugin
* Checks if the plugin is enabled.
* @return GMapDataRetriever $this for chainability
*/
public function use_simple_fields(){
if(!function_exists('simple_fields_get_post_group_values')){
wp_die('You need Simple Fields to be Up And Running!');
}
$default = array(
'Map' => array(
array(
'lat' => 0,
'lng' => 0
)
),
'Title' => array(''),
'Description' => array(''),
'Balloon Text' => array('')
);
$map_data = simple_fields_get_post_group_values(get_the_ID(),'Map Data');
if(!empty($map_data)) ThemeHelpers::load_js('map');
$map_data = wp_parse_args($map_data, $default);
if(function_exists('simple_fields_field_googlemaps_register')){
//vd($map_data);
$data = array(
'center' => array(
'lat' => floatval($map_data['Map'][0]['lat']),
'lng' => floatval($map_data['Map'][0]['lng'])
),
'point' => array(
'lat' => floatval($map_data['Map'][0]['lat']),
'lng' => floatval($map_data['Map'][0]['lng'])
),
'zoom' => intval($map_data['Map'][0]['preferred_zoom']),
'type' => $map_data['Map Type'][0],
'title' => $map_data['Title'][0],
'content' => str_replace(
array('%book%'),
array('<a class="book-action" href="javascript:;">'.__('book','theme').'</a>'),
$map_data['Balloon Text'][0]
),
'book_trans' => __('book','theme')
);
} else {
$data = array(
'center' => array(
'lat' => floatval(
empty($map_data['Center Latitude'][0])
? $map_data['Latitude'][0]
: $map_data['Center Latitude'][0]
),
'lng' => floatval(
empty($map_data['Center Longitude'][0])
? $map_data['Longitude'][0]
: $map_data['Center Longitude'][0]
)
),
'point' => array(
'lat' => floatval($map_data['Latitude'][0]),
'lng' => floatval($map_data['Longitude'][0])
),
'zoom' => intval($map_data['Zoom'][0]),
'type' => $map_data['Map Type'][0],
'title' => $map_data['Balloon Title'][0],
'content' => str_replace(
array('%book%'),
array('<a class="book-action" href="javascript:;">'.__('book','theme').'</a>'),
$map_data['Balloon Text'][0]
),
'book_trans' => __('book','theme')
);
}
return $this->set_map_data($data);
}
/*
public function use_shared_datastore(){
}*/
/**
* Get a <script> tag with a JSON variable in it.
* @example GMapDataRetriever.example.json
* @return string
*/
function get_script_content(){
return HtmlHelper::script('var map_info = ' . json_encode($this->map_data));
}
/**
* Prints the <scrpt> tag generated by get_script_content to the DOM
*/
function the_script(){
echo $this->get_script_content();
}
}