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

1,645 lines 83.2 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'] ) ) ? $_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'] ) ) ? $_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 CP 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 CP 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)) $cpm_point = @unserialize($cpm_point);
883 if($cpm_point === false) $cpm_point = array();
884
885 $cpm_map = get_post_meta($post->ID, 'cpm_map', TRUE);
886 $general_options = $this->get_configuration_option();
887 $options = array_merge((array)$general_options, (array)$cpm_point, (array)$cpm_map);
888 $options['post_id'] = $post->ID;
889 $this->_print_form($options);
890 } // End insert_form
891
892 //---------- LOADING RESOURCES ----------
893
894 /*
895 * Load the required scripts and styles for ADMIN section of website
896 */
897 function load_admin_resources(){
898 wp_enqueue_style(
899 'admin_cpm_style',
900 CPM_PLUGIN_URL.'/styles/cpm-admin-styles.css'
901 );
902
903 wp_enqueue_script(
904 'admin_cpm_script',
905 CPM_PLUGIN_URL.'/js/cpm.admin.js',
906 array('jquery'),
907 null,
908 true
909 );
910
911 $cpm_global = array();
912 $api_key = $this->get_configuration_option( 'api_key' );
913 if( !empty( $api_key ) )
914 {
915 $cpm_global[ 'api_key' ] = trim($api_key);
916 }
917 wp_localize_script('admin_cpm_script', 'cpm_global', $cpm_global);
918 } // End load_admin_resources
919
920 /**
921 * Loads the scripts required to integrate the plugin with the Gutenberg Editor.
922 */
923 function load_gutenberg_code(){
924 global $post;
925 wp_enqueue_style('cpm-admin-gutenberg-editor-css', CPM_PLUGIN_URL.'/styles/cpm-gutenberg.css');
926
927 if(!empty($post)) $url = get_preview_post_link($post->ID);
928 else $url = rtrim( get_home_url( get_current_blog_id() ), "/" ).( ( strpos( get_current_blog_id(), '?' ) === false ) ? "/" : "" );
929
930 $url .= ((strpos($url, '?') === false) ? '?' : '&').'cpm-preview=';
931 $config = array('url' => $url);
932 wp_enqueue_script('cpm-gutenberg-editor', CPM_PLUGIN_URL.'/js/gutenberg.js');
933 wp_localize_script('cpm-gutenberg-editor', 'cpm_ge_config', $config);
934 } // End load_gutenberg_code
935
936 /**
937 * Load script and style files required for display google maps on public website
938 */
939 function load_resources() {
940 global $cpm_resources_loaded;
941 if( !is_admin() && empty( $cpm_resources_loaded ) )
942 {
943 $cpm_resources_loaded = true;
944
945 if(get_option('cpm_load_resources_in_footer', false))
946 {
947 wp_enqueue_script('jquery');
948 wp_enqueue_style('cpm_style_css', CPM_PLUGIN_URL.'/styles/cpm-styles.css');
949 wp_enqueue_script('cpm_public_js', CPM_PLUGIN_URL.'/js/cpm.js', array('jquery'), 'pro', true);
950 }
951 else
952 {
953 if( !wp_script_is( 'jquery' ) )
954 {
955 print "<script src='".(is_ssl() ? "https" : "http")."://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>";
956 }
957
958 print "<link rel='stylesheet' id='cpm_style-css' href='".CPM_PLUGIN_URL.'/styles/cpm-styles.css'."' type='text/css' media='all' />";
959 print "<script src='".CPM_PLUGIN_URL.'/js/cpm.js'."'></script>";
960 }
961 }
962 } // End load_resources
963
964 function load_header_resources(){
965 echo '<style>.cpm-map img{ max-width: none !important;box-shadow:none !important;}</style>';
966 } // End load_header_resources
967
968 /**
969 * Print the settings page for entering the general setting's data of maps
970 */
971 function settings_page(){
972 if (isset($_GET["page"]))
973 {
974 if( $_GET["page"] == 'google_maps_cp_upgrade' )
975 {
976 echo("Redirecting to upgrade page...<script type='text/javascript'>document.location='http://wordpress.dwbooster.com/content-tools/codepeople-post-map?acode=18517#download';</script>");
977 exit;
978 }
979 elseif( $_GET["page"] == 'google_maps_cp_help')
980 {
981 echo("Redirecting to documentation...<script type='text/javascript'>document.location='http://wordpress.dwbooster.com/content-tools/codepeople-post-map?acode=18517';</script>");
982 exit;
983 }
984 elseif( $_GET["page"] == 'google_maps_cp_question')
985 {
986 echo("Redirecting to documentation...<script type='text/javascript'>document.location='https://wordpress.org/support/plugin/codepeople-post-map/#new-post';</script>");
987 exit;
988 }
989
990 }
991
992 // Check if post exists and save the configuraton options
993 if (isset($_POST['cpm_map_noncename']) && wp_verify_nonce($_POST['cpm_map_noncename'],__FILE__)){
994 $options = $_POST['cpm_map'];
995 $options = $this->array_map_recursive('sanitize_text_field', $options);
996 $options['drag_map'] = ( isset( $options[ 'drag_map' ] ) ) ? true : false;
997 $options['windowhtml'] = $this->get_configuration_option('windowhtml');
998 update_option('cpm_config', $options);
999 update_option('cpm_load_resources_in_footer', (isset($_POST['cpm_load_resources_in_footer'])) ? true : false);
1000 echo '<div class="updated"><p><strong>'.__("Settings Updated", 'codepeople-post-map').'</strong></div>';
1001 }else{
1002 $options = $this->get_configuration_option();
1003 }
1004
1005 ?>
1006 <div class="wrap">
1007 <form method="post">
1008 <?php
1009 $this->_deploy_map_form($options);
1010 ?>
1011 <table class="form-table cpm-settings">
1012 <tr valign="top">
1013 <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>
1014 <td>
1015 <input type="checkbox" DISABLED />
1016 <?php _e('The geolocation information is added to the images from your mobiles or cameras, if they have associated GPS devices', 'codepeople-post-map');?>
1017 <br /><br />
1018 <a class="button" href="javascript:void(0);"><?php _e( 'Process All Previous Images', 'codepeople-post-map' ); ?></a><br><br>
1019 <?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 />
1020 <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>
1021 </td>
1022 </tr>
1023
1024 <tr valign="top">
1025 <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>
1026 <td>
1027 <input type="checkbox" DISABLED />
1028 <?php _e('The geolocation information is added to the post from WordPress app in your mobile', 'codepeople-post-map');?>
1029 <br />
1030 <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>
1031 </td>
1032 </tr>
1033
1034 <tr valign="top">
1035 <th scope="row"><label for="cpm_map_search" style="color:#CCCCCC;"><?php _e('Use points information in search results:', 'codepeople-post-map'); ?></label></th>
1036 <td>
1037 <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>
1038 </td>
1039 </tr>
1040 <tr valign="top">
1041 <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>
1042 <td>
1043 <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>
1044 </td>
1045 </tr>
1046 <tr valign="top">
1047 <th scope="row"><label for="cpm_map_highlight_class" style="color:#CCCCCC;"><?php _e('Highlight class:', 'codepeople-post-map'); ?></label></th>
1048 <td>
1049 <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>
1050 </td>
1051 </tr>
1052 <tr valign="top">
1053 <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>
1054 <td valign="top">
1055 <?php
1056 $post_types = get_post_types(array('public' => true), 'names');
1057 print '<i>' . __('Posts and Pages are selected by default', 'codepeople-post-map') . '.</i><br>';
1058 ?>
1059 <select multiple size="3" DISABLED >
1060 <?php
1061 foreach($post_types as $post_type){
1062 print '<option value="'.esc_attr($post_type).'" >'.$post_type.'</option>';
1063 }
1064 ?>
1065 </select>
1066 <br />
1067 <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>
1068 </td>
1069 </tr>
1070 </table>
1071 <table cellpadding="10" cellspacing="10" width="500px">
1072 <tr valign="top">
1073 <td align="center" width="30%">
1074 <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map" target="_blank">
1075 <img src="<?php echo(CPM_PLUGIN_URL.'/images/routes.jpg'); ?>" width="100px" height="100px" class="cpm_thumbnail_admin" style="border:1px solid #AAA;" />
1076 </a>
1077 <br /><?php _e('Draws Routes', 'codepeople-post-map'); ?>
1078 </td>
1079 <td align="center">
1080 <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map" target="_blank">
1081 <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;" />
1082 </a>
1083 <br /><?php _e('Associate maps to custom post types', 'codepeople-post-map'); ?>
1084 </td>
1085 <td align="center" width="30%">
1086 <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map" target="_blank">
1087 <img src="<?php echo(CPM_PLUGIN_URL.'/images/multiple.jpg'); ?>" width="100px" height="100px" class="cpm_thumbnail_admin" style="border:1px solid #AAA;" />
1088 </a>
1089 <br/><?php _e('Display a map for each post in pages with multiple posts', 'codepeople-post-map'); ?>
1090 </td>
1091 </tr>
1092 </table>
1093 <?php
1094 if ( defined( 'ICL_SITEPRESS_VERSION' ) ):
1095 ?>
1096 <div id="metabox_basic_settings" class="postbox" >
1097 <h3 class="hndle" style="padding:5px;"><span><?php _e( 'WPML Related Section', 'codepeople-post-map' ); ?></span></h3>
1098 <div class="inside">
1099 <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>
1100 <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>
1101 </div>
1102 </div>
1103 <?php
1104 endif;
1105 ?>
1106 <div id="metabox_basic_settings" class="postbox" >
1107 <h3 class="hndle" style="padding:5px;"><span><?php _e( 'Troubleshoot Section', 'codepeople-post-map' ); ?></span></h3>
1108 <div class="inside">
1109 <table class="form-table cpm-settings">
1110 <tr>
1111 <td>
1112 <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'); ?>
1113 </td>
1114 </tr>
1115 </table>
1116 </div>
1117 </div>
1118 <script>
1119 jQuery(function(){
1120 jQuery('.cpm_thumbnail_admin').on('mouseover',function(){jQuery(this).width(300).height(300);}).on('mouseout',function(){jQuery(this).width(100).height(100);});
1121 });
1122 </script>
1123 <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>
1124 <div class="submit"><input type="submit" class="button-primary" value="<?php esc_attr_e(__('Update Settings', 'codepeople-post-map'));?>" /></div>
1125 <?php
1126 // create a custom nonce for submit verification later
1127 echo '<input type="hidden" name="cpm_map_noncename" value="' . wp_create_nonce(__FILE__) . '" />';
1128 ?>
1129 </form>
1130 </div>
1131 <?php
1132 } // End settings_page
1133
1134 //---------- SHORTCODE METHODS ----------
1135
1136 /*
1137 * Populate the attribute points
1138 */
1139 function populate_points($post_id){
1140 if( is_admin() ) return;
1141
1142 $point = get_post_meta($post_id, 'cpm_point', TRUE);
1143 if(!empty($point)){
1144 if(is_string($point))
1145 {
1146 $tmp_point = @unserialize($point);
1147 if($tmp_point !== false) $point = $tmp_point;
1148 }
1149
1150 if( !is_array( $point ) )
1151 {
1152 $point = array( 'address' => $point );
1153 }
1154 $point['post_id'] = $post_id;
1155 if(!in_array($point, $this->points)){
1156 $this->points[] = $point;
1157 }
1158 }
1159 else
1160 {
1161 $latitude = apply_filters('cpm-post-latitude', '', $post_id);
1162 $longitude = apply_filters('cpm-post-longitude', '', $post_id);
1163 $address = apply_filters('cpm-post-address', '', $post_id);
1164
1165 if( (!empty( $latitude ) && !empty( $longitude )) || !empty($address))
1166 {
1167 $point = array();
1168 if(!empty( $latitude ) && !empty( $longitude ))
1169 {
1170 $point['latitude'] = $latitude;
1171 $point['longitude'] = $longitude;
1172 }
1173 if(!empty( $address ))
1174 {
1175 $point['address'] = $address;
1176 }
1177 $point['post_id'] = $post_id;
1178 if(!in_array($point, $this->points)){
1179 $this->points[] = apply_filters('cpm-point', $point);
1180 }
1181 }
1182 }
1183 } // End populate_points
1184
1185 /*
1186 * Generates the javascript code of map points, only called from webpage of multiples posts
1187 */
1188 function print_points(){
1189 global $id;
1190
1191 $limit = abs($this->limit);
1192
1193 $str = '';
1194 $current_post = '';
1195 $count_posts = 0;
1196 $count_points = 0;
1197
1198 foreach($this->points as $point){
1199 if(!empty($limit)){
1200 if($current_post != $point['post_id']){
1201 $current_post = $point['post_id'];
1202 $count_posts++;
1203 if( $count_posts > $limit) break;
1204 if( !empty($this->defaultpost) && $this->defaultpost == $current_post )
1205 {
1206 $point[ 'default' ] = 1;
1207 $this->defaultpost = '';
1208 }
1209 }
1210 }
1211
1212 $str .= $this->_set_map_point($point, $count_points);
1213 $count_points++;
1214 }
1215 if(strlen($str))
1216 {
1217 $str = "<script>if(typeof cpm_global != 'undefined' && typeof cpm_global['".$this->map_id."'] != 'undefined' && typeof cpm_global['".$this->map_id."']['markers'] != 'undefined'){ ".$str." }</script>";
1218 }
1219
1220 $this->points = array();
1221 print $str;
1222 } // End print_points
1223
1224 /**
1225 * Replace each [codepeople-post-map] shortcode by the map
1226 */
1227 function replace_shortcode($atts){
1228 if(defined( 'REST_REQUEST' )) return;
1229 global $post, $id, $cpm_objs, $cpm_in_loop;
1230
1231 // Load the plugin resources
1232 $this->load_resources();
1233
1234 $cpm_obj = new CPM;
1235 $cpm_objs[] = $cpm_obj;
1236
1237 if(is_array($atts)) $cpm_obj->extended = $atts;
1238
1239 if( !empty( $atts[ 'defaultpost' ] ) ) $cpm_obj->defaultpost = str_replace( ' ', '', $atts[ 'defaultpost' ] );
1240
1241 if( isset($id) && ( is_singular() || !empty( $cpm_in_loop ) ) ){
1242 $cpm_map = get_post_meta($id, 'cpm_map', TRUE);
1243 }
1244
1245 if(empty($cpm_map)){
1246 $cpm_map = $cpm_obj->get_configuration_option();
1247 }
1248
1249 if( ! empty($atts['mapid']) ) $cpm_map['mapid'] = trim( $atts['mapid'] );
1250
1251 if(!empty($cpm_map['points'])){
1252 $cpm_obj->limit = $cpm_map['points'];
1253 }
1254
1255 if( !empty( $atts[ 'points' ] ) )
1256 {
1257 $atts[ 'points' ] = trim( $atts[ 'points' ] );
1258 if( is_numeric( $atts[ 'points' ] ) && $atts[ 'points' ] > 0 ) $cpm_obj->limit = $atts[ 'points' ];
1259 }
1260
1261 $cpm_map[ 'tooltip' ] = $this->get_configuration_option('tooltip');
1262
1263 if( isset( $atts[ 'tooltip' ] ) )
1264 {
1265 $cpm_map[ 'tooltip' ] = trim($atts[ 'tooltip' ]);
1266 }
1267
1268 if( isset($id) && ( is_singular() || !empty( $cpm_in_loop ) ) ){ // For maps in a post or page
1269 // Set the actual post only to avoid duplicates
1270 $posts = array( $id );
1271
1272 $query_arg = array(
1273 'meta_query' => array(
1274 'relation' => 'OR',
1275 array(
1276 'key' => 'cpm_point'
1277 ),
1278 ),
1279 'post_status' => 'publish',
1280 'orderby' => 'post_date',
1281 'order' => 'DESC',
1282 'cache_results' => false,
1283 'fields' => 'ids',
1284 'post__not_in' => array( $id )
1285 );
1286
1287 /*
1288 * If the latitude and longitude or address is stored into custom fields,
1289 * it is possible to include them in the selector query
1290 * function custom_complete_query_structure($query_components)
1291 * {
1292 * $query_components[] = array(
1293 * 'key' => 'custom_address'
1294 * );
1295 * return $query_components;
1296 * }
1297 * add_filter('cpm-complete-structured-query', 'custom_complete_query_structure');
1298 */
1299 $query_arg['meta_query'] = apply_filters('cpm-complete-structured-query', $query_arg['meta_query']);
1300
1301 if( !empty($cpm_obj->limit) ){
1302 $query_arg[ 'numberposts' ] = $cpm_obj->limit - 1;
1303 }
1304
1305 // Get POSTs in the same category
1306 $categories = get_the_category();
1307 $categories_ids = array();
1308 foreach($categories as $category){
1309 array_push( $categories_ids, $category->term_id);
1310 }
1311
1312 if( !empty( $categories_ids ) ){
1313 $query_arg[ 'category' ] = implode( ',', $categories_ids );
1314 }
1315
1316 $posts = array_merge( $posts, get_posts( $query_arg ) );
1317
1318 // WMPL
1319 $wpml_option = $this->get_configuration_option( 'wpml' );
1320 if(function_exists( 'icl_object_id' )) $current_lang = apply_filters( 'wpml_current_language', NULL );
1321
1322 foreach( $posts as $_post){
1323 if(function_exists( 'icl_object_id' )) {
1324 $post_language_information = apply_filters( 'wpml_post_language_details', NULL, $_post );
1325 $language = $post_language_information["language_code"];
1326 if(
1327 $language != $current_lang &&
1328 ! empty( $wpml_option ) &&
1329 'some' == $wpml_option
1330 ) continue;
1331 }
1332 $cpm_obj->populate_points($_post);
1333 }
1334
1335 }else{
1336 $cpm_obj->multiple = true;
1337 }
1338
1339 $output = $cpm_obj->_set_map_tag($cpm_map);
1340 $output .= $cpm_obj->_set_map_config($cpm_map);
1341
1342 $output .= "<noscript>
1343 codepeople-post-map require JavaScript
1344 </noscript>
1345 ";
1346
1347 if( !empty( $atts['print'] ) ){
1348 print $output;
1349 $cpm_obj->print_points();
1350 return '';
1351 }
1352
1353 return $output;
1354 } // End replace_shortcode
1355
1356 function preview()
1357 {
1358 $user = wp_get_current_user();
1359 $allowed_roles = array('editor', 'administrator', 'author');
1360
1361 if(array_intersect($allowed_roles, $user->roles ))
1362 {
1363 if(
1364 !empty($_REQUEST['cpm-preview']) &&
1365 !empty($_REQUEST['post-id']) &&
1366 ($post_id = @intval($_REQUEST['post-id'])) !== 0
1367 )
1368 {
1369 // Sanitizing variable
1370 $preview = stripcslashes($_REQUEST['cpm-preview']);
1371 $preview = strip_tags($preview);
1372
1373 // Remove every shortcode that is not in the music store list
1374 remove_all_shortcodes();
1375 add_shortcode('codepeople-post-map', array(&$this, 'replace_shortcode'));
1376 get_post($post_id);
1377
1378 if(has_shortcode($preview, 'codepeople-post-map'))
1379 {
1380 // To indicate in the replace_shortcode that should be used the particular settings.
1381 global $id, $cpm_in_loop;
1382 $id = $post_id;
1383 $cpm_in_loop = true;
1384
1385 // Includes the print attribute in the shortcode
1386 $preview = preg_replace('/(\[codepeople\-post\-map)/i', '$1 print="1" ', $preview);
1387 wp_head();
1388 print '<div class="cpm-preview-container">'.do_shortcode($preview).'</div>';
1389
1390 if(
1391 function_exists('wp_print_styles') &&
1392 function_exists('wp_print_scripts')
1393 )
1394 {
1395 wp_print_styles();
1396 wp_print_scripts();
1397 }
1398 else
1399 {
1400 wp_footer();
1401 }
1402 print'<script type="text/javascript">jQuery(window).on("load", function(){
1403 var frameEl = window.frameElement,
1404 interval_id,
1405 counter = 10;
1406 if(frameEl) {
1407 interval_id = setInterval(function(){
1408 if( counter <= 0) clearInterval(interval_id);
1409 counter--;
1410 var cpm = jQuery(".cpm-map:visible");
1411 if(cpm.length) {
1412 clearInterval(interval_id);
1413 frameEl.height = cpm.outerHeight(true)+5;
1414 }
1415 }, 1000);
1416 }
1417 });</script>';
1418 exit;
1419 }
1420 }
1421 }
1422 } // End preview
1423
1424 /*
1425 * Generates the DIV tag where the map will be loaded
1426 */
1427 function _set_map_tag($atts){
1428 $atts = array_merge($atts, $this->extended);
1429 extract($atts);
1430
1431 if(isset($width))
1432 {
1433 $width = trim($width);
1434 if(is_numeric($width)) $width .= 'px';
1435 }
1436 else $width = '100%';
1437
1438 if(isset($height))
1439 {
1440 $height = trim($height);
1441 if(is_numeric($height)) $height .= 'px';
1442 }
1443 else $height = '500px';
1444
1445 $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).'; ';
1446
1447 if(!isset($align)) $align = 'center';
1448 if(!isset($margin)) $margin = 0;
1449
1450 switch ($align) {
1451 case "left" :
1452 $output .= 'float:left; margin:'.esc_attr($margin).'px;"';
1453 break;
1454 case "right" :
1455 $output .= 'float:right; margin:'.esc_attr($margin).'px;"';
1456 break;
1457 case "center" :
1458 default:
1459 $output .= 'clear:both; overflow:hidden; margin:'.esc_attr($margin).'px auto;"';
1460 break;
1461 }
1462 $output .= "></div>";
1463 return $output;
1464 } // End _set_map_tag
1465
1466 /*
1467 * Generates the javascript tag with map configuration
1468 */
1469 function _set_map_config($atts){
1470 $atts = array_merge($atts, $this->extended);
1471
1472 extract($atts);
1473
1474 if(!isset($display)) $display = 'map';
1475 if(!isset($type)) $type = 'ROADMAP';
1476
1477 $default_language = $this->get_configuration_option('language');
1478 $output = "<script type=\"text/javascript\">\n";
1479
1480 if(isset($language))
1481 $output .= 'var cpm_language = {"lng":"'.esc_js($language).'"};';
1482 elseif(isset($default_language))
1483 $output .= 'var cpm_language = {"lng":"'.esc_js($default_language).'"};';
1484
1485 $api_key = $this->get_configuration_option( 'api_key' );
1486 $output .= "var cpm_api_key = '".esc_js((!empty( $api_key ))?trim($api_key) :'')."';\n";
1487
1488 $output .= "var cpm_global = cpm_global || {};\n";
1489 $output .= "cpm_global['$this->map_id'] = {}; \n";
1490 $output .= "cpm_global['$this->map_id']['zoom'] = ".((!empty($zoom)) ? @intval($zoom) : $this->_default_configuration('zoom')).";\n";
1491 $output .= "cpm_global['$this->map_id']['dynamic_zoom'] = ".((isset($dynamic_zoom) && $dynamic_zoom) ? 'true' : 'false').";\n";
1492 $output .= "cpm_global['$this->map_id']['markers'] = new Array();\n";
1493 $output .= "cpm_global['$this->map_id']['display'] = '$display';\n";
1494 $output .= "cpm_global['$this->map_id']['drag_map'] = ".( ( !isset( $drag_map ) || $drag_map ) ? 'true' : 'false' ).";\n";
1495 $output .= "cpm_global['$this->map_id']['highlight_class'] = '".$this->get_configuration_option('highlight_class')."';\n";
1496
1497 if(isset($tooltip))
1498 $output .= "cpm_global['$this->map_id']['marker_title'] = '".esc_js($tooltip)."';\n";
1499
1500 $highlight = $this->get_configuration_option('highlight');
1501 $output .= "cpm_global['$this->map_id']['highlight'] = ".(($highlight && !is_singular()) ? 'true' : 'false').";\n";
1502 $output .= "cpm_global['$this->map_id']['type'] = '$type';\n";
1503 $output .= "cpm_global['$this->map_id']['show_window'] = ".((isset($show_window) && $show_window) ? 'true' : 'false').";\n";
1504 $output .= "cpm_global['$this->map_id']['show_default'] = ".((isset($show_default) && $show_default) ? 'true' : 'false').";\n";
1505
1506 // Set maps centre
1507 if( !empty( $center ) )
1508 {
1509 $output .= "cpm_global['$this->map_id']['center'] = [".trim( $center )."];\n";
1510 }
1511
1512 // Define controls
1513 $output .= "cpm_global['$this->map_id']['mousewheel'] = ".((isset($mousewheel) && $mousewheel) ? 'true' : 'false').";\n";
1514 $output .= "cpm_global['$this->map_id']['zoompancontrol'] = ".((isset($zoompancontrol) && $zoompancontrol) ? 'true' : 'false').";\n";
1515 $output .= "cpm_global['$this->map_id']['fullscreencontrol'] = ".((isset($fullscreencontrol) && $fullscreencontrol) ? 'true' : 'false').";\n";
1516 $output .= "cpm_global['$this->map_id']['typecontrol'] = ".((isset($typecontrol) && $typecontrol) ? 'true' : 'false').";\n";
1517 $output .= "cpm_global['$this->map_id']['streetviewcontrol'] = ".((isset($streetviewcontrol) && $streetviewcontrol) ? 'true' : 'false').";\n";
1518 $output .= "cpm_global['$this->map_id']['trafficlayer'] = ".((isset($trafficlayer) && $trafficlayer) ? 'true' : 'false').";\n";
1519 $output .= "</script>";
1520
1521 return $output;
1522 } // End _set_map_config
1523
1524 /*
1525 * Generates the javascript code of map points
1526 */
1527 function _set_map_point($point, $index){
1528 if(
1529 empty( $point['address'] ) &&
1530 empty( $point['latitude'] ) &&
1531 empty( $point['longitude'] )
1532 ) return;
1533
1534 $icon = (!empty($point['icon'])) ? $point['icon'] : $this->get_configuration_option('default_icon');
1535 if( preg_match( '/http(s)?:\/\//i', $icon ) == 0 ) $icon = CPM_PLUGIN_URL.$icon;
1536 $obj = new stdClass;
1537 $obj->address = str_replace(array('&quot;', '&lt;', '&gt;', '&#039;', '&amp;'), array('\"', '<', '>', "'", '&'), ( ( empty( $point['address'] ) ) ? '' : $point['address'] ) );
1538
1539 if(!empty($point['latitude']) ) $obj->lat = $point['latitude'];
1540 if(!empty($point['longitude']) )$obj->lng = $point['longitude'];
1541
1542 $obj->info = str_replace(array('&quot;', '&lt;', '&gt;', '&#039;', '&amp;'), array('\"', '<', '>', "'", '&'), $this->_get_windowhtml($point));
1543
1544 $obj->icon = $icon;
1545 $obj->post = $point['post_id'];
1546 $obj->default = ( !empty( $point[ 'default' ] ) ) ? true : false;
1547 return 'cpm_global["'.$this->map_id.'"]["markers"]['.$index.'] = '.json_encode( $obj ).';';
1548 } // End _set_map_point
1549
1550 function _get_img_id($url){
1551 global $wpdb;
1552 $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM " . $wpdb->prefix . "posts" . " WHERE guid='%s';", $url ));
1553 return $attachment[0];
1554 } // End get_img_id
1555
1556 /**
1557 * Get the html info associated to point marker
1558 */
1559 function _get_windowhtml(&$point) {
1560
1561 $windowhtml = "";
1562 $windowhtml_frame = $this->get_configuration_option('windowhtml');
1563 $windowhtml_frame = apply_filters('cpm-point-infowindow-template', $windowhtml_frame, $point);
1564
1565 $point_title = (!empty($point['name'])) ? $point['name'] : get_the_title($point['post_id']);
1566 $point_link = (!empty($point['post_id'])) ? get_permalink($point['post_id']) : '';
1567 $point_img_url = '';
1568
1569 if (isset($point['thumbnail']) && !empty($point['thumbnail'])) {
1570 $point_img_url = $point['thumbnail'];
1571 if(preg_match("/attachment_id=(\d+)/i", $point['thumbnail'], $matches)){
1572 $thumb = wp_get_attachment_image_src($matches[1], 'thumbnail');
1573 if(is_array($thumb))$point_thumbnail = $thumb[0];
1574 }else{
1575 $point_thumbnail = $point['thumbnail'];
1576 }
1577 if( !empty( $point_thumbnail ) ) $point_img_url = $point_thumbnail;
1578 }else
1579 {
1580 $featured_image = $this->get_configuration_option( 'featured_image' );
1581 if( !empty( $featured_image ) )
1582 {
1583 $featured_image_url = wp_get_attachment_url( get_post_thumbnail_id( $point['post_id'] ) );
1584 if( $featured_image_url ) $point_img_url = $featured_image_url;
1585 }
1586 }
1587
1588 $point_img_url = apply_filters('cpm-point-image', $point_img_url, $point['post_id']);
1589
1590 $point_description = apply_filters('cpm-point-description', ( !empty( $point['description'] ) ) ? $point['description'] : $this->_get_excerpt($point['post_id']), $point['post_id']);
1591
1592 $point_address = apply_filters('cpm-point-address', isset( $point['address'] ) ? $point['address'] : '', $point['post_id']);
1593
1594 if( !empty( $point_img_url ) ) {
1595 $point_img = "<img src='".$point_img_url."' class='cpm-thumbnail' style='margin:8px 0 0 8px !important; width:90px; height:90px' align='right' />";
1596 $html_width = "310px";
1597 } else {
1598 $point_img = "";
1599 $html_width = "auto";
1600 }
1601
1602 $find = array("%title%","%link%","%thumbnail%", "%excerpt%","%description%","%address%","%width%","\r\n","\f","\v","\t","\r","\n","\\","\"");
1603 $replace = array($point_title,$point_link,$point_img,"",do_shortcode($point_description),$point_address,$html_width,"","","","","","","","'");
1604
1605 $windowhtml = str_replace( $find, $replace, $windowhtml_frame);
1606
1607 return apply_filters('cpm-point-infowindow', $windowhtml, $point);
1608 } // End _get_windowhtml
1609
1610 /**
1611 * Get the excerpt from content
1612 */
1613 function _get_excerpt($post_id) { // Fakes an excerpt if needed
1614
1615 $content_post = get_post($post_id);
1616 $content = $content_post->post_content;
1617
1618 if ( '' != $content ) {
1619 return wp_trim_words( strip_shortcodes( $content ), 10 );
1620 }
1621 return $content;
1622 } // End _get_excerpt
1623
1624 /*
1625 Set a link to contact page
1626 */
1627 function customizationLink($links) {
1628 $settings_link = '<a href="https://wordpress.org/support/plugin/codepeople-post-map/#new-post" target="_blank">'.__('Help').'</a>';
1629 array_unshift($links, $settings_link);
1630 $settings_link = '<a href="http://wordpress.dwbooster.com/contact-us" target="_blank">'.__('Request custom changes', 'codepeople-post-map').'</a>';
1631 array_unshift($links, $settings_link);
1632 return $links;
1633 } // End customizationLink
1634
1635 public static function troubleshoot($option)
1636 {
1637 if(!is_admin())
1638 {
1639 // Solves a conflict caused by the "Speed Booster Pack" plugin
1640 if(is_array($option) && isset($option['jquery_to_footer'])) unset($option['jquery_to_footer']);
1641 }
1642 return $option;
1643 }
1644 } // End CPM class
1645 ?>