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