PluginProbe
CodePeople Post Map for Google Maps / trunk
CodePeople Post Map for Google Maps vtrunk
1.3.0 1.2.9 1.2.8 1.2.7 1.2.6 trunk 1.0.44 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5
codepeople-post-map / include / functions.php

functions.php in CodePeople Post Map for Google Maps trunk, at include/functions.php

1,696 lines 85.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CodePeople Post Map
4 * Version: 1.0.4
5 * Author: CodePeople
6 * Plugin URI: http://wordpress.dwbooster.com
7 */
8
9 class CPM {
10 //---------- VARIABLES ----------
11
12 var $lang_array; // List of supported languages
13 var $points = array(); // List of points to set on map
14 var $points_str = ''; // List of points as javascript code
15 var $map_id; // ID of map
16 var $limit=0; // The number of pins allowed in map zero = unlimited
17 var $defaultpost=''; // The post ID for centring the map, and display by default the infowindow
18 var $extended = array();
19 var $multiple = false;
20
21 //---------- CONSTRUCTOR ----------
22
23 function __construct(){
24 $this->map_id = "cpm_".wp_generate_password(6, false);
25 $this->lang_array = array(
26 "ar"=>__("ARABIC","codepeople-post-map"),
27 "eu"=>__("BASQUE","codepeople-post-map"),
28 "bg"=>__("BULGARIAN","codepeople-post-map"),
29 "bn"=>__("BENGALI","codepeople-post-map"),
30 "ca"=>__("CATALAN","codepeople-post-map"),
31 "cs"=>__("CZECH","codepeople-post-map"),
32 "da"=>__("DANISH","codepeople-post-map"),
33 "de"=>__("GERMAN","codepeople-post-map"),
34 "el"=>__("GREEK","codepeople-post-map"),
35 "en"=>__("ENGLISH","codepeople-post-map"),
36 "en-AU"=>__("ENGLISH (AUSTRALIAN)","codepeople-post-map"),
37 "en-GB"=>__("ENGLISH (GREAT BRITAIN)","codepeople-post-map"),
38 "es"=>__("SPANISH","codepeople-post-map"),
39 "eu"=>__("BASQUE","codepeople-post-map"),
40 "fa"=>__("FARSI","codepeople-post-map"),
41 "fi"=>__("FINNISH","codepeople-post-map"),
42 "fil"=>__("FILIPINO","codepeople-post-map"),
43 "fr"=>__("FRENCH","codepeople-post-map"),
44 "gl"=>__("GALICIAN","codepeople-post-map"),
45 "gu"=>__("GUJARATI","codepeople-post-map"),
46 "hi"=>__("HINDI","codepeople-post-map"),
47 "hr"=>__("CROATIAN","codepeople-post-map"),
48 "hu"=>__("HUNGARIAN","codepeople-post-map"),
49 "id"=>__("INDONESIAN","codepeople-post-map"),
50 "it"=>__("ITALIAN","codepeople-post-map"),
51 "iw"=>__("HEBREW","codepeople-post-map"),
52 "ja"=>__("JAPANESE","codepeople-post-map"),
53 "kn"=>__("KANNADA","codepeople-post-map"),
54 "ko"=>__("KOREAN","codepeople-post-map"),
55 "lt"=>__("LITHUANIAN","codepeople-post-map"),
56 "lv"=>__("LATVIAN","codepeople-post-map"),
57 "ml"=>__("MALAYALAM","codepeople-post-map"),
58 "mr"=>__("MARATHI","codepeople-post-map"),
59 "nl"=>__("DUTCH","codepeople-post-map"),
60 "no"=>__("NORWEGIAN","codepeople-post-map"),
61 "or"=>__("ORIYA","codepeople-post-map"),
62 "pl"=>__("POLISH","codepeople-post-map"),
63 "pt"=>__("PORTUGUESE","codepeople-post-map"),
64 "pt-BR"=>__("PORTUGUESE (BRAZIL)","codepeople-post-map"),
65 "pt-PT"=>__("PORTUGUESE (PORTUGAL)","codepeople-post-map"),
66 "ro"=>__("ROMANIAN","codepeople-post-map"),
67 "ru"=>__("RUSSIAN","codepeople-post-map"),
68 "sk"=>__("SLOVAK","codepeople-post-map"),
69 "sl"=>__("SLOVENIAN","codepeople-post-map"),
70 "sr"=>__("SERBIAN","codepeople-post-map"),
71 "sv"=>__("SWEDISH","codepeople-post-map"),
72 "tl"=>__("TAGALOG","codepeople-post-map"),
73 "ta"=>__("TAMIL","codepeople-post-map"),
74 "te"=>__("TELUGU","codepeople-post-map"),
75 "th"=>__("THAI","codepeople-post-map"),
76 "tr"=>__("TURKISH","codepeople-post-map"),
77 "uk"=>__("UKRAINIAN","codepeople-post-map"),
78 "vi"=>__("VIETNAMESE","codepeople-post-map"),
79 "zh-CN"=>__("CHINESE (SIMPLIFIED)","codepeople-post-map"),
80 "zh-TW"=>__("CHINESE (TRADITIONAL)","codepeople-post-map")
81
82 );
83
84 } // End __construct
85
86 function array_map_recursive($callback, $array)
87 {
88 foreach ($array as $key => $value) {
89 if (is_array($array[$key])) {
90 $array[$key] = $this->array_map_recursive($callback, $array[$key]);
91 }
92 else {
93 $array[$key] = call_user_func($callback, $array[$key]);
94 }
95 }
96 return $array;
97 }
98
99 function sanitize_coord( $v )
100 {
101 if ( ! is_string( $v ) && ! is_numeric( $v ) ) return '';
102 $v = trim( (string) $v );
103 return preg_match( '/^-?\d{1,3}(\.\d+)?$/', $v ) ? $v : '';
104 } // End sanitize_coord
105
106 function sanitize_description( $v )
107 {
108 if ( ! is_string( $v ) ) return '';
109 return wp_kses_post( $v );
110 } // End sanitize_description
111
112 //---------- CREATE MAP ----------
113
114 /**
115 * Save a map object in database
116 * called by the action save_post
117 */
118 function save_map($post_id){
119 // authentication checks
120
121 // make sure data came from our meta box
122 if (!isset($_POST['cpm_map_noncename']) || !wp_verify_nonce($_POST['cpm_map_noncename'],__FILE__)) return $post_id;
123
124 // check user permissions
125 if (isset($_POST['post_type'] ) && $_POST['post_type'] == 'page'){
126 if (!current_user_can('publish_pages')) return $post_id;
127 }
128 else{
129 if (!current_user_can('publish_posts')) return $post_id;
130 }
131
132 // authentication passed, save data
133 $default_icon = ( !empty( $_POST['default_icon'] ) ) ? sanitize_text_field( wp_unslash( $_POST['default_icon'] ) ) : $this->get_configuration_option('default_icon');
134
135 delete_post_meta($post_id,'cpm_point');
136 delete_post_meta($post_id,'cpm_map');
137
138 $new_cpm_point = ( isset( $_POST['cpm_point'] ) && is_array( $_POST['cpm_point'] ) ) ? wp_unslash( $_POST['cpm_point'] ) : array();
139 $new_cpm_map = ( isset( $_POST['cpm_map'] ) && is_array( $_POST['cpm_map'] ) ) ? wp_unslash( $_POST['cpm_map'] ) : array();
140 $new_cpm_map = $this->array_map_recursive('sanitize_text_field', $new_cpm_map);
141
142 // Per-field sanitization (storage layer hardening).
143 // Runs unconditionally - never gated by $new_cpm_map['single'].
144 $new_cpm_point['address'] = isset( $new_cpm_point['address'] )
145 ? sanitize_text_field( $new_cpm_point['address'] )
146 : '';
147 $new_cpm_point['name'] = isset( $new_cpm_point['name'] )
148 ? sanitize_text_field( $new_cpm_point['name'] )
149 : '';
150 $new_cpm_point['description'] = isset( $new_cpm_point['description'] )
151 ? $this->sanitize_description( $new_cpm_point['description'] )
152 : '';
153 $new_cpm_point['latitude'] = isset( $new_cpm_point['latitude'] )
154 ? $this->sanitize_coord( $new_cpm_point['latitude'] )
155 : '';
156 $new_cpm_point['longitude'] = isset( $new_cpm_point['longitude'] )
157 ? $this->sanitize_coord( $new_cpm_point['longitude'] )
158 : '';
159 $new_cpm_point['thumbnail'] = isset( $new_cpm_point['thumbnail'] )
160 ? esc_url_raw( $new_cpm_point['thumbnail'], array( 'http', 'https' ) )
161 : '';
162
163 $new_cpm_point['icon'] = str_replace( CPM_PLUGIN_URL, '', $default_icon );
164
165 // Set the map's config
166 $new_cpm_map['single'] = (isset($new_cpm_map['single'])) ? true : false;
167 if($new_cpm_map['single']){
168 $new_cpm_map['zoompancontrol'] = (! empty( $new_cpm_map['zoompancontrol'] ) && $new_cpm_map['zoompancontrol'] == true);
169 $new_cpm_map['fullscreencontrol'] = (! empty( $new_cpm_map['fullscreencontrol'] ) && $new_cpm_map['fullscreencontrol'] == true);
170 $new_cpm_map['mousewheel'] = (! empty( $new_cpm_map['mousewheel'] ) && $new_cpm_map['mousewheel'] == true);
171 $new_cpm_map['typecontrol'] = (! empty( $new_cpm_map['typecontrol'] ) && $new_cpm_map['typecontrol'] == true);
172 $new_cpm_map['streetviewcontrol'] = (! empty( $new_cpm_map['streetviewcontrol'] ) && $new_cpm_map['streetviewcontrol'] == true);
173 $new_cpm_map['trafficlayer'] = (! empty( $new_cpm_map['trafficlayer'] ) && $new_cpm_map['trafficlayer'] == true);
174 $new_cpm_map['dynamic_zoom'] = (isset($new_cpm_map['dynamic_zoom']) && $new_cpm_map['dynamic_zoom']) ? true : false;
175 $new_cpm_map['show_default'] = (isset($new_cpm_map['show_default']) && $new_cpm_map['show_default']) ? true : false;
176 $new_cpm_map['show_window'] = (isset($new_cpm_map['show_window']) && $new_cpm_map['show_window']) ? true : false;
177 $new_cpm_map['drag_map'] = (isset($new_cpm_map['drag_map']) && $new_cpm_map['drag_map']) ? true : false;
178
179 add_post_meta($post_id,'cpm_map',$new_cpm_map,TRUE);
180 }
181
182 // The address is required, if address is empty the couple: latitude, longitude must be defined
183 if(!(empty($new_cpm_point['latitude']) || empty($new_cpm_point['longitude']))){
184 add_post_meta($post_id,'cpm_point',$new_cpm_point,TRUE);
185 }
186
187 } // End save_map
188
189 //---------- OPTIONS FOR CODEPEOPLE POST MAP ----------
190 /**
191 * Get default configuration options
192 */
193 function _default_configuration( $attr = '' ){
194 $default = array(
195 'zoom' => '10',
196 'dynamic_zoom' => false,
197 'width' => '450',
198 'height' => '450',
199 'margin' => '10',
200 'align' => 'center',
201 'language' => 'en',
202 'drag_map' => true,
203 'icons' => array(),
204 'default_icon' => CPM_PLUGIN_URL.'/images/icons/marker.png',
205 'type' => 'ROADMAP',
206 'points' => 3,
207 'display' => 'map',
208 'mousewheel' => true,
209 'zoompancontrol' => true,
210 'fullscreencontrol' => true,
211 'typecontrol' => true,
212 'streetviewcontrol' => true,
213 'trafficlayer' => false,
214 'highlight' => true,
215 'highlight_class' => 'cpm_highlight',
216 'tooltip' => 'title',
217 'show_window' => true,
218 'show_default' => true,
219 'wpml' => 'all',
220 'windowhtml' => "<div class='cpm-infowindow'>
221 <div class='cpm-content'>
222 <a title='%link%' href='%link%'>%thumbnail%</a>
223 <a class='title' href='%link%'>%title%</a>
224 <div class='address'>%address%</div>
225 <div class='description'>%description%</div>
226 </div>
227 <div style='clear:both;'></div>
228 </div>"
229 );
230 return (!empty($attr) && isset($default[$attr])) ? $default[$attr] : $default;
231 } // End _default_configuration
232
233 /**
234 * Set default system and maps configuration
235 */
236 function set_default_configuration(){
237 $cpm_default = $this->_default_configuration();
238 $options = get_option('cpm_config');
239 if($options !== false) $options = array_replace_recursive($cpm_default, $options);
240 else $options = $cpm_default;
241 return $options;
242 } // End set_default_configuration
243
244 /**
245 * Get a part of option variable or the complete array
246 */
247 function get_configuration_option($option = null){
248
249 $options = get_option('cpm_config');
250 $default = $this->_default_configuration();
251
252 if(!isset($options)){
253 $options = $default;
254 }
255
256 if(isset($option)){
257 return (isset($options[$option])) ? $options[$option] : ((isset($default[$option])) ? $default[$option] : null);
258 }else{
259 return $options;
260 }
261
262 } // End get_configuration_option
263
264 //---------- METADATA FORM METHODS ----------
265
266 /**
267 * Private method to deploy the list of languages
268 */
269 function _deploy_languages($options){
270 print '<select name="cpm_map[language]" id="cpm_map_language">';
271 foreach($this->lang_array as $key=>$value)
272 print '<option value="'.esc_attr($key).'" '.((isset($options['language']) && $options['language'] == $key) ? 'selected' : '').'>'.$value.'</option>';
273 print '</select>';
274 } // End _deploy_languages
275
276 /**
277 * Private method to get the list of icons
278 */
279 function _deploy_icons($options = null){
280 $icon_path = CPM_PLUGIN_URL.'/images/icons/';
281 $icon_dir = CPM_PLUGIN_DIR.'/images/icons/';
282
283 $icons_array = array();
284
285 $default_icon = (isset($options) && isset($options['icon'])) ? $options['icon'] : $this->get_configuration_option('default_icon');
286 if( strpos($default_icon, 'http') !== 0 ) $default_icon = CPM_PLUGIN_URL.$default_icon;
287
288 if ($handle = opendir($icon_dir)) {
289
290 while (false !== ($file = readdir($handle))) {
291
292 $file_type = wp_check_filetype($file);
293 $file_ext = $file_type['ext'];
294 if ($file != "." && $file != ".." && ($file_ext == 'gif' || $file_ext == 'jpg' || $file_ext == 'png') ) {
295 array_push($icons_array,$icon_path.$file);
296 }
297 }
298 }
299 ?>
300 <div class="cpm_label">
301 <?php _e("Select the marker by clicking on the images", "codepeople-post-map"); ?>
302 </div>
303 <div id="cpm_icon_cont">
304 <input type="hidden" name="default_icon" value="<?php esc_attr_e($default_icon); ?>" id="default_icon" />
305 <?php foreach ($icons_array as $icon){ ?>
306 <div class="cpm_icon <?php if ($default_icon == $icon) echo "cpm_selected" ?>">
307 <img src="<?php echo $icon ?>" />
308 </div>
309 <?php } ?>
310 </div>
311 <div id="icon_credit">
312 <span><?php _e("Powered by","codepeople-post-map"); ?></span>
313 <a href="http://mapicons.nicolasmollet.com" target="_blank">
314 <img src="<?php echo CPM_PLUGIN_URL ?>/images/miclogo-88x31.gif" />
315 </a>
316 </div>
317 <div class="clear"></div>
318 <span class="cpm_more_info_hndl cpm_blink_me" style="margin-left: 10px;"><a href="javascript:void(0);" onclick="cpm_display_more_info( this );">[ + more information]</a></span>
319 <div class="cpm_more_info">
320 <p>To use your own markers icons, you only should to upload the icons images to the following location:</p>
321 <p>/wp-content/plugins/codepeople-post-map/images/icons</p>
322 <p>and then select the icon's image from the list</p>
323 <a href="javascript:void(0)" onclick="cpm_hide_more_info( this );">[ + less information]</a>
324 </div>
325 <?php
326 } // End _deploy_icons
327
328 /**
329 * Private method to insert the map form
330 */
331 function _deploy_map_form($options = NULL, $single = false){
332 ?>
333 <h1><?php _e('Maps Configuration', 'codepeople-post-map'); ?></h1>
334 <p style="border:1px solid #E6DB55;margin-bottom:10px;padding:5px;background-color: #FFFFE0;">
335 <?php _e('For any issues with the map, go to our <a href="http://wordpress.dwbooster.com/contact-us" target="_blank">contact page</a> and leave us a message.', 'codepeople-post-map'); ?><br/><br />
336 <?php _e('To test the premium version of CodePeople Post Map for Google Maps, please, go to the following links:<br/> <a href="https://demos.dwbooster.com/cp-google-maps/wp-login.php" target="_blank">Administration area: Click to access the administration area demo</a><br/> <a href="https://demos.dwbooster.com/cp-google-maps/" target="_blank">Public page: Click to access the CodePeople Post Map for Google Maps</a>', 'codepeople-post-map' ); ?>
337 </p>
338 <?php
339 if(!$single)
340 {
341 ?>
342 <div style="padding:10px; border: 1px solid #DADADA;margin-bottom:20px;text-align:center;">
343 <h2><?php _e('Video Tutorial', 'codepeople-post-map'); ?></h2>
344 <style>.videoWrapper {position: relative;padding-bottom: 56.25%;height: 0;} .videoWrapper iframe {position: absolute;top: 0;left: 0;width: 100%;height: 100%;}</style>
345 <div class="videoWrapper">
346 <iframe width="560" height="349" src="https://www.youtube.com/embed/VL067cYfYyM" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
347 </div>
348 </div>
349 <?php
350 }
351 ?>
352 <style>
353 .cpm-settings input[type="text"],
354 .cpm-settings input[type="file"],
355 .cpm-settings input[type="number"],
356 .cpm-settings select,
357 .cpm-settings textarea{ min-width:50%;}
358 </style>
359 <table class="form-table cpm-settings">
360 <?php
361 $additional_tr_styles = '';
362 if( !$single )
363 {
364 // $additional_tr_styles = 'display:block';
365 ?>
366 <tr valign="top">
367 <th scope="row"><label><?php _e('I have an API key:', 'codepeople-post-map')?></label></th>
368 <td>
369 <p class="cpm_blink_me" style="color:red;"><span style="font-size:2em;">&#11024;</span> <?php _e('Enter your API Key', 'codepeople-post-map');?></p>
370 <input type="text" name="cpm_map[api_key]" id="cpm_map_api_key" value="<?php esc_attr_e( ( !empty( $options['api_key'] ) ) ? $options['api_key'] : '' ); ?>" /><br>
371 <?php
372 _e( 'Please, visit the following link to get the API Key for your website:', 'codepeople-post-map');
373 ?><br>
374 <a href="https://developers.google.com/maps/documentation/javascript/get-api-key" target="_blank">https://developers.google.com/maps/documentation/javascript/get-api-key</a>
375 <p style="margin-top:20px; border: 1px dashed #DEDEDE; padding: 10px;">
376 <?php _e('With the Google project, activate at least the following APIs', 'codepeople-post-map'); ?>:<br />
377 <b>- Maps JavaScript API</b><br />
378 <b>- Geocoding API</b><br />
379 <b>- Places API</b> (<?php _e('Required if the <i>"Display a search box for places"</i> option is enabled', 'codepeople-post-map'); ?>)<br />
380 <b>- Directions API</b> (<?php _e('Required if the <i>"Display route"</i> option is enabled', 'codepeople-post-map'); ?>)
381 </p>
382 </td>
383 </tr>
384 <?php
385 }
386 if($single){
387 ?>
388 <tr valign="top">
389 <th scope="row" colspan="2">
390 <label for="cpm_map_single">
391 <?php _e('Use particular settings for this map:', 'codepeople-post-map')?>
392 <input type="checkbox" name="cpm_map[single]" id="cpm_map_single" <?php
393 if(isset($options['single']))
394 {
395 // $additional_tr_styles = 'display:block;';
396 print 'CHECKED';
397 }
398 else
399 {
400 $additional_tr_styles = 'display:none;';
401 }
402 ?> />
403 </label>
404 </th>
405 </tr>
406 <?php
407 }
408 ?>
409 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
410 <th scope="row"><label for="cpm_map_zoom"><?php _e('Map zoom:', 'codepeople-post-map')?></label></th>
411 <td>
412 <input type="text" size="4" name="cpm_map[zoom]" id="cpm_map_zoom" value="<?php esc_attr_e((isset($options['zoom'])) ? $options['zoom'] : '');?>" />
413 </td>
414 </tr>
415 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
416 <th scope="row"><label for="cpm_map_dynamic_zoom"><?php _e('Dynamic zoom:', 'codepeople-post-map')?></label></th>
417 <td>
418 <input type="checkbox" name="cpm_map[dynamic_zoom]" id="cpm_map_dynamic_zoom" <?php echo ( ( isset($options['dynamic_zoom'] ) && $options['dynamic_zoom'] ) ? 'CHECKED' : '' ); ?> /> <?php _e( 'Allows to adjust the zoom dynamically to display all points on map', 'codepeople-post-map' ); ?>
419 </td>
420 </tr>
421 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
422 <th scope="row"><label for="cpm_map_width"><?php _e('Map width:', 'codepeople-post-map'); ?></label></th>
423 <td>
424 <input type="text" size="4" name="cpm_map[width]" id="cpm_map_width" value="<?php esc_attr_e((isset($options['width'])) ? $options['width'] : '');?>" />
425 <span class="cpm_more_info_hndl cpm_blink_me" style="margin-left: 10px;"><a href="javascript:void(0);" onclick="cpm_display_more_info( this );">[ + more information]</a></span>
426 <div class="cpm_more_info">
427 <p>To insert the map in a responsive design (in a responsive design, the map's width should be adjusted with the page width):</p>
428 <p>the value of map's width should be defined as a percentage of container's width, for example, type the value: <strong>100%</strong></p>
429 <a href="javascript:void(0)" onclick="cpm_hide_more_info( this );">[ + less information]</a>
430 </div>
431 </td>
432 </tr>
433 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
434 <th scope="row"><label for="cpm_map_height"><?php _e('Map height:', 'codepeople-post-map'); ?></label></th>
435 <td>
436 <input type="text" size="4" name="cpm_map[height]" id="cpm_map_height" value="<?php esc_attr_e((isset($options['height'])) ? $options['height'] : '');?>" />
437 </td>
438 </tr>
439 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
440 <th scope="row"><label for="cpm_map_margin"><?php _e('Map margin:', 'codepeople-post-map'); ?></label></th>
441 <td>
442 <input type="text" size="4" name="cpm_map[margin]" id="cpm_map_margin" value="<?php esc_attr_e((isset($options['height'])) ? $options['margin'] : '');?>" />
443 </td>
444 </tr>
445 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
446 <th scope="row"><label for="cpm_map_align"><?php _e('Map align:', 'codepeople-post-map'); ?></label></th>
447 <td>
448 <select id="cpm_map_align" name="cpm_map[align]">
449 <option value="left" <?php echo((isset($options['align']) && $options['align'] == 'left') ? 'selected': ''); ?>><?php _e('left', 'codepeople-post-map'); ?></option>
450 <option value="center" <?php echo((isset($options['align']) && $options['align'] == 'center') ? 'selected': ''); ?>><?php _e('center', 'codepeople-post-map'); ?></option>
451 <option value="right" <?php echo((isset($options['align']) && $options['align'] == 'right') ? 'selected': ''); ?>><?php _e('right', 'codepeople-post-map'); ?></option>
452 </select>
453 </td>
454 </tr>
455 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
456 <th scope="row"><label for="cpm_map_type"><?php _e('Map type:', 'codepeople-post-map'); ?></label></th>
457 <td>
458 <select name="cpm_map[type]" id="cpm_map_type" >
459 <option value="ROADMAP" <?php echo ((isset($options['type']) && $options['type']=='ROADMAP') ? 'selected' : '');?>><?php _e('ROADMAP - Displays a normal street map', 'codepeople-post-map');?></option>
460 <option value="SATELLITE" <?php echo ((isset($options['type']) && $options['type']=='SATELLITE') ? 'selected' : '');?>><?php _e('SATELLITE - Displays satellite images', 'codepeople-post-map');?></option>
461 <option value="TERRAIN" <?php echo ((isset($options['type']) && $options['type']=='TERRAIN') ? 'selected' : '');?>><?php _e('TERRAIN - Displays maps with physical features such as terrain and vegetation', 'codepeople-post-map');?></option>
462 <option value="HYBRID" <?php echo ((isset($options['type']) && $options['type']=='HYBRID') ? 'selected' : '');?>><?php _e('HYBRID - Displays a transparent layer of major streets on satellite images', 'codepeople-post-map');?></option>
463 </select>
464 </td>
465 </tr>
466 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
467 <th scope="row"><label for="cpm_map_language"><?php _e('Map language:', 'codepeople-post-map');?></label></th>
468 <td><?php $this->_deploy_languages($options); ?></td>
469 </tr>
470 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
471 <th scope="row"><label for="cpm_drag_map"><?php _e('Allow drag the map:', 'codepeople-post-map'); ?></label></th>
472 <td>
473 <input type="checkbox" name="cpm_map[drag_map]" id="cpm_drag_map" <?php echo ((!isset( $options['drag_map'] ) || $options['drag_map']) ? 'CHECKED' : '');?> />
474 </td>
475 </tr>
476 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
477 <th scope="row"><label for="cpm_map_display"><?php _e('Display map in post/page:', 'codepeople-post-map'); ?></label></th>
478 <td>
479 <select name="cpm_map[display]" id="cpm_map_display" >
480 <option value="icon" <?php echo ((isset($options['display']) && $options['display']=='icon') ? 'selected' : '');?>><?php _e('as icon', 'codepeople-post-map'); ?></option>
481 <option value="map" <?php echo ((isset($options['display']) && $options['display']=='map') ? 'selected' : '');?>><?php _e('as full map', 'codepeople-post-map'); ?></option>
482 </select>
483 </td>
484 </tr>
485
486 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
487 <th scope="row"><label for="cpm_show_window"><?php _e('Show info bubbles:', 'codepeople-post-map');?></label></th>
488 <td>
489 <input type="checkbox" id="cpm_show_window" name="cpm_map[show_window]" value="true" <?php echo ((isset($options['show_window']) && $options['show_window']) ? 'checked' : '');?>><span> <?php _e( 'Display the bubbles associated to the points', 'codepeople-post-map');?></span>
490 </td>
491 </tr>
492
493 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
494 <th scope="row"><label for="cpm_show_default"><?php _e('Display a bubble by default:', 'codepeople-post-map');?></label></th>
495 <td>
496 <input type="checkbox" id="cpm_show_default" name="cpm_map[show_default]" value="true" <?php echo ((isset($options['show_default']) && $options['show_default']) ? 'checked' : '');?>><span> <?php _e( 'Display a bubble opened by default', 'codepeople-post-map' ); ?></span>
497 </td>
498 </tr>
499
500 <?php
501 if( !$single )
502 {
503 ?>
504 <tr valign="top">
505 <th scope="row"><label for="cpm_tooltip"><?php _e('Display as marker tooltip:', 'codepeople-post-map');?></label></th>
506 <td>
507 <input type="radio" name="cpm_map[tooltip]" value="title" <?php echo ((!isset($options['tooltip']) || $options['tooltip'] == 'title') ? 'checked' : '');?> /><span> <?php _e( 'Point location name', 'codepeople-post-map' ); ?></span><br />
508 <input type="radio" name="cpm_map[tooltip]" value="address" <?php echo ((isset($options['tooltip']) && $options['tooltip'] == 'address') ? 'checked' : '');?> /><span> <?php _e( 'Point address', 'codepeople-post-map' ); ?></span><br />
509 <input type="radio" name="cpm_map[tooltip]" value="none" <?php echo ((isset($options['tooltip']) && $options['tooltip'] == 'none') ? 'checked' : '');?> /><span> <?php _e( 'None', 'codepeople-post-map' ); ?></span>
510 </td>
511 </tr>
512
513 <tr valign="top">
514 <th scope="row"><label for="cpm_featured_image"><?php _e('Display Featured Image by default:', 'codepeople-post-map');?></label></th>
515 <td>
516 <input type="checkbox" id="cpm_featured_image" name="cpm_map[featured_image]" value="true" <?php echo ((isset($options['featured_image']) && $options['featured_image']) ? 'checked' : '');?>><span> <?php _e( 'Displays the Featured Image in posts and pages in the infowindows, if the points don\'t have associated an image', 'codepeople-post-map' ); ?></span>
517 </td>
518 </tr>
519
520 <tr valign="top">
521 <th scope="row"><label for="cpm_get_direction" style="color:#CCCCCC;"><?php _e('Display the get directions link:', 'codepeople-post-map');?></label></th>
522 <td>
523 <input type="checkbox" disabled><span> <?php _e( 'Display a link at bottom of infowindow to get directions', 'codepeople-post-map' ); ?></span><br />
524 <span style="color:#FF0000;"><?php _e( 'The feature is available only for the commercial version of plugin. <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download">Click Here</a>', 'codepeople-post-map' ); ?></span>
525 </td>
526 </tr>
527
528 <tr valign="top">
529 <th scope="row"><label for="cpm_map_link" style="color:#CCCCCC;"><?php _e('Display a link to Google Maps:', 'codepeople-post-map');?></label></th>
530 <td>
531 <input type="checkbox" disabled><span> <?php _e( 'Display a link at bottom of infowindow to display on Google Maps', 'codepeople-post-map' ); ?></span><br />
532 <span style="color:#FF0000;"><?php _e( 'The feature is available only for the commercial version of plugin. <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download">Click Here</a>', 'codepeople-post-map' ); ?></span>
533 </td>
534 </tr>
535
536 <tr valign="top">
537 <th scope="row"><label for="cpm_street_view_link" style="color:#CCCCCC;"><?php _e('Display a link to street view:', 'codepeople-post-map');?></label></th>
538 <td>
539 <input type="checkbox" disabled /><span> <?php _e( 'Display a link at bottom of infowindow to load the corresponding street view', 'codepeople-post-map' ); ?></span><br />
540 <span style="color:#FF0000;"><?php _e( 'The feature is available only for the commercial version of plugin. <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download">Click Here</a>', 'codepeople-post-map' ); ?></span>
541 </td>
542 </tr>
543
544 <tr valign="top">
545 <th scope="row"><label for="cpm_MarkerClusterer" style="color:#CCCCCC;"><?php _e('Display a bundle of points in the same area, like a cluster:', 'codepeople-post-map');?></label></th>
546 <td>
547 <input type="checkbox" disabled /><span> <?php _e( 'Displays the number of points in the cluster', 'codepeople-post-map' ); ?></span><br />
548 <span style="color:#FF0000;"><?php _e( 'The feature is available only for the commercial version of plugin. <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download">Click Here</a>', 'codepeople-post-map' ); ?></span>
549 </td>
550 </tr>
551
552 <tr valign="top">
553 <th scope="row"><label for="cpm_your_location" style="color:#CCCCCC;"><?php _e('Display the user\'s location:', 'codepeople-post-map');?></label></th>
554 <td>
555 <input type="checkbox" disabled /><span> <?php _e( "Display an icon with the user's location on map", 'codepeople-post-map' ); ?> </span><br />
556 <span style="color:#FF0000;"><?php _e( 'The feature is available only for the commercial version of plugin. <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download">Click Here</a>', 'codepeople-post-map' ); ?></span>
557 </td>
558 </tr>
559
560 <tr valign="top">
561 <th scope="row"><label for="cpm_refresh_location" style="color:#CCCCCC;"><?php _e('Refresh the user\'s location every:', 'codepeople-post-map');?></label></th>
562 <td>
563 <input type="text" disabled /><span> <?php _e( "milliseconds", 'codepeople-post-map' ); ?></span><br />
564 <span style="color:#FF0000;"><?php _e( 'The feature is available only for the commercial version of plugin. <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download">Click Here</a>', 'codepeople-post-map' ); ?></span>
565 </td>
566 </tr>
567
568 <tr valign="top">
569 <th scope="row"><label for="cpm_your_location_title" style="color:#CCCCCC;"><?php _e("Title of user's location:", 'codepeople-post-map');?></label></th>
570 <td>
571 <input type="text" disabled value="You are here" /><span> <?php _e("Title of user's location", 'codepeople-post-map');?></span><br />
572 <span style="color:#FF0000;"><?php _e( 'The feature is available only for the commercial version of plugin. <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download">Click Here</a>', 'codepeople-post-map' ); ?></span>
573 </td>
574 </tr>
575 <?php
576 }
577 ?>
578 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
579 <th scope="row"><label for="cpm_search_box" style="color:#CCCCCC;"><?php _e('Display a search box for places:', 'codepeople-post-map');?></label></th>
580 <td>
581 <input type="checkbox" disabled><span> <?php _e( "Includes an input box on the map for searching places", 'codepeople-post-map' ); ?></span><br />
582 <?php _e( 'The feature is available only for the commercial version of plugin. <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download">Click Here</a>', 'codepeople-post-map' ); ?></span>
583 </td>
584 </tr>
585
586 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
587 <th scope="row"><label for="cpm_map_route" style="color:#CCCCCC;"><?php _e('Display route:', 'codepeople-post-map');?></label></th>
588 <td>
589 <input type="checkbox" DISABLED><span> <?php _e( 'Draws the route between the points in the same post', 'codepeople-post-map'); ?></span><br />
590 <input type="checkbox" DISABLED><span> <?php _e( 'Connect the points with polylines, even if there is not a route between points', 'codepeople-post-map' ); ?> </span><br />
591 <span style="color:#FF0000;">The route between points is available only for the commercial version of plugin. <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download">Click Here</a></span>
592 </td>
593 </tr>
594
595 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
596 <th scope="row"><label for="cpm_travel_mode" style="color:#CCCCCC;"><?php _e('Travel mode:', 'codepeople-post-map');?></label></th>
597 <td>
598 <select disabled>
599 <option value="DRIVING">Driving</option>
600 </select>
601 </td>
602 </tr>
603
604 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
605 <th scope="row"><label for="cpm_map_traffic"><?php _e('Include traffic layer:', 'codepeople-post-map');?></label></th>
606 <td>
607 <input type="checkbox" name="cpm_map[trafficlayer]" <?php if( isset($options['trafficlayer']) && $options['trafficlayer'] ) print 'CHECKED'; ?>><span> <?php _e( 'Displays a layer over the map for traffic', 'codepeople-post-map'); ?></span>
608 </td>
609 </tr>
610
611 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
612 <th scope="row"><label for="wpGoogleMaps_description"><?php _e('Options', 'codepeople-post-map'); ?>:</label></th>
613 <td>
614 <input type="checkbox" name="cpm_map[streetviewcontrol]" id="cpm_map_streetviewcontrol" value="true" <?php echo ((isset($options['streetviewcontrol']) && $options['streetviewcontrol']) ? 'checked' : '');?> />
615 <label for="cpm_map_streetviewcontrol"><?php _e('Display the street view control', 'codepeople-post-map'); ?></label><br />
616 <input type="checkbox" name="cpm_map[mousewheel]" id="cpm_map_mousewheel" value="true" <?php echo ((isset($options['mousewheel']) && $options['mousewheel']) ? 'checked' : '');?> />
617 <label for="cpm_map_mousewheel"><?php _e('Enable mouse wheel zoom', 'codepeople-post-map'); ?></label><br />
618 <input type="checkbox" name="cpm_map[zoompancontrol]" id="cpm_map_zoompancontrol" value="true" <?php echo ((isset($options['zoompancontrol']) && $options['zoompancontrol']) ? 'checked' : '');?> />
619 <label for="cpm_map_zoompancontrol"><?php _e('Enable zoom controls', 'codepeople-post-map'); ?></label><br />
620 <input type="checkbox" name="cpm_map[fullscreencontrol]" id="cpm_map_fullscreencontrol" value="true" <?php echo ((isset($options['fullscreencontrol']) && $options['fullscreencontrol']) ? 'checked' : '');?> />
621 <label for="cpm_map_fullscreencontrol"><?php _e('Enable fullscreen control', 'codepeople-post-map'); ?></label><br />
622 <input type="checkbox" name="cpm_map[typecontrol]" id="cpm_map_typecontrol" value="true" <?php echo ((isset($options['typecontrol']) && $options['typecontrol']) ? 'checked' : '');?> />
623 <label for="cpm_map_typecontrol"> <?php _e('Enable map type controls (Map, Satellite, or Hybrid)', 'codepeople-post-map'); ?> </label><br />
624 </td>
625 </tr>
626 <tr valign="top" class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
627 <th scope="row"><label for="cpm_map_points"><?php _e('Enter the number of posts to display on the post/page map', 'codepeople-post-map'); ?>:</label></th>
628 <td><input type="text" name="cpm_map[points]" id="cpm_map_points" value="<?php esc_attr_e((isset($options['points'])) ? $options['points'] : '');?>" /></td>
629 </tr>
630 <tr class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
631 <th scope="row"><label><?php _e('Allow stylize the maps:', 'codepeople-post-map')?></label></th>
632 <td valign="top" style="border:1px solid #CCC; padding: 20px;">
633 <p><?php
634 esc_html_e( "Map styling has changed in the latest Google Maps APIs. You must now do this through the Google Cloud Console.", 'codepeople-post-map' ); ?></p>
635 <p><?php
636 esc_html_e( "Creating custom Google Maps styles and associating them with Map IDs allows you to tailor your maps to your website's aesthetic and functionality. Here's a step-by-step guide:", 'codepeople-post-map' ); ?></p>
637 <ol>
638 <li>
639 <strong><?php esc_html_e( 'Create a Map ID:', 'codepeople-post-map' ); ?></strong>
640 <ul style="list-style:disc;margin-left:20px;">
641 <li><?php esc_html_e( 'Access the ', 'codepeople-post-map' ); ?><a href="https://console.cloud.google.com/" target="_blank">Google Cloud Console</a>.</li>
642 <li><?php esc_html_e( 'Navigate to', 'codepeople-post-map' ); ?> <strong>"Map Management"</strong> <?php esc_html_e( 'within the Google Maps Platform.', 'codepeople-post-map' ); ?></li>
643 <li><?php esc_html_e( 'Click', 'codepeople-post-map' ); ?> <strong>"Create Map ID,"</strong> <?php esc_html_e( 'provide a name, select the map type', 'codepeople-post-map' ); ?> (<strong>JavaScript</strong>), <?php esc_html_e( 'and create.', 'codepeople-post-map' ); ?></li>
644 <li><?php esc_html_e( 'Note your generated Map ID.', 'codepeople-post-map' ); ?></li>
645 </ul>
646 </li>
647 <li>
648 <strong><?php esc_html_e( 'Create a Map Style:', 'codepeople-post-map' ); ?></strong>
649 <ul style="list-style:disc;margin-left:20px;">
650 <li><?php esc_html_e( 'Go to', 'codepeople-post-map' ); ?> <strong>"Map Styles"</strong> <?php esc_html_e( 'in the Google Maps Platform.', 'codepeople-post-map' ); ?></li>
651 <li><?php esc_html_e( 'Click', 'codepeople-post-map' ); ?> <strong>"Create style."</strong></li>
652 <li>
653 <?php esc_html_e( 'Customize visually or using JSON:', 'codepeople-post-map' ); ?>
654 <ul style="list-style:circle;margin-left:20px;">
655 <li><strong><?php esc_html_e( 'Visual Customization:', 'codepeople-post-map' ); ?></strong> <?php esc_html_e( 'Use the editor tools to modify features and colors.', 'codepeople-post-map' ); ?></li>
656 <li><strong><?php esc_html_e( 'JSON Customization:', 'codepeople-post-map' ); ?></strong> <?php esc_html_e( 'Paste your JSON styling code into the editor.', 'codepeople-post-map' ); ?></li>
657 <li><?php esc_html_e( 'Refine in the visual editor after importing JSON, if desired.', 'codepeople-post-map' ); ?></li>
658 </ul>
659 </li>
660 <li><?php esc_html_e( 'Name and publish your style.', 'codepeople-post-map' ); ?></li>
661 </ul>
662 </li>
663 <li>
664 <strong><?php esc_html_e( 'Associate the Map Style with the Map ID (via Map Management):', 'codepeople-post-map' ); ?></strong>
665 <ul style="list-style:disc;margin-left:20px;">
666 <li><?php esc_html_e( 'Navigate to', 'codepeople-post-map' );?> <strong>"Map Management"</strong> <?php esc_html_e( 'within the Google Maps Platform.', 'codepeople-post-map' ); ?></li>
667 <li><?php esc_html_e( 'Select the Map ID from the list by clicking its name.', 'codepeople-post-map' ); ?></li>
668 <li><?php esc_html_e( 'In the Map ID details, locate the', 'codepeople-post-map' ); ?> <strong>"Style"</strong> <?php esc_html_e( 'or', 'codepeople-post-map' ); ?> <strong>"Associated Style"</strong> <?php esc_html_e( 'section and click', 'codepeople-post-map' ); ?> <strong>"Edit."</strong></li>
669 <li><?php esc_html_e( 'Choose your desired map style from the dropdown or list.', 'codepeople-post-map' ); ?></li>
670 <li><?php esc_html_e( 'Save the changes.', 'codepeople-post-map' ); ?></li>
671 </ul>
672 </li>
673 <li>
674 <strong><?php esc_html_e( 'Using it in your website:', 'codepeople-post-map' ); ?></strong>
675 <ul style="list-style:disc;margin-left:20px;">
676 <li><?php esc_html_e( 'Pass the', 'codepeople-post-map' ); ?> <strong>"Map ID"</strong> <?php esc_html_e( 'through the map shortcode:', 'codepeople-post-map' ); ?>
677 <p><strong style="font-size:1.3em;">[codepeople-post-map mapid="1234567890"]</strong></p>
678 </li>
679 </ul>
680 </li>
681 </ol>
682 </td>
683 </tr>
684 <tr class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
685 <th scope="row"><label for="cpm_map_legend" style="color:#CCCCCC;"><?php _e("Display the map's legend:", 'codepeople-post-map');?></label></th>
686 <td valign="top">
687 <input type="checkbox" disabled readonly /> <span style="color:#FF0000;">This feature is available only in commercial version of plugin. <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download">Click Here</a></span>
688 </td>
689 </tr>
690 <tr class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
691 <th scope="row"><label for="cpm_map_legend_taxonomy" style="color:#CCCCCC;"><?php _e('Select the taxonomy to display on legend:', 'codepeople-post-map'); ?></label></th>
692 <td valign="top">
693 <select disabled readonly>
694 <option value=""><?php _e( 'Select a taxonomy', 'codepeople-post-map' ); ?></option>
695 </select>
696 </td>
697 </tr>
698 <tr class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
699 <th scope="row"><label for="cpm_map_legend_title" style="color:#CCCCCC;"><?php _e('Enter a title for legend:', 'codepeople-post-map'); ?></label></th>
700 <td valign="top">
701 <input type="text" disabled readonly />
702 </td>
703 </tr>
704 <tr class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
705 <th scope="row"><label for="cpm_map_legend_class" style="color:#CCCCCC;"><?php _e('Enter a classname to be applied to the legend:', 'codepeople-post-map'); ?></label></th>
706 <td valign="top">
707 <input type="text" disabled readonly />
708 </td>
709 </tr>
710
711 </table>
712 <?php
713 } // End _deploy_map_form
714
715 /**
716 * Private method to print Maps form
717 */
718 function _print_form($options){
719 global $post;
720 $default_configuration = $this->_default_configuration();
721
722 // create a custom nonce for submit verification later
723 echo '<input type="hidden" name="cpm_map_noncename" value="' . wp_create_nonce(__FILE__) . '" />';
724 ?>
725 <script>
726 var cpm_default_marker = <?php echo wp_json_encode( $default_configuration['default_icon'] ); ?>;
727 var cpm_point = {};
728
729 <?php
730 if(!empty($options['address']) || (!empty($options['latitude']) && !empty($options['longitude']))){
731 if(!empty($options['address'])) echo 'cpm_point["address"]=' . wp_json_encode( $options['address'] ) . ';';
732 if(!empty($options['latitude']) && !empty($options['longitude'])){
733 echo 'cpm_point["latitude"]=' . wp_json_encode( $options['latitude'] ) . ';';
734 echo 'cpm_point["longitude"]=' . wp_json_encode( $options['longitude'] ) . ';';
735 }
736
737 } else {
738 echo 'cpm_point["address"]=' . wp_json_encode( 'Statue of Liberty, Statue of Liberty National Monument, Statue Of Liberty, New York, NY 10004, USA' ) . ';';
739 echo 'cpm_point["latitude"]=' . wp_json_encode( '40.689848' ) . ';';
740 echo 'cpm_point["longitude"]=' . wp_json_encode( '-74.044869' ) . ';';
741 }
742 ?>
743
744 </script>
745 <p style="font-weight:bold;"><?php _e('For more information go to the <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map" target="_blank">CodePeople Post Map</a> plugin page', 'codepeople-post-map'); ?></p>
746 <p style="border:1px solid #E6DB55;margin-bottom:10px;padding:5px;background-color: #FFFFE0;"><?php _e('For any issues with the map, go to our <a href="http://wordpress.dwbooster.com/contact-us" target="_blank">contact page</a> and leave us a message.', 'codepeople-post-map'); ?></p>
747 <p>
748 <?php _e( 'To insert a map in the post follow the steps below', 'codepeople-post-map');?>:
749 </p>
750 <ol>
751 <li><?php _e( 'Enter the point\'s information (the latitude and longitude are required, but are obtained pressing the "verify" button after type the address', 'codepeople-post-map' );?></li>
752 <li><?php _e('Insert the shortcode in the post\'s content pressing the "insert the map tag" button', 'codepeople-post-map');?></li>
753 <li><?php _e('If you want to use specific settings just for this map, tick the checkbox "Use particular settings for this map", and then, modify the map\'s attributes', 'codepeople-post-map'); ?></li>
754 <li><?php _e( 'Don\'t forget to press the "Update" button for save the post and map data', 'codepeople-post-map');?></li>
755 </ol>
756 <div class="cpm_error_mssg"></div>
757 <div style="border:1px solid #CCC;margin-bottom:10px;min-height:60px; padding:5px;">
758 <h3><?php _e('Map points', 'codepeople-post-map'); ?></h3>
759 <div id="points_container" style="padding:10px;">
760 <?php _e('Multiple points in the same Post/Page are available only in the <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download" target="_blank">advanced version</a>.', 'codepeople-post-map'); ?>
761 </div>
762 </div>
763 <div class="point_form" style="border:1px solid #CCC; padding:5px;">
764 <h3><?php _e('Map point description', 'codepeople-post-map'); ?></h3>
765 <table class="form-table cpm-settings">
766 <tr valign="top">
767 <th scope="row"><label for="cpm_name"><?php _e('Location name:', 'codepeople-post-map');?></label></th>
768 <td>
769 <input type="text" size="40" style="width:95%;" name="cpm_point[name]" id="cpm_point_name" value="<?php esc_attr_e((isset($options['name'])) ? $options['name'] : '');?>" />
770 </td>
771 </tr>
772 <tr valign="top">
773 <th scope="row"><label for="cpm_point_description"><?php _e('Location description:', 'codepeople-post-map');?></label></th>
774 <td>
775 <input type="text" size="40" style="width:95%;" name="cpm_point[description]" id="cpm_point_description" value="<?php esc_attr_e((isset($options['description'])) ? $options['description'] : '');?>" />
776 <br />
777 <em>It is possible to insert a link to another page in the infowindow associated to the point. Type the link tag to the other page in the point description box, similar to: <span style="white-space:nowrap;"><strong>&lt;a href="http://wordpress.dwbooster.com" &gt;CLICK HERE &lt;/a&gt;</strong></span></em>
778 </td>
779 </tr>
780 <tr valign="top">
781 <th scope="row">
782 <?php _e("Select an image to attach to the point: ","codepeople-post-map"); ?>
783 </th>
784 <td>
785 <input type="text" name="cpm_point[thumbnail]" value="<?php if(isset($options["thumbnail"])){ esc_attr_e($options["thumbnail"]);} ?>" id="cpm_point_thumbnail" />
786 <input class="button" type="button" value="Upload Images" onclick="cpm_thumbnail_selection(this);" />
787 </td>
788 </tr>
789 <tr valign="top">
790 <td colspan="2">
791 <table>
792 <tr valign="top">
793 <td>
794 <span style="font-weight:bold;">Address, latitude and longitude are required fields.</span>
795 <table>
796 <tr valign="top">
797 <th scope="row"><label for="cpm_point_address"><?php _e('Address:', 'codepeople-post-map');?></label></th>
798 <td width="100%">
799 <input type="text" style="width:100%;" name="cpm_point[address]" id="cpm_point_address" value="<?php esc_attr_e((isset($options['address'])) ? $options['address'] : '');?>" />
800 </td>
801 </tr>
802 <tr valign="top">
803 <th scope="row"><label for="cpm_point_latitude"><?php _e('Latitude:', 'codepeople-post-map');?></label></th>
804 <td>
805 <input type="text" style="width:100%;" name="cpm_point[latitude]" id="cpm_point_latitude" value="<?php esc_attr_e((isset($options['latitude'])) ? $options['latitude'] : '');?>" />
806 </td>
807 </tr>
808 <tr valign="top">
809 <th scope="row"><label for="cpm_point_longitude"><?php _e('Longitude:', 'codepeople-post-map');?></label></th>
810 <td>
811 <input type="text" style="width:100%;" name="cpm_point[longitude]" id="cpm_point_longitude" value="<?php esc_attr_e((isset($options['longitude'])) ? $options['longitude'] : '');?>" />
812 </td>
813 </tr>
814 <tr valign="top">
815 <th scope="row" style="text-align:right;"><p class="submit"><input type="button" name="cpm_point_verify" id="cpm_point_verify" value="<?php esc_attr_e(__('Verify', 'codepeople-post-map')); ?>" onclick="cpm_checking_point(this);" /></p></th>
816 <td>
817 <label for="cpm_point_verify"><?php _e('Verify this latitude and longitude using Geocoding. This could overwrite the point address.', 'codepeople-post-map');?><span style="color:#FF0000">(<?php _e('Required: Press the button "verify" after complete the address.', 'codepeople-post-map'); ?>)</span></label>
818 </td>
819 </tr>
820 </table>
821 </td>
822 <td width="50%" style="vertical-align:top;">
823 <div id="cpm_map_container" class="cpm_map_container" style="height:250px; border:1px dotted #CCC;">
824 </div>
825 </td>
826 </tr>
827 </table>
828 </td>
829 </tr>
830 <tr valign="top">
831 <td colspan="2">
832 <?php $this->_deploy_icons($options); ?>
833 </td>
834 </tr>
835 </table>
836 </div>
837 <div style="border:1px solid #CCC; padding:10px; margin:10px 0;">
838 <p class="cpm-classic-editor">
839 <?php
840 _e( 'To insert this map in a post/page, press the <strong>"insert the map tag"</strong> button and save the post/page modifications.', 'codepeople-post-map' );
841 ?>
842 </p>
843 <div style="border:1px solid #CCC; padding:10px; padding:5px;">
844 <p style="color:#CCC;">
845 <input type="checkbox" DISABLED />
846 <?php
847 _e( 'Do you want display a <strong>shape</strong> on map?', 'codepeople-post-map' );
848 ?>
849 <br /><span style="color:#FF0000;"><?php _e( 'The feature is available only for the commercial version of plugin. <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download">Click Here</a>', 'codepeople-post-map' ); ?></span>
850 </p>
851 </div>
852 <table class="form-table cpm-settings">
853 <tr valign="top">
854 <td scope="row" valign="top" style="vertical-align:top;width:350px;" class="cpm-classic-editor">
855 <label><?php _e('If you want to display the map in page / post:', 'codepeople-post-map');?></label><br />
856 <input type="button" class="button-primary" name="cpm_map_shortcode" id="cpm_map_shortcode" value="<?php esc_attr_e(__('Insert the map tag', 'codepeople-post-map')); ?>" style="height:40px; padding-left:30px; padding-right:30px; font-size:1.5em;" /><br />
857 <span class="cpm_more_info_hndl cpm_blink_me" style="margin-left: 10px;"><a href="javascript:void(0);" onclick="cpm_display_more_info( this );">[ + more information]</a></span>
858 <div class="cpm_more_info">
859 <?php _e('<p>It is possible to use attributes in the shortcode, like: width, height, zoom and the other maps attributes:</p>
860 <p><strong>[codepeople-post-map width="450" height="500"]</strong></p>
861 <p>The premium version of plugin allows to use a special attribute "cat" (referent to category), to display all points created in a category:</p>
862 <p><strong>[codepeople-post-map cat="35"]</strong><br/>Note: the number 35 correspond to the ID of category.</p>
863 <p>or all points on website, using as category ID the value "-1"</p>
864 <p><strong>[codepeople-post-map cat="-1"]</strong></p>
865 <p>The special attribute "tag", allow to display all points that belong to the posts with a specific tag assigned, for example "mytag":</p>
866 <p><strong>[codepeople-post-map tag="mytag"]</strong></p>', 'codepeople-post-map' ); ?>
867 <br />
868 <a href="javascript:void(0)" onclick="cpm_hide_more_info( this );"><?php _e('[ + less information]', 'codepeople-post-map'); ?></a>
869 </div>
870 </td>
871 <td valign="top" class="cpm-gutenberg-editor" style="vertical-align:top;">
872 <label style="color:#CCC;"><?php _e('To display the points that belong to any category','codepeople-post-map');?>:</label><br />
873 <select size="2" multiple="multiple" style="height:48px;width:100%;" disabled>
874 <option value="-1"><?php _e( 'All points on website', 'codepeople-post-map'); ?></option>
875 <?php
876 $categories = get_categories();
877 foreach( $categories as $category )
878 {
879 print '<option value="'.$category->term_id.'">'.$category->name.'</option>';
880 }
881
882 ?>
883 </select>
884 <br /><span style="color:#FF0000;"><?php _e( 'The feature is available only for the commercial version of plugin. <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download">Click Here</a>', 'codepeople-post-map' ); ?></span>
885 </td>
886 </tr>
887 </table>
888 </div>
889 <div id="map_data">
890 <?php $this->_deploy_map_form($options, true); ?>
891 </div>
892 <p>&nbsp;</p>
893 <?php
894 } // End _print_form
895
896 /**
897 * Form for maps insertion and update
898 */
899 function insert_form(){
900 global $post, $wpdb;
901
902 $cpm_point = get_post_meta($post->ID, 'cpm_point', TRUE);
903 if(is_string($cpm_point) && preg_match('/^a:\d+:\{/', $cpm_point)){
904 $tmp = @unserialize($cpm_point, array('allowed_classes' => false));
905 $cpm_point = ( is_array($tmp) ) ? $tmp : array();
906 }elseif(!is_array($cpm_point)){
907 $cpm_point = array();
908 }
909
910 $cpm_map = get_post_meta($post->ID, 'cpm_map', TRUE);
911 $general_options = $this->get_configuration_option();
912 $options = array_merge((array)$general_options, (array)$cpm_point, (array)$cpm_map);
913 $options['post_id'] = $post->ID;
914 $this->_print_form($options);
915 } // End insert_form
916
917 //---------- LOADING RESOURCES ----------
918
919 /*
920 * Load the required scripts and styles for ADMIN section of website
921 */
922 function load_admin_resources(){
923 wp_enqueue_style(
924 'admin_cpm_style',
925 CPM_PLUGIN_URL.'/styles/cpm-admin-styles.css'
926 );
927
928 wp_enqueue_script(
929 'admin_cpm_script',
930 CPM_PLUGIN_URL.'/js/cpm.admin.js',
931 array('jquery'),
932 null,
933 true
934 );
935
936 $cpm_global = array();
937 $api_key = $this->get_configuration_option( 'api_key' );
938 if( !empty( $api_key ) )
939 {
940 $cpm_global[ 'api_key' ] = trim($api_key);
941 }
942 wp_localize_script('admin_cpm_script', 'cpm_global', $cpm_global);
943 } // End load_admin_resources
944
945 /**
946 * Loads the scripts required to integrate the plugin with the Gutenberg Editor.
947 */
948 function load_gutenberg_code(){
949 global $post;
950 wp_enqueue_style('cpm-admin-gutenberg-editor-css', CPM_PLUGIN_URL.'/styles/cpm-gutenberg.css');
951
952 if(!empty($post)) $url = get_preview_post_link($post->ID);
953 else $url = rtrim( get_home_url( get_current_blog_id() ), "/" ).( ( strpos( get_current_blog_id(), '?' ) === false ) ? "/" : "" );
954
955 $nonce = !empty($post) ? wp_create_nonce('cpm-preview-'.$post->ID) : '';
956 $url .= ((strpos($url, '?') === false) ? '?' : '&') . 'cpm_preview_nonce=' . urlencode($nonce) .'&cpm-preview=';
957
958 $config = array('url' => $url);
959 wp_enqueue_script('cpm-gutenberg-editor', CPM_PLUGIN_URL.'/js/gutenberg.js');
960 wp_localize_script('cpm-gutenberg-editor', 'cpm_ge_config', $config);
961 } // End load_gutenberg_code
962
963 /**
964 * Load script and style files required for display google maps on public website
965 */
966 function load_resources() {
967 global $cpm_resources_loaded;
968 if( !is_admin() && empty( $cpm_resources_loaded ) )
969 {
970 $cpm_resources_loaded = true;
971
972 if(get_option('cpm_load_resources_in_footer', false))
973 {
974 wp_enqueue_script('jquery');
975 wp_enqueue_style('cpm_style_css', CPM_PLUGIN_URL.'/styles/cpm-styles.css');
976 wp_enqueue_script('cpm_public_js', CPM_PLUGIN_URL.'/js/cpm.js', array('jquery'), 'pro', true);
977 }
978 else
979 {
980 if( !wp_script_is( 'jquery' ) )
981 {
982 print "<script src='".(is_ssl() ? "https" : "http")."://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>";
983 }
984
985 print "<link rel='stylesheet' id='cpm_style-css' href='".CPM_PLUGIN_URL.'/styles/cpm-styles.css'."' type='text/css' media='all' />";
986 print "<script src='".CPM_PLUGIN_URL.'/js/cpm.js'."'></script>";
987 }
988 }
989 } // End load_resources
990
991 function load_header_resources(){
992 echo '<style>.cpm-map img{ max-width: none !important;box-shadow:none !important;}</style>';
993 } // End load_header_resources
994
995 /**
996 * Print the settings page for entering the general setting's data of maps
997 */
998 function settings_page(){
999 if (isset($_GET["page"]))
1000 {
1001 if( $_GET["page"] == 'google_maps_cp_upgrade' )
1002 {
1003 echo("Redirecting to upgrade page...<script type='text/javascript'>document.location='http://wordpress.dwbooster.com/content-tools/codepeople-post-map?acode=18517#download';</script>");
1004 exit;
1005 }
1006 elseif( $_GET["page"] == 'google_maps_cp_help')
1007 {
1008 echo("Redirecting to documentation...<script type='text/javascript'>document.location='http://wordpress.dwbooster.com/content-tools/codepeople-post-map?acode=18517';</script>");
1009 exit;
1010 }
1011 elseif( $_GET["page"] == 'google_maps_cp_question')
1012 {
1013 echo("Redirecting to documentation...<script type='text/javascript'>document.location='https://wordpress.org/support/plugin/codepeople-post-map/#new-post';</script>");
1014 exit;
1015 }
1016
1017 }
1018
1019 // Check if post exists and save the configuraton options
1020 if (isset($_POST['cpm_map_noncename']) && wp_verify_nonce($_POST['cpm_map_noncename'],__FILE__)){
1021 $options = $_POST['cpm_map'];
1022 $options = $this->array_map_recursive('sanitize_text_field', $options);
1023 $options['drag_map'] = ( isset( $options[ 'drag_map' ] ) ) ? true : false;
1024 $options['windowhtml'] = $this->get_configuration_option('windowhtml');
1025 update_option('cpm_config', $options);
1026 update_option('cpm_load_resources_in_footer', (isset($_POST['cpm_load_resources_in_footer'])) ? true : false);
1027 echo '<div class="updated"><p><strong>'.__("Settings Updated", 'codepeople-post-map').'</strong></div>';
1028 }else{
1029 $options = $this->get_configuration_option();
1030 }
1031
1032 ?>
1033 <div class="wrap">
1034 <form method="post">
1035 <?php
1036 $this->_deploy_map_form($options);
1037 ?>
1038 <table class="form-table cpm-settings">
1039 <tr valign="top">
1040 <th scope="row" style="color:#CCCCCC;"><label for="cpm_map_exif_information"><?php _e('Generate points dynamically from geolocation information included on images, when images are uploaded to WordPress:', 'codepeople-post-map'); ?></label></th>
1041 <td>
1042 <input type="checkbox" DISABLED />
1043 <?php _e('The geolocation information is added to the images from your mobiles or cameras, if they have associated GPS devices', 'codepeople-post-map');?>
1044 <br /><br />
1045 <a class="button" href="javascript:void(0);"><?php _e( 'Process All Previous Images', 'codepeople-post-map' ); ?></a><br><br>
1046 <?php _e('Process all images in the library, and generates new points in the parents pages, with the geocode information in the images metadata. A post/page is the parent of an image, if the image was uploaded to the library from the post/page.', 'codepeople-post-map');?><br />
1047 <span style="color:#FF0000;"><?php _e('The free version of CodePeople Post Map allows only one map by webpage.','codepeople-post-map'); ?> <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download"><?php _e('Click Here', 'codepeople-post-map');?></a></span>
1048 </td>
1049 </tr>
1050
1051 <tr valign="top">
1052 <th scope="row" style="color:#CCCCCC;"><label for="cpm_map_geolocation_information"><?php _e('Generate points dynamically from geolocation information included on posts:', 'codepeople-post-map'); ?></label></th>
1053 <td>
1054 <input type="checkbox" DISABLED />
1055 <?php _e('The geolocation information is added to the post from WordPress app in your mobile', 'codepeople-post-map');?>
1056 <br />
1057 <span style="color:#FF0000;"><?php _e('The free version of CodePeople Post Map allows only one map by webpage.', 'codepeople-post-map'); ?> <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download"><?php _e('Click Here', 'codepeople-post-map'); ?></a></span>
1058 </td>
1059 </tr>
1060
1061 <tr valign="top">
1062 <th scope="row"><label for="cpm_map_search" style="color:#CCCCCC;"><?php _e('Use points information in search results:', 'codepeople-post-map'); ?></label></th>
1063 <td>
1064 <input type="checkbox" name="cpm_map[search]" id="cpm_map_search" value="true" disabled /> <span style="color:#FF0000;"><?php _e('The search in the maps data is available only in commercial version of plugin.','codepeople-post-map'); ?> <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download"><?php _e('Click Here', 'codepeople-post-map'); ?></a></span>
1065 </td>
1066 </tr>
1067 <tr valign="top">
1068 <th scope="row"><label for="cpm_map_highlight" style="color:#CCCCCC;"><?php _e('Highlight post when mouse move over related point on map:', 'codepeople-post-map'); ?></label></th>
1069 <td>
1070 <input type="checkbox" name="cpm_map[highlight]" id="cpm_map_highlight" value="true" disabled /> <span style="color:#FF0000;"><?php _e('The post highlight is available only in commercial version of plugin.', 'codepeople-post-map'); ?> <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download"><?php _e('Click Here', 'codepeople-post-map'); ?></a></span>
1071 </td>
1072 </tr>
1073 <tr valign="top">
1074 <th scope="row"><label for="cpm_map_highlight_class" style="color:#CCCCCC;"><?php _e('Highlight class:', 'codepeople-post-map'); ?></label></th>
1075 <td>
1076 <input type="text" name="cpm_map[highlight_class]" id="cpm_map_highlight_class" disabled /><span style="color:#FF0000;"><?php _e('The highlight class is available only in commercial version of plugin.', 'codepeople-post-map');?> <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download"><?php _e('Click Here', 'codepeople-post-map'); ?></a></span>
1077 </td>
1078 </tr>
1079 <tr valign="top">
1080 <th scope="row"><label for="cpm_map_post_type" style="color:#CCCCCC;"><?php _e('Allow to associate a map to the post types:', 'codepeople-post-map'); ?></label></th>
1081 <td valign="top">
1082 <?php
1083 $post_types = get_post_types(array('public' => true), 'names');
1084 print '<i>' . __('Posts and Pages are selected by default', 'codepeople-post-map') . '.</i><br>';
1085 ?>
1086 <select multiple size="3" DISABLED >
1087 <?php
1088 foreach($post_types as $post_type){
1089 print '<option value="'.esc_attr($post_type).'" >'.$post_type.'</option>';
1090 }
1091 ?>
1092 </select>
1093 <br />
1094 <span style="color:#FF0000;"><?php _e('Associate the maps to custom post types is available only in commercial version of plugin.', 'codepeople-post-map'); ?> <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map#download"><?php _e('Click Here', 'codepeople-post-map'); ?></a></span>
1095 </td>
1096 </tr>
1097 </table>
1098 <table cellpadding="10" cellspacing="10" width="500px">
1099 <tr valign="top">
1100 <td align="center" width="30%">
1101 <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map" target="_blank">
1102 <img src="<?php echo(CPM_PLUGIN_URL.'/images/routes.jpg'); ?>" width="100px" height="100px" class="cpm_thumbnail_admin" style="border:1px solid #AAA;" />
1103 </a>
1104 <br /><?php _e('Draws Routes', 'codepeople-post-map'); ?>
1105 </td>
1106 <td align="center">
1107 <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map" target="_blank">
1108 <img src="<?php echo(CPM_PLUGIN_URL.'/images/custom_post_type.jpg'); ?>" width="100px" height="100px" class="cpm_thumbnail_admin" style="border:1px solid #AAA;" />
1109 </a>
1110 <br /><?php _e('Associate maps to custom post types', 'codepeople-post-map'); ?>
1111 </td>
1112 <td align="center" width="30%">
1113 <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map" target="_blank">
1114 <img src="<?php echo(CPM_PLUGIN_URL.'/images/multiple.jpg'); ?>" width="100px" height="100px" class="cpm_thumbnail_admin" style="border:1px solid #AAA;" />
1115 </a>
1116 <br/><?php _e('Display a map for each post in pages with multiple posts', 'codepeople-post-map'); ?>
1117 </td>
1118 </tr>
1119 </table>
1120 <?php
1121 if ( defined( 'ICL_SITEPRESS_VERSION' ) ):
1122 ?>
1123 <div id="metabox_basic_settings" class="postbox" >
1124 <h3 class="hndle" style="padding:5px;"><span><?php _e( 'WPML Related Section', 'codepeople-post-map' ); ?></span></h3>
1125 <div class="inside">
1126 <label style="margin-right:20px;"><input type="radio" name="cpm_map[wpml]" value="all" <?php if ( ! isset( $options['wpml'] ) || 'all' == $options['wpml']) print 'CHECKED'; ?>> <?php esc_html_e( 'Load all points, no matter the website language' ); ?></label>
1127 <label><input type="radio" name="cpm_map[wpml]" value="some" <?php if ( isset( $options['wpml'] ) && 'some' == $options['wpml']) print 'CHECKED'; ?>> <?php esc_html_e( 'Load only the points in posts/pages in the active website language' ); ?></label>
1128 </div>
1129 </div>
1130 <?php
1131 endif;
1132 ?>
1133 <div id="metabox_basic_settings" class="postbox" >
1134 <h3 class="hndle" style="padding:5px;"><span><?php _e( 'Troubleshoot Section', 'codepeople-post-map' ); ?></span></h3>
1135 <div class="inside">
1136 <table class="form-table cpm-settings">
1137 <tr>
1138 <td>
1139 <input type="checkbox" name="cpm_load_resources_in_footer" <?php echo (get_option('cpm_load_resources_in_footer', false)) ? 'checked' : ''; ?> /> <?php _e( 'Load required resources (javascript files) in footer','codepeople-post-map'); ?>
1140 </td>
1141 </tr>
1142 </table>
1143 </div>
1144 </div>
1145 <script>
1146 jQuery(function(){
1147 jQuery('.cpm_thumbnail_admin').on('mouseover',function(){jQuery(this).width(300).height(300);}).on('mouseout',function(){jQuery(this).width(100).height(100);});
1148 });
1149 </script>
1150 <p style="font-weight:bold;"><?php _e('For more information go to the <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map" target="_blank">CodePeople Post Map</a> plugin page', 'codepeople-post-map'); ?></p>
1151 <div class="submit"><input type="submit" class="button-primary" value="<?php esc_attr_e(__('Update Settings', 'codepeople-post-map'));?>" /></div>
1152 <?php
1153 // create a custom nonce for submit verification later
1154 echo '<input type="hidden" name="cpm_map_noncename" value="' . wp_create_nonce(__FILE__) . '" />';
1155 ?>
1156 </form>
1157 </div>
1158 <?php
1159 } // End settings_page
1160
1161 //---------- SHORTCODE METHODS ----------
1162
1163 /*
1164 * Populate the attribute points
1165 */
1166 function populate_points($post_id){
1167 if( is_admin() ) return;
1168
1169 $point = get_post_meta($post_id, 'cpm_point', TRUE);
1170 if(!empty($point)){
1171 if(is_string($point) && preg_match('/^a:\d+:\{/', $point))
1172 {
1173 $tmp_point = @unserialize($point, array('allowed_classes' => false));
1174 $point = ( is_array($tmp_point) ) ? $tmp_point : array( 'address' => $point );
1175 }
1176
1177 if( !is_array( $point ) )
1178 {
1179 $point = array( 'address' => $point );
1180 }
1181 $point['post_id'] = $post_id;
1182 if(!in_array($point, $this->points)){
1183 $this->points[] = $point;
1184 }
1185 }
1186 else
1187 {
1188 $latitude = apply_filters('cpm-post-latitude', '', $post_id);
1189 $longitude = apply_filters('cpm-post-longitude', '', $post_id);
1190 $address = apply_filters('cpm-post-address', '', $post_id);
1191
1192 if( (!empty( $latitude ) && !empty( $longitude )) || !empty($address))
1193 {
1194 $point = array();
1195 if(!empty( $latitude ) && !empty( $longitude ))
1196 {
1197 $point['latitude'] = $latitude;
1198 $point['longitude'] = $longitude;
1199 }
1200 if(!empty( $address ))
1201 {
1202 $point['address'] = $address;
1203 }
1204 $point['post_id'] = $post_id;
1205 if(!in_array($point, $this->points)){
1206 $this->points[] = apply_filters('cpm-point', $point);
1207 }
1208 }
1209 }
1210 } // End populate_points
1211
1212 /*
1213 * Generates the javascript code of map points, only called from webpage of multiples posts
1214 */
1215 function print_points(){
1216 global $id;
1217
1218 $limit = abs($this->limit);
1219
1220 $str = '';
1221 $current_post = '';
1222 $count_posts = 0;
1223 $count_points = 0;
1224
1225 foreach($this->points as $point){
1226 if(!empty($limit)){
1227 if($current_post != $point['post_id']){
1228 $current_post = $point['post_id'];
1229 $count_posts++;
1230 if( $count_posts > $limit) break;
1231 if( !empty($this->defaultpost) && $this->defaultpost == $current_post )
1232 {
1233 $point[ 'default' ] = 1;
1234 $this->defaultpost = '';
1235 }
1236 }
1237 }
1238
1239 $str .= $this->_set_map_point($point, $count_points);
1240 $count_points++;
1241 }
1242 if(strlen($str))
1243 {
1244 $map_id_json = wp_json_encode( $this->map_id );
1245 $str = '<script>if(typeof cpm_global != \'undefined\' && typeof cpm_global[' . $map_id_json . '] != \'undefined\' && typeof cpm_global[' . $map_id_json . '][\'markers\'] != \'undefined\'){ ' . $str . ' }</script>';
1246 }
1247
1248 $this->points = array();
1249 print $str;
1250 } // End print_points
1251
1252 /**
1253 * Replace each [codepeople-post-map] shortcode by the map
1254 */
1255 function replace_shortcode($atts){
1256 if(defined( 'REST_REQUEST' )) return;
1257 global $post, $id, $cpm_objs, $cpm_in_loop;
1258
1259 // Load the plugin resources
1260 $this->load_resources();
1261
1262 $cpm_obj = new CPM;
1263 $cpm_objs[] = $cpm_obj;
1264
1265 if(is_array($atts)) $cpm_obj->extended = $atts;
1266
1267 if( !empty( $atts[ 'defaultpost' ] ) ) $cpm_obj->defaultpost = str_replace( ' ', '', $atts[ 'defaultpost' ] );
1268
1269 if( isset($id) && ( is_singular() || !empty( $cpm_in_loop ) ) ){
1270 $cpm_map = get_post_meta($id, 'cpm_map', TRUE);
1271 }
1272
1273 if(empty($cpm_map)){
1274 $cpm_map = $cpm_obj->get_configuration_option();
1275 }
1276
1277 if( ! empty($atts['mapid']) ) $cpm_map['mapid'] = trim( $atts['mapid'] );
1278
1279 if(!empty($cpm_map['points'])){
1280 $cpm_obj->limit = $cpm_map['points'];
1281 }
1282
1283 if( !empty( $atts[ 'points' ] ) )
1284 {
1285 $atts[ 'points' ] = trim( $atts[ 'points' ] );
1286 if( is_numeric( $atts[ 'points' ] ) && $atts[ 'points' ] > 0 ) $cpm_obj->limit = $atts[ 'points' ];
1287 }
1288
1289 $cpm_map[ 'tooltip' ] = $this->get_configuration_option('tooltip');
1290
1291 if( isset( $atts[ 'tooltip' ] ) )
1292 {
1293 $cpm_map[ 'tooltip' ] = trim($atts[ 'tooltip' ]);
1294 }
1295
1296 if( isset($id) && ( is_singular() || !empty( $cpm_in_loop ) ) ){ // For maps in a post or page
1297 // Set the actual post only to avoid duplicates
1298 $posts = array( $id );
1299
1300 $query_arg = array(
1301 'meta_query' => array(
1302 'relation' => 'OR',
1303 array(
1304 'key' => 'cpm_point'
1305 ),
1306 ),
1307 'post_status' => 'publish',
1308 'orderby' => 'post_date',
1309 'order' => 'DESC',
1310 'cache_results' => false,
1311 'fields' => 'ids',
1312 'post__not_in' => array( $id )
1313 );
1314
1315 /*
1316 * If the latitude and longitude or address is stored into custom fields,
1317 * it is possible to include them in the selector query
1318 * function custom_complete_query_structure($query_components)
1319 * {
1320 * $query_components[] = array(
1321 * 'key' => 'custom_address'
1322 * );
1323 * return $query_components;
1324 * }
1325 * add_filter('cpm-complete-structured-query', 'custom_complete_query_structure');
1326 */
1327 $query_arg['meta_query'] = apply_filters('cpm-complete-structured-query', $query_arg['meta_query']);
1328
1329 if( !empty($cpm_obj->limit) ){
1330 $query_arg[ 'numberposts' ] = $cpm_obj->limit - 1;
1331 }
1332
1333 // Get POSTs in the same category
1334 $categories = get_the_category();
1335 $categories_ids = array();
1336 foreach($categories as $category){
1337 array_push( $categories_ids, $category->term_id);
1338 }
1339
1340 if( !empty( $categories_ids ) ){
1341 $query_arg[ 'category' ] = implode( ',', $categories_ids );
1342 }
1343
1344 $posts = array_merge( $posts, get_posts( $query_arg ) );
1345
1346 // WMPL
1347 $wpml_option = $this->get_configuration_option( 'wpml' );
1348 if(function_exists( 'icl_object_id' )) $current_lang = apply_filters( 'wpml_current_language', NULL );
1349
1350 foreach( $posts as $_post){
1351 if(function_exists( 'icl_object_id' )) {
1352 $post_language_information = apply_filters( 'wpml_post_language_details', NULL, $_post );
1353 $language = $post_language_information["language_code"];
1354 if(
1355 $language != $current_lang &&
1356 ! empty( $wpml_option ) &&
1357 'some' == $wpml_option
1358 ) continue;
1359 }
1360 $cpm_obj->populate_points($_post);
1361 }
1362
1363 }else{
1364 $cpm_obj->multiple = true;
1365 }
1366
1367 $output = $cpm_obj->_set_map_tag($cpm_map);
1368 $output .= $cpm_obj->_set_map_config($cpm_map);
1369
1370 $output .= "<noscript>
1371 codepeople-post-map require JavaScript
1372 </noscript>
1373 ";
1374
1375 if( !empty( $atts['print'] ) ){
1376 print $output;
1377 $cpm_obj->print_points();
1378 return '';
1379 }
1380
1381 return $output;
1382 } // End replace_shortcode
1383
1384 function preview()
1385 {
1386 $user = wp_get_current_user();
1387 $allowed_roles = array('editor', 'administrator', 'author');
1388
1389 if(array_intersect($allowed_roles, $user->roles ))
1390 {
1391 if(
1392 !empty($_REQUEST['cpm-preview']) &&
1393 !empty($_REQUEST['post-id']) &&
1394 ($post_id = @intval($_REQUEST['post-id'])) !== 0
1395 )
1396 {
1397 // Nonce verification
1398 if (!isset($_REQUEST['cpm_preview_nonce']) ||
1399 !wp_verify_nonce(
1400 sanitize_text_field(wp_unslash($_REQUEST['cpm_preview_nonce'])),
1401 'cpm-preview-'.$post_id
1402 )) {
1403 return;
1404 }
1405
1406 // Object-level capability check
1407 if (!current_user_can('read_post', $post_id)) {
1408 return;
1409 }
1410
1411 // Sanitizing variable
1412 $preview = sanitize_text_field(wp_unslash($_REQUEST['cpm-preview']));
1413
1414 // Remove every shortcode that is not in the music store list
1415 remove_all_shortcodes();
1416 add_shortcode('codepeople-post-map', array(&$this, 'replace_shortcode'));
1417 get_post($post_id);
1418
1419 if(has_shortcode($preview, 'codepeople-post-map'))
1420 {
1421 // To indicate in the replace_shortcode that should be used the particular settings.
1422 global $id, $cpm_in_loop;
1423 $id = $post_id;
1424 $cpm_in_loop = true;
1425
1426 // Includes the print attribute in the shortcode
1427 $preview = preg_replace('/(\[codepeople\-post\-map)/i', '$1 print="1" ', $preview);
1428 wp_head();
1429 print '<div class="cpm-preview-container">'.do_shortcode($preview).'</div>';
1430
1431 if(
1432 function_exists('wp_print_styles') &&
1433 function_exists('wp_print_scripts')
1434 )
1435 {
1436 wp_print_styles();
1437 wp_print_scripts();
1438 }
1439 else
1440 {
1441 wp_footer();
1442 }
1443 print'<script type="text/javascript">jQuery(window).on("load", function(){
1444 var frameEl = window.frameElement,
1445 interval_id,
1446 counter = 10;
1447 if(frameEl) {
1448 interval_id = setInterval(function(){
1449 if( counter <= 0) clearInterval(interval_id);
1450 counter--;
1451 var cpm = jQuery(".cpm-map:visible");
1452 if(cpm.length) {
1453 clearInterval(interval_id);
1454 frameEl.height = cpm.outerHeight(true)+5;
1455 }
1456 }, 1000);
1457 }
1458 });</script>';
1459 exit;
1460 }
1461 }
1462 }
1463 } // End preview
1464
1465 /*
1466 * Generates the DIV tag where the map will be loaded
1467 */
1468 function _set_map_tag($atts){
1469 $atts = array_merge($atts, $this->extended);
1470 extract($atts, EXTR_SKIP);
1471
1472 if(isset($width))
1473 {
1474 $width = trim($width);
1475 if(is_numeric($width)) $width .= 'px';
1476 }
1477 else $width = '100%';
1478
1479 if(isset($height))
1480 {
1481 $height = trim($height);
1482 if(is_numeric($height)) $height .= 'px';
1483 }
1484 else $height = '500px';
1485
1486 $output ='<div id="' . esc_attr( $this->map_id ) . '" data-mapid="' . esc_attr( ! empty( $atts['mapid'] ) ? $atts['mapid'] : '' ). '" class="cpm-map" style="display:none; width:'.esc_attr($width).'; height:'.esc_attr($height).'; ';
1487
1488 if(!isset($align)) $align = 'center';
1489 if(!isset($margin)) $margin = 0;
1490
1491 switch ($align) {
1492 case "left" :
1493 $output .= 'float:left; margin:'.esc_attr($margin).'px;"';
1494 break;
1495 case "right" :
1496 $output .= 'float:right; margin:'.esc_attr($margin).'px;"';
1497 break;
1498 case "center" :
1499 default:
1500 $output .= 'clear:both; overflow:hidden; margin:'.esc_attr($margin).'px auto;"';
1501 break;
1502 }
1503 $output .= "></div>";
1504 return $output;
1505 } // End _set_map_tag
1506
1507 /*
1508 * Generates the javascript tag with map configuration
1509 */
1510 function _set_map_config($atts){
1511 $atts = array_merge($atts, $this->extended);
1512
1513 extract($atts, EXTR_SKIP);
1514
1515 if(!isset($display)) $display = 'map';
1516 if(!isset($type)) $type = 'ROADMAP';
1517
1518 $default_language = $this->get_configuration_option('language');
1519 $map_id_json = wp_json_encode( $this->map_id );
1520 $output = "<script type=\"text/javascript\">\n";
1521
1522 if(isset($language))
1523 $output .= 'var cpm_language = {"lng":' . wp_json_encode( $language ) . '};';
1524 elseif(isset($default_language))
1525 $output .= 'var cpm_language = {"lng":' . wp_json_encode( $default_language ) . '};';
1526
1527 $api_key = $this->get_configuration_option( 'api_key' );
1528 $output .= 'var cpm_api_key = ' . wp_json_encode( (!empty( $api_key )) ? trim($api_key) : '' ) . ";\n";
1529
1530 $output .= "var cpm_global = cpm_global || {};\n";
1531 $output .= "cpm_global[" . $map_id_json . "] = {}; \n";
1532 $output .= "cpm_global[" . $map_id_json . "]['zoom'] = ".((!empty($zoom)) ? @intval($zoom) : $this->_default_configuration('zoom')).";\n";
1533 $output .= "cpm_global[" . $map_id_json . "]['dynamic_zoom'] = ".((isset($dynamic_zoom) && $dynamic_zoom) ? 'true' : 'false').";\n";
1534 $output .= "cpm_global[" . $map_id_json . "]['markers'] = new Array();\n";
1535 $output .= "cpm_global[" . $map_id_json . "]['display'] = " . wp_json_encode( $display ) . ";\n";
1536 $output .= "cpm_global[" . $map_id_json . "]['drag_map'] = ".( ( !isset( $drag_map ) || $drag_map ) ? 'true' : 'false' ).";\n";
1537 $output .= "cpm_global[" . $map_id_json . "]['highlight_class'] = " . wp_json_encode( $this->get_configuration_option('highlight_class') ) . "\n";
1538
1539 if(isset($tooltip))
1540 $output .= "cpm_global[" . $map_id_json . "]['marker_title'] = " . wp_json_encode( $tooltip ) . "\n";
1541
1542 $highlight = $this->get_configuration_option('highlight');
1543 $output .= "cpm_global[" . $map_id_json . "]['highlight'] = ".(($highlight && !is_singular()) ? 'true' : 'false').";\n";
1544 $output .= "cpm_global[" . $map_id_json . "]['type'] = " . wp_json_encode( $type ) . "\n";
1545 $output .= "cpm_global[" . $map_id_json . "]['show_window'] = ".((isset($show_window) && $show_window) ? 'true' : 'false').";\n";
1546 $output .= "cpm_global[" . $map_id_json . "]['show_default'] = ".((isset($show_default) && $show_default) ? 'true' : 'false').";\n";
1547
1548 // Set maps centre
1549 if( !empty( $center ) )
1550 {
1551 $coords = preg_split('/\s*,\s*/', trim($center), 2, PREG_SPLIT_NO_EMPTY);
1552 if(
1553 count($coords) === 2 &&
1554 is_numeric($coords[0]) &&
1555 is_numeric($coords[1])
1556 ){
1557 $output .= "cpm_global[" . $map_id_json . "]['center'] = ["
1558 . floatval($coords[0]) . "," . floatval($coords[1])
1559 . "];\n";
1560 }
1561 }
1562
1563 // Define controls
1564 $output .= "cpm_global[" . $map_id_json . "]['mousewheel'] = ".((isset($mousewheel) && $mousewheel) ? 'true' : 'false').";\n";
1565 $output .= "cpm_global[" . $map_id_json . "]['zoompancontrol'] = ".((isset($zoompancontrol) && $zoompancontrol) ? 'true' : 'false').";\n";
1566 $output .= "cpm_global[" . $map_id_json . "]['fullscreencontrol'] = ".((isset($fullscreencontrol) && $fullscreencontrol) ? 'true' : 'false').";\n";
1567 $output .= "cpm_global[" . $map_id_json . "]['typecontrol'] = ".((isset($typecontrol) && $typecontrol) ? 'true' : 'false').";\n";
1568 $output .= "cpm_global[" . $map_id_json . "]['streetviewcontrol'] = ".((isset($streetviewcontrol) && $streetviewcontrol) ? 'true' : 'false').";\n";
1569 $output .= "cpm_global[" . $map_id_json . "]['trafficlayer'] = ".((isset($trafficlayer) && $trafficlayer) ? 'true' : 'false').";\n";
1570 $output .= "</script>";
1571
1572 return $output;
1573 } // End _set_map_config
1574
1575 /*
1576 * Generates the javascript code of map points
1577 */
1578 function _set_map_point($point, $index){
1579 if(
1580 empty( $point['address'] ) &&
1581 empty( $point['latitude'] ) &&
1582 empty( $point['longitude'] )
1583 ) return;
1584
1585 $icon = (!empty($point['icon'])) ? $point['icon'] : $this->get_configuration_option('default_icon');
1586 if( preg_match( '/http(s)?:\/\//i', $icon ) == 0 ) $icon = CPM_PLUGIN_URL.$icon;
1587 $obj = new stdClass;
1588 $obj->address = wp_kses_post(str_replace(array('&quot;', '&lt;', '&gt;', '&#039;', '&amp;'), array('\"', '<', '>', "'", '&'), ( ( empty( $point['address'] ) ) ? '' : $point['address'] ) ));
1589
1590 if(!empty($point['latitude']) ) $obj->lat = $point['latitude'];
1591 if(!empty($point['longitude']) )$obj->lng = $point['longitude'];
1592
1593 $obj->info = wp_kses_post(str_replace(array('&quot;', '&lt;', '&gt;', '&#039;', '&amp;'), array('\"', '<', '>', "'", '&'), $this->_get_windowhtml($point)));
1594
1595 $obj->icon = $icon;
1596 $obj->post = $point['post_id'];
1597 $obj->default = ( !empty( $point[ 'default' ] ) ) ? true : false;
1598 return 'cpm_global[' . wp_json_encode( $this->map_id ) . ']["markers"]['.$index.'] = '.wp_json_encode( $obj ).';';
1599 } // End _set_map_point
1600
1601 function _get_img_id($url){
1602 global $wpdb;
1603 $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM " . $wpdb->prefix . "posts" . " WHERE guid='%s';", $url ));
1604 return $attachment[0];
1605 } // End get_img_id
1606
1607 /**
1608 * Get the html info associated to point marker
1609 */
1610 function _get_windowhtml(&$point) {
1611
1612 $windowhtml = "";
1613 $windowhtml_frame = $this->get_configuration_option('windowhtml');
1614 $windowhtml_frame = apply_filters('cpm-point-infowindow-template', $windowhtml_frame, $point);
1615
1616 $point_title = (!empty($point['name'])) ? $point['name'] : get_the_title($point['post_id']);
1617 $point_link = (!empty($point['post_id'])) ? get_permalink($point['post_id']) : '';
1618 $point_img_url = '';
1619
1620 if (isset($point['thumbnail']) && !empty($point['thumbnail'])) {
1621 $point_img_url = $point['thumbnail'];
1622 if(preg_match("/attachment_id=(\d+)/i", $point['thumbnail'], $matches)){
1623 $thumb = wp_get_attachment_image_src($matches[1], 'thumbnail');
1624 if(is_array($thumb))$point_thumbnail = $thumb[0];
1625 }else{
1626 $point_thumbnail = $point['thumbnail'];
1627 }
1628 if( !empty( $point_thumbnail ) ) $point_img_url = $point_thumbnail;
1629 }else
1630 {
1631 $featured_image = $this->get_configuration_option( 'featured_image' );
1632 if( !empty( $featured_image ) )
1633 {
1634 $featured_image_url = wp_get_attachment_url( get_post_thumbnail_id( $point['post_id'] ) );
1635 if( $featured_image_url ) $point_img_url = $featured_image_url;
1636 }
1637 }
1638
1639 $point_img_url = apply_filters('cpm-point-image', $point_img_url, $point['post_id']);
1640
1641 $point_description = apply_filters('cpm-point-description', ( !empty( $point['description'] ) ) ? $point['description'] : $this->_get_excerpt($point['post_id']), $point['post_id']);
1642
1643 $point_address = apply_filters('cpm-point-address', isset( $point['address'] ) ? $point['address'] : '', $point['post_id']);
1644
1645 if( !empty( $point_img_url ) ) {
1646 $point_img = "<img src='".esc_url($point_img_url)."' class='cpm-thumbnail' style='margin:8px 0 0 8px !important; width:90px; height:90px' align='right' />";
1647 $html_width = "310px";
1648 } else {
1649 $point_img = "";
1650 $html_width = "auto";
1651 }
1652
1653 $find = array("%title%","%link%","%thumbnail%", "%excerpt%","%description%","%address%","%width%","\r\n","\f","\v","\t","\r","\n","\\","\"");
1654 $replace = array(esc_html($point_title),esc_url($point_link),$point_img,"",wp_kses_post(do_shortcode($point_description)),esc_html($point_address),$html_width,"","","","","","","","'");
1655
1656 $windowhtml = str_replace( $find, $replace, $windowhtml_frame);
1657
1658 return apply_filters('cpm-point-infowindow', $windowhtml, $point);
1659 } // End _get_windowhtml
1660
1661 /**
1662 * Get the excerpt from content
1663 */
1664 function _get_excerpt($post_id) { // Fakes an excerpt if needed
1665
1666 $content_post = get_post($post_id);
1667 $content = $content_post->post_content;
1668
1669 if ( '' != $content ) {
1670 return wp_trim_words( strip_shortcodes( $content ), 10 );
1671 }
1672 return $content;
1673 } // End _get_excerpt
1674
1675 /*
1676 Set a link to contact page
1677 */
1678 function customizationLink($links) {
1679 $settings_link = '<a href="https://wordpress.org/support/plugin/codepeople-post-map/#new-post" target="_blank">'.__('Help').'</a>';
1680 array_unshift($links, $settings_link);
1681 $settings_link = '<a href="http://wordpress.dwbooster.com/contact-us" target="_blank">'.__('Request custom changes', 'codepeople-post-map').'</a>';
1682 array_unshift($links, $settings_link);
1683 return $links;
1684 } // End customizationLink
1685
1686 public static function troubleshoot($option)
1687 {
1688 if(!is_admin())
1689 {
1690 // Solves a conflict caused by the "Speed Booster Pack" plugin
1691 if(is_array($option) && isset($option['jquery_to_footer'])) unset($option['jquery_to_footer']);
1692 }
1693 return $option;
1694 }
1695 } // End CPM class
1696 ?>