PluginProbe
Leaflet Map / 2.17.0
Leaflet Map v2.17.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.shortcode.php

class.shortcode.php in Leaflet Map 2.17.0, at shortcodes/class.shortcode.php

94 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Abstract Shortcode
4 *
5 * PHP Version 5.5
6 *
7 * @category Shortcode
8 * @author Benjamin J DeLong <ben@bozdoz.com>
9 */
10
11 /**
12 * Abstract Shortcode Class
13 *
14 * Use with add_shortcode('leaflet-map', array ('Leaflet_Shortcode', 'shortcode'))
15 * extend and manipulate __construct
16 */
17 abstract class Leaflet_Shortcode
18 {
19 protected $LM;
20
21 /**
22 * Generate HTML from the shortcode
23 * Maybe won't always be required
24 *
25 * @param array $atts string
26 * @param string $content Optional
27 *
28 * @since 2.8.2
29 *
30 * @return string (typically, return a script tag with Leaflet logic)
31 */
32 abstract protected function getHTML($atts='', $content=null);
33
34 public static function getClass()
35 {
36 return function_exists('get_called_class') ? get_called_class() : __CLASS__;
37 }
38
39 /**
40 * Instantiate class and get HTML for shortcode
41 *
42 * @param array $atts string|array
43 * @param string $content Optional
44 *
45 * @return string (see above)
46 */
47 public static function shortcode($atts = '', $content = null)
48 {
49 $class = self::getClass();
50 $instance = new $class();
51
52 // swap sequential array with associative array
53 // this enables assumed-boolean attributes,
54 // like: [leaflet-marker draggable svg]
55 // meaning draggable=1 svg=1
56 // and: [leaflet-marker !doubleClickZoom !boxZoom]
57 // meaning doubleClickZoom=0 boxZoom=0
58 if (!empty($atts)) {
59 foreach($atts as $k => $v) {
60 if (
61 is_numeric($k) &&
62 !key_exists($v, $atts) &&
63 !!$v
64 ) {
65 // false if starts with !, else true
66 if ($v[0] === '!') {
67 $k = substr($v, 1);
68 $v = 0;
69 } else {
70 $k = $v;
71 $v = 1;
72 }
73 $atts[$k] = $v;
74 }
75 // change hyphens to underscores for `extract()`
76 if (strpos($k, '-')) {
77 $k = str_replace('-', '_', $k);
78 $atts[$k] = $v;
79 }
80 }
81 }
82
83 return $instance->getHTML($atts, $content);
84 }
85
86 /**
87 * Create an LM variable for each shortcode class
88 * instance
89 */
90 protected function __construct()
91 {
92 $this->LM = Leaflet_Map::init();
93 }
94 }