PluginProbe
CodePeople Post Map for Google Maps / 1.2.6
CodePeople Post Map for Google Maps v1.2.6
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 1.2.6, at include/functions.php

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