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