示例#1
0
/**
 * bp_em_setup_nav()
 *
 * Sets up the user profile navigation items for the component. This adds the top level nav
 * item and all the sub level nav items to the navigation array. This is then
 * rendered in the template.
 */
function bp_em_setup_nav()
{
    global $bp;
    $count = 0;
    /* Add 'Events' to the main user profile navigation */
    bp_core_new_nav_item(array('name' => __('Events', 'bp-em'), 'slug' => $bp->events->slug, 'position' => 80, 'screen_function' => bp_is_my_profile() ? 'bp_em_my_events' : 'bp_em_events', 'default_subnav_slug' => bp_is_my_profile() ? 'my-events' : ''));
    $em_link = $bp->loggedin_user->domain . $bp->events->slug . '/';
    /* Create two sub nav items for this component */
    bp_core_new_subnav_item(array('name' => __('My Profile', 'dbem'), 'slug' => 'profile', 'parent_slug' => $bp->events->slug, 'parent_url' => $em_link, 'screen_function' => 'bp_em_events', 'position' => 10, 'user_has_access' => bp_is_my_profile()));
    bp_core_new_subnav_item(array('name' => __('Events I\'m Attending', 'dbem'), 'slug' => 'attending', 'parent_slug' => $bp->events->slug, 'parent_url' => $em_link, 'screen_function' => 'bp_em_attending', 'position' => 20, 'user_has_access' => bp_is_my_profile()));
    bp_core_new_subnav_item(array('name' => __('My Events', 'dbem'), 'slug' => 'my-events', 'parent_slug' => $bp->events->slug, 'parent_url' => $em_link, 'screen_function' => 'bp_em_my_events', 'position' => 30, 'user_has_access' => bp_is_my_profile()));
    bp_core_new_subnav_item(array('name' => __('My Locations', 'dbem'), 'slug' => 'my-locations', 'parent_slug' => $bp->events->slug, 'parent_url' => $em_link, 'screen_function' => 'bp_em_my_locations', 'position' => 40, 'user_has_access' => bp_is_my_profile()));
    bp_core_new_subnav_item(array('name' => __('My Event Bookings', 'dbem'), 'slug' => 'my-bookings', 'parent_slug' => $bp->events->slug, 'parent_url' => $em_link, 'screen_function' => 'bp_em_my_bookings', 'position' => 50, 'user_has_access' => bp_is_my_profile()));
    /* Add a nav item for this component under the settings nav item. */
    bp_core_new_subnav_item(array('name' => __('Events', 'dbem'), 'slug' => 'group-events', 'parent_slug' => $bp->groups->slug, 'parent_url' => $bp->loggedin_user->domain . $bp->groups->slug . '/', 'screen_function' => 'bp_em_my_group_events', 'position' => 60, 'user_has_access' => bp_is_my_profile()));
    /* Add a nav item for this component under the settings nav item. */
    bp_core_new_subnav_item(array('name' => __('Events', 'dbem'), 'slug' => 'events-settings', 'parent_slug' => $bp->settings->slug, 'parent_url' => $bp->loggedin_user->domain . $bp->settings->slug . '/', 'screen_function' => 'bp_em_screen_settings_menu', 'position' => 40, 'user_has_access' => bp_is_my_profile()));
    /* Create two sub nav items for this component */
    $group_link = $bp->root_domain . '/' . $bp->groups->slug . '/' . $bp->groups->current_group->slug . '/';
    if ($bp->current_component == 'groups') {
        $count = EM_Events::count(array('group' => $bp->groups->current_group->id));
        if (empty($count)) {
            $count = 0;
        }
    }
    bp_core_new_subnav_item(array('name' => sprintf(__('Events (%s)', 'dbem'), $count), 'slug' => 'events', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'bp_em_group_events', 'position' => 50, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'forums'));
}
 /**
  * Hooks in after EM_Tag_Taxonomy::template() and makes sure WPML doesn't reset $wp_query and wipe the work EM just did.  
  */
 public static function tag_taxonomy_workaround()
 {
     global $EM_Tag;
     if (defined('EM_WPML_TAXONOMIES_TWEAKED') && EM_WPML_TAXONOMIES_TWEAKED) {
         return;
     }
     //prevent endless loop
     if (EM_Events::count(array('tag' => $EM_Tag->term_id)) == 0) {
         self::preset_query($EM_Tag->output(get_option('dbem_tag_page_title_format')));
     }
     define('EM_WPML_TAXONOMIES_TWEAKED', true);
     wp_reset_query();
     add_filter('the_post', 'EM_Tag_Taxonomy::template', 1);
 }
示例#3
0
 function output($format, $target = "html")
 {
     preg_match_all('/\\{([a-zA-Z0-9_]+)\\}([^{]+)\\{\\/[a-zA-Z0-9_]+\\}/', $format, $conditionals);
     if (count($conditionals[0]) > 0) {
         //Check if the language we want exists, if not we take the first language there
         foreach ($conditionals[1] as $key => $condition) {
             $format = str_replace($conditionals[0][$key], apply_filters('em_category_output_condition', '', $condition, $conditionals[0][$key], $this), $format);
         }
     }
     $category_string = $format;
     preg_match_all("/(#@?_?[A-Za-z0-9]+)({([a-zA-Z0-9,]+)})?/", $format, $placeholders);
     $replaces = array();
     foreach ($placeholders[1] as $key => $result) {
         $replace = '';
         $full_result = $placeholders[0][$key];
         switch ($result) {
             case '#_CATEGORYNAME':
                 $replace = $this->name;
                 break;
             case '#_CATEGORYID':
                 $replace = $this->term_id;
                 break;
             case '#_CATEGORYNOTES':
             case '#_CATEGORYDESCRIPTION':
                 $replace = $this->description;
                 break;
             case '#_CATEGORYIMAGE':
             case '#_CATEGORYIMAGEURL':
                 if ($this->get_image_url() != '') {
                     $image_url = esc_url($this->get_image_url());
                     if ($result == '#_CATEGORYIMAGEURL') {
                         $replace = $image_url;
                     } else {
                         if (empty($placeholders[3][$key])) {
                             $replace = "<img src='" . esc_url($this->get_image_url()) . "' alt='" . esc_attr($this->name) . "'/>";
                         } else {
                             $image_size = explode(',', $placeholders[3][$key]);
                             if (self::array_is_numeric($image_size) && count($image_size) > 1) {
                                 if ($this->get_image_id()) {
                                     //get a thumbnail
                                     if (get_option('dbem_disable_thumbnails')) {
                                         $image_attr = '';
                                         $image_args = array();
                                         if (empty($image_size[1]) && !empty($image_size[0])) {
                                             $image_attr = 'width="' . $image_size[0] . '"';
                                             $image_args['w'] = $image_size[0];
                                         } elseif (empty($image_size[0]) && !empty($image_size[1])) {
                                             $image_attr = 'height="' . $image_size[1] . '"';
                                             $image_args['h'] = $image_size[1];
                                         } elseif (!empty($image_size[0]) && !empty($image_size[1])) {
                                             $image_attr = 'width="' . $image_size[0] . '" height="' . $image_size[1] . '"';
                                             $image_args = array('w' => $image_size[0], 'h' => $image_size[1]);
                                         }
                                         $replace = "<img src='" . esc_url(em_add_get_params($image_url, $image_args)) . "' alt='" . esc_attr($this->name) . "' {$image_attr} />";
                                     } else {
                                         //since we previously didn't store image ids along with the url to the image (since taxonomies don't allow normal featured images), sometimes we won't be able to do this, which is why we check there's a valid image id first
                                         self::ms_global_switch();
                                         $replace = wp_get_attachment_image($this->get_image_id(), $image_size);
                                         self::ms_global_switch_back();
                                     }
                                 }
                             } else {
                                 $replace = "<img src='" . esc_url($this->get_image_url()) . "' alt='" . esc_attr($this->name) . "'/>";
                             }
                         }
                     }
                 }
                 break;
             case '#_CATEGORYCOLOR':
                 $replace = $this->get_color();
                 break;
             case '#_CATEGORYLINK':
             case '#_CATEGORYURL':
                 $link = $this->get_url();
                 $replace = $result == '#_CATEGORYURL' ? $link : '<a href="' . $link . '">' . esc_html($this->name) . '</a>';
                 break;
             case '#_CATEGORYICALURL':
             case '#_CATEGORYICALLINK':
                 $replace = $this->get_ical_url();
                 if ($result == '#_CATEGORYICALLINK') {
                     $replace = '<a href="' . esc_url($replace) . '">iCal</a>';
                 }
                 break;
             case '#_CATEGORYRSSURL':
             case '#_CATEGORYRSSLINK':
                 $replace = $this->get_rss_url();
                 if ($result == '#_CATEGORYRSSLINK') {
                     $replace = '<a href="' . esc_url($replace) . '">RSS</a>';
                 }
                 break;
             case '#_CATEGORYSLUG':
                 $replace = $this->slug;
                 break;
             case '#_CATEGORYEVENTSPAST':
                 //deprecated, erroneous documentation, left for compatability
             //deprecated, erroneous documentation, left for compatability
             case '#_CATEGORYEVENTSNEXT':
                 //deprecated, erroneous documentation, left for compatability
             //deprecated, erroneous documentation, left for compatability
             case '#_CATEGORYEVENTSALL':
                 //deprecated, erroneous documentation, left for compatability
             //deprecated, erroneous documentation, left for compatability
             case '#_CATEGORYPASTEVENTS':
             case '#_CATEGORYNEXTEVENTS':
             case '#_CATEGORYALLEVENTS':
                 //convert deprecated placeholders for compatability
                 $result = $result == '#_CATEGORYEVENTSPAST' ? '#_CATEGORYPASTEVENTS' : $result;
                 $result = $result == '#_CATEGORYEVENTSNEXT' ? '#_CATEGORYNEXTEVENTS' : $result;
                 $result = $result == '#_CATEGORYEVENTSALL' ? '#_CATEGORYALLEVENTS' : $result;
                 //forget it ever happened? :/
                 if ($result == '#_CATEGORYPASTEVENTS') {
                     $scope = 'past';
                 } elseif ($result == '#_CATEGORYNEXTEVENTS') {
                     $scope = 'future';
                 } else {
                     $scope = 'all';
                 }
                 $events_count = EM_Events::count(array('category' => $this->term_id, 'scope' => $scope));
                 if ($events_count > 0) {
                     $args = array('category' => $this->term_id, 'scope' => $scope, 'pagination' => 1, 'ajax' => 0);
                     $args['format_header'] = get_option('dbem_category_event_list_item_header_format');
                     $args['format_footer'] = get_option('dbem_category_event_list_item_footer_format');
                     $args['format'] = get_option('dbem_category_event_list_item_format');
                     $args['limit'] = get_option('dbem_category_event_list_limit');
                     $args['page'] = !empty($_REQUEST['pno']) && is_numeric($_REQUEST['pno']) ? $_REQUEST['pno'] : 1;
                     $replace = EM_Events::output($args);
                 } else {
                     $replace = get_option('dbem_category_no_events_message', '</ul>');
                 }
                 break;
             case '#_CATEGORYNEXTEVENT':
                 $events = EM_Events::get(array('category' => $this->term_id, 'scope' => 'future', 'limit' => 1, 'orderby' => 'event_start_date,event_start_time'));
                 $replace = get_option('dbem_category_no_event_message');
                 foreach ($events as $EM_Event) {
                     $replace = $EM_Event->output(get_option('dbem_category_event_single_format'));
                 }
                 break;
             default:
                 $replace = $full_result;
                 break;
         }
         $replaces[$full_result] = apply_filters('em_category_output_placeholder', $replace, $this, $full_result, $target);
     }
     krsort($replaces);
     foreach ($replaces as $full_result => $replacement) {
         $category_string = str_replace($full_result, $replacement, $category_string);
     }
     return apply_filters('em_category_output', $category_string, $this, $format, $target);
 }
