-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.php
163 lines (147 loc) · 3.83 KB
/
classes.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
class PL_Map
{
var $latitude;
public $longitude;
public $zoom;
public $height;
public $width;
public $is_static;
public $markers;
public $showcontrol;
public $category;
public function __construct($args)
{
if(!is_array($args))
{
$args = array();
}
$defaults = Post_Locations_API::get_default_map_settings();
$settings = array_merge($defaults, $args);
$valid_vars = array_keys(get_object_vars($this));
foreach($settings as $key => $value)
{
if(in_array($key, $valid_vars))
{
$this->$key = $value;
}
}
}
public function add_marker($marker)
{
$this->markers[] = $marker;
}
public function get_markers()
{
//do some cleanup in case someone assigned something else to the markers.
if(!is_array($this->markers))
{
if(is_a($this->markers, 'PL_Marker'))
{
$this->markers = array($this->markers);
}
else
{
$this->markers = array();
}
}
return $this->markers;
}
}
class PL_Marker
{
public $latitude;
public $longitude;
public $html;
public $title;
public function __construct($latitude, $longitude, $title = '', $html = '')
{
$this->latitude = $latitude;
$this->longitude = $longitude;
$this->html = $html;
$this->title = $title;
}
}
class PL_Map_Loader
{
private static $instance;
private $page_maps;
private function __construct()
{
$page_maps = array();
}
/**
* Gets the singleton instance of the map loader.
*
* @return PL_Map_Loader
*/
public static function get_instance()
{
if(self::$instance == null)
{
self::$instance = new PL_Map_Loader();
}
return self::$instance;
}
/**
* Adds the map settings to the loader and returns the html id of the new map
*
* @param $map PL_Map
* @return string HTML ID of the new map;
*/
public function add_map($map)
{
$this->page_maps[] = $map;
$id = 'map-'.(count($this->page_maps) - 1);
return $id;
}
public function print_js()
{
if(count($this->page_maps) > 0) //make sure there are maps on the page
{
$pl = new Post_Locations_API();
?>
<script type="text/javascript">
// <![CDATA[
//settings
var archiveUrl = '<?php echo site_url(); ?>/archives/';
var ajaxUrl = '<?php bloginfo('siteurl');?>/wp-admin/admin-ajax.php';
var markerUrl = '<?php echo get_bloginfo('template_directory') . '/plugins/google-post-locations/images/marker.png';?>';
var shadowUrl = '<?php echo get_bloginfo('template_directory') . '/plugins/google-post-locations/images/shadow.png';?>';
var grpMarkerUrl = 'http://maps.google.com/mapfiles/arrow.png';
var grpShadowUrl = 'http://www.google.com/intl/en_us/mapfiles/arrowshadow.png';
var static_maps = [];
var dynamic_maps = [];
<?php
$i = 0;
$j = 0;
foreach($this->page_maps as $id => $map)
{
if($map->is_static)
{
?>static_maps[<?php echo $i ?>]={'id':'<?php echo $id ?>', 'lat':<?php echo $map->latitude ?>, 'lng':<?php echo $map->longitude ?>, 'zm':<?php echo $map->zoom ?>, 'w':<?php echo $map->width ?>, 'h':<?php echo $map->height ?>};<?php
$i++;
}
else
{
?>dynamic_maps[<?php echo $j?>]={'id':'<?php echo $id?>', 'lat':<?php echo $map->latitude ?>, 'lng':<?php echo $map->longitude ?>, 'zm':<?php echo $map->zoom ?>, 'w':<?php echo $map->width ?>, 'h':<?php echo $map->height ?>};<?php
$j++;
}
}
?>
jQuery(document).ready(function(){
for(var i=0; i<static_maps.length; i++)
{
add_static_map(static_maps[i].id, static_maps[i].lat, static_maps[i].lng, static_maps[i].zm, static_maps[i].w, static_maps[i].h, '<?php echo $pl->get_api_key() ?>', markerUrl, shadowUrl);
}
for(var i=0; i<dynamic_maps.length; i++)
{
add_dynamic_map(dynamic_maps[i].id, dynamic_maps[i].lat, dynamic_maps[i].lng, dynamic_maps[i].zm, dynamic_maps[i].w, dynamic_maps[i].h);
}
});
// ]]>
</script>
<?php
}
}
}