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-settings.php

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

331 lines 13.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class for getting and setting db/default values
4 *
5 * PHP Version 5.5
6 *
7 * @category Admin
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 . 'class.plugin-option.php';
17
18 /**
19 * Used to get and set values
20 *
21 * Features:
22 * * Add prefixes to db options
23 * * built-in admin settings page method
24 */
25 class Leaflet_Map_Plugin_Settings
26 {
27 /**
28 * Prefix for options, for unique db entries
29 *
30 * @var string $prefix
31 */
32 public $prefix = 'leaflet_';
33
34 /**
35 * Singleton instance
36 *
37 * @var Leaflet_Map_Plugin_Settings
38 **/
39 private static $_instance = null;
40
41 /**
42 * Default values and admin form information
43 * Needs to be created within __construct
44 * in order to use a function such as __()
45 *
46 * @var array $options
47 */
48 public $options = array();
49
50 /**
51 * Singleton
52 *
53 * @static
54 *
55 * @return Leaflet_Map_Plugin_Settings
56 */
57 public static function init() {
58 if ( !self::$_instance ) {
59 self::$_instance = new self;
60 }
61
62 return self::$_instance;
63 }
64
65 /**
66 * Instantiate the class
67 */
68 private function __construct()
69 {
70
71 /* update leaflet version from main class */
72 $leaflet_version = Leaflet_Map::$leaflet_version;
73
74 $foreachmap = __('You can also change this for each map');
75
76 /*
77 * initiate options using internationalization!
78 */
79 $this->options = array(
80 'default_lat' => array(
81 'display_name'=>__('Default Latitude', 'leaflet-map'),
82 'default'=>'44.67',
83 'type' => 'text',
84 'helptext' => sprintf(
85 '%1$s %2$s <br /> <code>[leaflet-map lat="44.67"]</code>',
86 __('Default latitude for maps.', 'leaflet-map'),
87 $foreachmap
88 )
89 ),
90 'default_lng' => array(
91 'display_name'=>__('Default Longitude', 'leaflet-map'),
92 'default'=>'-63.61',
93 'type' => 'text',
94 'helptext' => sprintf(
95 '%1$s %2$s <br /> <code>[leaflet-map lng="-63.61"]</code>',
96 __('Default longitude for maps.', 'leaflet-map'),
97 $foreachmap
98 )
99 ),
100 'default_zoom' => array(
101 'display_name'=>__('Default Zoom', 'leaflet-map'),
102 'default'=>'12',
103 'type' => 'text',
104 'helptext' => sprintf(
105 '%1$s %2$s <br /> <code>[leaflet-map zoom="5"]</code>',
106 __('Default zoom for maps.', 'leaflet-map'),
107 $foreachmap
108 )
109 ),
110 'default_height' => array(
111 'display_name'=>__('Default Height', 'leaflet-map'),
112 'default'=>'250',
113 'type' => 'text',
114 'helptext' => sprintf(
115 '%1$s %2$s <br /> <code>[leaflet-map height="250"]</code>',
116 __('Default height for maps. Values can include "px" but it is not necessary. Can also be "%". ', 'leaflet-map'),
117 $foreachmap
118 )
119 ),
120 'default_width' => array(
121 'display_name'=>__('Default Width', 'leaflet-map'),
122 'default'=>'100%',
123 'type' => 'text',
124 'helptext' => sprintf(
125 '%1$s %2$s <br /> <code>[leaflet-map width="100%"]</code>',
126 __('Default width for maps. Values can include "px" but it is not necessary. Can also be "%".', 'leaflet-map'),
127 $foreachmap
128 )
129 ),
130 'fit_markers' => array(
131 'display_name'=>__('Fit Markers', 'leaflet-map'),
132 'default' => '0',
133 'type' => 'checkbox',
134 'helptext' => sprintf(
135 '%1$s %2$s <br /> <code>[leaflet-map fit_markers="1"]</code>',
136 __('If enabled, all markers on each map will alter the view of the map; i.e. the map will fit to the bounds of all of the markers on the map.', 'leaflet-map'),
137 $foreachmap
138 )
139 ),
140 'show_zoom_controls' => array(
141 'display_name'=>__('Show Zoom Controls', 'leaflet-map'),
142 'default' => '0',
143 'type' => 'checkbox',
144 'helptext' => sprintf(
145 '%1$s %2$s <br /> <code>[leaflet-map zoomcontrol="0"]</code>',
146 __('The zoom buttons can be large and annoying.', 'leaflet-map'),
147 $foreachmap
148 )
149 ),
150 'scroll_wheel_zoom' => array(
151 'display_name'=>__('Scroll Wheel Zoom', 'leaflet-map'),
152 'default' => '0',
153 'type' => 'checkbox',
154 'helptext' => sprintf(
155 '%1$s %2$s <br /> <code>[leaflet-map scrollwheel="0"]</code>',
156 __('Disable zoom with mouse scroll wheel. Sometimes someone wants to scroll down the page, and not zoom the map.', 'leaflet-map'),
157 $foreachmap
158 )
159 ),
160 'double_click_zoom' => array(
161 'display_name'=>__('Double Click Zoom', 'leaflet-map'),
162 'default' => '0',
163 'type' => 'checkbox',
164 'helptext' => sprintf(
165 '%1$s %2$s <br /> <code>[leaflet-map doubleClickZoom=false]</code>',
166 __('If enabled, your maps will zoom with a double click. By default it is disabled: If we\'re going to remove zoom controls and have scroll wheel zoom off by default, we might as well stick to our guns and not zoom the map.', 'leaflet-map'),
167 $foreachmap
168 )
169 ),
170 'default_min_zoom' => array(
171 'display_name'=>__('Default Min Zoom', 'leaflet-map'),
172 'default' => '0',
173 'type' => 'text',
174 'helptext' => sprintf(
175 '%1$s %2$s <br /> <code>[leaflet-map min_zoom="1"]</code>',
176 __('Restrict the viewer from zooming in past the minimum zoom. Can set per map in shortcode or adjust for all maps here.', 'leaflet-map'),
177 $foreachmap
178 )
179 ),
180 'default_max_zoom' => array(
181 'display_name'=>__('Default Max Zoom', 'leaflet-map'),
182 'default' => '20',
183 'type' => 'text',
184 'helptext' => sprintf(
185 '%1$s %2%s <br /> <code>%3$s</code>',
186 __('Restrict the viewer from zooming out past the maximum zoom. Can set per map in shortcode or adjust for all maps here', 'leaflet-map'),
187 $foreachmap,
188 '[leaflet-map max_zoom="10"]'
189 )
190 ),
191 'default_tiling_service' => array(
192 'display_name'=>__('Default Tiling Service', 'leaflet-map'),
193 'default' => 'other',
194 'type' => 'select',
195 'options' => array(
196 'other' => __('I will provide my own map tile URL', 'leaflet-map'),
197 'mapquest' => __('MapQuest (I have an app key)', 'leaflet-map'),
198 ),
199 'helptext' => __('Choose a tiling service or provide your own.', 'leaflet-map')
200 ),
201 'mapquest_appkey' => array(
202 'display_name'=>__('MapQuest App Key', 'leaflet-map'),
203 'default' => __('Supply an app key if you choose MapQuest', 'leaflet-map'),
204 'type' => 'text',
205 'noreset' => true,
206 'helptext' => sprintf(
207 '%1$s <a href="https://developer.mapquest.com/plan_purchase/steps/business_edition/business_edition_free/register" target="_blank"> %2$s </a>, %3$s <a href="https://developer.mapquest.com/user/me/apps" target="_blank"> %4$s </a> %5$s',
208 __('If you choose MapQuest, you must provide an app key.', 'leaflet-map'),
209 __('Sign up', 'leaflet-map'),
210 __('then', 'leaflet-map'),
211 __('Create a new app', 'leaflet-map'),
212 __('then supply the "Consumer Key" here.', 'leaflet-map')
213 )
214 ),
215 'map_tile_url' => array(
216 'display_name'=>__('Map Tile URL', 'leaflet-map'),
217 'default'=>'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
218 'type' => 'text',
219 'helptext' => sprintf(
220 '%1$s: <a href="http://wiki.openstreetmap.org/wiki/Tile_servers" target="_blank"> %2$s </a>. %3$s: <a href="http://devblog.mapquest.com/2016/06/15/modernization-of-mapquest-results-in-changes-to-open-tile-access/" target="_blank"> %4$s </a>. %5$s <br/> <code>[leaflet-map tileurl=http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg subdomains=abcd]</code>',
221 __('See more tile servers', 'leaflet-map'),
222 __('here', 'leaflet-map'),
223 __('Please note: free tiles from MapQuest have been discontinued without use of an app key', 'leaflet-map'),
224 __('blog post', 'leaflet-map'),
225 $foreachmap
226 )
227 ),
228 'map_tile_url_subdomains' => array(
229 'display_name'=>__('Map Tile URL Subdomains', 'leaflet-map'),
230 'default'=>'abc',
231 'type' => 'text',
232 'helptext' => sprintf(
233 '%1$s %2$s <br/> <code>[leaflet-map subdomains="1234"]</code>',
234 __('Some maps get tiles from multiple servers with subdomains such as a,b,c,d or 1,2,3,4', 'leaflet-map'),
235 $foreachmap
236 )
237 ),
238 'js_url' => array(
239 'display_name'=>__('JavaScript URL', 'leaflet-map'),
240 'default' => sprintf('https://unpkg.com/leaflet@%s/dist/leaflet.js', $leaflet_version),
241 'type' => 'text',
242 'helptext' => __('If you host your own Leaflet files, then paste the URL here.', 'leaflet-map')
243 ),
244 'css_url' => array(
245 'display_name'=>__('CSS URL', 'leaflet-map'),
246 'default' => sprintf('https://unpkg.com/leaflet@%s/dist/leaflet.css', $leaflet_version),
247 'type' => 'text',
248 'helptext' => __('Same as above.', 'leaflet-map')
249 ),
250 'default_attribution' => array(
251 'display_name' => __('Default Attribution', 'leaflet-map'),
252 'default' => sprintf(
253 '<a href="http://leafletjs.com" title="%1$s">Leaflet</a>; \r\n© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> %2$s',
254 __("A JS library for interactive maps", 'leaflet-map'),
255 __("contributors", 'leaflet-map')
256 ),
257 'type' => 'textarea',
258 'helptext' => __('Attribution to a custom tile url. Use semi-colons (;) to separate multiple.', 'leaflet-map')
259 ),
260 'geocoder' => array(
261 'display_name'=>__('Geocoder', 'leaflet-map'),
262 'default' => 'osm',
263 'type' => 'select',
264 'options' => array(
265 'osm' => __('OpenStreetMap Nominatim', 'leaflet-map'),
266 'google' => __('Google Maps', 'leaflet-map'),
267 'dawa' => __('Denmark Addresses', 'leaflet-map')
268 ),
269 'helptext' => __('Select the Geocoding provider to use to retrieve addresses defined in shortcode.', 'leaflet-map')
270 )
271 );
272
273 foreach ($this->options as $name => $details) {
274 $this->options[ $name ] = new Leaflet_Map_Plugin_Option($details);
275 }
276 }
277
278 /**
279 * Wrapper for WordPress get_options (adds prefix to default options)
280 *
281 * @param string $key
282 *
283 * @return varies
284 */
285 public function get($key)
286 {
287 $default = $this->options[ $key ]->default;
288 $key = $this->prefix . $key;
289 return get_option($key, $default);
290 }
291
292 /**
293 * Wrapper for WordPress update_option (adds prefix to default options)
294 *
295 * @param string $key Unique db key
296 * @param varies $value Value to insert
297 *
298 * @return Leaflet_Map_Plugin_Settings
299 */
300 public function set ($key, $value) {
301 $key = $this->prefix . $key;
302 update_option($key, $value);
303 return $this;
304 }
305
306 /**
307 * Wrapper for WordPress delete_option (adds prefix to default options)
308 *
309 * @param string $key Unique db key
310 *
311 * @return boolean
312 */
313 public function delete($key)
314 {
315 $key = $this->prefix . $key;
316 return delete_option($key);
317 }
318
319 /**
320 * Delete all options
321 *
322 * @return Leaflet_Map_Plugin_Settings
323 */
324 public function reset()
325 {
326 foreach ($this->options as $name => $option) {
327 $this->delete($name);
328 }
329 return $this;
330 }
331 }