示例#4
0
 function output($format, $target = "html")
 {
     $location_string = $format;
     //First let's do some conditional placeholder removals
     for ($i = 0; $i < EM_CONDITIONAL_RECURSIONS; $i++) {
         //you can add nested recursions by modifying this setting in your wp_options table
         preg_match_all('/\\{([a-zA-Z0-9_]+)\\}(.+?)\\{\\/\\1\\}/s', $location_string, $conditionals);
         if (count($conditionals[0]) > 0) {
             //Check if the language we want exists, if not we take the first language there
             foreach ($conditionals[1] as $key => $condition) {
                 $show_condition = false;
                 if ($condition == 'has_loc_image') {
                     //does this event have an image?
                     $show_condition = $this->get_image_url() != '';
                 } elseif ($condition == 'no_loc_image') {
                     //does this event have an image?
                     $show_condition = $this->get_image_url() == '';
                 }
                 $show_condition = apply_filters('em_location_output_show_condition', $show_condition, $condition, $conditionals[0][$key], $this);
                 if ($show_condition) {
                     //calculate lengths to delete placeholders
                     $placeholder_length = strlen($condition) + 2;
                     $replacement = substr($conditionals[0][$key], $placeholder_length, strlen($conditionals[0][$key]) - ($placeholder_length * 2 + 1));
                 } else {
                     $replacement = '';
                 }
                 $location_string = str_replace($conditionals[0][$key], apply_filters('em_location_output_condition', $replacement, $condition, $conditionals[0][$key], $this), $location_string);
             }
         }
     }
     //This is for the custom attributes
     preg_match_all('/#_LATT\\{([^}]+)\\}(\\{([^}]+)\\})?/', $location_string, $results);
     foreach ($results[0] as $resultKey => $result) {
         //Strip string of placeholder and just leave the reference
         $attRef = substr(substr($result, 0, strpos($result, '}')), 7);
         $attString = '';
         if (is_array($this->location_attributes) && array_key_exists($attRef, $this->location_attributes) && !empty($this->location_attributes[$attRef])) {
             $attString = $this->location_attributes[$attRef];
         } elseif (!empty($results[3][$resultKey])) {
             //Check to see if we have a second set of braces;
             $attString = $results[3][$resultKey];
         }
         $attString = apply_filters('em_location_output_placeholder', $attString, $this, $result, $target);
         $location_string = str_replace($result, $attString, $location_string);
     }
     preg_match_all("/(#@?_?[A-Za-z0-9]+)({([^}]+)})?/", $location_string, $placeholders);
     $replaces = array();
     foreach ($placeholders[1] as $key => $result) {
         $replace = '';
         $full_result = $placeholders[0][$key];
         switch ($result) {
             case '#_LOCATIONID':
                 $replace = $this->location_id;
                 break;
             case '#_LOCATIONPOSTID':
                 $replace = $this->post_id;
                 break;
             case '#_NAME':
                 //Depricated
             //Depricated
             case '#_LOCATION':
                 //Depricated
             //Depricated
             case '#_LOCATIONNAME':
                 $replace = $this->location_name;
                 break;
             case '#_ADDRESS':
                 //Depricated
             //Depricated
             case '#_LOCATIONADDRESS':
                 $replace = $this->location_address;
                 break;
             case '#_TOWN':
                 //Depricated
             //Depricated
             case '#_LOCATIONTOWN':
                 $replace = $this->location_town;
                 break;
             case '#_LOCATIONSTATE':
                 $replace = $this->location_state;
                 break;
             case '#_LOCATIONPOSTCODE':
                 $replace = $this->location_postcode;
                 break;
             case '#_LOCATIONREGION':
                 $replace = $this->location_region;
                 break;
             case '#_LOCATIONCOUNTRY':
                 $replace = $this->get_country();
                 break;
             case '#_LOCATIONFULLLINE':
                 $replace = $this->location_address;
                 $replace .= empty($this->location_town) ? '' : ', ' . $this->location_town;
                 $replace .= empty($this->location_state) ? '' : ', ' . $this->location_state;
                 $replace .= empty($this->location_postcode) ? '' : ', ' . $this->location_postcode;
                 $replace .= empty($this->location_region) ? '' : ', ' . $this->location_region;
                 break;
             case '#_LOCATIONFULLBR':
                 $replace = $this->location_address;
                 $replace .= empty($this->location_town) ? '' : '<br />' . $this->location_town;
                 $replace .= empty($this->location_state) ? '' : '<br />' . $this->location_state;
                 $replace .= empty($this->location_postcode) ? '' : '<br />' . $this->location_postcode;
                 $replace .= empty($this->location_region) ? '' : '<br />' . $this->location_region;
                 break;
             case '#_MAP':
                 //Depricated (but will remain)
             //Depricated (but will remain)
             case '#_LOCATIONMAP':
                 ob_start();
                 $args = array();
                 if (!empty($placeholders[3][$key])) {
                     $dimensions = explode(',', $placeholders[3][$key]);
                     if (!empty($dimensions[0])) {
                         $args['width'] = $dimensions[0];
                     }
                     if (!empty($dimensions[1])) {
                         $args['height'] = $dimensions[1];
                     }
                 }
                 $template = em_locate_template('placeholders/locationmap.php', true, array('args' => $args, 'EM_Location' => $this));
                 $replace = ob_get_clean();
                 break;
             case '#_LOCATIONLONGITUDE':
                 $replace = $this->location_longitude;
                 break;
             case '#_LOCATIONLATITUDE':
                 $replace = $this->location_latitude;
                 break;
             case '#_DESCRIPTION':
                 //Depricated
             //Depricated
             case '#_EXCERPT':
                 //Depricated
             //Depricated
             case '#_LOCATIONNOTES':
             case '#_LOCATIONEXCERPT':
                 $replace = $this->post_content;
                 if ($result == "#_EXCERPT" || $result == "#_LOCATIONEXCERPT") {
                     if (!empty($this->post_excerpt)) {
                         $replace = $this->post_excerpt;
                     } else {
                         $excerpt_length = 55;
                         $excerpt_more = apply_filters('em_excerpt_more', ' ' . '[...]');
                         if (!empty($placeholders[3][$key])) {
                             $trim = true;
                             $ph_args = explode(',', $placeholders[3][$key]);
                             if (is_numeric($ph_args[0])) {
                                 $excerpt_length = $ph_args[0];
                             }
                             if (!empty($ph_args[1])) {
                                 $excerpt_more = $ph_args[1];
                             }
                         }
                         if (preg_match('/<!--more(.*?)?-->/', $replace, $matches)) {
                             $content = explode($matches[0], $replace, 2);
                             $replace = force_balance_tags($content[0]);
                         }
                         if (!empty($trim)) {
                             //shorten content by supplied number - copied from wp_trim_excerpt
                             $replace = strip_shortcodes($replace);
                             $replace = str_replace(']]>', ']]&gt;', $replace);
                             $replace = wp_trim_words($replace, $excerpt_length, $excerpt_more);
                         }
                     }
                 }
                 break;
             case '#_LOCATIONIMAGEURL':
             case '#_LOCATIONIMAGE':
                 if ($this->get_image_url() != '') {
                     $image_url = esc_url($this->get_image_url());
                     if ($result == '#_LOCATIONIMAGEURL') {
                         $replace = $this->get_image_url();
                     } else {
                         if (empty($placeholders[3][$key])) {
                             $replace = "<img src='" . $image_url . "' alt='" . esc_attr($this->location_name) . "'/>";
                         } else {
                             $image_size = explode(',', $placeholders[3][$key]);
                             if (self::array_is_numeric($image_size) && count($image_size) > 1) {
                                 if (EM_MS_GLOBAL && get_current_blog_id() != $this->blog_id) {
                                     //get a thumbnail
                                     if (get_option('dbem_disable_thumbnails')) {
                                         $image_attr = '';
                                         $image_args = array();
                                         if (empty($image_size[1]) && !empty($image_size[0])) {
                                             $image_attr = 'width="' . $image_size[0] . '"';
                                             $image_args['w'] = $image_size[0];
                                         } elseif (empty($image_size[0]) && !empty($image_size[1])) {
                                             $image_attr = 'height="' . $image_size[1] . '"';
                                             $image_args['h'] = $image_size[1];
                                         } elseif (!empty($image_size[0]) && !empty($image_size[1])) {
                                             $image_attr = 'width="' . $image_size[0] . '" height="' . $image_size[1] . '"';
                                             $image_args = array('w' => $image_size[0], 'h' => $image_size[1]);
                                         }
                                         $replace = "<img src='" . esc_url(em_add_get_params($image_url, $image_args)) . "' alt='" . esc_attr($this->location_name) . "' {$image_attr} />";
                                     } else {
                                         //location belongs to another blog, so switch blog then call the default wp fucntion
                                         if (EM_MS_GLOBAL && get_current_blog_id() != $this->blog_id) {
                                             switch_to_blog($this->blog_id);
                                             $switch_back = true;
                                         }
                                         $replace = get_the_post_thumbnail($this->ID, $image_size);
                                         if (!empty($switch_back)) {
                                             restore_current_blog();
                                         }
                                     }
                                 } else {
                                     $replace = get_the_post_thumbnail($this->ID, $image_size);
                                 }
                             } else {
                                 $replace = "<img src='" . $image_url . "' alt='" . esc_attr($this->location_name) . "'/>";
                             }
                         }
                     }
                 }
                 break;
             case '#_LOCATIONURL':
             case '#_LOCATIONLINK':
             case '#_LOCATIONPAGEURL':
                 //Depricated
                 $link = esc_url($this->get_permalink());
                 $replace = $result == '#_LOCATIONURL' || $result == '#_LOCATIONPAGEURL' ? $link : '<a href="' . $link . '" title="' . esc_attr($this->location_name) . '">' . esc_html($this->location_name) . '</a>';
                 break;
             case '#_LOCATIONEDITURL':
             case '#_LOCATIONEDITLINK':
                 if ($this->can_manage('edit_locations', 'edit_others_locations')) {
                     $link = esc_url($this->get_edit_url());
                     $replace = $result == '#_LOCATIONEDITURL' ? $link : '<a href="' . $link . '" title="' . esc_attr($this->location_name) . '">' . esc_html(sprintf(__('Edit Location', 'dbem'))) . '</a>';
                 }
                 break;
             case '#_LOCATIONICALURL':
             case '#_LOCATIONICALLINK':
                 $replace = $this->get_ical_url();
                 if ($result == '#_LOCATIONICALLINK') {
                     $replace = '<a href="' . esc_url($replace) . '">iCal</a>';
                 }
                 break;
             case '#_LOCATIONRSSURL':
             case '#_LOCATIONRSSLINK':
                 $replace = $this->get_rss_url();
                 if ($result == '#_LOCATIONRSSLINK') {
                     $replace = '<a href="' . esc_url($replace) . '">RSS</a>';
                 }
                 break;
             case '#_PASTEVENTS':
                 //Depricated
             //Depricated
             case '#_LOCATIONPASTEVENTS':
             case '#_NEXTEVENTS':
                 //Depricated
             //Depricated
             case '#_LOCATIONNEXTEVENTS':
             case '#_ALLEVENTS':
                 //Depricated
             //Depricated
             case '#_LOCATIONALLEVENTS':
                 //TODO: add limit to lists of events
                 //convert depreciated placeholders for compatability
                 $result = $result == '#_PASTEVENTS' ? '#_LOCATIONPASTEVENTS' : $result;
                 $result = $result == '#_NEXTEVENTS' ? '#_LOCATIONNEXTEVENTS' : $result;
                 $result = $result == '#_ALLEVENTS' ? '#_LOCATIONALLEVENTS' : $result;
                 //forget it ever happened? :/
                 if ($result == '#_LOCATIONPASTEVENTS') {
                     $scope = 'past';
                 } elseif ($result == '#_LOCATIONNEXTEVENTS') {
                     $scope = 'future';
                 } else {
                     $scope = 'all';
                 }
                 $events_count = EM_Events::count(array('location' => $this->location_id, 'scope' => $scope));
                 if ($events_count > 0) {
                     $args = array('location' => $this->location_id, 'scope' => $scope, 'pagination' => 1, 'ajax' => 0);
                     $args['format_header'] = get_option('dbem_location_event_list_item_header_format');
                     $args['format_footer'] = get_option('dbem_location_event_list_item_footer_format');
                     $args['format'] = get_option('dbem_location_event_list_item_format');
                     $args['limit'] = get_option('dbem_location_event_list_limit');
                     $args['page'] = !empty($_REQUEST['pno']) && is_numeric($_REQUEST['pno']) ? $_REQUEST['pno'] : 1;
                     $replace = EM_Events::output($args);
                 } else {
                     $replace = get_option('dbem_location_no_events_message');
                 }
                 break;
             case '#_LOCATIONNEXTEVENT':
                 $events = EM_Events::get(array('location' => $this->location_id, 'scope' => 'future', 'limit' => 1, 'orderby' => 'event_start_date,event_start_time'));
                 $replace = get_option('dbem_location_no_event_message');
                 foreach ($events as $EM_Event) {
                     $replace = $EM_Event->output(get_option('dbem_location_event_single_format'));
                 }
                 break;
             default:
                 $replace = $full_result;
                 break;
         }
         $replaces[$full_result] = apply_filters('em_location_output_placeholder', $replace, $this, $full_result, $target);
     }
     //sort out replacements so that during replacements shorter placeholders don't overwrite longer varieties.
     krsort($replaces);
     foreach ($replaces as $full_result => $replacement) {
         if (!in_array($full_result, array('#_DESCRIPTION', '#_LOCATIONNOTES'))) {
             $location_string = str_replace($full_result, $replacement, $location_string);
         } else {
             $desc_replace[$full_result] = $replacement;
         }
     }
     //Finally, do the location notes, so that previous placeholders don't get replaced within the content, which may use shortcodes
     if (!empty($desc_replace)) {
         foreach ($desc_replace as $full_result => $replacement) {
             $location_string = str_replace($full_result, $replacement, $location_string);
         }
     }
     return apply_filters('em_location_output', $location_string, $this, $format, $target);
 }
