PluginProbe
Leaflet Map / 2.11.5
Leaflet Map v2.11.5
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.11.5, at shortcodes/class.line-shortcode.php

98 lines 2.9 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 * PHP Version 5.5
8 *
9 * @category Shortcode
10 * @author Benjamin J DeLong <ben@bozdoz.com>
11 */
12
13 // Exit if accessed directly
14 if (!defined('ABSPATH')) {
15 exit;
16 }
17
18 require_once LEAFLET_MAP__PLUGIN_DIR . 'shortcodes/class.shortcode.php';
19
20 /**
21 * Leaflet Line Shortcode Class
22 */
23 class Leaflet_Line_Shortcode extends Leaflet_Shortcode
24 {
25 /**
26 * Get Script for Shortcode
27 *
28 * @param string $atts shortcode attributes
29 * @param string $content optional
30 *
31 * @return string HTML
32 */
33 protected function getHTML($atts='', $content=null)
34 {
35 if (!empty($atts)) {
36 extract($atts);
37 }
38
39 $style_json = $this->LM->get_style_json($atts);
40
41 $fitbounds = empty($fitbounds) ? 0 : $fitbounds;
42
43 // backwards compatible `fitline`
44 if (!empty($fitline)) {
45 $fitbounds = $fitline;
46 }
47
48 $locations = Array();
49
50 if (!empty($addresses)) {
51 include_once LEAFLET_MAP__PLUGIN_DIR . 'class.geocoder.php';
52 $addresses = preg_split('/\s?[;|\/]\s?/', $addresses);
53 foreach ($addresses as $address) {
54 if (trim($address)) {
55 $location = new Leaflet_Geocoder($address);
56 $locations[] = Array($location->lat, $location->lng);
57 }
58 }
59 } else if (!empty($latlngs)) {
60 $latlngs = preg_split('/\s?[;|\/]\s?/', $latlngs);
61 foreach ($latlngs as $latlng) {
62 if (trim($latlng)) {
63 $locations[] = array_map('floatval', preg_split('/\s?,\s?/', $latlng));
64 }
65 }
66 } else if (!empty($coordinates)) {
67 $coordinates = preg_split('/\s?[;|\/]\s?/', $coordinates);
68 foreach ($coordinates as $xy) {
69 if (trim($xy)) {
70 $locations[] = array_map('floatval', preg_split('/\s?,\s?/', $xy));
71 }
72 }
73 }
74
75 $location_json = json_encode($locations);
76 ob_start();
77 ?>
78 <script>
79 window.WPLeafletMapPlugin = window.WPLeafletMapPlugin || [];
80 window.WPLeafletMapPlugin.push(function () {
81 var previous_map = window.WPLeafletMapPlugin.getCurrentMap(),
82 line = L.polyline(<?php echo $location_json; ?>, <?php echo $style_json; ?>),
83 fitbounds = <?php echo $fitbounds; ?>;
84 line.addTo( previous_map );
85 if (fitbounds) {
86 // zoom the map to the polyline
87 previous_map.fitBounds( line.getBounds() );
88 }
89 <?php
90 $this->LM->add_popup_to_shape($atts, $content, 'line');
91 ?>
92 window.WPLeafletMapPlugin.lines.push( line );
93 });
94 </script>
95 <?php
96 return ob_get_clean();
97 }
98 }