| 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 |
| 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($atts, $content); |
| 51 |
return $instance->getHTML($atts, $content); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Create an LM variable for each shortcode class |
| 56 |
* instance |
| 57 |
*/ |
| 58 |
protected function __construct() |
| 59 |
{ |
| 60 |
$this->LM = Leaflet_Map::init(); |
| 61 |
} |
| 62 |
} |