示例#5
0
function em_admin_menu()
{
    global $menu, $submenu, $pagenow;
    //Count pending bookings
    if (get_option('dbem_rsvp_enabled')) {
        $bookings_num = '';
        $bookings_pending_count = apply_filters('em_bookings_pending_count', 0);
        if (get_option('dbem_bookings_approval') == 1) {
            $bookings_pending_count += count(EM_Bookings::get(array('status' => '0', 'blog' => get_current_blog_id()))->bookings);
        }
        if ($bookings_pending_count > 0) {
            $bookings_num = '<span class="update-plugins count-' . $bookings_pending_count . '"><span class="plugin-count">' . $bookings_pending_count . '</span></span>';
        }
    } else {
        $bookings_num = '';
        $bookings_pending_count = 0;
    }
    //Count pending events
    $events_num = '';
    $events_pending_count = EM_Events::count(array('status' => 0, 'scope' => 'all', 'blog' => get_current_blog_id()));
    //TODO Add flexible permissions
    if ($events_pending_count > 0) {
        $events_num = '<span class="update-plugins count-' . $events_pending_count . '"><span class="plugin-count">' . $events_pending_count . '</span></span>';
    }
    //Count pending recurring events
    $events_recurring_num = '';
    $events_recurring_pending_count = EM_Events::count(array('status' => 0, 'recurring' => 1, 'scope' => 'all', 'blog' => get_current_blog_id()));
    //TODO Add flexible permissions
    if ($events_recurring_pending_count > 0) {
        $events_recurring_num = '<span class="update-plugins count-' . $events_recurring_pending_count . '"><span class="plugin-count">' . $events_recurring_pending_count . '</span></span>';
    }
    $both_pending_count = apply_filters('em_items_pending_count', $events_pending_count + $bookings_pending_count + $events_recurring_pending_count);
    $both_num = $both_pending_count > 0 ? '<span class="update-plugins count-' . $both_pending_count . '"><span class="plugin-count">' . $both_pending_count . '</span></span>' : '';
    // Add a submenu to the custom top-level menu:
    $plugin_pages = array();
    if (get_option('dbem_rsvp_enabled')) {
        $plugin_pages['bookings'] = add_submenu_page('edit.php?post_type=' . EM_POST_TYPE_EVENT, __('Bookings', 'events-manager'), __('Bookings', 'events-manager') . $bookings_num, 'manage_bookings', 'events-manager-bookings', "em_bookings_page");
    }
    $plugin_pages['options'] = add_submenu_page('edit.php?post_type=' . EM_POST_TYPE_EVENT, __('Events Manager Settings', 'events-manager'), __('Settings', 'events-manager'), 'manage_options', "events-manager-options", 'em_admin_options_page');
    $plugin_pages['help'] = add_submenu_page('edit.php?post_type=' . EM_POST_TYPE_EVENT, __('Getting Help for Events Manager', 'events-manager'), __('Help', 'events-manager'), 'manage_options', "events-manager-help", 'em_admin_help_page');
    //If multisite global with locations set to be saved in main blogs we can force locations to be created on the main blog only
    if (EM_MS_GLOBAL && !is_main_site() && get_site_option('dbem_ms_mainblog_locations')) {
        include dirname(__FILE__) . "/em-ms-locations.php";
        $plugin_pages['locations'] = add_submenu_page('edit.php?post_type=' . EM_POST_TYPE_EVENT, __('Locations', 'events-manager'), __('Locations', 'events-manager'), 'read_others_locations', "locations", 'em_admin_ms_locations');
    }
    $plugin_pages = apply_filters('em_create_events_submenu', $plugin_pages);
    //We have to modify the menus manually
    if (!empty($both_num)) {
        //Main Event Menu
        //go through the menu array and modify the events menu if found
        foreach ((array) $menu as $key => $parent_menu) {
            if ($parent_menu[2] == 'edit.php?post_type=' . EM_POST_TYPE_EVENT) {
                $menu[$key][0] = $menu[$key][0] . $both_num;
                break;
            }
        }
    }
    if (!empty($events_num) && !empty($submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT])) {
        //Submenu Event Item
        //go through the menu array and modify the events menu if found
        foreach ((array) $submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT] as $key => $submenu_item) {
            if ($submenu_item[2] == 'edit.php?post_type=' . EM_POST_TYPE_EVENT) {
                $submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT][$key][0] = $submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT][$key][0] . $events_num;
                break;
            }
        }
    }
    if (!empty($events_recurring_num) && !empty($submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT])) {
        //Submenu Recurring Event Item
        //go through the menu array and modify the events menu if found
        foreach ((array) $submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT] as $key => $submenu_item) {
            if ($submenu_item[2] == 'edit.php?post_type=event-recurring') {
                $submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT][$key][0] = $submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT][$key][0] . $events_recurring_num;
                break;
            }
        }
    }
    /* Hack! Add location/recurrence isn't possible atm so this is a workaround */
    global $_wp_submenu_nopriv;
    if ($pagenow == 'post-new.php' && !empty($_REQUEST['post_type'])) {
        if ($_REQUEST['post_type'] == EM_POST_TYPE_LOCATION && !empty($_wp_submenu_nopriv['edit.php']['post-new.php']) && current_user_can('edit_locations')) {
            unset($_wp_submenu_nopriv['edit.php']['post-new.php']);
        }
        if ($_REQUEST['post_type'] == 'event-recurring' && !empty($_wp_submenu_nopriv['edit.php']['post-new.php']) && current_user_can('edit_recurring_events')) {
            unset($_wp_submenu_nopriv['edit.php']['post-new.php']);
        }
    }
}
示例#6
0
 function setup_group_nav()
 {
     global $bp;
     /* Add some group subnav items */
     $user_access = false;
     $group_link = '';
     if (bp_is_active('groups') && !empty($bp->groups->current_group)) {
         $group_link = $bp->root_domain . '/' . bp_get_groups_root_slug() . '/' . $bp->groups->current_group->slug . '/';
         $user_access = $bp->groups->current_group->user_has_access;
         if (!empty($bp->current_component) && $bp->current_component == 'groups') {
             $count = EM_Events::count(array('group' => $bp->groups->current_group->id));
             if (empty($count)) {
                 $count = 0;
             }
         }
         bp_core_new_subnav_item(array('name' => __('Events', 'dbem') . " <span>{$count}</span>", 'slug' => 'events', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->current_group->slug, 'screen_function' => 'bp_em_group_events', 'position' => 50, 'user_has_access' => $user_access, 'item_css_id' => 'forums'));
     }
 }
示例#7
0
 /**
  * Adds Future view to make things simpler, and also changes counts if user doesn't have edit_others_events permission
  * @param array $views
  * @return array
  */
 public static function restrict_views($views)
 {
     global $wp_query;
     //TODO alter views of locations, events and recurrences, specifically find a good way to alter the wp_count_posts method to force user owned posts only
     $post_type = get_current_screen()->post_type;
     if (in_array($post_type, array(EM_POST_TYPE_EVENT, 'event-recurring'))) {
         //get counts for future events
         $num_posts = wp_count_posts($post_type, 'readable');
         //prepare to alter cache if neccessary
         if (!isset($num_posts->em_future)) {
             $cache_key = $post_type;
             $user = wp_get_current_user();
             if (is_user_logged_in() && !current_user_can('read_private_events')) {
                 $cache_key .= '_readable_' . $user->ID;
                 //as seen on wp_count_posts
             }
             $args = array('scope' => 'future', 'status' => 'all');
             if ($post_type == 'event-recurring') {
                 $args['recurring'] = 1;
             }
             $num_posts->em_future = EM_Events::count($args);
             wp_cache_set($cache_key, $num_posts, 'counts');
         }
         $class = '';
         //highlight the 'Future' status if necessary
         if (empty($_REQUEST['post_status']) && !empty($wp_query->query_vars['scope']) && $wp_query->query_vars['scope'] == 'future') {
             $class = ' class="current"';
             foreach ($views as $key => $view) {
                 $views[$key] = str_replace(' class="current"', '', $view);
             }
         }
         //change the 'All' status to have scope=all
         $views['all'] = str_replace('edit.php?', 'edit.php?scope=all&', $views['all']);
         //merge new custom status into views
         $old_views = $views;
         $views = array('em_future' => "<a href='edit.php?post_type={$post_type}'{$class}>" . sprintf(_nx('Future <span class="count">(%s)</span>', 'Future <span class="count">(%s)</span>', $num_posts->em_future, 'events', 'events-manager'), number_format_i18n($num_posts->em_future)) . '</a>');
         $views = array_merge($views, $old_views);
     }
     return $views;
 }
示例#8
0
/**
 * Determines whether to show event page or events page, and saves any updates to the event or events
 * @return null
 */
