PluginProbe
Leaflet Map / 2.10.0
Leaflet Map v2.10.0
3.4.7 3.4.6 trunk 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.11.5 2.12.0 2.13.0 2.14.0 2.15.0 2.16.0 2.16.1 2.16.2 2.17.0 2.17.1 2.17.2 2.17.3 2.18.0 2.19.0 2.19.1 All 49 releases
leaflet-map / shortcodes / class.line-shortcode.php

class.line-shortcode.php in Leaflet Map 2.10.0, at shortcodes/class.line-shortcode.php

80 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Line Shortcode
4 *
5 * Use with [leaflet-line ...]
6 *
7 * @param array $atts user-input array
8 * @param string $content user-input content (allows HTML)
9 * @return string content for post/page
10 */
11
12 // Exit if accessed directly
13 if ( !defined( 'ABSPATH' ) ) exit;
14
15 include_once(LEAFLET_MAP__PLUGIN_DIR . 'shortcodes/class.shortcode.php');
16
17 class Leaflet_Line_Shortcode extends Leaflet_Shortcode {
18 protected function getHTML ($atts='', $content=null) {
19 if (!empty($atts)) extract($atts);
20
21 $style_json = $this->LM->get_style_json( $atts );
22
23 $fitbounds = empty($fitbounds) ? 0 : $fitbounds;
24
25 // backwards compatible `fitline`
26 if (!empty($fitline)) {
27 $fitbounds = $fitline;
28 }
29
30 $locations = Array();
31
32 if (!empty($addresses)) {
33 include_once(LEAFLET_MAP__PLUGIN_DIR . 'class.geocoder.php');
34 $addresses = preg_split('/\s?[;|\/]\s?/', $addresses);
35 foreach ($addresses as $address) {
36 if (trim($address)) {
37 $location = new Leaflet_Geocoder( $address );
38 $locations[] = Array($location->lat, $location->lng);
39 }
40 }
41 } else if (!empty($latlngs)) {
42 $latlngs = preg_split('/\s?[;|\/]\s?/', $latlngs);
43 foreach ($latlngs as $latlng) {
44 if (trim($latlng)) {
45 $locations[] = array_map('floatval', preg_split('/\s?,\s?/', $latlng));
46 }
47 }
48 } else if (!empty($coordinates)) {
49 $coordinates = preg_split('/\s?[;|\/]\s?/', $coordinates);
50 foreach ($coordinates as $xy) {
51 if (trim($xy)) {
52 $locations[] = array_map('floatval', preg_split('/\s?,\s?/', $xy));
53 }
54 }
55 }
56
57 $location_json = json_encode($locations);
58 ob_start();
59 ?>
60 <script>
61 WPLeafletMapPlugin.add(function () {
62 var previous_map = WPLeafletMapPlugin.getCurrentMap(),
63 line = L.polyline(<?php echo $location_json; ?>, <?php echo $style_json; ?>),
64 fitbounds = <?php echo $fitbounds; ?>;
65 line.addTo( previous_map );
66 if (fitbounds) {
67 // zoom the map to the polyline
68 previous_map.fitBounds( line.getBounds() );
69 }
70 <?php
71 $this->LM->add_popup_to_shape($atts, $content, 'line');
72 ?>
73 WPLeafletMapPlugin.lines.push( line );
74 });
75 </script>
76 <?php
77
78 return ob_get_clean();
79 }
80 }