PluginProbe
Event Post / trunk
Event Post vtrunk
6.1.1 6.1.0 6.0.1 6.0.0 5.12.0 trunk 3.9 4.0 4.2 4.3 4.4 4.5 5.0 5.1 5.10.0 5.10.1 5.10.2 5.10.3 5.10.4 5.11.0 5.11.1 5.2 5.5 5.6 5.6.1 All 46 releases
event-post / inc / settings.php

settings.php in Event Post trunk, at inc/settings.php

580 lines 21.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace EventPost;
4
5 class Settings{
6 private $dashicons;
7 public function __construct($dashicons) {
8 $this->dashicons = $dashicons;
9 add_action('admin_menu', array(&$this, 'manage_options'));
10 add_action('admin_init', array(&$this, 'register_settings'));
11 add_filter('plugin_action_links_event-post/eventpost.php', array( &$this, 'settings_link' ) );
12 add_filter('plugin_row_meta', array( &$this, 'row_meta' ), 1, 4);
13 }
14 public function get_settings(){
15 $ep_settings = get_option('ep_settings');
16 $reg_settings=false;
17 if(!is_array($ep_settings)){
18 $ep_settings = array();
19 }
20 if (!isset($ep_settings['dateformat']) || empty($ep_settings['dateformat'])) {
21 $ep_settings['dateformat'] = get_option('date_format');
22 $reg_settings=true;
23 }
24 if (!isset($ep_settings['timeformat']) || empty($ep_settings['timeformat'])) {
25 $ep_settings['timeformat'] = get_option('time_format');
26 $reg_settings=true;
27 }
28 if (!isset($ep_settings['tile']) || empty($ep_settings['tile']) || !isset(EventPost()->maps[$ep_settings['tile']])) {
29 $maps = array_keys(EventPost()->maps);
30 $ep_settings['tile'] = EventPost()->maps[$maps[0]]['id'];
31 $reg_settings=true;
32 }
33 if (!isset($ep_settings['tile_api_key']) || empty($ep_settings['tile_api_key']) ) {
34 $ep_settings['tile_api_key'] = '';
35 $reg_settings=true;
36 }
37 if(!isset($ep_settings['zoom']) || !is_numeric($ep_settings['zoom'])){
38 $ep_settings['zoom']=12;
39 $reg_settings=true;
40 }
41 if (!isset($ep_settings['cache']) || !is_numeric($ep_settings['cache'])) {
42 $ep_settings['cache'] = 0;
43 $reg_settings=true;
44 }
45 if (!isset($ep_settings['export']) || empty($ep_settings['export'])) {
46 $ep_settings['export'] = 'both';
47 $reg_settings=true;
48 }
49 if (!isset($ep_settings['export_when']) || empty($ep_settings['export_when'])) {
50 $ep_settings['export_when'] = 'future';
51 $reg_settings=true;
52 }
53 if (!isset($ep_settings['dateforhumans'])) {
54 $ep_settings['dateforhumans'] = 1;
55 $reg_settings=true;
56 }
57 if (!isset($ep_settings['emptylink'])) {
58 $ep_settings['emptylink'] = 1;
59 $reg_settings=true;
60 }
61 if (!isset($ep_settings['markpath'])) {
62 $ep_settings['markpath'] = '';
63 $reg_settings=true;
64 }
65 if (!isset($ep_settings['markurl'])) {
66 $ep_settings['markurl'] = '';
67 $reg_settings=true;
68 }
69 if (!isset($ep_settings['customcss'])) {
70 $ep_settings['customcss'] = '';
71 $reg_settings=true;
72 }
73 if (!isset($ep_settings['singlepos']) || empty($ep_settings['singlepos'])) {
74 $ep_settings['singlepos'] = 'after';
75 $reg_settings=true;
76 }
77 if (!isset($ep_settings['loopicons'])) {
78 $ep_settings['loopicons'] = 1;
79 $reg_settings=true;
80 }
81 if (!isset($ep_settings['displaystatus']) || empty($ep_settings['displaystatus'])) {
82 $ep_settings['displaystatus'] = 'both';
83 $reg_settings=true;
84 }
85 if (!isset($ep_settings['adminpos']) || empty($ep_settings['adminpos'])) {
86 $ep_settings['adminpos'] = 'side';
87 $reg_settings=true;
88 }
89 if (!isset($ep_settings['container_shema']) ) {
90 $ep_settings['container_shema'] = '';
91 $reg_settings=true;
92 }
93 if (!isset($ep_settings['item_shema']) ) {
94 $ep_settings['item_shema'] = '';
95 $reg_settings=true;
96 }
97 if(!isset($ep_settings['datepicker']) || !in_array($ep_settings['datepicker'], array('simple', 'native'))){
98 $ep_settings['datepicker']='simple';
99 $reg_settings=true;
100 }
101 if(!isset($ep_settings['posttypes']) || !is_array($ep_settings['posttypes'])){
102 $ep_settings['posttypes']=array('post');
103 $reg_settings=true;
104 }
105 if(!isset($ep_settings['default_color'])){
106 $ep_settings['default_color']= "#000000";
107 $reg_settings=true;
108 }
109 if(!isset($ep_settings['default_icon'])){
110 $ep_settings['default_icon']= "location";
111 $reg_settings=true;
112 }
113
114 do_action_ref_array('eventpost_getsettings_action', array(&$ep_settings, &$reg_settings));
115
116 //Save settings not changed
117 if($reg_settings===true){
118 update_option('ep_settings', $ep_settings);
119 }
120 return $ep_settings;
121 }
122
123
124 /**
125 * Settings link on the plugins page
126 */
127 public function settings_link( $links ) {
128 $settings_link = '<a href="options-general.php?page=event-settings">' . __( 'Settings', 'event-post' ) . '</a>';
129 // place it before other links
130 array_unshift( $links, $settings_link );
131 return $links;
132 }
133 /**
134 *
135 * @param type $plugin_meta
136 * @param type $plugin_file
137 * @param type $plugin_data
138 * @param type $status
139 * @return type
140 */
141 public function row_meta($plugin_meta, $plugin_file, $plugin_data, $status){
142 if($plugin_file=='event-post/eventpost.php'){
143 $plugin_link = '<a href="http://event-post.com" target="_blank">' . __( 'Plugin site', 'event-post' ) . '</a>';
144 $review_link = '<a href="https://wordpress.org/support/plugin/event-post/reviews/#new-post" target="_blank">' . __( 'Give a note', 'event-post' ) . '</a>';
145 array_push($plugin_meta, $plugin_link, $review_link);
146 }
147 return $plugin_meta;
148 }
149
150 /**
151 * adds menu items
152 */
153 public function manage_options() {
154 add_options_page(__('Events settings', 'event-post'), __('Events', 'event-post'), 'manage_options', 'event-settings', array(&$this, 'manage_settings'));
155 }
156
157 /**
158 * @action eventpost_register_settings
159 */
160 public function register_settings(){
161 register_setting( 'eventpost-settings', 'ep_settings' );
162
163 // Global
164 add_settings_section(
165 'eventpost-settings-general',
166 '<span class="dashicons dashicons-admin-appearance"></span>&nbsp;'.__('Global settings', 'event-post'),
167 array(&$this, 'settings_section_callback'),
168 'eventpost-settings'
169 );
170 //--
171 add_settings_field(
172 'emptylink',
173 __('Print link for empty posts', 'event-post'),
174 array(&$this, 'settings_field_select_callback'),
175 'eventpost-settings',
176 'eventpost-settings-general',
177 array( 'name' => 'emptylink', 'options'=>array(
178 1=>__('Link all posts', 'event-post'),
179 0=>__('Do not link posts with empty content', 'event-post')
180 )
181 )
182 );
183 add_settings_field(
184 'singlepos',
185 __('Event bar position for single posts', 'event-post'),
186 array(&$this, 'settings_field_select_callback'),
187 'eventpost-settings',
188 'eventpost-settings-general',
189 array( 'name' => 'singlepos', 'options'=>array(
190 'before'=>__('Before the content', 'event-post'),
191 'after'=>__('After the content', 'event-post'),
192 'none'=>__('Not displayed', 'event-post')
193 ) )
194 );
195 add_settings_field(
196 'loopicons',
197 __('Add icons for events in the loop', 'event-post'),
198 array(&$this, 'settings_field_select_callback'),
199 'eventpost-settings',
200 'eventpost-settings-general',
201 array( 'name' => 'loopicons', 'options'=>array(
202 1=>__('Emojis', 'event-post'),
203 0=>__('Hide', 'event-post'),
204 2=>__('Icons', 'event-post')
205 ) )
206 );
207 add_settings_field(
208 'displaystatus',
209 __('Display Event Status on:', 'event-post'),
210 array(&$this, 'settings_field_select_callback'),
211 'eventpost-settings',
212 'eventpost-settings-general',
213 array( 'name' => 'displaystatus', 'options'=>array(
214 'list'=>__('List only', 'event-post'),
215 'single'=>__('Single only', 'event-post'),
216 'both'=>__('Both', 'event-post'),
217 'none'=>__('None', 'event-post'),
218 ) )
219 );
220 add_settings_field(
221 'customcss',
222 __('Use this custom CSS file', 'event-post'),
223 array(&$this, 'settings_field_default_callback'),
224 'eventpost-settings',
225 'eventpost-settings-general',
226 array( 'name' => 'customcss', 'description'=>sprintf(__('Leave empty to use the <a href="%s" target="_blank">default CSS file</a>.', 'event-post'), plugins_url('/css/event-post.css', __FILE__)).'<br>'
227 . (is_file(get_stylesheet_directory().'/event-post.css') || is_file(get_template_directory().'/event-post.css')
228 ? __('Your theme contains an <code>event-post.css</code> file. It will be used as default stylesheet.', 'event-post')
229 : __('You can also add a <code>event-post.css</code> in your theme directory. It will be used as default stylesheet.', 'event-post')))
230 );
231
232 // Date
233 add_settings_section(
234 'eventpost-settings-date',
235 '<span class="dashicons dashicons-clock"></span>&nbsp;'.__('Date settings', 'event-post'),
236 array(&$this, 'settings_section_callback'),
237 'eventpost-settings'
238 );
239 //--
240 add_settings_field(
241 'dateformat',
242 __('Date format', 'event-post'),
243 array(&$this, 'settings_field_default_callback'),
244 'eventpost-settings',
245 'eventpost-settings-date',
246 array( 'name' => 'dateformat')
247 );
248 add_settings_field(
249 'timeformat',
250 __('Time format', 'event-post'),
251 array(&$this, 'settings_field_default_callback'),
252 'eventpost-settings',
253 'eventpost-settings-date',
254 array( 'name' => 'timeformat')
255 );
256 add_settings_field(
257 'export',
258 __('Show export buttons on:', 'event-post'),
259 array(&$this, 'settings_field_select_callback'),
260 'eventpost-settings',
261 'eventpost-settings-date',
262 array( 'name' => 'export', 'options'=>array(
263 'list'=>__('List only', 'event-post'),
264 'single'=>__('Single only', 'event-post'),
265 'both'=>__('Both', 'event-post'),
266 'none'=>__('None', 'event-post'),
267 ) )
268 );
269 add_settings_field(
270 'export_when',
271 __('Show export buttons on:', 'event-post'),
272 array(&$this, 'settings_field_select_callback'),
273 'eventpost-settings',
274 'eventpost-settings-date',
275 array( 'name' => 'export_when', 'options'=>array(
276 'future'=>__('Future only', 'event-post'),
277 'past'=>__('Past only', 'event-post'),
278 'both'=>__('Both', 'event-post'),
279 'none'=>__('None', 'event-post'),
280 ) )
281 );
282 add_settings_field(
283 'dateforhumans',
284 __('Relative human dates:', 'event-post'),
285 array(&$this, 'settings_field_select_callback'),
286 'eventpost-settings',
287 'eventpost-settings-date',
288 array( 'name' => 'dateforhumans',
289 'description'=>__('Replace absolute dates by "today", "yesterday", and "tomorrow".', 'event-post'),
290 'options'=>array(
291 1=>__('Yes', 'event-post'),
292 0=>__('No', 'event-post'),
293 ) )
294 );
295
296 // List
297 add_settings_section(
298 'eventpost-settings-list',
299 '<span class="dashicons dashicons-editor-ul"></span>&nbsp;'.__('List settings', 'event-post'),
300 array(&$this, 'settings_section_callback'),
301 'eventpost-settings'
302 );
303 //--
304 add_settings_field(
305 'container_shema',
306 __('Container schema', 'event-post'),
307 array(&$this, 'settings_field_textarea_callback'),
308 'eventpost-settings',
309 'eventpost-settings-list',
310 array( 'name' => 'container_shema', 'description'=>__('default:','event-post').' <code>'.htmlentities(EventPost()->default_list_shema['container']).'</code>')
311 );
312 add_settings_field(
313 'item_shema',
314 __('Item schema', 'event-post'),
315 array(&$this, 'settings_field_textarea_callback'),
316 'eventpost-settings',
317 'eventpost-settings-list',
318 array( 'name' => 'item_shema', 'description'=>__('default:','event-post').' <code>'.htmlentities(EventPost()->default_list_shema['item']).'</code>')
319 );
320 // Timeline
321 add_settings_section(
322 'eventpost-settings-timeline',
323 '<span class="dashicons dashicons-arrow-right-alt"></span>&nbsp;'.__('Timeline settings', 'event-post'),
324 array(&$this, 'settings_section_callback'),
325 'eventpost-settings'
326 );
327 //--
328 add_settings_field(
329 'timeline_container_shema',
330 __('Timeline Container schema', 'event-post'),
331 array(&$this, 'settings_field_textarea_callback'),
332 'eventpost-settings',
333 'eventpost-settings-timeline',
334 array( 'name' => 'container_shema', 'description'=>__('default:','event-post').' <code>'.htmlentities(EventPost()->default_timeline_shema['container']).'</code>')
335 );
336 add_settings_field(
337 'timeline_item_shema',
338 __('Timeline Item schema', 'event-post'),
339 array(&$this, 'settings_field_textarea_callback'),
340 'eventpost-settings',
341 'eventpost-settings-timeline',
342 array( 'name' => 'item_shema', 'description'=>__('default:','event-post').' <code>'.htmlentities(EventPost()->default_timeline_shema['item']).'</code>')
343 );
344 // Appearance
345 add_settings_section(
346 'eventpost-settings-appearence',
347 '<span class="dashicons dashicons-admin-appearance"></span>&nbsp;'.__('Appearence settings', 'event-post'),
348 array(&$this, 'settings_section_callback'),
349 'eventpost-settings'
350 );
351 //--
352 add_settings_field(
353 'appearence_default_color',
354 __('Default Marker Color', 'event-post'),
355 array(&$this, 'settings_field_default_callback'),
356 'eventpost-settings',
357 'eventpost-settings-appearence',
358 array( 'name' => 'default_color', 'input-class'=> 'color-field','description'=>__('Default color used for Map Marker','event-post'))
359 );
360 add_settings_field(
361 'appearence_default_icon',
362 __('Default Marker Icon', 'event-post'),
363 array(&$this, 'settings_field_select_callback'),
364 'eventpost-settings',
365 'eventpost-settings-appearence',
366 array( 'name' => 'default_icon','class'=>'','input-style'=>'font-family : dashicons;', 'description'=>__('Default icon used for Map Marker','event-post'),'options' => $this->dashicons->icons_html_entities)
367 );
368 add_settings_field(
369 'markpath',
370 __('Makers custom directory after <code>ABSPATH/</code>', 'event-post'),
371 array(&$this, 'settings_field_default_callback'),
372 'eventpost-settings',
373 'eventpost-settings-appearence',
374 array( 'name' => 'markpath', 'description'=>__('(leave empty for default settings)','event-post'))
375 );
376 add_settings_field(
377 'markurl',
378 __('Makers custom directory URL', 'event-post'),
379 array(&$this, 'settings_field_default_callback'),
380 'eventpost-settings',
381 'eventpost-settings-appearence',
382 array( 'name' => 'markurl', 'description'=>__('(leave empty for default settings)','event-post'))
383 );
384 // Map
385 add_settings_section(
386 'eventpost-settings-map',
387 '<span class="dashicons dashicons-location-alt"></span>&nbsp;'.__('Map settings', 'event-post'),
388 array(&$this, 'settings_section_callback'),
389 'eventpost-settings'
390 );
391 //--
392 $maps = array();
393 foreach (EventPost()->maps as $map){
394 $maps[$map['id']]=$map['name'].(isset($map['urls_retina']) ? ' '.__('(Retina support)', 'event-post') : '');
395 }
396 add_settings_field(
397 'tile',
398 __('Map background', 'event-post'),
399 array(&$this, 'settings_field_select_callback'),
400 'eventpost-settings',
401 'eventpost-settings-map',
402 array( 'name' => 'tile', 'options'=>$maps)
403 );
404 add_settings_field(
405 'tile_api_key',
406 __('Optional API key', 'event-post'),
407 array(&$this, 'settings_field_default_callback'),
408 'eventpost-settings',
409 'eventpost-settings-map',
410 array( 'name' => 'tile_api_key', 'description'=>__('Some tiles need an API key to be displayed.','event-post'))
411 );
412 add_settings_field(
413 'zoom',
414 __('Default zoom', 'event-post'),
415 array(&$this, 'settings_field_default_callback'),
416 'eventpost-settings',
417 'eventpost-settings-map',
418 array( 'name' => 'zoom')
419 );
420
421
422 // Admin
423 add_settings_section(
424 'eventpost-settings-admin',
425 '<span class="dashicons dashicons-admin-generic"></span>&nbsp;'.__('Admin settings', 'event-post'),
426 array(&$this, 'settings_section_callback'),
427 'eventpost-settings'
428 );
429 //--
430 add_settings_field(
431 'adminpos',
432 __('Position of event details boxes', 'event-post'),
433 array(&$this, 'settings_field_select_callback'),
434 'eventpost-settings',
435 'eventpost-settings-admin',
436 array( 'name' => 'adminpos', 'options'=>array(
437 'side'=>__('Side', 'event-post'),
438 'normal'=>__('Under the text', 'event-post'),
439 ) )
440 );
441 $post_types = array();
442 $posttypes = apply_filters('eventpost_get_post_types', get_post_types(array(), 'objects'));
443 foreach($posttypes as $type=>$posttype){
444 $post_types[$posttype->name]=$posttype->labels->name;
445 }
446 add_settings_field(
447 'posttypes',
448 __('Which post types can be events?', 'event-post'),
449 array(&$this, 'settings_field_checkbox_callback'),
450 'eventpost-settings',
451 'eventpost-settings-admin',
452 array( 'name' => 'posttypes', 'options'=>$post_types)
453 );
454 add_settings_field(
455 'datepicker',
456 __('Datepicker style', 'event-post'),
457 array(&$this, 'settings_field_datepicker_callback'),
458 'eventpost-settings',
459 'eventpost-settings-admin',
460 array( 'name' => 'datepicker')
461 );
462 add_settings_field(
463 'cache',
464 __('Use cache', 'event-post'),
465 array(&$this, 'settings_field_default_callback'),
466 'eventpost-settings',
467 'eventpost-settings-admin',
468 array( 'name' => 'cache', 'description'=>__('Use cache for results','event-post'))
469 );
470
471 do_action('eventpost_register_settings');
472 }
473 function settings_section_callback( $arg ) {
474 echo '<hr>';
475 }
476
477 function settings_field_default_callback($args){
478 ?>
479 <input name="ep_settings[<?php echo $args['name']; ?>]"
480 style="<?php echo isset($args['input-style']) ? $args['input-style'] : null ?>"
481 id="<?php echo $args['name']; ?>"
482 value="<?php echo EventPost()->settings[$args['name']]; ?>"
483 class="regular-text <?php echo isset($args['input-class']) ? $args['input-class'] : null ?>"/>
484 <?php if(isset($args['description']) && $args['description']): ?>
485 <p class="description"><?php echo $args['description']; ?></p>
486 <?php endif; ?>
487 <?php
488 }
489 function settings_field_textarea_callback($args){
490 ?>
491 <textarea name="ep_settings[<?php echo $args['name']; ?>]"
492 style="<?php echo isset($args['input-style']) ? $args['input-style'] : null ?>"
493 id="<?php echo $args['name']; ?>"
494 class="regular-text <?php echo isset($args['input-class']) ? $args['input-class'] : null ?>"
495 ><?php echo EventPost()->settings[$args['name']]; ?></textarea>
496 <?php if(isset($args['description']) && $args['description']): ?>
497 <p class="description"><?php echo $args['description']; ?></p>
498 <?php endif; ?>
499 <?php
500 }
501 function settings_field_select_callback($args){
502 ?>
503 <select name="ep_settings[<?php echo $args['name']; ?>]"
504 style="<?php echo isset($args['input-style']) ? $args['input-style'] : null ?>"
505 id="<?php echo $args['name']; ?>"
506 class="<?php echo isset($args['input-class']) ? $args['input-class'] : null ?>">
507 <?php foreach($args['options'] as $value=>$label) : ?>
508 <option value="<?php echo $value; ?>" <?php selected($value, EventPost()->settings[$args['name']], true);?>><?php echo $label; ?></option>
509 <?php endforeach; ?>
510 </select>
511 <?php if(isset($args['description']) && $args['description']): ?>
512 <p class="description"><?php echo $args['description']; ?></p>
513 <?php endif; ?>
514 <?php
515 }
516 function settings_field_checkbox_callback($args){
517 ?>
518 <?php foreach($args['options'] as $value=>$label) : ?>
519 <p>
520 <label>
521 <input type="checkbox" name="ep_settings[<?php echo $args['name']; ?>][<?php echo $value; ?>]" value="<?php echo $value; ?>" <?php checked(in_array($value, EventPost()->settings[$args['name']]),true, true) ?>>
522 <?php echo $label; ?>
523 </label>
524 </p>
525 <?php endforeach; ?>
526 <?php if(isset($args['description']) && $args['description']): ?>
527 <p class="description"><?php echo $args['description']; ?></p>
528 <?php endif; ?>
529 <?php
530 }
531 function settings_field_datepicker_callback($args){
532 $now = current_time('mysql');
533 $human_date = EventPost()->human_date(current_time('timestamp')) .' '. date(EventPost()->settings['timeformat'], current_time('timestamp'));
534 ?>
535 <div>
536 <label>
537 <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_simple" value="simple" <?php checked(EventPost()->settings['datepicker'],'simple', true) ?>>
538 <?php _e('Simple', 'event-post'); ?>
539 </label>
540 <p>
541 <span id="eventpost_simple_date_human" class="human_date">
542 <?php echo $human_date; ?>
543 </span>
544 <input type="text" class="eventpost-datepicker-simple" id="eventpost_simple_date" value="<?php echo $now; ?>">
545 </p>
546 </div>
547 <div>
548 <label>
549 <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_native" value="native" <?php checked(EventPost()->settings['datepicker'],'native', true) ?>>
550 <?php _e('Native WordPress style', 'event-post'); ?>
551 </label>
552 <p>
553 <span id="eventpost_native_date_human" class="human_date">
554 <?php echo $human_date; ?>
555 </span>
556 <input type="text" class="eventpost-datepicker-native" id="eventpost_native_date" value="<?php echo $now; ?>">
557 </p>
558 </div>
559 <?php
560 }
561 /**
562 * output content of the setting page
563 */
564 public function manage_settings() {
565 $ep_settings = EventPost()->settings;
566 ?>
567 <div class="wrap">
568 <h2><?php _e('Events settings', 'event-post'); ?></h2>
569 <form action="options.php" method="post">
570 <?php settings_fields( 'eventpost-settings' ); ?>
571 <?php do_settings_sections('eventpost-settings'); ?>
572 <?php do_action('eventpost_settings_form', $ep_settings); ?>
573 <?php submit_button(); ?>
574 </form>
575 </div>
576 <?php
577 do_action('eventpost_after_settings_form');
578 }
579 }
580