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
leaflet-map / shortcodes / class.scale-shortcode.php

class.scale-shortcode.php in Leaflet Map 3.4.5, at shortcodes/class.scale-shortcode.php

70 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }