This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ecwd_admin_class.php
485 lines (422 loc) · 18.2 KB
/
ecwd_admin_class.php
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
<?php
/**
* ECWD_Admin
*/
class ECWD_Admin {
protected static $instance = null;
protected $version = '1.0.24';
protected $ecwd_page = null;
protected $notices = null;
private function __construct() {
$plugin = ECWD::get_instance();
$this->prefix = $plugin->get_prefix();
$this->version = $plugin->get_version();
$this->notices = new ECWD_Notices();
add_filter( 'plugin_action_links_' . plugin_basename( plugin_dir_path( __FILE__ ) . $this->prefix . '.php' ), array(
$this,
'add_action_links'
) );
// Setup admin stants
add_action( 'init', array( $this, 'define_admin_constants' ) );
add_action( 'init', array( $this, ECWD_PLUGIN_PREFIX . '_shortcode_button' ) );
// Add admin styles and scripts
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
// Add the options page and menu item.
add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ), 2 );
foreach ( array( 'post.php', 'post-new.php' ) as $hook ) {
add_action( "admin_head-$hook", array( $this, 'admin_head' ) );
}
//add_filter( 'auto_update_plugin', array($this, 'ecwd_update'), 10, 2 );
//Web Dorado Logo
add_action( 'admin_notices', array( $this, 'create_logo_to_head' ) );
// Runs the admin notice ignore function incase a dismiss button has been clicked
add_action( 'admin_init', array( $this, 'admin_notice_ignore' ) );
add_action( 'admin_notices', array( $this, 'ecwd_admin_notices' ) );
}
/**
* Check user is on plugin page
* @return bool
*/
private function ecwd_page() {
if ( ! isset( $this->ecwd_page ) ) {
return false;
}
$screen = get_current_screen();
if ( $screen->id == 'edit-ecwd_event' || $screen->id == ECWD_PLUGIN_PREFIX . '_event' || in_array( $screen->id, $this->ecwd_page ) || $screen->post_type == ECWD_PLUGIN_PREFIX . '_event' || $screen->post_type == ECWD_PLUGIN_PREFIX . '_theme' || $screen->post_type == ECWD_PLUGIN_PREFIX . '_venue' || $screen->id == 'edit-ecwd_calendar' || $screen->id == ECWD_PLUGIN_PREFIX . '_calendar' || $screen->id == ECWD_PLUGIN_PREFIX . '_countdown_theme' || $screen->post_type == ECWD_PLUGIN_PREFIX . '_organizer' ) {
return true;
} else {
return false;
}
}
public static function activate() {
if ( ! defined( 'ECWD_PLUGIN_PREFIX' ) ) {
define( 'ECWD_PLUGIN_PREFIX', 'ecwd' );
}
$has_option = get_option( 'ecwd_old_events' );
if ( $has_option === false ) {
$old_event = get_posts( array(
'posts_per_page' => 1,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'ecwd_event',
'post_status' => 'any'
) );
if ( $old_event && isset( $old_event[0]->post_date ) ) {
add_option( 'ecwd_old_events', 1 );
} else {
add_option( 'ecwd_old_events', 0 );
}
}
}
public static function uninstall() {
}
public function add_plugin_admin_menu() {
$this->ecwd_page[] = add_submenu_page(
'edit.php?post_type=ecwd_calendar', __( 'Settings', 'ecwd' ), __( 'Settings', 'ecwd' ), 'manage_options', $this->prefix . '_general_settings', array(
$this,
'display_admin_page'
)
);
$this->ecwd_page[] = add_submenu_page(
'edit.php?post_type=ecwd_calendar', __( 'Licensing', 'ecwd' ), __( 'Licensing', 'ecwd' ), 'manage_options', $this->prefix . '_licensing', array(
$this,
'display_license_page'
)
);
$this->ecwd_page[] = add_submenu_page(
'edit.php?post_type=ecwd_calendar', __( 'Featured plugins', 'ecwd' ), __( 'Featured plugins', 'ecwd' ), 'manage_options', $this->prefix . '_featured_plugins', array(
$this,
'display_featured_plugins'
)
);
$this->ecwd_page[] = add_submenu_page(
'edit.php?post_type=ecwd_calendar', __( 'Featured themes', 'ecwd' ), __( 'Featured themes', 'ecwd' ), 'manage_options', $this->prefix . '_featured_themes', array(
$this,
'display_featured_themes'
)
);
$this->ecwd_page[] = add_menu_page(
__( 'Calendar Add-ons', 'ecwd' ), __( 'Calendar Add-ons', 'ecwd' ), 'manage_options', $this->prefix . '_addons', array(
$this,
'display_addons_page'
), plugins_url( '/assets/add-ons-icon.png', ECWD_MAIN_FILE ), '26,12'
);
$this->ecwd_page[] = add_menu_page(
__( 'Calendar Themes', 'ecwd' ), __( 'Calendar Themes', 'ecwd' ), 'manage_options', $this->prefix . '_themes', array(
$this,
'display_themes_page'
), plugins_url( '/assets/themes-icon.png', ECWD_MAIN_FILE ), '26,18'
);
}
public function display_addons_page() {
$addons = array(
'Management' => array(
'add_event' => array(
'name' => 'ECWD Frontend Event Management',
'url' => 'https://web-dorado.com/products/wordpress-event-calendar-wd/add-ons/frontend-event-management.html',
'description' => 'This add-on is designed for allowing the users/guests to add events to the calendar from the front end. In addition, the users can also have permissions to edit/delete their events.',
'icon' => '',
'image' => plugins_url( 'assets/add_addevent.jpg', __FILE__ ),
),
'import_export' => array(
'name' => 'ECWD Import/Export',
'url' => 'https://web-dorado.com/products/wordpress-event-calendar-wd/add-ons/import-export.html',
'description' => 'The following data of the Event Calendar WD can be exported and imported: Events, Categories, Venues,Organizers and Tags. The exported/imported data will be in CSV format, which can be further edited, modified and imported',
'icon' => '',
'image' => plugins_url( 'assets/import_export.png', __FILE__ )
),
'custom_fields' => array(
'name' => 'ECWD Custom Fields',
'url' => 'https://web-dorado.com/products/wordpress-event-calendar-wd/add-ons/custom-fields.html',
'description' => 'Custom Fields Add-On will enable you to have more fields for more detailed and structured content: you can use this add-on and create additional fields for each event, venue and organizer.',
'icon' => '',
'image' => plugins_url( 'assets/custom_fields.png', __FILE__ )
),
),
'Events Grouping' => array(
'event_filters' => array(
'name' => 'ECWD Filter Bar',
'url' => 'https://web-dorado.com/products/wordpress-event-calendar-wd/add-ons/filter.html',
'description' => 'This add-on is designed for advanced event filter and browsing. It will display multiple filters, which will make it easier for the user to find the relevant event from the calendar.',
'icon' => '',
'image' => plugins_url( 'assets/add_filters.png', __FILE__ ),
),
'event_countdown' => array(
'name' => 'ECWD Event Countdown',
'url' => 'https://web-dorado.com/products/wordpress-event-calendar-wd/add-ons/countdown.html',
'description' => 'With this add-on you can add an elegant countdown to your site. It supports calendar events or a custom one. The styles and colors of the countdown can be modified. It can be used as both as widget and shortcode.',
'icon' => '',
'image' => plugins_url( 'assets/add_cdown.jpg', __FILE__ ),
),
'upcoming_events' => array(
'name' => 'ECWD Upcoming events widget',
'url' => 'https://web-dorado.com/products/wordpress-event-calendar-wd/add-ons/upcoming-events.html',
'description' => 'The Upcoming events widget is designed for displaying upcoming events lists. The number of events, the event date ranges, as well as the appearance of the widget is fully customizable and easy to manage.',
'icon' => '',
'image' => plugins_url( 'assets/upcoming_events.png', __FILE__ ),
),
),
'Integrations' => array(
'fb' => array(
'name' => 'ECWD Facebook Integration',
'url' => 'https://web-dorado.com/products/wordpress-event-calendar-wd/add-ons/facebook-integration.html',
'description' => 'This addon integrates ECWD with your Facebook page and gives functionality to import events or just display events without importing.',
'icon' => '',
'image' => plugins_url( 'assets/add_fb.jpg', __FILE__ ),
),
'gcal' => array(
'name' => 'ECWD Google Calendar Integration',
'url' => 'https://web-dorado.com/products/wordpress-event-calendar-wd/add-ons/google-calendar-integration.html',
'description' => 'This addon integrates ECWD with your Google Calendar and gives functionality to import events or just display events without importing.',
'icon' => '',
'image' => plugins_url( 'assets/add_gcal.jpg', __FILE__ ),
),
'ical' => array(
'name' => 'ECWD iCAL Integration',
'url' => 'https://web-dorado.com/products/wordpress-event-calendar-wd/add-ons/ical-integration.html',
'description' => 'This addon integrates ECWD with your iCAL Calendar and gives functionality to import events or just display events without importing.',
'icon' => '',
'image' => plugins_url( 'assets/add_ical.jpg', __FILE__ )
),
)
);
include_once( 'views/admin/addons.php' );
}
public function display_featured_themes() {
include_once( ECWD_DIR . '/views/admin/ecwd-featured-themes.php' );
}
public function display_featured_plugins() {
include_once( ECWD_DIR . '/views/admin/ecwd-featured-plugins.php' );
}
public function display_themes_page() {
include_once( ECWD_DIR . '/views/admin/ecwd-theme-meta.php' );
}
public function display_license_page() {
include_once( ECWD_DIR . '/views/admin/licensing.php' );
}
public function display_admin_page() {
include_once( 'views/admin/admin.php' );
}
/**
* Enqueue styles for the admin area
*/
public function enqueue_admin_styles() {
wp_enqueue_style( $this->prefix . '-calendar-buttons-style', plugins_url( 'css/admin/mse-buttons.css', __FILE__ ), '', $this->version, 'all' );
if ( $this->ecwd_page() ) {
wp_enqueue_style( $this->prefix . '-main', plugins_url( 'css/calendar.css', __FILE__ ), '', $this->version );
wp_enqueue_style( 'ecwd-admin-css', plugins_url( 'css/admin/admin.css', __FILE__ ), array(), $this->version, 'all' );
wp_enqueue_style( 'ecwd-admin-datetimepicker-css', plugins_url( 'css/admin/jquery.datetimepicker.css', __FILE__ ), array(), $this->version, 'all' );
wp_enqueue_style( 'ecwd-admin-colorpicker-css', plugins_url( 'css/admin/evol.colorpicker.css', __FILE__ ), array(), $this->version, 'all' );
wp_enqueue_style( $this->prefix . '-calendar-style', plugins_url( 'css/style.css', __FILE__ ), '', $this->version, 'all' );
wp_enqueue_style( $this->prefix . '_font-awesome', plugins_url( '/css/font-awesome/font-awesome.css', __FILE__ ), '', $this->version, 'all' );
wp_enqueue_style( $this->prefix . '-featured_plugins', plugins_url( '/css/admin/featured_plugins.css', __FILE__ ), '', $this->version, 'all' );
wp_enqueue_style( $this->prefix . '-featured_themes', plugins_url( '/css/admin/featured_themes.css', __FILE__ ), '', $this->version, 'all' );
wp_enqueue_style( $this->prefix . '-licensing', plugins_url( '/css/admin/licensing.css', __FILE__ ), '', $this->version, 'all' );
}
}
/**
* Register scripts for the admin area
*/
public function enqueue_admin_scripts() {
if ( $this->ecwd_page() ) {
wp_enqueue_script( $this->prefix . '-admin-datetimepicker', plugins_url( 'js/admin/jquery.datetimepicker.js', __FILE__ ), array(
'jquery',
'jquery-ui-widget'
), $this->version, true );
wp_enqueue_script( $this->prefix . '-admin-colorpicker', plugins_url( 'js/admin/evol.colorpicker.js', __FILE__ ), array( 'jquery' ), $this->version, true );
//wp_enqueue_script('sp-admin-google', 'https://maps.googleapis.com/maps/api/js?key=AIzaSyCIUXhK7om6EZ9Ca5xFcEbXMKEQZz7U2kM', array('jquery'), $this->version, true);
wp_enqueue_script( $this->prefix . '-public', plugins_url( 'js/scripts.js', __FILE__ ), array(
'jquery',
'masonry'
), $this->version, true );
wp_register_script( $this->prefix . '-admin-scripts', plugins_url( 'js/admin/admin.js', __FILE__ ), array(
'jquery',
'jquery-ui-datepicker',
'jquery-ui-tabs',
'jquery-ui-selectable',
$this->prefix . '-public'
), $this->version, true );
wp_enqueue_script( $this->prefix . '-admin-datetimepicker-scripts', plugins_url( 'js/admin/datepicker.js', __FILE__ ), array( 'jquery' ), $this->version, true );
$params['ajaxurl'] = admin_url( 'admin-ajax.php' );
$params['version'] = get_bloginfo( 'version' );
if ( $params['version'] >= 3.5 ) {
wp_enqueue_media();
} else {
wp_enqueue_style( 'thickbox' );
wp_enqueue_script( 'thickbox' );
}
wp_localize_script( $this->prefix . '-admin-scripts', 'params', $params );
wp_localize_script( ECWD_PLUGIN_PREFIX . '-public', 'ecwd', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'ajaxnonce' => wp_create_nonce( ECWD_PLUGIN_PREFIX . '_ajax_nonce' ),
'loadingText' => __( 'Loading...', 'ecwd' ),
'plugin_url' => ECWD_URL
) );
wp_enqueue_script( $this->prefix . '-admin-scripts' );
}
}
/**
* Localize Script
*/
public function admin_head() {
$args = array(
'post_type' => ECWD_PLUGIN_PREFIX . '_calendar',
'post_status' => 'publish',
'posts_per_page' => - 1,
'ignore_sticky_posts' => 1
);
$calendar_posts = get_posts( $args );
$args = array(
'post_type' => $this->prefix . '_event',
'post_status' => 'publish',
'posts_per_page' => - 1,
'ignore_sticky_posts' => 1
);
$event_posts = get_posts( $args );
$plugin_url = plugins_url( '/', __FILE__ );
?>
<!-- TinyMCE Shortcode Plugin -->
<script type='text/javascript'>
var ecwd_plugin = {
'url': '<?php echo $plugin_url; ?>',
'ecwd_calendars': [
<?php foreach($calendar_posts as $calendar){?>
{
text: '<?php echo str_replace("'", "\'", $calendar->post_title);?>',
value: '<?php echo $calendar->ID;?>'
},
<?php }?>
],
'ecwd_events': [
{text: 'None', value: 'none'},
<?php foreach($event_posts as $event){?>
{
text: '<?php echo str_replace("'", "\'", $event->post_title);?>',
value: '<?php echo $event->ID;?>'
},
<?php }?>
],
'ecwd_views': [
{text: 'None', value: 'none'},
{text: 'Month', value: 'full'},
{text: 'List', value: 'list'},
{text: 'Week', value: 'week'},
{text: 'Day', value: 'day'}
]
};
</script>
<!-- TinyMCE Shortcode Plugin -->
<?php
}
public function ecwd_shortcode_button() {
// Don't bother doing this stuff if the current user lacks permissions
if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
return;
}
// Add only in Rich Editor mode
if ( get_user_option( 'rich_editing' ) == 'true' ) {
// filter the tinyMCE buttons and add our own
add_filter( "mce_external_plugins", array( $this, 'add_tinymce_plugin' ) );
add_filter( 'mce_buttons', array( $this, 'register_buttons' ) );
}
}
// registers the buttons for use
function register_buttons( $buttons ) {
// inserts a separator between existing buttons and our new one
// "friendly_button" is the ID of our button
if ( ! $this->ecwd_page() ) {
array_push( $buttons, "|", ECWD_PLUGIN_PREFIX );
}
return $buttons;
}
// add the button to the tinyMCE bar
function add_tinymce_plugin( $plugin_array ) {
if ( ! $this->ecwd_page() ) {
$plugin_array[ ECWD_PLUGIN_PREFIX ] = plugins_url( 'js/admin/editor-buttons.js', __FILE__ );
}
return $plugin_array;
}
//auto update plugin
function ecwd_update( $update, $item ) {
global $ecwd_options;
if ( ! isset( $ecwd_options['auto_update'] ) || $ecwd_options['auto_update'] == 1 ) {
$plugins = array( // Plugins to auto-update
'event-calendar-wd'
);
if ( in_array( $item->slug, $plugins ) ) {
return true;
} // Auto-update specified plugins
else {
return false;
} // Don't auto-update all other plugins
}
}
public function define_admin_constants() {
if ( ! defined( 'ECWD_DIR' ) ) {
define( 'ECWD_DIR', dirname( __FILE__ ) );
}
}
/********ECWD notices************/
function ecwd_admin_notices() {
// Notices filter and run the notices function.
$admin_notices = apply_filters( 'ecwd_admin_notices', array() );
$this->notices->admin_notice( $admin_notices );
}
// Ignore function that gets ran at admin init to ensure any messages that were dismissed get marked
public function admin_notice_ignore() {
$slug = ( isset( $_GET['ecwd_admin_notice_ignore'] ) ) ? $_GET['ecwd_admin_notice_ignore'] : '';
if ( isset( $_GET['ecwd_admin_notice_ignore'] ) && current_user_can( 'manage_options' ) ) {
$admin_notices_option = get_option( 'ecwd_admin_notice', array() );
$admin_notices_option[ $_GET['ecwd_admin_notice_ignore'] ]['dismissed'] = 1;
update_option( 'ecwd_admin_notice', $admin_notices_option );
$query_str = remove_query_arg( 'ecwd_admin_notice_ignore' );
wp_redirect( $query_str );
exit;
}
}
/**
* Set Web Dorado Logo in admin pages
*/
public function create_logo_to_head() {
global $pagenow, $post;
if ( $this->ecwd_page() ) { ?>
<div style="width: 100%; text-align: right;clear:both;">
<a href="https://web-dorado.com/files/fromEventCalendarWD.php" target="_blank"
style="text-decoration:none;box-shadow: none;">
<img src="<?php echo plugins_url( '/assets/pro.png', __FILE__ ); ?>" border="0"
alt="https://web-dorado.com/files/fromEventCalendarWD.php" width="215">
</a>
</div>
<?php }
}
/**
* Return an instance of this class.
*/
public static function get_instance() {
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Return the page
*/
public function get_page() {
return $this->ecwd_page();
}
/**
* Return plugin name
*/
public function get_plugin_title() {
return __( 'Event Calendar WD', 'ecwd' );
}
public function add_action_links( $links ) {
return array_merge(
array(
'settings' => '<a href="' . admin_url( 'edit.php?post_type=ecwd_calendar&page=ecwd_general_settings' ) . '">' . __( 'Settings', 'ecwd' ) . '</a>',
'events' => '<a href="' . admin_url( 'edit.php?post_type=ecwd_event' ) . '">' . __( 'Events', 'ecwd' ) . '</a>'
), $links
);
}
}