| 1 |
<?php |
| 2 |
/** |
| 3 |
* Scale Shortcode |
| 4 |
* |
| 5 |
* Use with [leaflet-scale ...] |
| 6 |
* |
| 7 |
* @category Shortcode |
| 8 |
* @author Benjamin J DeLong <ben@bozdoz.com> |
| 9 |
*/ |
| 10 |
|
| 11 |
// Exit if accessed directly |
| 12 |
if (!defined('ABSPATH')) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
require_once LEAFLET_MAP__PLUGIN_DIR . 'shortcodes/class.shortcode.php'; |
| 17 |
|
| 18 |
/** |
| 19 |
* Leaflet Scale Shortcode Class |
| 20 |
*/ |
| 21 |
class Leaflet_Scale_Shortcode extends Leaflet_Shortcode |
| 22 |
{ |
| 23 |
/** |
| 24 |
* Get Script for Shortcode |
| 25 |
* |
| 26 |
* @param string $atts shortcode attributes |
| 27 |
* @param string $content optional |
| 28 |
* |
| 29 |
* @return string HTML |
| 30 |
*/ |
| 31 |
protected function getHTML($atts='', $content=null) |
| 32 |
{ |
| 33 |
if (!empty($atts)) { |
| 34 |
extract($atts, EXTR_SKIP); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Options: |
| 39 |
* https://leafletjs.com/reference.html#control-scale |
| 40 |
*/ |
| 41 |
|
| 42 |
$options = array( |
| 43 |
'maxWidth' => isset($maxwidth) ? $maxwidth : null, |
| 44 |
'metric' => isset($metric) ? $metric : null, |
| 45 |
'imperial' => isset($imperial) ? $imperial : null, |
| 46 |
'updateWhenIdle' => isset($updateWhenIdle) ? $updateWhenIdle : null, |
| 47 |
'position' => isset($position) ? $position : null |
| 48 |
); |
| 49 |
|
| 50 |
$filters = array( |
| 51 |
'maxWidth' => FILTER_VALIDATE_INT, |
| 52 |
'metric' => FILTER_VALIDATE_BOOLEAN, |
| 53 |
'imperial' => FILTER_VALIDATE_BOOLEAN, |
| 54 |
'updateWhenIdle' => FILTER_VALIDATE_BOOLEAN, |
| 55 |
'position' => FILTER_SANITIZE_FULL_SPECIAL_CHARS |
| 56 |
); |
| 57 |
|
| 58 |
$options = $this->LM->json_sanitize($options, $filters); |
| 59 |
|
| 60 |
$script = "window.WPLeafletMapPlugin.createScale($options);"; |
| 61 |
|
| 62 |
if (isset($noScriptWrap)) { |
| 63 |
// don't wrap script |
| 64 |
// (probably already wrapped in map-shortcode) |
| 65 |
return $script; |
| 66 |
} |
| 67 |
|
| 68 |
return $this->wrap_script($script, 'WPLeafletScaleShortcode'); |
| 69 |
} |
| 70 |
} |