PluginProbe
Leaflet Map / trunk
Leaflet Map vtrunk
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 trunk, at class.plugin-option.php

189 lines 4.8 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 * All properties that we will be setting
53 */
54 public $display_name = '';
55 public $min = 0;
56 public $max = 0;
57 public $step = 0;
58 public $placeholder = '';
59
60 /**
61 * Instantiate class
62 *
63 * @param array $details A list of options
64 */
65 function __construct($details = array())
66 {
67 if (!$details) {
68 // just an empty db entry (for now)
69 // nothing to store, nothing to render
70 return;
71 }
72
73 $option_filter = array(
74 'display_name' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
75 'default' => FILTER_DEFAULT,
76 'type' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
77 'min' => FILTER_DEFAULT,
78 'max' => FILTER_DEFAULT,
79 'step' => FILTER_DEFAULT,
80 'placeholder' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
81 'options' => array(
82 'filter' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
83 'flags' => FILTER_FORCE_ARRAY
84 ),
85 'helptext' => FILTER_DEFAULT
86 );
87
88 // get matching keys only
89 $details = array_intersect_key($details, $option_filter);
90
91 // apply filter
92 $details = filter_var_array($details, $option_filter);
93
94 foreach ($details as $key => $value) {
95 $this->$key = $value;
96 }
97 }
98
99 /**
100 * Renders a widget
101 *
102 * @param string $name widget name
103 * @param varies $value widget value
104 *
105 * @return HTML
106 */
107 function widget ($name, $value)
108 {
109 switch ($this->type) {
110 case 'text':
111 case 'email':
112 ?>
113 <input
114 class="full-width"
115 name="<?php echo esc_attr( $name ); ?>"
116 type="<?php echo esc_attr( $this->type ); ?>"
117 id="<?php echo esc_attr( $name ); ?>"
118 placeholder="<?php echo esc_attr( $this->placeholder ); ?>"
119 value="<?php echo esc_attr( $value ); ?>"
120 />
121 <?php
122 break;
123
124
125 case 'number':
126 ?>
127 <input
128 class="full-width"
129 min="<?php echo isset($this->min) ? esc_attr( $this->min ) : ""; ?>"
130 max="<?php echo isset($this->max) ? esc_attr( $this->max ) : ""; ?>"
131 step="<?php echo isset($this->step) ? esc_attr( $this->step ) : "any"; ?>"
132 name="<?php echo esc_attr( $name ); ?>"
133 type="<?php echo esc_attr( $this->type ); ?>"
134 id="<?php echo esc_attr( $name ); ?>"
135 value="<?php echo esc_attr( $value ); ?>"
136 />
137 <?php
138 break;
139
140 case 'textarea':
141 ?>
142
143 <textarea
144 id="<?php echo esc_attr( $name ); ?>"
145 class="full-width"
146 name="<?php echo esc_attr( $name ); ?>"><?php echo esc_textarea( $value ); ?></textarea>
147
148 <?php
149 break;
150
151 case 'checkbox':
152 ?>
153
154 <input
155 class="checkbox"
156 name="<?php echo esc_attr( $name ); ?>"
157 type="checkbox"
158 id="<?php echo esc_attr( $name ); ?>"
159 <?php if ($value) echo ' checked="checked"' ?>
160 />
161 <?php
162 break;
163
164 case 'select':
165 ?>
166 <select id="<?php echo esc_attr( $name ); ?>"
167 name="<?php echo esc_attr( $name ); ?>"
168 class="full-width">
169 <?php
170 foreach ($this->options as $o => $n) {
171 ?>
172 <option value="<?php echo esc_attr( $o ); ?>"<?php if ($value == $o) echo ' selected' ?>>
173 <?php echo $n; ?>
174 </option>
175 <?php
176 }
177 ?>
178 </select>
179 <?php
180 break;
181 default:
182 ?>
183 <div>No option type chosen for <?php echo esc_html( $name ); ?> with value <?php echo esc_html($value); ?></div>
184 <?php
185 break;
186 }
187 }
188 }
189