forked from logaan/Comprehensive-Google-Map-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
widget.php
153 lines (119 loc) · 6.41 KB
/
widget.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
<?php
/*
Copyright (C) 2011 Alexander Zagniotov
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if ( !function_exists( 'add_action' ) ) {
echo "Hi there! I'm just a plugin, not much I can do when called directly.";
exit;
}
class ComprehensiveGoogleMap_Widget extends WP_Widget {
function ComprehensiveGoogleMap_Widget() {
$widget_ops = array('classname' => 'comprehensivegooglemap_widget', 'description' => __("A simple and intuitive, yet elegant fully documented Google map plugin that installs as a widget and a short code. The plugin is packed with useful features. Widget and shortcode enabled. Offers extensive configuration options for marker, controls, size, KML files, location by latitude/longitude, location by address, info window, directions, traffic/bike lanes and more.", CGMP_NAME) );
$cops = array('width' => 570);
$this->WP_Widget('comprehensivegooglemap', __('AZ :: Google Map', CGMP_NAME), $widget_ops, $cops);
if ( is_active_widget(false, false, $this->id_base, true) ) {
}
}
function widget( $args, $instance ) {
if (is_admin() || is_feed()) {
return;
}
extract($args);
$map_data_properties = array();
$not_map_data_properties = array("title", "width", "height", "mapalign", "directionhint",
"latitude", "longitude", "addresscontent", "addmarkerlisthidden", "addmarkermashuphidden", "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)) ? $json_default_values[$key] : 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';
if ($addmarkermashuphidden == 'true') {
$addmarkerlisthidden = make_marker_geo_mashup();
} else if ($addmarkermashuphidden == 'false') {
$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);
$id = md5(time().' '.rand());
$map_data_properties['id'] = $id;
$map_data_properties['markerlist'] = $addmarkerlisthidden;
$map_data_properties['addmarkermashup'] = $addmarkermashuphidden;
$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['scrollwheelcontrol'] = isset($map_data_properties['scrollwheelcontrol']) ? $map_data_properties['scrollwheelcontrol'] : "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";
$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;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
foreach ($new_instance as $key => $val) {
$instance[$key] = strip_tags($new_instance[$key]);
}
return $instance;
}
function form( $instance ) {
$settings = array();
$json_html_elems = cgmp_fetch_json_data_file(CGMP_JSON_DATA_HTML_ELEMENTS_FORM_PARAMS);
$json_default_values = cgmp_fetch_json_data_file(CGMP_JSON_DATA_DEFAULT_WIDGET_PARAM_VALUES);
if (is_array($json_html_elems)) {
$legacy_params = array("latitude" => "", "longitude" => "", "addresscontent" => "", "addmarkerlisthidden" => "");
foreach ($json_html_elems as $data_chunk) {
$id = $data_chunk['dbParameterId'];
$value = trim($instance[$id]);
$value = (!isset($value) || empty($value)) ? $json_default_values[$id] : esc_attr(strip_tags($value));
if (array_key_exists($id, $legacy_params)) {
$legacy_params[$id] = $value;
}
if ($id == "addmarkerlisthidden") {
extract($legacy_params);
$addmarkerlisthidden = update_markerlist_from_legacy_locations($latitude, $longitude, $addresscontent, $addmarkerlisthidden);
$value = $addmarkerlisthidden;
}
$data_chunk['dbParameterValue'] = $value;
$data_chunk['dbParameterId'] = $this->get_field_id($id);
$data_chunk['dbParameterName'] = $this->get_field_name($id);
cgmp_set_values_for_html_rendering($settings, $data_chunk);
}
}
$template_values = array();
$template_values = cgmp_build_template_values($settings);
$tokens_with_values = array();
$tokens_with_values['WIDGET_ID_TOKEN'] = $this->id;
$tokens_with_values['WIDGET_FORM_TITLE_TEMPLATE_TOKEN'] = cgmp_render_template_with_values($template_values, CGMP_HTML_TEMPLATE_WIDGET_FORM_TITLE);
$tokens_with_values['MAP_CONFIGURATION_FORM_TEMPLATE_TOKEN'] = cgmp_render_template_with_values($template_values, CGMP_HTML_TEMPLATE_MAP_CONFIGURATION_FORM);
echo cgmp_render_template_with_values($tokens_with_values, CGMP_HTML_TEMPLATE_WIDGET);
}
}
?>