WordPress.org

Plugin Directory

Changeset 1720802


Ignore:
Timestamp:
08/28/17 19:26:43 (4 weeks ago)
Author:
netweblogic
Message:

5.7.3.2 (dev)

Location:
events-manager/trunk
Files:
8 added
6 deleted
43 edited

Legend:

Unmodified
Added
Removed
  • events-manager/trunk/admin/bookings/em-events.php

    r1651260 r1720802  
    3737    } 
    3838    $owner = !current_user_can('manage_others_bookings') ? get_current_user_id() : false; 
    39     $events = EM_Events::get( array('scope'=>$scope, 'limit'=>$limit, 'offset' => $offset, 'order'=>$order, 'bookings'=>true, 'owner' => $owner ) ); 
    40     $events_count = EM_Events::count( array('scope'=>$scope, 'limit'=>0, 'order'=>$order, 'bookings'=>true, 'owner' => $owner ) ); 
     39    $events = EM_Events::get( array('scope'=>$scope, 'limit'=>$limit, 'offset' => $offset, 'order'=>$order, 'bookings'=>true, 'owner' => $owner, 'pagination' => 1 ) ); 
     40    $events_count = EM_Events::$num_rows_found; 
    4141     
    4242    $use_events_end = get_option ( 'dbem_use_event_end' ); 
  • events-manager/trunk/admin/em-admin.php

    r1651260 r1720802  
    88        $bookings_pending_count = apply_filters('em_bookings_pending_count',0); 
    99        if( get_option('dbem_bookings_approval') == 1){  
    10             $bookings_pending_count += count(EM_Bookings::get(array('status'=>'0', 'blog'=>get_current_blog_id()))->bookings); 
     10            $bookings_pending_count += EM_Bookings::count(array('status'=>'0', 'blog'=>get_current_blog_id())); 
    1111        } 
    1212        if($bookings_pending_count > 0){ 
     
    174174        } 
    175175     
    176         if( is_multisite() && !empty($_REQUEST['page']) && $_REQUEST['page']=='events-manager-options' && is_super_admin() && get_option('dbem_ms_update_nag') ){ 
     176        if( is_multisite() && !empty($_REQUEST['page']) && $_REQUEST['page']=='events-manager-options' && em_wp_is_super_admin() && get_option('dbem_ms_update_nag') ){ 
    177177            if( !empty($_GET['disable_dbem_ms_update_nag']) ){ 
    178178                delete_site_option('dbem_ms_update_nag'); 
     
    186186        } 
    187187         
    188         if( is_super_admin() && get_option('dbem_migrate_images_nag') ){ 
     188        if( em_wp_is_super_admin() && get_option('dbem_migrate_images_nag') ){ 
    189189            if( !empty($_GET['disable_dbem_migrate_images_nag']) ){ 
    190190                delete_site_option('dbem_migrate_images_nag'); 
  • events-manager/trunk/admin/em-docs.php

    r1694715 r1720802  
    175175                            '#_EVENTICALURL' => array( 'desc' => 'Displays the URL of the event ical feed (ics file format).' ), 
    176176                            '#_EVENTICALLINK' => array( 'desc' => 'Displays an html link to the event ical feed (ics file format).' ), 
     177                            '#_EVENTICALURL' => array( 'desc' => 'Displays the URL of the event webcal feed (ical/ics file format) which will open up various calendar apps automatically including iCalendar, Outlook and Google Calendar.' ), 
     178                            '#_EVENTICALLINK' => array( 'desc' => 'Displays an html link to the event webcal feed (ical/ics file format),  which will open up various calendar apps automatically including iCalendar, Outlook and Google Calendar.' ), 
    177179                            '#_EVENTGCALURL' => array( 'desc' => 'Displays URL which would take the user to Google Calendar and pre-fill their add new event form.' ), 
    178180                            '#_EVENTGCALLINK' => array( 'desc' => 'Displays a button which would take the user to Google Calendar and pre-fill their add new event form.' ) 
     
    205207                    'iCal/RSS Feeds' => array( 
    206208                        'placeholders' => array( 
    207                             '#_CATEGORYICALURL' => array( 'desc' => 'Displays the URL of the event ical feed (ics file format) which shows all events happening in this category.', 'since'=>'5.5.2' ), 
    208                             '#_CATEGORYICALLINK' => array( 'desc' => 'Displays an html link to the event ical feed (ics file format) which shows all events happening in this category.', 'since'=>'5.5.2' ), 
     209                            '#_CATEGORYICALURL' => array( 'desc' => 'Displays the URL of the event ical feed (ics file format) which shows all events with this category.', 'since'=>'5.5.2' ), 
     210                            '#_CATEGORYICALLINK' => array( 'desc' => 'Displays an html link to the event ical feed (ics file format) which shows all events with this category.', 'since'=>'5.5.2' ), 
     211                            '#_CATEGORYWEBCALURL' => array( 'desc' => 'Displays the URL of the event webcal feed (ical/ics file format) which shows all events with this category.', 'since'=>'5.8' ), 
     212                            '#_CATEGORYWEBCALLINK' => array( 'desc' => 'Displays an html link to the event webcal feed (ical/ics file format) which shows all events with this category.' , 'since'=>'5.8'), 
    209213                            '#_CATEGORYRSSURL' => array( 'desc' => 'Displays the URL of an RSS feed showing all upcoming events happening in this category.', 'since'=>'5.5.2' ), 
    210214                            '#_CATEGORYRSSLINK' => array( 'desc' => 'Displays an html link to an RSS feed showing all upcoming events happening in this category.', 'since'=>'5.5.2' ) 
     
    237241                    'iCal/RSS Feeds' => array( 
    238242                        'placeholders' => array( 
    239                             '#_TAGICALURL' => array( 'desc' => 'Displays the URL of the event ical feed (ics file format) which shows all events happening in this tag.', 'since'=>'5.5.2' ), 
    240                             '#_TAGICALLINK' => array( 'desc' => 'Displays an html link to the event ical feed (ics file format) which shows all events happening in this tag.' , 'since'=>'5.5.2'), 
     243                            '#_TAGICALURL' => array( 'desc' => 'Displays the URL of the event ical feed (ics file format) which shows all events with this tag.', 'since'=>'5.5.2' ), 
     244                            '#_TAGICALLINK' => array( 'desc' => 'Displays an html link to the event ical feed (ics file format) which shows all events with this tag.' , 'since'=>'5.5.2'), 
     245                            '#_TAGWEBCALURL' => array( 'desc' => 'Displays the URL of the event webcal feed (ical/ics file format) which shows all events with this tag.', 'since'=>'5.8' ), 
     246                            '#_TAGWEBCALLINK' => array( 'desc' => 'Displays an html link to the event webcal feed (ical/ics file format) which shows all events with this tag.' , 'since'=>'5.8'), 
    241247                            '#_TAGRSSURL' => array( 'desc' => 'Displays the URL of an RSS feed showing all upcoming events happening in this tag.', 'since'=>'5.5.2' ), 
    242248                            '#_TAGRSSLINK' => array( 'desc' => 'Displays an html link to an RSS feed showing all upcoming events happening in this tag.', 'since'=>'5.5.2' ) 
     
    300306                            '#_LOCATIONICALURL' => array( 'desc' => 'Displays the URL of the location ical feed (ics file format) which shows all events happening at that location.', 'since'=>'5.5.2' ), 
    301307                            '#_LOCATIONICALLINK' => array( 'desc' => 'Displays an html link to the event ical feed (ics file format) which shows all events happening at that location.', 'since'=>'5.5.2' ), 
     308                            '#_LOCATIONWEBCALURL' => array( 'desc' => 'Displays the URL of the location webcal feed (ical/ics file format) which shows all events happening at that location.', 'since'=>'5.8' ), 
     309                            '#_LOCATIONWEBCALLINK' => array( 'desc' => 'Displays an html link to the event webcal feed (ical/ics file format) which shows all events happening at that location.', 'since'=>'5.8' ), 
    302310                            '#_LOCATIONRSSURL' => array( 'desc' => 'Displays the URL of an RSS feed showing all upcoming events happening at this location.', 'since'=>'5.5.2' ), 
    303311                            '#_LOCATIONRSSLINK' => array( 'desc' => 'Displays an html link to an RSS feed showing all upcoming events happening at this location.', 'since'=>'5.5.2' ) 
  • events-manager/trunk/admin/em-options.php

    r1694715 r1720802  
    3232        } 
    3333        //set capabilities 
    34         if( !empty($_POST['em_capabilities']) && is_array($_POST['em_capabilities']) && (!is_multisite() || is_multisite() && is_super_admin()) ){ 
     34        if( !empty($_POST['em_capabilities']) && is_array($_POST['em_capabilities']) && (!is_multisite() || is_multisite() && em_wp_is_super_admin()) ){ 
    3535            global $em_capabilities_array, $wp_roles; 
    3636            if( is_multisite() && is_network_admin() && $_POST['dbem_ms_global_caps'] == 1 ){ 
     
    6868        do_action('em_options_save'); 
    6969        $EM_Notices->add_confirm('<strong>'.__('Changes saved.', 'events-manager').'</strong>', true); 
    70         wp_redirect(em_wp_get_referer()); 
     70        $referrer = em_wp_get_referer(); 
     71        //add tab hash path to url if supplied 
     72        if( !empty($_REQUEST['tab_path']) ){ 
     73            $referrer_array = explode('#', $referrer); 
     74            $referrer = esc_url_raw($referrer_array[0] . '#' . $_REQUEST['tab_path']); 
     75        } 
     76        wp_redirect($referrer); 
    7177        exit(); 
    7278    } 
     
    8591    } 
    8692    //Uninstall 
    87     if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'uninstall' && current_user_can('activate_plugins') && !empty($_REQUEST['confirmed']) && check_admin_referer('em_uninstall_'.get_current_user_id().'_wpnonce') && is_super_admin() ){ 
     93    if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'uninstall' && current_user_can('activate_plugins') && !empty($_REQUEST['confirmed']) && check_admin_referer('em_uninstall_'.get_current_user_id().'_wpnonce') && em_wp_is_super_admin() ){ 
    8894        if( check_admin_referer('em_uninstall_'.get_current_user_id().'_confirmed','_wpnonce2') ){ 
    8995            //We have a go to uninstall 
     
    113119            $wpdb->query('DROP TABLE '.EM_TICKETS_BOOKINGS_TABLE); 
    114120            $wpdb->query('DROP TABLE '.EM_RECURRENCE_TABLE); 
    115             $wpdb->query('DROP TABLE '.EM_CATEGORIES_TABLE); 
    116121            $wpdb->query('DROP TABLE '.EM_META_TABLE); 
    117122             
     
    125130    } 
    126131    //Reset 
    127     if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'reset' && !empty($_REQUEST['confirmed']) && check_admin_referer('em_reset_'.get_current_user_id().'_wpnonce') && is_super_admin() ){ 
     132    if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'reset' && !empty($_REQUEST['confirmed']) && check_admin_referer('em_reset_'.get_current_user_id().'_wpnonce') && em_wp_is_super_admin() ){ 
    128133        if( check_admin_referer('em_reset_'.get_current_user_id().'_confirmed','_wpnonce2') ){ 
    129134            //We have a go to uninstall 
     
    145150    } 
    146151    //Cleanup Event Orphans 
    147     if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'cleanup_event_orphans' && check_admin_referer('em_cleanup_event_orphans_'.get_current_user_id().'_wpnonce') && is_super_admin() ){ 
     152    if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'cleanup_event_orphans' && check_admin_referer('em_cleanup_event_orphans_'.get_current_user_id().'_wpnonce') && em_wp_is_super_admin() ){ 
    148153        //Firstly, get all orphans 
    149154        global $wpdb; 
     
    170175    } 
    171176    //Force Update Recheck - Workaround for now 
    172     if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'recheck_updates' && check_admin_referer('em_recheck_updates_'.get_current_user_id().'_wpnonce') && is_super_admin() ){ 
     177    if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'recheck_updates' && check_admin_referer('em_recheck_updates_'.get_current_user_id().'_wpnonce') && em_wp_is_super_admin() ){ 
    173178        //force recheck of plugin updates, to refresh dl links 
    174179        delete_transient('update_plugins'); 
     
    179184    } 
    180185    //Flag version checking to look at trunk, not tag 
    181     if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'check_devs' && check_admin_referer('em_check_devs_wpnonce') && is_super_admin() ){ 
     186    if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'check_devs' && check_admin_referer('em_check_devs_wpnonce') && em_wp_is_super_admin() ){ 
    182187        //delete transients, and add a flag to recheck dev version next time round 
    183188        delete_transient('update_plugins'); 
     
    189194    } 
    190195    //import EM settings 
    191     if( !empty($_REQUEST['action']) && ( ($_REQUEST['action'] == 'import_em_settings' && check_admin_referer('import_em_settings')) || (is_multisite() && $_REQUEST['action'] == 'import_em_ms_settings' && check_admin_referer('import_em_ms_settings')) ) && is_super_admin() ){ 
     196    if( !empty($_REQUEST['action']) && ( ($_REQUEST['action'] == 'import_em_settings' && check_admin_referer('import_em_settings')) || (is_multisite() && $_REQUEST['action'] == 'import_em_ms_settings' && check_admin_referer('import_em_ms_settings')) ) && em_wp_is_super_admin() ){ 
    192197        //upload uniquely named file to system for usage later 
    193198        if( !empty($_FILES['import_settings_file']['size']) && is_uploaded_file($_FILES['import_settings_file']['tmp_name']) ){ 
     
    218223    } 
    219224    //export EM settings 
    220     if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'export_em_settings' && check_admin_referer('export_em_settings') && is_super_admin() ){ 
     225    if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'export_em_settings' && check_admin_referer('export_em_settings') && em_wp_is_super_admin() ){ 
    221226        global $wpdb; 
    222227        $results = $wpdb->get_results('SELECT option_name, option_value FROM '.$wpdb->options ." WHERE option_name LIKE 'dbem_%' OR option_name LIKE 'emp_%' OR option_name LIKE 'em_%'", ARRAY_A); 
     
    227232        echo json_encode($options); 
    228233        exit(); 
    229     }elseif( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'export_em_ms_settings' && check_admin_referer('export_em_ms_settings') && is_multisite() && is_super_admin() ){ 
     234    }elseif( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'export_em_ms_settings' && check_admin_referer('export_em_ms_settings') && is_multisite() && em_wp_is_super_admin() ){ 
    230235        //delete transients, and add a flag to recheck dev version next time round 
    231236        global $EM_MS_Globals, $wpdb; 
     
    285290 
    286291function em_admin_options_reset_page(){ 
    287     if( check_admin_referer('em_reset_'.get_current_user_id().'_wpnonce') && is_super_admin() ){ 
     292    if( check_admin_referer('em_reset_'.get_current_user_id().'_wpnonce') && em_wp_is_super_admin() ){ 
    288293        ?> 
    289294        <div class="wrap">       
     
    301306} 
    302307function em_admin_options_uninstall_page(){ 
    303     if( check_admin_referer('em_uninstall_'.get_current_user_id().'_wpnonce') && is_super_admin() ){ 
     308    if( check_admin_referer('em_uninstall_'.get_current_user_id().'_wpnonce') && em_wp_is_super_admin() ){ 
    304309        ?> 
    305310        <div class="wrap">       
  • events-manager/trunk/admin/settings/tabs/formats.php

    r1694715 r1720802  
    163163            em_options_radio_binary ( __( 'Show list on day with single event?', 'events-manager'), 'dbem_display_calendar_day_single', __( "By default, if a calendar day only has one event, it display a single event when clicking on the link of that calendar date. If you select Yes here, you will get always see a list of events.",'events-manager') ); 
    164164            ?> 
     165            <tr class="em-header"><td colspan="2"><h4><?php _e('Full-Size Calendar','events-manager'); ?></h4></td></tr> 
     166            <?php 
     167            em_options_input_text ( __( 'Month format', 'events-manager'), 'dbem_full_calendar_month_format', __('The format of the month/year header of the calendar.','events-manager').' '.$date_time_format_tip); 
     168            em_options_input_text ( __( 'Event format', 'events-manager'), 'dbem_full_calendar_event_format', __( 'The format of each event when displayed in the full calendar. Remember to include <code>li</code> tags before and after the event.', 'events-manager').$events_placeholder_tip ); 
     169            em_options_radio_binary( __( 'Abbreviated weekdays?', 'events-manager'), 'dbem_full_calendar_abbreviated_weekdays', __( 'Use abbreviations, e.g. Friday = Fri. Useful for certain languages where abbreviations differ from full names.','events-manager') ); 
     170            em_options_input_text ( __( 'Initial lengths', 'events-manager'), 'dbem_full_calendar_initials_length', __( 'Shorten the calendar headings containing the days of the week, use 0 for the full name.', 'events-manager').$events_placeholder_tip); 
     171            em_options_radio_binary( __( 'Show Long Events?', 'events-manager'), 'dbem_full_calendar_long_events', __( 'Events with multiple dates will appear on each of those dates in the calendar.','events-manager') ); 
     172            ?> 
    165173            <tr class="em-header"><td colspan="2"><h4><?php _e('Small Calendar','events-manager'); ?></h4></td></tr> 
    166174            <?php 
     
    171179            em_options_input_text ( __( 'Initial lengths', 'events-manager'), 'dbem_small_calendar_initials_length', __( 'Shorten the calendar headings containing the days of the week, use 0 for the full name.', 'events-manager').$events_placeholder_tip ); 
    172180            em_options_radio_binary( __( 'Show Long Events?', 'events-manager'), 'dbem_small_calendar_long_events', __( 'Events with multiple dates will appear on each of those dates in the calendar.','events-manager') ); 
    173             ?> 
    174             <tr class="em-header"><td colspan="2"><h4><?php _e('Full Calendar','events-manager'); ?></h4></td></tr> 
    175             <?php 
    176             em_options_input_text ( __( 'Month format', 'events-manager'), 'dbem_full_calendar_month_format', __('The format of the month/year header of the calendar.','events-manager').' '.$date_time_format_tip); 
    177             em_options_input_text ( __( 'Event format', 'events-manager'), 'dbem_full_calendar_event_format', __( 'The format of each event when displayed in the full calendar. Remember to include <code>li</code> tags before and after the event.', 'events-manager').$events_placeholder_tip ); 
    178             em_options_radio_binary( __( 'Abbreviated weekdays?', 'events-manager'), 'dbem_full_calendar_abbreviated_weekdays', __( 'Use abbreviations, e.g. Friday = Fri. Useful for certain languages where abbreviations differ from full names.','events-manager') ); 
    179             em_options_input_text ( __( 'Initial lengths', 'events-manager'), 'dbem_full_calendar_initials_length', __( 'Shorten the calendar headings containing the days of the week, use 0 for the full name.', 'events-manager').$events_placeholder_tip); 
    180             em_options_radio_binary( __( 'Show Long Events?', 'events-manager'), 'dbem_full_calendar_long_events', __( 'Events with multiple dates will appear on each of those dates in the calendar.','events-manager') ); 
    181181            ?>       
    182182            <tr class="em-header"><td colspan="2"><h4><?php echo __('Calendar Day Event List Settings','events-manager'); ?></h4></td></tr>          
  • events-manager/trunk/admin/settings/tabs/general.php

    r1311743 r1720802  
    8888    <?php if ( !is_multisite() ){ em_admin_option_box_image_sizes(); } ?> 
    8989     
    90     <?php if ( !is_multisite() || (is_super_admin() && !get_site_option('dbem_ms_global_caps')) ){ em_admin_option_box_caps(); } ?> 
     90    <?php if ( !is_multisite() || (em_wp_is_super_admin() && !get_site_option('dbem_ms_global_caps')) ){ em_admin_option_box_caps(); } ?> 
    9191     
    9292    <div  class="postbox" id="em-opt-event-submissions" > 
  • events-manager/trunk/admin/settings/tabs/pages.php

    r1311743 r1720802  
    6565                <?php  
    6666                em_options_radio_binary ( __( 'Show events search?', 'events-manager'), 'dbem_events_page_search_form', __( "If set to yes, a search form will appear just above your list of events.", 'events-manager') ); 
    67                 em_options_radio_binary ( __( 'Display calendar in events page?', 'events-manager'), 'dbem_display_calendar_in_events_page', __( 'This options allows to display the calendar in the events page, instead of the default list. It is recommended not to display both the calendar widget and a calendar page.','events-manager').' '.__('If you would like to show events that span over more than one day, see the Calendar section on this page.','events-manager') ); 
     67                em_options_radio_binary ( __( 'Display calendar in events page?', 'events-manager'), 'dbem_display_calendar_in_events_page', __( 'This options allows to display the full-sized calendar on the events page, instead of the default list.','events-manager') ); 
    6868                em_options_radio_binary ( __( 'Disable title rewriting?', 'events-manager'), 'dbem_disable_title_rewrites', __( "Some WordPress themes don't follow best practices when generating navigation menus, and so the automatic title rewriting feature may cause problems, if your menus aren't working correctly on the event pages, try setting this to 'Yes', and provide an appropriate HTML title format below.",'events-manager') ); 
    6969                em_options_input_text ( __( 'Event Manager titles', 'events-manager'), 'dbem_title_html', __( "This only setting only matters if you selected 'Yes' to above. You will notice the events page titles aren't being rewritten, and you have a new title underneath the default page name. This is where you control the HTML of this title. Make sure you keep the #_PAGETITLE placeholder here, as that's what is rewritten by events manager. To control what's rewritten in this title, see settings further down for page titles.", 'events-manager') ); 
     
    144144                    <select name="dbem_events_default_orderby" > 
    145145                        <?php  
    146                             $orderby_options = apply_filters('em_settings_events_default_orderby_ddm', array( 
     146                            $event_list_orderby_options = apply_filters('em_settings_events_default_orderby_ddm', array( 
    147147                                'event_start_date,event_start_time,event_name' => __('Order by start date, start time, then event name','events-manager'), 
    148148                                'event_name,event_start_date,event_start_time' => __('Order by name, start date, then start time','events-manager'), 
     
    151151                            ));  
    152152                        ?> 
    153                         <?php foreach($orderby_options as $key => $value) : ?>    
     153                        <?php foreach($event_list_orderby_options as $key => $value) : ?>    
    154154                        <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_events_default_orderby')) ? "selected='selected'" : ''; ?>> 
    155155                            <?php echo esc_html($value); ?> 
     
    161161                        $ascending = __('Ascending','events-manager'); 
    162162                        $descending = __('Descending','events-manager'); 
    163                         $order_options = apply_filters('em_settings_events_default_order_ddm', array( 
     163                        $event_list_order_options = apply_filters('em_settings_events_default_order_ddm', array( 
    164164                            'ASC' => __('All Ascending','events-manager'), 
    165165                            'DESC,ASC,ASC' => __("$descending, $ascending, $ascending",'events-manager'), 
     
    172172                        ));  
    173173                        ?> 
    174                         <?php foreach( $order_options as $key => $value) : ?>    
     174                        <?php foreach( $event_list_order_options as $key => $value) : ?>    
    175175                        <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_events_default_order')) ? "selected='selected'" : ''; ?>> 
    176176                            <?php echo esc_html($value); ?> 
     
    203203            em_options_radio_binary ( __( 'Override with Formats?', 'events-manager'), 'dbem_cp_locations_formats', sprintf($format_override_tip,__('locations','events-manager'))); 
    204204            em_options_radio_binary ( __( 'Enable Comments?', 'events-manager'), 'dbem_cp_locations_comments', sprintf(__('If you would like to disable comments entirely, disable this, otherwise you can disable comments on each single %s. Note that %s with comments enabled will still be until you resave them.','events-manager'),__('location','events-manager'),__('locations','events-manager'))); 
     205            ?> 
     206            <tr class="em-header"> 
     207                <td colspan="2"> 
     208                    <h4><?php echo sprintf(esc_html__('Default %s list options','events-manager'), __('event','events-manager')); ?></h4> 
     209                    <p><?php echo sprintf(esc_html__('The options below are applied to the %s placeholders.', 'events-manager'), '<code>#_LOCATIONNEXTEVENTS</code>, <code>#_LOCATIONPASTEVENTS</code>, <code>#_LOCATIONALLEVENTS</code>'); ?></p> 
     210                </td> 
     211            </tr> 
     212            <tr valign="top" id='dbem_location_events_default_orderby_row'> 
     213                <th scope="row"><?php _e('Default event list ordering','events-manager'); ?></th> 
     214                <td>    
     215                    <select name="dbem_location_event_list_orderby" > 
     216                        <?php foreach($event_list_orderby_options as $key => $value) : ?>    
     217                        <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_location_event_list_orderby')) ? "selected='selected'" : ''; ?>> 
     218                            <?php echo esc_html($value); ?> 
     219                        </option> 
     220                        <?php endforeach; ?> 
     221                    </select>  
     222                    <select name="dbem_location_event_list_order" > 
     223                        <?php foreach( $event_list_order_options as $key => $value) : ?>    
     224                        <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_location_event_list_order')) ? "selected='selected'" : ''; ?>> 
     225                            <?php echo esc_html($value); ?> 
     226                        </option> 
     227                        <?php endforeach; ?> 
     228                    </select> 
     229                    <br/> 
     230                    <em><?php _e('When Events Manager displays lists of events the default behavior is ordering by start date in ascending order. To change this, modify the values above.','events-manager'); ?></em> 
     231                </td> 
     232            </tr> 
     233            <?php 
    205234            em_options_input_text ( __( 'Event List Limits', 'events-manager'), 'dbem_location_event_list_limit', sprintf(__( "Controls how many events being held at a location are shown per page when using placeholders such as %s. Leave blank for no limit.", 'events-manager'), '<code>#_LOCATIONNEXTEVENTS</code>') ); 
    206235            echo $save_button; 
     
    243272                        <select name="dbem_locations_default_archive_orderby" > 
    244273                            <?php  
    245                                 $orderby_options = apply_filters('em_settings_locations_default_archive_orderby_ddm', array( 
     274                                $locations_list_orderby_options = apply_filters('em_settings_locations_default_archive_orderby_ddm', array( 
    246275                                    '_location_country' => sprintf(__('Order by %s','events-manager'),__('Country','events-manager')), 
    247276                                    '_location_town' => sprintf(__('Order by %s','events-manager'),__('Town','events-manager')), 
     
    249278                                ));  
    250279                            ?> 
    251                             <?php foreach($orderby_options as $key => $value) : ?>    
     280                            <?php foreach($locations_list_orderby_options as $key => $value) : ?>    
    252281                            <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_locations_default_archive_orderby')) ? "selected='selected'" : ''; ?>> 
    253282                                <?php echo esc_html($value) ?> 
     
    259288                            $ascending = __('Ascending','events-manager'); 
    260289                            $descending = __('Descending','events-manager'); 
    261                             $order_options = apply_filters('em_settings_locations_default_archive_order_ddm', array( 
     290                            $locations_list_order_options = apply_filters('em_settings_locations_default_archive_order_ddm', array( 
    262291                                'ASC' => __('Ascending','events-manager'), 
    263292                                'DESC' => __('Descending','events-manager') 
    264293                            ));  
    265294                            ?> 
    266                             <?php foreach( $order_options as $key => $value) : ?>    
     295                            <?php foreach( $locations_list_order_options as $key => $value) : ?>    
    267296                            <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_locations_default_archive_order')) ? "selected='selected'" : ''; ?>> 
    268297                                <?php echo esc_html($value) ?> 
     
    294323                    <select name="dbem_locations_default_orderby" > 
    295324                        <?php  
    296                             $orderby_options = apply_filters('em_settings_locations_default_orderby_ddm', array( 
     325                            $locations_list_orderby_options = apply_filters('em_settings_locations_default_orderby_ddm', array( 
    297326                                'location_country' => sprintf(__('Order by %s','events-manager'),__('Country','events-manager')), 
    298327                                'location_town' => sprintf(__('Order by %s','events-manager'),__('Town','events-manager')), 
     
    300329                            ));  
    301330                        ?> 
    302                         <?php foreach($orderby_options as $key => $value) : ?> 
     331                        <?php foreach($locations_list_orderby_options as $key => $value) : ?> 
    303332                        <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_locations_default_orderby')) ? "selected='selected'" : ''; ?>> 
    304333                            <?php echo esc_html($value) ?> 
     
    310339                        $ascending = __('Ascending','events-manager'); 
    311340                        $descending = __('Descending','events-manager'); 
    312                         $order_options = apply_filters('em_settings_locations_default_order_ddm', array( 
     341                        $locations_list_order_options = apply_filters('em_settings_locations_default_order_ddm', array( 
    313342                            'ASC' => __('Ascending','events-manager'), 
    314343                            'DESC' => __('Descending','events-manager') 
    315344                        ));  
    316345                        ?> 
    317                         <?php foreach( $order_options as $key => $value) : ?>    
     346                        <?php foreach( $locations_list_order_options as $key => $value) : ?>    
    318347                        <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_locations_default_order')) ? "selected='selected'" : ''; ?>> 
    319348                            <?php echo esc_html($value) ?> 
     
    358387                <td colspan="2"> 
    359388                    <h4><?php echo _e('General settings','events-manager'); ?></h4> 
     389                    <p><?php echo esc_html(sprintf(__('Viewing a general WordPress taxonomy page such as %s will show a list of events just like it would regular posts for a regular category or tag. Below you can edit things such as the order events are displayed, or completely override the archive look with our formats feature.','events-manager'), __('categories', 'events-manager'))); ?></p> 
    360390                </td> 
    361391            </tr> 
    362392            <?php 
    363             em_options_radio_binary ( __( 'Override with Formats?', 'events-manager'), 'dbem_cp_categories_formats', sprintf($format_override_tip,__('categories','events-manager'))." ".__('Setting this to yes will make categories display as a page rather than an archive.', 'events-manager')); 
    364             ?> 
    365             <tr valign="top"> 
    366                 <th scope="row"><?php _e('Default archive ordering','events-manager'); ?></th> 
     393            em_options_radio_binary ( __( 'Override with Formats?', 'events-manager'), 'dbem_cp_categories_formats', sprintf($format_override_tip,__('categories','events-manager'))." ".__('Setting this to yes will make categories display as a page rather than an archive.', 'events-manager'), '', '.em-default-categories-archive-ordering', true); 
     394            ?> 
     395            <tr valign="top" class="em-default-categories-archive-ordering"> 
     396                <th scope="row"><?php _e('Default event archive ordering','events-manager'); ?></th> 
    367397                <td>    
    368398                    <select name="dbem_categories_default_archive_orderby" > 
     
    380410                        <?php endforeach; ?> 
    381411                    </select> 
    382                     <br /><?php echo __('When listing events for a category, this order is applied.', 'events-manager'); ?> 
     412                    <br /><?php echo esc_html(sprintf(__('When listing event archives for a %s, this order is applied.', 'events-manager'), __('category', 'events-manager'))); ?> 
    383413                </td> 
    384414            </tr> 
     
    394424                    <select name="dbem_categories_default_orderby" > 
    395425                        <?php  
    396                             $orderby_options = apply_filters('em_settings_categories_default_orderby_ddm', array( 
     426                            $categories_list_orderby_options = apply_filters('em_settings_categories_default_orderby_ddm', array( 
    397427                                'id' => sprintf(__('Order by %s','events-manager'),__('ID','events-manager')), 
    398428                                'count' => sprintf(__('Order by %s','events-manager'),__('Count','events-manager')), 
     
    402432                            ));  
    403433                        ?> 
    404                         <?php foreach($orderby_options as $key => $value) : ?> 
     434                        <?php foreach($categories_list_orderby_options as $key => $value) : ?> 
    405435                        <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_categories_default_orderby')) ? "selected='selected'" : ''; ?>> 
    406436                            <?php echo esc_html($value) ?> 
     
    412442                        $ascending = __('Ascending','events-manager'); 
    413443                        $descending = __('Descending','events-manager'); 
    414                         $order_options = apply_filters('em_settings_categories_default_order_ddm', array( 
     444                        $categories_list_order_options = apply_filters('em_settings_categories_default_order_ddm', array( 
    415445                            'ASC' => __('Ascending','events-manager'), 
    416446                            'DESC' => __('Descending','events-manager') 
    417447                        ));  
    418448                        ?> 
    419                         <?php foreach( $order_options as $key => $value) : ?>    
     449                        <?php foreach( $categories_list_order_options as $key => $value) : ?>    
    420450                        <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_categories_default_order')) ? "selected='selected'" : ''; ?>> 
    421451                            <?php echo esc_html($value) ?> 
     
    428458            <?php 
    429459            em_options_input_text ( __( 'List Limits', 'events-manager'), 'dbem_categories_default_limit', sprintf(__( "This will control how many %s are shown on one list by default.", 'events-manager'),__('categories','events-manager')) ); 
     460            ?> 
     461            <tr class="em-header"> 
     462                <td colspan="2"> 
     463                    <h4><?php echo sprintf(esc_html__('Default %s list options','events-manager'), __('event','events-manager')); ?></h4> 
     464                    <p><?php echo sprintf(esc_html__('The options below are applied to the %s placeholders.', 'events-manager'), '<code>#_CATEGORYPASTEVENTS</code>, <code>#_CATEGORYNEXTEVENTS</code>, <code>#_CATEGORYALLEVENTS</code>'); ?></p> 
     465                </td> 
     466            </tr>                            
     467            <tr valign="top" id='dbem_category_events_default_orderby_row'> 
     468                <th scope="row"><?php _e('Default event list ordering','events-manager'); ?></th> 
     469                <td>    
     470                    <select name="dbem_category_event_list_orderby" > 
     471                        <?php foreach($event_list_orderby_options as $key => $value) : ?>    
     472                        <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_category_event_list_orderby')) ? "selected='selected'" : ''; ?>> 
     473                            <?php echo esc_html($value); ?> 
     474                        </option> 
     475                        <?php endforeach; ?> 
     476                    </select>  
     477                    <select name="dbem_category_event_list_order" > 
     478                        <?php foreach( $event_list_order_options as $key => $value) : ?>    
     479                        <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_category_event_list_order')) ? "selected='selected'" : ''; ?>> 
     480                            <?php echo esc_html($value); ?> 
     481                        </option> 
     482                        <?php endforeach; ?> 
     483                    </select> 
     484                    <br/> 
     485                    <em><?php _e('When Events Manager displays lists of events the default behavior is ordering by start date in ascending order. To change this, modify the values above.','events-manager'); ?></em> 
     486                </td> 
     487            </tr> 
     488            <?php 
    430489            em_options_input_text ( __( 'Event List Limits', 'events-manager'), 'dbem_category_event_list_limit', sprintf(__( "Controls how many events belonging to a category are shown per page when using placeholders such as %s. Leave blank for no limit.", 'events-manager'), '<code>#_CATEGORYNEXTEVENTS</code>') ); 
    431             echo $save_button; 
     490            echo $save_button; 
    432491            ?> 
    433492            </table> 
     
    462521                    <td colspan="2"> 
    463522                        <h4><?php echo _e('General settings','events-manager'); ?></h4> 
     523                        <p><?php echo esc_html(sprintf(__('Viewing a general WordPress taxonomy page such as %s will show a list of events just like it would regular posts for a regular category or tag. Below you can edit things such as the order events are displayed, or completely override the archive look with our formats feature.','events-manager'), __('tags', 'events-manager'))); ?></p> 
    464524                    </td> 
    465525                </tr> 
    466526                <?php 
    467                 em_options_radio_binary ( __( 'Override with Formats?', 'events-manager'), 'dbem_cp_tags_formats', sprintf($format_override_tip,__('tags','events-manager'))); 
     527                em_options_radio_binary ( __( 'Override with Formats?', 'events-manager'), 'dbem_cp_tags_formats', sprintf($format_override_tip,__('tags','events-manager')), '', '.em-default-tags-archive-ordering', true); 
    468528                ?> 
    469                 <tr valign="top"> 
    470                     <th scope="row"><?php _e('Default archive ordering','events-manager'); ?></th> 
     529                <tr valign="top" class="em-default-tags-archive-ordering"> 
     530                    <th scope="row"><?php _e('Default event archive ordering','events-manager'); ?></th> 
    471531                    <td>    
    472532                        <select name="dbem_tags_default_archive_orderby" > 
     
    484544                            <?php endforeach; ?> 
    485545                        </select> 
     546                        <br /><?php echo esc_html(sprintf(__('When listing event archives for a %s, this order is applied.', 'events-manager'), __('tag', 'events-manager'))); ?> 
    486547                    </td> 
    487548                </tr>    
     
    497558                        <select name="dbem_tags_default_orderby" > 
    498559                            <?php  
    499                                 $orderby_options = apply_filters('em_settings_tags_default_orderby_ddm', array( 
     560                                $tags_list_orderby_options = apply_filters('em_settings_tags_default_orderby_ddm', array( 
    500561                                    'id' => sprintf(__('Order by %s','events-manager'),__('ID','events-manager')), 
    501562                                    'count' => sprintf(__('Order by %s','events-manager'),__('Count','events-manager')), 
     
    505566                                ));  
    506567                            ?> 
    507                             <?php foreach($orderby_options as $key => $value) : ?> 
     568                            <?php foreach($tags_list_orderby_options as $key => $value) : ?> 
    508569                            <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_tags_default_orderby')) ? "selected='selected'" : ''; ?>> 
    509570                                <?php echo esc_html($value) ?> 
     
    515576                            $ascending = __('Ascending','events-manager'); 
    516577                            $descending = __('Descending','events-manager'); 
    517                             $order_options = apply_filters('em_settings_tags_default_order_ddm', array( 
     578                            $tags_list_order_options = apply_filters('em_settings_tags_default_order_ddm', array( 
    518579                                'ASC' => __('Ascending','events-manager'), 
    519580                                'DESC' => __('Descending','events-manager') 
    520581                            ));  
    521582                            ?> 
    522                             <?php foreach( $order_options as $key => $value) : ?>    
     583                            <?php foreach( $tags_list_order_options as $key => $value) : ?>    
    523584                            <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_tags_default_order')) ? "selected='selected'" : ''; ?>> 
    524585                                <?php echo esc_html($value) ?> 
     
    531592                <?php 
    532593                em_options_input_text ( __( 'List Limits', 'events-manager'), 'dbem_tags_default_limit', sprintf(__( "This will control how many %s are shown on one list by default.", 'events-manager'),__('tags','events-manager')) ); 
     594                ?> 
     595                <tr class="em-header"> 
     596                    <td colspan="2"> 
     597                        <h4><?php echo sprintf(esc_html__('Default %s list options','events-manager'), __('event','events-manager')); ?></h4> 
     598                        <p><?php echo sprintf(esc_html__('The options below are applied to the %s placeholders.', 'events-manager'), '<code>#_TAGPASTEVENTS</code>, <code>#_TAGNEXTEVENTS</code>, <code>#_TAGALLEVENTS</code>'); ?></p> 
     599                    </td> 
     600                </tr> 
     601                <tr valign="top" id='dbem_tag_events_default_orderby_row'> 
     602                    <th scope="row"><?php _e('Default event list ordering','events-manager'); ?></th> 
     603                    <td>    
     604                        <select name="dbem_tag_event_list_orderby" > 
     605                            <?php foreach($event_list_orderby_options as $key => $value) : ?>    
     606                            <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_tag_event_list_orderby')) ? "selected='selected'" : ''; ?>> 
     607                                <?php echo esc_html($value); ?> 
     608                            </option> 
     609                            <?php endforeach; ?> 
     610                        </select>  
     611                        <select name="dbem_tag_event_list_order" > 
     612                            <?php foreach( $event_list_order_options as $key => $value) : ?>    
     613                            <option value='<?php echo esc_attr($key) ?>' <?php echo ($key == get_option('dbem_tag_event_list_order')) ? "selected='selected'" : ''; ?>> 
     614                                <?php echo esc_html($value); ?> 
     615                            </option> 
     616                            <?php endforeach; ?> 
     617                        </select> 
     618                        <br/> 
     619                        <em><?php _e('When Events Manager displays lists of events the default behavior is ordering by start date in ascending order. To change this, modify the values above.','events-manager'); ?></em> 
     620                    </td> 
     621                </tr> 
     622                <?php 
    533623                em_options_input_text ( __( 'Event List Limits', 'events-manager'), 'dbem_tag_event_list_limit', sprintf(__( "Controls how many events belonging to a tag are shown per page when using placeholders such as %s. Leave blank for no limit.", 'events-manager'), '<code>#_TAGNEXTEVENTS</code>') ); 
    534624                echo $save_button; ?> 
  • events-manager/trunk/buddypress/bp-em-notifications.php

    r1651260 r1720802  
    5555function bp_em_remove_screen_notifications() { 
    5656    global $bp; 
    57     if( function_exists('bp_notifications_delete_notifications_by_type') ){ //backwards compat for BP 1.9 
     57    if( function_exists('bp_notifications_delete_notifications_by_type') ){ 
    5858        bp_notifications_delete_notifications_by_type( $bp->loggedin_user->id, $bp->events->slug, 'attending' ); 
    59     }else{ 
    60         bp_core_delete_notifications_by_type( $bp->loggedin_user->id, $bp->events->slug, 'attending' ); 
    6159    } 
    6260} 
  • events-manager/trunk/classes/em-booking.php

    r1655537 r1720802  
    377377    } 
    378378     
    379     function get_price_pre_taxes( $format = false ){ 
     379    function get_price_pre_taxes( $format = false, $include_adjustments = true ){ 
    380380        $price = $base_price = $this->get_price_base(); 
    381381        //apply pre-tax discounts 
    382         $price -= $this->get_price_adjustments_amount('discounts', 'pre', $base_price); 
    383         $price += $this->get_price_adjustments_amount('surcharges', 'pre', $base_price); 
    384         $price = apply_filters('em_booking_get_price_pre_taxes', $price, $base_price, $this); 
     382        if( $include_adjustments ){ 
     383            $price -= $this->get_price_adjustments_amount('discounts', 'pre', $base_price); 
     384            $price += $this->get_price_adjustments_amount('surcharges', 'pre', $base_price); 
     385        } 
     386        $price = apply_filters('em_booking_get_price_pre_taxes', $price, $base_price, $this, $include_adjustments); 
    385387        if( $price < 0 ){ $price = 0; } //no negative prices 
    386388        //return amount of taxes applied, formatted or not 
     
    394396     * @return double|string 
    395397     */ 
    396     function get_price_post_taxes( $format = false ){ 
     398    function get_price_post_taxes( $format = false, $include_adjustments = true ){ 
    397399        //get price before taxes 
    398         $price = $this->get_price_pre_taxes(); 
     400        $price = $this->get_price_pre_taxes( false, $include_adjustments ); 
    399401        //add taxes to price 
    400402        if( $this->get_tax_rate() > 0 ){ 
     
    405407        //apply post-tax discounts 
    406408        $price_after_taxes = $price; 
    407         $price -= $this->get_price_adjustments_amount('discounts', 'post', $price_after_taxes); 
    408         $price += $this->get_price_adjustments_amount('surcharges', 'post', $price_after_taxes); 
    409         $price = apply_filters('em_booking_get_price_post_taxes', $price, $price_after_taxes, $this); 
     409        if( $include_adjustments ){ 
     410            $price -= $this->get_price_adjustments_amount('discounts', 'post', $price_after_taxes); 
     411            $price += $this->get_price_adjustments_amount('surcharges', 'post', $price_after_taxes); 
     412        } 
     413        $price = apply_filters('em_booking_get_price_post_taxes', $price, $price_after_taxes, $this, $include_adjustments); 
    410414        if( $price < 0 ){ $price = 0; } //no negative prices 
    411415        //return amount of taxes applied, formatted or not 
  • events-manager/trunk/classes/em-bookings.php

    r1651260 r1720802  
    1111     * @var array 
    1212     */ 
    13     var $bookings = array(); 
     13    protected $bookings; 
    1414    /** 
    1515     * @var EM_Tickets 
     
    3939     */ 
    4040    public static $disable_restrictions = false; 
     41     
     42    protected $booked_spaces; 
     43    protected $pending_spaces; 
     44    protected $available_spaces; 
    4145     
    4246    /** 
     
    4751    function __construct( $data = false ){ 
    4852        if( is_object($data) && get_class($data) == "EM_Event" ){ //Creates a blank bookings object if needed 
    49             global $wpdb; 
    5053            $this->event_id = $data->event_id; 
    51             $bookings = array(); 
    52             if( $this->event_id > 0 ){ 
    53                 $sql = "SELECT * FROM ". EM_BOOKINGS_TABLE ." WHERE event_id ='{$this->event_id}' ORDER BY booking_date"; 
    54                 $bookings = $wpdb->get_results($sql, ARRAY_A); 
    55             } 
    56             foreach ($bookings as $booking){ 
    57                 $this->bookings[] = em_get_booking($booking); 
    58             } 
    59             $this->spaces = $this->get_spaces(); 
    6054        }elseif( is_array($data) ){ 
    6155            foreach( $data as $EM_Booking ){ 
     
    6559            } 
    6660        } 
     61    } 
     62     
     63    public function __get( $var ){ 
     64        if( $var == 'bookings' ){ 
     65            return $this->load(); 
     66        } 
     67    } 
     68     
     69    public function load( $refresh = false ){ 
     70        if( $refresh || $this->bookings === null ){ 
     71            global $wpdb; 
     72            $bookings = $this->bookings = array(); 
     73            if( $this->event_id > 0 ){ 
     74                $sql = "SELECT * FROM ". EM_BOOKINGS_TABLE ." WHERE event_id ='{$this->event_id}' ORDER BY booking_date"; 
     75                $bookings = $wpdb->get_results($sql, ARRAY_A); 
     76            } 
     77            foreach ($bookings as $booking){ 
     78                $this->bookings[] = em_get_booking($booking); 
     79            } 
     80        } 
     81        return apply_filters('em_bookings_load', $this->bookings); 
    6782    } 
    6883     
     
    8499            //Success 
    85100            do_action('em_bookings_added', $EM_Booking); 
    86             $this->bookings[] = $EM_Booking; 
     101            if( $this->bookings !== null ) $this->bookings[] = $EM_Booking; 
    87102            $email = $EM_Booking->email(); 
    88103            if( get_option('dbem_bookings_approval') == 1 && $EM_Booking->booking_status == 0){ 
     
    169184                    if( $EM_Event->is_recurring() && !empty($EM_Ticket->ticket_meta['recurrences']) ){ 
    170185                        $EM_Event->recurrence_rsvp_days = $EM_Ticket->ticket_meta['recurrences']['end_days'];                        
    171                     }                
     186                    } 
    172187                }else{ 
    173188                    //if no end date is set, use event end date (which will have defaulted to the event start date  
     
    202217    } 
    203218     
     219    /** 
     220     * Deprecated - was never used and therefore is deprecated, will always return an array() and will eventually be removed entirely. 
     221     * @return array 
     222     */ 
    204223    function get_user_list(){ 
    205         $users = array(); 
    206         foreach( $this->get_bookings()->bookings as $EM_Booking ){ 
    207             $users[$EM_Booking->person->ID] = $EM_Booking->person; 
    208         } 
    209         return $users; 
    210     } 
    211      
    212     /** 
    213      * does this ticket exist? 
     224        return array(); 
     225    } 
     226     
     227    /** 
     228     * Returns a boolean indicating whether this ticket exists in this bookings context. 
    214229     * @return bool  
    215230     */ 
     
    365380     */ 
    366381    function get_booked_spaces($force_refresh = false){ 
    367         $booked_spaces = 0; 
    368         foreach ( $this->bookings as $EM_Booking ){ 
    369             if( $EM_Booking->booking_status == 1 || (!get_option('dbem_bookings_approval') && $EM_Booking->booking_status == 0 ) ){ 
    370                 $booked_spaces += $EM_Booking->get_spaces($force_refresh); 
    371             } 
    372         } 
    373         return apply_filters('em_bookings_get_booked_spaces', $booked_spaces, $this); 
     382        global $wpdb; 
     383        if( $this->booked_spaces === null || $force_refresh ){ 
     384            $status_cond = !get_option('dbem_bookings_approval') ? 'booking_status IN (0,1)' : 'booking_status = 1'; 
     385            $sql = 'SELECT SUM(booking_spaces) FROM '.EM_BOOKINGS_TABLE. " WHERE $status_cond AND event_id=".absint($this->event_id); 
     386            $booked_spaces = $wpdb->get_var($sql); 
     387            $this->booked_spaces = $booked_spaces > 0 ? $booked_spaces : 0; 
     388        } 
     389        return apply_filters('em_bookings_get_booked_spaces', $this->booked_spaces, $this, $force_refresh); 
    374390    } 
    375391     
     
    378394     * @return int 
    379395     */ 
    380     function get_pending_spaces(){ 
     396    function get_pending_spaces( $force_refresh = false ){ 
    381397        if( get_option('dbem_bookings_approval') == 0 ){ 
    382398            return apply_filters('em_bookings_get_pending_spaces', 0, $this); 
    383399        } 
    384         $pending = 0; 
    385         foreach ( $this->bookings as $booking ){ 
    386             if($booking->booking_status == 0){ 
    387                 $pending += $booking->get_spaces(); 
    388             } 
    389         } 
    390         return apply_filters('em_bookings_get_pending_spaces', $pending, $this); 
     400        global $wpdb; 
     401        if( $this->pending_spaces === null || $force_refresh ){ 
     402            $sql = 'SELECT SUM(booking_spaces) FROM '.EM_BOOKINGS_TABLE. ' WHERE booking_status=0 AND event_id='.absint($this->event_id); 
     403            $pending_spaces = $wpdb->get_var($sql); 
     404            $this->pending_spaces = $pending_spaces > 0 ? $pending_spaces : 0; 
     405        } 
     406        return apply_filters('em_bookings_get_pending_spaces', $this->pending_spaces, $this, $force_refresh); 
    391407    } 
    392408     
     
    397413    function get_bookings( $all_bookings = false ){ 
    398414        $confirmed = array(); 
    399         foreach ( $this->bookings as $booking ){ 
    400             if( $booking->booking_status == 1 || (get_option('dbem_bookings_approval') == 0 && $booking->booking_status == 0) || $all_bookings ){ 
    401                 $confirmed[] = $booking; 
     415        foreach ( $this->load() as $EM_Booking ){ 
     416            if( $EM_Booking->booking_status == 1 || (get_option('dbem_bookings_approval') == 0 && $EM_Booking->booking_status == 0) || $all_bookings ){ 
     417                $confirmed[] = $EM_Booking; 
    402418            } 
    403419        } 
     
    415431        } 
    416432        $pending = array(); 
    417         foreach ( $this->bookings as $booking ){ 
    418             if($booking->booking_status == 0){ 
    419                 $pending[] = $booking; 
     433        foreach ( $this->load() as $EM_Booking ){ 
     434            if($EM_Booking->booking_status == 0){ 
     435                $pending[] = $EM_Booking; 
    420436            } 
    421437        } 
     
    430446    function get_rejected_bookings(){ 
    431447        $rejected = array(); 
    432         foreach ( $this->bookings as $booking ){ 
    433             if($booking->booking_status == 2){ 
    434                 $rejected[] = $booking; 
     448        foreach ( $this->load() as $EM_Booking ){ 
     449            if($EM_Booking->booking_status == 2){ 
     450                $rejected[] = $EM_Booking; 
    435451            } 
    436452        } 
     
    445461    function get_cancelled_bookings(){ 
    446462        $cancelled = array(); 
    447         foreach ( $this->bookings as $booking ){ 
    448             if($booking->booking_status == 3){ 
    449                 $cancelled[] = $booking; 
     463        foreach ( $this->load() as $EM_Booking ){ 
     464            if($EM_Booking->booking_status == 3){ 
     465                $cancelled[] = $EM_Booking; 
    450466            } 
    451467        } 
     
    465481        if( is_numeric($EM_Booking->person->ID) && $EM_Booking->person->ID > 0 ){ 
    466482            $EM_Booking->person_id = $EM_Booking->person->ID; 
    467             foreach ($this->bookings as $booking){ 
     483            foreach ($this->load() as $booking){ 
    468484                if( $booking->person_id == $EM_Booking->person->ID ){ 
    469485                    return $booking; 
     
    483499        } 
    484500        if( is_numeric($user_id) && $user_id > 0 ){ 
    485             foreach ($this->bookings as $EM_Booking){ 
     501            foreach ($this->load() as $EM_Booking){ 
    486502                if( $EM_Booking->person->ID == $user_id && !in_array($EM_Booking->booking_status, array(2,3)) ){ 
    487503                    return apply_filters('em_bookings_has_booking', $EM_Booking, $this); 
     
    535551        //Now, build orderby sql 
    536552        $orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : 'ORDER BY booking_date'; 
    537         //Selector 
    538         $selectors = ( $count ) ?  'COUNT(*)':'*'; 
    539          
     553        //Selectors 
     554        if( $count ){ 
     555            $selectors = 'COUNT(*)'; 
     556        }elseif( is_array($args['array']) ){ 
     557            $selectors = implode(',', $args['array']); 
     558        }else{ 
     559            $selectors = '*'; 
     560        } 
    540561        //Create the SQL statement and execute 
    541562        $sql = apply_filters('em_bookings_get_sql'," 
     
    682703            'person' => true, //to add later, search by person's bookings... 
    683704            'blog' => get_current_blog_id(), 
    684             'ticket_id' => false 
     705            'ticket_id' => false, 
     706            'array' => false //returns an array of results if true, if an array or text it's assumed an array or single row requested  
    685707        ); 
    686708        //sort out whether defaults were supplied or just the array of search values 
     
    690712            $defaults = array_merge($defaults, $array_or_defaults); 
    691713        } 
     714        //clean up array value 
     715        if( !empty($args['array']) ){ 
     716            $EM_Booking = new EM_Booking(); 
     717            if( is_array($args['array']) ){ 
     718                $clean_arg = array(); 
     719                foreach( $args['array'] as $k => $field ){ 
     720                    if( array_key_exists($field, $EM_Booking->fields) ){ 
     721                        $clean_arg[] = $field; 
     722                    } 
     723                } 
     724                $args['array'] = !empty($clean_arg) ? $clean_arg : true; //if invalid args given, just return all fields 
     725            }elseif( is_string($args['array']) && array_key_exists($args['array'], $EM_Booking->fields) ){ 
     726                $args['array'] = array($args['array']); 
     727            }else{ 
     728                $args['array'] = true; 
     729            } 
     730        }else{ 
     731            $args['array'] = false; 
     732        } 
    692733        //figure out default owning permissions 
    693734        if( !current_user_can('edit_others_events') ){ 
     
    704745    } 
    705746 
    706     //Iterator Implementation 
     747    //Iterator Implementation - if we iterate this object, we automatically invoke the load() function first 
     748    //and load up all bookings to go through from the database. 
    707749    public function rewind(){ 
     750        $this->load(); 
    708751        reset($this->bookings); 
    709752    }   
    710753    public function current(){ 
     754        $this->load(); 
    711755        $var = current($this->bookings); 
    712756        return $var; 
    713757    }   
    714758    public function key(){ 
     759        $this->load(); 
    715760        $var = key($this->bookings); 
    716761        return $var; 
    717762    }   
    718763    public function next(){ 
     764        $this->load(); 
    719765        $var = next($this->bookings); 
    720766        return $var; 
    721767    }   
    722768    public function valid(){ 
     769        $this->load(); 
    723770        $key = key($this->bookings); 
    724771        $var = ($key !== NULL && $key !== FALSE); 
  • events-manager/trunk/classes/em-calendar.php

    r1694715 r1720802  
    3333        $limit = $args['limit']; //limit arg will be used per day and not for events search 
    3434         
    35         $week_starts_on_sunday = get_option('dbem_week_starts_sunday'); 
    36         $start_of_week = get_option('start_of_week'); 
     35        $start_of_week = get_option('start_of_week'); 
    3736         
    3837        if( !(is_numeric($month) && $month <= 12 && $month > 0) )   { 
     
    287286        //generate a link argument string containing event search only 
    288287        $day_link_args = self::get_query_args( array_intersect_key($original_args, EM_Events::get_post_search($args, true) )); 
     288        //get event link  
     289        if( get_option("dbem_events_page") > 0 ){ 
     290            $event_page_link = get_permalink(get_option("dbem_events_page")); //PAGE URI OF EM 
     291        }else{ 
     292            if( $wp_rewrite->using_permalinks() ){ 
     293                $event_page_link = trailingslashit(home_url()).EM_POST_TYPE_EVENT_SLUG.'/'; //don't use EM_URI here, since ajax calls this before EM_URI is defined. 
     294            }else{ 
     295                //not needed atm anyway, but we use esc_url later on, in case you're wondering ;)  
     296                $event_page_link = add_query_arg(array('post_type'=>EM_POST_TYPE_EVENT), home_url()); //don't use EM_URI here, since ajax calls this before EM_URI is defined. 
     297            } 
     298        } 
     299        $event_page_link_parts = explode('?', $event_page_link); //in case we have other plugins (e.g. WPML) adding querystring params to the end  
    289300        foreach($eventful_days as $day_key => $events) { 
    290301            if( array_key_exists($day_key, $calendar_array['cells']) ){ 
     
    304315                global $wp_rewrite; 
    305316                if( $eventful_days_count[$day_key] > 1 || !get_option('dbem_calendar_direct_links')  ){ 
    306                     if( get_option("dbem_events_page") > 0 ){ 
    307                         $event_page_link = get_permalink(get_option("dbem_events_page")); //PAGE URI OF EM 
    308                     }else{ 
    309                         if( $wp_rewrite->using_permalinks() ){ 
    310                             $event_page_link = trailingslashit(home_url()).EM_POST_TYPE_EVENT_SLUG.'/'; //don't use EM_URI here, since ajax calls this before EM_URI is defined. 
    311                         }else{ 
    312                             //not needed atm anyway, but we use esc_url later on, in case you're wondering ;)  
    313                             $event_page_link = add_query_arg(array('post_type'=>EM_POST_TYPE_EVENT), home_url()); //don't use EM_URI here, since ajax calls this before EM_URI is defined. 
    314                         } 
    315                     } 
    316317                    if( $wp_rewrite->using_permalinks() && !defined('EM_DISABLE_PERMALINKS') ){ 
    317                         $calendar_array['cells'][$day_key]['link'] = trailingslashit($event_page_link).$day_key."/"; 
     318                        $calendar_array['cells'][$day_key]['link'] = trailingslashit($event_page_link_parts[0]).$day_key."/"; 
     319                        if( !empty($event_page_link_parts[1]) ) $calendar_array['cells'][$day_key]['link'] .= '?' . $event_page_link_parts[1]; 
    318320                        //add query vars to end of link 
    319321                        if( !empty($day_link_args) ){ 
  • events-manager/trunk/classes/em-categories.php

    r1651260 r1720802  
    11<?php 
    2 class EM_Categories extends EM_Object implements Iterator{ 
     2class EM_Categories extends EM_Taxonomy_Terms { 
    33     
    4     /** 
    5      * Array of EM_Category objects for a specific event 
    6      * @var array 
    7      */ 
    8     var $categories = array(); 
    9     /** 
    10      * Event ID of this set of categories 
    11      * @var int 
    12      */ 
    13     var $event_id; 
    14     /** 
    15      * Post ID of this set of categories 
    16      * @var int 
    17      */ 
    18     var $post_id; 
     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'; 
    1910     
    2011    /** 
     
    2415     */ 
    2516    function __construct( $data = false ){ 
    26         global $wpdb; 
    27         self::ms_global_switch(); 
    28         if( is_object($data) && get_class($data) == "EM_Event" && !empty($data->post_id) ){ //Creates a blank categories object if needed 
    29             $this->event_id = $data->event_id; 
    30             $this->post_id = $data->post_id; 
    31             if( EM_MS_GLOBAL && !is_main_site($data->blog_id) ){ 
    32                 $cat_ids = $wpdb->get_col('SELECT meta_value FROM '.EM_META_TABLE." WHERE object_id='{$this->event_id}' AND meta_key='event-category'"); 
    33                 foreach($cat_ids as $cat_id){ 
    34                     $this->categories[$cat_id] = new EM_Category($cat_id); 
    35                 } 
    36             }else{ 
    37                 $results = get_the_terms( $data->post_id, EM_TAXONOMY_CATEGORY ); 
    38                 if( is_array($results) ){ 
    39                     foreach($results as $result){ 
    40                         $this->categories[$result->term_id] = new EM_Category($result); 
    41                     } 
    42                 } 
    43             } 
    44         }elseif( is_array($data) && self::array_is_numeric($data) ){ 
    45             foreach($data as $category_id){ 
    46                 $this->categories[$category_id] =  new EM_Category($category_id); 
    47             } 
    48         }elseif( is_array($data) ){ 
    49             foreach( $data as $EM_Category ){ 
    50                 if( get_class($EM_Category) == 'EM_Category'){ 
    51                     $this->categories[] = $EM_Category; 
    52                 } 
    53             } 
     17        $this->taxonomy = EM_TAXONOMY_CATEGORY; 
     18        parent::__construct($data); 
     19    } 
     20         
     21    /** 
     22     * Legacy get overload for any use of $EM_Tags->tags 
     23     * @param string $var_name 
     24     * @return array|NULL 
     25     */ 
     26    function __get( $var_name ){ 
     27        if( $var_name == 'categories' ){ 
     28            return $this->terms; 
    5429        } 
    55         self::ms_global_switch_back(); 
    56         do_action('em_categories', $this); 
     30        return null; 
    5731    } 
    5832     
    59     function get_post(){ 
    60         self::ms_global_switch(); 
    61         $this->categories = array(); 
    62         if(!empty($_POST['event_categories']) && self::array_is_numeric($_POST['event_categories'])){ 
    63             foreach( $_POST['event_categories'] as $term ){ 
    64                 $this->categories[$term] = new EM_Category($term); 
    65             } 
    66         } 
    67         self::ms_global_switch_back(); 
    68         do_action('em_categories_get_post', $this); 
    69     } 
     33    //Functions we won't need when PHP 5.3 minimum allows for use of LSB 
    7034     
    71     function save(){ 
    72         $term_slugs = array(); 
    73         foreach($this->categories as $EM_Category){ 
    74             /* @var $EM_Category EM_Category */ 
    75             if( !empty($EM_Category->slug) ) $term_slugs[] = $EM_Category->slug; //save of category will soft-fail if slug is empty 
    76         } 
    77         if( count($term_slugs) == 0 && get_option('dbem_default_category') > 0 ){ 
    78             $default_term = get_term_by('id',get_option('dbem_default_category'), EM_TAXONOMY_CATEGORY); 
    79             if($default_term) $term_slugs[] = $default_term->slug; 
    80         } 
    81         if( is_multisite() ){ 
    82             //In MS Global mode, we also save category meta information for global lookups 
    83             if( EM_MS_GLOBAL && !empty($this->event_id) ){ 
    84                 //delete categories 
    85                 $this->save_index(); 
    86             } 
    87             if( !EM_MS_GLOBAL || is_main_site() ){ 
    88                 wp_set_object_terms($this->post_id, $term_slugs, EM_TAXONOMY_CATEGORY); 
    89             } 
    90         }else{ 
    91             wp_set_object_terms($this->post_id, $term_slugs, EM_TAXONOMY_CATEGORY); 
    92         } 
    93         do_action('em_categories_save', $this); 
    94     } 
    95      
    96     function save_index(){ 
    97         global $wpdb; 
    98         $wpdb->query('DELETE FROM '.EM_META_TABLE." WHERE object_id='{$this->event_id}' AND meta_key='event-category'"); 
    99         foreach($this->categories as $EM_Category){ 
    100             $wpdb->insert(EM_META_TABLE, array('meta_value'=>$EM_Category->term_id,'object_id'=>$this->event_id,'meta_key'=>'event-category')); 
    101         } 
    102     } 
    103          
    104     public static function get( $args = array() ) {      
    105         //Quick version, we can accept an array of IDs, which is easy to retrieve 
    106         self::ms_global_switch(); 
    107         if( self::array_is_numeric($args) ){ //Array of numbers, assume they are event IDs to retreive 
    108             $results = get_terms( EM_TAXONOMY_CATEGORY ); 
    109             $categories = array(); 
    110             foreach($results as $result){ 
    111                 if( in_array($result->term_id, $args) ){ 
    112                     $categories[$result->term_id] = new EM_Category($result); 
    113                 } 
    114             } 
    115         }else{ 
    116             //We assume it's either an empty array or array of search arguments to merge with defaults 
    117             $term_args = self::get_default_search($args);        
    118             $results = get_terms( EM_TAXONOMY_CATEGORY, $term_args);         
    119          
    120             //If we want results directly in an array, why not have a shortcut here? We don't use this in code, so if you're using it and filter the em_categories_get hook, you may want to do this one too. 
    121             if( !empty($args['array']) ){ 
    122                 return apply_filters('em_categories_get_array', $results, $args); 
    123             } 
    124              
    125             //Make returned results EM_Category objects 
    126             $results = (is_array($results)) ? $results:array(); 
    127             $categories = array(); 
    128             foreach ( $results as $category ){ 
    129                 $categories[$category->term_id] = new EM_Category($category); 
    130             } 
    131         } 
    132         self::ms_global_switch_back();   
    133         return apply_filters('em_categories_get', $categories, $args); 
     35    public static function get( $args = array() ){ 
     36        self::$instance = new EM_Categories(); 
     37        return parent::get($args); 
    13438    } 
    13539 
    136     public static function output( $args ){ 
    137         global $EM_Category; 
    138         $EM_Category_old = $EM_Category; //When looping, we can replace EM_Category global with the current event in the loop 
    139         //get page number if passed on by request (still needs pagination enabled to have effect) 
    140         $page_queryvar = !empty($args['page_queryvar']) ? $args['page_queryvar'] : 'pno'; 
    141         if( !array_key_exists('page',$args) && !empty($args['pagination']) && !empty($_REQUEST[$page_queryvar]) && is_numeric($_REQUEST[$page_queryvar]) ){ 
    142             $page = $args['page'] = $_REQUEST[$page_queryvar]; 
    143         } 
    144         //Can be either an array for the get search or an array of EM_Category objects 
    145         if( is_object(current($args)) && get_class((current($args))) == 'EM_Category' ){ 
    146             $func_args = func_get_args(); 
    147             $categories = $func_args[0]; 
    148             $args = (!empty($func_args[1])) ? $func_args[1] : array(); 
    149             $args = apply_filters('em_categories_output_args', self::get_default_search($args), $categories); 
    150             $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false; 
    151             $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0; 
    152             $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1; 
    153         }else{ 
    154             $args = apply_filters('em_categories_output_args', self::get_default_search($args) ); 
    155             $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false; 
    156             $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0; 
    157             $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1; 
    158             $args['limit'] = $args['offset'] = $args['page'] = false; //we count overall categories here 
    159             $categories = self::get( $args ); 
    160             $args['limit'] = $limit; 
    161             $args['offset'] = $offset; 
    162             $args['page'] = $page; 
    163         } 
    164         //What format shall we output this to, or use default 
    165         $format = ( $args['format'] == '' ) ? get_option( 'dbem_categories_list_item_format' ) : $args['format'] ; 
    166          
    167         $output = ""; 
    168         $categories_count = count($categories); 
    169         $categories = apply_filters('em_categories_output_categories', $categories); 
    170         if ( count($categories) > 0 ) { 
    171             $category_count = 0; 
    172             $categories_shown = 0; 
    173             foreach ( $categories as $EM_Category ) { 
    174                 if( ($categories_shown < $limit || empty($limit)) && ($category_count >= $offset || $offset === 0) ){ 
    175                     $output .= $EM_Category->output($format); 
    176                     $categories_shown++; 
    177                 } 
    178                 $category_count++; 
    179             } 
    180             //Add headers and footers to output 
    181             if( $format == get_option( 'dbem_categories_list_item_format' ) ){ 
    182                 //we're using the default format, so if a custom format header or footer is supplied, we can override it, if not use the default 
    183                 $format_header = empty($args['format_header']) ? get_option('dbem_categories_list_item_format_header') : $args['format_header']; 
    184                 $format_footer = empty($args['format_footer']) ? get_option('dbem_categories_list_item_format_footer') : $args['format_footer']; 
    185             }else{ 
    186                 //we're using a custom format, so if a header or footer isn't specifically supplied we assume it's blank 
    187                 $format_header = !empty($args['format_header']) ? $args['format_header'] : '' ; 
    188                 $format_footer = !empty($args['format_footer']) ? $args['format_footer'] : '' ; 
    189             } 
    190             $output =  $format_header .  $output . $format_footer; 
    191             //Pagination (if needed/requested) 
    192             if( !empty($args['pagination']) && !empty($limit) && $categories_count >= $limit ){ 
    193                 //Show the pagination links (unless there's less than 10 events, or the custom limit) 
    194                 $output .= self::get_pagination_links($args, $categories_count); 
    195             } 
    196         } else { 
    197             $output = get_option ( 'dbem_no_categories_message' ); 
    198         } 
    199         //FIXME check if reference is ok when restoring object, due to changes in php5 v 4 
    200         $EM_Category_old= $EM_Category; 
    201         return apply_filters('em_categories_output', $output, $categories, $args);       
     40    public static function output( $args = array() ){ 
     41        self::$instance = new EM_Categories(); 
     42        return parent::output($args); 
    20243    } 
    20344     
    20445    public static function get_pagination_links($args, $count, $search_action = 'search_cats', $default_args = array()){ 
    205         //get default args if we're in a search, supply to parent since we can't depend on late static binding until WP requires PHP 5.3 or later 
    206         if( empty($default_args) && (!empty($args['ajax']) || !empty($_REQUEST['action']) && $_REQUEST['action'] == $search_action) ){ 
    207             $default_args = self::get_default_search(); 
    208             $default_args['limit'] = get_option('dbem_categories_default_limit'); 
    209         } 
     46        self::$instance = new EM_Categories(); 
    21047        return parent::get_pagination_links($args, $count, $search_action, $default_args); 
    21148    } 
    21249 
    21350    public static function get_post_search($args = array(), $filter = false, $request = array(), $accepted_args = array()){ 
    214         //supply $accepted_args to parent argument since we can't depend on late static binding until WP requires PHP 5.3 or later 
    215         $accepted_args = !empty($accepted_args) ? $accepted_args : array_keys(self::get_default_search()); 
    216         return apply_filters('em_tags_get_post_search', parent::get_post_search($args, $filter, $request, $accepted_args)); 
     51        self::$instance = new EM_Categories(); 
     52        return parent::get_post_search($args, $filter, $request, $accepted_args); 
    21753    } 
    21854     
    219     function has( $search ){ 
    220         if( is_numeric($search) ){ 
    221             foreach($this->categories as $EM_Category){ 
    222                 if($EM_Category->term_id == $search) return apply_filters('em_categories_has', true, $search, $this); 
    223             } 
    224         }else{ 
    225             foreach($this->categories as $EM_Category){ 
    226                 if($EM_Category->slug == $search || $EM_Category->name == $search ) return apply_filters('em_categories_has', true, $search, $this); 
    227             }            
    228         } 
    229         return apply_filters('em_categories_has', false, $search, $this); 
     55    public static function get_default_search( $array_or_defaults = array(), $array = array() ){ 
     56        self::$instance = new EM_Categories(); 
     57        return parent::get_default_search($defaults,$array); 
    23058    } 
    231      
    232     function get_first(){ 
    233         foreach($this->categories as $EM_Category){ 
    234             return $EM_Category; 
    235         } 
    236         return false; 
    237     } 
    238      
    239     function get_ids(){ 
    240         $ids = array(); 
    241         foreach($this->categories as $EM_Category){ 
    242             if( !empty($EM_Category->term_id) ){ 
    243                 $ids[] = $EM_Category->term_id; 
    244             } 
    245         } 
    246         return $ids;     
    247     } 
    248      
    249     /** 
    250      * Gets the event for this object, or a blank event if none exists 
    251      * @return EM_Event 
    252      */ 
    253     function get_event(){ 
    254         if( is_numeric($this->event_id) ){ 
    255             return em_get_event($this->event_id); 
    256         }else{ 
    257             return new EM_Event(); 
    258         } 
    259     } 
    260      
    261     /*  
    262      * Adds custom calendar search defaults 
    263      * @param array $array_or_defaults may be the array to override defaults 
    264      * @param array $array 
    265      * @return array 
    266      * @uses EM_Object#get_default_search() 
    267      */ 
    268     public static function get_default_search( $array_or_defaults = array(), $array = array() ){ 
    269         $defaults = array( 
    270             //added from get_terms, so they don't get filtered out 
    271             'orderby' => get_option('dbem_categories_default_orderby'), 'order' => get_option('dbem_categories_default_order'), 
    272             'hide_empty' => false, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 
    273             'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 
    274             'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 
    275             'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core'      
    276         ); 
    277         //sort out whether defaults were supplied or just the array of search values 
    278         if( empty($array) ){ 
    279             $array = $array_or_defaults; 
    280         }else{ 
    281             $defaults = array_merge($defaults, $array_or_defaults); 
    282         } 
    283         return apply_filters('em_categories_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults); 
    284     } 
    285  
    286     //Iterator Implementation 
    287     public function rewind(){ 
    288         reset($this->categories); 
    289     }   
    290     public function current(){ 
    291         $var = current($this->categories); 
    292         return $var; 
    293     }   
    294     public function key(){ 
    295         $var = key($this->categories); 
    296         return $var; 
    297     }   
    298     public function next(){ 
    299         $var = next($this->categories); 
    300         return $var; 
    301     }   
    302     public function valid(){ 
    303         $key = key($this->categories); 
    304         $var = ($key !== NULL && $key !== FALSE); 
    305         return $var; 
    306     } 
    30759} 
  • events-manager/trunk/classes/em-category.php

    r1694715 r1720802  
    11<?php 
     2class 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 = false, $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 
    224/** 
    325 * Get an category in a db friendly way, by checking globals and passed variables to avoid extra class instantiations 
    426 * @param mixed $id 
    527 * @return EM_Category 
     28 * @uses EM_Category::get() 
    629 */ 
    7 function em_get_category($id = false) { 
    8     global $EM_Category; 
    9     //check if it's not already global so we don't instantiate again 
    10     if( is_object($EM_Category) && get_class($EM_Category) == 'EM_Category' ){ 
    11         if( $EM_Category->term_id == $id ){ 
    12             return $EM_Category; 
    13         }elseif( is_object($id) && $EM_Category->term_id == $id->term_id ){ 
    14             return $EM_Category; 
    15         } 
    16     } 
    17     if( is_object($id) && get_class($id) == 'EM_Category' ){ 
    18         return $id; 
    19     }else{ 
    20         return new EM_Category($id); 
    21     } 
     30function em_get_category( $id = false ) { 
     31    return EM_Category::get($id); 
    2232} 
    23 class EM_Category extends EM_Taxonomy { 
    24      
    25     public $option_name = 'category'; 
    26      
    27     /** 
    28      * Gets data from POST (default), supplied array, or from the database if an ID is supplied 
    29      * @param $category_data 
    30      * @return null 
    31      */ 
    32     function __construct( $category_data = false ) { 
    33         global $wpdb; 
    34         self::ms_global_switch(); 
    35         //Initialize 
    36         $category = array(); 
    37         if( !empty($category_data) ){ 
    38             //Load category data 
    39             if( is_object($category_data) && !empty($category_data->taxonomy) && $category_data->taxonomy == EM_TAXONOMY_CATEGORY ){ 
    40                 $category = $category_data; 
    41             }elseif( !is_numeric($category_data) ){ 
    42                 $category = get_term_by('slug', $category_data, EM_TAXONOMY_CATEGORY); 
    43                 if( !$category ){ 
    44                     $category = get_term_by('name', $category_data, EM_TAXONOMY_CATEGORY);                   
    45                 } 
    46             }else{       
    47                 $category = get_term_by('id', $category_data, EM_TAXONOMY_CATEGORY); 
    48             } 
    49         } 
    50         if( is_object($category) || is_array($category) ){ 
    51             foreach($category as $key => $value){ 
    52                 $this->$key = $value; 
    53             } 
    54         } 
    55         $this->id = $this->term_id; //backward compatability 
    56         self::ms_global_switch_back(); 
    57         do_action('em_category',$this, $category_data); 
    58     } 
    59      
    60     function get_url(){ 
    61         if( empty($this->link) ){ 
    62             self::ms_global_switch(); 
    63             $this->link = get_term_link($this->slug, EM_TAXONOMY_CATEGORY); 
    64             self::ms_global_switch_back(); 
    65             if ( is_wp_error($this->link) ) $this->link = ''; 
    66         } 
    67         return apply_filters('em_category_get_url', $this->link); 
    68     } 
    69  
    70     function get_ical_url(){ 
    71         global $wp_rewrite; 
    72         if( !empty($wp_rewrite) && $wp_rewrite->using_permalinks() ){ 
    73             $return = trailingslashit($this->get_url()).'ical/'; 
    74         }else{ 
    75             $return = em_add_get_params($this->get_url(), array('ical'=>1)); 
    76         } 
    77         return apply_filters('em_category_get_ical_url', $return); 
    78     } 
    79  
    80     function get_rss_url(){ 
    81         global $wp_rewrite; 
    82         if( !empty($wp_rewrite) && $wp_rewrite->using_permalinks() ){ 
    83             $return = trailingslashit($this->get_url()).'feed/'; 
    84         }else{ 
    85             $return = em_add_get_params($this->get_url(), array('feed'=>1)); 
    86         } 
    87         return apply_filters('em_category_get_rss_url', $return); 
    88     } 
    89      
    90     /** 
    91      * deprecated, don't use. 
    92      * @return mixed 
    93      */ 
    94     function has_events(){ 
    95         global $wpdb; 
    96         return false; 
    97     } 
    98      
    99     function output_single($target = 'html'){ 
    100         $format = get_option ( 'dbem_category_page_format' ); 
    101         return apply_filters('em_category_output_single', $this->output($format, $target), $this, $target);  
    102     } 
    103      
    104     function output($format, $target="html") { 
    105         preg_match_all('/\{([a-zA-Z0-9_]+)\}([^{]+)\{\/[a-zA-Z0-9_]+\}/', $format, $conditionals); 
    106         if( count($conditionals[0]) > 0 ){ 
    107             //Check if the language we want exists, if not we take the first language there 
    108             foreach($conditionals[1] as $key => $condition){ 
    109                 $format = str_replace($conditionals[0][$key], apply_filters('em_category_output_condition', '', $condition, $conditionals[0][$key], $this), $format); 
    110             } 
    111         } 
    112         $category_string = $format;       
    113         preg_match_all("/(#@?_?[A-Za-z0-9]+)({([a-zA-Z0-9,]+)})?/", $format, $placeholders); 
    114         $replaces = array(); 
    115         foreach($placeholders[1] as $key => $result) { 
    116             $replace = ''; 
    117             $full_result = $placeholders[0][$key]; 
    118             switch( $result ){ 
    119                 case '#_CATEGORYNAME': 
    120                     $replace = $this->name; 
    121                     break; 
    122                 case '#_CATEGORYID': 
    123                     $replace = $this->term_id; 
    124                     break; 
    125                 case '#_CATEGORYNOTES': 
    126                 case '#_CATEGORYDESCRIPTION': 
    127                     $replace = $this->description; 
    128                     break; 
    129                 case '#_CATEGORYIMAGEURL': 
    130                     $replace = esc_url($this->get_image_url()); 
    131                     break; 
    132                 case '#_CATEGORYIMAGE': 
    133                     $replace = $this->placeholder_image($replace, $placeholders, $key); 
    134                     break; 
    135                 case '#_CATEGORYCOLOR': 
    136                     $replace = $this->get_color();  
    137                     break; 
    138                 case '#_CATEGORYLINK': 
    139                 case '#_CATEGORYURL': 
    140                     $link = $this->get_url(); 
    141                     $replace = ($result == '#_CATEGORYURL') ? $link : '<a href="'.$link.'">'.esc_html($this->name).'</a>'; 
    142                     break; 
    143                 case '#_CATEGORYICALURL': 
    144                 case '#_CATEGORYICALLINK': 
    145                     $replace = $this->get_ical_url(); 
    146                     if( $result == '#_CATEGORYICALLINK' ){ 
    147                         $replace = '<a href="'.esc_url($replace).'">iCal</a>'; 
    148                     } 
    149                     break; 
    150                 case '#_CATEGORYRSSURL': 
    151                 case '#_CATEGORYRSSLINK': 
    152                     $replace = $this->get_rss_url(); 
    153                     if( $result == '#_CATEGORYRSSLINK' ){ 
    154                         $replace = '<a href="'.esc_url($replace).'">RSS</a>'; 
    155                     } 
    156                     break; 
    157                 case '#_CATEGORYSLUG': 
    158                     $replace = $this->slug; 
    159                     break; 
    160                 case '#_CATEGORYEVENTSPAST': //deprecated, erroneous documentation, left for compatability 
    161                 case '#_CATEGORYEVENTSNEXT': //deprecated, erroneous documentation, left for compatability 
    162                 case '#_CATEGORYEVENTSALL': //deprecated, erroneous documentation, left for compatability 
    163                 case '#_CATEGORYPASTEVENTS': 
    164                 case '#_CATEGORYNEXTEVENTS': 
    165                 case '#_CATEGORYALLEVENTS': 
    166                     //convert deprecated placeholders for compatability 
    167                     $result = ($result == '#_CATEGORYEVENTSPAST') ? '#_CATEGORYPASTEVENTS':$result;  
    168                     $result = ($result == '#_CATEGORYEVENTSNEXT') ? '#_CATEGORYNEXTEVENTS':$result; 
    169                     $result = ($result == '#_CATEGORYEVENTSALL') ? '#_CATEGORYALLEVENTS':$result; 
    170                     //forget it ever happened? :/ 
    171                     if ($result == '#_CATEGORYPASTEVENTS'){ $scope = 'past'; } 
    172                     elseif ( $result == '#_CATEGORYNEXTEVENTS' ){ $scope = 'future'; } 
    173                     else{ $scope = 'all'; }                  
    174                     $events_count = EM_Events::count( array('category'=>$this->term_id, 'scope'=>$scope) ); 
    175                     if ( $events_count > 0 ){ 
    176                         $args = array('category'=>$this->term_id, 'scope'=>$scope, 'pagination'=>1, 'ajax'=>0); 
    177                         $args['format_header'] = get_option('dbem_category_event_list_item_header_format'); 
    178                         $args['format_footer'] = get_option('dbem_category_event_list_item_footer_format'); 
    179                         $args['format'] = get_option('dbem_category_event_list_item_format'); 
    180                         $args['limit'] = get_option('dbem_category_event_list_limit'); 
    181                         $args['page'] = (!empty($_REQUEST['pno']) && is_numeric($_REQUEST['pno']) )? $_REQUEST['pno'] : 1; 
    182                         $replace = EM_Events::output($args); 
    183                     } else { 
    184                         $replace = get_option('dbem_category_no_events_message','</ul>'); 
    185                     } 
    186                     break; 
    187                 case '#_CATEGORYNEXTEVENT': 
    188                     $events = EM_Events::get( array('category'=>$this->term_id, 'scope'=>'future', 'limit'=>1, 'orderby'=>'event_start_date,event_start_time') ); 
    189                     $replace = get_option('dbem_category_no_event_message'); 
    190                     foreach($events as $EM_Event){ 
    191                         $replace = $EM_Event->output(get_option('dbem_category_event_single_format')); 
    192                     } 
    193                     break; 
    194                 default: 
    195                     $replace = $full_result; 
    196                     break; 
    197             } 
    198             $replaces[$full_result] = apply_filters('em_category_output_placeholder', $replace, $this, $full_result, $target); 
    199         } 
    200         krsort($replaces); 
    201         foreach($replaces as $full_result => $replacement){ 
    202             $category_string = str_replace($full_result, $replacement , $category_string ); 
    203         } 
    204         return apply_filters('em_category_output', $category_string, $this, $format, $target);   
    205     } 
    206      
    207     function can_manage( $capability_owner = 'edit_categories', $capability_admin = false, $user_to_check = false ){ 
    208         global $em_capabilities_array; 
    209         //Figure out if this is multisite and require an extra bit of validation 
    210         $multisite_check = true; 
    211         $can_manage = current_user_can($capability_owner); 
    212         //if multisite and supoer admin, just return true 
    213         if( is_multisite() && is_super_admin() ){ return true; } 
    214         if( EM_MS_GLOBAL && !is_main_site() ){ 
    215             //User can't admin this bit, as they're on a sub-blog 
    216             $can_manage = false; 
    217             if(array_key_exists($capability_owner, $em_capabilities_array) ){ 
    218                 $this->add_error( $em_capabilities_array[$capability_owner]); 
    219             } 
    220         } 
    221         return $can_manage; 
    222     } 
    223 } 
    224 ?> 
  • events-manager/trunk/classes/em-event-post-admin.php

    r1651260 r1720802  
    162162                    $sql = $wpdb->prepare("UPDATE ".EM_EVENTS_TABLE." SET event_name=%s, event_owner=%d, event_slug=%s, event_status={$event_status}, event_private=%d WHERE event_id=%d", $where_array); 
    163163                    $wpdb->query($sql); 
    164                     if( $EM_Event->is_recurring() &&  $EM_Event->is_published()){ 
     164                    if( $EM_Event->is_recurring() && ($EM_Event->is_published() || (defined('EM_FORCE_RECURRENCES_SAVE') && EM_FORCE_RECURRENCES_SAVE)) ){ 
    165165                        //recurrences are (re)saved only if event is published 
    166166                        $EM_Event->save_events(); 
  • events-manager/trunk/classes/em-event-post.php

    r1694715 r1720802  
    1414            add_filter('the_content', array('EM_Event_Post','the_content')); 
    1515            add_filter('the_excerpt_rss', array('EM_Event_Post','the_excerpt_rss')); 
     16            //excerpts can trigger the_content which isn't ideal, so we disable the_content between the first and last excerpt calls within WP logic 
     17            add_filter('get_the_excerpt', array('EM_Event_Post','disable_the_content'), 1); 
     18            add_filter('get_the_excerpt', array('EM_Event_Post','enable_the_content'), 100); 
    1619            if( get_option('dbem_cp_events_excerpt_formats') ){ 
    17                 add_filter('the_excerpt', array('EM_Event_Post','the_excerpt')); 
     20                //important add this before wp_trim_excerpt hook, as it can screw up things like wp_editor() for WordPress SEO plugin 
     21                add_filter('get_the_excerpt', array('EM_Event_Post','get_the_excerpt')); 
    1822            } 
    1923            //display as page template? 
     
    9296     * Overrides the_excerpt if this is an event post type 
    9397     */ 
    94     public static function the_excerpt($content){ 
     98    public static function get_the_excerpt($content){ 
    9599        global $post; 
    96100        if( $post->post_type == EM_POST_TYPE_EVENT ){ 
     
    101105        return $content; 
    102106    } 
     107    public static function the_excerpt($content){ return self::get_the_excerpt($content); } 
    103108     
    104109    public static function the_excerpt_rss( $content ){ 
     
    112117        } 
    113118        return $content; 
     119    } 
     120     
     121    public static function enable_the_content(){ 
     122        add_filter('the_content', array('EM_Event_Post','the_content')); 
     123    } 
     124    public static function disable_the_content(){ 
     125        remove_filter('the_content', array('EM_Event_Post','the_content')); 
    114126    } 
    115127     
  • events-manager/trunk/classes/em-event-posts-admin.php

    r1694715 r1720802  
    2323            add_filter($row_action_type, array('EM_Event_Posts_Admin','row_actions'),10,2); 
    2424            add_action('admin_head', array('EM_Event_Posts_Admin','admin_head')); 
    25             //collumns 
    26             add_filter('manage_edit-'.EM_POST_TYPE_EVENT.'_columns' , array('EM_Event_Posts_Admin','columns_add')); 
    27             add_filter('manage_'.EM_POST_TYPE_EVENT.'_posts_custom_column' , array('EM_Event_Posts_Admin','columns_output'),10,2 ); 
    28             add_filter('manage_edit-'.EM_POST_TYPE_EVENT.'_sortable_columns', array('EM_Event_Posts_Admin','sortable_columns') ); 
    2925             
    3026            if( empty($_GET['orderby']) ) $_GET['orderby'] = 'date-time'; 
    3127            if( empty($_GET['order']) ) $_GET['order'] = 'asc'; 
    3228        } 
     29        //collumns 
     30        add_filter('manage_edit-'.EM_POST_TYPE_EVENT.'_columns' , array('EM_Event_Posts_Admin','columns_add')); 
     31        add_filter('manage_'.EM_POST_TYPE_EVENT.'_posts_custom_column' , array('EM_Event_Posts_Admin','columns_output'),10,2 ); 
     32        add_filter('manage_edit-'.EM_POST_TYPE_EVENT.'_sortable_columns', array('EM_Event_Posts_Admin','sortable_columns') ); 
    3333        //clean up the views in the admin selection area - WIP 
    3434        //add_filter('views_edit-'.EM_POST_TYPE_EVENT, array('EM_Event_Posts_Admin','restrict_views'),10,2); 
     
    296296            add_action('admin_notices',array('EM_Event_Recurring_Posts_Admin','admin_notices')); 
    297297            add_action('admin_head', array('EM_Event_Recurring_Posts_Admin','admin_head')); 
    298             //collumns 
    299             add_filter('manage_edit-event-recurring_columns' , array('EM_Event_Recurring_Posts_Admin','columns_add')); 
    300             add_filter('manage_posts_custom_column' , array('EM_Event_Recurring_Posts_Admin','columns_output'),10,1 ); 
    301             add_action('restrict_manage_posts', array('EM_Event_Posts_Admin','restrict_manage_posts')); 
    302             add_filter( 'manage_edit-event-recurring_sortable_columns', array('EM_Event_Posts_Admin','sortable_columns') ); 
    303298            //actions 
    304299            $row_action_type = is_post_type_hierarchical( EM_POST_TYPE_EVENT ) ? 'page_row_actions' : 'post_row_actions'; 
    305300            add_filter($row_action_type, array('EM_Event_Recurring_Posts_Admin','row_actions'),10,2); 
    306301        } 
     302        //collumns 
     303        add_filter('manage_edit-event-recurring_columns' , array('EM_Event_Recurring_Posts_Admin','columns_add')); 
     304        add_filter('manage_posts_custom_column' , array('EM_Event_Recurring_Posts_Admin','columns_output'),10,1 ); 
     305        add_action('restrict_manage_posts', array('EM_Event_Posts_Admin','restrict_manage_posts')); 
     306        add_filter( 'manage_edit-event-recurring_sortable_columns', array('EM_Event_Posts_Admin','sortable_columns') ); 
    307307    } 
    308308     
  • events-manager/trunk/classes/em-event.php

    r1694715 r1720802  
    11<?php 
    22/** 
    3  * Get an event in a db friendly way, by checking globals and passed variables to avoid extra class instantiations 
     3 * Get an event in a db friendly way, by checking globals, cache and passed variables to avoid extra class instantiations. 
    44 * @param mixed $id 
    55 * @param mixed $search_by 
     
    2323        return apply_filters('em_get_event', $id); 
    2424    }else{ 
     25        //check the cache first 
     26        $event_id = false; 
     27        if( is_numeric($id) ){ 
     28            if( $search_by == 'event_id' ){ 
     29                $event_id = $id; 
     30            }elseif( $search_by == 'post_id' ){ 
     31                $event_id = wp_cache_get($id, 'em_events_ids'); 
     32            } 
     33        }elseif( !empty($id->ID) && !empty($id->post_type) && ($id->post_type == EM_POST_TYPE_EVENT || $id->post_type == 'event-recurring') ){ 
     34            $event_id = wp_cache_get($id->ID, 'em_events_ids'); 
     35        } 
     36        if( $event_id ){ 
     37            $event = wp_cache_get($event_id, 'em_events'); 
     38            if( is_object($event) && !empty($event->event_id) && $event->event_id){ 
     39                return apply_filters('em_get_event', $event); 
     40            } 
     41        } 
     42        //if we get this far, just create a new event 
    2543        return apply_filters('em_get_event', new EM_Event($id,$search_by)); 
    2644    } 
     
    113131        'recurrence_rsvp_days' => array( 'name'=>'recurrence_rsvp_days', 'type'=>'%d', 'null'=>true ), //days before or after start date to generat bookings cut-off date 
    114132    ); 
    115     var $post_fields = array('event_slug','event_owner','event_name','event_attributes','post_id','post_content'); //fields that won't be taken from the em_events table anymore 
    116     var $recurrence_fields = array('recurrence_interval', 'recurrence_freq', 'recurrence_days', 'recurrence_byday', 'recurrence_byweekno'); 
     133    var $post_fields = array('event_slug','event_owner','event_name','event_private','event_status','event_attributes','post_id','post_content'); //fields that won't be taken from the em_events table anymore 
     134    var $recurrence_fields = array('recurrence', 'recurrence_interval', 'recurrence_freq', 'recurrence_days', 'recurrence_byday', 'recurrence_byweekno', 'recurrence_rsvp_days'); 
    117135     
    118136    var $image_url = ''; 
     
    286304            1 => __('Approved','events-manager') 
    287305        ); 
     306        //add this event to the cache 
     307        if( $this->event_id && $this->post_id ){ 
     308            wp_cache_set($this->event_id, $this, 'em_events'); 
     309            wp_cache_set($this->post_id, $this->event_id, 'em_events_ids'); 
     310        } 
    288311        do_action('em_event', $this, $id, $search_by); 
     312    } 
     313     
     314    /** 
     315     * When cloning this event, we get rid of the bookings and location objects, since they can be retrieved again from the cache instead.  
     316     */ 
     317    public function __clone(){ 
     318        $this->bookings = null; 
     319        $this->location = null; 
    289320    } 
    290321     
     
    371402            $this->end = strtotime($this->event_end_date." ".$this->event_end_time, current_time('timestamp')); 
    372403        } 
     404        if( empty($this->location_id) && !empty($this->event_id) ) $this->location_id = 0; //just set location_id to 0 and avoid any doubt 
    373405    } 
    374406     
     
    380412            restore_current_blog(); 
    381413            $this->blog_id = $blog_id; 
     414        }elseif( EM_MS_GLOBAL ){ 
     415            $this->ms_global_switch(); 
     416            $event_meta = get_post_meta($this->post_id); 
     417            $this->ms_global_switch_back(); 
    382418        }else{ 
    383419            $event_meta = get_post_meta($this->post_id); 
     
    409445        $this->get_post_meta(false); 
    410446        $result = $validate ? $this->validate():true; //validate both post and meta, otherwise return true 
    411         return apply_filters('em_event_get_post', $result, $this);       
     447        return apply_filters('em_event_get_post', $result, $this); 
    412448    } 
    413449     
     
    544580            if( empty($_POST['event_rsvp']) && $this->event_rsvp ) $deleting_bookings = true; 
    545581            $this->event_rsvp = 0; 
    546             $this->event_rsvp_time = '00:00:00'; 
     582            $this->event_rsvp_time = null; 
    547583        } 
    548584         
     
    557593                        $this->event_attributes[$att_key] = ''; 
    558594                        $att_vals = isset($event_available_attributes['values'][$att_key]) ? count($event_available_attributes['values'][$att_key]) : 0; 
    559                         if( !empty($att_value) ){ 
     595                        if( $att_value != '' ){ 
    560596                            if( $att_vals <= 1 || ($att_vals > 1 && in_array($att_value, $event_available_attributes['values'][$att_key])) ){ 
    561597                                $this->event_attributes[$att_key] = wp_unslash($att_value); 
    562598                            } 
    563599                        } 
    564                         if( empty($att_value) && $att_vals > 1){ 
     600                        if( $att_value != '' && $att_vals > 1){ 
    565601                            $this->event_attributes[$att_key] = wp_unslash(wp_kses($event_available_attributes['values'][$att_key][0], $allowedtags)); 
    566602                        } 
     
    648684                $this->recurring_reschedule = $this->recurring_recreate_bookings = true; 
    649685            } 
     686        }else{ 
     687            foreach( $this->recurrence_fields as $recurrence_field ){ 
     688                $this->$recurrence_field = null; 
     689            } 
    650690        } 
    651691        //categories in MS GLobal 
     
    841881            } 
    842882            //Update Post Meta 
     883            $current_meta_values = $this->get_event_meta(); 
    843884            foreach( $this->fields as $key => $field_info ){ 
     885                //certain keys will not be saved if not needed, including flags with a 0 value. Older databases using custom WP_Query calls will need to use an array of meta_query items using NOT EXISTS - OR - value=0 
    844886                if( !in_array($key, $this->post_fields) && $key != 'event_attributes' ){ 
    845                     update_post_meta($this->post_id, '_'.$key, $this->$key); 
     887                    //ignore certain fields and delete if not new 
     888                    $save_meta_key = true; 
     889                    $recurrence_array = array('recurrence_id', 'recurrence', 'recurrence_interval', 'recurrence_freq', 'recurrence_days', 'recurrence_byday', 'recurrence_byweekno', 'recurrence_rsvp_days'); 
     890                    if( !$this->is_recurring() && in_array($key, $recurrence_array) ) $save_meta_key = false; 
     891                    $ignore_zero_keys = array('location_id', 'group_id', 'event_all_day' ); 
     892                    if( in_array($key, $ignore_zero_keys) && empty($this->$key) ) $save_meta_key = false; 
     893                    if( $key == 'blog_id' ) $save_meta_key = false; //not needed, given postmeta is stored on the actual blog table in MultiSite 
     894                    //we don't need rsvp info if rsvp is not set, including the RSVP flag too 
     895                    if( empty($this->event_rsvp) && in_array($key, array('event_rsvp','event_rsvp_date', 'event_rsvp_time', 'event_rsvp_spaces', 'event_spaces')) ) $save_meta_key = false; 
     896                    //save key or ignore/delete key 
     897                    if( $save_meta_key ){ 
     898                        update_post_meta($this->post_id, '_'.$key, $this->$key); 
     899                    }elseif( array_key_exists('_'.$key, $current_meta_values) ){ 
     900                        //delete if this event already existed, in case this event already had the values before 
     901                        delete_post_meta($this->post_id, '_'.$key); 
     902                    } 
     903                }elseif( array_key_exists('_'.$key, $current_meta_values) && $key != 'event_attributes' ){ //we should delete event_attributes, but maybe something else uses it without us knowing 
     904                    delete_post_meta($this->post_id, '_'.$key); 
    846905                } 
    847906            } 
     
    851910                $this->event_attributes = maybe_unserialize($this->event_attributes); 
    852911                foreach( $atts['names'] as $event_attribute_key ){ 
    853                     if( !empty($this->event_attributes[$event_attribute_key]) ){ 
     912                    if( array_key_exists($event_attribute_key, $this->event_attributes) && $this->event_attributes[$event_attribute_key] != '' ){ 
    854913                        update_post_meta($this->post_id, $event_attribute_key, $this->event_attributes[$event_attribute_key]); 
    855914                    }else{ 
     
    9431002            $this->compat_keys(); //compatability keys, loaded before saving recurrences 
    9441003            //build recurrences if needed 
    945             if( $this->is_recurring() && $result && ($this->is_published() || $this->post_status == 'future') ){ //only save events if recurring event validates and is published or set for future 
     1004            if( $this->is_recurring() && $result && ($this->is_published() || $this->post_status == 'future' || (defined('EM_FORCE_RECURRENCES_SAVE') && EM_FORCE_RECURRENCES_SAVE)) ){ //only save events if recurring event validates and is published or set for future 
    9461005                global $EM_EVENT_SAVE_POST; 
    9471006                //If we're in WP Admin and this was called by EM_Event_Post_Admin::save_post, don't save here, it'll be done later in EM_Event_Recurring_Post_Admin::save_post 
     
    9571016            } 
    9581017        } 
    959         return apply_filters('em_event_save_meta', count($this->errors) == 0, $this); 
     1018        $result = count($this->errors) == 0; 
     1019        //add this event to the cache 
     1020        if( $result ){ 
     1021            wp_cache_set($this->event_id, $this, 'em_events'); 
     1022            wp_cache_set($this->post_id, $this->event_id, 'em_events_ids'); 
     1023        } 
     1024        return apply_filters('em_event_save_meta', $result, $this); 
    9601025    } 
    9611026     
     
    11531218            if($set_post_status){ 
    11541219                $wpdb->update( $wpdb->posts, array( 'post_status' => $post_status, 'post_name' => $this->post_name ), array( 'ID' => $this->post_id ) ); 
    1155             }elseif( $set_post_name ){ 
     1220            }elseif( !empty($set_post_name) ){ 
    11561221                //if we've added a post slug then update wp_posts anyway 
    11571222                $wpdb->update( $wpdb->posts, array( 'post_name' => $this->post_name ), array( 'ID' => $this->post_id ) ); 
     
    12951360     
    12961361    /** 
     1362     * Deprecated - use $this->get_bookings()->get_spaces() instead. 
    12971363     * Gets number of spaces in this event, dependent on ticket spaces or hard limit, whichever is smaller. 
    12981364     * @param boolean $force_refresh 
     
    14001466            } 
    14011467        } 
    1402         return apply_filters('em_event_is_free',$free,$this); 
     1468        return apply_filters('em_event_is_free',$free, $this, $now); 
    14031469    } 
    14041470     
     
    14451511        $attributes = em_get_attributes(); 
    14461512        foreach($results[0] as $resultKey => $result) { 
     1513            //check that we haven't mistakenly captured a closing bracket in second bracket set 
     1514            if( !empty($results[3][$resultKey]) && $results[3][$resultKey][0] == '/' ){ 
     1515                $result = $results[0][$resultKey] = str_replace($results[2][$resultKey], '', $result); 
     1516                $results[3][$resultKey] = $results[2][$resultKey] = ''; 
     1517            } 
    14471518            //Strip string of placeholder and just leave the reference 
    14481519            $attRef = substr( substr($result, 0, strpos($result, '}')), 6 ); 
     
    19412012                    } 
    19422013                    break; 
     2014                case '#_EVENTWEBCALURL': 
     2015                case '#_EVENTWEBCALLINK': 
     2016                    $replace = $this->get_ical_url(); 
     2017                    $replace = str_replace(array('http://','https://'), 'webcal://', $replace); 
     2018                    if( $result == '#_EVENTWEBCALLINK' ){ 
     2019                        $replace = '<a href="'.esc_url($replace).'">webcal</a>'; 
     2020                    } 
     2021                    break; 
    19432022                case '#_EVENTGCALURL': 
    19442023                case '#_EVENTGCALLINK': 
     
    21022181     
    21032182    /** 
    2104      * Gets the event recurrence template, which is an EM_Event_Recurrence object (based off an event-recurring post) 
    2105      * @return EM_Event_Recurrence 
     2183     * Gets the event recurrence template, which is an EM_Event object (based off an event-recurring post) 
     2184     * @return EM_Event 
    21062185     */ 
    21072186    function get_event_recurrence(){ 
    21082187        if(!$this->is_recurring()){ 
    2109             return new EM_Event($this->recurrence_id); //remember, recurrence_id is a post! 
     2188            return em_get_event($this->recurrence_id, 'event_id'); 
    21102189        }else{ 
    21112190            return $this; 
     
    21302209            //remove recurrence id from post meta and index table 
    21312210            $url = $this->get_attach_url($this->recurrence_id); 
    2132             $wpdb->update(EM_EVENTS_TABLE, array('recurrence_id'=>0), array('event_id' => $this->event_id)); 
    2133             update_post_meta($this->post_id, '_recurrence_id', 0); 
     2211            $wpdb->update(EM_EVENTS_TABLE, array('recurrence_id'=>null), array('event_id' => $this->event_id)); 
     2212            update_post_meta($this->post_id, '_recurrence_id', null); 
    21342213            $this->feedback_message = __('Event detached.','events-manager') . ' <a href="'.$url.'">'.__('Undo','events-manager').'</a>'; 
    21352214            $this->recurrence_id = 0; 
     
    21632242    function save_events() { 
    21642243        global $wpdb; 
    2165         $event_ids = $post_ids = array(); 
    2166         if( $this->can_manage('edit_events','edit_others_events') && ($this->is_published() || 'future' == $this->post_status) ){ 
     2244        $event_ids = $post_ids = $event_dates = array(); 
     2245        if( !$this->can_manage('edit_events','edit_others_events') ) return apply_filters('em_event_save_events', false, $this, $event_ids, $post_ids); 
     2246        if( ($this->is_published() || 'future' == $this->post_status) ){ 
    21672247            //check if there's any events already created, if not (such as when an event is first submitted for approval and then published), force a reschedule. 
    21682248            if( $wpdb->get_var('SELECT COUNT(event_id) FROM '.EM_EVENTS_TABLE.' WHERE recurrence_id='. absint($this->event_id)) == 0 ){ 
     
    21902270            if( isset($meta_fields['_post_id']) ) unset($meta_fields['_post_id']); //legacy bugfix, post_id was never needed in meta table 
    21912271            //remove recurrence meta info we won't need in events 
    2192             foreach( array_keys($this->recurrence_fields) as $recurrence_field){ 
    2193                 unset($event[$recurrence_field]); 
     2272            foreach( $this->recurrence_fields as $recurrence_field){ 
     2273                $event[$recurrence_field] = null; 
    21942274                unset($meta_fields['_'.$recurrence_field]); 
    21952275            } 
    21962276            //Set the recurrence ID 
    21972277            $event['recurrence_id'] = $meta_fields['_recurrence_id'] = $this->event_id; 
    2198             $event['recurrence'] = $meta_fields['_recurrence'] = 0; 
     2278            $event['recurrence'] = 0; 
    21992279             
    22002280            //Let's start saving! 
     
    22112291                    foreach( $matching_days as $day ) { 
    22122292                        //rewrite post fields if needed 
    2213                         $post_fields['post_name'] = $event['event_slug'] = $meta_fields['_event_slug'] = apply_filters('em_event_save_events_slug', $post_name.'-'.date($recurring_date_format, $day), $post_fields, $day, $matching_days, $this); 
     2293                        $post_fields['post_name'] = $event['event_slug'] = apply_filters('em_event_save_events_slug', $post_name.'-'.date($recurring_date_format, $day), $post_fields, $day, $matching_days, $this); 
    22142294                        //adjust certain meta information 
    22152295                        $event['event_start_date'] = $meta_fields['_event_start_date'] = date("Y-m-d", $day); 
     
    22712351                foreach($EM_Events as $EM_Event){ /* @var $EM_Event EM_Event */ 
    22722352                    $event_ids[$EM_Event->post_id] = $EM_Event->event_id; 
     2353                    $event_dates[$EM_Event->event_id] = $EM_Event->start; 
    22732354                    $post_ids[] = $EM_Event->post_id; 
    22742355                    //do we need to change the slugs? 
    2275                     $post_fields['post_name'] = $event['event_slug'] = $meta_fields['_event_slug'] = apply_filters('em_event_save_events_slug', $post_name.'-'.date($recurring_date_format, $EM_Event->start), $post_fields, $EM_Event->start, array(), $this); 
     2356                    $post_fields['post_name'] = $event['event_slug'] = apply_filters('em_event_save_events_slug', $post_name.'-'.date($recurring_date_format, $EM_Event->start), $post_fields, $EM_Event->start, array(), $this); 
    22762357                    //adjust certain meta information relativv 
    22772358                    if( !empty($event['recurrence_rsvp_days']) && is_numeric($event['recurrence_rsvp_days']) ){ 
     
    24162497            } 
    24172498            return apply_filters('em_event_save_events', !in_array(false, $event_saves) && $result !== false, $this, $event_ids, $post_ids); 
     2499        }elseif( !$this->is_published() && $this->get_previous_status() != $this->get_status() && defined('EM_FORCE_RECURRENCES_SAVE') && EM_FORCE_RECURRENCES_SAVE ){ 
     2500            $this->set_status_events($this->get_status()); 
    24182501        } 
    24192502        return apply_filters('em_event_save_events', false, $this, $event_ids, $post_ids); 
     
    25602643    function set_status_events($status){ 
    25612644        //give sub events same status 
    2562         $events_array = EM_Events::get( array('recurrence_id'=>$this->post_id, 'scope'=>'all', 'status'=>false ) ); 
    2563         foreach($events_array as $EM_Event){ 
    2564             /* @var $EM_Event EM_Event */ 
    2565             if($EM_Event->recurrence_id == $this->event_id){ 
    2566                 $EM_Event->set_status($status); 
    2567             } 
    2568         } 
     2645        global $wpdb; 
     2646        $this->ms_global_switch(); 
     2647        //get post and event ids of recurrences 
     2648        $post_ids = $event_ids = array(); 
     2649        $events_array = EM_Events::get( array('recurrence'=>$this->event_id, 'scope'=>'all', 'status'=>false, 'array'=>true) ); //only get recurrences that aren't trashed or drafted 
     2650        foreach( $events_array as $event_array ){ 
     2651            $post_ids[] = absint($event_array['post_id']); 
     2652            $event_ids[] = absint($event_array['event_id']); 
     2653        } 
     2654        if( !empty($post_ids) ){ 
     2655            //decide on what status to set and update wp_posts in the process 
     2656            if($status === null){  
     2657                $set_status='NULL'; //draft post 
     2658                $post_status = 'draft'; //set post status in this instance 
     2659            }elseif( $status == -1 ){ //trashed post 
     2660                $set_status = -1; 
     2661                $post_status = 'trash'; //set post status in this instance 
     2662            }else{ 
     2663                $set_status = $status ? 1:0; //published or pending post 
     2664                $post_status = $set_status ? 'publish':'pending'; 
     2665            } 
     2666            $result = $wpdb->query( $wpdb->prepare("UPDATE ".$wpdb->posts." SET post_status=%s WHERE ID IN (". implode(',', $post_ids) .')', array($post_status)) ); 
     2667            $result = $result && $wpdb->query( $wpdb->prepare("UPDATE ".EM_EVENTS_TABLE." SET event_status=%s WHERE event_id IN (". implode(',', $event_ids) .')', array($set_status)) ); 
     2668        } 
     2669        $this->ms_global_switch_back(); 
     2670        return apply_filters('em_event_set_status_events', $result !== false, $status, $this, $event_ids, $post_ids); 
    25692671    } 
    25702672     
  • events-manager/trunk/classes/em-events.php

    r1651260 r1720802  
    88     
    99    /** 
     10     * Like WPDB->num_rows it holds the number of results found on the last query. 
     11     * @var int 
     12     */ 
     13    public static $num_rows; 
     14     
     15    /** 
     16     * If $args['pagination'] is true or $args['offset'] or $args['page'] is greater than one, and a limit is imposed when using a get() query,  
     17     * this will contain the total records found without a limit for the last query. 
     18     * If no limit was used or pagination was not enabled, this will be the same as self::$num_rows 
     19     * @var int 
     20     */ 
     21    public static $num_rows_found; 
     22     
     23    /** 
    1024     * Returns an array of EM_Events that match the given specs in the argument, or returns a list of future evetnts in future  
    1125     * (see EM_Events::get_default_search() ) for explanation of possible search array values. You can also supply a numeric array 
     
    3448        $limit = ( $args['limit'] && is_numeric($args['limit'])) ? "LIMIT {$args['limit']}" : ''; 
    3549        $offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : ''; 
    36         $groupby_sql = array(); 
    37          
    38         //Get the default conditions 
    39         $conditions = self::build_sql_conditions($args); 
    40         //Put it all together 
    41         $where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):''; 
    42          
    43         //Get ordering instructions 
     50         
     51        //Get fields that we can use in ordering and grouping, which can be event and location (excluding ambiguous) fields 
    4452        $EM_Event = new EM_Event(); 
    4553        $EM_Location = new EM_Location(); 
    46         $orderby = self::build_sql_orderby($args, array_keys(array_merge($EM_Event->fields, $EM_Location->fields)), get_option('dbem_events_default_order')); 
    47         //Now, build orderby sql 
    48         $orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : ''; 
     54        $event_fields = array_keys($EM_Event->fields); 
     55        $location_fields = array(); //will contain location-specific fields, not ambiguous ones 
     56        foreach( array_keys($EM_Location->fields) as $field_name ){ 
     57            if( !in_array($field_name, $event_fields) ) $location_fields[] = $field_name; 
     58        } 
     59        $accepted_fields = array_merge($event_fields, $location_fields); 
    4960         
    5061        //Create the SQL statement and execute 
    51          
    52         if( !$count && $args['array'] ){ 
    53             $selectors_array = array(); 
    54             foreach( array_keys($EM_Event->fields) as $field_selector){ 
    55                 $selectors_array[] = $events_table.'.'.$field_selector; 
    56             } 
    57             $selectors = implode(',', $selectors_array); 
    58         }elseif( EM_MS_GLOBAL ){ 
    59             $selectors = $events_table.'.post_id, '.$events_table.'.blog_id'; 
    60             $groupby_sql[] = $events_table.'.post_id, '. $events_table.'.blog_id'; 
    61         }else{ 
    62             $selectors = $events_table.'.post_id'; 
    63             $groupby_sql[] = $events_table.'.post_id'; //prevent duplicates showing in lists 
    64         } 
     62        $calc_found_rows = $limit && ( $args['pagination'] || $args['offset'] > 0 || $args['page'] > 0 ); 
    6563        if( $count ){ 
    66             $selectors = 'SQL_CALC_FOUND_ROWS *'; 
     64            $selectors = 'COUNT(DISTINCT '.$events_table . '.event_id)'; 
    6765            $limit = 'LIMIT 1'; 
    6866            $offset = 'OFFSET 0'; 
    69         } 
    70          
    71         //add group_by if needed 
    72         $groupby_sql = !empty($groupby_sql) && is_array($groupby_sql) ? 'GROUP BY '.implode(',', $groupby_sql):'';  
    73          
    74         $sql = apply_filters('em_events_get_sql'," 
    75             SELECT $selectors FROM $events_table 
    76             LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id 
    77             $where 
    78             $groupby_sql $orderby_sql 
    79             $limit $offset 
    80         ", $args); 
     67        }else{ 
     68            if( $args['array'] ){ 
     69                //get all fields from table, add events table prefix to avoid ambiguous fields from location 
     70                $selectors = $events_table . '.*'; 
     71            }elseif( EM_MS_GLOBAL ){ 
     72                $selectors = $events_table.'.post_id, '.$events_table.'.blog_id'; 
     73            }else{ 
     74                $selectors = $events_table.'.post_id'; 
     75            } 
     76            if( $calc_found_rows ) $selectors = 'SQL_CALC_FOUND_ROWS ' . $selectors; //for storing total rows found 
     77            $selectors = 'DISTINCT ' . $selectors; //duplicate avoidance 
     78        } 
     79         
     80        //check if we need to join a location table for this search, which is necessary if any location-specific are supplied, or if certain arguments such as orderby contain location fields 
     81        if( !empty($args['groupby']) || (defined('EM_DISABLE_OPTIONAL_JOINS') && EM_DISABLE_OPTIONAL_JOINS) ){ 
     82            $location_specific_args = array('town', 'state', 'country', 'region', 'near', 'geo', 'search'); 
     83            $join_locations = false; 
     84            foreach( $location_specific_args as $arg ) if( !empty($args[$arg]) ) $join_locations = true; 
     85            //if set to false the following would provide a false negative in the line above 
     86            if( $args['location_status'] !== false ){ $join_locations = true; } 
     87            //check ordering and grouping arguments for precense of location fields requiring a join 
     88            if( !$join_locations ){ 
     89                foreach( array('groupby', 'orderby', 'groupby_orderby') as $arg ){ 
     90                    if( !is_array($args[$arg]) ) continue; //ignore this argument if set to false 
     91                    //we assume all these arguments are now array thanks to self::get_search_defaults() cleaning it up 
     92                    foreach( $args[$arg] as $field_name ){ 
     93                        if( in_array($field_name, $location_fields) ){ 
     94                            $join_locations = true; 
     95                            break; //we join, no need to keep searching 
     96                        } 
     97                    } 
     98                } 
     99            } 
     100        }else{ $join_locations = true; }//end temporary if( !empty($args['groupby']).... wrapper 
     101        //plugins can override this optional joining behaviour here in case they add custom WHERE conditions or something like that 
     102        $join_locations = apply_filters('em_events_get_join_locations_table', $join_locations, $args, $count); 
     103        //depending on whether to join we do certain things like add a join SQL, change specific values like status search 
     104        $location_optional_join = $join_locations ? "LEFT JOIN $locations_table ON {$locations_table}.location_id={$events_table}.location_id" : ''; 
     105        $args['location_status'] = $args['location_status'] === false ? $join_locations : $args['location_status']; //if we're joining events table, by default we want status to match that of locations in this search 
     106         
     107        //Build ORDER BY and WHERE SQL statements here, after we've done all the pre-processing necessary 
     108        $conditions = self::build_sql_conditions($args); 
     109        $where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):''; 
     110        $orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')); 
     111        $orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : ''; 
     112         
     113        //Build GROUP BY SQL statement, which will be very different if we group things due to how we need to filter out by event date 
     114        if( !empty($args['groupby']) ){ 
     115            //get groupby field(s) 
     116            $groupby_fields = self::build_sql_groupby($args, $accepted_fields); 
     117            if( !empty($groupby_fields[0]) ){ 
     118                //we can safely assume we've been passed at least one array item with index of 0 containing a valid field due to build_sql_groupby() 
     119                $groupby_field = $groupby_fields[0]; //we only support one field for events 
     120                $groupby_orderby = self::build_sql_groupby_orderby($args, $accepted_fields); 
     121                $groupby_orderby_sql = !empty($groupby_orderby) ? ', '. implode(', ', $groupby_orderby) : ''; 
     122                //get minimum required selectors within the inner query to shorten query length as much as possible 
     123                $inner_selectors = $events_table . '.*'; 
     124                if( $location_optional_join ){ 
     125                    //we're selecting all fields from events table so add only location fields required in the outer ORDER BY statement 
     126                    foreach( $args['orderby'] as $orderby_field ){ 
     127                        if( in_array($orderby_field, $location_fields) ){ 
     128                            $inner_selectors .= ', '. $locations_table .'.'. $orderby_field; 
     129                        } 
     130                    } 
     131                } 
    81132                 
    82         //If we're only counting results, return the number of results 
     133                //THE Query - Grouped 
     134                if( in_array($groupby_field, $location_fields) || count(array_intersect($location_fields, $args['groupby_orderby'])) || defined('EM_FORCE_GROUPED_DATASET_SQL') ){ 
     135                    //if we're grouping by any fields in the locations table, we run a different (slightly slower) query to provide reliable results 
     136                    if( in_array($groupby_field, $location_fields) && !in_array($groupby_field, $args['orderby']) ){ 
     137                        //we may not have included the grouped field if it's not in the outer ORDER BY clause, so we add it for this specific query 
     138                        $inner_selectors .= ', '. $locations_table .'.'. $groupby_field; 
     139                    } 
     140                    $sql = " 
     141SELECT $selectors 
     142FROM ( 
     143    SELECT *, 
     144        @cur := IF($groupby_field = @id, @cur+1, 1) AS RowNumber, 
     145        @id := $groupby_field AS IdCache 
     146    FROM ( 
     147        SELECT {$inner_selectors} FROM {$events_table} 
     148        $location_optional_join 
     149        $where 
     150        ORDER BY $groupby_field $groupby_orderby_sql 
     151    ) {$events_table} 
     152    INNER JOIN ( 
     153        SELECT @id:=0, @cur:=0 
     154    ) AS lookup 
     155) {$events_table} 
     156WHERE RowNumber = 1 
     157$orderby_sql 
     158$limit $offset"; 
     159                }else{ 
     160                    //we'll keep this query simply because it's a little faster and still seems reliable when not grouping or group-sorting any fields in the locations table 
     161                    $sql = " 
     162SELECT $selectors 
     163FROM ( 
     164    SELECT {$inner_selectors}, 
     165        @cur := IF($groupby_field = @id, @cur+1, 1) AS RowNumber, 
     166        @id := $groupby_field AS IdCache 
     167    FROM {$events_table} 
     168    INNER JOIN ( 
     169        SELECT @id:=0, @cur:=0 
     170    ) AS lookup 
     171    $location_optional_join 
     172    $where 
     173    ORDER BY {$groupby_field} $groupby_orderby_sql 
     174) {$events_table} 
     175WHERE RowNumber = 1 
     176$orderby_sql 
     177$limit $offset"; 
     178                } 
     179            } 
     180        } 
     181         
     182        //Build THE Query SQL statement if not already built for a grouped query 
     183        if( empty($sql) ){ 
     184            //THE Query 
     185            $sql = " 
     186SELECT $selectors FROM $events_table 
     187$location_optional_join 
     188$where 
     189$orderby_sql 
     190$limit $offset"; 
     191        } 
     192         
     193        //THE Query filter 
     194        $sql = apply_filters('em_events_get_sql', $sql, $args); 
     195        //if( em_wp_is_super_admin() && WP_DEBUG_DISPLAY ){ echo "<pre>"; print_r($sql); echo '</pre>'; } 
     196                 
     197        //If we're only counting results, return the number of results and go no further 
    83198        if( $count ){ 
    84             $wpdb->query($sql); 
    85             return apply_filters('em_events_get_count', $wpdb->get_var('SELECT FOUND_ROWS()'), $args);       
    86         } 
     199            self::$num_rows_found = self::$num_rows = $wpdb->get_var($sql); 
     200            return apply_filters('em_events_get_count', self::$num_rows, $args);         
     201        } 
     202         
     203        //get the result and count results 
    87204        $results = $wpdb->get_results( $sql, ARRAY_A); 
     205        self::$num_rows = $wpdb->num_rows; 
     206        if( $calc_found_rows ){ 
     207            self::$num_rows_found = $wpdb->get_var('SELECT FOUND_ROWS()'); 
     208        }else{ 
     209            self::$num_rows_found = self::$num_rows; 
     210        } 
    88211 
    89212        //If we want results directly in an array, why not have a shortcut here? 
     
    161284        $page_queryvar = !empty($args['page_queryvar']) ? $args['page_queryvar'] : 'pno'; 
    162285        if( !empty($args['pagination']) && !array_key_exists('page',$args) && !empty($_REQUEST[$page_queryvar]) && is_numeric($_REQUEST[$page_queryvar]) ){ 
    163             $page = $args['page'] = $_REQUEST[$page_queryvar]; 
     286            $args['page'] = $_REQUEST[$page_queryvar]; 
    164287        } 
    165288        //Can be either an array for the get search or an array of EM_Event objects 
     
    170293            $args = apply_filters('em_events_output_args', self::get_default_search($args), $events); 
    171294            $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false; 
    172             $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0; 
    173             $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1; 
    174295            $events_count = count($events); 
    175296        }else{ 
     
    177298            $args = apply_filters('em_events_output_args', self::get_default_search($args)); 
    178299            $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false; 
    179             $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0; 
    180             $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1; 
    181             $args_count = $args; 
    182             $args_count['limit'] = false; 
    183             $args_count['offset'] = false; 
    184             $args_count['page'] = false; 
    185             $events_count = self::count($args_count); 
    186300            $events = self::get( $args ); 
     301            $events_count = self::$num_rows_found; 
    187302        } 
    188303        //What format shall we output this to, or use default 
     
    190305         
    191306        $output = ""; 
    192         $events = apply_filters('em_events_output_events', $events); 
     307         
    193308        if ( $events_count > 0 ) { 
     309            $events = apply_filters('em_events_output_events', $events); 
    194310            foreach ( $events as $EM_Event ) { 
    195311                $output .= $EM_Event->output($format); 
     
    210326                $output .= self::get_pagination_links($args, $events_count); 
    211327            } 
    212         } else { 
    213             $output = get_option ( 'dbem_no_events_message' ); 
    214         }    
     328        }elseif( $args['no_results_msg'] !== false ){ 
     329            $output = !empty($args['no_results_msg']) ? $args['no_results_msg'] : get_option('dbem_no_events_message'); 
     330        } 
    215331         
    216332        //TODO check if reference is ok when restoring object, due to changes in php5 v 4 
     
    242358        $args['mode'] = !empty($args['mode']) ? $args['mode'] : get_option('dbem_event_list_groupby'); 
    243359        $args['header_format'] = !empty($args['header_format']) ? $args['header_format'] :  get_option('dbem_event_list_groupby_header_format', '<h2>#s</h2>'); 
     360        $args['date_format'] = !empty($args['date_format']) ? $args['date_format'] :  get_option('dbem_event_list_groupby_format',''); 
    244361        //Reset some vars for counting events and displaying set arrays of events 
    245362        $atts = (array) $args; 
     
    348465                echo self::get_pagination_links($args, $events_count, 'search_events_grouped'); 
    349466            } 
    350         }else{ 
    351             echo get_option ( 'dbem_no_events_message' ); 
     467        }elseif( $args['no_results_msg'] !== false ){ 
     468            echo !empty($args['no_results_msg']) ? $args['no_results_msg'] : get_option('dbem_no_events_message'); 
    352469        } 
    353470        return ob_get_clean(); 
     
    393510        self::$context = EM_POST_TYPE_EVENT; 
    394511        global $wpdb; 
     512        //continue with conditions 
    395513        $conditions = parent::build_sql_conditions($args); 
    396514        if( !empty($args['search']) ){ 
     
    401519            $like_search_sql = "(".implode(" LIKE %s OR ", $like_search). "  LIKE %s)"; 
    402520            $conditions['search'] = $wpdb->prepare($like_search_sql, $like_search_strings); 
    403         } 
    404         $conditions['status'] = "(`event_status` >= 0 )"; //shows pending & published if not defined 
    405         if( array_key_exists('status',$args) ){ 
    406             if( is_numeric($args['status']) ){ 
    407                 $conditions['status'] = "(`event_status`={$args['status']})"; //pending or published 
    408             }elseif( $args['status'] == 'pending' ){ 
    409                 $conditions['status'] = "(`event_status`=0)"; //pending 
    410             }elseif( $args['status'] == 'publish' ){ 
    411                 $conditions['status'] = "(`event_status`=1)"; //published 
    412             }elseif( $args['status'] === null || $args['status'] == 'draft' ){ 
    413                 $conditions['status'] = "(`event_status` IS NULL )"; //show draft items 
    414             }elseif( $args['status'] == 'trash' ){ 
    415                 $conditions['status'] = "(`event_status` = -1 )"; //show trashed items 
    416             }elseif( $args['status'] == 'all'){ 
    417                 $conditions['status'] = "(`event_status` >= 0 OR `event_status` IS NULL)"; //search all statuses that aren't trashed 
    418             }elseif( $args['status'] == 'everything'){ 
    419                 unset($conditions['status']); //search all statuses 
    420             } 
    421521        } 
    422522        //private events 
     
    441541            } 
    442542        } 
    443         if( $args['bookings'] === 'user' && is_user_logged_in()){ 
    444             //get bookings of user 
    445             $EM_Person = new EM_Person(get_current_user_id()); 
    446             $booking_ids = $EM_Person->get_bookings(true); 
    447             if( count($booking_ids) > 0 ){ 
    448                 $conditions['bookings'] = "(event_id IN (SELECT event_id FROM ".EM_BOOKINGS_TABLE." WHERE booking_id IN (".implode(',',$booking_ids).")))"; 
    449             }else{ 
    450                 $conditions['bookings'] = "(event_id = 0)"; 
    451             } 
    452         } 
    453543        //post search 
    454544        if( !empty($args['post_id'])){ 
     
    468558    } 
    469559     
    470     /* Overrides EM_Object method to apply a filter to result 
    471      * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_orderby() 
     560    /** 
     561     * Overrides EM_Object method to clean ambiguous fields and apply a filter to result. 
     562     * @see EM_Object::build_sql_orderby() 
    472563     */ 
    473564    public static function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){ 
    474         self::$context = EM_POST_TYPE_EVENT; 
    475565        $accepted_fields[] = 'event_date_modified'; 
    476566        $accepted_fields[] = 'event_date_created'; 
    477         return apply_filters( 'em_events_build_sql_orderby', parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')), $args, $accepted_fields, $default_order ); 
     567        $orderby = parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')); 
     568        $orderby = self::build_sql_ambiguous_fields_helper($orderby); //fix ambiguous fields 
     569        return apply_filters( 'em_events_build_sql_orderby', $orderby, $args, $accepted_fields, $default_order ); 
     570    } 
     571     
     572    /** 
     573     * Overrides EM_Object method to clean ambiguous fields and apply a filter to result. 
     574     * @see EM_Object::build_sql_groupby() 
     575     */ 
     576    public static function build_sql_groupby( $args, $accepted_fields, $groupby_order = false, $default_order = 'ASC' ){ 
     577        $accepted_fields[] = 'event_date_modified'; 
     578        $accepted_fields[] = 'event_date_created'; 
     579        $groupby = parent::build_sql_groupby($args, $accepted_fields); 
     580        //fix ambiguous fields and give them scope of events table 
     581        $groupby = self::build_sql_ambiguous_fields_helper($groupby); 
     582        return apply_filters( 'em_events_build_sql_groupby', $groupby, $args, $accepted_fields ); 
     583    } 
     584     
     585    /** 
     586     * Overrides EM_Object method to clean ambiguous fields and apply a filter to result. 
     587     * @see EM_Object::build_sql_groupby_orderby() 
     588     */ 
     589    public static function build_sql_groupby_orderby($args, $accepted_fields, $default_order = 'ASC' ){ 
     590        $accepted_fields[] = 'event_date_modified'; 
     591        $accepted_fields[] = 'event_date_created'; 
     592        $group_orderby = parent::build_sql_groupby_orderby($args, $accepted_fields, get_option('dbem_events_default_order')); 
     593        //fix ambiguous fields and give them scope of events table 
     594        $group_orderby = self::build_sql_ambiguous_fields_helper($group_orderby); 
     595        return apply_filters( 'em_events_build_sql_groupby_orderby', $group_orderby, $args, $accepted_fields, $default_order ); 
     596    } 
     597     
     598    /** 
     599     * Overrides EM_Object method to provide specific reserved fields and events table. 
     600     * @see EM_Object::build_sql_ambiguous_fields_helper() 
     601     */ 
     602    protected static function build_sql_ambiguous_fields_helper( $fields, $reserved_fields = array(), $prefix = 'table_name' ){ 
     603        //This will likely be removed when PHP 5.3 is the minimum and LSB is a given 
     604        return parent::build_sql_ambiguous_fields_helper($fields, array('post_id', 'location_id', 'blog_id'), EM_EVENTS_TABLE); 
    478605    } 
    479606     
     
    488615        self::$context = EM_POST_TYPE_EVENT; 
    489616        $defaults = array( 
     617            'recurring' => false, //we don't initially look for recurring events 
    490618            'orderby' => get_option('dbem_events_default_orderby'), 
    491619            'order' => get_option('dbem_events_default_order'), 
    492             'bookings' => false, //if set to true, only events with bookings enabled are returned 
     620            'groupby' => false, 
     621            'groupby_orderby' => 'event_start_date, event_start_time', //groups according to event start time, i.e. by default shows earliest event in a scope 
     622            'groupby_order' => 'ASC', //groups according to event start time, i.e. by default shows earliest event in a scope 
    493623            'status' => 1, //approved events only 
    494624            'town' => false, 
     
    496626            'country' => false, 
    497627            'region' => false, 
    498             'has_location' => false, 
    499             'no_location' => false, 
    500628            'blog' => get_current_blog_id(), 
    501629            'private' => current_user_can('read_private_events'), 
    502630            'private_only' => false, 
    503             'post_id' => false 
     631            'post_id' => false, 
     632            //event-specific search attributes 
     633            'has_location' => false, //search events with a location 
     634            'no_location' => false, //search events without a location 
     635            'location_status' => false //search events with locations of a specific publish status 
    504636        ); 
    505637        //sort out whether defaults were supplied or just the array of search values 
     
    515647            } 
    516648        } 
     649        //admin-area specific modifiers 
    517650        if( is_admin() && !defined('DOING_AJAX') ){ 
    518651            //figure out default owning permissions 
  • events-manager/trunk/classes/em-location-post.php

    r1234828 r1720802  
    88            //override excerpts? 
    99            if( get_option('dbem_cp_locations_excerpt_formats') ){ 
    10                 add_filter('the_excerpt', array('EM_Location_Post','the_excerpt')); 
     10                add_filter('get_the_excerpt', array('EM_Location_Post','the_excerpt'), 9); 
    1111            } 
     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); 
    1215            //display as page or other template? 
    1316            if( get_option('dbem_cp_locations_template') ){ 
     
    6972     * Overrides the_excerpt if this is an location post type 
    7073     */ 
    71     public static function the_excerpt($content){ 
     74    public static function get_the_excerpt($content){ 
    7275        global $post; 
    7376        if( $post->post_type == EM_POST_TYPE_LOCATION ){ 
     
    7780        } 
    7881        return $content; 
     82    } 
     83    public static function the_excerpt($content){ return self::get_the_excerpt($content); } 
     84     
     85    public static function enable_the_content(){ 
     86        add_filter('the_content', array('EM_Location_Post','the_content')); 
     87    } 
     88    public static function disable_the_content(){ 
     89        remove_filter('the_content', array('EM_Location_Post','the_content')); 
    7990    } 
    8091     
  • events-manager/trunk/classes/em-location.php

    r1694715 r1720802  
    11<?php 
    22/** 
    3  * gets a location 
     3 * Get an event in a db friendly way, by checking globals, cache and passed variables to avoid extra class instantiations. 
    44 * @param mixed $id 
    55 * @param mixed $search_by 
     
    77 */ 
    88function em_get_location($id = false, $search_by = 'location_id') { 
     9    global $EM_Location; 
     10    //check if it's not already global so we don't instantiate again 
     11    if( is_object($EM_Location) && get_class($EM_Location) == 'EM_Location' ){ 
     12        if( is_object($id) && $EM_Location->post_id == $id->ID ){ 
     13            return apply_filters('em_get_location', $EM_Location); 
     14        }elseif( !is_object($id) ){ 
     15            if( $search_by == 'location_id' && $EM_Location->location_id == $id ){ 
     16                return apply_filters('em_get_location', $EM_Location); 
     17            }elseif( $search_by == 'post_id' && $EM_Location->post_id == $id ){ 
     18                return apply_filters('em_get_location', $EM_Location); 
     19            } 
     20        } 
     21    } 
    922    if( is_object($id) && get_class($id) == 'EM_Location' ){ 
    1023        return apply_filters('em_get_location', $id); 
    1124    }else{ 
     25        //check the cache first 
     26        $location_id = false; 
     27        if( is_numeric($id) ){ 
     28            if( $search_by == 'location_id' ){ 
     29                $location_id = $id; 
     30            }elseif( $search_by == 'post_id' ){ 
     31                $location_id = wp_cache_get($id, 'em_locations_ids'); 
     32            } 
     33        }elseif( !empty($id->ID) && !empty($id->post_type) && $id->post_type == EM_POST_TYPE_LOCATION ){ 
     34            $location_id = wp_cache_get($id->ID, 'em_locations_ids'); 
     35        } 
     36        if( $location_id ){ 
     37            $location = wp_cache_get($location_id, 'em_locations'); 
     38            if( is_object($location) && !empty($location->location_id) && $location->location_id){ 
     39                return apply_filters('em_get_location', $location); 
     40            } 
     41        } 
    1242        return apply_filters('em_get_location', new EM_Location($id,$search_by)); 
    1343    } 
     
    5484        'location_status' => array('name'=>'status','type'=>'%d', 'null'=>true) 
    5585    ); 
    56     var $post_fields = array('post_id','location_slug','location_name','post_content','location_owner'); 
     86    var $post_fields = array('post_id','location_slug','location_status', 'location_name','post_content','location_owner'); 
    5787    var $location_attributes = array(); 
    5888    var $image_url = ''; 
     
    145175        } 
    146176        $this->compat_keys(); 
     177        //add this location to the cache 
     178        if( $this->location_id && $this->post_id ){ 
     179            wp_cache_set($this->location_id, $this, 'em_locations'); 
     180            wp_cache_set($this->post_id, $this->location_id, 'em_locations_ids'); 
     181        } 
    147182        do_action('em_location', $this, $id, $search_by); 
    148183    } 
     
    366401            } 
    367402            //Update Post Meta 
     403            $current_meta_values = get_post_meta($this->post_id); 
    368404            foreach( array_keys($this->fields) as $key ){ 
    369                 if( !in_array($key, $this->post_fields) ){ 
     405                if( !in_array($key, $this->post_fields) && $key != 'blog_id' && $this->$key != '' ){ 
    370406                    update_post_meta($this->post_id, '_'.$key, $this->$key); 
     407                }elseif( array_key_exists('_'.$key, $current_meta_values) ){ //we should delete event_attributes, but maybe something else uses it without us knowing 
     408                    delete_post_meta($this->post_id, '_'.$key); 
    371409                } 
    372410            } 
     
    427465        } 
    428466        $this->compat_keys(); 
     467        $result = count($this->errors) == 0; 
     468        //add this location to the cache 
     469        if( $result ){ 
     470            wp_cache_set($this->location_id, $this, 'em_locations'); 
     471            wp_cache_set($this->post_id, $this->location_id, 'em_locations_ids'); 
     472        } 
    429473        return apply_filters('em_location_save_meta', count($this->errors) == 0, $this); 
    430474    } 
     
    506550            if($set_post_status){ 
    507551                $wpdb->update( $wpdb->posts, array( 'post_status' => $post_status, 'post_name' => $this->post_name ), array( 'ID' => $this->post_id ) ); 
    508             }elseif( $set_post_name ){ 
     552            }elseif( !empty($set_post_name) ){ 
    509553                //if we've added a post slug then update wp_posts anyway 
    510554                $wpdb->update( $wpdb->posts, array( 'post_name' => $this->post_name ), array( 'ID' => $this->post_id ) ); 
     
    571615    function has_events( $status = 1 ){ 
    572616        global $wpdb;    
    573         $events_table = EM_EVENTS_TABLE; 
    574         $sql = $wpdb->prepare("SELECT count(event_id) as events_no FROM $events_table WHERE location_id=%d AND event_status=%d", $this->location_id, $status); 
    575         $affected_events = $wpdb->get_var($sql); 
    576         return apply_filters('em_location_has_events', $affected_events > 0, $this); 
     617        $events_count = EM_Events::count(array('location_id' => $this->location_id, 'status' => $status)); 
     618        return apply_filters('em_location_has_events', $events_count > 0, $this); 
    577619    } 
    578620     
     
    897939                    } 
    898940                    break; 
     941                case '#_LOCATIONWEBCALURL': 
     942                case '#_LOCATIONWEBCALLINK': 
     943                    $replace = $this->get_ical_url(); 
     944                    $replace = str_replace(array('http://','https://'), 'webcal://', $replace); 
     945                    if( $result == '#_LOCATIONWEBCALLINK' ){ 
     946                        $replace = '<a href="'.esc_url($replace).'">Webcal</a>'; 
     947                    } 
     948                    break; 
    899949                case '#_LOCATIONRSSURL': 
    900950                case '#_LOCATIONRSSLINK': 
     
    919969                    elseif ( $result == '#_LOCATIONNEXTEVENTS' ){ $scope = 'future'; } 
    920970                    else{ $scope = 'all'; } 
    921                     $events_count = EM_Events::count( array('location'=>$this->location_id, 'scope'=>$scope) ); 
    922                     if ( $events_count > 0 ){ 
    923                         $args = array('location'=>$this->location_id, 'scope'=>$scope, 'pagination'=>1, 'ajax'=>0); 
    924                         $args['format_header'] = get_option('dbem_location_event_list_item_header_format'); 
    925                         $args['format_footer'] = get_option('dbem_location_event_list_item_footer_format'); 
    926                         $args['format'] = get_option('dbem_location_event_list_item_format'); 
    927                         $args['limit'] = get_option('dbem_location_event_list_limit'); 
    928                         $args['page'] = (!empty($_REQUEST['pno']) && is_numeric($_REQUEST['pno']) )? $_REQUEST['pno'] : 1; 
    929                         $replace = EM_Events::output($args); 
    930                     } else { 
    931                         $replace = get_option('dbem_location_no_events_message'); 
    932                     } 
     971                    $args = array('location'=>$this->location_id, 'scope'=>$scope, 'pagination'=>1, 'ajax'=>0); 
     972                    $args['format_header'] = get_option('dbem_location_event_list_item_header_format'); 
     973                    $args['format_footer'] = get_option('dbem_location_event_list_item_footer_format'); 
     974                    $args['format'] = get_option('dbem_location_event_list_item_format'); 
     975                    $args['no_results_msg'] = get_option('dbem_location_no_events_message'); 
     976                    $args['limit'] = get_option('dbem_location_event_list_limit'); 
     977                    $args['orderby'] = get_option('dbem_location_event_list_orderby'); 
     978                    $args['order'] = get_option('dbem_location_event_list_order'); 
     979                    $args['page'] = (!empty($_REQUEST['pno']) && is_numeric($_REQUEST['pno']) )? $_REQUEST['pno'] : 1; 
     980                    $replace = EM_Events::output($args); 
    933981                    break; 
    934982                case '#_LOCATIONNEXTEVENT': 
  • events-manager/trunk/classes/em-locations.php

    r1651260 r1720802  
    66 */ 
    77class EM_Locations extends EM_Object { 
     8     
     9    /** 
     10     * Like WPDB->num_rows it holds the number of results found on the last query. 
     11     * @var int 
     12     */ 
     13    public static $num_rows; 
     14     
     15    /** 
     16     * If $args['pagination'] is true or $args['offset'] or $args['page'] is greater than one, and a limit is imposed when using a get() query,  
     17     * this will contain the total records found without a limit for the last query. 
     18     * If no limit was used or pagination was not enabled, this will be the same as self::$num_rows 
     19     * @var int 
     20     */ 
     21    public static $num_rows_found; 
    822     
    923    /** 
     
    4155        $offset = ( $limit != "" && is_numeric($args['offset']) ) ? "OFFSET {$args['offset']}" : ''; 
    4256         
    43         //Get the default conditions 
    44         $conditions = self::build_sql_conditions($args); 
    45          
    46         //Put it all together 
    47         $where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):''; 
    48          
    49         //Get ordering instructions 
     57        //Get fields that we can use in ordering and grouping, which can be event and location (excluding ambiguous) fields 
    5058        $EM_Event = new EM_Event(); //blank event for below 
    5159        $EM_Location = new EM_Location(0); //blank location for below 
    52         $accepted_fields = $EM_Location->get_fields(true); 
    53         $accepted_fields = array_merge($EM_Event->get_fields(true),$accepted_fields); 
     60        $location_fields = array_keys($EM_Location->fields); 
     61        $event_fields = array(); //will contain event-specific fields, not ambiguous ones 
     62        foreach( array_keys($EM_Event->fields) as $field_name ){ 
     63            if( !in_array($field_name, $location_fields) ) $event_fields[] = $field_name; 
     64        } 
     65        $accepted_fields = array_merge($event_fields, $location_fields); 
     66 
     67        //add selectors 
     68        $calc_found_rows = $limit && ( $args['pagination'] || $args['offset'] > 0 || $args['page'] > 0 ); 
     69        if( $count ){ 
     70            $selectors = 'COUNT(DISTINCT '.$locations_table . '.location_id)'; //works in MS Global mode since location_id is always unique, post_id is not 
     71            $limit = 'LIMIT 1'; 
     72            $offset = 'OFFSET 0'; 
     73        }else{ 
     74            if( $args['array'] ){ 
     75                //get all fields from table, add events table prefix to avoid ambiguous fields from location 
     76                $selectors = $locations_table . '.*'; 
     77            }elseif( EM_MS_GLOBAL ){ 
     78                $selectors = $locations_table.'.post_id, '.$locations_table.'.blog_id'; 
     79            }else{ 
     80                $selectors = $locations_table.'.post_id'; 
     81            } 
     82            if( $calc_found_rows ) $selectors = 'SQL_CALC_FOUND_ROWS ' . $selectors; //for storing total rows found 
     83            $selectors = 'DISTINCT ' . $selectors; //duplicate avoidance 
     84        } 
     85         
     86        //check if we need to join a location table for this search, which is necessary if any location-specific are supplied, or if certain arguments such as orderby contain location fields 
     87        $join_events_table = false; 
     88        //for we only will check optional joining by default for groupby searches, and for the original searches if EM_DISABLE_OPTIONAL_JOINS is set to true in wp-config.php 
     89        if( !empty($args['groupby']) || (defined('EM_DISABLE_OPTIONAL_JOINS') && EM_DISABLE_OPTIONAL_JOINS) ){ 
     90            $event_specific_args = array('eventful', 'eventless', 'tag', 'category', 'event', 'recurrence', 'month', 'year', 'rsvp', 'bookings'); 
     91            $join_events_table = $args['scope'] != 'all'; //only value where false is not default so we check that first 
     92            foreach( $event_specific_args as $arg ) if( !empty($args[$arg]) ) $join_events_table = true; 
     93            //if set to false the following would provide a false negative in the line above 
     94            if( $args['recurrences'] !== null ) $join_events_table = true; 
     95            if( $args['recurring'] !== null ) $join_events_table = true; 
     96            if( $args['event_status'] !== false ){ $join_events_table = true; } 
     97            //check ordering and grouping arguments for precense of event fields requiring a join 
     98            if( !$join_events_table ){ 
     99                foreach( array('groupby', 'orderby', 'groupby_orderby') as $arg ){ 
     100                    if( !is_array($args[$arg]) ) continue; //ignore this argument if set to false 
     101                    //we assume all these arguments are now array thanks to self::get_search_defaults() cleaning it up 
     102                    foreach( $args[$arg] as $field_name ){ 
     103                        if( in_array($field_name, $event_fields) ){ 
     104                            $join_events_table = true; 
     105                            break; //we join, no need to keep searching 
     106                        } 
     107                    } 
     108                } 
     109            } 
     110            //EM_Events has a special argument for recurring events (the template), where it automatically omits recurring event templates. If we are searching events, and recurring was not explicitly set, we set it to the same as in EM_Events default  
     111            if( $join_events_table && $args['recurring'] === null ) $args['recurring'] = false; 
     112        }else{ $join_events_table = true; }//end temporary if( !empty($args['groupby']).... wrapper  
     113        //plugins can override this optional joining behaviour here in case they add custom WHERE conditions or something like that 
     114        $join_events_table = apply_filters('em_locations_get_join_events_table', $join_events_table, $args, $count); 
     115        //depending on whether to join we do certain things like add a join SQL, change specific values like status search 
     116        $event_optional_join = $join_events_table ? "LEFT JOIN $events_table ON {$locations_table}.location_id={$events_table}.location_id" : ''; 
     117        $args['event_status'] = $args['event_status'] === false ? $join_events_table : $args['event_status']; //if we're joining events table, by default we want status to match that of locations in this search  
     118         
     119        //Build ORDER BY and WHERE SQL statements here, after we've done all the pre-processing necessary 
     120        $conditions = self::build_sql_conditions($args); 
     121        $where = ( count($conditions) > 0 ) ? " WHERE " . implode ( " AND ", $conditions ):''; 
    54122        $orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')); 
    55         //Now, build orderby sql 
    56123        $orderby_sql = ( count($orderby) > 0 ) ? 'ORDER BY '. implode(', ', $orderby) : ''; 
    57124         
    58         if( EM_MS_GLOBAL ){ 
    59             $selectors = ( $count ) ?  'COUNT('.$locations_table.'.location_id)':$locations_table.'.post_id, '.$locations_table.'.blog_id'; 
    60         }else{ 
    61             $selectors = ( $count ) ?  'COUNT('.$locations_table.'.location_id)':$locations_table.'.post_id'; 
    62         } 
    63         //Create the SQL statement and execute 
    64         $sql = apply_filters('em_locations_get_sql', " 
    65             SELECT $selectors FROM $locations_table 
    66             LEFT JOIN $events_table ON {$locations_table}.location_id={$events_table}.location_id 
    67             $where 
    68             GROUP BY {$locations_table}.location_id 
    69             $orderby_sql 
    70             $limit $offset 
    71         ", $args); 
     125        //Build GROUP BY SQL statement, which will be very different if we group things due to how we need to filter out by event date 
     126        if( !empty($args['groupby']) ){ 
     127            //get groupby field(s) 
     128            $groupby_fields = self::build_sql_groupby($args, $accepted_fields); 
     129            if( !empty($groupby_fields[0]) ){ 
     130                //we can safely assume we've been passed at least one array item with index of 0 containing a valid field due to build_sql_groupby() 
     131                $groupby_field = $groupby_fields[0]; //we only support one field for events 
     132                $groupby_orderby = self::build_sql_groupby_orderby($args, $accepted_fields); 
     133                $groupby_orderby_sql = !empty($groupby_orderby) ? ', '. implode(', ', $groupby_orderby) : ''; 
     134                //get minimum required selectors within the inner query to shorten query length as much as possible 
     135                $inner_selectors = $locations_table . '.*'; 
     136                if( $event_optional_join ){ 
     137                    //we're selecting all fields from events table so add only location fields required in the outer ORDER BY statement 
     138                    if( in_array($groupby_field, $event_fields) && !in_array($groupby_field, $args['orderby']) ){ 
     139                        //we may not have included the grouped field if it's not in the outer ORDER BY clause, so we add it for this specific query 
     140                        $inner_selectors .= ', '. $events_table .'.'. $groupby_field; 
     141                    } 
     142                    foreach( $args['orderby'] as $orderby_field ){ 
     143                        if( in_array($orderby_field, $event_fields) ){ 
     144                            $inner_selectors .= ', '. $events_table .'.'. $orderby_field; 
     145                        } 
     146                    } 
     147                } 
     148                //THE Query - Grouped 
     149                $sql = " 
     150SELECT DISTINCT $selectors 
     151FROM ( 
     152    SELECT *, 
     153        @cur := IF($groupby_field = @id, @cur+1, 1) AS RowNumber, 
     154        @id := $groupby_field AS IdCache 
     155    FROM ( 
     156        SELECT {$inner_selectors} FROM {$locations_table} 
     157        $event_optional_join 
     158        $where 
     159        ORDER BY {$groupby_field} $groupby_orderby_sql 
     160    ) DataSet 
     161    INNER JOIN ( 
     162        SELECT @id:='', @cur:=0 
     163    ) AS lookup 
     164) {$locations_table} 
     165WHERE RowNumber = 1 
     166$orderby_sql 
     167$limit $offset"; 
     168            } 
     169        } 
     170 
     171        //build the SQL statement if not already built for group 
     172        if( empty($sql) ){ 
     173            //THE query 
     174            $sql = " 
     175SELECT DISTINCT $selectors FROM $locations_table 
     176$event_optional_join 
     177$where 
     178$orderby_sql 
     179$limit $offset 
     180            "; 
     181        } 
     182         
     183        //the query filter 
     184        $sql = apply_filters('em_locations_get_sql', $sql, $args);  
     185        //if( em_wp_is_super_admin() && WP_DEBUG_DISPLAY ){ echo "<pre>"; print_r($sql); echo '</pre>'; } 
    72186         
    73187        //If we're only counting results, return the number of results 
    74188        if( $count ){ 
    75             return apply_filters('em_locations_get_count', count($wpdb->get_col($sql)), $args);  
    76         } 
    77         $results = $wpdb->get_results($sql, ARRAY_A); 
    78          
     189            self::$num_rows_found = self::$num_rows = $wpdb->get_var($sql); 
     190            return apply_filters('em_locations_get_count', self::$num_rows, $args);  
     191        } 
     192         
     193        //get the result and count results 
     194        $results = $wpdb->get_results( $sql, ARRAY_A); 
     195        self::$num_rows = $wpdb->num_rows; 
     196        if( $calc_found_rows ){ 
     197            self::$num_rows_found = $wpdb->get_var('SELECT FOUND_ROWS()'); 
     198        }else{ 
     199            self::$num_rows_found = self::$num_rows; 
     200        } 
     201 
    79202        //If we want results directly in an array, why not have a shortcut here? 
    80203        if( $args['array'] == true ){ 
     
    110233        $page_queryvar = !empty($args['page_queryvar']) ? $args['page_queryvar'] : 'pno'; 
    111234        if( !empty($args['pagination']) && !array_key_exists('page',$args) && !empty($_REQUEST[$page_queryvar]) && is_numeric($_REQUEST[$page_queryvar]) ){ 
    112             $page = $args['page'] = $_REQUEST[$page_queryvar]; 
     235            $args['page'] = $_REQUEST[$page_queryvar]; 
    113236        } 
    114237        if( is_object(current($args)) && get_class((current($args))) == 'EM_Location' ){ 
     
    118241            $args = apply_filters('em_locations_output_args', self::get_default_search($args), $locations); 
    119242            $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false; 
    120             $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0; 
    121             $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1; 
    122243            $locations_count = count($locations); 
    123244        }else{ 
    124245            $args = apply_filters('em_locations_output_args', self::get_default_search($args) ); 
    125246            $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false; 
    126             $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0; 
    127             $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1; 
    128             $args_count = $args; 
    129             $args_count['limit'] = 0; 
    130             $args_count['offset'] = 0; 
    131             $args_count['page'] = 1; 
    132             $locations_count = self::count($args_count); 
    133247            $locations = self::get( $args ); 
     248            $locations_count = self::$num_rows_found; 
    134249        } 
    135250        //What format shall we output this to, or use default 
     
    159274                $output .= self::get_pagination_links($args, $locations_count); 
    160275            } 
    161         } else { 
    162             $output = get_option ( 'dbem_no_locations_message' ); 
     276        }elseif( $args['no_results_msg'] !== false ){ 
     277            $output = !empty($args['no_results_msg']) ? $args['no_results_msg'] : get_option('dbem_no_locations_message'); 
    163278        } 
    164279        //FIXME check if reference is ok when restoring object, due to changes in php5 v 4 
     
    226341        //eventful locations 
    227342        if( true == $args['eventful'] ){ 
    228             $conditions['eventful'] = "{$events_table}.event_id IS NOT NULL AND event_status=1"; 
     343            $conditions['eventful'] = "{$events_table}.event_id IS NOT NULL"; 
    229344        }elseif( true == $args['eventless'] ){ 
    230345            $conditions['eventless'] = "{$events_table}.event_id IS NULL"; 
     
    255370            } 
    256371        } 
    257         //status 
    258         $conditions['status'] = "(`location_status` >= 0)"; //pending and published if status is not explicitly defined (Default is 1) 
    259         if( array_key_exists('status',$args) ){  
    260             if( is_numeric($args['status']) ){ 
    261                 $conditions['status'] = "(`location_status`={$args['status']} )"; //trash (-1), pending, (0) or published (1) 
    262             }elseif( $args['status'] == 'pending' ){ 
    263                 $conditions['status'] = "(`location_status`=0)"; //pending 
    264             }elseif( $args['status'] == 'publish' ){ 
    265                 $conditions['status'] = "(`location_status`=1)"; //published 
    266             }elseif( $args['status'] === null || $args['status'] == 'draft' ){ 
    267                 $conditions['status'] = "(`location_status` IS NULL )"; //show draft items 
    268             }elseif( $args['status'] == 'trash' ){ 
    269                 $conditions['status'] = "(`location_status` = -1 )"; //show trashed items 
    270             }elseif( $args['status'] == 'all'){ 
    271                 $conditions['status'] = "(`location_status` >= 0 OR `location_status` IS NULL)"; //search all statuses that aren't trashed 
    272             }elseif( $args['status'] == 'everything'){ 
    273                 unset($conditions['status']); //search all statuses 
    274             } 
    275         } 
    276372        //private locations 
    277373        if( empty($args['private']) ){ 
     
    291387    } 
    292388     
    293     /* Overrides EM_Object method to apply a filter to result 
    294      * @see wp-content/plugins/events-manager/classes/EM_Object#build_sql_orderby() 
    295      */ 
    296     public static function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){ 
    297         self::$context = EM_POST_TYPE_LOCATION; 
    298         return apply_filters( 'em_locations_build_sql_orderby', parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')), $args, $accepted_fields, $default_order ); 
     389    /** 
     390     * Overrides EM_Object method to clean ambiguous fields and apply a filter to result. 
     391     * @see EM_Object::build_sql_orderby() 
     392     */ 
     393     public static function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){ 
     394        $orderby = parent::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')); 
     395        $orderby = self::build_sql_ambiguous_fields_helper($orderby); //fix ambiguous fields 
     396        return apply_filters( 'em_locations_build_sql_orderby', $orderby, $args, $accepted_fields, $default_order ); 
     397    } 
     398     
     399    /** 
     400     * Overrides EM_Object method to clean ambiguous fields and apply a filter to result. 
     401     * @see EM_Object::build_sql_groupby() 
     402     */ 
     403    public static function build_sql_groupby( $args, $accepted_fields, $groupby_order = false, $default_order = 'ASC' ){ 
     404        $groupby = parent::build_sql_groupby($args, $accepted_fields); 
     405        //fix ambiguous fields and give them scope of events table 
     406        $groupby = self::build_sql_ambiguous_fields_helper($groupby); 
     407        return apply_filters( 'em_locations_build_sql_groupby', $groupby, $args, $accepted_fields ); 
     408    } 
     409     
     410    /** 
     411     * Overrides EM_Object method to clean ambiguous fields and apply a filter to result. 
     412     * @see EM_Object::build_sql_groupby_orderby() 
     413     */ 
     414     public static function build_sql_groupby_orderby($args, $accepted_fields, $default_order = 'ASC' ){ 
     415        $group_orderby = parent::build_sql_groupby_orderby($args, $accepted_fields, get_option('dbem_events_default_order')); 
     416        //fix ambiguous fields and give them scope of events table 
     417        $group_orderby = self::build_sql_ambiguous_fields_helper($group_orderby); 
     418        return apply_filters( 'em_locations_build_sql_groupby_orderby', $group_orderby, $args, $accepted_fields, $default_order ); 
     419    } 
     420     
     421    /** 
     422     * Overrides EM_Object method to provide specific reserved fields and locations table. 
     423     * @see EM_Object::build_sql_ambiguous_fields_helper() 
     424     */ 
     425    protected static function build_sql_ambiguous_fields_helper( $fields, $reserved_fields = array(), $prefix = 'table_name' ){ 
     426        //This will likely be removed when PHP 5.3 is the minimum and LSB is a given 
     427        return parent::build_sql_ambiguous_fields_helper($fields, array('post_id', 'location_id', 'blog_id'), EM_LOCATIONS_TABLE); 
    299428    } 
    300429     
     
    309438        self::$context = EM_POST_TYPE_LOCATION; 
    310439        $defaults = array( 
    311             'eventful' => false, //Locations that have an event (scope will also play a part here 
    312             'eventless' => false, //Locations WITHOUT events, eventful takes precedence 
    313440            'orderby' => 'location_name', 
     441            'groupby' => false, 
     442            'groupby_orderby' => 'location_name', //groups according to event start time, i.e. by default shows earliest event in a scope 
     443            'groupby_order' => 'ASC', //groups according to event start time, i.e. by default shows earliest event in a scope 
    314444            'town' => false, 
    315445            'state' => false, 
     
    321451            'private' => current_user_can('read_private_locations'), 
    322452            'private_only' => false, 
    323             'post_id' => false 
     453            'post_id' => false, 
     454            //location-specific attributes 
     455            'eventful' => false, //Locations that have an event (scope will also play a part here 
     456            'eventless' => false, //Locations WITHOUT events, eventful takes precedence 
     457            'event_status' => false //search locations with events of a specific publish status 
    324458        ); 
    325459        //sort out whether defaults were supplied or just the array of search values 
  • events-manager/trunk/classes/em-object.php

    r1694715 r1720802  
    2929            'order' => 'ASC', //hard-coded at end of this function 
    3030            'orderby' => false, 
     31            'groupby' => false, 
     32            'groupby_orderby' => false, 
     33            'groupby_order' => 'ASC', 
    3134            'format' => '',  
    3235            'format_header' => '', //custom html above the list 
    3336            'format_footer' => '', //custom html below the list 
     37            'no_results_msg' => '', //default message if no results used in output() function 
    3438            'category' => 0, 
    3539            'tag' => 0, 
    3640            'location' => false, 
    37             'event' => false,  
     41            'event' => false, 
     42            'event_status' => false, //automatically set to 'status' value if in EM_Events, useful only for EM_Locations 
     43            'location_status' => false,  //automatically set to 'status' value if in EM_Locations, useful only for EM_Events 
    3844            'offset'=>0, 
    3945            'page'=>1,//basically, if greater than 0, calculates offset at end 
    4046            'page_queryvar'=>null, 
    41             'recurrence'=>0, 
    42             'recurrences'=>null, 
    43             'recurring'=>false, 
     47            'recurrence' => 0, //look for a specific recurrence by ID 
     48            'recurrences' => null, //if set, exclusively show (true) or omit (false) recurrences 
     49            'recurring' => null, //if set to 'include' it'll only show recurring event templates, if set to false, it'll omit them from results, null or true will include in results 
    4450            'month'=>'', 
    4551            'year'=>'', 
     
    4854            'owner'=>false, 
    4955            'rsvp'=>false, //deprecated for bookings 
    50             'bookings'=>false, 
     56            'bookings' => false, //if set to true, only events with bookings enabled are returned 
    5157            'search'=>false, 
    5258            'geo'=>false, //reserved for future searching via name 
     
    103109                $array['country'] = explode(',',$array['country']); 
    104110            } 
    105              
    106             //OrderBy - can be a comma-separated array of field names to order by (field names of object, not db) 
    107             if( array_key_exists('orderby', $array)){ 
    108                 if( !is_array($array['orderby']) && preg_match('/,/', $array['orderby']) ) { 
    109                     $array['orderby'] = explode(',', $array['orderby']); 
    110                 } 
    111             } 
    112111            //TODO validate search query array 
    113112            //Clean the supplied array, so we only have allowed keys 
     
    150149            } 
    151150        } 
    152         //Order - it's either ASC or DESC, so let's just validate 
    153         if( !is_array($defaults['order']) && preg_match('/,/', $defaults['order']) ) { 
    154             $defaults['order'] = explode(',', $defaults['order']); 
    155         }elseif( !in_array($defaults['order'], array('ASC','DESC','asc','desc')) ){ 
    156             $defaults['order'] = $super_defaults['order']; 
    157         } 
    158         //ORDER BY, split if an array 
    159         if( !is_array($defaults['orderby']) && preg_match('/,/', $defaults['orderby']) ) { 
    160             $defaults['orderby'] = explode(',', $defaults['orderby']); 
    161         } 
    162         //TODO should we clean format of malicious code over here and run everything thorugh this? 
     151        //ORDER and GROUP BY ORDER - split up string array, if just text do a quick validation and set to default if upon failure 
     152        foreach( array('order', 'groupby_order') as $order_arg ){ 
     153            if( !is_array($defaults[$order_arg]) && preg_match('/,/', $defaults[$order_arg]) ) { 
     154                $defaults[$order_arg] = str_replace(' ', '', $defaults[$order_arg]); 
     155                $defaults[$order_arg] = explode(',', $defaults[$order_arg]); 
     156            }elseif( !is_array($defaults[$order_arg]) && !in_array($defaults[$order_arg], array('ASC','DESC','asc','desc')) ){ 
     157                $defaults[$order_arg] = $super_defaults[$order_arg]; 
     158            } 
     159        } 
     160        //ORDER BY, GROUP BY and GROUP BY ORDER ensure we have a valid array, splitting by commas if present 
     161        foreach( array('orderby', 'groupby', 'groupby_orderby') as $orderby_arg ){ 
     162            if( !is_array($defaults[$orderby_arg]) && preg_match('/,/', $defaults[$orderby_arg]) ) { 
     163                $defaults[$orderby_arg] = str_replace(' ', '', $defaults[$orderby_arg]); 
     164                $defaults[$orderby_arg] = explode(',', $defaults[$orderby_arg]); 
     165            }elseif( !empty($defaults[$orderby_arg]) && !is_array($defaults[$orderby_arg]) ){ 
     166                $defaults[$orderby_arg] = array($defaults[$orderby_arg]); 
     167            } 
     168            if( is_array($defaults[$orderby_arg]) ) $defaults[$orderby_arg] = array_values($defaults[$orderby_arg]); //reset array keys because we want an index 0 present 
     169        } 
     170        //TODO should we clean format of malicious code over here and run everything through this? 
    163171        $defaults['array'] = ($defaults['array'] == true); 
    164172        $defaults['pagination'] = ($defaults['pagination'] == true); 
    165173        $defaults['limit'] = (is_numeric($defaults['limit'])) ? $defaults['limit']:$super_defaults['limit']; 
    166174        $defaults['offset'] = (is_numeric($defaults['offset'])) ? $defaults['offset']:$super_defaults['offset']; 
    167         $defaults['recurring'] = $defaults['recurring'] === 'include' ?  $defaults['recurring']:($defaults['recurring'] == true); 
     175        if( $defaults['recurring'] !== null ) $defaults['recurring'] = $defaults['recurring'] === 'include' ?  $defaults['recurring']:($defaults['recurring'] == true); 
    168176        $defaults['search'] = ($defaults['search']) ? trim($defaults['search']):false; 
    169177        //Calculate offset if event page is set 
     
    207215        $today = date('Y-m-d', current_time('timestamp')); 
    208216        //Create the WHERE statement 
     217        $conditions = array(); 
     218         
     219        //Statuses - we search for the 'status' based on the context of current object (i.e. is it an event or location for the moment) 
     220        // if we define the alternative status such as location_status in event context, if set to true it matches the event 'status' 
     221        // if a specific status search value is given i.e. not true and not false then that's used to generate the right condition for that specific field 
     222        // e.g. if in events, search for 'publish' events and 0 location_status, it'll find events with a location pending review. 
     223        foreach( array('event_status', 'location_status') as $status_type ){ 
     224            $is_location_status = $status_type == "location_status" && self::$context == EM_POST_TYPE_LOCATION; 
     225            $is_event_status = $status_type == "event_status" && self::$context == EM_POST_TYPE_EVENT; 
     226            $is_joined_status = (!$is_location_status || !$is_event_status) && $args[$status_type] !== false; 
     227            if( $is_location_status || $is_event_status || $args[$status_type] !== false ){ 
     228                $condition_status = $is_joined_status ? $status_type : 'status'; 
     229                $status_arg = $is_joined_status && $args[$status_type] !== true ? $args[$status_type] : $args['status']; 
     230                $conditions[$condition_status] = "(`{$status_type}` >= 0 )"; //shows pending & published if not defined 
     231                if( is_numeric($status_arg) ){ 
     232                    $conditions[$condition_status] = "(`{$status_type}`={$status_arg})"; //pending or published 
     233                }elseif( $status_arg == 'pending' ){ 
     234                    $conditions[$condition_status] = "(`{$status_type}`=0)"; //pending 
     235                }elseif( $status_arg == 'publish' ){ 
     236                    $conditions[$condition_status] = "(`{$status_type}`=1)"; //published 
     237                }elseif( $status_arg === null || $status_arg == 'draft' ){ 
     238                    $conditions[$condition_status] = "(`{$status_type}` IS NULL )"; //show draft items 
     239                }elseif( $status_arg == 'trash' ){ 
     240                    $conditions[$condition_status] = "(`{$status_type}` = -1 )"; //show trashed items 
     241                }elseif( $status_arg == 'all'){ 
     242                    $conditions[$condition_status] = "(`{$status_type}` >= 0 OR `{$status_type}` IS NULL)"; //search all statuses that aren't trashed 
     243                }elseif( $status_arg == 'everything'){ 
     244                    unset($conditions[$condition_status]); //search all statuses 
     245                } 
     246            } 
     247        } 
    209248         
    210249        //Recurrences 
    211         $conditions = array(); 
    212250        if( $recurring ){ 
    213             //we show recurring event templates here, if 'recurring' is 'include' then we show both recurring and normal events. 
     251            //we show recurring event templates as well within results, if 'recurring' is 'include' then we show both recurring and normal events. 
    214252            if( $recurring !== 'include' ){ 
    215253                $conditions['recurring'] = "`recurrence`=1"; 
     
    218256            $conditions['recurrence'] = $wpdb->prepare("`recurrence_id`=%d", $recurrence); 
    219257        }else{ 
     258            //we choose to either exclusively show or completely omit recurrences, if not set then both are shown 
    220259            if( $recurrences !== null ){ 
    221260                $conditions['recurrences'] = $recurrences ? "(`recurrence_id` > 0 )":"(`recurrence_id` IS NULL OR `recurrence_id`=0 )"; 
    222261            } 
    223             $conditions['recurring'] = "(`recurrence`!=1 OR `recurrence` IS NULL)";          
     262            //if we get here and $recurring is not exactly null, it was set to false or 0 meaning recurring events shouldn't be included 
     263            if( $recurring !== null ){ 
     264                $conditions['recurring'] = "(`recurrence`!=1 OR `recurrence` IS NULL)"; 
     265            } 
    224266        } 
    225267        //Dates - first check 'month', and 'year', and adjust scope if needed 
     
    332374         
    333375        //Filter by Location - can be object, array, or id 
     376        $location_id_table = self::$context == EM_POST_TYPE_EVENT ? $events_table:$locations_table; 
    334377        if ( is_numeric($location) && $location > 0 ) { //Location ID takes precedence 
    335             $conditions['location'] = " {$locations_table}.location_id = $location"; 
     378            $conditions['location'] = " {$location_id_table}.location_id = $location"; 
    336379        }elseif ( $location === 0 ) { //only helpful is searching events 
    337380            $conditions['location'] = " {$events_table}.location_id = $location OR {$events_table}.location_id IS NULL"; 
    338381        }elseif ( self::array_is_numeric($location) ){ 
    339             $conditions['location'] = "( {$locations_table}.location_id = " . implode(" OR {$locations_table}.location_id = ", $location) .' )'; 
     382            $conditions['location'] = "{$location_id_table}.location_id IN (" . implode(',', $location) .')'; 
    340383        }elseif ( is_object($location) && get_class($location)=='EM_Location' ){ //Now we deal with objects 
    341             $conditions['location'] = " {$locations_table}.location_id = $location->location_id"; 
     384            $conditions['location'] = " {$location_id_table}.location_id = $location->location_id"; 
    342385        }elseif ( is_array($location) && @get_class(current($location)=='EM_Location') ){ //we can accept array of ids or EM_Location objects 
    343386            foreach($location as $EM_Location){ 
    344387                $location_ids[] = $EM_Location->location_id; 
    345388            } 
    346             $conditions['location'] = "( {$locations_table}.location_id=". implode(" {$locations_table}.location_id=", $location_ids) ." )"; 
     389            $conditions['location'] = "{$location_id_table}.location_id IN (" . implode(',', $location_ids) .')'; 
    347390        } 
    348391         
     
    351394            $conditions['event'] = " {$events_table}.event_id = $event"; 
    352395        }elseif ( self::array_is_numeric($event) ){ //array of ids 
    353             $conditions['event'] = "( {$events_table}.event_id = " . implode(" OR {$events_table}.event_id = ", $event) .' )'; 
     396            $conditions['event'] = "{$events_table}.event_id IN (" . implode(',', $event) .')'; 
    354397        }elseif ( is_object($event) && get_class($event)=='EM_Event' ){ //Now we deal with objects 
    355398            $conditions['event'] = " {$events_table}.event_id = $event->event_id"; 
     
    358401                $event_ids[] = $EM_Event->event_id; 
    359402            } 
    360             $conditions['event'] = "( {$events_table}.event_id=". implode(" {$events_table}.event_id=", $event_ids) ." )"; 
     403            $conditions['event'] = "{$events_table}.event_id IN (" . implode(',', $event_ids) .')'; 
    361404        } 
    362405 
     
    503546        if( $bookings == 1 ){ 
    504547            $conditions['bookings'] = 'event_rsvp=1'; 
     548        }elseif( $bookings === 'user' && is_user_logged_in()){ 
     549            //get bookings of user 
     550            $EM_Person = new EM_Person(get_current_user_id()); 
     551            $booking_ids = $EM_Person->get_bookings(true); 
     552            if( count($booking_ids) > 0 ){ 
     553                $conditions['bookings'] = "(event_id IN (SELECT event_id FROM ".EM_BOOKINGS_TABLE." WHERE booking_id IN (".implode(',',$booking_ids).")))"; 
     554            }else{ 
     555                $conditions['bookings'] = "(event_id = 0)"; 
     556            } 
    505557        } 
    506558        //Default ownership belongs to an event, child objects can just overwrite this if needed. 
     
    844896    } 
    845897     
     898    /** 
     899     * Sanitizes the ORDER BY part of the SQL statement so only valid fields are supplied for ordering. 
     900     * Also combines default orders which can be an array which is applied to each specific ordering field, or just one value applied to all ordering fields. 
     901     * @uses EM_Object::build_sql_x_by_helper() 
     902     * @param array $args 
     903     * @param array $accepted_fields 
     904     * @param string|array $default_order 
     905     * @return array 
     906     */ 
    846907    public static function build_sql_orderby( $args, $accepted_fields, $default_order = 'ASC' ){ 
    847908        //First, ORDER BY 
    848         $args = apply_filters('em_object_build_sql_orderby_args', $args); 
    849         $orderby = array(); 
    850         if(is_array($args['orderby'])){ 
     909        $args = apply_filters('em_object_build_sql_orderby_args', $args, $accepted_fields, $default_order ); 
     910        $orderby = self::build_sql_x_by_helper($args['orderby'], $args['order'], $accepted_fields, $default_order); 
     911        return apply_filters('em_object_build_sql_orderby', $orderby, $args, $accepted_fields, $default_order ); 
     912    } 
     913     
     914    /** 
     915     * Returns a set of further fields this query should be grouped by. Not required for straight-forward GROUP BY SQL queries.  
     916     * This is supplementary for build_sql_groupby in cases such as events, where ordering and grouping are mixed due to complex SQL sub-queries and partitions.  
     917     * @uses EM_Object::build_sql_x_by_helper() 
     918     * @param unknown $args 
     919     * @param unknown $accepted_fields 
     920     * @param string $default_order 
     921     * @return mixed|unknown 
     922     */ 
     923    public static function build_sql_groupby_orderby( $args, $accepted_fields, $default_order = 'ASC' ){ 
     924        $args = apply_filters('em_object_build_sql_groupby_orderby_args', $args, $accepted_fields, $default_order ); 
     925        $orderby = self::build_sql_x_by_helper($args['groupby_orderby'], $args['groupby_order'], $accepted_fields, $default_order); 
     926        return apply_filters('em_object_build_sql_groupby_orderby', $orderby, $args, $accepted_fields, $default_order ); 
     927    } 
     928     
     929    /** 
     930     * Sanitizes the group by statement so it includes only accepted fields. Returns an array of valid field names to group by. 
     931     * Optionally, if a $groupby_order value is provided then ASC/DESC values will be added to each field similar to EM_Object::build_sql_orderby 
     932     * @uses EM_Object::build_sql_x_by_helper() 
     933     * @param unknown $args 
     934     * @param unknown $accepted_fields 
     935     * @param string $groupby_order 
     936     * @param string $default_order 
     937     * @return mixed|unknown 
     938     */ 
     939    public static function build_sql_groupby( $args, $accepted_fields, $groupby_order = false, $default_order = 'ASC' ){ 
     940        //First, ORDER BY 
     941        $args = apply_filters('em_object_build_sql_groupby_args', $args); 
     942        $groupby = self::build_sql_x_by_helper($args['groupby'], $groupby_order, $accepted_fields, $default_order); 
     943        return apply_filters('em_object_build_sql_groupby', $groupby, $args, $accepted_fields); 
     944    } 
     945     
     946    /** 
     947     * Helper for building arrays of fields  
     948     * @param unknown $x_by_field 
     949     * @param unknown $order 
     950     * @param unknown $accepted_fields 
     951     * @param string $default_order 
     952     * @return array 
     953     */ 
     954    protected static function build_sql_x_by_helper($x_by_field, $order, $accepted_fields, $default_order = 'ASC' ){ 
     955        $x_by = array(); 
     956        if(is_array($x_by_field)){ 
    851957            //Clean orderby array so we only have accepted values 
    852             foreach( $args['orderby'] as $key => $field ){ 
     958            foreach( $x_by_field as $key => $field ){ 
    853959                if( array_key_exists($field, $accepted_fields) ){ 
    854                     $orderby[] = $accepted_fields[$field]; 
     960                    //maybe cases we're given an array where keys are shortcut names e.g. id => event_id - this way will be deprecated at one point 
     961                    $x_by[] = $accepted_fields[$field]; 
    855962                }elseif( in_array($field,$accepted_fields) ){ 
    856                     $orderby[] = $field; 
     963                    $x_by[] = $field; 
    857964                }else{ 
    858                     unset($args['orderby'][$key]); 
    859                 } 
    860             } 
    861         }elseif( $args['orderby'] != '' && array_key_exists($args['orderby'], $accepted_fields) ){ 
    862             $orderby[] = $accepted_fields[$args['orderby']]; 
    863         }elseif( $args['orderby'] != '' && in_array($args['orderby'], $accepted_fields) ){ 
    864             $orderby[] = $args['orderby']; 
     965                    unset($x_by[$key]); 
     966                } 
     967            } 
     968        }elseif( $x_by_field != '' && array_key_exists($x_by_field, $accepted_fields) ){ 
     969            $x_by[] = $accepted_fields[$x_by_field]; 
     970        }elseif( $x_by_field != '' && in_array($x_by_field, $accepted_fields) ){ 
     971            $x_by[] = $x_by_field; 
    865972        } 
    866973        //ORDER 
    867         //If order is an array, we'll go through the orderby array and match the order values (in order of array) with orderby values 
    868         //If orders don't match up, or it's not ASC/DESC, the default events search in EM settings/options page will be used. 
    869         foreach($orderby as $i => $field){ 
    870             $orderby[$i] .= ' '; 
    871             if(is_array($args['order'])){ 
    872                 if( in_array($args['order'][$i], array('ASC','DESC','asc','desc')) ){ 
    873                     $orderby[$i] .= $args['order'][$i]; 
     974        if( $order !== false ){ 
     975            foreach($x_by as $i => $field){ 
     976                $x_by[$i] .= ' '; 
     977                if(is_array($order)){ 
     978                    //If order is an array, we'll go through the orderby array and match the order values (in order of array) with orderby values 
     979                    if( in_array($order[$i], array('ASC','DESC','asc','desc')) ){ 
     980                        $x_by[$i] .= $order[$i]; 
     981                    }else{ 
     982                        //If orders don't match up, or it's not ASC/DESC, the default events search in EM settings/options page will be used. 
     983                        $x_by[$i] .= $default_order; 
     984                    } 
    874985                }else{ 
    875                     $orderby[$i] .= $default_order; 
    876                 } 
    877             }else{ 
    878                 $orderby[$i] .= ( in_array($args['order'], array('ASC','DESC','asc','desc')) ) ? $args['order'] : $default_order; 
    879             } 
    880         } 
    881         return apply_filters('em_object_build_sql_orderby', $orderby); 
     986                    $x_by[$i] .= ( in_array($order, array('ASC','DESC','asc','desc')) ) ? $order : $default_order; 
     987                } 
     988            } 
     989        } 
     990        return $x_by; 
     991    } 
     992     
     993    /** 
     994     * Fixes ambiguous fields in a given array (which can contain prefixed ASC/DESC arguments) and give them scope of events table 
     995     * @param array $fields 
     996     * @return array 
     997     */ 
     998    protected static function build_sql_ambiguous_fields_helper( $fields, $reserved_fields = array(), $prefix = 'table_name' ){ 
     999        foreach($fields as $k => $v){ 
     1000            $needle = trim(str_replace(array('ASC','DESC'), '', $v)); //remove ASC DESC for searching/comparison arrays such as order by 
     1001            if( in_array($needle, $reserved_fields) ){ 
     1002                $fields[$k] = $prefix.'.'.$v; 
     1003            } 
     1004        } 
     1005        return $fields; 
    8821006    } 
    8831007     
     
    10291153        global $em_capabilities_array; 
    10301154        //if multisite and super admin, just return true 
    1031         if( is_multisite() && is_super_admin() ){ return true; } 
     1155        if( is_multisite() && em_wp_is_super_admin() ){ return true; } 
    10321156        //set user to the desired user we're verifying, otherwise default to current user 
    10331157        if( $user_to_check ){ 
     
    10541178            $error_msg = $em_capabilities_array[$admin_capability]; 
    10551179        } 
    1056          
     1180        $can_manage = apply_filters('em_object_can_manage', $can_manage, $this, $owner_capability, $admin_capability, $user_to_check); 
    10571181        if( !$can_manage && !$is_owner && !empty($error_msg) ){ 
    10581182            $this->add_error($error_msg); 
     
    11191243                if( !empty($this->$key) || $this->$key === 0 || $this->$key === '0' || empty($val['null']) ){ 
    11201244                    $array[$key] = $this->$key; 
     1245                }elseif( $this->$key === null && !empty($val['null']) ){ 
     1246                    $array[$key] = null; 
    11211247                } 
    11221248            }else{ 
  • events-manager/trunk/classes/em-permalinks.php

    r1651260 r1720802  
    3535            global $wp_rewrite; 
    3636            $wp_rewrite->flush_rules(); 
    37             delete_option('dbem_flush_needed'); 
     37            update_option('dbem_flush_needed', 0); 
    3838        } 
    3939         
  • events-manager/trunk/classes/em-tag.php

    r1694715 r1720802  
    11<?php 
    22/** 
    3  * Get an tag in a db friendly way, by checking globals and passed variables to avoid extra class instantiations 
    4  * @param mixed $id 
    5  * @return EM_Tag 
     3 * A single event tag object. * 
    64 */ 
    7 function em_get_tag($id = false) { 
    8     global $EM_Tag; 
    9     //check if it's not already global so we don't instantiate again 
    10     if( is_object($EM_Tag) && get_class($EM_Tag) == 'EM_Tag' ){ 
    11         if( $EM_Tag->term_id == $id ){ 
    12             return $EM_Tag; 
    13         }elseif( is_object($id) && $EM_Tag->term_id == $id->term_id ){ 
    14             return $EM_Tag; 
    15         } 
     5class 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 = false, $class_name = 'EM_Tag' ){ 
     18        return parent::get($id, $class_name); 
    1619    } 
    17     if( is_object($id) && get_class($id) == 'EM_Tag' ){ 
    18         return $id; 
    19     }else{ 
    20         return new EM_Tag($id); 
     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); 
    2123    } 
    2224} 
    23 class EM_Tag extends EM_Taxonomy { 
    24      
    25     public $option_name = 'tag'; 
    26      
    27     /** 
    28      * Gets data from POST (default), supplied array, or from the database if an ID is supplied 
    29      * @param $tag_data 
    30      * @return null 
    31      */ 
    32     function __construct( $tag_data = false ) { 
    33         global $wpdb; 
    34         //Initialize 
    35         $tag = array(); 
    36         if( !empty($tag_data) ){ 
    37             //Load tag data 
    38             if( is_object($tag_data) && !empty($tag_data->taxonomy) && $tag_data->taxonomy == EM_TAXONOMY_TAG ){ 
    39                 $tag = $tag_data; 
    40             }elseif( !is_numeric($tag_data) ){ 
    41                 $tag = get_term_by('name', $tag_data, EM_TAXONOMY_TAG); 
    42                 if( empty($tag) ){ 
    43                     $tag = get_term_by('slug', $tag_data, EM_TAXONOMY_TAG);                  
    44                 } 
    45             }else{       
    46                 $tag = get_term_by('id', $tag_data, EM_TAXONOMY_TAG); 
    47             } 
    48         } 
    49         if( !empty($tag) ){ 
    50             foreach($tag as $key => $value){ 
    51                 $this->$key = $value; 
    52             } 
    53             $this->id = $this->term_id; //backward compatability 
    54         } 
    55         do_action('em_tag',$this, $tag_data); 
    56     } 
    57      
    58     function get_url(){ 
    59         if( empty($this->link) ){ 
    60             self::ms_global_switch(); 
    61             $this->link = get_term_link($this->slug, EM_TAXONOMY_TAG); 
    62             self::ms_global_switch_back(); 
    63             if ( is_wp_error($this->link) ) $this->link = ''; 
    64         } 
    65         return apply_filters('em_tag_get_url', $this->link); 
    66     } 
    6725 
    68     function get_ical_url(){ 
    69         global $wp_rewrite; 
    70         if( !empty($wp_rewrite) && $wp_rewrite->using_permalinks() ){ 
    71             $return = trailingslashit($this->get_url()).'ical/'; 
    72         }else{ 
    73             $return = em_add_get_params($this->get_url(), array('ical'=>1)); 
    74         } 
    75         return apply_filters('em_tag_get_ical_url', $return); 
    76     } 
    77  
    78     function get_rss_url(){ 
    79         global $wp_rewrite; 
    80         if( !empty($wp_rewrite) && $wp_rewrite->using_permalinks() ){ 
    81             $return = trailingslashit($this->get_url()).'feed/'; 
    82         }else{ 
    83             $return = em_add_get_params($this->get_url(), array('feed'=>1)); 
    84         } 
    85         return apply_filters('em_tag_get_rss_url', $return); 
    86     } 
    87      
    88     function output_single($target = 'html'){ 
    89         $format = get_option ( 'dbem_tag_page_format' ); 
    90         return apply_filters('em_tag_output_single', $this->output($format, $target), $this, $target);   
    91     } 
    92      
    93     function output($format, $target="html") { 
    94         preg_match_all('/\{([a-zA-Z0-9_]+)\}([^{]+)\{\/[a-zA-Z0-9_]+\}/', $format, $conditionals); 
    95         if( count($conditionals[0]) > 0 ){ 
    96             foreach($conditionals[1] as $key => $condition){ 
    97                 $format = str_replace($conditionals[0][$key], apply_filters('em_tag_output_condition', '', $condition, $conditionals[0][$key], $this), $format); 
    98             } 
    99         } 
    100         $tag_string = $format;        
    101         preg_match_all("/(#@?_?[A-Za-z0-9]+)({([a-zA-Z0-9,]+)})?/", $format, $placeholders); 
    102         $replaces = array(); 
    103         foreach($placeholders[1] as $key => $result) { 
    104             $match = true; 
    105             $replace = ''; 
    106             $full_result = $placeholders[0][$key]; 
    107             switch( $result ){ 
    108                 case '#_TAGNAME': 
    109                     $replace = $this->name; 
    110                     break; 
    111                 case '#_TAGID': 
    112                     $replace = $this->term_id; 
    113                     break; 
    114                 case '#_TAGSLUG': 
    115                     $replace = $this->slug; 
    116                     break; 
    117                 case '#_TAGLINK': 
    118                 case '#_TAGURL': 
    119                     $link = $this->get_url(); 
    120                     $replace = ($result == '#_TAGURL') ? $link : '<a href="'.$link.'">'.esc_html($this->name).'</a>'; 
    121                     break; 
    122                 case '#_TAGICALURL': 
    123                 case '#_TAGICALLINK': 
    124                     $replace = $this->get_ical_url(); 
    125                     if( $result == '#_TAGICALLINK' ){ 
    126                         $replace = '<a href="'.esc_url($replace).'">iCal</a>'; 
    127                     } 
    128                     break; 
    129                 case '#_TAGRSSURL': 
    130                 case '#_TAGRSSLINK': 
    131                     $replace = $this->get_rss_url(); 
    132                     if( $result == '#_TAGRSSLINK' ){ 
    133                         $replace = '<a href="'.esc_url($replace).'">RSS</a>'; 
    134                     } 
    135                     break; 
    136                 case '#_TAGIMAGEURL': 
    137                     $replace = esc_url($this->get_image_url()); 
    138                     break; 
    139                 case '#_TAGIMAGE': 
    140                     $replace = $this->placeholder_image($replace, $placeholders, $key); 
    141                     break; 
    142                 case '#_TAGCOLOR': 
    143                     $replace = $this->get_color();  
    144                     break; 
    145                 case '#_TAGNOTES': 
    146                     $replace = $this->description; 
    147                     break; 
    148                 case '#_TAGEVENTSPAST': //deprecated, erroneous documentation, left for compatability 
    149                 case '#_TAGEVENTSNEXT': //deprecated, erroneous documentation, left for compatability 
    150                 case '#_TAGEVENTSALL': //deprecated, erroneous documentation, left for compatability 
    151                 case '#_TAGPASTEVENTS': 
    152                 case '#_TAGNEXTEVENTS': 
    153                 case '#_TAGALLEVENTS': 
    154                     //convert deprecated placeholders for compatability 
    155                     $result = ($result == '#_TAGEVENTSPAST') ? '#_TAGPASTEVENTS':$result;  
    156                     $result = ($result == '#_TAGEVENTSNEXT') ? '#_TAGNEXTEVENTS':$result; 
    157                     $result = ($result == '#_TAGEVENTSALL') ? '#_TAGALLEVENTS':$result; 
    158                     //forget it ever happened? :/ 
    159                     if ($result == '#_TAGPASTEVENTS'){ $scope = 'past'; } 
    160                     elseif ( $result == '#_TAGNEXTEVENTS' ){ $scope = 'future'; } 
    161                     else{ $scope = 'all'; } 
    162                     $events_count = EM_Events::count( array('tag'=>$this->term_id, 'scope'=>$scope) ); 
    163                     if ( $events_count > 0 ){ 
    164                         $args = array('tag'=>$this->term_id, 'scope'=>$scope, 'pagination'=>1, 'ajax'=>0); 
    165                         $args['format_header'] = get_option('dbem_tag_event_list_item_header_format'); 
    166                         $args['format_footer'] = get_option('dbem_tag_event_list_item_footer_format'); 
    167                         $args['format'] = get_option('dbem_tag_event_list_item_format'); 
    168                         $args['limit'] = get_option('dbem_tag_event_list_limit'); 
    169                         $args['page'] = (!empty($_REQUEST['pno']) && is_numeric($_REQUEST['pno']) )? $_REQUEST['pno'] : 1; 
    170                         $replace = EM_Events::output($args); 
    171                     } else { 
    172                         $replace = get_option('dbem_tag_no_events_message'); 
    173                     } 
    174                     break; 
    175                 case '#_TAGNEXTEVENT': 
    176                     $events = EM_Events::get( array('tag'=>$this->term_id, 'scope'=>'future', 'limit'=>1, 'orderby'=>'event_start_date,event_start_time') ); 
    177                     $replace = get_option('dbem_tag_no_event_message'); 
    178                     foreach($events as $EM_Event){ 
    179                         $replace = $EM_Event->output(get_option('dbem_tag_event_single_format')); 
    180                     } 
    181                     break; 
    182                 default: 
    183                     $replace = $full_result; 
    184                     break; 
    185             } 
    186             $replaces[$full_result] = apply_filters('em_tag_output_placeholder', $replace, $this, $full_result, $target); 
    187         } 
    188         krsort($replaces); 
    189         foreach($replaces as $full_result => $replacement){ 
    190             $tag_string = str_replace($full_result, $replacement , $tag_string ); 
    191         } 
    192         return apply_filters('em_tag_output', $tag_string, $this, $format, $target);     
    193     } 
     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_Category::get() 
     31 */ 
     32function em_get_tag( $id = false ) { 
     33    return EM_Tag::get($id); 
    19434} 
    195 ?> 
  • events-manager/trunk/classes/em-tags.php

    r1234828 r1720802  
    11<?php 
    2 class EM_Tags extends EM_Object implements Iterator{ 
     2class 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'; 
    38     
    49    /** 
    5      * Array of EM_Tag objects for a specific event 
    6      * @var array 
    7      */ 
    8     var $tags = array(); 
    9     /** 
    10      * Event ID of this set of tags 
    11      * @var int 
    12      */ 
    13     var $event_id; 
    14     /** 
    15      * Post ID of this set of tags 
    16      * @var int 
    17      */ 
    18     var $post_id; 
    19      
    20     /** 
    21      * Creates an EM_Tags instance, currently accepts an EM_Event object (gets all Tags for that event) or array of any EM_Tag objects, which can be manipulated in bulk with helper functions. 
     10     * 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. 
    2211     * @param mixed $data 
    2312     * @return null 
    2413     */ 
    25     function __construct( $data = false ){ 
    26         global $wpdb; 
    27         //an EM_Event object 
    28         if( is_object($data) && get_class($data) == "EM_Event" && !empty($data->post_id) ){ //Creates a blank tags object if needed 
    29             $this->event_id = $data->event_id; 
    30             $this->post_id = $data->post_id; 
    31             if( EM_MS_GLOBAL && (get_current_blog_id() !== $data->blog_id || (!$data->blog_id && !is_main_site()) )  ){ 
    32                 if( !$this->blog_id ) $this->blog_id = get_current_site()->blog_id; 
    33                 switch_to_blog($this->blog_id); 
    34                 $results = get_the_terms( $data->post_id, EM_TAXONOMY_TAG ); 
    35                 restore_current_blog(); 
    36             }else{ 
    37                 $results = get_the_terms( $data->post_id, EM_TAXONOMY_TAG ); 
    38             } 
    39             if( is_array($results) ){ 
    40                 foreach($results as $result){ 
    41                     $this->tags[$result->term_id] = new EM_Tag($result); 
    42                 } 
    43             } 
    44         //array of EM_Tag ids 
    45         }elseif( is_array($data) && self::array_is_numeric($data) ){ 
    46             foreach($data as $tag_id){ 
    47                 $this->tags[$tag_id] =  new EM_Tag($tag_id); 
    48             } 
    49         //array of EM_Tag objects 
    50         }elseif( is_array($data) ){ 
    51             foreach( $data as $EM_Tag ){ 
    52                 if( get_class($EM_Tag) == 'EM_Tag'){ 
    53                     $this->tags[] = $EM_Tag; 
    54                 } 
    55             } 
    56         } 
    57         do_action('em_tags', $this); 
    58     } 
    59      
    60     /* experimental, not tested! */ 
    61     function get_post(){ 
    62         self::ms_global_switch(); 
    63         $this->tags = array(); 
    64         if(!empty($_POST['event_tags']) && self::array_is_numeric($_POST['event_tags'])){ 
    65             foreach( $_POST['event_tags'] as $term ){ 
    66                 $this->tags[$term] = new EM_Tag($term); 
    67             } 
    68         } 
    69         self::ms_global_switch_back(); 
    70         do_action('em_tags_get_post', $this); 
    71     } 
    72  
    73     /* experimental, not tested! */ 
    74     function save(){ 
    75         $term_slugs = array(); 
    76         foreach($this->tags as $EM_Tag){ 
    77             /* @var $EM_Tag EM_Tag */ 
    78             if( !empty($EM_Tag->slug) ) $term_slugs[] = $EM_Tag->slug; //save of tag will soft-fail if slug is empty 
    79         } 
    80         if( count($term_slugs) == 0 && get_option('dbem_default_tag') > 0 ){ 
    81             $default_term = get_term_by('id',get_option('dbem_default_tag'), EM_TAXONOMY_TAG); 
    82             if($default_term) $term_slugs[] = $default_term->slug; 
    83         } 
    84         if( count($term_slugs) > 0 ){ 
    85             wp_set_object_terms($this->post_id, $term_slugs, EM_TAXONOMY_TAG); 
    86         } 
    87         do_action('em_tags_save', $this); 
    88     } 
    89          
    90     public static function get( $args = array() ) {      
    91         //Quick version, we can accept an array of IDs, which is easy to retrieve 
    92         if( self::array_is_numeric($args) ){ //Array of numbers, assume they are event IDs to retreive 
    93             $results = get_terms( EM_TAXONOMY_TAG ); 
    94             $tags = array(); 
    95             foreach($results as $result){ 
    96                 if( in_array($result->term_id, $args) ){ 
    97                     $tags[$result->term_id] = new EM_Tag($result); 
    98                 } 
    99             } 
    100         }else{ 
    101             //We assume it's either an empty array or array of search arguments to merge with defaults 
    102             $term_args = self::get_default_search($args);        
    103             $results = get_terms( EM_TAXONOMY_TAG, $term_args);      
    104          
    105             //If we want results directly in an array, why not have a shortcut here? We don't use this in code, so if you're using it and filter the em_tags_get hook, you may want to do this one too. 
    106             if( !empty($args['array']) ){ 
    107                 return apply_filters('em_tags_get_array', $results, $args); 
    108             } 
    109              
    110             //Make returned results EM_Tag objects 
    111             $results = (is_array($results)) ? $results:array(); 
    112             $tags = array(); 
    113             foreach ( $results as $tag ){ 
    114                 $tags[$tag->term_id] = new EM_Tag($tag); 
    115             } 
    116         } 
    117         self::ms_global_switch_back();   
    118         return apply_filters('em_tags_get', $tags, $args); 
    119     } 
    120  
    121     public static function output( $args ){ 
    122         global $EM_Tag; 
    123         $EM_Tag_old = $EM_Tag; //When looping, we can replace EM_Tag global with the current event in the loop 
    124         //get page number if passed on by request (still needs pagination enabled to have effect) 
    125         $page_queryvar = !empty($args['page_queryvar']) ? $args['page_queryvar'] : 'pno'; 
    126         if( !empty($args['pagination']) && !array_key_exists('page',$args) && !empty($_REQUEST[$page_queryvar]) && is_numeric($_REQUEST[$page_queryvar]) ){ 
    127             $page = $args['page'] = $_REQUEST[$page_queryvar]; 
    128         } 
    129         //Can be either an array for the get search or an array of EM_Tag objects 
    130         if( is_object(current($args)) && get_class((current($args))) == 'EM_Tag' ){ 
    131             $func_args = func_get_args(); 
    132             $tags = $func_args[0]; 
    133             $args = (!empty($func_args[1])) ? $func_args[1] : array(); 
    134             $args = apply_filters('em_tags_output_args', self::get_default_search($args), $tags); 
    135             $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false; 
    136             $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0; 
    137             $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1; 
    138         }else{ 
    139             $args = apply_filters('em_tags_output_args', self::get_default_search($args) ); 
    140             $limit = ( !empty($args['limit']) && is_numeric($args['limit']) ) ? $args['limit']:false; 
    141             $offset = ( !empty($args['offset']) && is_numeric($args['offset']) ) ? $args['offset']:0; 
    142             $page = ( !empty($args['page']) && is_numeric($args['page']) ) ? $args['page']:1; 
    143             $args['limit'] = $args['offset'] = $args['page'] = false; //we count overall tags here 
    144             $tags = self::get( $args ); 
    145             $args['limit'] = $limit; 
    146             $args['offset'] = $offset; 
    147             $args['page'] = $page; 
    148         } 
    149         //What format shall we output this to, or use default 
    150         $format = ( $args['format'] == '' ) ? get_option( 'dbem_tags_list_item_format' ) : $args['format'] ; 
    151          
    152         $output = ""; 
    153         $tags_count = count($tags); 
    154         $tags = apply_filters('em_tags_output_tags', $tags); 
    155         if ( count($tags) > 0 ) { 
    156             $tag_count = 0; 
    157             $tags_shown = 0; 
    158             foreach ( $tags as $EM_Tag ) { 
    159                 if( ($tags_shown < $limit || empty($limit)) && ($tag_count >= $offset || $offset === 0) ){ 
    160                     $output .= $EM_Tag->output($format); 
    161                     $tags_shown++; 
    162                 } 
    163                 $tag_count++; 
    164             } 
    165             //Add headers and footers to output 
    166             if( $format == get_option( 'dbem_tags_list_item_format' ) ){ 
    167                 //we're using the default format, so if a custom format header or footer is supplied, we can override it, if not use the default 
    168                 $format_header = empty($args['format_header']) ? get_option('dbem_tags_list_item_format_header') : $args['format_header']; 
    169                 $format_footer = empty($args['format_footer']) ? get_option('dbem_tags_list_item_format_footer') : $args['format_footer']; 
    170             }else{ 
    171                 //we're using a custom format, so if a header or footer isn't specifically supplied we assume it's blank 
    172                 $format_header = !empty($args['format_header']) ? $args['format_header'] : '' ; 
    173                 $format_footer = !empty($args['format_footer']) ? $args['format_footer'] : '' ; 
    174             } 
    175             $output =  $format_header .  $output . $format_footer; 
    176              
    177             //Pagination (if needed/requested) 
    178             if( !empty($args['pagination']) && !empty($limit) && $tags_count >= $limit ){ 
    179                 $output .= self::get_pagination_links($args, $tags_count); 
    180             } 
    181         } else { 
    182             $output = get_option ( 'dbem_no_tags_message' ); 
    183         } 
    184         //FIXME check if reference is ok when restoring object, due to changes in php5 v 4 
    185         $EM_Tag_old= $EM_Tag; 
    186         return apply_filters('em_tags_output', $output, $tags, $args);       
    187     } 
    188      
    189     public static function get_pagination_links($args, $count, $search_action = 'search_tags', $default_args = array()){ 
    190         //get default args if we're in a search, supply to parent since we can't depend on late static binding until WP requires PHP 5.3 or later 
    191         if( empty($default_args) && (!empty($args['ajax']) || !empty($_REQUEST['action']) && $_REQUEST['action'] == $search_action) ){  
    192             $default_args = self::get_default_search(); 
    193             $default_args['limit'] = get_option('dbem_tags_default_limit'); 
    194         } 
    195         return parent::get_pagination_links($args, $count, $search_action, $default_args); 
    196     } 
    197      
    198     public static function get_post_search($args = array(), $filter = false, $request = array(), $accepted_args = array()){ 
    199         //supply $accepted_args to parent argument since we can't depend on late static binding until WP requires PHP 5.3 or later 
    200         $accepted_args = !empty($accepted_args) ? $accepted_args : array_keys(self::get_default_search()); 
    201         return apply_filters('em_tags_get_post_search', parent::get_post_search($args, $filter, $request, $accepted_args)); 
    202     } 
    203      
    204     function has( $search ){ 
    205         if( is_numeric($search) ){ 
    206             foreach($this->tags as $EM_Tag){ 
    207                 if($EM_Tag->term_id == $search) return apply_filters('em_tags_has', true, $search, $this); 
    208             } 
    209         }else{ 
    210             foreach($this->tags as $EM_Tag){ 
    211                 if($EM_Tag->slug == $search || $EM_Tag->name == $search ) return apply_filters('em_tags_has', true, $search, $this); 
    212             }            
    213         } 
    214         return apply_filters('em_tags_has', false, $search, $this); 
    215     } 
    216      
    217     function get_first(){ 
    218         foreach($this->tags as $EM_Tag){ 
    219             return $EM_Tag; 
    220         } 
    221         return false; 
    222     } 
    223      
    224     function get_ids(){ 
    225         $ids = array(); 
    226         foreach($this->tags as $EM_Tag){ 
    227             if( !empty($EM_Tag->term_id) ){ 
    228                 $ids[] = $EM_Tag->term_id; 
    229             } 
    230         } 
    231         return $ids;     
     14    public function __construct( $data = false ){ 
     15        $this->taxonomy = EM_TAXONOMY_TAG; 
     16        parent::__construct($data); 
    23217    } 
    23318     
    23419    /** 
    235      * Gets the event for this object, or a blank event if none exists 
    236      * @return EM_Event 
     20     * Legacy get overload for any use of $EM_Tags->tags 
     21     * @param string $var_name 
     22     * @return array|NULL 
    23723     */ 
    238     function get_event(){ 
    239         if( is_numeric($this->event_id) ){ 
    240             return em_get_event($this->event_id); 
    241         }else{ 
    242             return new EM_Event(); 
     24    public function __get( $var_name ){ 
     25        if( $var_name == 'tags' ){ 
     26            return $this->terms; 
    24327        } 
     28        return null; 
    24429    } 
    24530     
    246     /*  
    247      * Adds custom tags search defaults 
    248      * @param array $array_or_defaults may be the array to override defaults 
    249      * @param array $array 
    250      * @return array 
    251      * @uses EM_Object#get_default_search() 
    252      */ 
    253     public static function get_default_search( $array_or_defaults = array(), $array = array() ){ 
    254         $defaults = array( 
    255             //added from get_terms, so they don't get filtered out 
    256             'orderby' => get_option('dbem_tags_default_orderby', 'name'), 'order' => get_option('dbem_tags_default_order', 'name'), 
    257             'hide_empty' => false, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 
    258             'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 
    259             'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 
    260             'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core'      
    261         ); 
    262         //sort out whether defaults were supplied or just the array of search values 
    263         if( empty($array) ){ 
    264             $array = $array_or_defaults; 
    265         }else{ 
    266             $defaults = array_merge($defaults, $array_or_defaults); 
    267         } 
    268         return apply_filters('em_tags_get_default_search', parent::get_default_search($defaults,$array), $array, $defaults); 
     31    //Functions we won't need when PHP 5.3 minimum allows for use of LSB 
     32     
     33    public static function get( $args = array() ){ 
     34        self::$instance = new EM_Tags(); 
     35        return parent::get($args); 
    26936    } 
    27037 
    271     //Iterator Implementation 
    272     public function rewind(){ 
    273         reset($this->tags); 
    274     }   
    275     public function current(){ 
    276         $var = current($this->tags); 
    277         return $var; 
    278     }   
    279     public function key(){ 
    280         $var = key($this->tags); 
    281         return $var; 
    282     }   
    283     public function next(){ 
    284         $var = next($this->tags); 
    285         return $var; 
    286     }   
    287     public function valid(){ 
    288         $key = key($this->tags); 
    289         $var = ($key !== NULL && $key !== FALSE); 
    290         return $var; 
    291     } 
     38    public static function output( $args = array() ){ 
     39        self::$instance = new EM_Tags(); 
     40        return parent::output($args); 
     41    } 
     42     
     43    public static function get_pagination_links($args, $count, $search_action = 'search_cats', $default_args = array()){ 
     44        self::$instance = new EM_Tags(); 
     45        return parent::get_pagination_links($args, $count, $search_action, $default_args); 
     46    } 
     47 
     48    public static function get_post_search($args = array(), $filter = false, $request = array(), $accepted_args = array()){ 
     49        self::$instance = new EM_Tags(); 
     50        return parent::get_post_search($args, $filter, $request, $accepted_args); 
     51    } 
     52     
     53    public static function get_default_search( $array_or_defaults = array(), $array = array() ){ 
     54        self::$instance = new EM_Tags(); 
     55        return parent::get_default_search($defaults,$array); 
     56    } 
    29257} 
  • events-manager/trunk/classes/em-ticket.php

    r1655537 r1720802  
    5050     
    5151    /** 
     52     * An associative array containing event IDs as the keys and pending spaces as values. 
     53     * This is in array form for future-proofing since at one point tickets could be used for multiple events. 
     54     * @var array 
     55     */ 
     56    protected $pending_spaces = array(); 
     57    protected $booked_spaces = array(); 
     58    protected $bookings_count = array(); 
     59     
     60    /** 
    5261     * Creates ticket object and retreives ticket data (default is a blank ticket object). Accepts either array of ticket data (from db) or a ticket id. 
    5362     * @param mixed $ticket_data 
     
    372381    } 
    373382     
    374     function get_pending_spaces(){ 
    375         $spaces = 0; 
    376         foreach( $this->get_bookings()->get_pending_bookings()->bookings as $EM_Booking ){ //get_bookings() is used twice so we get the confirmed (or all if confirmation disabled) bookings of this ticket's total bookings. 
    377             //foreach booking, get this ticket booking info if found 
    378             foreach($EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking){ 
    379                 if( $EM_Ticket_Booking->ticket_id == $this->ticket_id ){ 
    380                     $spaces += $EM_Ticket_Booking->get_spaces(); 
    381                 } 
    382             } 
    383         } 
    384         return apply_filters('em_ticket_get_pending_spaces', $spaces, $this); 
     383    /** 
     384     * Get total number of pending spaces for this ticket. 
     385     * @param boolean $force_refresh 
     386     * @return int 
     387     */ 
     388    function get_pending_spaces( $force_refresh = false ){ 
     389        global $wpdb; 
     390        if( !array_key_exists($this->event_id, $this->pending_spaces) || $force_refresh ){ 
     391            $sub_sql = 'SELECT booking_id FROM '.EM_BOOKINGS_TABLE." WHERE event_id=%d AND booking_status=0"; 
     392            $sql = 'SELECT SUM(ticket_booking_spaces) FROM '.EM_TICKETS_BOOKINGS_TABLE. " WHERE booking_id IN ($sub_sql) AND ticket_id=%d"; 
     393            $pending_spaces = $wpdb->get_var($wpdb->prepare($sql, $this->event_id, $this->ticket_id)); 
     394            $this->pending_spaces[$this->event_id] = $pending_spaces > 0 ? $pending_spaces : 0; 
     395            $this->pending_spaces[$this->event_id] = apply_filters('em_ticket_get_pending_spaces', $this->pending_spaces[$this->event_id], $this, $force_refresh);   
     396        } 
     397        return $this->pending_spaces[$this->event_id]; 
    385398    } 
    386399 
    387400    /** 
    388401     * Returns the number of booked spaces in this ticket. 
     402     * @param boolean $force_refresh 
    389403     * @return int 
    390404     */ 
    391     function get_booked_spaces($force_reload=false){ 
    392         //get all bookings for this event 
    393         $spaces = 0; 
    394         if( is_object($this->bookings) && $force_reload ){ 
    395             //return $this->bookings; 
    396         } 
    397         foreach( $this->get_bookings()->get_bookings()->bookings as $EM_Booking ){ //get_bookings() is used twice so we get the confirmed (or all if confirmation disabled) bookings of this ticket's total bookings. 
    398             //foreach booking, get this ticket booking info if found 
    399             foreach($EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking){ 
    400                 if( $EM_Ticket_Booking->ticket_id == $this->ticket_id ){ 
    401                     $spaces += $EM_Ticket_Booking->get_spaces(); 
    402                 } 
    403             } 
    404         } 
    405         return apply_filters('em_ticket_get_booked_spaces', $spaces, $this); 
     405    function get_booked_spaces( $force_refresh = false ){ 
     406        global $wpdb; 
     407        if( !array_key_exists($this->event_id, $this->pending_spaces) || $force_refresh ){ 
     408            $status_cond = !get_option('dbem_bookings_approval') ? 'booking_status IN (0,1)' : 'booking_status = 1'; 
     409            $sub_sql = 'SELECT booking_id FROM '.EM_BOOKINGS_TABLE." WHERE event_id=%d AND $status_cond"; 
     410            $sql = 'SELECT SUM(ticket_booking_spaces) FROM '.EM_TICKETS_BOOKINGS_TABLE. " WHERE booking_id IN ($sub_sql) AND ticket_id=%d"; 
     411            $booked_spaces = $wpdb->get_var($wpdb->prepare($sql, $this->event_id, $this->ticket_id)); 
     412            $this->booked_spaces[$this->event_id] = $booked_spaces > 0 ? $booked_spaces : 0; 
     413            $this->booked_spaces[$this->event_id] = apply_filters('em_ticket_get_booked_spaces', $this->booked_spaces[$this->event_id], $this, $force_refresh); 
     414        } 
     415        return $this->booked_spaces[$this->event_id]; 
     416    } 
     417 
     418    /** 
     419     * Returns the total number of bookings of all statuses for this ticket 
     420     * @param int $status 
     421     * @param boolean $force_refresh 
     422     * @return int 
     423     */ 
     424    function get_bookings_count( $status = false, $force_refresh = false ){ 
     425        global $wpdb; 
     426        if( !array_key_exists($this->event_id, $this->bookings_count) || $force_refresh ){ 
     427            $sql = 'SELECT COUNT(*) FROM '.EM_TICKETS_BOOKINGS_TABLE. ' WHERE booking_id IN (SELECT booking_id FROM '.EM_BOOKINGS_TABLE.' WHERE event_id=%d) AND ticket_id=%d'; 
     428            $bookings_count = $wpdb->get_var($wpdb->prepare($sql, $this->event_id, $this->ticket_id)); 
     429            $this->bookings_count[$this->event_id] = $bookings_count > 0 ? $bookings_count : 0; 
     430            $this->bookings_count[$this->event_id] = apply_filters('em_ticket_get_bookings_count', $this->bookings_count[$this->event_id], $this, $force_refresh); 
     431        } 
     432        return $this->bookings_count[$this->event_id]; 
    406433    } 
    407434     
  • events-manager/trunk/em-actions.php

    r1651260 r1720802  
    4242            } 
    4343            echo EM_Object::json_encode($json_locations); 
    44             die();    
     44            die(); 
    4545        } 
    4646        if(isset($_REQUEST['query']) && $_REQUEST['query'] == 'GlobalEventsMapData') { 
    4747            $_REQUEST['has_location'] = true; //we're looking for locations in this context, so locations necessary 
     48            $_REQUEST['groupby'] = 'location_id'; //grouping will generally produce much faster processing 
    4849            $EM_Events = EM_Events::get( $_REQUEST ); 
    4950            $json_locations = array(); 
    5051            $locations = array(); 
    5152            foreach($EM_Events as $EM_Event) { 
    52                 if( !empty($EM_Event->location_id) && empty($locations[$EM_Event->location_id]) ){ 
    53                     $EM_Location = $EM_Event->get_location(); 
    54                     $location_array = $EM_Event->get_location()->to_array(); 
    55                     $location_array['location_balloon'] = $EM_Location->output(get_option('dbem_map_text_format')); 
    56                     $json_locations[] = $location_array; 
    57                     $locations[$EM_Event->location_id] = true; 
    58                 } 
     53                $EM_Location = $EM_Event->get_location(); 
     54                $location_array = $EM_Event->get_location()->to_array(); 
     55                $location_array['location_balloon'] = $EM_Location->output(get_option('dbem_map_text_format')); 
     56                $json_locations[] = $location_array; 
    5957            } 
    6058            echo EM_Object::json_encode($json_locations); 
     
    308306            //ADD/EDIT Booking 
    309307            em_verify_nonce('booking_add_one'); 
    310             if( !$EM_Event->get_bookings()->has_booking(get_current_user_id()) || get_option('dbem_bookings_double')){ 
     308            if( get_option('dbem_bookings_double') || !$EM_Event->get_bookings()->has_booking(get_current_user_id()) ){ 
    311309                $EM_Booking = em_get_booking(array('person_id'=>get_current_user_id(), 'event_id'=>$EM_Event->event_id, 'booking_spaces'=>1)); //new booking 
    312310                $EM_Ticket = $EM_Event->get_bookings()->get_tickets()->get_first();  
  • events-manager/trunk/em-events.php

    r1651260 r1720802  
    2626    ); 
    2727    $args['ajax'] = isset($args['ajax']) ? $args['ajax']:(!defined('EM_AJAX') || EM_AJAX ); 
    28     if( !post_password_required() && in_array($post->ID, array($events_page_id, $locations_page_id, $categories_page_id, $edit_bookings_page_id, $edit_events_page_id, $edit_locations_page_id, $my_bookings_page_id, $tags_page_id)) ){ 
     28    if( in_the_loop() && is_main_query() && !post_password_required() && in_array($post->ID, array($events_page_id, $locations_page_id, $categories_page_id, $edit_bookings_page_id, $edit_events_page_id, $edit_locations_page_id, $my_bookings_page_id, $tags_page_id)) ){ 
    2929        $content = apply_filters('em_content_pre', '', $page_content); 
    3030        if( empty($content) ){ 
  • events-manager/trunk/em-functions.php

    r1694715 r1720802  
    519519    global $EM_Mailer; 
    520520    return $EM_Mailer->send(get_option('dbem_bookings_email_registration_subject'), $message, $user_email); 
     521} 
     522 
     523/** 
     524 * Transitional function to handle WP's eventual move away from the is_super_user() function  
     525 */ 
     526function em_wp_is_super_admin( $user_id = false ){ 
     527    $user = ( ! $user_id || $user_id == get_current_user_id() ) ? wp_get_current_user() : get_userdata( $user_id ); 
     528 
     529    if ( ! $user || ! $user->exists() ) return false; 
     530 
     531    if ( is_multisite() ) { 
     532        if( $user->has_cap('manage_network_options') ) return true; 
     533    } else { 
     534        if ( $user->has_cap('delete_users') ) return true; 
     535    } 
     536    return false; 
    521537} 
    522538 
     
    642658        <th scope="row"><?php echo esc_html($title); ?></th> 
    643659        <td> 
    644             <input name="<?php echo esc_attr($name) ?>" type="text" id="<?php echo esc_attr($name) ?>" style="width: 95%" value="<?php echo esc_attr(get_option($name, $default), ENT_QUOTES); ?>" size="45" />          
     660            <input name="<?php echo esc_attr($name) ?>" type="text" id="<?php echo esc_attr($name) ?>" value="<?php echo esc_attr(get_option($name, $default), ENT_QUOTES); ?>" size="45" />             
    645661            <?php if( $translate ): ?><span class="em-translatable dashicons dashicons-admin-site"></span><?php endif; ?> 
    646662            <br /> 
     
    689705        <th scope="row"><?php echo esc_html($title); ?></th> 
    690706            <td> 
    691                 <textarea name="<?php echo esc_attr($name) ?>" id="<?php echo esc_attr($name) ?>" rows="6" cols="60"><?php echo esc_attr(get_option($name), ENT_QUOTES);?></textarea>            
     707                <textarea name="<?php echo esc_attr($name) ?>" id="<?php echo esc_attr($name) ?>" rows="6"><?php echo esc_attr(get_option($name), ENT_QUOTES);?></textarea>          
    692708                <?php if( $translate ): ?><span class="em-translatable  dashicons dashicons-admin-site"></span><?php endif; ?> 
    693709                <br /> 
     
    741757} 
    742758 
    743 function em_options_radio_binary($title, $name, $description='', $option_names = '', $trigger='') { 
     759function em_options_radio_binary($title, $name, $description='', $option_names = '', $trigger='', $untrigger=false) { 
    744760    if( empty($option_names) ) $option_names = array(0 => __('No','events-manager'), 1 => __('Yes','events-manager')); 
    745761    if( substr($name, 0, 7) == 'dbem_ms' ){ 
     
    748764        $list_events_page = get_option($name); 
    749765    } 
    750     $trigger_att = ($trigger) ? 'data-trigger="'.esc_attr($trigger).'" class="em-trigger"':''; 
     766    if( $untrigger ){ 
     767        $trigger_att = ($trigger) ? 'data-trigger="'.esc_attr($trigger).'" class="em-untrigger"':''; 
     768    }else{ 
     769        $trigger_att = ($trigger) ? 'data-trigger="'.esc_attr($trigger).'" class="em-trigger"':''; 
     770    } 
    751771    ?> 
    752772    <tr valign="top" id='<?php echo $name;?>_row'> 
  • events-manager/trunk/em-install.php

    r1694715 r1720802  
    150150        location_id bigint(20) unsigned NULL DEFAULT NULL, 
    151151        recurrence_id bigint(20) unsigned NULL DEFAULT NULL, 
    152         event_category_id bigint(20) unsigned NULL DEFAULT NULL, 
    153152        event_date_created datetime NULL DEFAULT NULL, 
    154153        event_date_modified datetime NULL DEFAULT NULL, 
    155         recurrence bool NOT NULL DEFAULT 0, 
     154        recurrence bool NULL DEFAULT 0, 
    156155        recurrence_interval int(4) NULL DEFAULT NULL, 
    157156        recurrence_freq tinytext NULL DEFAULT NULL, 
     
    179178        */ 
    180179    }else{ 
    181         if( get_option('dbem_version') < 4.939 ){ 
     180        if( get_option('dbem_version') != '' && get_option('dbem_version') < 4.939 ){ 
    182181            //if updating from version 4 (4.934 is beta v5) then set all statuses to 1 since it's new 
    183182            $wpdb->query("ALTER TABLE $table_name CHANGE event_notes post_content longtext NULL DEFAULT NULL"); 
     
    256255        */ 
    257256    }else{ 
    258         if( get_option('dbem_version') < 4.938 ){ 
     257        if( get_option('dbem_version') != '' && get_option('dbem_version') < 4.938 ){ 
    259258            $wpdb->query("ALTER TABLE $table_name CHANGE location_description post_content longtext NULL DEFAULT NULL"); 
    260259        } 
    261260        dbDelta($sql); 
    262         if( get_option('dbem_version') < 4.93 ){ 
     261        if( get_option('dbem_version') != '' && get_option('dbem_version') < 4.93 ){ 
    263262            //if updating from version 4 (4.93 is beta v5) then set all statuses to 1 since it's new 
    264263            $wpdb->query("UPDATE ".$table_name." SET location_status=1"); 
     
    550549        'dbem_location_event_list_item_footer_format' => "</ul>", 
    551550        'dbem_location_event_list_limit' => 20, 
     551        'dbem_location_event_list_orderby' => 'event_start_date,event_start_time,event_name', 
     552        'dbem_location_event_list_order' => 'ASC', 
    552553        'dbem_location_event_single_format' => '#_EVENTLINK - #_EVENTDATES - #_EVENTTIMES', 
    553554        'dbem_location_no_event_message' => __('No events in this location', 'events-manager'), 
     
    569570        'dbem_category_event_list_item_footer_format' => '</ul>', 
    570571        'dbem_category_event_list_limit' => 20, 
     572        'dbem_category_event_list_orderby' => 'event_start_date,event_start_time,event_name', 
     573        'dbem_category_event_list_order' => 'ASC', 
    571574        'dbem_category_event_single_format' => '#_EVENTLINK - #_EVENTDATES - #_EVENTTIMES', 
    572575        'dbem_category_no_event_message' => __('No events in this category', 'events-manager'), 
     
    591594        'dbem_tag_no_event_message' => __('No events with this tag', 'events-manager'), 
    592595        'dbem_tag_event_list_limit' => 20, 
     596        'dbem_tag_event_list_orderby' => 'event_start_date,event_start_time,event_name', 
     597        'dbem_tag_event_list_order' => 'ASC', 
    593598        'dbem_tag_default_color' => '#a8d145', 
    594599        //RSS Stuff 
     
    809814        'dbem_disable_thumbnails'=> false, 
    810815        //feedback reminder 
    811         'dbem_feedback_reminder' => time() 
     816        'dbem_feedback_reminder' => time(), 
     817        'dbem_events_page_ajax' => 0, 
     818        'dbem_conditional_recursions' => 1 
    812819    ); 
    813820     
     
    12151222    //-- CATEGORIES -- 
    12161223    //Create the terms according to category table, use the category owner for the term ids to store this 
    1217     $categories = $wpdb->get_results("SELECT * FROM ".EM_CATEGORIES_TABLE, ARRAY_A); //taking a wild-hope guess that there aren't too many categories on one site/blog 
     1224    $categories = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix.'em_categories', ARRAY_A); //taking a wild-hope guess that there aren't too many categories on one site/blog 
    12181225    foreach( $categories as $category ){ 
    12191226        //get all events with this category before resetting ids 
  • events-manager/trunk/em-posts.php

    r1488912 r1720802  
    116116        )); 
    117117    } 
     118    $event_post_type_supports = apply_filters('em_cp_event_supports', array('custom-fields','title','editor','excerpt','comments','thumbnail','author')); 
    118119    $event_post_type = array(    
    119120        'public' => true, 
     
    127128        'rewrite' => array('slug' => EM_POST_TYPE_EVENT_SLUG,'with_front'=>false), 
    128129        'has_archive' => get_option('dbem_cp_events_has_archive', false) == true, 
    129         'supports' => apply_filters('em_cp_event_supports', array('custom-fields','title','editor','excerpt','comments','thumbnail','author')), 
     130        'supports' => $event_post_type_supports, 
    130131        'capability_type' => 'event', 
    131132        'capabilities' => array( 
     
    173174            'can_export' => true, 
    174175            'hierarchical' => false, 
    175             'supports' => apply_filters('em_cp_event_supports', array('custom-fields','title','editor','excerpt','comments','thumbnail','author')), 
     176            'supports' => $event_post_type_supports, 
    176177            'capability_type' => 'recurring_events', 
    177178            'rewrite' => array('slug' => 'events-recurring','with_front'=>false), 
     
    307308        /* Handle event reads */ 
    308309        if ( 'edit_event' == $cap || 'delete_event' == $cap || 'read_event' == $cap ) { 
    309             $EM_Event = em_get_event($args[0],'post_id'); 
     310            $post = get_post($args[0]); 
     311            //check for revisions and deal with non-event post types 
     312            if( !empty($post->post_type) && $post->post_type == 'revision' ) $post = get_post($post->post_parent); 
     313            if( empty($post->post_type) || !in_array($post->post_type, array(EM_POST_TYPE_EVENT, 'event-recurring')) ) return $caps; 
     314            //continue with getting post type and assigning caps 
     315            $EM_Event = em_get_event($post); 
    310316            $post_type = get_post_type_object( $EM_Event->post_type ); 
    311317            /* Set an empty array for the caps. */ 
     
    336342        } 
    337343        if ( 'edit_recurring_event' == $cap || 'delete_recurring_event' == $cap || 'read_recurring_event' == $cap ) { 
    338             $EM_Event = em_get_event($args[0],'post_id'); 
     344            $post = get_post($args[0]); 
     345            //check for revisions and deal with non-event post types 
     346            if( !empty($post->post_type) && $post->post_type == 'revision' ) $post = get_post($post->post_parent); 
     347            if( empty($post->post_type) || $post->post_type != 'event-recurring' ) return $caps; 
     348            //continue with getting post type and assigning caps 
     349            $EM_Event = em_get_event($post); 
    339350            $post_type = get_post_type_object( $EM_Event->post_type ); 
    340351            /* Set an empty array for the caps. */ 
     
    365376        } 
    366377        if ( 'edit_location' == $cap || 'delete_location' == $cap || 'read_location' == $cap ) { 
    367             $EM_Location = em_get_location($args[0],'post_id'); 
     378            $post = get_post($args[0]); 
     379            //check for revisions and deal with non-location post types 
     380            if( !empty($post->post_type) && $post->post_type == 'revision' ) $post = get_post($post->post_parent); 
     381            if( empty($post->post_type) || $post->post_type != EM_POST_TYPE_LOCATION ) return $caps; 
     382            //continue with getting post type and assigning caps 
     383            $EM_Location = em_get_location($post); 
    368384            $post_type = get_post_type_object( $EM_Location->post_type ); 
    369385            /* Set an empty array for the caps. */ 
  • events-manager/trunk/em-pro-compatibility.php

    r1234828 r1720802  
    1717        <?php 
    1818    } 
    19     if( is_super_admin() ){ 
     19    if( em_wp_is_super_admin() ){ 
    2020        add_action ( 'admin_notices', 'em_empro_lt_2376_notice', 100 ); 
    2121        add_action ( 'network_admin_notices', 'em_empro_lt_2376_notice', 100 ); 
  • events-manager/trunk/em-shortcode.php

    r1677796 r1720802  
    2929 */ 
    3030function em_get_locations_map_shortcode($args){ 
     31    $args = (array) $args; 
    3132    $args['em_ajax'] = true; 
    3233    $args['query'] = 'GlobalMapData'; 
     
    6667 */ 
    6768function em_get_events_map_shortcode($args){ 
     69    $args = (array) $args; 
    6870    $args['em_ajax'] = true; 
    6971    $args['query'] = 'GlobalEventsMapData'; 
  • events-manager/trunk/events-manager.php

    r1694715 r1720802  
    22/* 
    33Plugin Name: Events Manager 
    4 Version: 5.7.3.1 
     4Version: 5.7.3.2 
    55Plugin URI: http://wp-events-plugin.com 
    66Description: Event registration and booking management for WordPress. Recurring events, locations, google maps, rss, ical, booking registration and more! 
     
    1111 
    1212/* 
    13 Copyright (c) 2016, Marcus Sykes 
     13Copyright (c) 2017, Marcus Sykes 
    1414 
    1515This program is free software; you can redistribute it and/or 
     
    2929 
    3030// Setting constants 
    31 define('EM_VERSION', 5.731); //self expanatory 
     31define('EM_VERSION', 5.732); //self expanatory 
    3232define('EM_PRO_MIN_VERSION', 2.392); //self expanatory 
    3333define('EM_PRO_MIN_VERSION_CRITICAL', 2.377); //self expanatory 
     
    4444 
    4545//EM_MS_GLOBAL 
    46 if( get_site_option('dbem_ms_global_table') && is_multisite() ){ 
     46if( is_multisite() && get_site_option('dbem_ms_global_table') ){ 
    4747    define('EM_MS_GLOBAL', true); 
    4848}else{ 
     
    6868//Base classes 
    6969include('classes/em-object.php'); 
    70 include('classes/em-taxonomy.php'); 
     70include('classes/em-taxonomy-term.php'); 
     71include('classes/em-taxonomy-terms.php'); 
     72include('classes/em-taxonomy-frontend.php'); 
    7173//set up events as posts 
    7274include("em-posts.php"); 
     
    9294include('classes/em-calendar.php'); 
    9395include('classes/em-category.php'); 
    94 include('classes/em-category-taxonomy.php'); 
    9596include('classes/em-categories.php'); 
     97include('classes/em-categories-frontend.php'); 
    9698include('classes/em-event.php'); 
    9799include('classes/em-event-post.php'); 
     
    106108include('classes/em-permalinks.php'); 
    107109include('classes/em-tag.php'); 
    108 include('classes/em-tag-taxonomy.php'); 
    109110include('classes/em-tags.php'); 
     111include('classes/em-tags-frontend.php'); 
    110112include('classes/em-ticket-booking.php'); 
    111113include('classes/em-ticket.php'); 
     
    128130    include('classes/em-location-posts-admin.php'); 
    129131    include('classes/em-taxonomy-admin.php'); 
    130     include('classes/em-categories-taxonomy.php'); 
    131     include('classes/em-tags-taxonomy.php'); 
     132    include('classes/em-categories-admin.php'); 
     133    include('classes/em-tags-admin.php'); 
    132134    //bookings folder 
    133135        include('admin/bookings/em-cancelled.php'); 
     
    154156    $prefix = $wpdb->prefix; 
    155157} 
    156     define('EM_CATEGORIES_TABLE', $prefix.'em_categories'); //TABLE NAME 
    157158    define('EM_EVENTS_TABLE',$prefix.'em_events'); //TABLE NAME 
    158159    define('EM_TICKETS_TABLE', $prefix.'em_tickets'); //TABLE NAME 
     
    367368        if( is_user_logged_in() || is_page(get_option('dbem_edit_events_page')) ){ 
    368369            if( get_option('dbem_recurrence_enabled') ){ 
    369                 if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'edit' && !empty($_REQUEST['event_id'])){ 
    370                     $em_localized_js['event_reschedule_warning'] = __('Are you sure you want to continue?', 'events-manager') .PHP_EOL.PHP_EOL; 
     370                if( !empty($_REQUEST['action']) && ($_REQUEST['action'] == 'edit' || $_REQUEST['action'] == 'event_save') && !empty($_REQUEST['event_id']) ){ 
     371                    $em_localized_js['event_reschedule_warning'] = __('Are you sure you want to continue?', 'events-manager') .PHP_EOL; 
    371372                    $em_localized_js['event_reschedule_warning'] .= __('Modifications to event times will cause all recurrences of this event to be deleted and recreated, previous bookings will be deleted.', 'events-manager'); 
    372                     $em_localized_js['event_recurrence_overwrite'] = __('Are you sure you want to continue?', 'events-manager') .PHP_EOL.PHP_EOL; 
    373                     $em_localized_js['event_recurrence_overwrite'] .= __( 'Modifications to recurring events will be applied to all recurrences and will overwrite any changes made to those individual event recurrences.', 'events-manager') .PHP_EOL.PHP_EOL; 
     373                    $em_localized_js['event_recurrence_overwrite'] = __('Are you sure you want to continue?', 'events-manager') .PHP_EOL; 
     374                    $em_localized_js['event_recurrence_overwrite'] .= __( 'Modifications to recurring events will be applied to all recurrences and will overwrite any changes made to those individual event recurrences.', 'events-manager') .PHP_EOL; 
    374375                    $em_localized_js['event_recurrence_overwrite'] .= __( 'Bookings to individual event recurrences will be preserved if event times and ticket settings are not modified.', 'events-manager'); 
    375                     $em_localized_js['event_recurrence_bookings'] = __('Are you sure you want to continue?', 'events-manager') .PHP_EOL.PHP_EOL; 
     376                    $em_localized_js['event_recurrence_bookings'] = __('Are you sure you want to continue?', 'events-manager') .PHP_EOL; 
    376377                    $em_localized_js['event_recurrence_bookings'] .= __('Modifications to event tickets will cause all bookings to individual recurrences of this event to be deleted.', 'events-manager'); 
    377378                } 
     
    593594                return $return; 
    594595            }elseif( strstr($filter_name, 'pre_update_option_') !== false ){ 
    595                 if( is_super_admin() ){ 
     596                if( em_wp_is_super_admin() ){ 
    596597                    update_site_option(str_replace('pre_update_option_','',$filter_name), $value[0]); 
    597598                } 
    598599                return $value[1]; 
    599600            }elseif( strstr($filter_name, 'add_option_') !== false ){ 
    600                 if( is_super_admin() ){ 
     601                if( em_wp_is_super_admin() ){ 
    601602                    update_site_option(str_replace('add_option_','',$filter_name),$value[0]); 
    602603                } 
  • events-manager/trunk/includes/css/events_manager_admin.css

    r1651260 r1720802  
    130130#em-options-form tbody.em-subsection th { padding-left:35px; } 
    131131table.em-caps-table th, table.em-caps-table td { width:auto !important; } 
     132#em-options-form textarea, #em-options-form input[type="text"] { width:95%; } 
    132133.em-translatable { display:inline-block; width:20px; height:20px; font-size:20px; padding:0px 5px 0px 0px; cursor:pointer; } 
    133134.em-ml-options { display:none; } 
  • events-manager/trunk/includes/js/admin-settings.js

    r1694715 r1720802  
    3030    var navUrl = document.location.toString(); 
    3131    if (navUrl.match('#')) { //anchor-based navigation 
    32         var nav_tab = navUrl.split('#'); 
    33         var current_tab = 'a#em-menu-' + nav_tab[1]; 
     32        var nav_tab = navUrl.split('#').pop().split('+'); 
     33        var current_tab = 'a#em-menu-' + nav_tab[0]; 
    3434        $(current_tab).trigger('click'); 
    35         if( nav_tab.length > 2 ){ 
    36             section = $("#em-opt-"+nav_tab[2]); 
     35        if( nav_tab.length > 1 ){ 
     36            section = $("#em-opt-"+nav_tab[1]); 
    3737            if( section.length > 0 ){ 
    3838                section.children('h3').trigger('click'); 
     
    5050        var newloc = docloc[0]; 
    5151        if( docloc.length > 1 ){ 
    52             var nav_tab = docloc[1].split('#'); 
    53             newloc = newloc + "#" + nav_tab[0]; 
     52            var nav_tab = docloc[1].split('+'); 
     53            var tab_path = nav_tab[0]; 
    5454            if( el.attr('id') ){ 
    55                 newloc = newloc + "#" + el.attr('id').replace('em-opt-',''); 
     55                tab_path = tab_path + "+" + el.attr('id').replace('em-opt-',''); 
    5656            } 
     57            newloc = newloc + "#" + tab_path; 
    5758        } 
    5859        document.location = newloc; 
     60        $(this).closest('form').append('<input type="hidden" name="tab_path" value="'+ tab_path +'" />'); 
    5961    }); 
    6062    //Page Options 
     
    108110    }); 
    109111    $('input.em-trigger:checked').trigger('change'); 
     112    $('input.em-untrigger').change(function(e){ 
     113        var el = $(this); 
     114        el.val() == '0' ? $(el.attr('data-trigger')).show() : $(el.attr('data-trigger')).hide(); 
     115    }); 
     116    $('input.em-untrigger:checked').trigger('change'); 
    110117    //admin tools confirm 
    111118    $('a.admin-tools-db-cleanup').click( function( e ){ 
  • events-manager/trunk/readme.txt

    r1694715 r1720802  
    55Text Domain: events-manager 
    66Requires at least: 3.5 
    7 Tested up to: 4.8 
     7Tested up to: 4.8.1 
    88Stable tag: 5.7.3 
    99 
     
    100100 
    101101== Changelog == 
    102 = (dev) 5.7.3.1 = 
     102= (dev) 5.7.3.2 = 
    103103* fixed category color picker and image uploader problems 
    104104* created base classes for EM taxonomies to make adding custom EM taxonomies even easier in the future, 
     
    117117* fixed single initial abbreviation issues in Chinese calendars 
    118118* fixed duplicate events not being published to social networks via jetpack publicize (kudos @gnaag) 
     119* fixed potential incompatibilities with other plugins using wp_query_reset() on category pages, preventing our page formats from showing 
     120* fixed taxonomy archive pages returning zero results if taxonomy formatting is disabled and events are excluded from searches (WP Bug workaround) 
     121* fixed inconsistent line ending causing warnings with PHP compatibility checker 
     122* unified Tag and Category class functions into sets of parent class functionn 
     123* fixed PHP fatal error with BP when disabling notifications 
     124* fixed calendar day links being incorrect if another plugin adds querystring params to permalinks 
     125* added groupby, groupby_orderby and groupby_order arguments allowing grouping in search results for events and locations 
     126* improved validation and sanitization of orderby arguments to avoid ambiguous field SQL errors 
     127* added optimization to optionally join event/location tables when needed for grouped searches or if EM_DISABLE_OPTIONAL_JOINS is defined and set to true 
     128* moved condition of when argument 'bookings' = 'user' to EM_Object so it's accessible by EM_Location too 
     129* changed default 'recurring' argument to null so that non EM_Events searches can by default avoid the recurring conditional being generated 
     130* added grouping to AJAX response for event_map shortcode and function resulting in performance improvements 
     131* fixed use of get_terms via deprecated two argument method 
     132* fixed recreation of tickets for a recurring event having wrong start/end ticket dates 
     133* fixed custom fields with a 0 value getting deleted instead of saved 
     134* fixed/changed - shortened SQL search conditions when filtering by array or comma list of event/location ids 
     135* fixed escaping of apostrophes on search term placeholder 
     136* added optimized result counts (EM_Events::$num_rows and EM_Events::$num_rows_total) in EM_Events::get() to reduce number of SQL calls 
     137* added optimized result counts (EM_Locations::$num_rows and EM_Locations::$num_rows_total) in EM_Locations::get() to reduce number of SQL calls 
     138* changed as a result of the above two additions above we tweaked various event list areas to half number of SQL queries run per list 
     139* added no_results_msg argument to EM_Events::output() functions for custom 'no events found' 
     140* added location_status and event_status search arguments to event and location searches respectively 
     141* fixed column alignment issues when using quick edit for events in wp dashboard 
     142* tweaked excerpt filters and reduced redundant calls to our the_content filters (reducing overhead) 
     143* changed event page the_content loading so it only shows when in_the_loop() and is_main_query() is true 
     144* fixed issues with WordPress SEO plugin breaking the wp editor front-end 
     145* added event list default sorting options to locations, tags and categories 
     146* added em_wp_is_super_admin() replacing is_super_admin() in anticipation of its deprecation  
     147* changed and optimized postmeta saving process to reduce number of rows by up to 80% per event, 
     148* optimized events table to save NULL values when possible 
     149* changed/removed unused event_category_id field from events table 
     150* added em_object_can_manage filter 
     151* fixed nested attributes such as {cond}#_ATT{name}{/cond} not being parsed properly 
     152* fixed some installation SQL PHP errors/warnings 
     153* fixed capability mapping problems if revisions enabled for events or locations 
     154* added WEBCAL placeholders to events, locations, categories and tags (e.g. #_EVENTICALLINK > #_EVENTWEBCALLINK) 
     155* removed unnecessary SQL queries for undeclared wp_options reducing number of queries made per page load 
     156* tweaked settings page textarea elements to be wider 
     157* added (possibly temporary) EM_FORCE_RECURRENCES_SAVE constant forcing status save for when recurrences change status, 
     158* fixed EM_Event::set_status_events() which was not working correctly and now also runs a em_event_set_status_events filter 
     159* fixed recurring events warning text not appearing in front-end editor if first submission produced validation errors 
     160* performance improvements to EM_Bookings and EM_Ticket objects by preventing pre-loading of all bookings on instantiation and when querying availability 
     161* added cache optimization for event and location loading, 
     162* improved optimized loading of EM_Location via em_get_location() by checking globals first, 
     163* changed bookings/tickets template for event editor to avoid loading all bookings for counting purposes 
     164* added $include_adjustments argument to get_price_pre_taxes and get_price_post_taxes for calculation of prices without discounts/surcharges (those making use of the em_booking_get_price_post_taxes and em_booking_get_price_pre_taxes filters should check for this passed argument in their custom code) 
    119165 
    120166= 5.7.3 = 
  • events-manager/trunk/templates/buddypress/profile.php

    r1311743 r1720802  
    1212        'format' => get_option('dbem_bp_events_list_format'), 
    1313        'format_footer' => get_option('dbem_bp_events_list_format_footer'), 
     14        'no_results_msg' => false, 
    1415        'owner' => $bp->displayed_user->id, 
    1516        'pagination'=>1 
    1617    ); 
    1718    $args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_events_default_limit'); 
    18     if( EM_Events::count($args) > 0 ){ 
    19         echo EM_Events::output($args); 
    20     }else{ 
     19    echo EM_Events::output($args); 
     20    if( EM_Events::$num_rows_found == 0 ){ 
     21        //no events output on last function 
    2122        ?> 
    2223        <p><?php _e('No Events', 'events-manager'); ?>. 
  • events-manager/trunk/templates/forms/event/bookings.php

    r1655537 r1720802  
    8989                                    <div class="ticket-actions"> 
    9090                                        <a href="#" class="ticket-actions-edit"><?php esc_html_e('Edit','events-manager'); ?></a>  
    91                                         <?php if( count($EM_Ticket->get_bookings()->bookings) == 0 ): ?> 
     91                                        <?php if( $EM_Ticket->get_bookings_count() == 0 ): ?> 
    9292                                        | <a href="<?php bloginfo('wpurl'); ?>/wp-load.php" class="ticket-actions-delete"><?php esc_html_e('Delete','events-manager'); ?></a> 
    9393                                        <?php else: ?> 
  • events-manager/trunk/templates/forms/event/group.php

    r1311743 r1720802  
    44$user_groups = array(); 
    55$group_data = groups_get_user_groups(get_current_user_id()); 
    6 if( !is_super_admin() ){ 
     6if( !em_wp_is_super_admin() ){ 
    77    foreach( $group_data['groups'] as $group_id ){ 
    88        if( groups_is_user_admin(get_current_user_id(), $group_id) ){ 
     
    4040    <em><?php _e ( 'Select a group you admin to attach this event to it. Note that all other admins of that group can modify the booking.', 'events-manager')?></em> 
    4141    </p> 
    42     <?php if( is_super_admin() ): ?> 
     42    <?php if( em_wp_is_super_admin() ): ?> 
    4343    <p><em><?php _e ( 'As a site admin, you see all group events, users will only be able to choose groups they are admins of.', 'events-manager')?></em></p> 
    4444    <?php endif;  
  • events-manager/trunk/templates/templates/search/search.php

    r1488912 r1720802  
    66<div class="em-search-text em-search-field"> 
    77    <script type="text/javascript"> 
    8     EM.search_term_placeholder = '<?php echo esc_attr($args['search_term_label']); ?>'; 
     8    EM.search_term_placeholder = '<?php echo esc_js($args['search_term_label']); ?>'; 
    99    </script> 
    1010    <label> 
  • events-manager/trunk/widgets/em-events.php

    r1395984 r1720802  
    9999            //balance tags and sanitize output formats 
    100100            if( in_array($key, array('format', 'no_events_text', 'all_events_text')) ){ 
    101                 if( is_multisite() && !is_super_admin() ) $new_instance[$key] = wp_kses_post($new_instance[$key]); //for multisite 
     101                if( is_multisite() && !em_wp_is_super_admin() ) $new_instance[$key] = wp_kses_post($new_instance[$key]); //for multisite 
    102102                $new_instance[$key] = force_balance_tags($new_instance[$key]); 
    103103            } 
  • events-manager/trunk/widgets/em-locations.php

    r1395984 r1720802  
    7171            //balance tags and sanitize output formats 
    7272            if( in_array($key, array('format', 'no_locations_text')) ){ 
    73                 if( is_multisite() && !is_super_admin() ) $new_instance[$key] = wp_kses_post($new_instance[$key]); //for multisite 
     73                if( is_multisite() && !em_wp_is_super_admin() ) $new_instance[$key] = wp_kses_post($new_instance[$key]); //for multisite 
    7474                $new_instance[$key] = force_balance_tags($new_instance[$key]); 
    7575            } 
Note: See TracChangeset for help on using the changeset viewer.