PluginProbe
Event Post / 6.0.1
Event Post v6.0.1
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 / class-settings.php

class-settings.php in Event Post 6.0.1, at inc/class-settings.php

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