Example #1
0
/**
 * Shows a list of events according to given specifications. Accepts any event query attribute.
 * @param array $atts
 * @return string
 */
function em_get_event_shortcode($atts, $format = '')
{
    $atts = (array) $atts;
    $atts['format'] = $format != '' || empty($atts['format']) ? $format : $atts['format'];
    $atts['format'] = html_entity_decode($atts['format']);
    //shorcode doesn't accept html
    if (!empty($atts['event']) && is_numeric($atts['event'])) {
        $EM_Event = new EM_Event($atts['event']);
        return !empty($atts['format']) ? $EM_Event->output($atts['format']) : $EM_Event->output_single();
    }
}
Example #2
0
/**
 * Filters for page content and if an event replaces it with the relevant event data.
 * @param $data
 * @return string
 */
function em_content($content)
{
    $events_page_id = get_option('dbem_events_page');
    if (get_the_ID() == $events_page_id && $events_page_id != 0) {
        global $wpdb, $EM_Event;
        //TODO FILTER - filter em page content before placeholder replacing
        //TODO any loop should put the current $EM_Event etc. into the global variable
        //general defaults
        $args = array('orderby' => get_option('dbem_events_default_orderby'), 'order' => get_option('dbem_events_default_order'), 'owner' => false, 'pagination' => 1);
        if (!empty($_REQUEST['calendar_day'])) {
            //Events for a specific day
            $args['scope'] = $_REQUEST['calendar_day'];
            $page = !empty($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1;
            $events = EM_Events::get(apply_filters('em_content_calendar_day_args', $args));
            //Get events first, so we know how many there are in advance
            if (count($events) > 1 || $page > 1 || get_option('dbem_display_calendar_day_single') == 1) {
                $args['limit'] = get_option('dbem_events_default_limit');
                $args['offset'] = $args['limit'] * ($page - 1);
                $content = EM_Events::output($events, apply_filters('em_content_calendar_day_output_args', $args));
            } elseif (count($events) == 1) {
                $EM_Event = $events[0];
                $content = $EM_Event->output_single();
            } else {
                $content = get_option('dbem_no_events_message');
            }
        } elseif (!empty($_REQUEST['location_id']) && is_numeric($_REQUEST['location_id'])) {
            //Just a single location
            $location = new EM_Location($_REQUEST['location_id']);
            $content = $location->output_single();
        } elseif (!empty($_REQUEST['event_id']) && is_numeric($_REQUEST['event_id'])) {
            // single event page
            $event = new EM_Event($_REQUEST['event_id']);
            $content = $event->output_single();
        } elseif (!empty($_REQUEST['bookings_id'])) {
            //bookings page
        } else {
            // Multiple events page
            $scope = !empty($_REQUEST['scope']) ? EM_Object::sanitize($_REQUEST['scope']) : "future";
            //If we have a $_GET['page'] var, use it to calculate the offset/limit ratios (safer than offset/limit get vars)
            $args['scope'] = $scope;
            if (!empty($_REQUEST['category_id'])) {
                $args['category'] = $_REQUEST['category_id'];
            }
            if (get_option('dbem_display_calendar_in_events_page')) {
                $args['full'] = 1;
                $args['long_events'] = get_option('dbem_full_calendar_long_events');
                $content = EM_Calendar::output(apply_filters('em_content_calendar_args', $args));
            } else {
                $args['limit'] = get_option('dbem_events_default_limit');
                $args['page'] = !empty($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1;
                /*calculate event list time range */
                $time_limit = get_option('dbem_events_page_time_limit');
                if (is_numeric($time_limit) && $time_limit > 0) {
                    $args['scope'] = date('Y-m-d') . "," . date('Y-m-t', strtotime('+' . ($time_limit - 1) . ' month'));
                }
                $content = EM_Events::output(apply_filters('em_content_events_args', $args));
            }
        }
        //If disable rewrite flag is on, then we need to add a placeholder here
        if (get_option('dbem_disable_title_rewrites') == 1) {
            $content = str_replace('#_PAGETITLE', em_events_page_title(''), get_option('dbem_title_html')) . $content;
        }
        //TODO FILTER - filter em page content before display
        return apply_filters('em_content', '<div id="em-wrapper">' . $content . '</div>');
    }
    return $content;
}