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

1,597 lines 79.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');?></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');?></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');?></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');?></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');?></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');?></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');?></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');?></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');?></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');?></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');?></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');?></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');?></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');?></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');?></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');?></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'); ?>:</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 for="cpm_map_stylized" style="color:#CCCCCC;"><?php _e('Allow stylize the maps:', 'codepeople-post-map'); ?></label></th>
611 <td valign="top">
612 <input type="checkbox" DISABLED />
613 </td>
614 </tr>
615 <tr class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
616 <th></th>
617 <td>
618 <span>
619 <?php
620 _e( "If you want change the maps' styles, be sure to know how to create a JSON structure with the map's styles", 'codepeople-post-map');
621 ?>
622 </span><br />
623 <textarea rows="10" cols="80" DISABLED READONLY ></textarea><br />
624 <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>
625 </td>
626 </tr>
627 <tr class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
628 <th scope="row"><label for="cpm_map_legend" style="color:#CCCCCC;"><?php _e("Display the map's legend:", 'codepeople-post-map');?></label></th>
629 <td valign="top">
630 <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>
631 </td>
632 </tr>
633 <tr class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
634 <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>
635 <td valign="top">
636 <select disabled readonly>
637 <option value=""><?php _e( 'Select a taxonomy', 'codepeople-post-map' ); ?></option>
638 </select>
639 </td>
640 </tr>
641 <tr class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
642 <th scope="row"><label for="cpm_map_legend_title" style="color:#CCCCCC;"><?php _e('Enter a title for legend:', 'codepeople-post-map'); ?></label></th>
643 <td valign="top">
644 <input type="text" disabled readonly />
645 </td>
646 </tr>
647 <tr class="cpm-map-settings" style="<?php print $additional_tr_styles; ?>">
648 <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>
649 <td valign="top">
650 <input type="text" disabled readonly />
651 </td>
652 </tr>
653
654 </table>
655 <?php
656 } // End _deploy_map_form
657
658 /**
659 * Private method to print Maps form
660 */
661 function _print_form($options){
662 global $post;
663 $default_configuration = $this->_default_configuration();
664
665 // create a custom nonce for submit verification later
666 echo '<input type="hidden" name="cpm_map_noncename" value="' . wp_create_nonce(__FILE__) . '" />';
667 ?>
668 <script>
669 var cpm_default_marker = "<?php echo $default_configuration['default_icon']; ?>";
670 var cpm_point = {};
671
672 <?php
673 if(!empty($options['address']) || (!empty($options['latitude']) && !empty($options['longitude']))){
674 if(!empty($options['address'])) echo 'cpm_point["address"]="'.$options['address'].'";';
675 if(!empty($options['latitude']) && !empty($options['longitude'])){
676 echo 'cpm_point["latitude"]="'.$options['latitude'].'";';
677 echo 'cpm_point["longitude"]="'.$options['longitude'].'";';
678 }
679
680 } else {
681 echo 'cpm_point["address"]="Statue of Liberty, Statue of Liberty National Monument, Statue Of Liberty, New York, NY 10004, USA";';
682 echo 'cpm_point["latitude"]="40.689848";';
683 echo 'cpm_point["longitude"]="-74.044869";';
684 }
685 ?>
686
687 </script>
688 <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>
689 <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>
690 <p>
691 <?php _e( 'To insert a map in the post follow the steps below', 'codepeople-post-map');?>:
692 </p>
693 <ol>
694 <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>
695 <li><?php _e('Insert the shortcode in the post\'s content pressing the "insert the map tag" button', 'codepeople-post-map');?></li>
696 <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>
697 <li><?php _e( 'Don\'t forget to press the "Update" button for save the post and map data', 'codepeople-post-map');?></li>
698 </ol>
699 <div class="cpm_error_mssg"></div>
700 <div style="border:1px solid #CCC;margin-bottom:10px;min-height:60px; padding:5px;">
701 <h3><?php _e('Map points', 'codepeople-post-map'); ?></h3>
702 <div id="points_container" style="padding:10px;">
703 <?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'); ?>
704 </div>
705 </div>
706 <div class="point_form" style="border:1px solid #CCC; padding:5px;">
707 <h3><?php _e('Map point description', 'codepeople-post-map'); ?></h3>
708 <table class="form-table cpm-settings">
709 <tr valign="top">
710 <th scope="row"><label for="cpm_name"><?php _e('Location name:', 'codepeople-post-map');?></label></th>
711 <td>
712 <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'] : '');?>" />
713 </td>
714 </tr>
715 <tr valign="top">
716 <th scope="row"><label for="cpm_point_description"><?php _e('Location description:', 'codepeople-post-map');?></label></th>
717 <td>
718 <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'] : '');?>" />
719 <br />
720 <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>
721 </td>
722 </tr>
723 <tr valign="top">
724 <th scope="row">
725 <?php _e("Select an image to attach to the point: ","codepeople-post-map"); ?>
726 </th>
727 <td>
728 <input type="text" name="cpm_point[thumbnail]" value="<?php if(isset($options["thumbnail"])){ esc_attr_e($options["thumbnail"]);} ?>" id="cpm_point_thumbnail" />
729 <input class="button" type="button" value="Upload Images" onclick="cpm_thumbnail_selection(this);" />
730 </td>
731 </tr>
732 <tr valign="top">
733 <td colspan="2">
734 <table>
735 <tr valign="top">
736 <td>
737 <span style="font-weight:bold;">Address, latitude and longitude are required fields.</span>
738 <table>
739 <tr valign="top">
740 <th scope="row"><label for="cpm_point_address"><?php _e('Address:', 'codepeople-post-map');?></label></th>
741 <td width="100%">
742 <input type="text" style="width:100%;" name="cpm_point[address]" id="cpm_point_address" value="<?php esc_attr_e((isset($options['address'])) ? $options['address'] : '');?>" />
743 </td>
744 </tr>
745 <tr valign="top">
746 <th scope="row"><label for="cpm_point_latitude"><?php _e('Latitude:', 'codepeople-post-map');?></label></th>
747 <td>
748 <input type="text" style="width:100%;" name="cpm_point[latitude]" id="cpm_point_latitude" value="<?php esc_attr_e((isset($options['latitude'])) ? $options['latitude'] : '');?>" />
749 </td>
750 </tr>
751 <tr valign="top">
752 <th scope="row"><label for="cpm_point_longitude"><?php _e('Longitude:', 'codepeople-post-map');?></label></th>
753 <td>
754 <input type="text" style="width:100%;" name="cpm_point[longitude]" id="cpm_point_longitude" value="<?php esc_attr_e((isset($options['longitude'])) ? $options['longitude'] : '');?>" />
755 </td>
756 </tr>
757 <tr valign="top">
758 <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>
759 <td>
760 <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>
761 </td>
762 </tr>
763 </table>
764 </td>
765 <td width="50%">
766 <div id="cpm_map_container" class="cpm_map_container" style="height:250px; border:1px dotted #CCC;">
767 </div>
768 </td>
769 </tr>
770 </table>
771 </td>
772 </tr>
773 <tr valign="top">
774 <td colspan="2">
775 <?php $this->_deploy_icons($options); ?>
776 </td>
777 </tr>
778 </table>
779 </div>
780 <div style="border:1px solid #CCC; padding:10px; margin:10px 0;">
781 <p class="cpm-classic-editor">
782 <?php
783 _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' );
784 ?>
785 </p>
786 <div style="border:1px solid #CCC; padding:10px; padding:5px;">
787 <p style="color:#CCC;">
788 <input type="checkbox" DISABLED />
789 <?php
790 _e( 'Do you want display a <strong>shape</strong> on map?', 'codepeople-post-map' );
791 ?>
792 <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>
793 </p>
794 </div>
795 <table class="form-table cpm-settings">
796 <tr valign="top">
797 <td scope="row" valign="top" style="vertical-align:top;width:350px;" class="cpm-classic-editor">
798 <label><?php _e('If you want to display the map in page / post:', 'codepeople-post-map');?></label><br />
799 <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 />
800 <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>
801 <div class="cpm_more_info">
802 <?php _e('<p>It is possible to use attributes in the shortcode, like: width, height, zoom and the other maps attributes:</p>
803 <p><strong>[codepeople-post-map width="450" height="500"]</strong></p>
804 <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>
805 <p><strong>[codepeople-post-map cat="35"]</strong><br/>Note: the number 35 correspond to the ID of category.</p>
806 <p>or all points on website, using as category ID the value "-1"</p>
807 <p><strong>[codepeople-post-map cat="-1"]</strong></p>
808 <p>The special attribute "tag", allow to display all points that belong to the posts with a specific tag assigned, for example "mytag":</p>
809 <p><strong>[codepeople-post-map tag="mytag"]</strong></p>', 'codepeople-post-map' ); ?>
810 <br />
811 <a href="javascript:void(0)" onclick="cpm_hide_more_info( this );"><?php _e('[ + less information]', 'codepeople-post-map'); ?></a>
812 </div>
813 </td>
814 <td valign="top" class="cpm-gutenberg-editor" style="vertical-align:top;">
815 <label style="color:#CCC;"><?php _e('To display the points that belong to any category','codepeople-post-map');?>:</label><br />
816 <select size="2" multiple="multiple" style="height:48px;width:100%;" disabled>
817 <option value="-1"><?php _e( 'All points on website', 'codepeople-post-map'); ?></option>
818 <?php
819 $categories = get_categories();
820 foreach( $categories as $category )
821 {
822 print '<option value="'.$category->term_id.'">'.$category->name.'</option>';
823 }
824
825 ?>
826 </select>
827 <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>
828 </td>
829 </tr>
830 </table>
831 </div>
832 <div id="map_data">
833 <?php $this->_deploy_map_form($options, true); ?>
834 </div>
835 <p>&nbsp;</p>
836 <?php
837 } // End _print_form
838
839 /**
840 * Form for maps insertion and update
841 */
842 function insert_form(){
843 global $post, $wpdb;
844
845 $cpm_point = get_post_meta($post->ID, 'cpm_point', TRUE);
846 if(is_string($cpm_point)) $cpm_point = @unserialize($cpm_point);
847 if($cpm_point === false) $cpm_point = array();
848
849 $cpm_map = get_post_meta($post->ID, 'cpm_map', TRUE);
850 $general_options = $this->get_configuration_option();
851 $options = array_merge((array)$general_options, (array)$cpm_point, (array)$cpm_map);
852 $options['post_id'] = $post->ID;
853 $this->_print_form($options);
854 } // End insert_form
855
856 //---------- LOADING RESOURCES ----------
857
858 /*
859 * Load the required scripts and styles for ADMIN section of website
860 */
861 function load_admin_resources(){
862 wp_enqueue_style(
863 'admin_cpm_style',
864 CPM_PLUGIN_URL.'/styles/cpm-admin-styles.css'
865 );
866
867 wp_enqueue_script(
868 'admin_cpm_script',
869 CPM_PLUGIN_URL.'/js/cpm.admin.js',
870 array('jquery'),
871 null,
872 true
873 );
874
875 $cpm_global = array();
876 $api_key = $this->get_configuration_option( 'api_key' );
877 if( !empty( $api_key ) )
878 {
879 $cpm_global[ 'api_key' ] = trim($api_key);
880 }
881 wp_localize_script('admin_cpm_script', 'cpm_global', $cpm_global);
882 } // End load_admin_resources
883
884 /**
885 * Loads the scripts required to integrate the plugin with the Gutenberg Editor.
886 */
887 function load_gutenberg_code(){
888 global $post;
889 wp_enqueue_style('cpm-admin-gutenberg-editor-css', CPM_PLUGIN_URL.'/styles/cpm-gutenberg.css');
890
891 if(!empty($post)) $url = get_preview_post_link($post->ID);
892 else $url = rtrim( get_home_url( get_current_blog_id() ), "/" ).( ( strpos( get_current_blog_id(), '?' ) === false ) ? "/" : "" );
893
894 $url .= ((strpos($url, '?') === false) ? '?' : '&').'cpm-preview=';
895 $config = array('url' => $url);
896 wp_enqueue_script('cpm-gutenberg-editor', CPM_PLUGIN_URL.'/js/gutenberg.js');
897 wp_localize_script('cpm-gutenberg-editor', 'cpm_ge_config', $config);
898 } // End load_gutenberg_code
899
900 /**
901 * Load script and style files required for display google maps on public website
902 */
903 function load_resources() {
904 global $cpm_resources_loaded;
905 if( !is_admin() && empty( $cpm_resources_loaded ) )
906 {
907 $cpm_resources_loaded = true;
908
909 if(get_option('cpm_load_resources_in_footer', false))
910 {
911 wp_enqueue_script('jquery');
912 wp_enqueue_style('cpm_style_css', CPM_PLUGIN_URL.'/styles/cpm-styles.css');
913 wp_enqueue_script('cpm_public_js', CPM_PLUGIN_URL.'/js/cpm.js', array('jquery'), 'pro', true);
914 }
915 else
916 {
917 if( !wp_script_is( 'jquery' ) )
918 {
919 print "<script src='".(is_ssl() ? "https" : "http")."://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>";
920 }
921
922 print "<link rel='stylesheet' id='cpm_style-css' href='".CPM_PLUGIN_URL.'/styles/cpm-styles.css'."' type='text/css' media='all' />";
923 print "<script src='".CPM_PLUGIN_URL.'/js/cpm.js'."'></script>";
924 }
925 }
926 } // End load_resources
927
928 function load_header_resources(){
929 echo '<style>.cpm-map img{ max-width: none !important;box-shadow:none !important;}</style>';
930 } // End load_header_resources
931
932 /**
933 * Print the settings page for entering the general setting's data of maps
934 */
935 function settings_page(){
936 if (isset($_GET["page"]))
937 {
938 if( $_GET["page"] == 'google_maps_cp_upgrade' )
939 {
940 echo("Redirecting to upgrade page...<script type='text/javascript'>document.location='http://wordpress.dwbooster.com/content-tools/codepeople-post-map?acode=18517#download';</script>");
941 exit;
942 }
943 elseif( $_GET["page"] == 'google_maps_cp_help')
944 {
945 echo("Redirecting to documentation...<script type='text/javascript'>document.location='http://wordpress.dwbooster.com/content-tools/codepeople-post-map?acode=18517';</script>");
946 exit;
947 }
948 elseif( $_GET["page"] == 'google_maps_cp_question')
949 {
950 echo("Redirecting to documentation...<script type='text/javascript'>document.location='https://wordpress.org/support/plugin/codepeople-post-map/#new-post';</script>");
951 exit;
952 }
953
954 }
955
956 // Check if post exists and save the configuraton options
957 if (isset($_POST['cpm_map_noncename']) && wp_verify_nonce($_POST['cpm_map_noncename'],__FILE__)){
958 $options = $_POST['cpm_map'];
959 $options = $this->array_map_recursive('sanitize_text_field', $options);
960 $options['drag_map'] = ( isset( $options[ 'drag_map' ] ) ) ? true : false;
961 $options['windowhtml'] = $this->get_configuration_option('windowhtml');
962 update_option('cpm_config', $options);
963 update_option('cpm_load_resources_in_footer', (isset($_POST['cpm_load_resources_in_footer'])) ? true : false);
964 echo '<div class="updated"><p><strong>'.__("Settings Updated", 'codepeople-post-map').'</strong></div>';
965 }else{
966 $options = $this->get_configuration_option();
967 }
968
969 ?>
970 <div class="wrap">
971 <form method="post">
972 <?php
973 $this->_deploy_map_form($options);
974 ?>
975 <table class="form-table cpm-settings">
976 <tr valign="top">
977 <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>
978 <td>
979 <input type="checkbox" DISABLED />
980 <?php _e('The geolocation information is added to the images from your mobiles or cameras, if they have associated GPS devices', 'codepeople-post-map');?>
981 <br /><br />
982 <a class="button" href="javascript:void(0);"><?php _e( 'Process All Previous Images', 'codepeople-post-map' ); ?></a><br><br>
983 <?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 />
984 <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>
985 </td>
986 </tr>
987
988 <tr valign="top">
989 <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>
990 <td>
991 <input type="checkbox" DISABLED />
992 <?php _e('The geolocation information is added to the post from WordPress app in your mobile', 'codepeople-post-map');?>
993 <br />
994 <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>
995 </td>
996 </tr>
997
998 <tr valign="top">
999 <th scope="row"><label for="cpm_map_search" style="color:#CCCCCC;"><?php _e('Use points information in search results:', 'codepeople-post-map'); ?></label></th>
1000 <td>
1001 <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>
1002 </td>
1003 </tr>
1004 <tr valign="top">
1005 <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>
1006 <td>
1007 <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>
1008 </td>
1009 </tr>
1010 <tr valign="top">
1011 <th scope="row"><label for="cpm_map_highlight_class" style="color:#CCCCCC;"><?php _e('Highlight class:', 'codepeople-post-map'); ?></label></th>
1012 <td>
1013 <input type="input" 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>
1014 </td>
1015 </tr>
1016 <tr valign="top">
1017 <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>
1018 <td valign="top">
1019 <?php
1020 $post_types = get_post_types(array('public' => true), 'names');
1021 print '<i>' . __('Posts and Pages are selected by default', 'codepeople-post-map') . '.</i><br>';
1022 ?>
1023 <select multiple size="3" DISABLED >
1024 <?php
1025 foreach($post_types as $post_type){
1026 print '<option value="'.esc_attr($post_type).'" >'.$post_type.'</option>';
1027 }
1028 ?>
1029 </select>
1030 <br />
1031 <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>
1032 </td>
1033 </tr>
1034 </table>
1035 <table cellpadding="10" cellspacing="10" width="500px">
1036 <tr valign="top">
1037 <td align="center" width="30%">
1038 <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map" target="_blank">
1039 <img src="<?php echo(CPM_PLUGIN_URL.'/images/routes.jpg'); ?>" width="100px" height="100px" class="cpm_thumbnail_admin" style="border:1px solid #AAA;" />
1040 </a>
1041 <br /><?php _e('Draws Routes', 'codepeople-post-map'); ?>
1042 </td>
1043 <td align="center">
1044 <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map" target="_blank">
1045 <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;" />
1046 </a>
1047 <br /><?php _e('Associate maps to custom post types', 'codepeople-post-map'); ?>
1048 </td>
1049 <td align="center" width="30%">
1050 <a href="http://wordpress.dwbooster.com/content-tools/codepeople-post-map" target="_blank">
1051 <img src="<?php echo(CPM_PLUGIN_URL.'/images/multiple.jpg'); ?>" width="100px" height="100px" class="cpm_thumbnail_admin" style="border:1px solid #AAA;" />
1052 </a>
1053 <br/><?php _e('Display a map for each post in pages with multiple posts', 'codepeople-post-map'); ?>
1054 </td>
1055 </tr>
1056 </table>
1057 <?php
1058 if ( defined( 'ICL_SITEPRESS_VERSION' ) ):
1059 ?>
1060 <div id="metabox_basic_settings" class="postbox" >
1061 <h3 class="hndle" style="padding:5px;"><span><?php _e( 'WPML Related Section', 'codepeople-post-map' ); ?></span></h3>
1062 <div class="inside">
1063 <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>
1064 <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>
1065 </div>
1066 </div>
1067 <?php
1068 endif;
1069 ?>
1070 <div id="metabox_basic_settings" class="postbox" >
1071 <h3 class="hndle" style="padding:5px;"><span><?php _e( 'Troubleshoot Section', 'codepeople-post-map' ); ?></span></h3>
1072 <div class="inside">
1073 <table class="form-table cpm-settings">
1074 <tr>
1075 <td>
1076 <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'); ?>
1077 </td>
1078 </tr>
1079 </table>
1080 </div>
1081 </div>
1082 <script>
1083 jQuery(function(){
1084 jQuery('.cpm_thumbnail_admin').on('mouseover',function(){jQuery(this).width(300).height(300);}).on('mouseout',function(){jQuery(this).width(100).height(100);});
1085 });
1086 </script>
1087 <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>
1088 <div class="submit"><input type="submit" class="button-primary" value="<?php esc_attr_e(__('Update Settings', 'codepeople-post-map'));?>" /></div>
1089 <?php
1090 // create a custom nonce for submit verification later
1091 echo '<input type="hidden" name="cpm_map_noncename" value="' . wp_create_nonce(__FILE__) . '" />';
1092 ?>
1093 </form>
1094 </div>
1095 <?php
1096 } // End settings_page
1097
1098 //---------- SHORTCODE METHODS ----------
1099
1100 /*
1101 * Populate the attribute points
1102 */
1103 function populate_points($post_id){
1104 if( is_admin() ) return;
1105
1106 $point = get_post_meta($post_id, 'cpm_point', TRUE);
1107 if(!empty($point)){
1108 if(is_string($point))
1109 {
1110 $tmp_point = @unserialize($point);
1111 if($tmp_point !== false) $point = $tmp_point;
1112 }
1113
1114 if( !is_array( $point ) )
1115 {
1116 $point = array( 'address' => $point );
1117 }
1118 $point['post_id'] = $post_id;
1119 if(!in_array($point, $this->points)){
1120 $this->points[] = $point;
1121 }
1122 }
1123 else
1124 {
1125 $latitude = apply_filters('cpm-post-latitude', '', $post_id);
1126 $longitude = apply_filters('cpm-post-longitude', '', $post_id);
1127 $address = apply_filters('cpm-post-address', '', $post_id);
1128
1129 if( (!empty( $latitude ) && !empty( $longitude )) || !empty($address))
1130 {
1131 $point = array();
1132 if(!empty( $latitude ) && !empty( $longitude ))
1133 {
1134 $point['latitude'] = $latitude;
1135 $point['longitude'] = $longitude;
1136 }
1137 if(!empty( $address ))
1138 {
1139 $point['address'] = $address;
1140 }
1141 $point['post_id'] = $post_id;
1142 if(!in_array($point, $this->points)){
1143 $this->points[] = apply_filters('cpm-point', $point);
1144 }
1145 }
1146 }
1147 } // End populate_points
1148
1149 /*
1150 * Generates the javascript code of map points, only called from webpage of multiples posts
1151 */
1152 function print_points(){
1153 global $id;
1154
1155 $limit = abs($this->limit);
1156
1157 $str = '';
1158 $current_post = '';
1159 $count_posts = 0;
1160 $count_points = 0;
1161
1162 foreach($this->points as $point){
1163 if(!empty($limit)){
1164 if($current_post != $point['post_id']){
1165 $current_post = $point['post_id'];
1166 $count_posts++;
1167 if( $count_posts > $limit) break;
1168 if( !empty($this->defaultpost) && $this->defaultpost == $current_post )
1169 {
1170 $point[ 'default' ] = 1;
1171 $this->defaultpost = '';
1172 }
1173 }
1174 }
1175
1176 $str .= $this->_set_map_point($point, $count_points);
1177 $count_points++;
1178 }
1179 if(strlen($str))
1180 {
1181 $str = "<script>if(typeof cpm_global != 'undefined' && typeof cpm_global['".$this->map_id."'] != 'undefined' && typeof cpm_global['".$this->map_id."']['markers'] != 'undefined'){ ".$str." }</script>";
1182 }
1183
1184 $this->points = array();
1185 print $str;
1186 } // End print_points
1187
1188 /**
1189 * Replace each [codepeople-post-map] shortcode by the map
1190 */
1191 function replace_shortcode($atts){
1192 if(defined( 'REST_REQUEST' )) return;
1193 global $post, $id, $cpm_objs, $cpm_in_loop;
1194
1195 // Load the plugin resources
1196 $this->load_resources();
1197
1198 $cpm_obj = new CPM;
1199 $cpm_objs[] = $cpm_obj;
1200
1201 if(is_array($atts)) $cpm_obj->extended = $atts;
1202
1203 if( !empty( $atts[ 'defaultpost' ] ) ) $cpm_obj->defaultpost = str_replace( ' ', '', $atts[ 'defaultpost' ] );
1204
1205 if( isset($id) && ( is_singular() || !empty( $cpm_in_loop ) ) ){
1206 $cpm_map = get_post_meta($id, 'cpm_map', TRUE);
1207 }
1208
1209 if(empty($cpm_map)){
1210 $cpm_map = $cpm_obj->get_configuration_option();
1211 }
1212
1213 if(!empty($cpm_map['points'])){
1214 $cpm_obj->limit = $cpm_map['points'];
1215 }
1216
1217 if( !empty( $atts[ 'points' ] ) )
1218 {
1219 $atts[ 'points' ] = trim( $atts[ 'points' ] );
1220 if( is_numeric( $atts[ 'points' ] ) && $atts[ 'points' ] > 0 ) $cpm_obj->limit = $atts[ 'points' ];
1221 }
1222
1223 $cpm_map[ 'tooltip' ] = $this->get_configuration_option('tooltip');
1224
1225 if( isset( $atts[ 'tooltip' ] ) )
1226 {
1227 $cpm_map[ 'tooltip' ] = trim($atts[ 'tooltip' ]);
1228 }
1229
1230 if( isset($id) && ( is_singular() || !empty( $cpm_in_loop ) ) ){ // For maps in a post or page
1231 // Set the actual post only to avoid duplicates
1232 $posts = array( $id );
1233
1234 $query_arg = array(
1235 'meta_query' => array(
1236 'relation' => 'OR',
1237 array(
1238 'key' => 'cpm_point'
1239 ),
1240 ),
1241 'post_status' => 'publish',
1242 'orderby' => 'post_date',
1243 'order' => 'DESC',
1244 'cache_results' => false,
1245 'fields' => 'ids',
1246 'post__not_in' => array( $id )
1247 );
1248
1249 /*
1250 * If the latitude and longitude or address is stored into custom fields,
1251 * it is possible to include them in the selector query
1252 * function custom_complete_query_structure($query_components)
1253 * {
1254 * $query_components[] = array(
1255 * 'key' => 'custom_address'
1256 * );
1257 * return $query_components;
1258 * }
1259 * add_filter('cpm-complete-structured-query', 'custom_complete_query_structure');
1260 */
1261 $query_arg['meta_query'] = apply_filters('cpm-complete-structured-query', $query_arg['meta_query']);
1262
1263 if( !empty($cpm_obj->limit) ){
1264 $query_arg[ 'numberposts' ] = $cpm_obj->limit - 1;
1265 }
1266
1267 // Get POSTs in the same category
1268 $categories = get_the_category();
1269 $categories_ids = array();
1270 foreach($categories as $category){
1271 array_push( $categories_ids, $category->term_id);
1272 }
1273
1274 if( !empty( $categories_ids ) ){
1275 $query_arg[ 'category' ] = implode( ',', $categories_ids );
1276 }
1277
1278 $posts = array_merge( $posts, get_posts( $query_arg ) );
1279
1280 // WMPL
1281 $wpml_option = $this->get_configuration_option( 'wpml' );
1282 if(function_exists( 'icl_object_id' )) $current_lang = apply_filters( 'wpml_current_language', NULL );
1283
1284 foreach( $posts as $_post){
1285 if(function_exists( 'icl_object_id' )) {
1286 $post_language_information = apply_filters( 'wpml_post_language_details', NULL, $_post );
1287 $language = $post_language_information["language_code"];
1288 if(
1289 $language != $current_lang &&
1290 ! empty( $wpml_option ) &&
1291 'some' == $wpml_option
1292 ) continue;
1293 }
1294 $cpm_obj->populate_points($_post);
1295 }
1296
1297 }else{
1298 $cpm_obj->multiple = true;
1299 }
1300
1301 $output = $cpm_obj->_set_map_tag($cpm_map);
1302 $output .= $cpm_obj->_set_map_config($cpm_map);
1303
1304 $output .= "<noscript>
1305 codepeople-post-map require JavaScript
1306 </noscript>
1307 ";
1308
1309 if( !empty( $atts['print'] ) ){
1310 print $output;
1311 $cpm_obj->print_points();
1312 return '';
1313 }
1314
1315 return $output;
1316 } // End replace_shortcode
1317
1318 function preview()
1319 {
1320 $user = wp_get_current_user();
1321 $allowed_roles = array('editor', 'administrator', 'author');
1322
1323 if(array_intersect($allowed_roles, $user->roles ))
1324 {
1325 if(
1326 !empty($_REQUEST['cpm-preview']) &&
1327 !empty($_REQUEST['post-id']) &&
1328 ($post_id = @intval($_REQUEST['post-id'])) !== 0
1329 )
1330 {
1331 // Sanitizing variable
1332 $preview = stripcslashes($_REQUEST['cpm-preview']);
1333 $preview = strip_tags($preview);
1334
1335 // Remove every shortcode that is not in the music store list
1336 remove_all_shortcodes();
1337 add_shortcode('codepeople-post-map', array(&$this, 'replace_shortcode'));
1338 get_post($post_id);
1339
1340 if(has_shortcode($preview, 'codepeople-post-map'))
1341 {
1342 // To indicate in the replace_shortcode that should be used the particular settings.
1343 global $id, $cpm_in_loop;
1344 $id = $post_id;
1345 $cpm_in_loop = true;
1346
1347 // Includes the print attribute in the shortcode
1348 $preview = preg_replace('/(\[codepeople\-post\-map)/i', '$1 print="1" ', $preview);
1349 wp_head();
1350 print '<div class="cpm-preview-container">'.do_shortcode($preview).'</div>';
1351
1352 if(
1353 function_exists('wp_print_styles') &&
1354 function_exists('wp_print_scripts')
1355 )
1356 {
1357 wp_print_styles();
1358 wp_print_scripts();
1359 }
1360 else
1361 {
1362 wp_footer();
1363 }
1364 print'<script type="text/javascript">jQuery(window).on("load", function(){
1365 var frameEl = window.frameElement,
1366 cpm = jQuery(".cpm-map:visible");
1367 if(frameEl)
1368 frameEl.height = cpm.outerHeight(true)+5;
1369 });</script>';
1370 exit;
1371 }
1372 }
1373 }
1374 } // End preview
1375
1376 /*
1377 * Generates the DIV tag where the map will be loaded
1378 */
1379 function _set_map_tag($atts){
1380 $atts = array_merge($atts, $this->extended);
1381 extract($atts);
1382
1383 if(isset($width))
1384 {
1385 $width = trim($width);
1386 if(is_numeric($width)) $width .= 'px';
1387 }
1388 else $width = '100%';
1389
1390 if(isset($height))
1391 {
1392 $height = trim($height);
1393 if(is_numeric($height)) $height .= 'px';
1394 }
1395 else $height = '500px';
1396
1397 $output ='<div id="'.$this->map_id.'" class="cpm-map" style="display:none; width:'.esc_attr($width).'; height:'.esc_attr($height).'; ';
1398
1399 if(!isset($align)) $align = 'center';
1400 if(!isset($margin)) $margin = 0;
1401
1402 switch ($align) {
1403 case "left" :
1404 $output .= 'float:left; margin:'.esc_attr($margin).'px;"';
1405 break;
1406 case "right" :
1407 $output .= 'float:right; margin:'.esc_attr($margin).'px;"';
1408 break;
1409 case "center" :
1410 default:
1411 $output .= 'clear:both; overflow:hidden; margin:'.esc_attr($margin).'px auto;"';
1412 break;
1413 }
1414 $output .= "></div>";
1415 return $output;
1416 } // End _set_map_tag
1417
1418 /*
1419 * Generates the javascript tag with map configuration
1420 */
1421 function _set_map_config($atts){
1422 $atts = array_merge($atts, $this->extended);
1423
1424 extract($atts);
1425
1426 if(!isset($display)) $display = 'map';
1427 if(!isset($type)) $type = 'ROADMAP';
1428
1429 $default_language = $this->get_configuration_option('language');
1430 $output = "<script type=\"text/javascript\">\n";
1431
1432 if(isset($language))
1433 $output .= 'var cpm_language = {"lng":"'.esc_js($language).'"};';
1434 elseif(isset($default_language))
1435 $output .= 'var cpm_language = {"lng":"'.esc_js($default_language).'"};';
1436
1437 $api_key = $this->get_configuration_option( 'api_key' );
1438 $output .= "var cpm_api_key = '".esc_js((!empty( $api_key ))?trim($api_key) :'')."';\n";
1439
1440 $output .= "var cpm_global = cpm_global || {};\n";
1441 $output .= "cpm_global['$this->map_id'] = {}; \n";
1442 $output .= "cpm_global['$this->map_id']['zoom'] = ".((!empty($zoom)) ? @intval($zoom) : $this->_default_configuration('zoom')).";\n";
1443 $output .= "cpm_global['$this->map_id']['dynamic_zoom'] = ".((isset($dynamic_zoom) && $dynamic_zoom) ? 'true' : 'false').";\n";
1444 $output .= "cpm_global['$this->map_id']['markers'] = new Array();\n";
1445 $output .= "cpm_global['$this->map_id']['display'] = '$display';\n";
1446 $output .= "cpm_global['$this->map_id']['drag_map'] = ".( ( !isset( $drag_map ) || $drag_map ) ? 'true' : 'false' ).";\n";
1447 $output .= "cpm_global['$this->map_id']['highlight_class'] = '".$this->get_configuration_option('highlight_class')."';\n";
1448
1449 if(isset($tooltip))
1450 $output .= "cpm_global['$this->map_id']['marker_title'] = '".esc_js($tooltip)."';\n";
1451
1452 $highlight = $this->get_configuration_option('highlight');
1453 $output .= "cpm_global['$this->map_id']['highlight'] = ".(($highlight && !is_singular()) ? 'true' : 'false').";\n";
1454 $output .= "cpm_global['$this->map_id']['type'] = '$type';\n";
1455 $output .= "cpm_global['$this->map_id']['show_window'] = ".((isset($show_window) && $show_window) ? 'true' : 'false').";\n";
1456 $output .= "cpm_global['$this->map_id']['show_default'] = ".((isset($show_default) && $show_default) ? 'true' : 'false').";\n";
1457
1458 // Set maps centre
1459 if( !empty( $center ) )
1460 {
1461 $output .= "cpm_global['$this->map_id']['center'] = [".trim( $center )."];\n";
1462 }
1463
1464 // Define controls
1465 $output .= "cpm_global['$this->map_id']['mousewheel'] = ".((isset($mousewheel) && $mousewheel) ? 'true' : 'false').";\n";
1466 $output .= "cpm_global['$this->map_id']['zoompancontrol'] = ".((isset($zoompancontrol) && $zoompancontrol) ? 'true' : 'false').";\n";
1467 $output .= "cpm_global['$this->map_id']['fullscreencontrol'] = ".((isset($fullscreencontrol) && $fullscreencontrol) ? 'true' : 'false').";\n";
1468 $output .= "cpm_global['$this->map_id']['typecontrol'] = ".((isset($typecontrol) && $typecontrol) ? 'true' : 'false').";\n";
1469 $output .= "cpm_global['$this->map_id']['streetviewcontrol'] = ".((isset($streetviewcontrol) && $streetviewcontrol) ? 'true' : 'false').";\n";
1470 $output .= "cpm_global['$this->map_id']['trafficlayer'] = ".((isset($trafficlayer) && $trafficlayer) ? 'true' : 'false').";\n";
1471 $output .= "</script>";
1472
1473 return $output;
1474 } // End _set_map_config
1475
1476 /*
1477 * Generates the javascript code of map points
1478 */
1479 function _set_map_point($point, $index){
1480 if(
1481 empty( $point['address'] ) &&
1482 empty( $point['latitude'] ) &&
1483 empty( $point['longitude'] )
1484 ) return;
1485
1486 $icon = (!empty($point['icon'])) ? $point['icon'] : $this->get_configuration_option('default_icon');
1487 if( preg_match( '/http(s)?:\/\//i', $icon ) == 0 ) $icon = CPM_PLUGIN_URL.$icon;
1488 $obj = new stdClass;
1489 $obj->address = str_replace(array('&quot;', '&lt;', '&gt;', '&#039;', '&amp;'), array('\"', '<', '>', "'", '&'), ( ( empty( $point['address'] ) ) ? '' : $point['address'] ) );
1490
1491 if(!empty($point['latitude']) ) $obj->lat = $point['latitude'];
1492 if(!empty($point['longitude']) )$obj->lng = $point['longitude'];
1493
1494 $obj->info = str_replace(array('&quot;', '&lt;', '&gt;', '&#039;', '&amp;'), array('\"', '<', '>', "'", '&'), $this->_get_windowhtml($point));
1495
1496 $obj->icon = $icon;
1497 $obj->post = $point['post_id'];
1498 $obj->default = ( !empty( $point[ 'default' ] ) ) ? true : false;
1499 return 'cpm_global["'.$this->map_id.'"]["markers"]['.$index.'] = '.json_encode( $obj ).';';
1500 } // End _set_map_point
1501
1502 function _get_img_id($url){
1503 global $wpdb;
1504 $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM " . $wpdb->prefix . "posts" . " WHERE guid='%s';", $url ));
1505 return $attachment[0];
1506 } // End get_img_id
1507
1508 /**
1509 * Get the html info associated to point marker
1510 */
1511 function _get_windowhtml(&$point) {
1512
1513 $windowhtml = "";
1514 $windowhtml_frame = $this->get_configuration_option('windowhtml');
1515 $windowhtml_frame = apply_filters('cpm-point-infowindow-template', $windowhtml_frame, $point);
1516
1517 $point_title = (!empty($point['name'])) ? $point['name'] : get_the_title($point['post_id']);
1518 $point_link = (!empty($point['post_id'])) ? get_permalink($point['post_id']) : '';
1519 $point_img_url = '';
1520
1521 if (isset($point['thumbnail']) && !empty($point['thumbnail'])) {
1522 $point_img_url = $point['thumbnail'];
1523 if(preg_match("/attachment_id=(\d+)/i", $point['thumbnail'], $matches)){
1524 $thumb = wp_get_attachment_image_src($matches[1], 'thumbnail');
1525 if(is_array($thumb))$point_thumbnail = $thumb[0];
1526 }else{
1527 $point_thumbnail = $point['thumbnail'];
1528 }
1529 if( !empty( $point_thumbnail ) ) $point_img_url = $point_thumbnail;
1530 }else
1531 {
1532 $featured_image = $this->get_configuration_option( 'featured_image' );
1533 if( !empty( $featured_image ) )
1534 {
1535 $featured_image_url = wp_get_attachment_url( get_post_thumbnail_id( $point['post_id'] ) );
1536 if( $featured_image_url ) $point_img_url = $featured_image_url;
1537 }
1538 }
1539
1540 $point_img_url = apply_filters('cpm-point-image', $point_img_url, $point['post_id']);
1541
1542 $point_description = apply_filters('cpm-point-description', ( !empty( $point['description'] ) ) ? $point['description'] : $this->_get_excerpt($point['post_id']), $point['post_id']);
1543
1544 $point_address = apply_filters('cpm-point-address', isset( $point['address'] ) ? $point['address'] : '', $point['post_id']);
1545
1546 if( !empty( $point_img_url ) ) {
1547 $point_img = "<img src='".$point_img_url."' class='cpm-thumbnail' style='margin:8px 0 0 8px !important; width:90px; height:90px' align='right' />";
1548 $html_width = "310px";
1549 } else {
1550 $point_img = "";
1551 $html_width = "auto";
1552 }
1553
1554 $find = array("%title%","%link%","%thumbnail%", "%excerpt%","%description%","%address%","%width%","\r\n","\f","\v","\t","\r","\n","\\","\"");
1555 $replace = array($point_title,$point_link,$point_img,"",do_shortcode($point_description),$point_address,$html_width,"","","","","","","","'");
1556
1557 $windowhtml = str_replace( $find, $replace, $windowhtml_frame);
1558
1559 return apply_filters('cpm-point-infowindow', $windowhtml, $point);
1560 } // End _get_windowhtml
1561
1562 /**
1563 * Get the excerpt from content
1564 */
1565 function _get_excerpt($post_id) { // Fakes an excerpt if needed
1566
1567 $content_post = get_post($post_id);
1568 $content = $content_post->post_content;
1569
1570 if ( '' != $content ) {
1571 return wp_trim_words( strip_shortcodes( $content ), 10 );
1572 }
1573 return $content;
1574 } // End _get_excerpt
1575
1576 /*
1577 Set a link to contact page
1578 */
1579 function customizationLink($links) {
1580 $settings_link = '<a href="https://wordpress.org/support/plugin/codepeople-post-map/#new-post" target="_blank">'.__('Help').'</a>';
1581 array_unshift($links, $settings_link);
1582 $settings_link = '<a href="http://wordpress.dwbooster.com/contact-us" target="_blank">'.__('Request custom changes', 'codepeople-post-map').'</a>';
1583 array_unshift($links, $settings_link);
1584 return $links;
1585 } // End customizationLink
1586
1587 public static function troubleshoot($option)
1588 {
1589 if(!is_admin())
1590 {
1591 // Solves a conflict caused by the "Speed Booster Pack" plugin
1592 if(is_array($option) && isset($option['jquery_to_footer'])) unset($option['jquery_to_footer']);
1593 }
1594 return $option;
1595 }
1596 } // End CPM class
1597 ?>