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