PluginProbe
Leaflet Map / 3.4.5
Leaflet Map v3.4.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
← All changes | shortcodes/class.shortcode.php +34 -8 2.16.23.4.5 View file →
@@ -1,10 +1,8 @@
1 1 <?php
2 2 /**
3 3 * Abstract Shortcode
4 4 *
5 - * PHP Version 5.5
6 - *
7 5 * @category Shortcode
8 6 * @author Benjamin J DeLong <ben@bozdoz.com>
9 7 */
10 8
@@ -15,8 +13,11 @@
15 13 * extend and manipulate __construct
16 14 */
17 15 abstract class Leaflet_Shortcode
18 16 {
17 + /**
18 + * @var Leaflet_Map
19 + */
19 20 protected $LM;
20 21
21 22 /**
22 23 * Generate HTML from the shortcode
@@ -38,12 +39,12 @@
38 39
39 40 /**
40 41 * Instantiate class and get HTML for shortcode
41 42 *
42 - * @param array $atts string|array
43 - * @param string $content Optional
43 + * @param array|string|null $atts string|array
44 + * @param string|null $content Optional
44 45 *
45 - * @return string (see above)
46 + * @return string HTML
46 47 */
47 48 public static function shortcode($atts = '', $content = null)
48 49 {
49 50 $class = self::getClass();
@@ -62,18 +63,43 @@
62 63 !key_exists($v, $atts) &&
63 64 !!$v
64 65 ) {
65 66 // false if starts with !, else true
66 - if ($v[0] == '!') {
67 - $atts[substr($v, 1)] = 0;
67 + if ($v[0] === '!') {
68 + $k = substr($v, 1);
69 + $v = 0;
68 70 } else {
69 - $atts[$v] = 1;
71 + $k = $v;
72 + $v = 1;
70 73 }
74 + $atts[$k] = $v;
71 75 }
76 + // change hyphens to underscores for `extract()`
77 + if (strpos($k, '-')) {
78 + $k = str_replace('-', '_', $k);
79 + $atts[$k] = $v;
80 + }
72 81 }
73 82 }
74 83
75 84 return $instance->getHTML($atts, $content);
85 + }
86 +
87 + /**
88 + * Wrap Javascript output with common function and tags
89 + *
90 + * @param string $script JavaScript
91 + * @param string $name string name of function
92 + *
93 + * @return string JavaScript
94 + */
95 + protected function wrap_script($script, $name="")
96 + {
97 + ob_start();
98 + ?><script>
99 +window.WPLeafletMapPlugin = window.WPLeafletMapPlugin || [];
100 +window.WPLeafletMapPlugin.push(function <?php echo $name; ?>() {<?php echo $script; ?>});</script><?php
101 + return ob_get_clean();
76 102 }
77 103
78 104 /**
79 105 * Create an LM variable for each shortcode class