forked from wpdrift/BP-Events-Calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bp-events-calendar-core.php
executable file
·396 lines (315 loc) · 14.2 KB
/
bp-events-calendar-core.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
<?php
/**
* BuddyPress BP_Events_Component Loader
*
* @package BuddyPress
* @subpackage SettingsLoader
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
class BP_Events_Component extends BP_Component {
public function __construct() {
parent::start(
'events',
__( 'Events', 'bp-events-calendar' ),
plugin_dir_path( __FILE__ ),
array(
'adminbar_myaccount_order' => 100
)
);
// include our files
$this->includes();
// setup hooks
$this->setup_hooks();
}
/**
* Include files
*
* @global BuddyPress $bp The one true BuddyPress instance
*/
public function includes( $includes = array() ) {
include( BP_EVENTS_CALENDAR_PLUGIN_DIR . '/includes/class-bpec-event-form.php' );
include( BP_EVENTS_CALENDAR_PLUGIN_DIR . '/includes/bpec-functions.php' );
include( BP_EVENTS_CALENDAR_PLUGIN_DIR . '/includes/bpec-actions.php' );
include( BP_EVENTS_CALENDAR_PLUGIN_DIR . '/includes/bpec-templates.php' );
include( BP_EVENTS_CALENDAR_PLUGIN_DIR . '/includes/bpec-screens.php' );
//groups
require( BP_EVENTS_CALENDAR_PLUGIN_DIR .'/includes/bpec-groups-extension.php' );
require( BP_EVENTS_CALENDAR_PLUGIN_DIR .'/includes/class-bpec-events-members.php' );
//Admin includes
if ( is_admin() ) {
/** settings ***************************************************/
include( BP_EVENTS_CALENDAR_PLUGIN_DIR . '/includes/admin/class-bpec-settings.php' );
}
}
/**
* Setup hooks.
*/
public function setup_hooks() {
// javascript hook
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
// Admin hooks
// if ( is_admin() ) {
// //Setting page init
// $this->settings_page = new BPEC_Settings();
// add_action( 'admin_menu', array( $this, 'add_menu_page' ), 12 );
// }
}
/**
* Setup globals
*
* The BP_EVENTS_CALENDAR_SLUG constant is deprecated, and only used here for
* backwards compatibility.
*
* @since BuddyPress (1.5)
*/
public function setup_globals( $args = array() ) {
global $bp;
// Define a slug, if necessary
if ( !defined( 'BP_EVENTS_CALENDAR_SLUG' ) )
define( 'BP_EVENTS_CALENDAR_SLUG', $this->id );
/** Core setup globals ************************************************/
parent::setup_globals( array(
'slug' => BP_EVENTS_CALENDAR_SLUG,
'has_directory' => false,
'global_tables' => array(
'table_name' => $bp->table_prefix . 'bpec_groups_events',
'table_name_members' => $bp->table_prefix . 'bpec_events_members',
)
) );
}
/**
* Set up navigation.
*/
public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
if ( get_current_user_id() != bp_displayed_user_id() )
return;
// Determine user to use
if ( bp_displayed_user_domain() ) {
$user_domain = bp_displayed_user_domain();
} elseif ( bp_loggedin_user_domain() ) {
$user_domain = bp_loggedin_user_domain();
} else {
return;
}
$main_nav = array(
'name' => __( 'Events', 'bp-events-calendar' ),
'slug' => $this->slug,
'position' => 100,
'show_for_displayed_user' => bp_core_can_edit_settings(),
'screen_function' => 'bpec_event_list_screen',
'default_subnav_slug' => 'event-lists'
);
$events_link = trailingslashit( $user_domain . $this->slug );
$sub_nav[] = array(
'name' => __( 'Events', 'bp-events-calendar' ),
'slug' => 'event-lists',
'parent_url' => $events_link,
'parent_slug' => $this->slug,
'screen_function' => 'bpec_event_list_screen',
'position' => 10,
);
$sub_nav[] = array(
'name' => __( 'Add Event', 'bp-events-calendar' ),
'slug' => 'add-event',
'parent_url' => $events_link,
'parent_slug' => $this->slug,
'screen_function' => 'bpec_event_add_screen',
'position' => 20,
);
if ( bp_is_current_component($this->slug) && bp_is_current_action('attendees') && bp_action_variable(0) ) {
$sub_nav[] = array(
'name' => __( 'Attendees', 'bp-events-calendar' ),
'slug' => 'attendees',
'parent_url' => $events_link,
'parent_slug' => $this->slug,
'screen_function' => 'bpec_event_attendees_screen',
'position' => 30,
);
}
if ( bp_is_current_component($this->slug) && bp_is_current_action('orders') && bp_action_variable(0) ) {
$sub_nav[] = array(
'name' => __( 'Orders', 'bp-events-calendar' ),
'slug' => 'orders',
'parent_url' => $events_link,
'parent_slug' => $this->slug,
'screen_function' => 'bpec_event_orders_screen',
'position' => 40,
);
}
parent::setup_nav( $main_nav, $sub_nav );
}
/**
* Set up the Toolbar
*/
public function setup_admin_bar( $wp_admin_nav = array() ) {
// The instance
$bp = buddypress();
$tec = Tribe__Events__Main::instance();
$events_slug = $tec->getRewriteSlug();
$events_url = home_url() . '/' .$events_slug;
// Menus for logged in user
if ( is_user_logged_in() ) {
// Setup the logged in user variables
$user_domain = bp_loggedin_user_domain();
$events_link = trailingslashit( $user_domain . $this->slug );
$wp_admin_nav[] = array(
'parent' => $bp->my_account_menu_id,
'id' => 'my-account-' . $this->id,
'title' => __( 'Events', 'bp-events-calendar' ),
'href' => trailingslashit( $events_link )
);
$wp_admin_nav[] = array(
'parent' => 'my-account-' . $this->id,
'id' => 'my-account-' . $this->id . '-event-lists',
'title' => __( 'Event Lists', 'bp-events-calendar' ),
'href' => trailingslashit( $events_link . 'event-lists' )
);
$wp_admin_nav[] = array(
'parent' => 'my-account-' . $this->id,
'id' => 'my-account-' . $this->id . '-calendar',
'title' => __( 'Calendar', 'bp-events-calendar' ),
'href' => trailingslashit( $events_url )
);
$wp_admin_nav[] = array(
'parent' => 'my-account-' . $this->id,
'id' => 'my-account-' . $this->id . '-add-event',
'title' => __( 'Add Event', 'bp-events-calendar' ),
'href' => trailingslashit( $events_link . 'add-event' )
);
}
parent::setup_admin_bar( $wp_admin_nav );
}
/**
* Enqueues the javascript.
*
* The JS is used to add AJAX functionality when clicking on the follow button.
*/
public function enqueue_scripts() {
/** STYLE *****************************************************************************/
wp_enqueue_style('bpec-main', BP_EVENTS_CALENDAR_PLUGIN_URL . '/assets/css/bpec-main.css', array(), BP_EVENTS_CALENDAR_VERSION );
wp_enqueue_style('magnific-popup', BP_EVENTS_CALENDAR_PLUGIN_URL . '/assets/css/magnific-popup.css', array(), '1.1.0' );
/** SCRIPTS *****************************************************************************/
wp_enqueue_script('bpec-main', BP_EVENTS_CALENDAR_PLUGIN_URL . '/assets/js/bpec-main.js', array('jquery'), BP_EVENTS_CALENDAR_VERSION );
wp_enqueue_script('tether', BP_EVENTS_CALENDAR_PLUGIN_URL . '/assets/js/tether.min.js', array(), '1.4.0' );
wp_enqueue_script('drop', BP_EVENTS_CALENDAR_PLUGIN_URL . '/assets/js/drop.min.js', array(), '1.2.2' );
wp_enqueue_script('jquery.magnific-popup', BP_EVENTS_CALENDAR_PLUGIN_URL . '/assets/js/jquery.magnific-popup.min.js', array('jquery'), '1.1.0' );
/** TRIBE EVENT ASSETS *****************************************************************************/
$tec = Tribe__Events__Main::instance();
Tribe__Events__Template_Factory::asset_package( 'chosen' );
Tribe__Events__Template_Factory::asset_package( 'select2' );
Tribe__Events__Template_Factory::asset_package( 'dropdowns' );
Tribe__Events__Template_Factory::asset_package( 'admin-ui' );
Tribe__Events__Template_Factory::asset_package( 'datepicker' );
Tribe__Events__Template_Factory::asset_package( 'dialogue' );
Tribe__Events__Template_Factory::asset_package( 'ecp-plugins' );
Tribe__Events__Template_Factory::asset_package( 'admin' );
// This comes from Common Lib
wp_enqueue_style( 'tribe-jquery-ui-datepicker' );
// calling our own localization because wp_localize_scripts doesn't support arrays or objects for values, which we need.
add_action( 'admin_footer', array( $tec, 'printLocalizedAdmin' ) );
// hook for other plugins
do_action( 'tribe_events_enqueue' );
add_action( 'wp_footer', array( $tec, 'printLocalizedAdmin' ) );
// load EC resources
add_action( 'wp_enqueue_scripts', array( $this, 'addScriptsAndStyles' ) );
// jquery-resize
Tribe__Events__Template_Factory::asset_package( 'jquery-resize' );
// smoothness
Tribe__Events__Template_Factory::asset_package( 'smoothness' );
// Tribe Calendar JS
Tribe__Events__Template_Factory::asset_package( 'calendar-script' );
Tribe__Events__Template_Factory::asset_package( 'events-css' );
Tribe__Events__Template_Factory::asset_package( 'tribe-select2' );
// Admin Legacy Migration
Tribe__Events__Template_Factory::asset_package( 'admin-migrate-legacy-ignored-events' );
$data = array(
'post_types' => array(
'tribe_organizer' => "organizer",
'tribe_venue' => "venue"
),
);
wp_localize_script( 'tribe-events-admin', 'tribe_events_linked_posts', $data );
//Event list page styles and scripts
if ( bp_is_current_component('events') && bp_is_current_action('event-lists') ) {
wp_enqueue_style( Tribe__Events__Main::POSTTYPE . '-community' );
wp_enqueue_script( Tribe__Events__Main::POSTTYPE . '-community' );
}
if ( bpec_is_event_tickets_active() ) {
$resources_url = Tribe__Tickets__Main::instance()->plugin_url . 'src/resources/';
wp_enqueue_style( 'event-tickets', $resources_url .'/css/tickets.css', array(), Tribe__Tickets__Main::instance()->css_version() );
wp_enqueue_script( 'event-tickets', $resources_url .'/js/tickets.js', array( 'jquery-ui-datepicker' ), Tribe__Tickets__Main::instance()->js_version(), true );
wp_enqueue_style( 'tickets-attendees', $resources_url . '/css/tickets-attendees.css', array(), Tribe__Tickets__Main::instance()->css_version() );
wp_enqueue_style( 'tickets-attendees' . '-print', $resources_url . '/css/tickets-attendees-print.css', array(), Tribe__Tickets__Main::instance()->css_version(), 'print' );
wp_enqueue_script( 'tickets-attendees', $resources_url . '/js/tickets-attendees.js', array( 'jquery' ), Tribe__Tickets__Main::instance()->js_version() );
wp_localize_script( 'event-tickets', 'tribe_ticket_notices', array(
'confirm_alert' => __( 'Are you sure you want to delete this ticket? This cannot be undone.', 'bp-events-calendar' ),
) );
$upload_header_data = array(
'title' => esc_html__( 'Ticket header image', 'bp-events-calendar' ),
'button' => esc_html__( 'Set as ticket header', 'bp-events-calendar' ),
);
wp_localize_script( 'event-tickets', 'HeaderImageData', $upload_header_data );
wp_localize_script( 'event-tickets', 'tribe_global_stock_admin_ui', array(
'nav_away_msg' => __( 'It looks like you have modified your global stock settings but have not saved or updated the post.', 'bp-events-calendar' ),
) );
$nonces = array(
'add_ticket_nonce' => wp_create_nonce( 'add_ticket_nonce' ),
'edit_ticket_nonce' => wp_create_nonce( 'edit_ticket_nonce' ),
'remove_ticket_nonce' => wp_create_nonce( 'remove_ticket_nonce' ),
);
wp_localize_script( 'event-tickets', 'TribeTickets', $nonces );
$mail_data = array(
'nonce' => wp_create_nonce( 'email-attendee-list' ),
'required' => esc_html__( 'You need to select a user or type a valid email address', 'bp-events-calendar' ),
'sending' => esc_html__( 'Sending...', 'bp-events-calendar' ),
'checkin_nonce' => wp_create_nonce( 'checkin' ),
'uncheckin_nonce' => wp_create_nonce( 'uncheckin' ),
'cannot_move' => esc_html__( 'You must first select one or more tickets before you can move them!', 'bp-events-calendar' ),
'move_url' => add_query_arg( array(
'dialog' => Tribe__Tickets__Main::instance()->move_tickets()->dialog_name(),
'check' => wp_create_nonce( 'move_tickets' ),
'TB_iframe' => 'true',
) ),
);
wp_localize_script( 'tickets-attendees', 'Attendees', $mail_data );
wp_enqueue_script( 'tribe-bumpdown' );
}
wp_localize_script( 'bpec-main', 'bpec_global_vars', apply_filters( 'bpec_global_vars', array(
'join' => __( 'Join', 'bp-events-calendar' ),
'going' => __( 'Going', 'bp-events-calendar' ),
'not_going' => __( 'Not Going', 'bp-events-calendar' ),
'interested' => __( 'Interested', 'bp-events-calendar' ),
'not_interested' => __( 'Not Interested', 'bp-events-calendar' ),
) ) );
}
/**
* Add Admin Menu page link
*
* @return void
* @return void
*/
public function add_menu_page() {
global $wpdrift_admin_page_hooks;
if( ! isset( $wpdrift_admin_page_hooks ) ){
$position = apply_filters( 'wpdrift_panel_menu_item_position', '62.33' );
// Plugins text must not be translated
apply_filters('wpdrift_panel_menu_page_capability', current_user_can( 'manage_options' )) && add_menu_page( 'wpdrift_panel', 'WP Drift', 'manage_options', 'wpdrift_panel', NULL, '', $position );
}
add_submenu_page( 'wpdrift_panel', __( 'BP Events Calendar', 'bp-events-calendar' ), __( 'BP Events Calendar', 'bp-events-calendar' ), 'manage_options', 'bp-events-calendar-settings', array( $this->settings_page, 'output' ) );
remove_submenu_page( 'wpdrift_panel', 'wpdrift_panel' ); //Need to remove submenu "wpdrift_panel" created from parent add_menu_page
}
}
/**
* Loads the Follow component into the $bp global
*
* @package BP-Follow
* @global obj $bp BuddyPress instance
* @since 1.2
*/
function bpec_setup_component() {
global $bp;
$bp->bpec = new BP_Events_Component();
do_action( 'bpec_loaded' );
}
add_action( 'bp_loaded', 'bpec_setup_component' );