b82043ca by Jeff Balicki

insta and events

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent 64a4b5a7
Showing 886 changed files with 4939 additions and 0 deletions
<?php
/**
* Generates a "widget" table of confirmed bookings for a specific event.
*
* @param int $event_id
*/
function em_bookings_cancelled_table(){
global $EM_Event, $EM_Ticket, $wpdb, $current_user;
$action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_cancelled_table' );
$action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
$order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
$limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
$page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
$offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
if( is_object($EM_Ticket) ){
$EM_Bookings = $EM_Ticket->get_bookings()->get_cancelled_bookings();
}else{
if( is_object($EM_Event) ){
$EM_Bookings = $EM_Event->get_bookings()->get_cancelled_bookings();
}else{
return false;
}
}
$bookings_count = (is_array($EM_Bookings->bookings)) ? count($EM_Bookings->bookings):0;
?>
<div class='wrap em_bookings_pending_table em_obj'>
<form id='bookings-filter' method='get' action='<?php bloginfo('wpurl') ?>/wp-admin/edit.php'>
<input type="hidden" name="em_obj" value="em_bookings_pending_table" />
<!--
<ul class="subsubsub">
<li>
<a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> |
</li>
</ul>
<p class="search-box">
<label class="screen-reader-text" for="post-search-input"><?php _e('Search', 'events-manager'); ?>:</label>
<input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? esc_attr($_GET['em_search']):''; ?>" />
<input type="submit" value="<?php _e('Search', 'events-manager'); ?>" class="button" />
</p>
-->
<?php if ( $bookings_count >= $limit ) : ?>
<div class='tablenav'>
<!--
<div class="alignleft actions">
<select name="action">
<option value="-1" selected="selected">
<?php _e('Bulk Actions', 'events-manager'); ?>
</option>
<option value="approve">
<?php _e('Approve', 'events-manager'); ?>
</option>
<option value="decline">
<?php _e('Decline', 'events-manager'); ?>
</option>
</select>
<input type="submit" id="post-query-submit" value="Filter" class="button-secondary" />
</div>
-->
<!--
<div class="view-switch">
<a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
</div>
-->
<?php
if ( $bookings_count >= $limit ) {
$bookings_nav = em_admin_paginate( $bookings_count, $limit, $page, array('em_ajax'=>0, 'em_obj'=>'em_bookings_confirmed_table'));
echo $bookings_nav;
}
?>
<div class="clear"></div>
</div>
<?php endif; ?>
<div class="clear"></div>
<?php if( $bookings_count > 0 ): ?>
<div class='table-wrap'>
<table id='dbem-bookings-table' class='widefat post '>
<thead>
<tr>
<th class='manage-column column-cb check-column' scope='col'>
<input class='select-all' type="checkbox" value='1' />
</th>
<th class='manage-column' scope='col'><?php _e('Booker', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('E-mail', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Phone number', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Spaces', 'events-manager'); ?></th>
<th class='manage-column' scope='col'>&nbsp;</th>
</tr>
</thead>
<tbody>
<?php
$rowno = 0;
$event_count = 0;
foreach ($EM_Bookings->bookings as $EM_Booking) {
if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
$rowno++;
?>
<tr>
<th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->booking_id ?>' name='bookings[]'/></th>
<td><a href="<?php echo EM_ADMIN_URL; ?>&amp;page=events-manager-bookings&amp;person_id=<?php echo $EM_Booking->person->ID; ?>"><?php echo $EM_Booking->person->get_name() ?></a></td>
<td><?php echo $EM_Booking->person->user_email ?></td>
<td><?php echo $EM_Booking->person->phone ?></td>
<td><?php echo $EM_Booking->get_spaces() ?></td>
<td>
<?php
$approve_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_approve', 'booking_id'=>$EM_Booking->booking_id));
$delete_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_delete', 'booking_id'=>$EM_Booking->booking_id));
$edit_url = em_add_get_params($_SERVER['REQUEST_URI'], array('booking_id'=>$EM_Booking->booking_id, 'em_ajax'=>null, 'em_obj'=>null));
?>
<a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Restore','events-manager'); ?></a> |
<a class="em-bookings-edit" href="<?php echo $edit_url; ?>"><?php _e('Edit/View','events-manager'); ?></a> |
<a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','events-manager'); ?></a>
</td>
</tr>
<?php
}
$event_count++;
}
?>
</tbody>
</table>
</div>
<?php else: ?>
<?php _e('No cancelled bookings.', 'events-manager'); ?>
<?php endif; ?>
</form>
<?php if( !empty($bookings_nav) && $EM_Bookings >= $limit ) : ?>
<div class='tablenav'>
<?php echo $bookings_nav; ?>
<div class="clear"></div>
</div>
<?php endif; ?>
</div>
<?php
}
?>
\ No newline at end of file
<?php
/**
* Generates a "widget" table of confirmed bookings for a specific event.
*
* @param int $event_id
*/
function em_bookings_confirmed_table(){
global $EM_Event, $EM_Ticket, $wpdb, $current_user;
$action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_confirmed_table' );
$action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
$order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
$limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
$page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
$offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
if( is_object($EM_Ticket) ){
$EM_Bookings = $EM_Ticket->get_bookings()->get_bookings();
}else{
if( is_object($EM_Event) ){
$EM_Bookings = $EM_Event->get_bookings()->get_bookings();
}else{
return false;
}
}
$bookings_count = (is_array($EM_Bookings->bookings)) ? count($EM_Bookings->bookings):0;
?>
<div class='wrap em_bookings_pending_table em_obj'>
<form id='bookings-filter' method='get' action='<?php bloginfo('wpurl') ?>/wp-admin/edit.php'>
<input type="hidden" name="em_obj" value="em_bookings_pending_table" />
<!--
<ul class="subsubsub">
<li>
<a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> |
</li>
</ul>
<p class="search-box">
<label class="screen-reader-text" for="post-search-input"><?php _e('Search', 'events-manager'); ?>:</label>
<input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? esc_attr($_GET['em_search']):''; ?>" />
<input type="submit" value="<?php _e('Search', 'events-manager'); ?>" class="button" />
</p>
-->
<?php if ( $bookings_count >= $limit ) : ?>
<div class='tablenav'>
<!--
<div class="alignleft actions">
<select name="action">
<option value="-1" selected="selected">
<?php _e('Bulk Actions', 'events-manager'); ?>
</option>
<option value="approve">
<?php _e('Approve', 'events-manager'); ?>
</option>
<option value="decline">
<?php _e('Decline', 'events-manager'); ?>
</option>
</select>
<input type="submit" id="post-query-submit" value="Filter" class="button-secondary" />
</div>
-->
<!--
<div class="view-switch">
<a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
</div>
-->
<?php
if ( $bookings_count >= $limit ) {
$bookings_nav = em_admin_paginate($bookings_count, $limit, $page, array('em_ajax'=>0, 'em_obj'=>'em_bookings_confirmed_table'));
echo $bookings_nav;
}
?>
<div class="clear"></div>
</div>
<?php endif; ?>
<div class="clear"></div>
<?php if( $bookings_count > 0 ): ?>
<div class='table-wrap'>
<table id='dbem-bookings-table' class='widefat post '>
<thead>
<tr>
<th class='manage-column column-cb check-column' scope='col'>
<input class='select-all' type="checkbox" value='1' />
</th>
<th class='manage-column' scope='col'><?php _e('Booker', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('E-mail', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Phone number', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Spaces', 'events-manager'); ?></th>
<th class='manage-column' scope='col'>&nbsp;</th>
</tr>
</thead>
<tbody>
<?php
$rowno = 0;
$event_count = 0;
foreach ($EM_Bookings->bookings as $EM_Booking) {
if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
$rowno++;
?>
<tr>
<th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->booking_id ?>' name='bookings[]'/></th>
<td><a href="<?php echo EM_ADMIN_URL; ?>&amp;page=events-manager-bookings&amp;person_id=<?php echo $EM_Booking->person_id; ?>"><?php echo $EM_Booking->person->get_name() ?></a></td>
<td><?php echo $EM_Booking->person->user_email ?></td>
<td><?php echo $EM_Booking->person->phone ?></td>
<td><?php echo $EM_Booking->get_spaces() ?></td>
<td>
<?php
$unapprove_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_unapprove', 'booking_id'=>$EM_Booking->booking_id));
$reject_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_reject', 'booking_id'=>$EM_Booking->booking_id));
$delete_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_delete', 'booking_id'=>$EM_Booking->booking_id));
$edit_url = em_add_get_params($_SERVER['REQUEST_URI'], array('booking_id'=>$EM_Booking->booking_id, 'em_ajax'=>null, 'em_obj'=>null));
?>
<?php if( current_user_can('manage_bookings') && get_option('dbem_bookings_approval') ): ?>
<a class="em-bookings-unapprove" href="<?php echo $unapprove_url ?>"><?php _e('Unapprove','events-manager'); ?></a> |
<?php else: ?>
<a class="em-bookings-reject" href="<?php echo $reject_url ?>"><?php _e('Reject','events-manager'); ?></a> |
<?php endif; ?>
<span class="trash"><a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','events-manager'); ?></a></span> |
<a class="em-bookings-edit" href="<?php echo $edit_url; ?>"><?php _e('Edit/View','events-manager'); ?></a>
</td>
</tr>
<?php
}
$event_count++;
}
?>
</tbody>
</table>
</div>
<?php else: ?>
<?php _e('No confirmed bookings.', 'events-manager'); ?>
<?php endif; ?>
</form>
<?php if( !empty($bookings_nav) && $EM_Bookings >= $limit ) : ?>
<div class='tablenav'>
<?php echo $bookings_nav; ?>
<div class="clear"></div>
</div>
<?php endif; ?>
</div>
<?php
}
?>
\ No newline at end of file
<?php
/**
* Determines whether to show event page or events page, and saves any updates to the event or events
* @return null
*/
function em_bookings_events_table() {
//TODO Simplify panel for events, use form flags to detect certain actions (e.g. submitted, etc)
global $wpdb;
$scope_names = array (
'past' => __ ( 'Past events', 'events-manager'),
'all' => __ ( 'All events', 'events-manager'),
'future' => __ ( 'Future events', 'events-manager')
);
$action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_events_table' );
$action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
$order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
$limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
$page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
$offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
$scope = ( $action_scope && !empty($_GET ['scope']) && array_key_exists($_GET ['scope'], $scope_names) ) ? $_GET ['scope']:'future';
// No action, only showing the events list
switch ($scope) {
case "past" :
$title = __ ( 'Past Events', 'events-manager');
break;
case "all" :
$title = __ ( 'All Events', 'events-manager');
break;
default :
$title = __ ( 'Future Events', 'events-manager');
$scope = "future";
}
$owner = !current_user_can('manage_others_bookings') ? get_current_user_id() : false;
$events = EM_Events::get( array('scope'=>$scope, 'limit'=>$limit, 'offset' => $offset, 'order'=>$order, 'orderby'=>'event_start', 'bookings'=>true, 'owner' => $owner, 'pagination' => 1 ) );
$events_count = EM_Events::$num_rows_found;
$use_events_end = get_option ( 'dbem_use_event_end' );
?>
<div class="wrap em_bookings_events_table em_obj">
<form id="posts-filter" action="" method="get">
<input type="hidden" name="em_obj" value="em_bookings_events_table" />
<?php if(!empty($_GET['page'])): ?>
<input type='hidden' name='page' value='events-manager-bookings' />
<?php endif; ?>
<div class="tablenav">
<div class="alignleft actions">
<!--
<select name="action">
<option value="-1" selected="selected"><?php esc_html_e( 'Bulk Actions' ); ?></option>
<option value="deleteEvents"><?php esc_html_e( 'Delete selected','events-manager'); ?></option>
</select>
<input type="submit" value="<?php esc_html_e( 'Apply' ); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
-->
<select name="scope">
<?php
foreach ( $scope_names as $key => $value ) {
$selected = "";
if ($key == $scope)
$selected = "selected='selected'";
echo "<option value='$key' $selected>$value</option> ";
}
?>
</select>
<input id="post-query-submit" class="button-secondary" type="submit" value="<?php esc_html_e( 'Filter' )?>" />
</div>
<!--
<div class="view-switch">
<a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
</div>
-->
<?php
if ( $events_count >= $limit ) {
$events_nav = em_admin_paginate( $events_count, $limit, $page, array('em_ajax'=>0, 'em_obj'=>'em_bookings_events_table'));
echo $events_nav;
}
?>
</div>
<div class="clear"></div>
<?php
if (empty ( $events )) {
// TODO localize
_e ( 'no events','events-manager');
} else {
?>
<div class='table-wrap'>
<table class="widefat">
<thead>
<tr>
<th><?php esc_html_e( 'Event', 'events-manager'); ?></th>
<th><?php esc_html_e( 'Date and time', 'events-manager'); ?></th>
</tr>
</thead>
<tbody>
<?php
$rowno = 0;
foreach ( $events as $EM_Event ) {
/* @var $event EM_Event */
$rowno++;
$class = ($rowno % 2) ? ' class="alternate"' : '';
$style = "";
if ($EM_Event->start()->getTimestamp() < time() && $EM_Event->end()->getTimestamp() < time()){
$style = "style ='background-color: #FADDB7;'";
}
?>
<tr <?php echo "$class $style"; ?>>
<td>
<strong>
<?php echo $EM_Event->output('#_BOOKINGSLINK'); ?>
</strong>
&ndash;
<?php esc_html_e("Booked Spaces",'events-manager') ?>: <?php echo $EM_Event->get_bookings()->get_booked_spaces()."/".$EM_Event->get_spaces() ?>
<?php if( get_option('dbem_bookings_approval') == 1 ) : ?>
| <?php esc_html_e("Pending",'events-manager') ?>: <?php echo $EM_Event->get_bookings()->get_pending_spaces(); ?>
<?php endif; ?>
</td>
<td>
<?php echo $EM_Event->output_dates(false, " - "). ' @ ' . $EM_Event->output_times(false, ' - '); ?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<?php
} // end of table
?>
<div class='tablenav'>
<div class="alignleft actions">
<br class='clear' />
</div>
<?php if (!empty($events_nav) && $events_count >= $limit ) : ?>
<div class="tablenav-pages">
<?php
echo $events_nav;
?>
</div>
<?php endif; ?>
<br class='clear' />
</div>
</form>
</div>
<?php
}
?>
\ No newline at end of file
<?php
/**
* Generates a "widget" table of pending bookings with some quick admin operation options.
* If event id supplied then only pending bookings for that event will show.
*
* @param int $event_id
*/
function em_bookings_pending_table($event_id = false){
global $EM_Event, $EM_Ticket, $wpdb, $current_user;
if( get_option('dbem_bookings_approval') == 0 ){
return false;
}
$action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_pending_table' );
$action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
$order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
$limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
$page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
$offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
if( is_object($EM_Ticket) ){
$EM_Bookings = $EM_Ticket->get_bookings()->get_pending_bookings();
}else{
if( is_object($EM_Event) ){
$EM_Bookings = $EM_Event->get_bookings()->get_pending_bookings();
}else{
//To optimize performance, we can do one query here for all pending bookings to show.
$EM_Bookings = EM_Bookings::get(array('status'=>0));
$events = array();
//Now let's create events and bookings for this:
foreach($EM_Bookings->bookings as $EM_Booking){
//create event
if( !array_key_exists($EM_Booking->event_id,$events) ){
$events[$EM_Booking->event_id] = new EM_Event($EM_Booking->event_id);
}
}
}
}
$bookings_count = (is_array($EM_Bookings->bookings)) ? count($EM_Bookings->bookings):0;
?>
<div class='wrap em_bookings_pending_table em_obj'>
<form id='bookings-filter' method='get' action='<?php bloginfo('wpurl') ?>/wp-admin/edit.php'>
<input type="hidden" name="em_obj" value="em_bookings_pending_table" />
<!--
<ul class="subsubsub">
<li>
<a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> |
</li>
</ul>
<p class="search-box">
<label class="screen-reader-text" for="post-search-input"><?php _e('Search', 'events-manager'); ?>:</label>
<input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? esc_attr($_GET['em_search']):''; ?>" />
<input type="submit" value="<?php _e('Search', 'events-manager'); ?>" class="button" />
</p>
-->
<?php if ( $bookings_count >= $limit ) : ?>
<div class='tablenav'>
<!--
<div class="alignleft actions">
<select name="action">
<option value="-1" selected="selected">
<?php _e('Bulk Actions', 'events-manager'); ?>
</option>
<option value="approve">
<?php _e('Approve', 'events-manager'); ?>
</option>
<option value="decline">
<?php _e('Decline', 'events-manager'); ?>
</option>
</select>
<input type="submit" id="post-query-submit" value="Filter" class="button-secondary" />
</div>
-->
<!--
<div class="view-switch">
<a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
</div>
-->
<?php
if ( $bookings_count >= $limit ) {
$bookings_nav = em_admin_paginate( $bookings_count, $limit, $page, array('em_ajax'=>0, 'em_obj'=>'em_bookings_pending_table'));
echo $bookings_nav;
}
?>
<div class="clear"></div>
</div>
<?php endif; ?>
<div class="clear"></div>
<?php if( $bookings_count > 0 ): ?>
<div class='table-wrap'>
<table id='dbem-bookings-table' class='widefat post '>
<thead>
<tr>
<th class='manage-column column-cb check-column' scope='col'>
<input class='select-all' type="checkbox" value='1' />
</th>
<th class='manage-column' scope='col'><?php _e('Booker', 'events-manager'); ?></th>
<?php if( !is_object($EM_Event) && !is_object($EM_Ticket) ): ?>
<th class='manage-column' scope="col"><?php _e('Event', 'events-manager'); ?></th>
<?php endif; ?>
<th class='manage-column' scope='col'><?php _e('E-mail', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Phone number', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Spaces', 'events-manager'); ?></th>
<th class='manage-column' scope='col'>&nbsp;</th>
</tr>
</thead>
<tbody>
<?php
$rowno = 0;
$event_count = 0;
foreach ($EM_Bookings->bookings as $EM_Booking) {
if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
$rowno++;
?>
<tr>
<th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->booking_id ?>' name='bookings[]'/></th>
<td><a href="<?php echo EM_ADMIN_URL; ?>&amp;page=events-manager-bookings&amp;person_id=<?php echo $EM_Booking->person->ID; ?>"><?php echo $EM_Booking->person->get_name() ?></a></td>
<?php if( !is_object($EM_Event) && !is_object($EM_Ticket) ): ?>
<td><a href="<?php echo EM_ADMIN_URL; ?>&amp;page=events-manager-bookings&amp;event_id=<?php echo $EM_Booking->event_id; ?>"><?php echo $events[$EM_Booking->event_id]->name ?></a></td>
<?php endif; ?>
<td><?php echo $EM_Booking->person->user_email ?></td>
<td><?php echo $EM_Booking->person->phone ?></td>
<td><?php echo $EM_Booking->get_spaces() ?></td>
<td>
<?php
$approve_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_approve', 'booking_id'=>$EM_Booking->booking_id));
$reject_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_reject', 'booking_id'=>$EM_Booking->booking_id));
$delete_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_delete', 'booking_id'=>$EM_Booking->booking_id));
?>
<a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Approve','events-manager'); ?></a> |
<a class="em-bookings-reject" href="<?php echo $reject_url ?>"><?php _e('Reject','events-manager'); ?></a> |
<span class="trash"><a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','events-manager'); ?></a></span> |
<a class="em-bookings-edit" href="<?php echo EM_ADMIN_URL; ?>&amp;page=events-manager-bookings&amp;booking_id=<?php echo $EM_Booking->booking_id; ?>"><?php _e('Edit/View','events-manager'); ?></a>
</td>
</tr>
<?php
}
$event_count++;
}
?>
</tbody>
</table>
</div>
<?php else: ?>
<?php _e('No pending bookings.', 'events-manager'); ?>
<?php endif; ?>
</form>
<?php if( !empty($bookings_nav) && $EM_Bookings >= $limit ) : ?>
<div class='tablenav'>
<?php echo $bookings_nav; ?>
<div class="clear"></div>
</div>
<?php endif; ?>
</div>
<?php
}
?>
\ No newline at end of file
<?php
/**
* Generates a "widget" table of confirmed bookings for a specific event.
*
* @param int $event_id
*/
function em_bookings_person_table(){
global $wpdb, $current_user,$EM_Person;
if(!is_object($EM_Person)){
return false;
}
$action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_confirmed_table' );
$action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
$order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
$limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
$page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
$offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
$bookings = $EM_Person->get_bookings();
$bookings_count = count($bookings);
if($bookings_count > 0){
//Get events here in one query to speed things up
foreach($bookings as $EM_Booking){
$event_ids[] = $EM_Booking->event_id;
}
$events = EM_Events::get($event_ids);
}
?>
<div class='wrap em_bookings_pending_table em_obj'>
<form id='bookings-filter' method='get' action='<?php bloginfo('wpurl') ?>/wp-admin/edit.php'>
<input type="hidden" name="em_obj" value="em_bookings_pending_table" />
<!--
<ul class="subsubsub">
<li>
<a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> |
</li>
</ul>
<p class="search-box">
<label class="screen-reader-text" for="post-search-input"><?php _e('Search', 'events-manager'); ?>:</label>
<input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? esc_attr($_GET['em_search']):''; ?>" />
<input type="submit" value="<?php _e('Search', 'events-manager'); ?>" class="button" />
</p>
-->
<?php if ( $bookings_count >= $limit ) : ?>
<div class='tablenav'>
<!--
<div class="alignleft actions">
<select name="action">
<option value="-1" selected="selected">
<?php _e('Bulk Actions', 'events-manager'); ?>
</option>
<option value="approve">
<?php _e('Approve', 'events-manager'); ?>
</option>
<option value="decline">
<?php _e('Decline', 'events-manager'); ?>
</option>
</select>
<input type="submit" id="post-query-submit" value="Filter" class="button-secondary" />
</div>
-->
<!--
<div class="view-switch">
<a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
</div>
-->
<?php
if ( $bookings_count >= $limit ) {
$bookings_nav = em_admin_paginate( $bookings_count, $limit, $page, array('em_ajax'=>0, 'em_obj'=>'em_bookings_confirmed_table'));
echo $bookings_nav;
}
?>
<div class="clear"></div>
</div>
<?php endif; ?>
<div class="clear"></div>
<?php if( $bookings_count > 0 ): ?>
<div class='table-wrap'>
<table id='dbem-bookings-table' class='widefat post '>
<thead>
<tr>
<th class='manage-column column-cb check-column' scope='col'>
<input class='select-all' type="checkbox" value='1' />
</th>
<th class='manage-column' scope='col'><?php _e('Event', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Spaces', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Status', 'events-manager'); ?></th>
<th class='manage-column' scope='col'>&nbsp;</th>
</tr>
</thead>
<tbody>
<?php
$rowno = 0;
$event_count = 0;
foreach ($bookings as $EM_Booking) {
$EM_Event = $events[$EM_Booking->event_id];
if( $EM_Event->can_manage('edit_events','edit_others_events') && ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
$rowno++;
?>
<tr>
<th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->booking_id ?>' name='bookings[]'/></th>
<td><a class="row-title" href="<?php echo EM_ADMIN_URL; ?>&amp;page=events-manager-bookings&amp;event_id=<?php echo $EM_Event->event_id ?>"><?php echo ($EM_Event->event_name); ?></a></td>
<td><?php echo $EM_Booking->get_spaces() ?></td>
<td><?php echo $EM_Booking->status_array[$EM_Booking->booking_status]; ?>
</td>
<td>
<?php
$unapprove_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_unapprove', 'booking_id'=>$EM_Booking->booking_id));
$approve_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_approve', 'booking_id'=>$EM_Booking->booking_id));
$reject_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_reject', 'booking_id'=>$EM_Booking->booking_id));
$delete_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_delete', 'booking_id'=>$EM_Booking->booking_id));
?>
<?php if( get_option('dbem_bookings_approval') && ($EM_Booking->booking_status == 0 ) ): ?>
<a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Approve','events-manager'); ?></a> |
<?php endif; ?>
<?php if( get_option('dbem_bookings_approval') && $EM_Booking->booking_status == 1 ): ?>
<a class="em-bookings-unapprove" href="<?php echo $unapprove_url ?>"><?php _e('Unapprove','events-manager'); ?></a> |
<?php endif; ?>
<?php if( $EM_Booking->booking_status == 2 ): ?>
<a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Restore','events-manager'); ?></a> |
<?php endif; ?>
<?php if( $EM_Booking->booking_status == 0 || $EM_Booking->booking_status == 1 ): ?>
<a class="em-bookings-reject" href="<?php echo $reject_url ?>"><?php _e('Reject','events-manager'); ?></a> |
<?php endif; ?>
<a class="em-bookings-edit" href="<?php echo EM_ADMIN_URL; ?>&amp;page=events-manager-bookings&amp;booking_id=<?php echo $EM_Booking->booking_id; ?>"><?php _e('Edit/View','events-manager'); ?></a> |
<span class="trash"><a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','events-manager'); ?></a></span>
</td>
</tr>
<?php
}
$event_count++;
}
?>
</tbody>
</table>
</div>
<?php else: ?>
<?php _e('No confirmed bookings.', 'events-manager'); ?>
<?php endif; ?>
</form>
<?php if( !empty($bookings_nav) && $bookings >= $limit ) : ?>
<div class='tablenav'>
<?php echo $bookings_nav; ?>
<div class="clear"></div>
</div>
<?php endif; ?>
</div>
<?php
}
?>
\ No newline at end of file
<?php
/**
* Generates a "widget" table of confirmed bookings for a specific event.
*
* @param int $event_id
*/
function em_bookings_rejected_table(){
global $EM_Event, $EM_Ticket, $wpdb, $current_user;
$action_scope = ( !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_confirmed_table' );
$action = ( $action_scope && !empty($_GET ['action']) ) ? $_GET ['action']:'';
$order = ( $action_scope && !empty($_GET ['order']) ) ? $_GET ['order']:'ASC';
$limit = ( $action_scope && !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
$page = ( $action_scope && !empty($_GET['pno']) ) ? $_GET['pno']:1;
$offset = ( $action_scope && $page > 1 ) ? ($page-1)*$limit : 0;
if( is_object($EM_Ticket) ){
$EM_Bookings = $EM_Ticket->get_bookings()->get_rejected_bookings();
}else{
if( is_object($EM_Event) ){
$EM_Bookings = $EM_Event->get_bookings()->get_rejected_bookings();
}else{
return false;
}
}
$bookings_count = (is_array($EM_Bookings->bookings)) ? count($EM_Bookings->bookings):0;
?>
<div class='wrap em_bookings_pending_table em_obj'>
<form id='bookings-filter' method='get' action='<?php bloginfo('wpurl') ?>/wp-admin/edit.php'>
<input type="hidden" name="em_obj" value="em_bookings_pending_table" />
<!--
<ul class="subsubsub">
<li>
<a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> |
</li>
</ul>
<p class="search-box">
<label class="screen-reader-text" for="post-search-input"><?php _e('Search', 'events-manager'); ?>:</label>
<input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_GET['em_search'])) ? esc_attr($_GET['em_search']):''; ?>" />
<input type="submit" value="<?php _e('Search', 'events-manager'); ?>" class="button" />
</p>
-->
<?php if ( $bookings_count >= $limit ) : ?>
<div class='tablenav'>
<!--
<div class="alignleft actions">
<select name="action">
<option value="-1" selected="selected">
<?php _e('Bulk Actions', 'events-manager'); ?>
</option>
<option value="approve">
<?php _e('Approve', 'events-manager'); ?>
</option>
<option value="decline">
<?php _e('Decline', 'events-manager'); ?>
</option>
</select>
<input type="submit" id="post-query-submit" value="Filter" class="button-secondary" />
</div>
-->
<!--
<div class="view-switch">
<a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
</div>
-->
<?php
if ( $bookings_count >= $limit ) {
$bookings_nav = em_admin_paginate( $bookings_count, $limit, $page, array('em_ajax'=>0, 'em_obj'=>'em_bookings_confirmed_table'));
echo $bookings_nav;
}
?>
<div class="clear"></div>
</div>
<?php endif; ?>
<div class="clear"></div>
<?php if( $bookings_count > 0 ): ?>
<div class='table-wrap'>
<table id='dbem-bookings-table' class='widefat post '>
<thead>
<tr>
<th class='manage-column column-cb check-column' scope='col'>
<input class='select-all' type="checkbox" value='1' />
</th>
<th class='manage-column' scope='col'><?php _e('Booker', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('E-mail', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Phone number', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Spaces', 'events-manager'); ?></th>
<th class='manage-column' scope='col'>&nbsp;</th>
</tr>
</thead>
<tbody>
<?php
$rowno = 0;
$event_count = 0;
foreach ($EM_Bookings->bookings as $EM_Booking) {
if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
$rowno++;
?>
<tr>
<th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->booking_id ?>' name='bookings[]'/></th>
<td><a href="<?php echo EM_ADMIN_URL; ?>&amp;page=events-manager-bookings&amp;person_id=<?php echo $EM_Booking->person->ID; ?>"><?php echo $EM_Booking->person->get_name() ?></a></td>
<td><?php echo $EM_Booking->person->user_email ?></td>
<td><?php echo $EM_Booking->person->phone ?></td>
<td><?php echo $EM_Booking->get_spaces() ?></td>
<td>
<?php
$approve_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_approve', 'booking_id'=>$EM_Booking->booking_id));
$delete_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'bookings_delete', 'booking_id'=>$EM_Booking->booking_id));
$edit_url = em_add_get_params($_SERVER['REQUEST_URI'], array('booking_id'=>$EM_Booking->booking_id, 'em_ajax'=>null, 'em_obj'=>null));
?>
<a class="em-bookings-approve" href="<?php echo $approve_url ?>"><?php _e('Approve','events-manager'); ?></a> |
<a class="em-bookings-edit" href="<?php echo $edit_url ?>"><?php _e('Edit/View','events-manager'); ?></a> |
<span class="trash"><a class="em-bookings-delete" href="<?php echo $delete_url ?>"><?php _e('Delete','events-manager'); ?></a></span>
</td>
</tr>
<?php
}
$event_count++;
}
?>
</tbody>
</table>
</div>
<?php else: ?>
<?php _e('No rejected bookings.', 'events-manager'); ?>
<?php endif; ?>
</form>
<?php if( !empty($bookings_nav) && $EM_Bookings >= $limit ) : ?>
<div class='tablenav'>
<?php echo $bookings_nav; ?>
<div class="clear"></div>
</div>
<?php endif; ?>
</div>
<?php
}
?>
\ No newline at end of file
<?php
/**
* Display function for the support page. here we can give links to forums and special upgrade instructions e.g. migration features
*/
function em_admin_help_page(){
global $wpdb;
?>
<div class="wrap">
<h1><?php _e('Getting Help for Events Manager','events-manager'); ?></h1>
<div class="em-docs">
<h2>Where To Get Help</h2>
<p>
This page is only a small portion of the event documentation which is here for quick reference. If you're just starting out, we recommend you visit the following places for further support:
</p>
<ol>
<li>New users are strongly encouraged to have a look at our <a href="http://wp-events-plugin.com/documentation/getting-started-guide/">getting started guide</a>.</li>
<li>Browse the other documentation pages and <a href="http://wp-events-plugin.com/tutorials/">tutorials</a>.</li>
<li>View the <a href="http://wp-events-plugin.com/documentation/faq/">FAQ</a> for general questions and <a href="http://wp-events-plugin.com/documentation/troubleshooting/">Troubleshooting</a> for common issues. These are regularly updated with recent issues.</li>
<li>Rather than trying to contact us directly, we request you use the <a href="http://wordpress.org/tags/events-manager?forum_id=10">support forums</a> as others may be experiencing the same issues as you. For faster support via private member forums and extra features please consider <a href="http://wp-events-plugin.com/events-manager-pro/">upgrading to pro</a>.</li>
</ol>
<p>
If you can't find what you're looking for in the documentation, you may find help on our <a href="http://wp-events-plugin.com/forums/">support forums</a>.
</p>
<h2><?php _e('Placeholders for customizing event pages','events-manager'); ?></h2>
<p><?php echo sprintf( __("In the <a href='%s'>settings page</a>, you'll find various textboxes where you can edit how event information looks, such as for event and location lists. Using the placeholders below, you can choose what information should be displayed.",'events-manager'), EM_ADMIN_URL .'&amp;events-manager-options'); ?></p>
<a name="event-placeholders"></a>
<h3 style="margin-top:20px;"><?php _e('Event Related Placeholders','events-manager'); ?></h3>
<?php echo em_docs_placeholders( array('type'=>'events') ); ?>
<h3 style="margin-top:20px;"><?php _e('Event Location Placeholders','events-manager'); ?></h3>
<?php echo em_docs_placeholders( array('type'=>'event-locations') ); ?>
<a name="category-placeholders"></a>
<h3><?php _e('Category Related Placeholders','events-manager'); ?></h3>
<?php echo em_docs_placeholders( array('type'=>'categories') ); ?>
<h3><?php _e('Tag Related Placeholders','events-manager'); ?></h3>
<?php echo em_docs_placeholders( array('type'=>'tags') ); ?>
<a name="location-placeholders"></a>
<h3><?php _e('Location Related Placeholders','events-manager'); ?></h3>
<?php echo em_docs_placeholders( array('type'=>'locations') ); ?>
<a name="booking-placeholders"></a>
<h3><?php _e('Booking Related Placeholders','events-manager'); ?></h3>
<?php echo em_docs_placeholders( array('type'=>'bookings') ); ?>
</div>
<?php
//Is this a previously imported installation?
$old_table_name = $wpdb->prefix.'dbem_events';
if( $wpdb->get_var("SHOW TABLES LIKE '$old_table_name'") == $old_table_name ){
?>
<hr style="margin:30px 10px;" />
<div class="updated">
<h3>Troubleshooting upgrades from version 2.x to 3.x</h3>
<p>We notice that you upgraded from version 2, as we are now using new database tables, and we do not delete the old tables in case something went wrong with this upgrade.</p>
<p>If something went wrong with the update to version 3 read on:</p>
<h4>Scenario 1: the plugin is working, but for some reason the old events weren't imported</h4>
<p>You can safely reimport your old events from the previous tables without any risk of deleting them. However, if you click the link below <b>YOU WILL OVERWRITE ANY NEW EVENTS YOU CREATED IN VERSION 3</b></p>
<p><a onclick="return confirm('Are you sure you want to do this? Any new changes made since updating will be overwritten by your old ones, and this cannot be undone');" href="<?php echo wp_nonce_url( EM_ADMIN_URL .'&amp;events-manager-help&em_reimport=1', 'em_reimport' ) ?>">Reimport Events from version 2</a></p>
<h4>Scenario 2: the plugin is not working, I want to go back to version 2!</h4>
<p>You can safely downgrade and will not lose any information.</p>
<ol>
<li>First of all, <a href='http://downloads.wordpress.org/plugin/events-manager.2.2.2.zip'>dowload a copy of version 2.2</a></li>
<li>Deactivate and delete Events Manager in the plugin page</li>
<li><a href="<?php bloginfo('wpurl'); ?>/wp-admin/plugin-install.php?tab=upload">Upload the zip file you just downloaded here</a></li>
<li>Let the developers know, of any bugs you ran into while upgrading. We'll help you out if there is a simple solution, and will fix reported bugs within days, if not quicker!</li>
</ol>
</div>
<?php
}
?>
</div>
<?php
}
?>
\ No newline at end of file
<?php
/**
* Looks at the request values, saves/updates and then displays the right menu in the admin
* @return null
*/
function em_admin_ms_locations() {
//TODO EM_Location is globalized, use it fully here
global $EM_Location;
//Take actions
if( !empty($_REQUEST['action']) && ($_REQUEST['action'] == "edit" || $_REQUEST['action'] == "location_save")) {
em_admin_location();
} else {
// no action, just a locations list
em_admin_locations();
}
}
function em_admin_locations($message='', $fill_fields = false) {
global $current_site;
?>
<div class='wrap'>
<div id='icon-edit' class='icon32'>
<br/>
</div>
<h2>
<?php _e('Locations', 'events-manager'); ?>
</h2>
<?php em_locations_admin(array('url' => $_SERVER['REQUEST_URI'])); ?>
</div>
<?php
}
function em_admin_location($message = "") {
global $EM_Location;
if( empty($EM_Location) || !is_object($EM_Location) ){
$title = __('Add location', 'events-manager');
$EM_Location = new EM_Location();
}else{
$title = __('Edit location', 'events-manager');
}
?>
<div class='wrap'>
<div id='icon-edit' class='icon32'>
<br/>
</div>
<h2><?php echo $title ?></h2>
<?php em_location_form(); ?>
</div>
<?php
}
?>
\ No newline at end of file
<?php
//This file will handle upgradeing from EM < 5.9 for timezones, removing the unecessary postmeta fields.
function em_admin_update_timezone_backcompat_site( $site_id = false ){
global $wpdb;
if( is_multisite() && $site_id != false ){ switch_to_blog($site_id); }
$sql = $wpdb->prepare('DELETE FROM '.$wpdb->postmeta.' WHERE meta_key=%s OR meta_key=%s', array('_start_ts', '_end_ts'));
$result = $wpdb->query($sql);
if( $result !== false && !is_multisite() ){
EM_Options::remove('updates', 'timezone-backcompat');
EM_Admin_Notices::remove('date_time_migration');
}
if( is_multisite() && $site_id != false ){ restore_current_blog(); }
return $result !== false;
}
function em_admin_update_timezone_backcompat(){
if( !empty($_REQUEST['confirmed']) && check_admin_referer('em_timezone_backcompat_confirmed') && em_wp_is_super_admin() ){
global $wpdb, $EM_Notices;
if( em_admin_update_timezone_backcompat_site() ){
$EM_Notices->add_confirm(__('You have successfully finalized upgrading your site.', 'events-manager'), true);
$redirect = esc_url_raw( remove_query_arg(array('action','update','confirmed','_wpnonce')) );
wp_safe_redirect($redirect);
exit();
}else{
$EM_Notices->add_error(__('There was an error upgrading your site, please try again or contact support.', 'events-manager'), true);
$redirect = esc_url_raw( remove_query_arg(array('confirmed','_wpnonce')) );
wp_safe_redirect($redirect);
exit();
}
}
}
add_action('em_admin_update_timezone-backcompat', 'em_admin_update_timezone_backcompat');
function em_admin_update_settings_timezone_backcompat(){
if( is_multisite() ) return;
?>
<div>
<h4 style="color:#ca4a1f;"><?php esc_html_e ( 'Finalize Timezones Upgrade', 'events-manager'); ?></h4>
<p><?php esc_html_e('Events Manager 5.9 introduced timezone functionality, which does not require certain fields in your database. To maintain backwards compatibility with earlier versions, these fields will still be created.','events-manager'); ?></p>
<p><?php esc_html_e('This is not a required step to enable any extra functionality, and therefore is not urgent. Only until you are happy with the upgrade and are confident you don\'t need to downgrade, finalize your upgrade by deleting and discontinuing these fields.','events-manager'); ?></p>
<p><a href="<?php echo esc_url(EM_ADMIN_URL.'&page=events-manager-options&amp;action=update&update_action=timezone-backcompat'); ?>" class="button-secondary"><?php esc_html_e ( 'Finalize Timezones Upgrade', 'events-manager'); ?></a>
</div>
<?php
}
add_action('em_admin_update_settings_timezone-backcompat', 'em_admin_update_settings_timezone_backcompat');
function em_admin_update_settings_confirm_timezone_backcompat(){
?>
<div class="wrap">
<h1><?php esc_html_e ( 'Finalize Timezones Upgrade', 'events-manager'); ?></h1>
<p><?php esc_html_e('Events Manager 5.9 introduced timezone functionality, which does not require certain fields in your database. To maintain backwards compatibility with earlier versions, these fields will still be created.','events-manager'); ?></p>
<p><?php esc_html_e('This is not a required step to enable any extra functionality, and therefore is not urgent. Only until you are happy with the upgrade and are confident you don\'t need to downgrade, finalize your upgrade by deleting and discontinuing these fields.','events-manager'); ?></p>
<p style="font-weight:bold;"><?php esc_html_e('We recommend you back up your database! Once the upgrade is finalized, you cannot downgrade to an earlier version of the plugin. This cannot be undone.','events-manager')?></p>
<p>
<a href="<?php echo esc_url(add_query_arg(array('_wpnonce' => wp_create_nonce('em_timezone_backcompat_confirmed'), 'confirmed'=>1))); ?>" class="button-primary"><?php _e('Finalize Timezones Upgrade','events-manager'); ?></a>
<a href="<?php echo esc_url(em_wp_get_referer()); ?>" class="button-secondary"><?php _e('Cancel','events-manager'); ?></a>
</p>
</div>
<?php
}
add_action('em_admin_update_settings_confirm_timezone-backcompat', 'em_admin_update_settings_confirm_timezone_backcompat');
function em_admin_update_ms_settings_timezone_backcompat(){
?>
<div>
<br><hr>
<h2 style="color:#ca4a1f;"><?php esc_html_e( 'Finalize Timezones Upgrade', 'events-manager'); ?></h2>
<p><?php esc_html_e('Events Manager 5.9 introduced timezone functionality, which does not require certain fields in your database. To maintain backwards compatibility with earlier versions, these fields will still be created.','events-manager'); ?></p>
<p><?php esc_html_e('This is not a required step to enable any extra functionality, and therefore is not urgent. Only until you are happy with the upgrade and are confident you don\'t need to downgrade, finalize your upgrade by deleting and discontinuing these fields.','events-manager'); ?></p>
<p style="font-weight:bold;"><?php esc_html_e('We recommend you back up your database! Once the upgrade is finalized, you cannot downgrade to an earlier version of the plugin. This cannot be undone.','events-manager')?></p>
<p>
<a href="<?php echo esc_url(add_query_arg(array('action'=>'timezone-backcompat', '_wpnonce' => wp_create_nonce('em_ms_finalize_timezone_upgrade')))); ?>" class="button-primary">
<?php esc_html_e ( 'Finalize Timezones Upgrade', 'events-manager'); ?>
</a>
</p>
</div>
<?php
}
add_action('em_admin_update_ms_settings_timezone-backcompat', 'em_admin_update_ms_settings_timezone_backcompat');
function em_admin_update_ms_timezone_backcompat(){
if( check_admin_referer('em_ms_finalize_timezone_upgrade') && em_wp_is_super_admin() ){
global $current_site,$wpdb;
$blog_ids = $wpdb->get_col('SELECT blog_id FROM '.$wpdb->blogs.' WHERE site_id='.$current_site->id);
$result = true;
echo '<h2 style="color:#ca4a1f;">'. esc_html__( 'Finalize Timezones Upgrade', 'events-manager') .'</h2>';
echo '<ul>';
$plugin_basename = plugin_basename(EM_DIR.'/events-manager.php');
$network_active = is_plugin_active_for_network($plugin_basename);
foreach($blog_ids as $blog_id){
if( $network_active || is_plugin_active($plugin_basename.'/events-manager.php') ){
if( em_admin_update_timezone_backcompat_site($blog_id) ){
echo "<li>".sprintf(_x('Updated %s.', 'Multisite Blog Update','events-manager'), get_blog_option($blog_id, 'blogname'))."</li>";
}else{
echo "<li>".sprintf(_x('Failed to update %s.', 'Multisite Blog Update','events-manager'), get_blog_option($blog_id, 'blogname'))."</li>";
$result = false;
}
}else{
echo "<li>".sprintf(_x('%s does not have Events Manager activated.', 'Multisite Blog Update','events-manager'), get_blog_option($blog_id, 'blogname'))."</li>";
}
}
echo '</ul>';
if( $result ){
EM_Admin_Notices::remove('date_time_migration', true);
EM_Options::site_remove('updates', 'timezone-backcompat');
echo "<p>".esc_html__('Update process has finished.', 'events-manager')."</p>";
}else{
echo "<p>".esc_html__('An error has occurred, not all sites were upgraded successfully.', 'events-manager')."</p>";
}
}
}
add_action('em_admin_update_ms_timezone-backcompat', 'em_admin_update_ms_timezone_backcompat');
\ No newline at end of file
<?php
/**
* Adds a note to the event post type in the admin area, so it's obvious EM is interfering.
*/
function wpfc_admin_options_post_type_event(){
echo " - <i>powered by Events Manager</i>";
}
add_action('wpfc_admin_options_post_type_event','wpfc_admin_options_post_type_event');
function wpfc_em_admin_notice(){
if( !empty($_REQUEST['page']) && $_REQUEST['page'] == 'wp-fullcalendar'){
?>
<div class="updated"><p><?php echo sprintf(__('If you choose the Event post type whilst Events Manager is activated, you can also visit the <a href="%s">Events Manager settings page</a> for a few more options when displaying event information on your calendar.','events-manager'), admin_url('edit.php?post_type='.EM_POST_TYPE_EVENT.'&page=events-manager-options')); ?></p></div>
<?php
}
}
add_action('admin_notices', 'wpfc_em_admin_notice');
function wpfc_em_admin_options(){
?>
<div class="postbox " >
<div class="handlediv" title="<?php __('Click to toggle', 'events-manager'); ?>"><br /></div><h3 class='hndle'><span><?php _e ( 'Full Calendar Options', 'events-manager'); ?> </span></h3>
<div class="inside">
<p class="em-boxheader"><?php echo sprintf(__('Looking for the rest of the FullCalendar Options? They\'ve moved <a href="%s">here</a>, the options below are for overriding specific bits relevant to Events Manager.','events-manager'), admin_url('options-general.php?page=wp-fullcalendar')); ?></p>
<table class='form-table'>
<?php
global $events_placeholder_tip, $save_button;
em_options_radio_binary ( __( 'Override calendar on events page?', 'events-manager'), 'dbem_emfc_override_calendar', __( 'If set to yes, the FullCalendar will be used instead of the standard calendar on the events page.', 'events-manager') );
em_options_radio_binary ( __( 'Override calendar shortcode?', 'events-manager'), 'dbem_emfc_override_shortcode', __( 'Overrides the default calendar shortcode. You can also use [events_fullcalendar] instead.','events-manager') );
em_options_input_text ( __( 'Event title format', 'events-manager'), 'dbem_emfc_full_calendar_event_format', __('HTML is not accepted.','events-manager').' '.$events_placeholder_tip, '#_EVENTNAME' );
em_options_textarea( __( 'Event tooltips format', 'events-manager'), 'dbem_emfc_qtips_format', __('If you enable tips, this information will be shown, which can include HTML.','events-manager').' '.$events_placeholder_tip, '#_EVENTNAME' );$positions_options = array();
?>
</table>
<?php echo $save_button; ?>
</div> <!-- . inside -->
</div> <!-- .postbox -->
<?php
}
add_action('em_options_page_footer', 'wpfc_em_admin_options');
function wpfc_em_install(){
//check for updates - try adding one option, if it works then it's a first time install so add more
if( current_user_can('manage_options') && get_option('dbem_emfc_full_calendar_event_format', false) ){
add_option('dbem_emfc_full_calendar_event_format','#_EVENTTIMES - #_EVENTNAME');
add_option('dbem_emfc_qtips_format', '{has_image}<div style="float:left; margin:5px 10px 5px 0px;">#_EVENTIMAGE{75,75}</div>{/has_image}#_EVENTEXCERPT');
}
}
add_action('init', 'wpfc_em_install');
\ No newline at end of file
<?php
// This file handles hooks/filter requiring activity stream publications
/**
* bp_em_record_activity()
*
* If the activity stream component is installed, this function will record activity items for your
* component.
*/
function bp_em_record_activity( $args = '' ) {
if ( !function_exists( 'bp_activity_add' ) )
return false;
$defaults = array(
'id' => false,
'user_id' => '',
'action' => '',
'content' => '',
'primary_link' => '',
'component' => 'events-manager',
'type' => false,
'item_id' => false,
'secondary_item_id' => false,
'recorded_time' => gmdate( "Y-m-d H:i:s" ),
'hide_sitewide' => false
);
$r = wp_parse_args( $args, $defaults );
extract( $r );
return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
}
function em_bp_register_activity_actions() {
if ( !bp_is_active( 'events' ) ) {
return false;
}
$bp = buddypress();
// @todo - Figure out why adding a second bp_activity_set_action creates two 'Bookings' actions in backend and different booking status front-end e.g. when friendships created/accepted do not
bp_activity_set_action(
$bp->events->id,
'new_booking',
__( 'Bookings', 'events-manager'),
'em_bp_events_format_activity_action_bookings',
__( 'Bookings', 'events-manager'),
array( 'activity', 'member' )
);
/*
bp_activity_set_action(
$bp->events->id,
'booking_cancelled',
__( 'Booking Cancelled', 'events-manager'),
'em_bp_events_format_activity_action_bookings',
__( 'Bookings', 'events-manager'),
array( 'activity', 'member' )
);
*/
bp_activity_set_action(
$bp->events->id,
'new_event',
__('New Event','events-manager'),
'em_bp_events_format_activity_action_events',
__( 'Events', 'events-manager'),
array( 'activity', 'member' )
);
}
add_action( 'bp_register_activity_actions', 'em_bp_register_activity_actions' );
/**
* Not yet used fully - formats booking-related actions
* @param string $action
* @param object $activity
* @return string
*/
function em_bp_events_format_activity_action_bookings( $action, $activity ) {
return '';
$member_link = bp_core_get_userlink( $activity->user_id );
$EM_Booking = em_get_booking( $activity->item );
$action = '';
switch ($activity->type){
case 'new_booking':
if( $activity->component == 'groups' ){
$action = sprintf(__('%s is attending %s of the group %s.','events-manager'), $member_link, $event_link, $group_link );
}else{
$action = sprintf(__('%s is attending %s.','events-manager'), $member_link, $event_link );
}
break;
case 'cancelled_booking':
if( $activity->component == 'groups' ){
$action = sprintf(__('%s will not be attending %s of group %s anymore.','events-manager'), $user_link, $event_link, $group_link );
}else{
$action = sprintf(__('%s will not be attending %s anymore.','events-manager'), $user_link, $event_link );
}
break;
}
return apply_filters( 'bp_events_format_activity_action_bookings', $action, $activity );
}
/**
* Not yet used fully - formats event-related actions
* @param string $action
* @param object $activity
* @return string
*/
function em_bp_events_format_activity_action_events( $action, $activity ) {
return '';
$member_link = bp_core_get_userlink( $activity->user_id );
$EM_Event = em_get_event( $activity->item_id );
$action = sprintf(__('%s added the event %s','events-manager'), $member_link, $EM_Event->output('#_EVENTLINK') );
return apply_filters( 'bp_events_format_activity_action_events', $action, $activity );
}
/**
* Records new events to the activity stream.
* @param unknown_type $result
* @param unknown_type $EM_Event
* @return unknown
*/
function bp_em_record_activity_event_save( $result, $EM_Event ){
if( $result && $EM_Event->event_status == 1 && $EM_Event->get_previous_status() != 1 ){
$user = get_userdata($EM_Event->event_owner);
$member_link = bp_core_get_user_domain($user->ID);
if( empty($EM_Event->group_id) ){
bp_em_record_activity( array(
'user_id' => $user->ID,
'action' => sprintf(__('%s added the event %s','events-manager'), "<a href='".$member_link."'>".$user->display_name."</a>", $EM_Event->output('#_EVENTLINK') ),
'primary_link' => $EM_Event->output('#_EVENTURL'),
'type' => 'new_event',
'item_id' => $EM_Event->event_id,
'hide_sitewide' => $EM_Event->event_private
));
}else{
//tis a group event
$group = new BP_Groups_Group($EM_Event->group_id);
bp_em_record_activity( array(
'user_id' => $user->ID,
'action' => sprintf(__('%s added the event %s to %s.','events-manager'), "<a href='".$member_link."'>".$user->display_name."</a>", $EM_Event->output('#_EVENTLINK'), '<a href="'.bp_get_group_permalink($group).'">'.bp_get_group_name($group).'</a>' ),
'component' => 'groups',
'type' => 'new_event',
'item_id' => $EM_Event->group_id,
'hide_sitewide' => $EM_Event->event_private
));
}
}
return $result;
}
add_filter('em_event_save','bp_em_record_activity_event_save', 10, 2);
/**
* @param boolean $result
* @param EM_Booking $EM_Booking
* @return boolean
*/
function bp_em_record_activity_booking_save( $result, $EM_Booking ){
/* @todo this isn't good at detecting status changes. */
if( !empty($EM_Booking->event_id) && $result ){
$action_type = 'new_booking';
if( !empty($EM_Booking->last_bp_activity) && $EM_Booking->last_bp_activity == $action_type ) return $result; //prevent duplicates
$EM_Booking->last_bp_activity = $action_type;
$rejected_statuses = array(0,2,3); //these statuses apply to rejected/cancelled bookings
$user = $EM_Booking->get_person();
$member_link = bp_core_get_user_domain($user->ID);
$user_link = "<a href='".$member_link."/'>".$user->display_name."</a>";
$event_link = $EM_Booking->get_event()->output('#_EVENTLINK');
$status = $EM_Booking->booking_status;
$EM_Event = $EM_Booking->get_event();
if( empty($EM_Event->group_id) ){
if( $status == 1 || (!get_option('dbem_bookings_approval') && $status < 2) ){
$action = sprintf(__('%s is attending %s.','events-manager'), $user_link, $event_link );
}elseif( ($EM_Booking->previous_status == 1 || (!get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2)) && in_array($status, $rejected_statuses) ){
$action = sprintf(__('%s will not be attending %s anymore.','events-manager'), $user_link, $event_link );
//$action_type = 'cancelled_booking';
}
}else{
$group = new BP_Groups_Group($EM_Event->group_id);
$group_link = '<a href="'.bp_get_group_permalink($group).'">'.bp_get_group_name($group).'</a>';
if( $status == 1 || (!get_option('dbem_bookings_approval') && $status < 2) ){
$action = sprintf(__('%s is attending %s of the group %s.','events-manager'), $user_link, $event_link, $group_link );
}elseif( ($EM_Booking->previous_status == 1 || (!get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2)) && in_array($status, $rejected_statuses) ){
$action = sprintf(__('%s will not be attending %s of group %s anymore.','events-manager'), $user_link, $event_link, $group_link );
//$action_type = 'cancelled_booking';
}
}
if( !empty($action) ){
if( empty($EM_Event->group_id) ){
bp_em_record_activity( array(
'user_id' => $EM_Booking->person->ID,
'action' => $action,
'primary_link' => $EM_Event->output('#_EVENTURL'),
'type' => $action_type,
'item_id' => $EM_Event->event_id,
'secondary_item_id' => $EM_Booking->booking_id,
'hide_sitewide' => $EM_Event->event_private
));
}else{
//tis a group event
bp_em_record_activity( array(
'component' => 'groups',
'user_id' => $EM_Booking->person->ID,
'action' => $action,
'primary_link' => $EM_Event->output('#_EVENTURL'),
'type' => $action_type,
'item_id' => $EM_Event->group_id,
'secondary_item_id' => $EM_Booking->booking_id,
'hide_sitewide' => $EM_Event->event_private
));
}
}
}
return $result;
}
add_filter('em_booking_set_status','bp_em_record_activity_booking_save', 100, 2);
add_filter('em_booking_save','bp_em_record_activity_booking_save', 100, 2);
add_filter('em_booking_delete','bp_em_record_activity_booking_save', 100, 2);
\ No newline at end of file
<?php
/**
* Turns an event private if the event belongs to a private BP Group
* @param EM_Event $EM_Event
*/
function bp_em_group_event_save($result, $EM_Event){
if( is_object($EM_Event) && !empty($EM_Event->event_id) ){
if( !empty($_REQUEST['group_id']) && is_numeric($_REQUEST['group_id']) && bp_is_active('groups') ){
//firstly, we check that the event has been published, otherwise users without publish rights can submit an event at a private group and event is marked private/published immediately
if( $EM_Event->event_status == 1 ){
//we have been requested an event creation tied to a group, so does this group exist, and does this person have admin rights to it?
if( groups_is_user_admin(get_current_user_id(), absint($_REQUEST['group_id']) ) ){
$EM_Event->group_id = absint($_REQUEST['group_id']);
}
if( !empty($EM_Event->group_id) ){
//if group is private, make it private
$group = groups_get_group(array('group_id'=>$EM_Event->group_id));
$is_member = groups_is_user_member(get_current_user_id(), $EM_Event->group_id) || groups_is_user_admin(get_current_user_id(), $EM_Event->group_id) || groups_is_user_mod(get_current_user_id(), $EM_Event->group_id);
if( $group->status != 'public' && $is_member ){
//Make sure event status is private and set post status to private
global $wpdb;
$EM_Event->event_private = 1;
$wpdb->update($wpdb->posts, array('post_status'=>'private'), array('ID'=>$EM_Event->post_id));
$wpdb->update(EM_EVENTS_TABLE, array('event_private'=>1), array('event_id'=>$EM_Event->event_id));
}
}
}
}else{
$EM_Event->group_id = null;
}
}
return $result;
}
add_action('em_event_save','bp_em_group_event_save',1,2);
/**
* Overrides the default capability of the user for another owner's event if the user is a group admin and the event belongs to a group.
* User must have the relevant permissions globally in order to inherit that capability for this event as well.
* @param boolean $result
* @param EM_Event $EM_Event
*/
function bp_em_group_event_can_manage( $result, $EM_Event, $owner_capability, $admin_capability, $user_to_check){
if( !$result && $EM_Event->event_owner != get_current_user_id() && !empty($EM_Event->group_id) && bp_is_active('groups') ){ //only override if already false, incase it's true
//if the user is an admin of this group, and actually has the relevant permissions globally, they can manage this event
$EM_Object = new EM_Object(); //create new object to prevent infinite loop should we call $EM_Event->can_manage();
if( groups_is_user_admin(get_current_user_id(),$EM_Event->group_id) && $EM_Object->can_manage($owner_capability, $admin_capability, $user_to_check) ){
//This user is an admin of the owner's group, so they can edit this event.
array_pop($EM_Event->errors); //remove last error
return true;
}else{
$EM_Event->add_error($EM_Object->get_errors()); //add any applicable errors
}
}
return $result;
}
add_filter('em_event_can_manage','bp_em_group_event_can_manage',1,5);
function bp_em_group_events_accepted_searches($searches){
if( bp_is_active('groups') ){
$searches[] = 'group';
}
return $searches;
}
add_filter('em_accepted_searches','bp_em_group_events_accepted_searches',1,1);
function bp_em_group_events_get_default_search($searches, $array){
if( !empty($array['group']) && (is_numeric($array['group']) || $array['group'] == 'my' || $array['group'] == 'this') && bp_is_active('groups') ){
if($array['group'] == 'this'){ //shows current group, if applicable
if( is_numeric(bp_get_current_group_id()) ){
$searches['group'] = bp_get_current_group_id();
}
}else{
$searches['group'] = $array['group'];
}
}
return $searches;
}
add_filter('em_events_get_default_search','bp_em_group_events_get_default_search',1,2);
/*
* Privacy Functions
*/
function bp_em_group_events_build_sql_conditions( $conditions, $args ){
if( !empty($args['group']) && is_numeric($args['group']) ){
$conditions['group'] = "( `group_id`={$args['group']} )";
}elseif( !empty($args['group']) && $args['group'] == 'my' ){
$groups = groups_get_user_groups(get_current_user_id());
if( count($groups) > 0 ){
$conditions['group'] = "( `group_id` IN (".implode(',',$groups['groups']).") )";
}
}
//deal with private groups and events
if( is_user_logged_in() ){
global $wpdb;
//find out what private groups they belong to, and don't show private group events not in their memberships
$group_ids = BP_Groups_Member::get_group_ids(get_current_user_id());
if( $group_ids['total'] > 0){
$conditions['group_privacy'] = "(`event_private`=0 OR (`event_private`=1 AND (`group_id` IS NULL OR `group_id` = 0)) OR (`event_private`=1 AND `group_id` IN (".implode(',',$group_ids['groups']).")))";
}else{
//find out what private groups they belong to, and don't show private group events not in their memberships
$conditions['group_privacy'] = "(`event_private`=0 OR (`event_private`=1 AND (`group_id` IS NULL OR `group_id` = 0)))";
}
}
return $conditions;
}
add_filter('em_events_build_sql_conditions','bp_em_group_events_build_sql_conditions',1,2);
/**
* Checks if the event is private and either belongs to a group or private group, as members of that group should be able to see the post even if not able to see private events.
* @param string $template
* @return string
*/
function bp_em_private_event_check($template){
global $post, $wpdb, $wp_query, $bp;
if( $post->post_type == EM_POST_TYPE_EVENT ){
$EM_Event = em_get_event($post);
//echo "<pre>"; print_r($EM_Event); echo "</pre>"; die();
if( !empty($EM_Event->event_private) && !empty($EM_Event->group_id) ){
if( is_user_logged_in() ){
//make sure user is a member of this group, whether private or not, private groups just aren't shown to non-members of a group
$id_lookup = $wpdb->get_var( $wpdb->prepare( "SELECT m.group_id FROM {$bp->groups->table_name_members} m WHERE m.group_id = %s AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $EM_Event->group_id, get_current_user_id() ) );
if($id_lookup != $EM_Event->group_id){
unset($post);
$wp_query->set_404();
$template = locate_template(array('404.php'),false);
}
}else{
unset($post);
$wp_query->set_404();
$template = locate_template(array('404.php'),false);
}
}
}
return $template;
}
add_filter('single_template','bp_em_private_event_check',20);
/*
* Admin Meta Boxes
*/
function bp_em_meta_boxes(){
add_meta_box('em-event-group', __('Group Ownership','events-manager'), 'bp_em_meta_box_group',EM_POST_TYPE_EVENT, 'side','low');
add_meta_box('em-event-group', __('Group Ownership','events-manager'), 'bp_em_meta_box_group','event-recurring', 'side','low');
}
add_action('add_meta_boxes', 'bp_em_meta_boxes');
function bp_em_meta_box_group(){
em_locate_template('forms/event/group.php',true);
}
\ No newline at end of file
<?php
//This file handles hooks requiring notifications
/**
* bp_em_format_notifications()
*
* The format notification function will take DB entries for notifications and format them
* so that they can be displayed and read on the screen.
*
* Notifications are "screen" notifications, that is, they appear on the notifications menu
* in the site wide navigation bar. They are not for email notifications.
*
*
* The recording is done by using bp_core_add_notification() which you can search for in this file for
* ems of usage.
*/
function bp_em_format_notifications( $action, $item_id, $secondary_item_id, $total_items ) {
global $bp;
switch ( $action ) {
case 'pending_booking':
//Count pending bookings
if( get_option('dbem_bookings_approval')){
if ( $total_items > 1 ) {
return '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/" title="' . __( 'My Bookings', 'events-manager') . '">' . __('You have a pending booking','events-manager'). '</a>';
} else {
return apply_filters( 'bp_em_format_new_booking_notification', '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/" title="' . __( 'My Bookings', 'events-manager') . '">' . sprintf(__('You have %s pending bookings','events-manager'), $total_items). '</a>' );
}
}
break;
case 'confirmed_booking':
//Count pending bookings
if ( $total_items > 1 ) {
return apply_filters( 'bp_em_format_confirmed_booking_notifications', '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/" title="' . __( 'My Bookings', 'events-manager') . '">' . __('You have a confirmed booking','events-manager'). '</a>' );
} else {
return apply_filters( 'bp_em_format_confirmed_booking_notification', '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/" title="' . __( 'My Bookings', 'events-manager') . '">' . sprintf(__('You have %s confirmed bookings','events-manager'), $total_items). '</a>' );
}
break;
case 'cancelled_booking':
//Count pending bookings
if ( $total_items > 1 ) {
return apply_filters( 'bp_em_format_cancelled_booking_notifications', '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/" title="' . __( 'My Bookings', 'events-manager') . '">' . __('A user cancelled a booking','events-manager'). '</a>' );
} else {
return apply_filters( 'bp_em_format_cancelled_booking_notification', '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/" title="' . __( 'My Bookings', 'events-manager') . '">' . sprintf(__('%s users cancelled bookings.','events-manager'), $total_items). '</a>' );
}
break;
}
do_action( 'bp_em_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
return false;
}
/**
* Remove a screen notification for a user.
*/
function bp_em_remove_screen_notifications() {
global $bp;
if( function_exists('bp_notifications_delete_notifications_by_type') ){
bp_notifications_delete_notifications_by_type( $bp->loggedin_user->id, $bp->events->slug, 'attending' );
}
}
add_action( 'bp_em_my_events', 'bp_em_remove_screen_notifications' );
add_action( 'xprofile_screen_display_profile', 'bp_em_remove_screen_notifications' );
/**
* Catch booking saves and add a BP notification.
* @param boolean $result
* @param EM_Booking $EM_Booking
* @return boolean
*/
function bp_em_add_booking_notification($result, $EM_Booking){
global $bp;
if( !function_exists('bp_notifications_add_notification') ) return $result; //no need if notifications are disabled
if( get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0 ){
$action = 'pending_booking';
}elseif( $EM_Booking->get_status() == 1 || (get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0) ){
$action = 'confirmed_booking';
}elseif( $EM_Booking->get_status() == 3 ){
$action = 'cancelled_booking';
}
if( !empty($action) && !$EM_Booking->is_no_user() ){
bp_notifications_add_notification( array(
'item_id' => $EM_Booking->booking_id,
'secondary_item_id' => $EM_Booking->event_id,
'user_id' => $EM_Booking->get_event()->get_contact()->ID,
'component_name' => 'events',
'component_action' => $action
));
}
return $result;
}
add_filter('em_booking_save','bp_em_add_booking_notification',1,2);
\ No newline at end of file
<?php
/**
* Echo the Events Manager BuddyPresss component's slug
* @since 5.0
*/
function em_bp_slug() {
echo em_bp_get_slug();
}
/**
* Return the Events Manager BuddyPresss component's slug
*
* @since 5.0
* @uses apply_filters() Filter 'em_bp_get_slug' to change the output
* @return str $slug The slug from $bp->events->slug, if it exists
*/
function em_bp_get_slug() {
global $bp;
// Avoid PHP warnings, in case the value is not set for some reason
$slug = !empty( $bp->events->slug ) ? $bp->events->slug : BP_EM_SLUG;
return apply_filters( 'em_bp_get_slug', $slug );
}
\ No newline at end of file
<?php
/**
* bp_em_screen_two()
*
* Sets up and displays the screen output for the sub nav item "em/screen-two"
*/
function bp_em_attending() {
global $bp;
/**
* If the user has not Accepted or Rejected anything, then the code above will not run,
* we can continue and load the template.
*/
do_action( 'bp_em_attending' );
add_action( 'bp_template_title', 'bp_em_attending_title' );
add_action( 'bp_template_content', 'bp_em_attending_content' );
/* Finally load the plugin template file. */
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
function bp_em_attending_title() {
_e( 'Events I\'m Attending', 'events-manager');
}
function bp_em_attending_content() {
//We can use the same template as the public user interface for non bp sites
em_my_bookings();
}
\ No newline at end of file
<?php
/**
* Controller for the event views in BP (using mvc terms here)
*/
function bp_em_group_events() {
global $bp;
do_action( 'bp_em_group_events' );
//plug into EM admin code (at least for now)
include_once(EM_DIR.'/admin/em-admin.php');
add_action( 'bp_template_title', 'bp_em_group_events_title' );
add_action( 'bp_template_content', 'bp_em_group_events_content' );
/* Finally load the plugin template file. */
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'groups/single/plugins' ) );
}
function bp_em_group_events_title() {
_e( 'Group Events', 'events-manager');
}
/**
* Determines whether to show event page or events page, and saves any updates to the event or events
* @return null
*/
function bp_em_group_events_content() {
em_locate_template('buddypress/group-events.php', true);
}
?>
\ No newline at end of file
<?php
/**
* bp_em_screen_two()
*
* Sets up and displays the screen output for the sub nav item "em/screen-two"
*/
function bp_em_my_bookings() {
global $bp, $EM_Event;
//assume any notifications here are considered viewed via this page
if( function_exists('bp_notifications_delete_notifications_by_type') ){
bp_notifications_delete_notifications_by_type(get_current_user_id(), 'events','pending_booking');
bp_notifications_delete_notifications_by_type(get_current_user_id(), 'events','confirmed_booking');
bp_notifications_delete_notifications_by_type(get_current_user_id(), 'events','cancelled_booking');
}
em_load_event();
/**
* If the user has not Accepted or Rejected anything, then the code above will not run,
* we can continue and load the template.
*/
do_action( 'bp_em_my_bookings' );
add_action( 'bp_template_title', 'bp_em_my_bookings_title' );
add_action( 'bp_template_content', 'bp_em_my_bookings_content' );
/* Finally load the plugin template file. */
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
function bp_em_my_bookings_title() {
_e( 'My Event Bookings', 'events-manager');
}
function bp_em_my_bookings_content() {
em_locate_template('buddypress/my-bookings.php',true);
}
\ No newline at end of file
<?php
/**
* Controller for the event views in BP (using mvc terms here)
*/
function bp_em_my_events() {
global $bp, $EM_Event;
if( !is_object($EM_Event) && !empty($_REQUEST['event_id']) ){
$EM_Event = new EM_Event( absint($_REQUEST['event_id']) );
}
do_action( 'bp_em_my_events' );
$template_title = 'bp_em_my_events_title';
$template_content = 'bp_em_my_events_content';
if( !empty($_GET['action']) ){
switch($_GET['action']){
case 'edit':
$template_title = 'bp_em_my_events_editor_title';
break;
}
}
add_action( 'bp_template_title', $template_title );
add_action( 'bp_template_content', $template_content );
/* Finally load the plugin template file. */
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
function bp_em_my_events_title() {
_e( 'My Events', 'events-manager');
}
/**
* Determines whether to show event page or events page, and saves any updates to the event or events
* @return null
*/
function bp_em_my_events_content() {
em_locate_template('buddypress/my-events.php', true);
}
function bp_em_my_events_editor_title() {
global $EM_Event;
if( is_object($EM_Event) ){
if($EM_Event->is_recurring()){
echo __( "Reschedule Events", 'events-manager')." '{$EM_Event->event_name}'";
}else{
echo __( "Edit Event", 'events-manager') . " '" . $EM_Event->event_name . "'";
}
}else{
_e( 'Add Event', 'events-manager');
}
}
?>
\ No newline at end of file
<?php
/**
* Controller for the event views in BP (using mvc terms here)
*/
function bp_em_my_group_events() {
global $bp;
do_action( 'bp_em_my_group_events' );
//plug into EM admin code (at least for now)
include_once(EM_DIR.'/admin/em-admin.php');
add_action( 'bp_template_title', 'bp_em_my_group_events_title' );
add_action( 'bp_template_content', 'bp_em_my_group_events_content' );
/* Finally load the plugin template file. */
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
function bp_em_my_group_events_title() {
_e( 'Group Events', 'events-manager');
}
function bp_em_my_group_events_content(){
em_locate_template('buddypress/my-group-events.php', true);
}
?>
\ No newline at end of file
<?php
/**
* Controller for the location views in BP (using mvc terms here)
*/
function bp_em_my_locations() {
global $bp, $EM_Location;
if( !is_object($EM_Location) && !empty($_REQUEST['location_id']) ){
$EM_Location = new EM_Location( absint($_REQUEST['location_id']) );
}
do_action( 'bp_em_my_locations' );
$template_title = 'bp_em_my_locations_title';
$template_content = 'bp_em_my_locations_content';
if( !empty($_GET['action']) ){
switch($_GET['action']){
case 'edit':
$template_title = 'bp_em_my_locations_editor_title';
break;
}
}
add_action( 'bp_template_title', $template_title );
add_action( 'bp_template_content', $template_content );
/* Finally load the plugin template file. */
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
function bp_em_my_locations_title() {
_e( 'My Locations', 'events-manager');
}
/**
* Determines whether to show location page or locations page, and saves any updates to the location or locations
* @return null
*/
function bp_em_my_locations_content() {
em_locate_template('buddypress/my-locations.php', true);
}
function bp_em_my_locations_editor_title() {
global $EM_Location;
if( empty($EM_Location) || !is_object($EM_Location) ){
$title = __('Add Location', 'events-manager');
}else{
$title = __('Edit Location', 'events-manager');
}
}
?>
\ No newline at end of file
<?php
/**
* bp_em_screen_one()
*
* Sets up and displays the screen output for the sub nav item "em/screen-one"
*/
function bp_em_events() {
global $bp, $EM_Notices;
if( bp_is_my_profile() ){
$EM_Notices->add_info( __('You are currently viewing your public page, this is what other users will see.', 'events-manager') );
}
/* Add a do action here, so your component can be extended by others. */
do_action( 'bp_em_events' );
add_action( 'bp_template_title', 'bp_em_events_title' );
add_action( 'bp_template_content', 'bp_em_events_content' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
//bp_core_load_template( apply_filters( 'bp_em_template_screen_one', 'em/screen-one' ) );
}
/***
* The second argument of each of the above add_action() calls is a function that will
* display the corresponding information. The functions are presented below:
*/
function bp_em_events_title() {
_e( 'Events', 'events-manager');
}
function bp_em_events_content() {
em_locate_template('buddypress/profile.php',true);
}
\ No newline at end of file
<?php
/**
* A single admin notice which contains information about who to display it to, what to dispaly, when and where to display it.
* @since 5.8.2.0
*/
class EM_Admin_Notice {
/**
* Notice key
* @var string
*/
public $name = '';
/**
* Which user should see this message. Can be 'admin', 'all' (or false), or a specific capability.
* Note that 'admin' in MultiSite context is considered a super admin, use the 'manage_options' cap instead.
* @var string
*/
public $who = 'admin';
/**
* What kind of notices this is, which can be 'success','info','warning' or 'error'
* @var string
*/
public $what = 'info';
/**
* Timestamp indicating when a notice should be shown. If empty, message will show immediately.
* @var int
*/
public $when;
/**
* Where a message should be shown. Values accepted are 'all' (all pages), 'network_admin', 'plugin' (plugin-specific pages), 'settings'
* or any value representing an admin page in the events admin menu, e.g. 'events-manager-bookings' would be the bookings admin page.
*
* @var string
*/
public $where = 'settings';
/**
* The actual message that will be displayed. If left blank, a filter will be applied upon output with format
* em_admin_notice_output_{$this->name}
* @var string
*/
public $message = false; //the message
/**
* Whether a message is dismissable
* @var boolean
*/
public $dismissible = true;
/**
* If a message is dismissable and this is set to true, it will be shown to every user matching the who property until dismissed.
* This is also set to true by default if the user type is not 'admin' and not previously set to true or false by the em_admin_notice_ hook.
* @var boolean
*/
protected $user_notice = null;
/**
* If set to true, this is treated as a network-level notice, meaning it can apply to all sites on the network or the network admin in MultiSite mode.
* @var bool
*/
public $network = false;
public function __construct( $key, $type = false, $message = false, $where = false ){
//process the supplied data
if( empty($message) ){
if( empty($type) && is_array($key) ){
$notice = $key;
}elseif( is_array($type) ){
$this->name = $key;
$notice = $type;
}elseif( is_array($key) ){
$notice = $key;
}else{
//we may even have simply a key/name for this notice, for hooking later on
if( is_string($key) ) $this->name = $key;
$notice = array();
}
}else{
//here we expect a string for eveything
$notice = array('name'=> (string) $key, 'what' => (string) $type, 'message' => (string) $message) ;
}
//we should have an array to process at this point
foreach( $notice as $key => $value ){
$this->$key = $value;
}
//add where if defined
if( !empty($where) ) $this->where = $where;
//call a hook
do_action('em_admin_notice_'.$this->name, $this);
if( !is_multisite() && $this->where == 'network_admin' ) $this->where = 'settings';
}
public function __set( $prop, $val ){
$this->$prop = $val;
}
public function __get( $prop ){
if( $prop == 'user_notice' ){
return $this->is_user_notice();
}
}
/**
* Returns whether or not this object should be dismissed on a per-user basis.
* @return boolean
*/
public function is_user_notice(){
if( $this->who != 'admin' && $this->user_notice === null ){
//user_notice was not specifically set, so if notice is dismissible and not targetted at admins we assume it's dismissed at per-user basis
return $this->dismissible;
}
return $this->user_notice;
}
/**
* Returns notice as an array with non-default values.
* @return array
*/
public function to_array(){
$default = new EM_Admin_Notice('default');
$notice = array();
foreach( get_class_vars('EM_Admin_Notice') as $var => $val ){
if( $this->$var != $default->$var ) $notice[$var] = $this->$var;
}
return $notice;
}
public function can_show(){
//check that we have at least a notice to show
if( empty($this->name) ) return false;
//can we display due to time?
$return = ( empty($this->when) || $this->when <= time() );
//who to display it to
if( $return && !empty($this->who) && $this->who != 'all' ){
$return = false; //unless this test passes, don't show it
if( $this->who == 'all' ) $return = true;
elseif ( $this->who == 'admin' ){
if( $this->network && em_wp_is_super_admin() ) $return = true;
elseif( current_user_can('manage_options') ) $return = true;
}
elseif( $this->who == 'blog_admin' && current_user_can('manage_options') ) $return = true;
elseif( !$return && current_user_can($this->who) ) $return = true;
}
//can we display due to location?
if( $return ){
$return = false; //unless this test passes, don't show it
if( empty($this->where) || $this->where == 'all' ){
$return = true;
}elseif( !empty($_REQUEST['post_type']) && in_array($_REQUEST['post_type'], array(EM_POST_TYPE_EVENT, EM_POST_TYPE_LOCATION, 'event-recurring')) ){
if( $this->where == 'plugin' ) $return = true;
elseif( empty($_REQUEST['page']) && in_array($this->where, array(EM_POST_TYPE_EVENT, EM_POST_TYPE_LOCATION, 'event-recurring')) ) $return = true;
elseif( $this->where == 'settings' && !empty($_REQUEST['page']) && $_REQUEST['page'] == 'events-manager-options' ) $return = true;
elseif( !empty($_REQUEST['page']) && ($this->where == $_REQUEST['page'] || (is_array($this->where) && in_array($_REQUEST['page'], $this->where))) ) $return = true;
}elseif( is_network_admin() && !empty($_REQUEST['page']) && preg_match('/^events\-manager\-/', $_REQUEST['page']) ){
$return = $this->where == 'plugin' || $this->where == 'settings' || $this->where == 'network_admin';
}elseif( !empty($_REQUEST['page']) && ($this->where == $_REQUEST['page'] || (is_array($this->where) && in_array($_REQUEST['page'], $this->where))) ){
$return = true;
}
}
//does this even have a message we can display?
if( $return && empty($this->message)){
$this->message = apply_filters('em_admin_notice_'.$this->name .'_message', false, $this);
$return = !empty($this->message);
}
//is this user-dismissable, and if so, did this user dismiss it?
if( $return && $this->is_user_notice() ){
$user_id = get_current_user_id();
$dismissed_notices = get_user_meta( $user_id, '_em_dismissed_notices', true);
$return = empty($dismissed_notices) || !in_array($this->name, $dismissed_notices);
}
return $return;
}
public function output(){
if( empty($this->message) ) return false;
$action = $this->network ? 'em_dismiss_network_admin_notice':'em_dismiss_admin_notice';
?>
<div class="em-admin-notice notice notice-<?php echo esc_attr($this->what); ?> <?php if($this->dismissible) echo 'is-dismissible'?>" id="notice-<?php echo esc_attr($this->name); ?>" data-dismiss-action="<?php echo $action; ?>" data-dismiss-key="<?php echo esc_attr($this->name); ?>">
<p><?php echo $this->message; ?></p>
</div>
<?php
return true;
}
}
\ No newline at end of file
<?php
/**
* Handles the registration and display of admin notices, including storage and retrieval of individual EM_Admin_Notice notice objects.
* @since 5.8.2.0
*/
class EM_Admin_Notices {
/**
* Flag for whether or not to add dismissable notice JS to admin page footer.
* @var boolean
*/
public static $js_footer = false;
/**
* Initialize EM Admin Notices by adding the relevant hooks.
*/
public static function init(){
add_action('admin_notices', 'EM_Admin_Notices::admin_notices');
add_action('wp_ajax_em_dismiss_admin_notice', 'EM_Admin_Notices::dismiss_admin_notice');
if( is_multisite() ){
add_action('admin_notices', 'EM_Admin_Notices::network_admin_notices');
add_action('network_admin_notices', 'EM_Admin_Notices::network_admin_notices');
add_action('wp_ajax_em_dismiss_network_admin_notice', 'EM_Admin_Notices::dismiss_admin_notice');
}
}
/**
* Adds an admin notice to the site. If $network is set to true, notice will be saved at network level.
* If a string is provided as $EM_Admin_Notice, it will be considered as a notice requiring a hook to ouptut anything.
* If a notice with an identical key is provided, it will overwrite the previously stored notice.
* When adding a notice that all users will see and can dismiss, it's recommended you use a hook to build the EM_Admin_Notice object, to avoid storing unecessary data in the DB
* @param EM_Admin_Notice|string $EM_Admin_Notice
* @param boolean $network
* @return boolean Returns true if added successfully, false if not or if the exact same record exists.
*/
public static function add( $EM_Admin_Notice, $network = false ){
$network = $network && is_multisite(); //make sure we are actually in multisite!
if( is_string($EM_Admin_Notice) ){
$EM_Admin_Notice = new EM_Admin_Notice( $EM_Admin_Notice );
$hook_notice = true;
}
if( !$EM_Admin_Notice->name ) return false;
//get options data
$data = $network ? get_site_option('dbem_data') : get_option('dbem_data');
$data = empty($data) ? array() : maybe_unserialize($data);
if( !is_array($data)) $data = array();
$notices_data = $network ? get_site_option('dbem_admin_notices') : get_option('dbem_admin_notices');
$notices_data = empty($notices_data) ? array() : maybe_unserialize($notices_data);
if( !is_array($notices_data)) $notices_data = array(); //we store the data regarldess of whether a message will require a hook, since it contains location and caps considtions
//start building data
$notices = !empty($data['admin_notices']) ? $data['admin_notices'] : array();
$notices[$EM_Admin_Notice->name] = !empty($EM_Admin_Notice->when) ? $EM_Admin_Notice->when : 0;
if( empty($hook_notice) ){ //we only skip this if simply a key is provided initially in $EM_Admin_Notice
$notices_data[$EM_Admin_Notice->name] = $EM_Admin_Notice->to_array();
}
if( !empty($notices) ){
$data['admin_notices'] = $notices;
$update_notices = $network ? update_site_option('dbem_data', $data) : update_option('dbem_data', $data);
$update_notices_data = true;
if( !empty($notices_data) ){
$update_notices_data = $network ? update_site_option('dbem_admin_notices', $notices_data) : update_option('dbem_admin_notices', $notices_data, false);
}
return $update_notices && $update_notices_data;
}
return false;
}
/**
* Remove an admin notice. If $network is true, then a network-level admin notice will be removed.
* @param string $notice_key
* @param string $network
* @return boolean Returns true if successfully deleted, false if there's an error or if there's nothing to delete.
*/
public static function remove( $notice_key, $network = false ){
$network = $network && is_multisite(); //make sure we are actually in multisite!
$data = $network ? get_site_option('dbem_data') : get_option('dbem_data');
if( !empty($data['admin_notices']) && isset($data['admin_notices'][$notice_key])){
unset($data['admin_notices'][$notice_key]);
if( empty($data['admin_notices']) ) unset($data['admin_notices']);
$result = $update_notices_data = $network ? update_site_option('dbem_data', $data) : update_option('dbem_data', $data);
$notices_data = $network ? get_site_option('dbem_admin_notices') : get_option('dbem_admin_notices');
if( !empty($notices_data[$notice_key]) ){
unset($notices_data[$notice_key]);
if( empty($notices_data) ){
$update_notices_data = $network ? delete_site_option('dbem_admin_notices') : delete_option('dbem_admin_notices');
}else{
$update_notices_data = $network ? update_site_option('dbem_admin_notices', $notices_data) : update_option('dbem_admin_notices', $notices_data, false);
}
}
return $result && $update_notices_data;
}
return false;
}
/**
* Adds admin notice to network rather than specific blog. Equivalent to self::add( $EM_Admin_Notice, true );
* @see EM_Admin_Notices::add()
*/
public static function network_add( $EM_Admin_Notice ){ return self::add( $EM_Admin_Notice, true ); }
/**
* Removes admin notice from network rather than specific blog. Equivalent to self::remove( $EM_Admin_Notice, true );
* @see EM_Admin_Notices::remove()
*/
public static function network_remove( $notice_key ){ return self::remove( $notice_key, true ); }
/**
* Output the admin notices we need to output now. If $network is true, MultiSite network messages will be output.
* @param string $network
*/
public static function admin_notices( $network = false ){
$notices = array();
$data = $network ? get_site_option('dbem_data') : get_option('dbem_data');
$possible_notices = is_array($data) && !empty($data['admin_notices']) ? $data['admin_notices'] : array();
//we may have something to show, so we make sure that there's something to show right now
foreach( $possible_notices as $key => $val ){
//to avoid extra loading etc. we weed out time-based notices that aren't triggered right now
if( empty($val) || ($val > 0 && $val < time()) ){
//we have a match, so we add this to $notices
$notices[$key] = self::get_notice($key, $network);
}
}
self::output( $notices, $network );
}
public static function get_notice( $key, $network = false ){
//build notice object
$notice_data = $network ? get_site_option('dbem_admin_notices') : get_option('dbem_admin_notices');
if( empty($notice_data[$key]) || !is_array($notice_data[$key]) ){
$notice = array('name'=>$key, 'network'=>$network);
}else{
$notice = $notice_data[$key];
$notice['network'] = $network;
}
return new EM_Admin_Notice($notice);
}
/**
* Outputs admin notices at network level, same as EM_Admin_Notices::admin_notices(true)
* @see EM_Admin_Notices::admin_notices()
*/
public static function network_admin_notices(){ self::admin_notices(true); }
/**
* Outputs admin notices and calls the dismissable JS to be output at footer of admin page.
* If $network is true, only MultiSite network-level notices will be shown.
* @param array $notices
* @param boolean $network
*/
public static function output( $notices, $network = false ){
foreach( $notices as $EM_Admin_Notice ){
//output the notice if meant to
if( $EM_Admin_Notice->can_show() ){
if( $EM_Admin_Notice->output() ) self::$js_footer = true;
}
}
if( self::$js_footer ){
add_action('admin_footer', 'EM_Admin_Notices::admin_footer');
}
}
/**
* If called via AJAX, the notice will be removed.
*/
public static function dismiss_admin_notice(){
if( empty($_REQUEST['notice']) ) return;
$key = $_REQUEST['notice'];
$network = $_REQUEST['action'] == 'em_dismiss_network_admin_notice';
//get the notice
$EM_Admin_Notice = self::get_notice($key, $network);
if( $EM_Admin_Notice->is_user_notice() ){
//user-specific notices are flagged on the user-level
$user_id = get_current_user_id();
$dismissed_notices = get_user_meta( $user_id, '_em_dismissed_notices', true);
$dismissed_notices = is_array($dismissed_notices) ? $dismissed_notices : array();
if( !in_array($EM_Admin_Notice->name, $dismissed_notices) ){
$dismissed_notices[] = $EM_Admin_Notice->name;
$result = update_user_meta( $user_id, '_em_dismissed_notices', $dismissed_notices);
}
}else{
$result = self::remove($_REQUEST['notice'], $network);
}
echo !empty($result) ? 'Thou art dismissed!' : 'Thou shall not pass!';
exit();
}
/**
* Outputs JS for dismissing notices.
*/
public static function admin_footer(){
?>
<script type="text/javascript">
jQuery(document).ready( function($){
$('.em-admin-notice').on('click', 'button.notice-dismiss', function(e){
var the_notice = $(this).closest('.em-admin-notice');
$.get('<?php echo admin_url('admin-ajax.php'); ?>', {'action' : the_notice.data('dismiss-action'), 'notice' : the_notice.data('dismiss-key') });
});
});
</script>
<?php
}
}
include('em-admin-notice.php');
EM_Admin_Notices::init();
\ No newline at end of file
<?php
/**
* This class extends the EM_Taxonomy_Admin and adds category images and colors to the admin area.
*
* Currently, all functions here serve the purpose of getting around lack of late static binding in PHP < 5.3.
* Eventually when PHP 5.3 is enforced only certain class properties need to be defined for use in the parent class via static::
*
*/
class EM_Categories_Admin extends EM_Taxonomy_Admin{
public static $taxonomy_name = 'EM_TAXONOMY_CATEGORY'; //converted into a constant value during init()
public static $this_class = 'EM_Categories_Admin'; //needed until 5.3 minimum is enforced for late static binding
public static $tax_class = 'EM_Category';
public static $option_name = 'category';
public static $name_singular = 'category';
public static $name_plural = 'categories';
public static $placeholder_image = '#_CATEGORYIMAGE';
public static $placeholder_color = '#_CATEGORYCOLOR';
public static function init(){
self::$taxonomy_name = EM_TAXONOMY_CATEGORY;
self::static_binding();
parent::init();
}
public static function form_add(){
self::static_binding();
parent::form_add();
}
public static function form_edit($tag){
self::static_binding();
parent::form_edit($tag);
}
public static function save( $term_id, $tt_id ){
self::static_binding();
parent::save( $term_id, $tt_id );
}
public static function delete( $term_id ){
self::static_binding();
parent::delete( $term_id );
}
/**
* Temporary function until WP requires PHP 5.3, so that we can make use of late static binding.
* Until then, all functions needing LST should run this function before calling the parent. If all extending classes do this we shouldn't have a problem.
*/
public static function static_binding(){
EM_Taxonomy_Admin::$taxonomy_name = self::$taxonomy_name;
EM_Taxonomy_Admin::$this_class = self::$this_class;
EM_Taxonomy_Admin::$tax_class = self::$tax_class;
EM_Taxonomy_Admin::$option_name = self::$option_name;
EM_Taxonomy_Admin::$name_singular = self::$name_singular;
EM_Taxonomy_Admin::$name_plural = self::$name_plural;
EM_Taxonomy_Admin::$placeholder_image = self::$placeholder_image;
EM_Taxonomy_Admin::$placeholder_color = self::$placeholder_color;
}
}
add_action('admin_init',array('EM_Categories_Admin','init'));
\ No newline at end of file
<?php
class EM_Categories_Frontend extends EM_Taxonomy_Frontend {
public static $taxonomy_name = 'event-category'; //converted into a constant value during init()
public static $this_class = 'EM_Categories_Frontend'; //needed until 5.3 minimum is enforced for late static binding
public static $tax_class = 'EM_Category';
public static $option_name = 'category';
public static $option_name_plural = 'categories';
public static function init(){
self::$taxonomy_name = EM_TAXONOMY_CATEGORY; //awaiting LST in PHP 5.3
self::static_binding();
parent::init();
}
//These following functions can be removed when PHP 5.3 is minimum and LSB is available
public static function template($template = ''){
self::static_binding();
return parent::template($template);
}
public static function the_content($content){
self::static_binding();
return parent::the_content($content);
}
public static function parse_query( $wp_query ){
//we do some double-checking here to prevent running self::static_binding() during the self::template() function when WP_Query is called.
if( !$wp_query->is_main_query() ) return;
if( $wp_query->is_tax(self::$taxonomy_name) || !empty($wp_query->{'em_'.self::$option_name.'_id'}) ){
self::static_binding();
return parent::parse_query( $wp_query );
}
}
public static function wpseo_breadcrumb_links( $links ){
self::static_binding();
return parent::wpseo_breadcrumb_links( $links );
}
/**
* Temporary function until WP requires PHP 5.3, so that we can make use of late static binding.
* Until then, all functions needing LST should run this function before calling the parent. If all extending classes do this we shouldn't have a problem.
*/
public static function static_binding(){
EM_Taxonomy_Frontend::$taxonomy_name = self::$taxonomy_name;
EM_Taxonomy_Frontend::$this_class = self::$this_class;
EM_Taxonomy_Frontend::$tax_class = self::$tax_class;
EM_Taxonomy_Frontend::$option_name = self::$option_name;
EM_Taxonomy_Frontend::$option_name_plural = self::$option_name_plural;
}
}
class EM_Category_Taxonomy extends EM_Categories_Frontend {} //backwards compatibility
EM_Categories_Frontend::init();
//Walker classes allowing for hierarchical display of categories
/**
* Create an array of Categories. Copied from Walker_CategoryDropdown, but makes it possible for the selected argument to be an array.
*
* @package WordPress
* @since 2.1.0
* @uses Walker
*/
class EM_Walker_Category extends Walker {
/**
* @see Walker::$tree_type
* @since 2.1.0
* @var string
*/
var $tree_type = 'event-category';
/**
* @see Walker::$db_fields
* @since 2.1.0
* @todo Decouple this
* @var array
*/
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
function __construct(){
$tree_type = EM_TAXONOMY_CATEGORY;
}
/**
* @see Walker::start_el()
*/
function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
$pad = str_repeat('&nbsp;', $depth * 3);
$cat_name = $object->name;
$name = !empty($args['name']) ? $args['name']:'event_categories[]';
$output .= !empty($args['before']) ? $args['after']:'';
$output .= $pad."<input type=\"checkbox\" name=\"$name\" class=\"level-$depth\" value=\"".$object->term_id."\"";
if ( (is_array($args['selected']) && in_array($object->term_id, $args['selected'])) || ($object->term_id == $args['selected']) )
$output .= ' checked="checked"';
$output .= ' /> ';
$output .= $cat_name;
$output .= !empty($args['after']) ? $args['after']:'<br />';
}
}
/**
* Create an array of Categories. Copied from Walker_CategoryDropdown, but makes it possible for the selected argument to be an array.
*
* @package WordPress
* @since 2.1.0
* @uses Walker
*/
class EM_Walker_CategoryMultiselect extends EM_Walker_Category {
/**
* @see Walker::start_el()
*/
function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
$pad = str_repeat('&nbsp;', $depth * 3);
$cat_name = $object->name;
$output .= "\t<option class=\"level-$depth\" value=\"".$object->term_id."\"";
if ( (is_array($args['selected']) && in_array($object->term_id, $args['selected'])) || ($object->term_id == $args['selected']) )
$output .= ' selected="selected"';
$output .= '>';
$output .= $pad.$cat_name;
$output .= "</option>\n";
}
}
\ No newline at end of file
<?php
class EM_Categories extends EM_Taxonomy_Terms {
//Overridable functions
protected $is_ms_global = true;
protected $taxonomy = 'event-categories';
protected $meta_key = 'event-category';
protected $terms_name = 'categories';
protected $term_class = 'EM_Category';
protected $ajax_search_action = 'search_cats';
/**
* Creates an EM_Categories instance, currently accepts an EM_Event object (gets all Categories for that event) or array of any EM_Category objects, which can be manipulated in bulk with helper functions.
* @param mixed $data
* @return null
*/
function __construct( $data = false ){
$this->taxonomy = EM_TAXONOMY_CATEGORY;
parent::__construct($data);
}
/**
* Legacy get overload for any use of $EM_Categories->tags
* @param string $var_name
* @return array|NULL
*/
function __get( $var_name ){
if( $var_name == 'categories' ){
return $this->terms;
}
return null;
}
/**
* Legacy overload for use of empty($this->categories)
* @param string $prop
* @return boolean
*/
function __isset( $prop ){
if( $prop == 'categories' ){
return !empty($this->terms);
}
return parent::__isset( $prop );
}
//Functions we won't need when PHP 5.3 minimum allows for use of LSB
public static function get( $args = array() ){
self::$instance = new EM_Categories();
return parent::get($args);
}
public static function output( $args = array() ){
self::$instance = new EM_Categories();
return parent::output($args);
}
public static function get_pagination_links($args, $count, $search_action = 'search_cats', $default_args = array()){
self::$instance = new EM_Categories();
return parent::get_pagination_links($args, $count, $search_action, $default_args);
}
public static function get_post_search($args = array(), $filter = false, $request = array(), $accepted_args = array()){
self::$instance = new EM_Categories();
return parent::get_post_search($args, $filter, $request, $accepted_args);
}
public static function get_default_search( $array_or_defaults = array(), $array = array() ){
self::$instance = new EM_Categories();
return parent::get_default_search($defaults,$array);
}
}
\ No newline at end of file
<?php
class EM_Category extends EM_Taxonomy_Term {
//static options for EM_Category, but until PHP 5.3 is the WP minimum requirement we'll make them regular properties due to lack of late static binding
public $option_ms_global = true;
public $option_name = 'category'; //the singular name of this taxonomy which is used in option names consistent across EM taxonomies
public $taxonomy = 'EM_TAXONOMY_CATEGORY';
/**
* Necessary to supply the $class_name until late static binding is reliably available on all WP sites running PHP 5.3
* @param string $id
* @param string $class_name
* @return EM_Taxonomy
*/
public static function get( $id, $class_name = 'EM_Category' ){
return parent::get($id, $class_name);
}
public function can_manage( $capability_owner = 'edit_event_categories', $capability_admin = false, $user_to_check = false ){
return parent::can_manage($capability_owner, $capability_admin, $user_to_check);
}
}
/**
* Get an category in a db friendly way, by checking globals and passed variables to avoid extra class instantiations
* @param mixed $id
* @return EM_Category
* @uses EM_Category::get()
*/
function em_get_category( $id ) {
return EM_Category::get($id);
}
\ No newline at end of file
<?php
/**
* Extends the native DateTimeZone object by allowing for UTC manual offsets as supported by WordPress, along with eash creation of a DateTimeZone object with the blog's timezone.
* @since 5.8.2
*/
class EM_DateTimeZone extends DateTimeZone {
public $utc_offset = false;
public function __construct( $timezone ){
//if we're not suppiled a DateTimeZone object, create one from string or implement manual offset
if( $timezone != 'UTC' ){
$timezone = preg_replace('/^UTC ?/', '', $timezone);
if( is_numeric($timezone) ){
if( absint($timezone) == 0 ){
$timezone = 'UTC';
}else{
// convert this to an offset, taken from wp_timezone
$offset = (float) $timezone;
$hours = (int) $offset;
$minutes = ( $offset - $hours );
$sign = ( $offset < 0 ) ? '-' : '+';
$abs_hour = abs( $hours );
$abs_mins = abs( $minutes * 60 );
$timezone = sprintf( '%s%02d%02d', $sign, $abs_hour, $abs_mins );
}
}
}
parent::__construct($timezone);
}
/**
* Special function which converts a timezone string, UTC offset or DateTimeZone object into a valid EM_DateTimeZone object.
* If no value supplied, a EM_DateTimezone with the default WP environment timezone is created.
* @param mixed $timezone
* @return EM_DateTimeZone
*/
public static function create( $timezone = false ){
//if we're not suppiled a DateTimeZone object, create one from string or implement manual offset
if( !empty($timezone) && !is_object($timezone) ){
//create EM_DateTimeZone object if valid, otherwise allow defaults to override later
try {
$timezone = new EM_DateTimeZone($timezone);
}catch( Exception $e ){
$timezone = null;
}
}elseif( is_object($timezone) && get_class($timezone) == 'DateTimeZone'){
//if supplied a regular DateTimeZone, convert it to EM_DateTimeZone
$timezone = new EM_DateTimeZone($timezone->getName());
}
if( !is_object($timezone) ){
//if no valid timezone supplied, get the default timezone in EM environment, otherwise the WP timezone or offset
$timezone = get_option( 'timezone_string' );
if( !$timezone ) $timezone = get_option('gmt_offset');
$timezone = new EM_DateTimeZone($timezone);
}
return $timezone;
}
#[\ReturnTypeWillChange]
/**
* {@inheritDoc}
* @see DateTimeZone::getName()
*/
public function getName(){
if( $this->isUTC() ){
return 'UTC'.parent::getName();
}
return parent::getName();
}
public function isUTC(){
$name = parent::getName();
return $name[0] === '-' || $name[0] === '+';
}
/**
* Returns WP-friendly timezone value, which accounts for UTC offsets and modifies accoridnly so that minute offsets also work.
* @return string
*/
public function getValue(){
if( $this->isUTC() ){
$time = explode(':', parent::getName());
if( !empty($time[1]) ){
$mins = $time[1] / 60;
$hours = (int) $time[0];
if( $hours > 0 ){
$time_int = '+' . ($hours + $mins);
}else{
$time_int = $hours - $mins;
}
return 'UTC'.$time_int;
}
}
return $this->getName();
}
#[\ReturnTypeWillChange]
/**
* If the timezone has a manual UTC offset, then an empty array of transitions is returned.
* {@inheritDoc}
* @see DateTimeZone::getTransitions()
*/
public function getTransitions( $timestamp_begin = 0, $timestamp_end = 0 ){
if( $timestamp_end === 0 ) $timestamp_end = time() * YEAR_IN_SECONDS;
if( $this->utc_offset !== false ){
return array();
}
return parent::getTransitions($timestamp_begin, $timestamp_end);
}
}
\ No newline at end of file
This diff could not be displayed because it is too large.
<?php
//in case we include it in EM core code
if( !class_exists('EM_Exception') ){
/**
* Extended Exception class that allows for creating multiple error messages in an exception as an array and outputting them together at once.
* Class Exception
*/
class EM_Exception extends Exception {
/**
* @var WP_Error
*/
public $wp_error;
/**
* @var array
*/
public $error_messages = array();
/**
* @var int|string Allows for a custom code to be used rather than an integer.
*/
public $error_code;
/**
* Exception constructor.
* @param string $error
* @param int $code
* @param null $previous
*/
public function __construct($error = '', $code = 0, $previous = null ){
if( is_array($error) ) {
$this->error_messages = $error;
$message = $this->get_message();
}elseif( is_wp_error($error) ){ /* @var WP_Error $error */
$this->wp_error = $error;
$code = $error->get_error_code();
$message = $error->get_error_message();
}else{
$message = $error;
}
if( !is_numeric($code) ){
$this->error_code = $code;
$code = 0;
}
parent::__construct($message, $code, $previous);
}
/**
* Returns either a string code reference, or a regular Exception code number.
* @return int|string
*/
public function get_error_code(){
if( $this->error_code ){
return $this->error_code;
}
return $this->getCode();
}
/**
* Provides a paragraph-formatted message which may contain multiple paragraphs for multiple errors.
* @return string
*/
public function get_message(){
if( $this->is_wp_error() ){
$message = '<p>' . implode('</p><p>', $this->wp_error->get_error_messages()) . '</p>';
}elseif( !empty($this->error_messages) ){
$message = '<p>' . implode('</p><p>', $this->error_messages) . '</p>';
}else{
$message = '<p>' . $this->getMessage() . '</p>';
}
return $message;
}
/**
* @return array|string
*/
public function get_messages(){
if( $this->is_wp_error() ){
return $this->wp_error->get_error_messages();
}elseif( !empty($this->error_messages) ){
return $this->error_messages;
}else{
return array($this->getMessage());
}
}
/**
* Whether or not this exception was triggered by a WP_Error
* @return bool
*/
public function is_wp_error(){
return is_wp_error( $this->wp_error );
}
/**
* Returns exception in WP_Error format, whether or not it was originally a WP_Error in the first place.
* @return WP_Error
*/
public function get_wp_error(){
if( $this->is_wp_error() ){
return $this->wp_error;
}
$WP_Error = new WP_Error();
$WP_Error->add_data( $this->get_messages(), $this->getCode() );
return $WP_Error;
}
}
}
\ No newline at end of file
<?php
namespace EM;
use WP_List_Table;
// WP_List_Table is not loaded automatically so we need to load it in our application
if( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
/**
* Create a new table class that will extend the WP_List_Table
*/
class List_Table extends WP_List_Table {
public $per_page = 20;
public $total_items = 0;
public $per_page_var = 'limit';
public $has_checkboxes = true;
public $checkbox_id = 'id';
/**
* Prepare the items for the table to process
*
* @return Void
*/
public function prepare_items(){
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
$this->per_page = $this->get_items_per_page( $this->per_page_var, $this->per_page );
$this->items = $this->table_data();
$this->set_pagination_args( array(
'total_items' => $this->total_items,
'per_page' => $this->per_page,
'total_pages' => ceil($this->total_items / $this->per_page),
) );
$this->_column_headers = array($columns, $hidden, $sortable);
}
/**
* Adds a wrapper to the top/bottom of the actual table of values
*
* @param $which
*
* @return void
*/
public function display_tablenav( $which ) {
if ( $which == 'top' ) {
parent::display_tablenav( $which );
echo '<div class="table-wrap">';
}else{
echo '</div>';
parent::display_tablenav( $which );
}
}
/**
* Define which columns are hidden
*
* @return array
*/
public function get_hidden_columns(){
return array();
}
/**
* Should be overriden, obtains data for populating the table.
* @return array
*/
protected function table_data(){
return array();
}
/**
* Override the parent columns method. Defines the columns to use in your listing table
*
* @return array
*/
public function get_columns() {
$columns = array();
if( $this->has_checkboxes ) {
$columns['cb'] = '<input type="checkbox" />';
}
return $columns;
}
/**
* Define what data to show on each column of the table
*
* @param array $item Data
* @param String $column_name - Current column name
*
* @return Mixed
*/
public function column_default( $item, $column_name ){
if( !empty( $item->$column_name) ){
return $item->$column_name;
}
return '';
}
/**
* Bulk Edit Checkbox
* @param array $item
* @return string
*/
function column_cb( $item ) {
if( is_object($item) ){
$id = $item->{$this->checkbox_id};
}else{
$id = $item[$this->checkbox_id];
}
return sprintf('<input type="checkbox" name="column_id[]" value="%s" />', $id);
}
}
\ No newline at end of file
<?php
class EM_Location_Post {
public static function init(){
//Front Side Modifiers
if( !is_admin() ){
//override single page with formats?
add_filter('the_content', array('EM_Location_Post','the_content'));
//override excerpts?
if( get_option('dbem_cp_locations_excerpt_formats') ){
add_filter('get_the_excerpt', array('EM_Location_Post','the_excerpt'), 9);
}
//excerpts can trigger the_content which isn't ideal, so we disable the_content between the first and last excerpt calls within WP logic
add_filter('get_the_excerpt', array('EM_Location_Post','disable_the_content'), 1);
add_filter('get_the_excerpt', array('EM_Location_Post','enable_the_content'), 100);
//display as page or other template?
if( get_option('dbem_cp_locations_template') ){
add_filter('single_template',array('EM_Location_Post','single_template'));
}
//add classes to body and post_class()
if( get_option('dbem_cp_locations_post_class') ){
add_filter('post_class', array('EM_Location_Post','post_class'), 10, 3);
}
if( get_option('dbem_cp_locations_body_class') ){
add_filter('body_class', array('EM_Location_Post','body_class'), 10, 3);
}
}
add_action('parse_query', array('EM_Location_Post','parse_query'));
}
/**
* Overrides the default post format of a location and can display a location as a page, which uses the page.php template.
* @param string $template
* @return string
*/
public static function single_template($template){
global $post;
if( !locate_template('single-'.EM_POST_TYPE_LOCATION.'.php') && $post->post_type == EM_POST_TYPE_LOCATION ){
//do we have a default template to choose for events?
if( get_option('dbem_cp_locations_template') == 'page' ){
$post_templates = array('page.php','index.php');
}else{
$post_templates = array(get_option('dbem_cp_locations_template'));
}
if( !empty($post_templates) ){
$post_template = locate_template($post_templates,false);
if( !empty($post_template) ) $template = $post_template;
}
}
return $template;
}
public static function post_class( $classes, $class, $post_id ){
$post = get_post($post_id);
if( $post->post_type == EM_POST_TYPE_LOCATION ){
foreach( explode(' ', get_option('dbem_cp_locations_post_class')) as $class ){
$classes[] = esc_attr($class);
}
}
return $classes;
}
public static function body_class( $classes ){
if( em_is_location_page() ){
foreach( explode(' ', get_option('dbem_cp_locations_body_class')) as $class ){
$classes[] = esc_attr($class);
}
}
return $classes;
}
/**
* Overrides the_excerpt if this is an location post type
*/
public static function get_the_excerpt($content){
global $post;
if( $post->post_type == EM_POST_TYPE_LOCATION ){
$EM_Location = em_get_location($post);
$output = !empty($EM_Location->post_excerpt) ? get_option('dbem_location_excerpt_format'):get_option('dbem_location_excerpt_alt_format');
$content = $EM_Location->output($output);
}
return $content;
}
public static function the_excerpt($content){ return self::get_the_excerpt($content); }
public static function enable_the_content( $content ){
add_filter('the_content', array('EM_Location_Post','the_content'));
return $content;
}
public static function disable_the_content( $content ){
remove_filter('the_content', array('EM_Location_Post','the_content'));
return $content;
}
public static function the_content( $content ){
global $post, $EM_Location;
if( !empty($post) && $post->post_type == EM_POST_TYPE_LOCATION ){
if( is_archive() || is_search() ){
if( get_option('dbem_cp_locations_archive_formats') ){
$EM_Location = em_get_location($post);
$content = $EM_Location->output(get_option('dbem_location_list_item_format'));
}
}else{
if( get_option('dbem_cp_locations_formats') && !post_password_required() ){
$EM_Location = em_get_location($post);
if( !empty($_REQUEST['preview']) ){
//we don't do extra checks here because WP will have already done the work for us here...
$EM_Location->post_content = $post->post_content;
$EM_Location->post_content_filtered = $post->post_content_filtered;
}else{
$EM_Location->post_content = $content;
}
ob_start();
em_locate_template('templates/location-single.php',true);
$content = ob_get_clean();
}
}
}
return $content;
}
public static function parse_query(){
global $wp_query;
if( !empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == EM_POST_TYPE_LOCATION ){
if( is_admin() ){
$wp_query->query_vars['orderby'] = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby']:'title';
$wp_query->query_vars['order'] = (!empty($_REQUEST['order'])) ? $_REQUEST['order']:'ASC';
}else{
if( get_option('dbem_locations_default_archive_orderby') == 'title'){
$wp_query->query_vars['orderby'] = 'title';
}else{
$wp_query->query_vars['orderby'] = 'meta_value_num';
$wp_query->query_vars['meta_key'] = get_option('dbem_locations_default_archive_orderby','_location_country');
}
$wp_query->query_vars['order'] = get_option('dbem_locations_default_archive_order','ASC');
}
}
}
}
EM_Location_Post::init();
\ No newline at end of file
<?php
class EM_Location_Posts_Admin{
public static function init(){
global $pagenow;
if($pagenow == 'edit.php' && !empty($_REQUEST['post_type']) && $_REQUEST['post_type'] == EM_POST_TYPE_LOCATION ){ //only needed if editing post
//hide some cols by default:
$screen = 'edit-'.EM_POST_TYPE_LOCATION;
$hidden = get_user_option( 'manage' . $screen . 'columnshidden' );
if( $hidden === false ){
$hidden = array('location-id');
update_user_option(get_current_user_id(), "manage{$screen}columnshidden", $hidden, true);
}
add_action('admin_head', array('EM_Location_Posts_Admin','admin_head'));
}
add_filter('manage_'.EM_POST_TYPE_LOCATION.'_posts_columns' , array('EM_Location_Posts_Admin','columns_add'));
add_filter('manage_'.EM_POST_TYPE_LOCATION.'_posts_custom_column' , array('EM_Location_Posts_Admin','columns_output'),10,2 );
}
public static function admin_head(){
//quick hacks to make event admin table make more sense for events
?>
<script type="text/javascript">
jQuery(document).ready( function($){
$('.inline-edit-date').prev().css('display','none').next().css('display','none').next().css('display','none');
});
</script>
<style>
table.fixed{ table-layout:auto !important; }
.tablenav select[name="m"] { display:none; }
</style>
<?php
}
public static function admin_menu(){
global $menu, $submenu;
// Add a submenu to the custom top-level menu:
$plugin_pages = array();
$plugin_pages[] = add_submenu_page('edit.php?post_type='.EM_POST_TYPE_EVENT, __('Locations', 'events-manager'), __('Locations', 'events-manager'), 'edit_locations', 'events-manager-locations', "edit.php?post_type=event");
$plugin_pages = apply_filters('em_create_locationss_submenu',$plugin_pages);
}
public static function columns_add($columns) {
//prepend ID after checkbox
if( array_key_exists('cb', $columns) ){
$cb = $columns['cb'];
unset($columns['cb']);
$id_array = array('cb'=>$cb, 'location-id' => sprintf(__('%s ID','events-manager'),__('Location','events-manager')));
}else{
$id_array = array('location-id' => sprintf(__('%s ID','events-manager'),__('Location','events-manager')));
}
unset($columns['author']);
unset($columns['date']);
unset($columns['comments']);
return array_merge($id_array, $columns, array(
'address' => __('Address','events-manager'),
'town' => __('Town','events-manager'),
'state' => __('State','events-manager'),
'country' => __('Country','events-manager')
));
}
public static function columns_output( $column ) {
global $post;
$post = em_get_location($post);
switch ( $column ) {
case 'location-id':
echo $post->location_id;
break;
case 'address':
echo $post->location_address;
break;
case 'town':
echo $post->location_town;
break;
case 'state':
echo $post->location_state;
break;
case 'country':
echo $post->location_country;
break;
}
}
}
add_action('admin_init', array('EM_Location_Posts_Admin','init'));
\ No newline at end of file
<?php
/**
* phpmailer support
*
*/
class EM_Mailer {
/**
* if any errors crop up, here they are
* @var array
*/
public $errors = array();
/**
* Array of attachments which will be added to WP_Mail's phpmailer just before sending, and subsequently emptied.
* @var array
*/
public static $attachments = array();
/**
* Send an email via the EM-saved settings.
* @param $subject
* @param $body
* @param $receiver
* @param $attachments
* @param $args
* @return boolean
*/
public function send($subject="no title",$body="No message specified", $receiver='', $attachments = array(), $args = array() ) {
//TODO add an EM_Error global object, for this sort of error reporting. (@marcus like StatusNotice)
$subject = html_entity_decode(wp_kses_data($subject)); //decode entities, but run kses first just in case users use placeholders containing html
if( is_array($receiver) ){
$receiver_emails = array();
foreach($receiver as $k => $receiver_email){
$receiver_email = trim($receiver_email);
$receiver[$k] = $receiver_email;
$receiver_emails[] = is_email($receiver_email);
}
$emails_ok = !in_array(false, $receiver_emails);
}else{
$receiver = trim($receiver);
$emails_ok = is_email($receiver);
}
if( get_option('dbem_smtp_html') && get_option('dbem_smtp_html_br') ){
$body = nl2br($body);
}
if ( $emails_ok && get_option('dbem_rsvp_mail_send_method') == 'wp_mail' ){
$from = get_option('dbem_mail_sender_address');
$headers = array();
$headers[] = get_option('dbem_mail_sender_name') ? 'From: '.get_option('dbem_mail_sender_name').' <'.$from.'>':'From: '.$from;
$headers[] = get_option('dbem_mail_sender_name') ? 'Reply-To: '.get_option('dbem_mail_sender_name').' <'.$from.'>':'From: '.$from;
if( get_option('dbem_smtp_html') ){ //create filter to change content type to html in wp_mail
add_filter('wp_mail_content_type','EM_Mailer::return_texthtml');
}
if( !empty($args) ){
if( !empty($args['reply-to']) && is_email($args['reply-to']) ){
array_pop($headers); // remove Reply-To
$name = !empty($args['reply-to-name']) ? filter_var($args['reply-to-name'], FILTER_SANITIZE_STRING) : false;
if( $name ){
$headers[] = 'Reply-To: '.$name.' <'.$args['reply-to'].'>';
}else{
$headers[] = 'Reply-To: '. $args['reply-to'];
}
}
}
//prep attachments for WP Mail, which only accept a path
self::$attachments = $attachments;
add_action('phpmailer_init', 'EM_Mailer::add_attachments_to_mailer', 9999, 1);
//send and handle errors
$send = wp_mail($receiver, $subject, $body, $headers);
//unload attachments hook
remove_action('phpmailer_init', 'EM_Mailer::add_attachments_to_mailer', 9999);
//send email
if(!$send){
global $phpmailer; /* @var PHPMailer $phpmailer */
if( !empty($phpmailer->ErrorInfo) ) {
$this->errors[] = $phpmailer->ErrorInfo;
}
}
//cleanup
self::delete_email_attachments($attachments);
return $send;
}elseif( $emails_ok ){
$this->load_phpmailer();
$mail = new PHPMailer\PHPMailer\PHPMailer();
try{
//$mail->SMTPDebug = true;
if( get_option('dbem_smtp_html') ){
$mail->isHTML();
}
$mail->clearAllRecipients();
$mail->clearAddresses();
$mail->clearAttachments();
$mail->clearCustomHeaders();
$mail->clearReplyTos();
$mail->CharSet = 'utf-8';
$mail->setLanguage('en', dirname(__FILE__).'/');
$mail->PluginDir = dirname(__FILE__).'/phpmailer/';
$host = get_option('dbem_smtp_host');
//if port is supplied via the host address, give that precedence over the port setting
if( preg_match('/^(.+):([0-9]+)$/', $host, $host_port_matches) ){
$mail->Host = $host_port_matches[1];
$mail->Port = $host_port_matches[2];
}else{
$mail->Host = $host;
$mail->Port = get_option('dbem_rsvp_mail_port');
}
$mail->Username = get_option('dbem_smtp_username');
$mail->Password = get_option('dbem_smtp_password');
$mail->From = get_option('dbem_mail_sender_address');
$mail->FromName = get_option('dbem_mail_sender_name'); // This is the from name in the email, you can put anything you like here
$mail->Body = $body;
$mail->Subject = $subject;
//SSL/TLS
if( get_option('dbem_smtp_encryption') ){
$mail->SMTPSecure = get_option('dbem_smtp_encryption');
}
$mail->SMTPAutoTLS = get_option('dbem_smtp_autotls') == 1;
//add attachments
self::add_attachments_to_mailer($mail, $attachments);
if(is_array($receiver)){
foreach($receiver as $receiver_email){
$mail->addAddress($receiver_email);
}
}else{
$mail->addAddress($receiver);
}
// extra args
if( !empty($args) ){
if( !empty($args['reply-to']) && is_email($args['reply-to']) ){
$name = !empty($args['reply-to-name']) ? filter_var($args['reply-to-name'], FILTER_SANITIZE_STRING) : false;
if( $name ){
$mail->addReplyTo($args['reply-to'], $name);
}else{
$mail->addReplyTo($args['reply-to']);
}
}
}
do_action('em_mailer', $mail); //$mail will still be modified
//Protocols
if( get_option('dbem_rsvp_mail_send_method') == 'qmail' ){
$mail->isQmail();
}elseif( get_option('dbem_rsvp_mail_send_method') == 'sendmail' ){
$mail->isSendmail();
}else {
$mail->Mailer = get_option('dbem_rsvp_mail_send_method');
}
if(get_option('dbem_rsvp_mail_SMTPAuth') == '1'){
$mail->SMTPAuth = TRUE;
}
do_action('em_mailer_before_send', $mail, $subject, $body, $receiver, $attachments); //$mail can still be modified
$send = $mail->send();
if(!$send){
$this->errors[] = $mail->ErrorInfo;
}
do_action('em_mailer_sent', $mail, $send); //$mail can still be modified
self::delete_email_attachments($attachments);
return $send;
}catch( phpmailerException $ex ){
$this->errors[] = $mail->ErrorInfo;
self::delete_email_attachments($attachments);
return false;
}
}else{
$this->errors[] = __('Please supply a valid email format.', 'events-manager');
self::delete_email_attachments($attachments);
return false;
}
}
/**
* load phpmailer classes
*/
public function load_phpmailer(){
require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
}
/**
* Shorthand function for filters to return 'text/html' string.
* @return string 'text/html'
*/
public static function return_texthtml(){
return "text/html";
}
/**
* WP_Mail doesn't accept attachment meta, only an array of paths, this function post-fixes attachments to the PHPMailer object.
* @param PHPMailer $phpmailer
* @param array $attachments
*/
public static function add_attachments_to_mailer( $phpmailer, $attachments = array() ){
//add attachments
$attachments = !empty($attachments) ? $attachments : self::$attachments;
if( !empty($attachments) ){
foreach($attachments as $attachment){
$att = array('name'=> '', 'encoding' => 'base64', 'type' => 'application/octet-stream');
if( is_array($attachment) ){
$att = array_merge($att, $attachment);
}else{
$att['path'] = $attachment;
}
try{
$phpmailer->addAttachment($att['path'], $att['name'], $att['encoding'], $att['type']);
}catch( phpmailerException $ex ){
//do nothing
}
}
}
self::$attachments = array();
}
public static function delete_email_attachments( $attachments ){
foreach( $attachments as $attachment ){
if( !empty($attachment['delete']) ){
@unlink( $attachment['path']);
}
}
}
/**
* Returns the path of the attachments folder, creating it if non-existent. Returns false if folder could not be created.
* A .htaccess file is also attempted to be created, although this will still return as true even if it cannot be created.
* @return bool|string
*/
public static function get_attachments_dir(){
//get and possibly create attachment directory path
$upload_dir = wp_upload_dir();
$attachments_dir = trailingslashit($upload_dir['basedir'])."em-email-attachments/";
if( !is_dir($attachments_dir) ){
//try to make a directory and create an .htaccess file
if( @mkdir($attachments_dir, 0755) ){
return $attachments_dir;
}
//could not create directory
return false;
}
//add .htaccess file to prevent access to folder by guessing filenames
if( !file_exists($attachments_dir.'.htaccess') ){
$file = @fopen($attachments_dir.'.htaccess','w');
if( $file ){
fwrite($file, 'deny from all');
fclose($file);
}
}
return $attachments_dir;
}
/**
* Adds file to email attachments folder, which defaults to wp-content/uploads/em-email-attachments/ and returns the location of said file, false if file could not be created.
* @param $file_name
* @param $file_content
* @return bool|string
*/
public static function add_email_attachment( $file_name, $file_content ){
$attachment_dir = self::get_attachments_dir();
if( $attachment_dir ){
$file = fopen($attachment_dir.$file_name,'w+');
if( $file ){
fwrite($file, $file_content);
fclose($file);
return $attachment_dir . $file_name;
}
}
return false;
}
}
?>
\ No newline at end of file
<?php
/**
*
* @author marcus
*
*/
class EM_Notices implements Iterator, JsonSerializable {
/**
* If object has been displayed, this gets set to true, can be checked to avoid duplicates.
* @var boolean
* @since 5.5.7
*/
public $displayed = false;
public $set_cookies = true;
public $notices = array('errors'=>array(), 'infos'=>array(), 'alerts'=>array(), 'confirms'=>array());
function __construct( $set_cookies = true ){
//Grab from cookie, if it exists
$this->set_cookies = $set_cookies == true;
if( $this->set_cookies ){
if( !empty($_COOKIE['em_notices']) ) {
$notices = json_decode(base64_decode($_COOKIE['em_notices']), true);
if( is_array($notices) ){
$this->notices = $notices;
setcookie('em_notices', '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true); //unset the cookie
}
}
}
add_filter('wp_redirect', array(&$this,'destruct'), 1,1);
}
function destruct($redirect = false){
//Flush notices that weren't made to stay cross-requests, we can do this if initialized immediately.
foreach($this->notices as $notice_type => $notices){
foreach ($notices as $key => $notice){
if( empty($notice['static']) ){
unset($this->notices[$notice_type][$key]);
}else{
unset($this->notices[$notice_type][$key]['static']); //so it gets removed next request
$has_static = true;
}
}
}
if( $this->set_cookies ){
if(count($this->notices['errors']) > 0 || count($this->notices['alerts']) > 0 || count($this->notices['infos']) > 0 || count($this->notices['confirms']) > 0){
setcookie('em_notices', base64_encode(json_encode($this->notices)), time() + 30, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true); //sets cookie for 30 seconds, which may be too much
}
}
return $redirect;
}
function display(){
echo $this;
}
function __toString(){
$string = false;
if(count($this->notices['errors']) > 0){
$string .= "<div class='em-notice em-notice-error notice notice-error'>{$this->get_errors()}</div>";
}
if(count($this->notices['alerts']) > 0){
$string .= "<div class='em-notice em-notice-warning notice notice-warning'>{$this->get_alerts()}</div>";
}
if(count($this->notices['infos']) > 0){
$string .= "<div class='em-notice notice notice-info'>{$this->get_infos()}</div>";
}
if(count($this->notices['confirms']) > 0){
$string .= "<div class='em-notice em-notice-success notice notice-success'>{$this->get_confirms()}</div>";
}
$this->displayed = true;
return ($string !== false) ? "<div class='statusnotice'>".$string."</div>" : '';
}
/* General */
function add($string, $type, $static = false){
if( is_array($string) ){
$result = true;
foreach($string as $key => $string_item){
if( !is_array($string_item) ){
if( $this->add($string_item, $type, $static) === false ){ $result = false; }
}else{
if( $this->add_item($string_item, $type, $static) === false ){ $result = false; }
}
}
return $result;
}
if($string != ''){
return $this->add_item($string, $type, $static);
}else{
return false;
}
}
function add_item($string, $type, $static = false){
if( isset($this->notices[$type]) ){
$notice_key = 0;
foreach( $this->notices[$type] as $notice_key => $notice ){
if($string == $notice['string']){
return $notice_key;
}elseif( is_array($string) && !empty($notice['title']) && $this->get_array_title($string) == $notice['title'] ){
return $notice_key;
}
}
$i = $notice_key+1;
if( is_array($string) ){
$this->notices[$type][$i]['title'] = $this->get_array_title($string);
$this->notices[$type][$i]['string'] = array_shift($string);
}else{
$this->notices[$type][$i]['string'] = $string;
}
if( $static ){
$this->notices[$type][$i]['static'] = true;
}
return $i;
}else{
return false;
}
}
/**
* Returns title of an array, assumes a assoc array with one item containing title => messages
* @param unknown_type $array
* @return unknown
*/
function get_array_title($array){
foreach($array as $title => $msgs)
return $title;
}
function remove($key, $type){
if( isset($this->notices[$type]) ){
unset($this->notices[$type][$key]);
return true;
}else{
return false;
}
}
function remove_all(){
$this->notices = array('errors'=>array(), 'infos'=>array(), 'alerts'=>array(), 'confirms'=>array());
}
function get($type){
if( isset($this->notices[$type]) ){
$string = '';
foreach ($this->notices[$type] as $message){
if( !is_array($message['string']) ){
if( preg_match('/<p>/', $message['string']) ){
$string .= $message['string'];
}else{
$string .= "<p>{$message['string']}</p>";
}
}else{
$string .= "<p><strong>".$message['title']."</strong><ul>";
foreach($message['string'] as $msg){
if( trim($msg) != '' ){
$string .= "<li>$msg</li>";
}
}
$string .= "</ul></p>";
}
}
return $string;
}
return false;
}
function count($type){
if( isset($this->notices[$type]) ){
return count($this->notices[$type]);
}
return 0;
}
/* Errors */
function add_error($string, $static=false){
return $this->add($string, 'errors', $static);
}
function remove_error($key){
return $this->remove($key, 'errors');
}
function get_errors(){
return $this->get('errors');
}
function count_errors(){
return $this->count('errors');
}
/* Alerts */
function add_alert($string, $static=false){
return $this->add($string, 'alerts', $static);
}
function remove_alert($key){
return $this->remove($key, 'alerts');
}
function get_alerts(){
return $this->get('alerts');
}
function count_alerts(){
return $this->count('alerts');
}
/* Info */
function add_info($string, $static=false){
return $this->add($string, 'infos', $static);
}
function remove_info($key){
return $this->remove($key, 'infos');
}
function get_infos(){
return $this->get('infos');
}
function count_infos(){
return $this->count('infos');
}
/* Confirms */
function add_confirm($string, $static=false){
return $this->add($string, 'confirms', $static);
}
function remove_confirm($key){
return $this->remove($key, 'confirms');
}
function get_confirms(){
return $this->get('confirms');
}
function count_confirms(){
return $this->count('confirms');
}
// Encoiding in JsonSerializable
#[\ReturnTypeWillChange]
function jsonSerialize(){
$notices = array();
foreach( $notices as $k => $v ){
if( !empty($v) ){
$notices[$k] = $v;
}
}
return $notices;
}
//Iterator Implementation
#[\ReturnTypeWillChange]
function rewind(){
reset($this->bookings);
}
#[\ReturnTypeWillChange]
function current(){
$var = current($this->bookings);
return $var;
}
#[\ReturnTypeWillChange]
function key(){
$var = key($this->bookings);
return $var;
}
#[\ReturnTypeWillChange]
function next(){
$var = next($this->bookings);
return $var;
}
#[\ReturnTypeWillChange]
function valid(){
$key = key($this->bookings);
$var = ($key !== NULL && $key !== FALSE);
return $var;
}
}
function em_notices_init(){
global $EM_Notices;
$EM_Notices = new EM_Notices();
}
add_action('plugins_loaded', 'em_notices_init');
?>
\ No newline at end of file
<?php
namespace EM_OAuth;
use EM_Options, EM_Exception;
use Matrix\Exception;
class OAuth_API_Admin_Settings {
public static $option_name = 'em_oauth';
public static $service_name = 'EM OAuth 2.0';
/**
* @var OAuth_API Class name of base API class for this service type, used for static variable referencing
*/
public static $api_class = 'EM_OAuth\OAuth_API';
public static $service_url = 'http://example.com';
public static $icon_url = '';
public static function init(){
$class = get_called_class(); //get child class name to call
self::$icon_url = plugin_dir_url(__FILE__). 'icon.png';
//handle service app creds
add_action('em_options_page_footer', "$class::em_settings_apps");
add_action('em_options_save', "$class::em_settings_save_apps");
}
/**
* @return OAuth_API
*/
public static function get_api_class(){
//set default API class name if not defined by parent
if( self::$api_class === static::$api_class && class_exists(str_replace('_Admin_Settings', '', get_called_class())) ){
static::$api_class = str_replace('_Admin_Settings', '', get_called_class());
}
return static::$api_class;
}
public static function em_settings_save_apps(){
$api = static::get_api_class();
if( $api::get_option_dataset() == 'dbem_oauth' ) return;
$option_names = array($api::get_option_name().'_app_id', $api::get_option_name().'_app_secret');
foreach( $option_names as $option_name ){
$value = !empty($_REQUEST[$api::get_option_dataset()][$option_name]) ? $_REQUEST[$api::get_option_dataset()][$option_name] : '';
EM_Options::set($option_name, $value, $api::get_option_dataset());
}
}
public static function em_settings_apps_header(){
// override this for extra content above settings meta box
}
public static function em_settings_apps(){
$desc = esc_html__("You'll need to create an App with %s and obtain the App credentials by going to %s.", 'events-manager');
$desc_url = esc_html__('You will also need supply an OAuth redirect url to %s. Your url for this site is : %s', 'events-manager');
$api = static::get_api_class(); /* @var OAuth_API $api */
$api_client_class = $api::get_client_class();
$callback_url = $api_client_class::get_oauth_callback_url();
$service_name = $api::get_service_name();
?>
<div class="postbox em-oaut-connect em-oauth-connect-<?php echo esc_attr($api::get_authorization_scope()); ?>" id="em-opt-<?php echo esc_attr($api::get_option_name()); ?>-app" >
<div class="handlediv" title="<?php __('Click to toggle', 'events-manager'); ?>"><br /></div><h3><span><?php echo esc_html($api::get_service_name()) ?></span></h3>
<div class="inside">
<?php static::em_settings_apps_header(); ?>
<h4><?php esc_html_e('Server API Credentials', 'events-manager-zoom'); ?></h4>
<p><?php printf( $desc, $service_name, '<a href="'. $api::get_service_url() .'">'. $api::get_service_url() .'</a>'); ?></p>
<p><?php printf( $desc_url, $service_name, "<code>$callback_url</code>") ?></p>
<p><?php printf( esc_html__('Once you have entered valid API information, you will see a button below to connect your site to %s.', 'events-manager-zoom'), $service_name); ?></p>
<table class='form-table'>
<?php
em_options_input_text(sprintf(__('%s App ID', 'events-manager'), $service_name), $api::get_option_dataset().'['.$api::get_option_name().'_app_id]', '');
em_options_input_text(sprintf(__('%s App Secret', 'events-manager'), $service_name), $api::get_option_dataset().'['.$api::get_option_name().'_app_secret]', '');
?>
</table>
<?php
static::em_settings_user_auth();
static::em_settings_apps_footer();
?>
</div> <!-- . inside -->
</div> <!-- .postbox -->
<?php
}
public static function em_settings_apps_footer(){
// override this for extra content above settings meta box
}
public static function em_settings_user_auth(){
//a fresh client with no token for generating oauth links
$api = static::get_api_class(); /* @var OAuth_API $api */
try{
$api_client = $api::get_client(false); /* @var OAuth_API_Client $api_client */
$service_name = $api::get_service_name();
$option_name = $api::get_option_name();
//get tokens if client is configured
if( !is_wp_error($api_client) ){ //oauth is not configured correctly...
$oauth_url = $api_client->get_oauth_url();
//we don't need to verify connections at this point, we just need to know if there are any
if( $api_client->authorization_scope == 'user' ){
$user_id = get_current_user_id();
$access_tokens = $api::get_user_tokens();
}else{
$user_id = null;
$access_tokens = $api::get_site_tokens();
}
$oauth_accounts = array();
$connected = $reconnect_required = false;
foreach( $access_tokens as $account_id => $oauth_account ){
try {
$api_client->load_token( $account_id, $user_id );
$verification = true;
} catch ( EM_Exception $e ) {
$verification = false;
}
$oauth_account['id'] = !empty($oauth_account['email']) ? $oauth_account['email'] : $account_id;
$disconnect_url_args = array( 'action' => 'em_oauth_'. $api::get_option_name(), 'callback' => 'disconnect', 'account' => $account_id, 'nonce' => wp_create_nonce('em-oauth-'. $option_name .'-disconnect-'.$account_id) );
$oauth_account['disconnect'] = add_query_arg( $disconnect_url_args, admin_url( 'admin-ajax.php' ) );
if( !$verification ){
$oauth_account['reconnect'] = true;
$reconnect_required = true;
}else{
$connected = true;
}
$oauth_accounts[] = $oauth_account;
}
if( $connected ){
$button_url = add_query_arg( array( 'action' => 'em_oauth_'. $option_name, 'callback' => 'disconnect', 'nonce' => wp_create_nonce('em-oauth-'. $option_name .'-disconnect') ), admin_url( 'admin-ajax.php' ) );
$button_text = count($oauth_accounts) > 1 ? __('Disconnect All', 'events-manager') : __('Disonnect', 'events-manager');
$button_class = 'button-secondary';
}else{
$button_url = $oauth_url;
$button_text = __('Connect', 'events-manager');
$button_class = 'button-primary';
}
}
?>
<div class="em-oauth-service-info">
<?php if( $api::get_authorization_scope() == 'user'): ?>
<h4><?php echo $service_name; ?></h4>
<?php else: ?>
<h4><?php esc_html_e('Account Connection', 'events-manager-zoom'); ?></h4>
<?php endif; ?>
<?php if( $connected || $reconnect_required ): ?>
<p><?php echo esc_html(sprintf(_n('You are successfully connected to the following %s account:', 'You are successfully connected to the following %s accounts:', count($oauth_accounts), 'events-manager-zoom'), $service_name)); ?></p>
<ul clss="em-oauth-service-accounts">
<?php foreach ( $oauth_accounts as $oauth_account ): ?>
<li class="em-oauth-service-account em-oauth-account-<?php echo empty($oauth_account['reconnect']) ? 'connected':'disconnected'; ?>">
<img src="<?php echo esc_url($oauth_account['photo']); ?>" width="25" height="25">
<div class="em-oauth-account-description">
<span class="em-oauth-account-label">
<?php if( !empty($oauth_account['reconnect']) ): ?><span class="dashicons dashicons-warning"></span><?php endif; ?>
<?php echo esc_html($oauth_account['name']) .' <em>('. esc_html($oauth_account['id']) .')</em>'; ?>
</span>
<span class="em-oauth-account-actions">
<?php if( count($oauth_accounts) > 1 ): ?>
<a href="<?php echo esc_url($oauth_account['disconnect']); ?>"><?php esc_html_e('Disconnect', 'events-manager'); ?></a>
<?php elseif( !empty($oauth_account['reconnect']) ): ?>
<a href="<?php echo esc_url($oauth_url); ?>"><?php esc_html_e('Reconnect', 'events-manager'); ?></a> |
<a href="<?php echo esc_url($oauth_account['disconnect']); ?>"><?php esc_html_e('Remove', 'events-manager'); ?></a>
<?php endif; ?>
</span>
</div>
</li>
<?php endforeach; ?>
</ul>
<p>
<a class="<?php echo $button_class; ?> em-oauth-connect-button" href="<?php echo esc_url($button_url); ?>"><?php echo esc_html($button_text); ?></a>
<?php if( $api::supports_multiple_tokens() ): ?>
<a class="button-secondary" href="<?php echo esc_url($oauth_url); ?>"><?php esc_html_e('Connect additional account') ?></a>
<?php endif; ?>
</p>
<?php do_action('em_settings_user_auth_after_connect_additional_'.$option_name); ?>
<p><em><?php esc_html_e('If you are experiencing errors when trying to use any of these accounts, try disconnecting and connecting again.', 'events-manager'); ?></em></p>
<?php else: ?>
<p><em><?php echo sprintf(esc_html__('Connect to import events and locations from %s.','events-manager'), $service_name); ?></em></p>
<p><a class="<?php echo $button_class; ?> em-oauth-connect-button" href="<?php echo esc_url($button_url); ?>"><?php echo esc_html($button_text); ?></a></p>
<?php endif; ?>
</div>
<?php
}catch( EM_Exception $ex ){
?>
<div class="em-oauth-service-info">
<p><em><?php echo $ex->get_message(); ?></em></p>
</div>
<?php
}
}
}
\ No newline at end of file
<?php
namespace EM_OAuth;
use EM_Exception;
class OAuth_API_Token {
public $access_token = '';
public $refresh_token = '';
public $token_type = '';
public $expires_in = 0;
/**
* @var int Timestamp when a token will expire at, which can be supplied instead of expires_in and that value will be generated from this one.
*/
public $expires_at = 0;
public $created = 0;
public $id = '';
public $email = '';
public $name = '';
public $photo = '';
/**
* @param array $token
* @throws EM_Exception
*/
public function __construct( $token ){
$this->refresh($token);
if( empty($token['created']) ) $this->created = time();
}
/**
* @param array $token
* @return boolean $updated
* @throws EM_Exception
*/
public function refresh( $token, $reset = false ){
$updated = false;
// reset values
if( $reset ){
$this->expires_in = $this->expires_at = $this->created = 0;
$this->access_token = $this->refresh_token = $this->token_type = '';
}
// add new values
foreach( $token as $k => $v ){
if( empty($this->$k) || $this->$k != $token[$k] ){
$this->$k = $token[$k];
$updated = true;
}
}
// set values that may not have been added
if( empty($this->id) && !empty($this->email) ) $this->id = $this->email;
if( !$this->created ) $this->created = time();
// set expires_at, which is what we'll use for expiry checking
if( $this->expires_at ){
$this->expires_in = $this->expires_at - time();
}elseif( $this->created && $this->expires_in ){
$this->expires_at = $this->expires_in + $this->created;
}else{
$this->expires_in = $this->expires_at = time();
}
$this->verify();
return $updated;
}
/**
* @throws EM_Exception
*/
public function verify(){
$missing = array();
foreach( array('access_token', 'expires_at') as $k ){
if( empty($this->$k) ) $missing[] = $k;
}
if( !empty($missing) ) throw new EM_Exception( sprintf(__('Involid token credentials, the folloiwng are missing: %s.', 'events-manager'), implode(', ', $missing)) );
}
public function is_expired(){
return $this->expires_at < time();
}
public function to_array(){
$array = array();
$ignore = array('id');
foreach( get_object_vars($this) as $k => $v ){
if( !in_array($k, $ignore) && !empty($this->$k) ) $array[$k] = $this->$k;
}
return $array;
}
}
\ No newline at end of file
<?php
namespace EM_OAuth;
use EM_Exception, EM_Notices, EM_Options;
class OAuth_API {
/**
* The name of this service to be displayed to the end user in notices etc.
* @var string
*/
protected static $service_name = 'EM OAuth 2.0';
/**
* @var string
*/
protected static $service_url = 'http://example.com';
/**
* Ths option/key name used to differentiate this from other OAuth objects stored in the database tables.
* @var string
*/
protected static $option_name = 'oauth';
/**
* Where data about this API is stored, which is by default in a serialized array with option name 'em_oauth'
* @var string
*/
protected static $option_dataset = 'dbem_oauth';
/**
* Allows overriding the default client class to be loaded, set this to the token class name you'd like to use instead.
* By default, the extended classname preceded by _Client will be used if it exists, otherwise OAuth_API_Client.
* @var string
*/
protected static $client_class;
/**
* Allows overriding the default token class to be loaded, set this to the token class name you'd like to use instead.
* By default, the extended classname preceded by _Token will be used if it exists, otherwise OAuth_API_Token.
* @var string
*/
protected static $token_class;
/**
* Defines whether authorization tokens are stored at a site, user or (eventually) network level.
* @var string 'site' or 'user' level (future consideration for 'network')
*/
protected static $authorization_scope = 'site';
/**
* Whether or not storage destination supports multiple accounts (e.g. multiple accounts for a site or a user)
* @var bool
*/
protected static $multiple_tokens = false;
/**
* @return string
*/
public static function get_service_name() {
return static::$service_name;
}
/**
* @return string
*/
public static function get_service_url() {
return static::$service_url;
}
/**
* @return string
*/
public static function get_option_name() {
return static::$option_name;
}
/**
* @return string
*/
public static function get_option_dataset() {
return static::$option_dataset;
}
/**
* @return OAuth_API_Client|string String representation of token class, used for instantiation or static function/property reference
*/
public static function get_client_class() {
if( static::$client_class !== null && class_exists(static::$client_class) ) return static::$client_class;
if( static::$client_class === null && class_exists(get_called_class().'_Client') ){
static::$client_class = get_called_class().'_Client';
return static::$client_class;
}
return 'EM_OAuth\OAuth_API_Client';
}
/**
* @return OAuth_API_Token|string String representation of token class, used for instantiation or static function/property reference
*/
public static function get_token_class() {
if( static::$token_class !== null && class_exists(static::$token_class) ) return static::$token_class;
if( static::$token_class === null && class_exists(get_called_class().'_Token') ){
static::$token_class = get_called_class().'_Token';
return static::$token_class;
}
return 'EM_OAuth\OAuth_API_Token';
}
/**
* @return string
*/
public static function get_authorization_scope() {
return static::$authorization_scope;
}
/**
* @return bool
*/
public static function supports_multiple_tokens() {
return static::$multiple_tokens;
}
/**
* Loads the service credentials into an abstract client api object. If a user ID is supplied and there's an issue retrieving an access token, an exception will be returned.
* @param int $user_id The User ID in WordPress
* @param int $api_user_id The ID of the account in Google (i.e. the email)
* @return OAuth_API_Client
* @throws EM_Exception
*/
public static function get_client( $user_id = 0, $api_user_id = 0 ) {
//set up the client
$client_class = static::get_client_class();
$client = new $client_class(); /* @var OAuth_API_Client $client */
//load user access token
if( $user_id !== false ) {
if ( empty($user_id) ) $user_id = get_current_user_id();
$client->load_token( $user_id, $api_user_id );
}
return $client;
}
public static function get_user_tokens( $user_id = false ){
if( static::$authorization_scope !== 'user' ) return array();
if( empty($user_id) ) $user_id = get_current_user_id();
$user_tokens = get_user_meta( $user_id, static::$option_dataset.'_'.static::$option_name, true );
if( empty($user_tokens) ) $user_tokens = array();
return $user_tokens;
}
/**
* @return array[OAuth_API_Token]
*/
public static function get_site_tokens(){
if( static::$authorization_scope !== 'site' ) return array();
$site_tokens = EM_Options::get(static::$option_name.'_token', array(), static::$option_dataset);
if( empty($site_tokens) ) $site_tokens = array();
return $site_tokens;
}
/**
* Includes and calls the code required to handle a callback from FB to store user auth token.
*/
public static function oauth_authorize() {
global $EM_Notices;
if( !empty($EM_Notices) ) $EM_Notices = new EM_Notices();
if( !empty($_REQUEST['code']) ){
try{
$client = static::get_client(false);
if( $client->oauth_state && (empty($_REQUEST['state']) || !wp_verify_nonce( $_REQUEST['state'], static::$option_name.'_authorize')) ){
$EM_Notices->add_error( sprintf( esc_html__( 'There was an error connecting to %s: %s', 'events-manager' ), static::$service_name, '<code>No State Provided</code>'), true );
}else{
try {
$client->request( $_REQUEST['code'] );
$EM_Notices->add_confirm( sprintf( esc_html__( 'Your account has been successfully connected with %s!', 'events-manager' ), static::$service_name ), true);
} catch ( EM_Exception $e ){
$EM_Notices->add_error( sprintf( esc_html__( 'There was an error connecting to %s: %s', 'events-manager' ), static::$service_name, '<code>'.$e->getMessage().'</code>' ), true );
}
}
} catch ( EM_Exception $ex ){
$EM_Notices->add_error($ex->get_messages(), true);
}
}else{
$EM_Notices->add_error( sprintf( esc_html__( 'There was an error connecting to %s: %s', 'events-manager' ), static::$service_name, '<code>No Authorization Code Provided</code>'), true );
}
// Redirect to settings page
$query_args = array( 'page' => 'events-manager-options' );
$url = add_query_arg( $query_args, admin_url( 'admin.php' ) );
wp_redirect( $url );
die();
}
/**
* Handles disconnecting a user from one or all their connected Google accounts, attempting to revoke their key in the process.
*/
public static function oauth_disconnect(){
global $EM_Notices;
if( !empty($EM_Notices) ) $EM_Notices = new EM_Notices();
if( static::$authorization_scope == 'user' ){
$account_tokens = static::get_user_tokens();
}else{
$account_tokens = static::get_site_tokens();
}
$accounts_to_disconnect = array();
if( empty($_REQUEST['user']) && !empty($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'em-oauth-'. static::$option_name .'-disconnect') ){
$accounts_to_disconnect = array_keys($account_tokens);
}elseif( !empty($_REQUEST['account']) && !empty($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'em-oauth-'. static::$option_name .'-disconnect-'.$_REQUEST['account']) ){
if( !empty($account_tokens[$_REQUEST['account']]) ){
$accounts_to_disconnect[] = $_REQUEST['account'];
}
}else{
$EM_Notices->add_error('Missing nonce, please contact your administrator.', true);
}
if( !empty($accounts_to_disconnect) ){
$errors = $disconnected_accounts = array();
foreach( $accounts_to_disconnect as $account_id ){
try{
$client = static::get_client( get_current_user_id(), $account_id);
$client->revoke();
} catch ( EM_Exception $ex ){
$account_name = !empty( $client->token->email ) ? $client->token->email : $client->token->name;
$errors[] = "<em>$account_name</em> - " . $ex->getMessage();
} finally{
$disconnected_accounts[] = $account_id;
unset($account_tokens[$account_id]);
}
}
if( !empty($disconnected_accounts) ){
if( static::$authorization_scope == 'user' ){
if( empty($account_tokens) ){
delete_user_meta( get_current_user_id(), 'em_oauth_'.static::$option_name );
}else{
update_user_meta( get_current_user_id(), 'em_oauth_'.static::$option_name, $account_tokens );
}
}else{
EM_Options::set(static::$option_name.'_token', $account_tokens, static::$option_dataset);
}
$success = _n('You have successfully disconnected from your %s account.', 'You have successfully disconnected from your %s accounts.', count($accounts_to_disconnect), 'events-manager');
$EM_Notices->add_confirm(sprintf($success, static::$service_name), true);
}
if( !empty($errors) ){
$error_msg = sprintf( esc_html__('There were some issues whilst disconnecting from your %s account(s) :', 'events-manager'), static::$service_name );
array_unshift( $errors, $error_msg );
$EM_Notices->add_error( $errors, true );
}
}
// Redirect to settings page
$query_args = array( 'page' => 'events-manager-options' );
$url = add_query_arg( $query_args, admin_url( 'admin.php' ) );
wp_redirect( $url );
die();
}
}
//include dependents
include('oauth-api-token.php');
include('oauth-api-client.php');
if( is_admin() ){
include('oauth-admin-settings.php');
}
\ No newline at end of file
<?php
/**
* An interface for the dbem_data option stored in wp_options as a serialized array.
* This option can hold various information which can be stored in one record rather than individual records in wp_options.
* The functions in this class deal directly with that dbem_data option as if it was the wp_options table itself, and therefore
* have similarities to the get_option and update_option functions.
* @since 5.8.2.0
*
*/
class EM_Options {
/**
* Get a specific setting form the EM options array. If no value is set, an empty array is provided by default.
* @param string $option_name
* @param mixed $default the default value to return
* @param string $dataset
* @param boolean $site if set to true it'll retrieve a site option in MultiSite instead
* @return mixed
*/
public static function get( $option_name, $default = array(), $dataset = 'dbem_data', $site = false ){
$data = $site ? get_site_option($dataset) : get_option($dataset);
if( isset($data[$option_name]) ){
return $data[$option_name];
}else{
return $default;
}
}
/**
* Set a value in the EM options array. Returns result of storage, which may be false if no changes are made.
* @param string $option_name
* @param mixed $option_value
* @param string $dataset
* @param boolean $site if set to true it'll retrieve a site option in MultiSite instead
* @return boolean
*/
public static function set( $option_name, $option_value, $dataset = 'dbem_data', $site = false ){
$data = $site ? get_site_option($dataset) : get_option($dataset);
if( empty($data) ) $data = array();
$data[$option_name] = $option_value;
return $site ? update_site_option($dataset, $data) : update_option($dataset, $data);
}
/**
* Adds a value to an specific key in the EM options array, and assumes the option name is an array.
* Returns true on success or false saving failed or if no changes made.
* @param string $option_name
* @param string $option_key
* @param mixed $option_value
* @param string $dataset
* @param boolean $site
* @return boolean
*/
public static function add( $option_name, $option_key, $option_value, $dataset = 'dbem_data', $site = false ){
$data = $site ? get_site_option($dataset) : get_option($dataset);
if( empty($data[$option_name]) ){
$data[$option_name] = array( $option_key => $option_value );
}else{
$data[$option_name][$option_key] = $option_value;
}
return $site ? update_site_option($dataset, $data) : update_option($dataset, $data);
}
/**
* Removes an item from an array in the EM options array, it assumes the supplied option name is an array.
*
* @param string $option_name
* @param string $option_key
* @param string $dataset
* @param boolean $site
* @return boolean
*/
public static function remove( $option_name, $option_key, $dataset = 'dbem_data', $site = false ){
$data = $site ? get_site_option($dataset) : get_option($dataset);
if( !empty($data[$option_name][$option_key]) ){
unset($data[$option_name][$option_key]);
if( empty($data[$option_name]) ) unset($data[$option_name]);
return $site ? update_site_option($dataset, $data) : update_option($dataset, $data);
}
return false;
}
/**
* @see EM_Options::get()
* @param string $option_name
* @param mixed $default
* @param string $dataset
* @return boolean
*/
public static function site_get( $option_name, $default = array(), $dataset = 'dbem_data' ){
return self::get( $option_name, $default, $dataset, true );
}
/**
* @see EM_Options::set()
* @param string $option_name
* @param mixed $option_value
* @param string $dataset
* @return boolean
*/
public static function site_set( $option_name, $option_value, $dataset = 'dbem_data' ){
return self::set( $option_name, $option_value, $dataset, true );
}
/**
* @see EM_Options::add()
* @param string $option_name
* @param string $option_key
* @param mixed $option_value
* @param string $dataset
* @return boolean
*/
public static function site_add( $option_name, $option_key, $option_value, $dataset = 'dbem_data' ){
return self::add( $option_name, $option_key, $option_value, $dataset, true );
}
/**
* @see EM_Options::remove()
* @param string $option_name
* @param string $option_key
* @param string $dataset
* @return boolean
*/
public static function site_remove( $option_name, $option_key, $dataset = 'dbem_data' ){
return self::remove( $option_name, $option_key, $dataset, true );
}
}
\ No newline at end of file
<?php
class EM_People extends EM_Object {
public static function init(){
add_action('delete_user', 'EM_People::delete_user', 10, 1);
add_filter( 'user_contactmethods', 'EM_People::user_contactmethods', 10, 1);
add_filter('pre_option_dbem_bookings_registration_user', 'EM_People::dbem_bookings_registration_user');
}
/**
* Handles the action of someone being deleted on WordPress
* @param int $id
*/
public static function delete_user( $id ){
global $wpdb;
//if events are set to be deleted, we hook in correctly already, if they're meant to be reassigned, we only need to update our tables as WP updated theirs
if( !empty($_REQUEST['delete_option']) && $_REQUEST['delete_option'] == 'reassign' && is_numeric($_REQUEST['reassign_user']) ){
$wpdb->update(EM_EVENTS_TABLE, array('event_owner'=>$_REQUEST['reassign_user']), array('event_owner'=>$id));
$wpdb->update(EM_LOCATIONS_TABLE, array('location_owner'=>$_REQUEST['reassign_user']), array('location_owner'=>$id));
}else{
//We delete all the events and locations owned by this user
foreach( EM_Events::get( array('owner'=>$id, 'status'=>'everything') ) as $EM_Event ) $EM_Event->delete();
foreach( EM_Locations::get( array('owner'=>$id, 'status'=>'everything', 'ids_only'=>true) ) as $EM_Location ) $EM_Location->delete();
}
//delete their bookings completely
//@TODO allow option to reassign bookings in a sensible way (i.e. handle personal data being transferred)
$EM_Person = new EM_Person();
$EM_Person->ID = $EM_Person->person_id = $id;
foreach( $EM_Person->get_bookings() as $EM_Booking){
$EM_Booking->manage_override = true;
$EM_Booking->delete();
}
}
/**
* Adds phone number to contact info of users, compatible with previous phone field method
* @param $array
* @return array
*/
public static function user_contactmethods($array){
$array['dbem_phone'] = __('Phone','events-manager') . ' <span class="description">('. __('Events Manager','events-manager') .')</span>';
return $array;
}
/**
* Workaround function for any legacy code requesting the dbem_bookings_registration_user option which should always be 0
* @return int
*/
public static function dbem_bookings_registration_user(){
return 0;
}
}
EM_People::init();
?>
\ No newline at end of file
<?php
// TODO make person details more secure and integrate with WP user data
class EM_Person extends WP_User{
public $custom_user_fields = array();
function __construct( $person_id = false, $username = '', $blog_id='' ){
if( is_array($person_id) ){
if( array_key_exists('person_id',$person_id) ){
$person_id = $person_id['person_id'];
}elseif ( array_key_exists('user_id',$person_id) ){
$person_id = $person_id['user_id'];
}else{
$person_id = $person_id['ID'];
}
}elseif( is_object($person_id) && get_class($person_id) == 'WP_User'){
$person_id = $person_id->ID; //create new object if passed a wp_user
}
if($username){
parent::__construct($person_id, $username);
}elseif( is_numeric($person_id) && $person_id == 0 ){
$this->data = new stdClass();
$this->ID = 0;
$this->display_name = 'Anonymous User';
$this->user_email = 'anonymous@'.preg_replace('/https?:\/\//', '', get_site_url());
}else{
parent::__construct($person_id);
}
$this->phone = get_metadata('user', $this->ID, 'dbem_phone', true); //extra field for EM
do_action('em_person',$this, $person_id, $username);
}
function get_bookings($ids_only = false, $status= false){
global $wpdb;
$status_condition = $blog_condition = '';
if( is_multisite() ){
if( !is_main_site() ){
//not the main blog, force single blog search
$blog_condition = "AND e.blog_id=".get_current_blog_id();
}elseif(is_main_site() && !get_option('dbem_ms_global_events')){
$blog_condition = "AND (e.blog_id=".get_current_blog_id().' OR e.blog_id IS NULL)';
}
}
if( is_numeric($status) ){
$status_condition = " AND booking_status=$status";
}elseif( EM_Object::array_is_numeric($status) ){
$status_condition = " AND booking_status IN (".implode(',', $status).")";
}
$EM_Booking = em_get_booking(); //empty booking for fields
$results = $wpdb->get_results("SELECT b.".implode(', b.', array_keys($EM_Booking->fields))." FROM ".EM_BOOKINGS_TABLE." b, ".EM_EVENTS_TABLE." e WHERE e.event_id=b.event_id AND person_id={$this->ID} {$blog_condition} {$status_condition} ORDER BY ".get_option('dbem_bookings_default_orderby','event_start_date')." ".get_option('dbem_bookings_default_order','ASC'),ARRAY_A);
$bookings = array();
if($ids_only){
foreach($results as $booking_data){
$bookings[] = $booking_data['booking_id'];
}
return apply_filters('em_person_get_bookings', $bookings, $this);
}else{
foreach($results as $booking_data){
$bookings[] = em_get_booking($booking_data);
}
return apply_filters('em_person_get_bookings', new EM_Bookings($bookings), $this);
}
}
/**
* @return EM_Events
*/
function get_events(){
global $wpdb;
$events = array();
foreach( $this->get_bookings()->get_bookings() as $EM_Booking ){
$events[$EM_Booking->event_id] = $EM_Booking->get_event();
}
return apply_filters('em_person_get_events', $events);
}
function get_bookings_url(){
if( get_option('dbem_edit_bookings_page') && (!is_admin() || !empty($_REQUEST['is_public'])) ){
$my_bookings_page = get_permalink(get_option('dbem_edit_bookings_page'));
$bookings_link = em_add_get_params($my_bookings_page, array('person_id'=>$this->ID, 'event_id'=>null, 'ticket_id'=>null, 'booking_id'=>null), false);
}else{
$bookings_link = EM_ADMIN_URL. "&page=events-manager-bookings&person_id=".$this->ID;
}
return apply_filters('em_person_get_bookings_url', $bookings_link, $this);
}
function display_summary(){
ob_start();
?>
<table class="em-form-fields">
<tr>
<td><?php echo get_avatar($this->ID); ?></td>
<td style="padding-left:10px; vertical-align: top;">
<table>
<?php if( $this->ID === 0 ): ?>
<tr><th><?php _e('Name','events-manager'); ?> : </th><th><?php echo $this->get_name(); ?></th></tr>
<?php else: ?>
<tr><th><?php _e('Name','events-manager'); ?> : </th><th><a href="<?php echo $this->get_bookings_url(); ?>"><?php echo $this->get_name(); ?></a></th></tr>
<?php endif; ?>
<tr><th><?php _e('Email','events-manager'); ?> : </th><td><?php echo $this->user_email; ?></td></tr>
<tr><th><?php _e('Phone','events-manager'); ?> : </th><td><?php echo esc_html($this->phone); ?></td></tr>
</table>
</td>
</tr>
</table>
<?php
return apply_filters('em_person_display_summary', ob_get_clean(), $this);
}
function get_summary(){
$summary = array(
'user_name' => array('name' => __('Name','events-manager'), 'value' => $this->get_name()),
'user_email' => array('name' => __('Email','events-manager'), 'value' => $this->user_email),
'dbem_phone' => array('name' => __('Phone','events-manager'), 'value' => $this->phone),
);
$summary = array_merge( $summary, $this->custom_user_fields );
return apply_filters('em_person_get_summary', $summary, $this);
}
function get_name(){
$full_name = $this->first_name . " " . $this->last_name ;
$full_name = wp_kses_data(trim($full_name));
$name = !empty($full_name) ? $full_name : $this->display_name;
return apply_filters('em_person_get_name', $name, $this);
}
function to_api(){
$person = array(
'id' => $this->ID, // maybe hide this depending on permissions
'name' => $this->get_name(),
'name_first' => $this->first_name,
'name_last' => $this->last_name,
'email' => $this->user_email,
'phone' => $this->phone,
'guest' => $this->ID > 0, // whether person is registered or not
);
$person = array_merge( $person, $this->custom_user_fields );
return apply_filters('em_person_to_api', $person);
}
}
?>
\ No newline at end of file
<?php
/**
* A single event tag object. *
*/
class EM_Tag extends EM_Taxonomy_Term {
//static options for EM_Category, but until PHP 5.3 is the WP minimum requirement we'll make them regular properties due to lack of late static binding
public $option_name = 'tag'; //the singular name of this taxonomy which is used in option names consistent across EM taxonomies
public $taxonomy = 'EM_TAXONOMY_TAG';
/**
* Necessary to supply the $class_name until late static binding is reliably available on all WP sites running PHP 5.3
* @param string $id
* @param string $class_name
* @return EM_Taxonomy
*/
public static function get( $id, $class_name = 'EM_Tag' ){
return parent::get($id, $class_name);
}
public function can_manage( $capability_owner = 'edit_event_tags', $capability_admin = false, $user_to_check = false ){
return parent::can_manage($capability_owner, $capability_admin, $user_to_check);
}
}
/**
* Get an category in a db friendly way, by checking globals and passed variables to avoid extra class instantiations
* @param mixed $id
* @return EM_Category
* @uses EM_Tag::get()
*/
function em_get_tag( $id ) {
return EM_Tag::get($id);
}
\ No newline at end of file
<?php
/**
* This class extends the EM_Taxonomy_Admin and adds category images and colors to the admin area.
*
* Currently, all functions here serve the purpose of getting around lack of late static binding in PHP < 5.3.
* Eventually when PHP 5.3 is enforced only certain class properties need to be defined for use in the parent class via static::
*
*/
class EM_Tags_Admin extends EM_Taxonomy_Admin{
public static $taxonomy_name = 'EM_TAXONOMY_TAG'; //converted into a constant value during init()
public static $this_class = 'EM_Tags_Admin'; //needed until 5.3 minimum is enforced for late static binding
public static $tax_class = 'EM_Tag';
public static $option_name = 'tag';
public static $name_singular = 'tag';
public static $name_plural = 'tags';
public static $placeholder_image = '#_TAGIMAGE';
public static $placeholder_color = '#_TAGCOLOR';
public static function init(){
self::$taxonomy_name = EM_TAXONOMY_TAG;
self::static_binding();
parent::init();
}
public static function form_add(){
self::static_binding();
parent::form_add();
}
public static function form_edit($tag){
self::static_binding();
parent::form_edit($tag);
}
public static function save( $term_id, $tt_id ){
self::static_binding();
parent::save( $term_id, $tt_id );
}
public static function delete( $term_id ){
self::static_binding();
parent::delete( $term_id );
}
/**
* Temporary function until WP requires PHP 5.3, so that we can make use of late static binding.
* Until then, all functions needing LST should run this function before calling the parent. If all extending classes do this we shouldn't have a problem.
*/
public static function static_binding(){
EM_Taxonomy_Admin::$taxonomy_name = self::$taxonomy_name;
EM_Taxonomy_Admin::$this_class = self::$this_class;
EM_Taxonomy_Admin::$tax_class = self::$tax_class;
EM_Taxonomy_Admin::$option_name = self::$option_name;
EM_Taxonomy_Admin::$name_singular = self::$name_singular;
EM_Taxonomy_Admin::$name_plural = self::$name_plural;
EM_Taxonomy_Admin::$placeholder_image = self::$placeholder_image;
EM_Taxonomy_Admin::$placeholder_color = self::$placeholder_color;
}
}
add_action('admin_init',array('EM_Tags_Admin','init'));
\ No newline at end of file
<?php
class EM_Tags_Frontend extends EM_Taxonomy_Frontend {
public static $taxonomy_name = 'event-tag'; //converted into a constant value during init()
public static $this_class = 'EM_Tags_Frontend'; //needed until 5.3 minimum is enforced for late static binding
public static $tax_class = 'EM_Tag';
public static $option_name = 'tag';
public static $option_name_plural = 'tags';
public static function init(){
self::$taxonomy_name = EM_TAXONOMY_TAG; //awaiting LSB in PHP 5.3
self::static_binding();
parent::init();
}
//These following functions can be removed when PHP 5.3 is minimum and LSB is available
public static function template($template = ''){
self::static_binding();
return parent::template($template);
}
public static function the_content($content){
self::static_binding();
return parent::the_content($content);
}
public static function parse_query( $wp_query ){
//we do some double-checking here to prevent running self::static_binding() during the self::template() function when WP_Query is called.
if( !$wp_query->is_main_query() ) return;
if( $wp_query->is_tax(self::$taxonomy_name) || !empty($wp_query->{'em_'.self::$option_name.'_id'}) ){
self::static_binding();
return parent::parse_query( $wp_query );
}
}
public static function wpseo_breadcrumb_links( $links ){
self::static_binding();
return parent::wpseo_breadcrumb_links( $links );
}
/**
* Temporary function until WP requires PHP 5.3, so that we can make use of late static binding.
* Until then, all functions needing LST should run this function before calling the parent. If all extending classes do this we shouldn't have a problem.
*/
public static function static_binding(){
EM_Taxonomy_Frontend::$taxonomy_name = self::$taxonomy_name;
EM_Taxonomy_Frontend::$this_class = self::$this_class;
EM_Taxonomy_Frontend::$tax_class = self::$tax_class;
EM_Taxonomy_Frontend::$option_name = self::$option_name;
EM_Taxonomy_Frontend::$option_name_plural = self::$option_name_plural;
}
}
class EM_Tag_Taxonomy extends EM_Tags_Frontend {} //backwards compatibility
EM_Tags_Frontend::init();
\ No newline at end of file
<?php
class EM_Tags extends EM_Taxonomy_Terms {
//Overridable functions
protected $taxonomy = 'event-tags';
protected $meta_key = 'event-tags';
protected $terms_name = 'tags';
protected $term_class = 'EM_Tag';
protected $ajax_search_action = 'search_tags';
/**
* Creates an EM_Tags instance, currently accepts an EM_Event object (gets all Categories for that event) or array of any EM_Category objects, which can be manipulated in bulk with helper functions.
* @param mixed $data
* @return null
*/
public function __construct( $data = false ){
$this->taxonomy = EM_TAXONOMY_TAG;
parent::__construct($data);
}
/**
* Legacy get overload for any use of $EM_Tags->tags
* @param string $var_name
* @return array|NULL
*/
public function __get( $var_name ){
if( $var_name == 'tags' ){
return $this->terms;
}
return null;
}
/**
* Legacy overload for use of empty($this->tags)
* @param string $prop
* @return boolean
*/
function __isset( $prop ){
if( $prop == 'tags' ){
return !empty($this->terms);
}
return parent::__isset( $prop );
}
//Functions we won't need when PHP 5.3 minimum allows for use of LSB
public static function get( $args = array() ){
self::$instance = new EM_Tags();
return parent::get($args);
}
public static function output( $args = array() ){
self::$instance = new EM_Tags();
return parent::output($args);
}
public static function get_pagination_links($args, $count, $search_action = 'search_tags', $default_args = array()){
self::$instance = new EM_Tags();
return parent::get_pagination_links($args, $count, $search_action, $default_args);
}
public static function get_post_search($args = array(), $filter = false, $request = array(), $accepted_args = array()){
self::$instance = new EM_Tags();
return parent::get_post_search($args, $filter, $request, $accepted_args);
}
public static function get_default_search( $array_or_defaults = array(), $array = array() ){
self::$instance = new EM_Tags();
return parent::get_default_search($defaults,$array);
}
}
\ No newline at end of file
<?php
/**
* Base class for taxonomies, adding extra features to the admin area such as displaying and saving image and color options.
*
* Classes extending this one must define the right
*/
class EM_Taxonomy_Admin {
/**
* The name of this taxonomy, e.g. event-categories, which is defined in child class.
* @var string
*/
public static $taxonomy_name;
/**
* The name of the child class, used for now whilst late static binding isn't guaranteed since we may be running on PHP <5.3
* Once PHP 5.3 is a minimum requirement in WP, we can get rid of this one.
* @var string
*/
public static $this_class = 'EM_Taxonomy_Admin';
/**
* Currently used to instantiate a class of the specific term. Eventually we could just use EM_Taxonomy since these will be standardized functions for any taxonomy.
* @var string
*/
public static $tax_class = 'EM_Taxonomy';
/**
* Name of taxonomy for reference in saving to database, e.g. category will be used to save category-image.
* This may differ from the name of the taxonomy, such as event-category can be category
* @var string
*/
public static $option_name = 'taxonomy';
public static $name_singular = 'taxonomy';
public static $name_plural = 'taxonomies';
public static $placeholder_image = '#_TAXONOMYIMAGE';
public static $placeholder_color = '#_TAXONOMYCOLOR';
public static function init(){
global $pagenow;
if( ($pagenow == 'edit-tags.php' || $pagenow == 'term.php') && !empty($_GET['taxonomy']) && $_GET['taxonomy'] == self::$taxonomy_name){
add_filter('admin_enqueue_scripts', 'EM_Taxonomy_Admin::admin_enqueue_scripts');
}
add_action( self::$taxonomy_name.'_edit_form_fields', array(self::$this_class, 'form_edit'), 10, 1);
add_action( self::$taxonomy_name.'_add_form_fields', array(self::$this_class, 'form_add'), 10, 1);
add_action( 'edited_'.self::$taxonomy_name, array(self::$this_class, 'save'), 10, 2);
add_action( 'create_'.self::$taxonomy_name, array(self::$this_class, 'save'), 10, 2);
add_action( 'delete_'.self::$taxonomy_name, array(self::$this_class, 'delete'), 10, 2);
add_filter('manage_edit-'.self::$taxonomy_name.'_columns' , array(self::$this_class, 'columns_add'));
add_filter('manage_'.self::$taxonomy_name.'_custom_column' , array(self::$this_class, 'columns_output'),10,3);
}
public static function columns_add($columns) {
//prepend ID after checkbox
$columns['term-id'] = __('ID','events-manager');
return $columns;
}
public static function columns_output( $val, $column, $term_id ) {
switch ( $column ) {
case 'term-id':
return $term_id;
break;
}
return $val;
}
public static function admin_enqueue_scripts(){
wp_enqueue_media();
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'em-taxonomies-admin', plugins_url().'/events-manager/includes/js/taxonomies-admin.js', array('jquery','media-upload','thickbox','farbtastic','wp-color-picker') );
}
public static function form_edit($tag){
$EM_Taxonomy = new self::$tax_class($tag);
$taxonomy_color = $EM_Taxonomy->get_color();
$taxonomy_image = $EM_Taxonomy->get_image_url();
$taxonomy_image_id = $EM_Taxonomy->get_image_id();
?>
<tr class="form-field term-color-wrap">
<th scope="row" valign="top"><label for="term-color"><?php esc_html_e('Color','events-manager'); ?></label></th>
<td>
<input type="text" name="term_color" id="term-color" class="term-color" value="<?php echo esc_attr($taxonomy_color); ?>" /><br />
<p class="description"><?php echo sprintf(__('Choose a color for your %s. You can access this using the %s placeholder.','events-manager'), __(self::$name_singular, 'events-manager'), '<code>'. self::$placeholder_color. '</code>'); ?></p>
<div id="picker" style="position:absolute; display:none; background:#DEDEDE"></div>
</td>
</tr>
<tr class="form-field term-image-wrap">
<th scope="row" valign="top"><label for="term-image"><?php esc_html_e('Image','events-manager'); ?></label></th>
<td>
<div class="img-container">
<?php if( !empty($taxonomy_image) ): ?>
<img src="<?php echo $taxonomy_image; ?>" />
<?php endif; ?>
</div>
<input type="text" name="term_image" id="term-image" class="img-url" value="<?php echo esc_attr($taxonomy_image); ?>" />
<input type="hidden" name="term_image_id" id="term-image-id" class="img-id" value="<?php echo esc_attr($taxonomy_image_id); ?>" />
<p class="hide-if-no-js">
<input id="upload_image_button" type="button" value="<?php _e('Choose/Upload Image','events-manager'); ?>" class="upload-img-button button-secondary" />
<input id="delete_image_button" type="button" value="<?php _e('Remove Image','events-manager'); ?>" class="delete-img-button button-secondary" <?php if( empty($taxonomy_image) ) echo 'style="display:none;"'; ?> />
</p>
<br />
<p class="description"><?php echo sprintf(__('Choose an image for your %s, which can be displayed using the %s placeholder.','events-manager'), __(self::$name_singular,'events-manager'),'<code>'. self::$placeholder_image. '</code>'); ?></p>
</td>
</tr>
<?php
}
public static function form_add(){
?>
<div class="term-color-wrap">
<label for="term-color"><?php esc_html_e('Color','events-manager'); ?></label>
<input type="text" name="term_color" id="term-color" class="term-color" value="#FFFFFF" /><br />
<p class="description"><?php echo sprintf(__('Choose a color for your %s. You can access this using the %s placeholder.','events-manager'), __(self::$name_singular,'events-manager'),'<code>'. self::$placeholder_color. '</code>'); ?></p>
</div>
<div class="form-field term-image-wrap">
<label for="term-image"><?php esc_html_e('Image','events-manager'); ?></label>
<div class="img-container"></div>
<input type="text" name="term_image" id="term-image" class="img-url" value="" />
<input type="hidden" name="term_image_id" id="term-image-id" class="img-id" value="" />
<p class="hide-if-no-js">
<input id="upload_image_button" type="button" value="<?php _e('Choose/Upload Image','events-manager'); ?>" class="upload-img-button button-secondary" />
<input id="delete_image_button" type="button" value="<?php _e('Remove Image','events-manager'); ?>" class="delete-img-button button-secondary" style="display:none;" />
</p>
<p class="description"><?php echo sprintf(__('Choose an image for your %s, which can be displayed using the %s placeholder.','events-manager'), __(self::$name_singular,'events-manager'),'<code>'. self::$placeholder_image. '</code>'); ?></p>
</div>
<?php
}
public static function save( $term_id, $tt_id ){
global $wpdb;
if (!$term_id) return;
if( !empty($_POST['term_color']) ){
//get results and save/update
$color = sanitize_hex_color($_POST['term_color']);
if( $color ){
$prev_settings = $wpdb->get_results('SELECT meta_value FROM '.EM_META_TABLE." WHERE object_id='{$term_id}' AND meta_key='". self::$option_name ."-bgcolor'");
if( count($prev_settings) > 0 ){
$wpdb->update(EM_META_TABLE, array('object_id' => $term_id, 'meta_value' => $color), array('object_id' => $term_id, 'meta_key' => self::$option_name .'-bgcolor'));
}else{
$wpdb->insert(EM_META_TABLE, array('object_id' => $term_id, 'meta_key' => self::$option_name .'-bgcolor', 'meta_value' => $color));
}
}
}
if( !empty($_POST['term_image']) ){
//get results and save/update
$term_image = esc_url_raw($_POST['term_image']);
$prev_settings = $wpdb->get_results('SELECT meta_value FROM '.EM_META_TABLE." WHERE object_id='{$term_id}' AND meta_key='". self::$option_name ."-image'");
if( count($prev_settings) > 0 ){
$wpdb->update(EM_META_TABLE, array('object_id' => $term_id, 'meta_value' => $term_image), array('object_id' => $term_id, 'meta_key' => self::$option_name .'-image'));
}else{
$wpdb->insert(EM_META_TABLE, array('object_id' => $term_id, 'meta_key' => self::$option_name .'-image', 'meta_value' => $term_image));
}
if( !empty($_POST['term_image_id']) && is_numeric($_POST['term_image_id']) ){
//get results and save/update
$term_image_id = absint($_POST['term_image_id']);
$prev_settings = $wpdb->get_results('SELECT meta_value FROM '.EM_META_TABLE." WHERE object_id='{$term_id}' AND meta_key='". self::$option_name ."-image-id'");
if( count($prev_settings) > 0 ){
$wpdb->update(EM_META_TABLE, array('object_id' => $term_id, 'meta_value' => $term_image_id), array('object_id' => $term_id, 'meta_key'=> self::$option_name .'-image-id'));
}else{
$wpdb->insert(EM_META_TABLE, array('object_id' => $term_id, 'meta_key'=> self::$option_name .'-image-id', 'meta_value' => $term_image_id));
}
}
}else{
//check if an image exists, if so remove association
$prev_settings = $wpdb->get_results('SELECT meta_value FROM '.EM_META_TABLE." WHERE object_id='{$term_id}' AND meta_key='". self::$option_name ."-image'");
if( count($prev_settings) > 0 ){
$wpdb->delete(EM_META_TABLE, array('object_id' => $term_id, 'meta_key' => self::$option_name .'-image'));
$wpdb->delete(EM_META_TABLE, array('object_id' => $term_id, 'meta_key' => self::$option_name .'-image-id'));
}
}
}
public static function delete( $term_id ){
global $wpdb;
//delete taxonomy image and color
$wpdb->query('DELETE FROM '.EM_META_TABLE." WHERE object_id='$term_id' AND (meta_key='". self::$option_name ."-image' OR meta_key='". self::$option_name ."-image-id' OR meta_key='". self::$option_name ."-bgcolor')");
//delete all events taxonomy relations for MultiSite Global Mode
if( EM_MS_GLOBAL ){
$wpdb->query('DELETE FROM '.EM_META_TABLE." WHERE meta_value='{$term_id}' AND meta_key='event-". self::$option_name ."'");
}
}
}
\ No newline at end of file
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.