function em_admin_events_page()
{
    //TODO Simplify panel for events, use form flags to detect certain actions (e.g. submitted, etc)
    global $wpdb, $EM_Notices, $EM_Event;
    $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
    $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'ASC';
    $limit = !empty($_REQUEST['limit']) ? $_REQUEST['limit'] : 20;
    //Default limit
    $page = !empty($_REQUEST['pno']) ? $_REQUEST['pno'] : 1;
    $offset = $page > 1 ? ($page - 1) * $limit : 0;
    $search = !empty($_REQUEST['em_search']) ? $_REQUEST['em_search'] : '';
    $scope_names = em_get_scopes();
    $scope = !empty($_REQUEST['scope']) && array_key_exists($_REQUEST['scope'], $scope_names) ? $_REQUEST['scope'] : 'future';
    $selectedEvents = !empty($_REQUEST['events']) ? $_REQUEST['events'] : '';
    $args = array('scope' => $scope, 'limit' => 0, 'order' => $order, 'search' => $search);
    if (!current_user_can('edit_others_events')) {
        $args['owner'] = get_current_user_id();
    }
    //Figure out what status to search for
    $args['status'] = isset($_REQUEST['status']) && is_numeric($_REQUEST['status']) ? $_REQUEST['status'] : false;
    $events = EM_Events::get($args);
    $events_count = count($events);
    $pending_count = EM_Events::count(array('status' => 0, 'scope' => $scope));
    $approved_count = EM_Events::count(array('status' => 1, 'scope' => $scope));
    $total_count = EM_Events::count(array('status' => false, 'scope' => $scope));
    $use_events_end = get_option('dbem_use_event_end');
    echo $EM_Notices;
    ?>
	<div class="wrap">
		<div id="icon-events" class="icon32"><br />
		</div>
		<h2>	
			<?php 
    echo $scope_names[$scope];
    ?>
 	 		<a href="admin.php?page=events-manager-event" class="button add-new-h2"><?php 
    _e('Add New', 'dbem');
    ?>
</a>
 	 	</h2>
		<?php 
    $link = array();
    $link['past'] = "<a href='" . get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager&amp;scope=past&amp;order=desc'>" . __('Past events', 'dbem') . "</a>";
    $link['all'] = " <a href='" . get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager&amp;scope=all&amp;order=desc'>" . __('All events', 'dbem') . "</a>";
    $link['future'] = "  <a href='" . get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager&amp;scope=future'>" . __('Future events', 'dbem') . "</a>";
    ?>
 
		<?php 
    if (!empty($_REQUEST['error'])) {
        ?>
		<div id='message' class='error'>
			<p><?php 
        echo $_REQUEST['error'];
        ?>
</p>
		</div>
		<?php 
    }
    ?>
		<?php 
    if (!empty($_REQUEST['message'])) {
        ?>
		<div id='message' class='updated fade'>
			<p><?php 
        echo $_REQUEST['message'];
        ?>
</p>
		</div>
		<?php 
    }
    ?>
		<form id="posts-filter" action="" method="get"><input type='hidden' name='page' value='events-manager' />
			<ul class="subsubsub">
				<li><a href='<?php 
    bloginfo('wpurl');
    ?>
/wp-admin/admin.php?page=events-manager&amp;scope=<?php 
    echo $scope;
    ?>
' <?php 
    echo !isset($_REQUEST['status']) ? 'class="current"' : '';
    ?>
><?php 
    _e('Total', 'dbem');
    ?>
 <span class="count">(<?php 
    echo $total_count;
    ?>
)</span></a></li>
				<?php 
    if (current_user_can('publish_events')) {
        ?>
				<li>| <a href='<?php 
        bloginfo('wpurl');
        ?>
/wp-admin/admin.php?page=events-manager&amp;scope=<?php 
        echo $scope;
        ?>
&amp;status=1' <?php 
        echo isset($_REQUEST['status']) && $_REQUEST['status'] == '1' ? 'class="current"' : '';
        ?>
><?php 
        _e('Approved', 'dbem');
        ?>
 <span class="count">(<?php 
        echo $approved_count;
        ?>
)</span></a></li>
				<li>| <a href='<?php 
        bloginfo('wpurl');
        ?>
/wp-admin/admin.php?page=events-manager&amp;scope=<?php 
        echo $scope;
        ?>
&amp;status=0' <?php 
        echo isset($_REQUEST['status']) && $_REQUEST['status'] == '0' ? 'class="current"' : '';
        ?>
><?php 
        _e('Pending', 'dbem');
        ?>
 <span class="count">(<?php 
        echo $pending_count;
        ?>
)</span></a></li>
				<?php 
    }
    ?>
			</ul>
			<p class="search-box">
				<label class="screen-reader-text" for="post-search-input"><?php 
    _e('Search Events', 'dbem');
    ?>
:</label>
				<input type="text" id="post-search-input" name="em_search" value="<?php 
    echo !empty($_REQUEST['em_search']) ? $_REQUEST['em_search'] : '';
    ?>
" />
				<input type="submit" value="<?php 
    _e('Search Events', 'dbem');
    ?>
" class="button" />
			</p>			
			<div class="tablenav">
			
				<div class="alignleft actions">
					<select name="action">
						<option value="-1" selected="selected"><?php 
    _e('Bulk Actions');
    ?>
</option>
						<option value="event_delete"><?php 
    _e('Delete selected', 'dbem');
    ?>
</option>
					</select> 
					<input type="submit" value="<?php 
    _e('Apply');
    ?>
" name="doaction2" id="doaction2" class="button-secondary action" /> 
					<select name="scope">
						<?php 
    foreach ($scope_names as $key => $value) {
        $selected = "";
        if ($key == $scope) {
            $selected = "selected='selected'";
        }
        echo "<option value='{$key}' {$selected}>{$value}</option>  ";
    }
    ?>
					</select> 
					<input id="post-query-submit" class="button-secondary" type="submit" value="<?php 
    _e('Filter');
    ?>
" />
				</div>
				<!--
				<div class="view-switch">
					<a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
				</div>
				-->
				<?php 
    if ($events_count >= $limit) {
        $events_nav = em_admin_paginate($events_count, $limit, $page);
        echo $events_nav;
    }
    ?>
				<br class="clear" />
			</div>
				
			<?php 
    if (empty($events)) {
        // TODO localize
        _e('no events', 'dbem');
    } else {
        ?>
					
			<table class="widefat events-table">
				<thead>
					<tr>
						<th class='manage-column column-cb check-column' scope='col'>
							<input class='select-all' type="checkbox" value='1' />
						</th>
						<th><?php 
        _e('Name', 'dbem');
        ?>
</th>
						<th>&nbsp;</th>
						<th><?php 
        _e('Location', 'dbem');
        ?>
</th>
						<th colspan="2"><?php 
        _e('Date and time', 'dbem');
        ?>
</th>
					</tr>
				</thead>
				<tbody>
					<?php 
        $rowno = 0;
        $event_count = 0;
        foreach ($events as $event) {
            /* @var $event EM_Event */
            if (($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0)) {
                $rowno++;
                $class = $rowno % 2 ? 'alternate' : '';
                // FIXME set to american
                $localised_start_date = date_i18n('D d M Y', $event->start);
                $localised_end_date = date_i18n('D d M Y', $event->end);
                $style = "";
                $today = date("Y-m-d");
                $location_summary = "<b>" . $event->location->name . "</b><br/>" . $event->location->address . " - " . $event->location->town;
                if ($event->start_date < $today && $event->end_date < $today) {
                    $class .= " past";
                }
                //Check pending approval events
                if (!$event->status) {
                    $class .= " pending";
                }
                ?>
							<tr class="event <?php 
                echo trim($class);
                ?>
" <?php 
                echo $style;
                ?>
 id="event_<?php 
                echo $event->id;
                ?>
">
								<td>
									<input type='checkbox' class='row-selector' value='<?php 
                echo $event->id;
                ?>
' name='events[]' />
								</td>
								<td>
									<strong>
										<a class="row-title" href="<?php 
                bloginfo('wpurl');
                ?>
/wp-admin/admin.php?page=events-manager-event&amp;event_id=<?php 
                echo $event->id;
                ?>
&amp;scope=<?php 
                echo $scope;
                ?>
&amp;pno=<?php 
                echo $page;
                ?>
"><?php 
                echo $event->name;
                ?>
</a>
									</strong>
									<?php 
                if (get_option('dbem_rsvp_enabled') == 1 && $event->rsvp == 1) {
                    ?>
										<br/>
										<a href="<?php 
                    bloginfo('wpurl');
                    ?>
/wp-admin/admin.php?page=events-manager-bookings&amp;event_id=<?php 
                    echo $event->id;
                    ?>
"><?php 
                    echo __("Bookings", 'dbem');
                    ?>
</a> &ndash;
										<?php 
                    _e("Booked", 'dbem');
                    ?>
: <?php 
                    echo $event->get_bookings()->get_booked_spaces() . "/" . $event->get_spaces();
                    ?>
										<?php 
                    if (get_option('dbem_bookings_approval') == 1) {
                        ?>
											| <?php 
                        _e("Pending", 'dbem');
                        ?>
: <?php 
                        echo $event->get_bookings()->get_pending_spaces();
                        ?>
										<?php 
                    }
                }
                ?>
									<div class="row-actions">
										<span class="trash"><a href="<?php 
                bloginfo('wpurl');
                ?>
/wp-admin/admin.php?page=events-manager&amp;action=event_delete&amp;event_id=<?php 
                echo $event->id;
                ?>
&amp;scope=<?php 
                echo $scope;
                ?>
&amp;pno=<?php 
                echo $page;
                ?>
" class="em-event-delete"><?php 
                _e('Delete', 'dbem');
                ?>
</a></span>
										<?php 
                if (!$event->status && current_user_can('publish_events')) {
                    ?>
										| <a href="<?php 
                    bloginfo('wpurl');
                    ?>
/wp-admin/admin.php?page=events-manager&amp;action=event_approve&amp;event_id=<?php 
                    echo $event->id;
                    ?>
&amp;scope=<?php 
                    echo $scope;
                    ?>
&amp;pno=<?php 
                    echo $page;
                    ?>
" class="em-event-approve" style="color:green"><?php 
                    _e('Approve', 'dbem');
                    ?>
</a>
										<?php 
                }
                ?>
									</div>
								</td>
								<td>
									<a href="<?php 
                bloginfo('wpurl');
                ?>
/wp-admin/admin.php?page=events-manager-event&amp;action=event_duplicate&amp;event_id=<?php 
                echo $event->id;
                ?>
&amp;scope=<?php 
                echo $scope;
                ?>
&amp;pno=<?php 
                echo $page;
                ?>
" title="<?php 
                _e('Duplicate this event', 'dbem');
                ?>
">
										<strong>+</strong>
									</a>
								</td>
								<td>
									<?php 
                echo $location_summary;
                ?>
								</td>
						
								<td>
									<?php 
                echo $localised_start_date;
                ?>
									<?php 
                echo $localised_end_date != $localised_start_date ? " - {$localised_end_date}" : '';
                ?>
									<br />
									<?php 
                //TODO Should 00:00 - 00:00 be treated as an all day event?
                echo substr($event->start_time, 0, 5) . " - " . substr($event->end_time, 0, 5);
                ?>
								</td>
								<td>
									<?php 
                if ($event->is_recurrence()) {
                    $recurrence_delete_confirm = __('WARNING! You will delete ALL recurrences of this event, including booking history associated with any event in this recurrence. To keep booking information, go to the relevant single event and save it to detach it from this recurrence series.', 'dbem');
                    ?>
										<strong>
										<?php 
                    echo $event->get_recurrence_description();
                    ?>
 <br />
										<a href="<?php 
                    bloginfo('wpurl');
                    ?>
/wp-admin/admin.php?page=events-manager-event&amp;event_id=<?php 
                    echo $event->recurrence_id;
                    ?>
&amp;scope=<?php 
                    echo $scope;
                    ?>
&amp;pno=<?php 
                    echo $page;
                    ?>
"><?php 
                    _e('Reschedule', 'dbem');
                    ?>
</a> |
										<span class="trash"><a href="<?php 
                    bloginfo('wpurl');
                    ?>
/wp-admin/admin.php?page=events-manager&amp;action=event_delete&amp;event_id=<?php 
                    echo $event->recurrence_id;
                    ?>
&amp;scope=<?php 
                    echo $scope;
                    ?>
&amp;pno=<?php 
                    echo $page;
                    ?>
" class="em-event-rec-delete" onclick ="if( !confirm('<?php 
                    echo $recurrence_delete_confirm;
                    ?>
') ){ return false; }"><?php 
                    _e('Delete', 'dbem');
                    ?>
</a></span>
										</strong>
										<?php 
                }
                ?>
								</td>
							</tr>
							<?php 
            }
            $event_count++;
        }
        ?>
				</tbody>
			</table>  
			<?php 
    }
    // end of table
    ?>
			<div class='tablenav'>
				<div class="alignleft actions">
				<br class='clear' />
				</div>
				<?php 
    if ($events_count >= $limit) {
        ?>
				<div class="tablenav-pages">
					<?php 
        echo $events_nav;
        ?>
				</div>
				<?php 
    }
    ?>
				<br class='clear' />
			</div>
		</form>
	</div>
	<?php 
}
示例#9
0
/**
 * Outputs table of events belonging to user
 * Additional search arguments:
 * * show_add_new - passes argument to template as $show_add_new whether to show the add new event button
 * @param array $args
 */
function em_events_admin($args = array())
{
    global $EM_Event, $bp;
    if (is_user_logged_in() && current_user_can('edit_events')) {
        if (!empty($_GET['action']) && $_GET['action'] == 'edit') {
            if (empty($_REQUEST['redirect_to'])) {
                $_REQUEST['redirect_to'] = em_add_get_params($_SERVER['REQUEST_URI'], array('action' => null, 'event_id' => null));
            }
            em_event_form();
        } else {
            if (get_option('dbem_css_editors')) {
                echo '<div class="css-events-admin">';
            }
            //template $args for different views
            $args_views['pending'] = array('status' => 0, 'owner' => get_current_user_id(), 'scope' => 'all', 'recurring' => 'include');
            $args_views['draft'] = array('status' => null, 'owner' => get_current_user_id(), 'scope' => 'all', 'recurring' => 'include');
            $args_views['past'] = array('status' => 'all', 'owner' => get_current_user_id(), 'scope' => 'past');
            $args_views['future'] = array('status' => '1', 'owner' => get_current_user_id(), 'scope' => 'future');
            //get listing options for $args
            $limit = !empty($_REQUEST['limit']) ? $_REQUEST['limit'] : 20;
            //Default limit
            $page = !empty($_REQUEST['pno']) ? $_REQUEST['pno'] : 1;
            $offset = $page > 1 ? ($page - 1) * $limit : 0;
            $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'ASC';
            $search = !empty($_REQUEST['em_search']) ? $_REQUEST['em_search'] : '';
            //deal with view or scope/status combinations
            $show_add_new = isset($args['show_add_new']) ? $args['show_add_new'] : true;
            $args = array('order' => $order, 'search' => $search, 'owner' => get_current_user_id());
            if (!empty($_REQUEST['view']) && in_array($_REQUEST['view'], array('future', 'draft', 'past', 'pending'))) {
                $args = array_merge($args, $args_views[$_REQUEST['view']]);
            } else {
                $scope_names = em_get_scopes();
                $args['scope'] = !empty($_REQUEST['scope']) && array_key_exists($_REQUEST['scope'], $scope_names) ? $_REQUEST['scope'] : 'future';
                if (array_key_exists('status', $_REQUEST)) {
                    $status = $_REQUEST['status'] ? 1 : 0;
                    if ($_REQUEST['status'] == 'all') {
                        $status = 'all';
                    }
                    if ($_REQUEST['status'] == 'draft') {
                        $status = null;
                    }
                } else {
                    $status = false;
                }
                $args['status'] = $status;
            }
            $events_count = EM_Events::count($args);
            //count events without limits for pagination
            $args['limit'] = $limit;
            $args['offset'] = $offset;
            $EM_Events = EM_Events::get($args);
            //now get the limited events to display
            $future_count = EM_Events::count($args_views['future']);
            $pending_count = EM_Events::count($args_views['pending']);
            $draft_count = EM_Events::count($args_views['draft']);
            $past_count = EM_Events::count($args_views['past']);
            em_locate_template('tables/events.php', true, array('args' => $args, 'EM_Events' => $EM_Events, 'events_count' => $events_count, 'future_count' => $future_count, 'pending_count' => $pending_count, 'draft_count' => $draft_count, 'past_count' => $past_count, 'page' => $page, 'limit' => $limit, 'offset' => $offset, 'show_add_new' => $show_add_new));
            if (get_option('dbem_css_editors')) {
                echo '</div>';
            }
        }
    } elseif (!is_user_logged_in() && get_option('dbem_events_anonymous_submissions')) {
        em_event_form($args);
    } else {
        if (get_option('dbem_css_editors')) {
            echo '<div class="css-events-admin">';
        }
        echo '<div class="css-events-admin-login">' . apply_filters('em_event_submission_login', __("You must log in to view and manage your events.", 'dbem')) . '</div>';
        if (get_option('dbem_css_editors')) {
            echo '</div>';
        }
    }
}
示例#10
0
 function output($format, $target = "html")
 {
     preg_match_all('/\\{([a-zA-Z0-9_]+)\\}([^{]+)\\{\\/[a-zA-Z0-9_]+\\}/', $format, $conditionals);
     if (count($conditionals[0]) > 0) {
         //Check if the language we want exists, if not we take the first language there
         foreach ($conditionals[1] as $key => $condition) {
             $format = str_replace($conditionals[0][$key], apply_filters('em_category_output_condition', '', $condition, $conditionals[0][$key], $this), $format);
         }
     }
     $category_string = $format;
     preg_match_all("/(#@?_?[A-Za-z0-9]+)({([a-zA-Z0-9,]+)})?/", $format, $placeholders);
     foreach ($placeholders[1] as $key => $result) {
         $replace = '';
         $full_result = $placeholders[0][$key];
         switch ($result) {
             case '#_CATEGORYNAME':
                 $replace = $this->name;
                 break;
             case '#_CATEGORYID':
                 $replace = $this->term_id;
                 break;
             case '#_CATEGORYNOTES':
             case '#_CATEGORYDESCRIPTION':
                 $replace = $this->description;
                 break;
             case '#_CATEGORYIMAGE':
             case '#_CATEGORYIMAGEURL':
                 if ($this->get_image_url() != '') {
                     if ($result == '#_CATEGORYIMAGEURL') {
                         $replace = $this->get_image_url();
                     } else {
                         if (empty($placeholders[3][$key])) {
                             $replace = "<img src='" . esc_url($this->get_image_url()) . "' alt='" . esc_attr($this->name) . "'/>";
                         } else {
                             $image_size = explode(',', $placeholders[3][$key]);
                             if ($this->array_is_numeric($image_size) && count($image_size) > 1) {
                                 if (get_option('dbem_disable_timthumb') && $this->get_image_id()) {
                                     //since we previously didn't store image ids along with the url to the image (since taxonomies don't allow normal featured images), sometimes we won't be able to do this, which is why we check there's a valid image id first
                                     $this->ms_global_switch();
                                     $replace = wp_get_attachment_image($this->get_image_id(), $image_size);
                                     $this->ms_global_switch_back();
                                 } else {
                                     $replace = "<img src='" . em_get_thumbnail_url($this->get_image_url(), $image_size[0], $image_size[1]) . "' alt='" . esc_attr($this->name) . "' width='{$image_size[0]}' height='{$image_size[1]}'/>";
                                 }
                             } else {
                                 $replace = "<img src='" . esc_url($this->get_image_url()) . "' alt='" . esc_attr($this->name) . "'/>";
                             }
                         }
                     }
                 }
                 break;
             case '#_CATEGORYCOLOR':
                 $replace = $this->get_color();
                 break;
             case '#_CATEGORYLINK':
             case '#_CATEGORYURL':
                 $link = $this->get_url();
                 $replace = $result == '#_CATEGORYURL' ? $link : '<a href="' . $link . '">' . esc_html($this->name) . '</a>';
                 break;
             case '#_CATEGORYSLUG':
                 $replace = $this->slug;
                 break;
             case '#_CATEGORYEVENTSPAST':
                 //depreciated, erroneous documentation, left for compatability
             //depreciated, erroneous documentation, left for compatability
             case '#_CATEGORYEVENTSNEXT':
                 //depreciated, erroneous documentation, left for compatability
             //depreciated, erroneous documentation, left for compatability
             case '#_CATEGORYEVENTSALL':
                 //depreciated, erroneous documentation, left for compatability
             //depreciated, erroneous documentation, left for compatability
             case '#_CATEGORYPASTEVENTS':
             case '#_CATEGORYNEXTEVENTS':
             case '#_CATEGORYALLEVENTS':
                 //convert depreciated placeholders for compatability
                 $result = $result == '#_CATEGORYEVENTSPAST' ? '#_CATEGORYPASTEVENTS' : $result;
                 $result = $result == '#_CATEGORYEVENTSNEXT' ? '#_CATEGORYNEXTEVENTS' : $result;
                 $result = $result == '#_CATEGORYEVENTSALL' ? '#_CATEGORYALLEVENTS' : $result;
                 //forget it ever happened? :/
                 if ($result == '#_CATEGORYPASTEVENTS') {
                     $scope = 'past';
                 } elseif ($result == '#_CATEGORYNEXTEVENTS') {
                     $scope = 'future';
                 } else {
                     $scope = 'all';
                 }
                 $events_count = EM_Events::count(array('category' => $this->term_id, 'scope' => $scope));
                 if ($events_count > 0) {
                     $args = array('category' => $this->term_id, 'scope' => $scope, 'pagination' => 1);
                     $args['format_header'] = get_option('dbem_category_event_list_item_header_format');
                     $args['format_footer'] = get_option('dbem_category_event_list_item_footer_format');
                     $args['format'] = get_option('dbem_category_event_list_item_format');
                     $args['limit'] = get_option('dbem_category_event_list_limit');
                     $args['page'] = !empty($_REQUEST['pno']) && is_numeric($_REQUEST['pno']) ? $_REQUEST['pno'] : 1;
                     $replace = EM_Events::output($args);
                 } else {
                     $replace = get_option('dbem_category_no_events_message', '</ul>');
                 }
                 break;
             default:
                 $replace = $full_result;
                 break;
         }
         $replace = apply_filters('em_category_output_placeholder', $replace, $this, $full_result, $target);
         //USE WITH CAUTION! THIS MIGHT GET RENAMED
         $category_string = str_replace($full_result, $replace, $category_string);
     }
     $name_filter = $target == "html" ? 'dbem_general' : 'dbem_general_rss';
     //TODO remove dbem_ filters
     $category_string = str_replace('#_CATEGORY', apply_filters($name_filter, $this->name), $category_string);
     //Depreciated
     return apply_filters('em_category_output', $category_string, $this, $format, $target);
 }
示例#11
0
function em_create_events_submenu()
{
    if (function_exists('add_submenu_page')) {
        //Count pending bookings
        $bookings_num = '';
        $bookings_pending_count = 0;
        if (get_option('dbem_bookings_approval') == 1) {
            $bookings_pending_count = count(EM_Bookings::get(array('status' => 0))->bookings);
            //TODO Add flexible permissions
            if ($bookings_pending_count > 0) {
                $bookings_num = '<span class="update-plugins count-' . $bookings_pending_count . '"><span class="plugin-count">' . $bookings_pending_count . '</span></span>';
            }
        }
        //Count pending events
        $events_num = '';
        $events_pending_count = EM_Events::count(array('status' => 0, 'scope' => 'all'));
        //TODO Add flexible permissions
        if ($events_pending_count > 0) {
            $events_num = '<span class="update-plugins count-' . $events_pending_count . '"><span class="plugin-count">' . $events_pending_count . '</span></span>';
        }
        $both_pending_count = $events_pending_count + $bookings_pending_count;
        $both_num = $both_pending_count > 0 ? '<span class="update-plugins count-' . $both_pending_count . '"><span class="plugin-count">' . $both_pending_count . '</span></span>' : '';
        add_object_page(__('Events', 'dbem'), __('Events', 'dbem') . $both_num, 'edit_events', 'events-manager', 'em_admin_events_page', '../wp-content/plugins/events-manager/includes/images/calendar-16.png');
        // Add a submenu to the custom top-level menu:
        $plugin_pages = array();
        $plugin_pages[] = add_submenu_page('events-manager', __('Edit'), __('Edit') . $events_num, 'edit_events', 'events-manager', 'em_admin_events_page');
        $plugin_pages[] = add_submenu_page('events-manager', __('Add new', 'dbem'), __('Add new', 'dbem'), 'edit_events', 'events-manager-event', "em_admin_event_page");
        $plugin_pages[] = add_submenu_page('events-manager', __('Locations', 'dbem'), __('Locations', 'dbem'), 'edit_locations', 'events-manager-locations', "em_admin_locations_page");
        $plugin_pages[] = add_submenu_page('events-manager', __('Bookings', 'dbem'), __('Bookings', 'dbem') . $bookings_num, 'manage_bookings', 'events-manager-bookings', "em_bookings_page");
        $plugin_pages[] = add_submenu_page('events-manager', __('Event Categories', 'dbem'), __('Categories', 'dbem'), 'edit_categories', "events-manager-categories", 'em_admin_categories_page');
        $plugin_pages[] = add_submenu_page('events-manager', __('Events Manager Settings', 'dbem'), __('Settings', 'dbem'), 'activate_plugins', "events-manager-options", 'em_admin_options_page');
        $plugin_pages[] = add_submenu_page('events-manager', __('Getting Help for Events Manager', 'dbem'), __('Help', 'dbem'), 'activate_plugins', "events-manager-help", 'em_admin_help_page');
        $plugin_pages = apply_filters('em_create_events_submenu', $plugin_pages);
        foreach ($plugin_pages as $plugin_page) {
            add_action('admin_print_scripts-' . $plugin_page, 'em_admin_load_scripts');
            add_action('admin_head-' . $plugin_page, 'em_admin_general_script');
            add_action('admin_print_styles-' . $plugin_page, 'em_admin_load_styles');
        }
    }
}
示例#12
0
/**
 * Outputs table of events belonging to user
 * @param array $args
 */
function em_events_admin($args = array())
{
    global $EM_Event, $bp;
    if (is_user_logged_in() && current_user_can('edit_events')) {
        if (!empty($_GET['action']) && $_GET['action'] == 'edit') {
            if (empty($_REQUEST['redirect_to'])) {
                $_REQUEST['redirect_to'] = em_add_get_params($_SERVER['REQUEST_URI'], array('action' => null, 'event_id' => null));
            }
            em_event_form();
        } else {
            $limit = !empty($_REQUEST['limit']) ? $_REQUEST['limit'] : 20;
            //Default limit
            $page = !empty($_REQUEST['pno']) ? $_REQUEST['pno'] : 1;
            $offset = $page > 1 ? ($page - 1) * $limit : 0;
            $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'ASC';
            $scope_names = em_get_scopes();
            $scope = !empty($_REQUEST['scope']) && array_key_exists($_REQUEST['scope'], $scope_names) ? $_REQUEST['scope'] : 'future';
            if (array_key_exists('status', $_REQUEST)) {
                $status = $_REQUEST['status'] ? 1 : 0;
            } else {
                $status = false;
            }
            $search = !empty($_REQUEST['em_search']) ? $_REQUEST['em_search'] : '';
            $args = array('scope' => $scope, 'order' => $order, 'search' => $search, 'owner' => get_current_user_id(), 'status' => $status);
            $events_count = EM_Events::count($args);
            //count events without limits for pagination
            $args['limit'] = $limit;
            $args['offset'] = $offset;
            $EM_Events = EM_Events::get($args);
            if ($scope != 'future') {
                $future_count = EM_Events::count(array('status' => 1, 'owner' => get_current_user_id(), 'scope' => 'future'));
            } else {
                $future_count = $events_count;
            }
            $pending_count = EM_Events::count(array('status' => 0, 'owner' => get_current_user_id(), 'scope' => 'all'));
            em_locate_template('tables/events.php', true, array('args' => $args, 'EM_Events' => $EM_Events, 'events_count' => $events_count, 'future_count' => $future_count, 'pending_count' => $pending_count, 'page' => $page, 'limit' => $limit, 'offset' => $offset, 'show_add_new' => true));
        }
    } elseif (!is_user_logged_in() && get_option('dbem_events_anonymous_submissions')) {
        em_event_form($args);
    } else {
        echo apply_filters('em_event_submission_login', __("You must log in to view and manage your events.", 'dbem'));
    }
}
示例#13
0
 function output($format, $target = "html")
 {
     preg_match_all('/\\{([a-zA-Z0-9_]+)\\}([^{]+)\\{\\/[a-zA-Z0-9_]+\\}/', $format, $conditionals);
     if (count($conditionals[0]) > 0) {
         foreach ($conditionals[1] as $key => $condition) {
             $format = str_replace($conditionals[0][$key], apply_filters('em_tag_output_condition', '', $condition, $conditionals[0][$key], $this), $format);
         }
     }
     $tag_string = $format;
     preg_match_all("/(#@?_?[A-Za-z0-9]+)({([a-zA-Z0-9,]+)})?/", $format, $placeholders);
     $replaces = array();
     foreach ($placeholders[1] as $key => $result) {
         $match = true;
         $replace = '';
         $full_result = $placeholders[0][$key];
         switch ($result) {
             case '#_TAGNAME':
                 $replace = $this->name;
                 break;
             case '#_TAGID':
                 $replace = $this->term_id;
                 break;
             case '#_TAGLINK':
             case '#_TAGURL':
                 $link = $this->get_url();
                 $replace = $result == '#_TAGURL' ? $link : '<a href="' . $link . '">' . esc_html($this->name) . '</a>';
                 break;
             case '#_TAGICALURL':
             case '#_TAGICALLINK':
                 $replace = $this->get_ical_url();
                 if ($result == '#_TAGICALLINK') {
                     $replace = '<a href="' . esc_url($replace) . '">iCal</a>';
                 }
                 break;
             case '#_TAGRSSURL':
             case '#_TAGRSSLINK':
                 $replace = $this->get_rss_url();
                 if ($result == '#_TAGRSSLINK') {
                     $replace = '<a href="' . esc_url($replace) . '">RSS</a>';
                 }
                 break;
             case '#_TAGNOTES':
                 $replace = $this->description;
                 break;
             case '#_TAGEVENTSPAST':
                 //depreciated, erroneous documentation, left for compatability
             //depreciated, erroneous documentation, left for compatability
             case '#_TAGEVENTSNEXT':
                 //depreciated, erroneous documentation, left for compatability
             //depreciated, erroneous documentation, left for compatability
             case '#_TAGEVENTSALL':
                 //depreciated, erroneous documentation, left for compatability
             //depreciated, erroneous documentation, left for compatability
             case '#_TAGPASTEVENTS':
             case '#_TAGNEXTEVENTS':
             case '#_TAGALLEVENTS':
                 //convert depreciated placeholders for compatability
                 $result = $result == '#_TAGEVENTSPAST' ? '#_TAGPASTEVENTS' : $result;
                 $result = $result == '#_TAGEVENTSNEXT' ? '#_TAGNEXTEVENTS' : $result;
                 $result = $result == '#_TAGEVENTSALL' ? '#_TAGALLEVENTS' : $result;
                 //forget it ever happened? :/
                 if ($result == '#_TAGPASTEVENTS') {
                     $scope = 'past';
                 } elseif ($result == '#_TAGNEXTEVENTS') {
                     $scope = 'future';
                 } else {
                     $scope = 'all';
                 }
                 $events_count = EM_Events::count(array('tag' => $this->term_id, 'scope' => $scope));
                 if ($events_count > 0) {
                     $args = array('tag' => $this->term_id, 'scope' => $scope, 'pagination' => 1, 'ajax' => 0);
                     $args['format_header'] = get_option('dbem_tag_event_list_item_header_format');
                     $args['format_footer'] = get_option('dbem_tag_event_list_item_footer_format');
                     $args['format'] = get_option('dbem_tag_event_list_item_format');
                     $args['limit'] = get_option('dbem_tag_event_list_limit');
                     $args['page'] = !empty($_REQUEST['pno']) && is_numeric($_REQUEST['pno']) ? $_REQUEST['pno'] : 1;
                     $replace = EM_Events::output($args);
                 } else {
                     $replace = get_option('dbem_tag_no_events_message');
                 }
                 break;
             case '#_TAGNEXTEVENT':
                 $events = EM_Events::get(array('tag' => $this->term_id, 'scope' => 'future', 'limit' => 1, 'orderby' => 'event_start_date,event_start_time'));
                 $replace = get_option('dbem_tag_no_event_message');
                 foreach ($events as $EM_Event) {
                     $replace = $EM_Event->output(get_option('dbem_tag_event_single_format'));
                 }
                 break;
             default:
                 $replace = $full_result;
                 break;
         }
         $replaces[$full_result] = apply_filters('em_tag_output_placeholder', $replace, $this, $full_result, $target);
     }
     krsort($replaces);
     foreach ($replaces as $full_result => $replacement) {
         $tag_string = str_replace($full_result, $replacement, $tag_string);
     }
     return apply_filters('em_tag_output', $tag_string, $this, $format, $target);
 }
示例#14
0
<?php

/* WARNING! This file may change in the near future as we intend to add features to BuddyPress - 2012-02-14 */
global $bp, $EM_Notices;
echo $EM_Notices;
$url = $bp->events->link . 'my-events/';
//url to this page
$order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'ASC';
$limit = !empty($_REQUEST['limit']) ? $_REQUEST['limit'] : 20;
//Default limit
$page = !empty($_REQUEST['pno']) ? $_REQUEST['pno'] : 1;
$offset = $page > 1 ? ($page - 1) * $limit : 0;
$EM_Events = EM_Events::get(array('group' => 'my', 'scope' => 'future', 'limit' => 0, 'order' => $order));
$events_count = count($EM_Events);
$future_count = EM_Events::count(array('status' => 1, 'owner' => get_current_user_id(), 'scope' => 'future'));
$pending_count = EM_Events::count(array('status' => 0, 'owner' => get_current_user_id(), 'scope' => 'all'));
$use_events_end = get_option('dbem_use_event_end');
echo $EM_Notices;
?>
	<div class="tablenav">
		<?php 
if ($events_count >= $limit) {
    $events_nav = em_admin_paginate($events_count, $limit, $page);
    echo $events_nav;
}
?>
		<br class="clear" />
	</div>
		
	<?php 
if (empty($EM_Events)) {
示例#15
0
<?php

/*
 * Default Calendar day
 * This page displays a list of events or single event for a specific calendar day, called during the em_content() if this is an calendar day page.
 * You can override the default display settings pages by copying this file to yourthemefolder/plugins/events-manager/templates/ and modifying it however you need.
 * You can display events however you wish, there are a few variables made available to you:
 * 
 * $args - the args passed onto EM_Events::output()
 * 
 */
$args['scope'] = $_REQUEST['calendar_day'];
$events_count = EM_Events::count(apply_filters('em_content_calendar_day_args', $args));
//Get events first, so we know how many there are in advance
if ($events_count > 1 || get_option('dbem_display_calendar_day_single') == 1) {
    em_locate_template('templates/events-list.php', true, array('args' => apply_filters('em_content_calendar_day_output_args', $args)));
} elseif ($events_count == 1) {
    $args['format'] = get_option('dbem_single_event_format');
    echo EM_Events::output(apply_filters('em_content_calendar_day_output_args', $args));
} else {
    echo get_option('dbem_no_events_message');
}
示例#16
0
 * Default Events List Template
 * This page displays a list of events, called during the em_content() if this is an events list page.
 * You can override the default display settings pages by copying this file to yourthemefolder/plugins/events-manager/templates/ and modifying it however you need.
 * You can display events however you wish, there are a few variables made available to you:
 * 
 * $args - the args passed onto EM_Events::output()
 * 
 */
if (get_option('dbem_events_page_search') && !defined('DOING_AJAX')) {
    em_locate_template('templates/events-search.php', true);
}
//TODO fine tune ajax searches - we have some pagination issues otherwise, due to search querystrings
if (get_option('dbem_events_page_ajax', defined('EM_AJAX_SEARCH'))) {
    echo "<div class='em-events-search-ajax'>";
}
$events_count = EM_Events::count(apply_filters('em_content_events_args', $args));
$args['limit'] = get_option('dbem_events_default_limit');
$args['page'] = !empty($_REQUEST['pno']) && is_numeric($_REQUEST['pno']) ? $_REQUEST['pno'] : 1;
if ($events_count > 0) {
    //If there's a search, let's change the pagination a little here
    if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'search_events') {
        $args['pagination'] = false;
        if (get_option('dbem_event_list_groupby')) {
            $args['mode'] = get_option('dbem_event_list_groupby');
            $args['date_format'] = get_option('dbem_event_list_groupby_format');
            echo em_events_list_grouped($args);
        } else {
            echo EM_Events::output($args);
        }
        //do some custom pagination (if needed/requested)
        if (!empty($args['limit']) && $events_count > $args['limit']) {
示例#17
0
文件: profile.php 项目: interfisch/lm
<?php

/* WARNING! This file may change in the near future as we intend to add features to BuddyPress - 2012-02-14 */
global $bp, $EM_Notices;
echo $EM_Notices;
if (user_can($bp->displayed_user->id, 'edit_events')) {
    ?>
	<h4><?php 
    _e('My Events', 'events-manager');
    ?>
</h4>
	<?php 
    $args = array('owner' => $bp->displayed_user->id, 'format_header' => get_option('dbem_bp_events_list_format_header'), 'format' => get_option('dbem_bp_events_list_format'), 'format_footer' => get_option('dbem_bp_events_list_format_footer'), 'owner' => $bp->displayed_user->id, 'pagination' => 1);
    $args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_events_default_limit');
    if (EM_Events::count($args) > 0) {
        echo EM_Events::output($args);
    } else {
        ?>
		<p><?php 
        _e('No Events', 'events-manager');
        ?>
.
		<?php 
        if (get_current_user_id() == $bp->displayed_user->id) {
            ?>
 
		<a href="<?php 
            echo $bp->events->link . 'my-events/edit/';
            ?>
"><?php 
            _e('Add Event', 'events-manager');
示例#18
0
/**
 * Determines whether to show event page or events page, and saves any updates to the event or events
 * @return null
 */
function em_bookings_events_table()
{
    //TODO Simplify panel for events, use form flags to detect certain actions (e.g. submitted, etc)
    global $wpdb;
    global $EM_Event;
    $scope_names = array('past' => __('Past events', 'dbem'), 'all' => __('All events', 'dbem'), 'future' => __('Future events', 'dbem'));
    $action_scope = !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_events_table';
    $action = $action_scope && !empty($_GET['action']) ? $_GET['action'] : '';
    $order = $action_scope && !empty($_GET['order']) ? $_GET['order'] : 'ASC';
    $limit = $action_scope && !empty($_GET['limit']) ? $_GET['limit'] : 20;
    //Default limit
    $page = $action_scope && !empty($_GET['pno']) ? $_GET['pno'] : 1;
    $offset = $action_scope && $page > 1 ? ($page - 1) * $limit : 0;
    $scope = $action_scope && !empty($_GET['scope']) && array_key_exists($_GET['scope'], $scope_names) ? $_GET['scope'] : 'future';
    // No action, only showing the events list
    switch ($scope) {
        case "past":
            $title = __('Past Events', 'dbem');
            break;
        case "all":
            $title = __('All Events', 'dbem');
            break;
        default:
            $title = __('Future Events', 'dbem');
            $scope = "future";
    }
    $owner = !current_user_can('manage_others_bookings') ? get_current_user_id() : false;
    $events = EM_Events::get(array('scope' => $scope, 'limit' => $limit, 'offset' => $offset, 'order' => $order, 'bookings' => true, 'owner' => $owner));
    $events_count = EM_Events::count(array('scope' => $scope, 'limit' => 0, 'order' => $order, 'bookings' => true, 'owner' => $owner));
    $use_events_end = get_option('dbem_use_event_end');
    ?>

	<div class="wrap em_bookings_events_table em_obj">
		<form id="posts-filter" action="" method="get">
			<input type="hidden" name="em_obj" value="em_bookings_events_table" />
			<?php 
    if (!empty($_GET['page'])) {
        ?>

			<input type='hidden' name='page' value='events-manager-bookings' />
			<?php 
    }
    ?>
		
			<div class="tablenav">			
				<div class="alignleft actions">
					<!--
					<select name="action">
						<option value="-1" selected="selected"><?php 
    esc_html_e('Bulk Actions');
    ?>
</option>
						<option value="deleteEvents"><?php 
    esc_html_e('Delete selected', 'dbem');
    ?>
</option>
					</select> 
					<input type="submit" value="<?php 
    esc_html_e('Apply');
    ?>
" name="doaction2" id="doaction2" class="button-secondary action" />
					 --> 
					<select name="scope">
						<?php 
    foreach ($scope_names as $key => $value) {
        $selected = "";
        if ($key == $scope) {
            $selected = "selected='selected'";
        }
        echo "<option value='{$key}' {$selected}>{$value}</option>  ";
    }
    ?>

					</select>
					<input id="post-query-submit" class="button-secondary" type="submit" value="<?php 
    esc_html_e('Filter');
    ?>
" />
				</div>
				<!--
				<div class="view-switch">
					<a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
				</div>
				-->
				<?php 
    if ($events_count >= $limit) {
        $events_nav = em_admin_paginate($events_count, $limit, $page, array('em_ajax' => 0, 'em_obj' => 'em_bookings_events_table'));
        echo $events_nav;
    }
    ?>

			</div>
				
			<?php 
    if (empty($events)) {
        // TODO localize
        _e('no events', 'dbem');
    } else {
        ?>

			<div class='table-wrap'>	
			<table class="widefat">
				<thead>
					<tr>
						<th><?php 
        esc_html_e('Event', 'dbem');
        ?>
</th>
						<th><?php 
        esc_html_e('Date and time', 'dbem');
        ?>
</th>
					</tr>
				</thead>
				<tbody>
					<?php 
        $rowno = 0;
        foreach ($events as $event) {
            /* @var $event EM_Event */
            $rowno++;
            $class = $rowno % 2 ? ' class="alternate"' : '';
            // FIXME set to american
            $localised_start_date = date_i18n(get_option('date_format'), $event->start);
            $localised_end_date = date_i18n(get_option('date_format'), $event->end);
            $style = "";
            $today = date("Y-m-d");
            if ($event->start_date < $today && $event->end_date < $today) {
                $style = "style ='background-color: #FADDB7;'";
            }
            ?>

						<tr <?php 
            echo "{$class} {$style}";
            ?>
>
							<td>
								<strong>
									<?php 
            echo $event->output('#_BOOKINGSLINK');
            ?>

								</strong>
								&ndash; 
								<?php 
            esc_html_e("Booked Spaces", 'dbem');
            ?>
: <?php 
            echo $event->get_bookings()->get_booked_spaces() . "/" . $event->get_spaces();
            ?>

								<?php 
            if (get_option('dbem_bookings_approval') == 1) {
                ?>

									| <?php 
                esc_html_e("Pending", 'dbem');
                ?>
: <?php 
                echo $event->get_bookings()->get_pending_spaces();
                ?>

								<?php 
            }
            ?>

							</td>
					
							<td>
								<?php 
            echo $localised_start_date;
            ?>

								<?php 
            echo $localised_end_date != $localised_start_date ? " - {$localised_end_date}" : '';
            ?>

								&ndash;
								<?php 
            //TODO Should 00:00 - 00:00 be treated as an all day event?
            echo substr($event->start_time, 0, 5) . " - " . substr($event->end_time, 0, 5);
            ?>

							</td>
						</tr>
						<?php 
        }
        ?>

				</tbody>
			</table>
			</div>
			<?php 
    }
    // end of table
    ?>

			<div class='tablenav'>
				<div class="alignleft actions">
				<br class='clear' />
				</div>
				<?php 
    if (!empty($events_nav) && $events_count >= $limit) {
        ?>

				<div class="tablenav-pages">
					<?php 
        echo $events_nav;
        ?>

				</div>
				<?php 
    }
    ?>

				<br class='clear' />
			</div>
		</form>
	</div>
	<?php 
}