PluginProbe
Leaflet Map / 3.0.5
Leaflet Map v3.0.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 3.0.5, at class.plugin-option.php

171 lines 3.9 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' => null
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="<?php echo $this->type; ?>"
103 id="<?php echo $name; ?>"
104 value="<?php echo htmlspecialchars($value); ?>"
105 />
106 <?php
107 break;
108
109
110 case 'number':
111 ?>
112 <input
113 class="full-width"
114 step="any"
115 name="<?php echo $name; ?>"
116 type="<?php echo $this->type; ?>"
117 id="<?php echo $name; ?>"
118 value="<?php echo htmlspecialchars($value); ?>"
119 />
120 <?php
121 break;
122
123 case 'textarea':
124 ?>
125
126 <textarea
127 id="<?php echo $name; ?>"
128 class="full-width"
129 name="<?php echo $name; ?>"><?php echo htmlspecialchars($value); ?></textarea>
130
131 <?php
132 break;
133
134 case 'checkbox':
135 ?>
136
137 <input
138 class="checkbox"
139 name="<?php echo $name; ?>"
140 type="checkbox"
141 id="<?php echo $name; ?>"
142 <?php if ($value) echo ' checked="checked"' ?>
143 />
144 <?php
145 break;
146
147 case 'select':
148 ?>
149 <select id="<?php echo $name; ?>"
150 name="<?php echo $name; ?>"
151 class="full-width">
152 <?php
153 foreach ($this->options as $o => $n) {
154 ?>
155 <option value="<?php echo $o; ?>"<?php if ($value == $o) echo ' selected' ?>>
156 <?php echo $n; ?>
157 </option>
158 <?php
159 }
160 ?>
161 </select>
162 <?php
163 break;
164 default:
165 ?>
166 <div>No option type chosen for <?php echo $name; ?> with value <?php echo htmlspecialchars($value); ?></div>
167 <?php
168 break;
169 }
170 }
171 }