-
Notifications
You must be signed in to change notification settings - Fork 3
/
head.php
226 lines (186 loc) · 10.9 KB
/
head.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
/*
Copyright (C) 2011-08/2014 Alexander Zagniotov
Copyright (C) 2015 Norbert Preining
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;
}
if ( !function_exists('sgmp_enqueue_head_scripts') ):
function sgmp_enqueue_head_scripts() {
wp_enqueue_script( array ( 'jquery' ) );
}
endif;
if ( !function_exists('sgmp_google_map_admin_add_style') ):
function sgmp_google_map_admin_add_style() {
wp_enqueue_style('slick-google-map-style', SGMP_PLUGIN_CSS . '/sgmp.admin.css', false, SGMP_VERSION, "screen");
}
endif;
if ( !function_exists('sgmp_google_map_admin_add_script') ):
function sgmp_google_map_admin_add_script() {
if (sgmp_should_load_admin_scripts()) {
$whitelist = array('localhost', '127.0.0.1');
wp_enqueue_script('sgmp-jquery-tools-tooltip', SGMP_PLUGIN_JS .'/jquery.tools.tooltip.min.js', array('jquery'), '1.2.5.a', true);
$minified = ".min";
if (in_array($_SERVER['HTTP_HOST'], $whitelist)) {
$minified = "";
}
wp_enqueue_script('sgmp-jquery-tokeninput', SGMP_PLUGIN_JS. '/sgmp.tokeninput'.$minified.'.js', array('jquery'), SGMP_VERSION, true);
/* temp fix - will probably be fixed with https://core.trac.wordpress.org/ticket/29520#comment:17
wp_enqueue_script('slick-google-map-plugin', SGMP_PLUGIN_JS. '/sgmp.admin'.$minified.'.js', array('jquery', 'media', 'wp-ajax-response'), SGMP_VERSION, true);
*/
wp_enqueue_script('slick-google-map-plugin', SGMP_PLUGIN_JS. '/sgmp.admin'.$minified.'.js', array('jquery', 'wp-ajax-response'), SGMP_VERSION, true);
}
if (sgmp_should_find_posts_scripts()) {
add_action('admin_footer', 'find_posts_div', 99);
}
}
endif;
if ( !function_exists('sgmp_insert_shortcode_to_post_action_callback') ):
function sgmp_insert_shortcode_to_post_action_callback() {
//check_ajax_referer( "sgmp_insert_shortcode_to_post_action", "_ajax_nonce");
if (isset($_POST['postId']) && isset($_POST['shortcodeName'])) {
$post = get_post($_POST['postId']);
$post_content = $post->post_content;
$persisted_shortcodes_json = get_option(SGMP_PERSISTED_SHORTCODES);
if (isset($persisted_shortcodes_json) && trim($persisted_shortcodes_json) != "") {
$persisted_shortcodes = json_decode($persisted_shortcodes_json, true);
if (is_array($persisted_shortcodes) && !empty($persisted_shortcodes)) {
if (isset($persisted_shortcodes[$_POST['shortcodeName']])) {
$shortcode = $persisted_shortcodes[$_POST['shortcodeName']];
if (is_array($shortcode)) {
$shortcode_id = substr(md5(rand()), 0, 10);
$raw_code = $shortcode['code'];
$cleaned_code = str_replace("TO_BE_GENERATED", $shortcode_id, $raw_code);
$updated_post_attribs = array('ID' => $_POST['postId'], 'post_content' => $post_content."<br />".$cleaned_code);
wp_update_post( $updated_post_attribs );
echo isset($post->post_title) && trim($post->post_title) != "" ? $post->post_title : "Titleless";
}
}
}
}
}
die();
}
endif;
if ( !function_exists('sgmp_should_find_posts_scripts') ):
function sgmp_should_find_posts_scripts() {
$admin_pages = array('sgmp-saved-shortcodes');
$plugin_admin_page = isset($_REQUEST['page']) && trim($_REQUEST['page']) != "" ? $_REQUEST['page'] : "";
return in_array($plugin_admin_page, $admin_pages);
}
endif;
if ( !function_exists('sgmp_google_map_tab_script') ):
function sgmp_google_map_tab_script() {
wp_enqueue_script('sgmp-jquery-tools-tabs', SGMP_PLUGIN_JS .'/jquery.tools.tabs.min.js', array('jquery'), '1.2.5', true);
}
endif;
if ( !function_exists('sgmp_google_map_register_scripts') ):
function sgmp_google_map_register_scripts() {
$whitelist = array('localhost', '127.0.0.1');
$minified = ".min";
if (in_array($_SERVER['HTTP_HOST'], $whitelist)) {
$minified = "";
}
wp_register_script('sgmp-google-map-orchestrator-framework', SGMP_PLUGIN_JS. '/sgmp.framework'.$minified.'.js', array(), SGMP_VERSION, true);
$api = SGMP_GOOGLE_API_URL;
if (is_ssl()) {
$api = SGMP_GOOGLE_API_URL_SSL;
}
wp_register_script('sgmp-google-map-jsapi', $api, array(), false, true);
}
endif;
if ( !function_exists('sgmp_google_map_init_global_admin_html_object') ):
function sgmp_google_map_init_global_admin_html_object() {
if (is_admin()) {
echo "<object id='global-data-placeholder' class='sgmp-data-placeholder'>".PHP_EOL;
echo " <param id='sep' name='sep' value='".SGMP_SEP."' />".PHP_EOL;
echo " <param id='ajaxurl' name='ajaxurl' value='".admin_url('admin-ajax.php')."' />".PHP_EOL;
echo " <param id='version' name='version' value='".SGMP_VERSION."' />".PHP_EOL;
$persisted_shortcodes_json = get_option(SGMP_PERSISTED_SHORTCODES);
if (isset($persisted_shortcodes_json) && trim($persisted_shortcodes_json) != "" && is_array(json_decode($persisted_shortcodes_json, true))) {
echo " <param id='shortcodes' name='shortcodes' value='".$persisted_shortcodes_json."' />".PHP_EOL;
} else {
echo " <param id='shortcodes' name='shortcodes' value='".json_encode(array())."' />".PHP_EOL;
}
echo " <param id='assets' name='assets' value='".SGMP_PLUGIN_ASSETS_URI."' />".PHP_EOL;
echo " <param id='customMarkersUri' name='customMarkersUri' value='".SGMP_PLUGIN_IMAGES."/markers/' />".PHP_EOL;
echo " <param id='defaultLocationText' name='defaultLocationText' value='Enter marker destination address or latitude,longitude here (required)' />".PHP_EOL;
echo " <param id='defaultBubbleText' name='defaultBubbleText' value='Enter marker info bubble text here (optional)' />".PHP_EOL;
echo "</object> ".PHP_EOL;
}
}
endif;
if ( !function_exists('sgmp_generate_global_options') ):
function sgmp_generate_global_options() {
$tokens_with_values = array();
$tokens_with_values['LABEL_KML'] = '[TITLE] [MSG] ([STATUS])';
$tokens_with_values['LABEL_DOCINVALID_KML'] = __('The KML file is not a valid KML, KMZ or GeoRSS document.',SGMP_NAME);
$tokens_with_values['LABEL_FETCHERROR_KML'] = __('The KML file could not be fetched.',SGMP_NAME);
$tokens_with_values['LABEL_LIMITS_KML'] = __('The KML file exceeds the feature limits of KmlLayer.',SGMP_NAME);
$tokens_with_values['LABEL_NOTFOUND_KML'] = __('The KML file could not be found. Most likely it is an invalid URL, or the document is not publicly available.',SGMP_NAME);
$tokens_with_values['LABEL_REQUESTINVALID_KML'] = __('The KmlLayer is invalid.',SGMP_NAME);
$tokens_with_values['LABEL_TIMEDOUT_KML'] = __('The KML file could not be loaded within a reasonable amount of time.',SGMP_NAME);
$tokens_with_values['LABEL_TOOLARGE_KML'] = __('The KML file exceeds the file size limits of KmlLayer.',SGMP_NAME);
$tokens_with_values['LABEL_UNKNOWN_KML'] = __('The KML file failed to load for an unknown reason.',SGMP_NAME);
$tokens_with_values = array_map('sgmp_escape_json',$tokens_with_values);
$global_error_messages_json_template = sgmp_render_template_with_values($tokens_with_values, SGMP_HTML_TEMPLATE_GLOBAL_ERROR_MESSAGES);
$tokens_with_values = array();
$tokens_with_values['LABEL_STREETVIEW'] = __('Street View',SGMP_NAME);
$tokens_with_values['LABEL_ADDRESS'] = __('Address',SGMP_NAME);
$tokens_with_values['LABEL_DIRECTIONS'] = __('Directions',SGMP_NAME);
$tokens_with_values['LABEL_TOHERE'] = __('To here',SGMP_NAME);
$tokens_with_values['LABEL_FROMHERE'] = __('From here',SGMP_NAME);
$tokens_with_values = array_map('sgmp_escape_json',$tokens_with_values);
$info_bubble_translated_template = sgmp_render_template_with_values($tokens_with_values, SGMP_HTML_TEMPLATE_INFO_BUBBLE);
global $sgmp_global_map_language;
$sgmp_global_map_language = (isset($sgmp_global_map_language) && $sgmp_global_map_language != '') ? $sgmp_global_map_language : "en";
$errorArray = json_decode($global_error_messages_json_template, true);
$translationArray = json_decode($info_bubble_translated_template, true);
$properties = array();
$properties['ajaxurl'] = admin_url('admin-ajax.php');
$properties['noBubbleDescriptionProvided'] = SGMP_NO_BUBBLE_DESC;
$properties['geoValidationClientRevalidate'] = SGMP_GEO_VALIDATION_CLIENT_REVALIDATE;
$properties['cssHref'] = SGMP_PLUGIN_URI."style.css?ver=".SGMP_VERSION;
$properties['language'] = $sgmp_global_map_language;
$properties['customMarkersUri'] = SGMP_PLUGIN_IMAGES."/markers/";
foreach($errorArray as $name => $value) {
$properties[$name] = $value;
}
foreach($translationArray as $name => $value) {
$properties[$name] = $value;
}
$setting_map_should_fill_viewport = get_option(SGMP_DB_SETTINGS_MAP_SHOULD_FILL_VIEWPORT);
if (isset($setting_map_should_fill_viewport) && $setting_map_should_fill_viewport == "true") {
$properties['mapFillViewport'] = "true";
} else {
$properties['mapFillViewport'] = "false";
}
$properties[SGMP_TIMESTAMP] = wp_create_nonce(SGMP_AJAX_CACHE_MAP_ACTION);
$properties['ajaxCacheMapAction'] = SGMP_AJAX_CACHE_MAP_ACTION;
$properties['sep'] = SGMP_SEP;
echo "<script type='text/javascript'>".PHP_EOL;
echo "/* <![CDATA[ */".PHP_EOL;
echo "// Slick Google Map plugin v".SGMP_VERSION.PHP_EOL;
echo "var SGMPGlobal = ".json_encode($properties).PHP_EOL;
echo "/* ]]> */".PHP_EOL;
echo "</script>".PHP_EOL;
}
endif;
if ( !function_exists('sgmp_escape_json') ):
function sgmp_escape_json( $encode ) {
return str_replace( array("'",'"','&') , array('\u0027','\u0022','\u0026') , $encode );
}
endif;
?>