PluginProbe
Leaflet Map / 2.11.5
Leaflet Map v2.11.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 / class.plugin-option.php

class.plugin-option.php in Leaflet Map 2.11.5, at class.plugin-option.php

157 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Leaflet_Map_Plugin_Option
4 *
5 * Store values; render widgets
6 *
7 * PHP Version 5.5
8 *
9 * @category Shortcode
10 * @author Benjamin J DeLong <ben@bozdoz.com>
11 */
12
13 // Exit if accessed directly
14 if (!defined('ABSPATH')) {
15 exit;
16 }
17
18 /**
19 * Leaflet_Map_Plugin_Option
20 */
21 class Leaflet_Map_Plugin_Option
22 {
23 /**
24 * Default Value
25 *
26 * @var varies $default
27 */
28 public $default = '';
29
30 /**
31 * Input type ex: ('text', 'select', 'checkbox')
32 *
33 * @var string $type
34 */
35 public $type;
36
37 /**
38 * Optional used for select; maybe checkbox/radio
39 *
40 * @var array $options
41 */
42 public $options = array();
43
44 /**
45 * Optional used for label under input
46 *
47 * @var string $helptext
48 */
49 public $helptext = '';
50
51 /**
52 * Instantiate class
53 *
54 * @param array $details A list of options
55 */
56 function __construct($details = array())
57 {
58 if (!$details) {
59 // just an empty db entry (for now)
60 // nothing to store, nothing to render
61 return;
62 }
63
64 $option_filter = array(
65 'display_name' => FILTER_SANITIZE_STRING,
66 'default' => null,
67 'type' => FILTER_SANITIZE_STRING,
68 'options' => array(
69 'filter' => FILTER_SANITIZE_STRING,
70 'flags' => FILTER_FORCE_ARRAY
71 ),
72 'helptext' => FILTER_SANITIZE_STRING
73 );
74
75 // get matching keys only
76 $details = array_intersect_key($details, $option_filter);
77
78 // apply filter
79 $details = filter_var_array($details, $option_filter);
80
81 foreach ($details as $key => $value) {
82 $this->$key = $value;
83 }
84 }
85
86 /**
87 * Renders a widget
88 *
89 * @param string $name widget name
90 * @param varies $value widget value
91 *
92 * @return HTML
93 */
94 function widget ($name, $value)
95 {
96 switch ($this->type) {
97 case 'text':
98 ?>
99 <input
100 class="full-width"
101 name="<?php echo $name; ?>"
102 type="text"
103 id="<?php echo $name; ?>"
104 value="<?php echo htmlspecialchars($value); ?>"
105 />
106 <?php
107 break;
108
109 case 'textarea':
110 ?>
111
112 <textarea
113 id="<?php echo $name; ?>"
114 class="full-width"
115 name="<?php echo $name; ?>"><?php echo htmlspecialchars($value); ?></textarea>
116
117 <?php
118 break;
119
120 case 'checkbox':
121 ?>
122
123 <input
124 class="checkbox"
125 name="<?php echo $name; ?>"
126 type="checkbox"
127 id="<?php echo $name; ?>"
128 <?php if ($value) echo ' checked="checked"' ?>
129 />
130 <?php
131 break;
132
133 case 'select':
134 ?>
135 <select id="<?php echo $name; ?>"
136 name="<?php echo $name; ?>"
137 class="full-width">
138 <?php
139 foreach ($this->options as $o => $n) {
140 ?>
141 <option value="<?php echo $o; ?>"<?php if ($value == $o) echo ' selected' ?>>
142 <?php echo $n; ?>
143 </option>
144 <?php
145 }
146 ?>
147 </select>
148 <?php
149 break;
150 default:
151 ?>
152 <div>No option type chosen for <?php echo $name; ?> with value <?php echo htmlspecialchars($value); ?></div>
153 <?php
154 break;
155 }
156 }
157 }