| @@ -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 |