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() != '') { 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 { $width = $image_size[0] ? 'width="' . esc_attr($image_size[0]) . '"' : ''; $height = $image_size[1] ? 'height="' . esc_attr($image_size[1]) . '"' : ''; $replace = "<img src='" . esc_url(em_get_thumbnail_url($this->get_image_url(), $image_size[0], $image_size[1])) . "' alt='" . esc_attr($this->name) . "' {$width} {$height} />"; } } 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; 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); }
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(']]>', ']]>', $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 (get_option('dbem_disable_timthumb')) { if (EM_MS_GLOBAL && get_current_blog_id() != $this->blog_id) { //location belongs to another blog, so switch blog then call the default wp fucntion switch_to_blog($this->blog_id); $replace = get_the_post_thumbnail($this->ID, $image_size); restore_current_blog(); } else { $replace = get_the_post_thumbnail($this->ID, $image_size); } } else { global $blog_id; if (is_multisite() && $blog_id > 0) { $imageParts = explode('/blogs.dir/', $image_url); if (isset($imageParts[1])) { $image_url = network_site_url('/wp-content/blogs.dir/' . $blog_id . '/' . $imageParts[1]); } } $width = $image_size[0] ? 'width="' . esc_attr($image_size[0]) . '"' : ''; $height = $image_size[1] ? 'height="' . esc_attr($image_size[1]) . '"' : ''; $replace = "<img src='" . esc_url(em_get_thumbnail_url($image_url, $image_size[0], $image_size[1])) . "' alt='" . esc_attr($this->location_name) . "' {$width} {$height} />"; } } 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_event_list_item_header_format') . get_option('dbem_location_no_events_message') . get_option('dbem_location_event_list_item_footer_format'); } 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); }
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) { $replace = "<img src='" . em_get_thumbnail_url($this->get_image_url(), $image_size[0], $image_size[1]) . "' alt='" . esc_attr($this->name) . "'/>"; } 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 '#_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 = EM_Events::get(array('category' => $this->term_id, 'scope' => $scope)); if (count($events) > 0) { $replace .= get_option('dbem_category_event_list_item_header_format', '<ul>'); foreach ($events as $EM_Event) { $replace .= $EM_Event->output(get_option('dbem_category_event_list_item_format')); } $replace .= get_option('dbem_category_event_list_item_footer_format'); } 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); }
/** * Will output a event in the format passed in $format by replacing placeholders within the format. * @param string $format * @param string $target * @return string */ function output($format, $target = "html") { $event_string = $format; //Time place holder that doesn't show if empty. //TODO add filter here too preg_match_all('/#@?_\\{[^}]+\\}/', $format, $results); foreach ($results[0] as $result) { if (substr($result, 0, 3) == "#@_") { $date = 'end_date'; $offset = 4; } else { $date = 'start_date'; $offset = 3; } if ($date == 'end_date' && $this->event_end_date == $this->event_start_date) { $replace = __(apply_filters('em_event_output_placeholder', '', $this, $result, $target)); } else { $replace = __(apply_filters('em_event_output_placeholder', mysql2date(substr($result, $offset, strlen($result) - ($offset + 1)), $this->{$date}), $this, $result, $target)); } $event_string = str_replace($result, $replace, $event_string); } //This is for the custom attributes preg_match_all('/#_ATT\\{([^}]+)\\}(\\{([^}]+)\\})?/', $event_string, $results); $attributes = em_get_attributes(); foreach ($results[0] as $resultKey => $result) { //Strip string of placeholder and just leave the reference $attRef = substr(substr($result, 0, strpos($result, '}')), 6); $attString = ''; if (is_array($this->event_attributes) && array_key_exists($attRef, $this->event_attributes)) { $attString = $this->event_attributes[$attRef]; } elseif (!empty($results[3][$resultKey])) { //Check to see if we have a second set of braces; $attString = $results[3][$resultKey]; } elseif (!empty($attributes['values'][$attRef][0])) { $attString = $attributes['values'][$attRef][0]; } $attString = apply_filters('em_event_output_placeholder', $attString, $this, $result, $target); $event_string = str_replace($result, $attString, $event_string); } //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', $event_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_bookings') { //check if there's a booking, if not, remove this section of code. $show_condition = $this->event_rsvp && get_option('dbem_rsvp_enabled'); } elseif ($condition == 'no_bookings') { //check if there's a booking, if not, remove this section of code. $show_condition = !$this->event_rsvp && get_option('dbem_rsvp_enabled'); } elseif ($condition == 'no_location') { //does this event have a valid location? $show_condition = empty($this->location_id) || !$this->get_location()->location_status; } elseif ($condition == 'has_location') { //does this event have a valid location? $show_condition = !empty($this->location_id) && $this->get_location()->location_status; } elseif ($condition == 'has_image') { //does this event have an image? $show_condition = $this->get_image_url() != ''; } elseif ($condition == 'no_image') { //does this event have an image? $show_condition = $this->get_image_url() == ''; } elseif ($condition == 'has_time') { //are the booking times different and not an all-day event $show_condition = $this->event_start_time != $this->event_end_time && !$this->event_all_day; } elseif ($condition == 'no_time') { //are the booking times exactly the same and it's not an all-day event. $show_condition = $this->event_start_time == $this->event_end_time && !$this->event_all_day; } elseif ($condition == 'all_day') { //is it an all day event $show_condition = !empty($this->event_all_day); } elseif ($condition == 'logged_in') { //user is logged in $show_condition = is_user_logged_in(); } elseif ($condition == 'not_logged_in') { //not logged in $show_condition = !is_user_logged_in(); } elseif ($condition == 'has_spaces') { //there are still empty spaces $show_condition = $this->event_rsvp && $this->get_bookings()->get_available_spaces() > 0; } elseif ($condition == 'fully_booked') { //event is fully booked $show_condition = $this->event_rsvp && $this->get_bookings()->get_available_spaces() <= 0; } elseif ($condition == 'bookings_open') { //bookings are still open $show_condition = $this->event_rsvp && $this->get_bookings()->is_open(); } elseif ($condition == 'bookings_closed') { //bookings are still closed $show_condition = $this->event_rsvp && !$this->get_bookings()->is_open(); } elseif ($condition == 'is_free' || $condition == 'is_free_now') { //is it a free day event, if _now then free right now $show_condition = !$this->event_rsvp || $this->is_free($condition == 'is_free_now'); } elseif ($condition == 'not_free' || $condition == 'not_free_now') { //is it a paid event, if _now then paid right now $show_condition = $this->event_rsvp && !$this->is_free($condition == 'not_free_now'); } elseif ($condition == 'is_long') { //is it an all day event $show_condition = $this->event_start_date != $this->event_end_date; } elseif ($condition == 'not_long') { //is it an all day event $show_condition = $this->event_start_date == $this->event_end_date; } elseif ($condition == 'is_past') { //if event is past if (get_option('dbem_events_current_are_past')) { $show_condition = $this->start <= current_time('timestamp'); } else { $show_condition = $this->end <= current_time('timestamp'); } } elseif ($condition == 'is_future') { //if event is upcoming $show_condition = $this->start > current_time('timestamp'); } elseif ($condition == 'is_current') { //if event is upcoming $ts = current_time('timestamp'); $show_condition = $this->start <= $ts && $this->end >= $ts; } elseif ($condition == 'is_recurrence') { //if event is a recurrence $show_condition = $this->is_recurrence(); } elseif ($condition == 'not_recurrence') { //if event is not a recurrence $show_condition = !$this->is_recurrence(); } elseif ($condition == 'is_private') { //if event is a recurrence $show_condition = $this->event_private == 1; } elseif ($condition == 'not_private') { //if event is not a recurrence $show_condition = $this->event_private == 0; } elseif (preg_match('/^has_category_([a-zA-Z0-9_\\-]+)$/', $condition, $category_match)) { //event is in this category $show_condition = has_term($category_match[1], EM_TAXONOMY_CATEGORY, $this->post_id); } elseif (preg_match('/^no_category_([a-zA-Z0-9_\\-]+)$/', $condition, $category_match)) { //event is NOT in this category $show_condition = !has_term($category_match[1], EM_TAXONOMY_CATEGORY, $this->post_id); } elseif (preg_match('/^has_tag_([a-zA-Z0-9_\\-]+)$/', $condition, $tag_match)) { //event has this tag $show_condition = has_term($tag_match[1], EM_TAXONOMY_TAG, $this->post_id); } elseif (preg_match('/^no_tag_([a-zA-Z0-9_\\-]+)$/', $condition, $tag_match)) { //event doesn't have this tag $show_condition = !has_term($tag_match[1], EM_TAXONOMY_TAG, $this->post_id); } //other potential ones - has_attribute_... no_attribute_... has_categories_... $show_condition = apply_filters('em_event_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 = ''; } $event_string = str_replace($conditionals[0][$key], apply_filters('em_event_output_condition', $replacement, $condition, $conditionals[0][$key], $this), $event_string); } } } //Now let's check out the placeholders. preg_match_all("/(#@?_?[A-Za-z0-9]+)({([^}]+)})?/", $event_string, $placeholders); $replaces = array(); foreach ($placeholders[1] as $key => $result) { $match = true; $replace = ''; $full_result = $placeholders[0][$key]; switch ($result) { //Event Details case '#_EVENTID': $replace = $this->event_id; break; case '#_EVENTPOSTID': $replace = $this->post_id; break; case '#_NAME': //depreciated //depreciated case '#_EVENTNAME': $replace = $this->event_name; break; case '#_NOTES': //depreciated //depreciated case '#_EXCERPT': //depreciated //depreciated case '#_EVENTNOTES': case '#_EVENTEXCERPT': $replace = $this->post_content; if ($result == "#_EXCERPT" || $result == "#_EVENTEXCERPT") { 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(']]>', ']]>', $replace); $replace = wp_trim_words($replace, $excerpt_length, $excerpt_more); } } } break; case '#_EVENTIMAGEURL': case '#_EVENTIMAGE': if ($this->get_image_url() != '') { if ($result == '#_EVENTIMAGEURL') { $replace = esc_url($this->image_url); } else { if (empty($placeholders[3][$key])) { $replace = "<img src='" . esc_url($this->image_url) . "' alt='" . esc_attr($this->event_name) . "'/>"; } else { $image_size = explode(',', $placeholders[3][$key]); $image_src = $this->image_url; if (self::array_is_numeric($image_size) && count($image_size) > 1) { //get a thumbnail if (get_option('dbem_disable_timthumb')) { 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 { if (is_multisite()) { //get the direct url as timthumb doesn't support redirect urls global $blog_id; $imageParts = explode('/blogs.dir/', $image_src); if (isset($imageParts[1])) { $image_src = network_site_url('/wp-content/blogs.dir/' . $imageParts[1]); } } $width = $image_size[0] ? 'width="' . esc_attr($image_size[0]) . '"' : ''; $height = $image_size[1] ? 'height="' . esc_attr($image_size[1]) . '"' : ''; $replace = "<img src='" . esc_url(em_get_thumbnail_url($image_src, $image_size[0], $image_size[1])) . "' alt='" . esc_attr($this->event_name) . "' {$width} {$height} />"; } } else { $replace = "<img src='" . esc_url($image_src) . "' alt='" . esc_attr($this->event_name) . "'/>"; } } } } break; //Times & Dates //Times & Dates case '#_24HSTARTTIME': case '#_24HENDTIME': $time = $result == '#_24HSTARTTIME' ? $this->event_start_time : $this->event_end_time; $replace = substr($time, 0, 5); break; case '#_12HSTARTTIME': case '#_12HENDTIME': $time = $result == '#_12HSTARTTIME' ? $this->event_start_time : $this->event_end_time; $replace = date('g:i A', strtotime($time)); break; case '#_EVENTTIMES': //get format of time to show if (!$this->event_all_day) { $time_format = get_option('dbem_time_format') ? get_option('dbem_time_format') : get_option('time_format'); if ($this->event_start_time != $this->event_end_time) { $replace = date_i18n($time_format, $this->start) . get_option('dbem_times_separator') . date_i18n($time_format, $this->end); } else { $replace = date_i18n($time_format, $this->start); } } else { $replace = get_option('dbem_event_all_day_message'); } break; case '#_EVENTDATES': //get format of time to show $date_format = get_option('dbem_date_format') ? get_option('dbem_date_format') : get_option('date_format'); if ($this->event_start_date != $this->event_end_date) { $replace = date_i18n($date_format, $this->start) . get_option('dbem_dates_separator') . date_i18n($date_format, $this->end); } else { $replace = date_i18n($date_format, $this->start); } break; //Links //Links case '#_EVENTPAGEURL': //Depreciated //Depreciated case '#_LINKEDNAME': //Depreciated //Depreciated case '#_EVENTURL': //Just the URL //Just the URL case '#_EVENTLINK': //HTML Link $event_link = esc_url($this->get_permalink()); if ($result == '#_LINKEDNAME' || $result == '#_EVENTLINK') { $replace = '<a href="' . $event_link . '" title="' . esc_attr($this->event_name) . '">' . esc_attr($this->event_name) . '</a>'; } else { $replace = $event_link; } break; case '#_EDITEVENTURL': case '#_EDITEVENTLINK': if ($this->can_manage('edit_events', 'edit_others_events')) { $link = esc_url($this->get_edit_url()); if ($result == '#_EDITEVENTLINK') { $replace = '<a href="' . $link . '">' . esc_html(sprintf(__('Edit Event', 'dbem'))) . '</a>'; } else { $replace = $link; } } break; //Bookings //Bookings case '#_ADDBOOKINGFORM': //Depreciated //Depreciated case '#_REMOVEBOOKINGFORM': //Depreciated //Depreciated case '#_BOOKINGFORM': if (get_option('dbem_rsvp_enabled')) { if (!defined('EM_XSS_BOOKINGFORM_FILTER') && locate_template('plugins/events-manager/placeholders/bookingform.php')) { //xss fix for old overriden booking forms add_filter('em_booking_form_action_url', 'esc_url'); define('EM_XSS_BOOKINGFORM_FILTER', true); } ob_start(); $template = em_locate_template('placeholders/bookingform.php', true, array('EM_Event' => $this)); EM_Bookings::enqueue_js(); $replace = ob_get_clean(); } break; case '#_BOOKINGBUTTON': if (get_option('dbem_rsvp_enabled') && $this->event_rsvp) { ob_start(); $template = em_locate_template('placeholders/bookingbutton.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); } break; case '#_EVENTPRICERANGEALL': $show_all_ticket_prices = true; //continues below //continues below case '#_EVENTPRICERANGE': //get the range of prices $min = false; $max = 0; if ($this->get_bookings()->is_open() || !empty($show_all_ticket_prices)) { foreach ($this->get_tickets()->tickets as $EM_Ticket) { /* @var $EM_Ticket EM_Ticket */ if ($EM_Ticket->is_available() || get_option('dbem_bookings_tickets_show_unavailable') || !empty($show_all_ticket_prices)) { if ($EM_Ticket->get_price() > $max) { $max = $EM_Ticket->get_price(); } if ($EM_Ticket->get_price() < $min || $min === false) { $min = $EM_Ticket->get_price(); } } } } if ($min === false) { $min = 0; } if ($min != $max) { $replace = em_get_currency_formatted($min) . ' - ' . em_get_currency_formatted($max); } else { $replace = em_get_currency_formatted($min); } break; case '#_EVENTPRICEMIN': //get the range of prices $min = false; foreach ($this->get_tickets()->tickets as $EM_Ticket) { /* @var $EM_Ticket EM_Ticket */ if ($EM_Ticket->is_available() || get_option('dbem_bookings_tickets_show_unavailable')) { if ($EM_Ticket->get_price() < $min || $min === false) { $min = $EM_Ticket->get_price(); } } } if ($min === false) { $min = 0; } $replace = em_get_currency_formatted($min); break; case '#_EVENTPRICEMAX': //get the range of prices $max = 0; foreach ($this->get_tickets()->tickets as $EM_Ticket) { /* @var $EM_Ticket EM_Ticket */ if ($EM_Ticket->is_available() || get_option('dbem_bookings_tickets_show_unavailable')) { if ($EM_Ticket->get_price() > $max) { $max = $EM_Ticket->get_price(); } } } $replace = em_get_currency_formatted($max); break; case '#_AVAILABLESEATS': //Depreciated //Depreciated case '#_AVAILABLESPACES': if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_available_spaces(); } else { $replace = "0"; } break; case '#_BOOKEDSEATS': //Depreciated //Depreciated case '#_BOOKEDSPACES': //This placeholder is actually a little misleading, as it'll consider reserved (i.e. pending) bookings as 'booked' if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_booked_spaces(); if (get_option('dbem_bookings_approval_reserved')) { $replace += $this->get_bookings()->get_pending_spaces(); } } else { $replace = "0"; } break; case '#_PENDINGSPACES': if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_pending_spaces(); } else { $replace = "0"; } break; case '#_SEATS': //Depreciated //Depreciated case '#_SPACES': $replace = $this->get_spaces(); break; case '#_BOOKINGSURL': case '#_BOOKINGSLINK': if ($this->can_manage('manage_bookings', 'manage_others_bookings')) { $bookings_link = esc_url($this->get_bookings_url()); if ($result == '#_BOOKINGSLINK') { $replace = '<a href="' . $bookings_link . '" title="' . esc_attr($this->event_name) . '">' . esc_html($this->event_name) . '</a>'; } else { $replace = $bookings_link; } } break; case '#_BOOKINGSCUTOFF': case '#_BOOKINGSCUTOFFDATE': case '#_BOOKINGSCUTOFFTIME': $replace = ''; if ($this->event_rsvp && get_option('dbem_rsvp_enabled') && !empty($this->rsvp_end)) { $replace_format = get_option('dbem_date_format') . ' ' . get_option('dbem_time_format'); if ($result == '#_BOOKINGSCUTOFFDATE') { $replace_format = get_option('dbem_date_format'); } if ($result == '#_BOOKINGSCUTOFFTIME') { $replace_format = get_option('dbem_time_format'); } $replace = date($replace_format, $this->rsvp_end); } break; //Contact Person //Contact Person case '#_CONTACTNAME': case '#_CONTACTPERSON': //Depreciated (your call, I think name is better) $replace = $this->get_contact()->display_name; break; case '#_CONTACTUSERNAME': $replace = $this->get_contact()->user_login; break; case '#_CONTACTEMAIL': case '#_CONTACTMAIL': //Depreciated $replace = $this->get_contact()->user_email; break; case '#_CONTACTURL': $replace = $this->get_contact()->user_url; break; case '#_CONTACTID': $replace = $this->get_contact()->ID; break; case '#_CONTACTPHONE': $replace = $this->get_contact()->phone != '' ? $this->get_contact()->phone : __('N/A', 'dbem'); break; case '#_CONTACTAVATAR': $replace = get_avatar($this->get_contact()->ID, $size = '50'); break; case '#_CONTACTPROFILELINK': case '#_CONTACTPROFILEURL': if (function_exists('bp_core_get_user_domain')) { $replace = bp_core_get_user_domain($this->get_contact()->ID); if ($result == '#_CONTACTPROFILELINK') { $replace = '<a href="' . esc_url($replace) . '">' . __('Profile', 'dbem') . '</a>'; } } break; case '#_CONTACTMETA': if (!empty($placeholders[3][$key])) { $replace = get_user_meta($this->event_owner, $placeholders[3][$key], true); } break; case '#_ATTENDEES': ob_start(); $template = em_locate_template('placeholders/attendees.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_ATTENDEESLIST': ob_start(); $template = em_locate_template('placeholders/attendeeslist.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_ATTENDEESPENDINGLIST': ob_start(); $template = em_locate_template('placeholders/attendeespendinglist.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; //Categories and Tags //Categories and Tags case '#_EVENTCATEGORIESIMAGES': ob_start(); $template = em_locate_template('placeholders/eventcategoriesimages.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_EVENTTAGS': ob_start(); $template = em_locate_template('placeholders/eventtags.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_CATEGORIES': //depreciated //depreciated case '#_EVENTCATEGORIES': ob_start(); $template = em_locate_template('placeholders/categories.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; //Ical Stuff //Ical Stuff case '#_EVENTICALURL': case '#_EVENTICALLINK': $replace = $this->get_ical_url(); if ($result == '#_EVENTICALLINK') { $replace = '<a href="' . esc_url($replace) . '">iCal</a>'; } break; case '#_EVENTGCALURL': case '#_EVENTGCALLINK': //get dates if ($this->event_all_day && $this->event_start_date == $this->event_end_date) { $dateStart = date('Ymd', $this->start - 60 * 60 * get_option('gmt_offset')); $dateEnd = date('Ymd', $this->start + 60 * 60 * 24 - 60 * 60 * get_option('gmt_offset')); } else { $dateStart = date('Ymd\\THis\\Z', $this->start - 60 * 60 * get_option('gmt_offset')); $dateEnd = date('Ymd\\THis\\Z', $this->end - 60 * 60 * get_option('gmt_offset')); } //build url $gcal_url = 'http://www.google.com/calendar/event?action=TEMPLATE&text=event_name&dates=start_date/end_date&details=post_content&location=location_name&trp=false&sprop=event_url&sprop=name:blog_name'; $gcal_url = str_replace('event_name', urlencode($this->event_name), $gcal_url); $gcal_url = str_replace('start_date', urlencode($dateStart), $gcal_url); $gcal_url = str_replace('end_date', urlencode($dateEnd), $gcal_url); $gcal_url = str_replace('location_name', urlencode($this->output('#_LOCATION')), $gcal_url); $gcal_url = str_replace('blog_name', urlencode(get_bloginfo()), $gcal_url); $gcal_url = str_replace('event_url', urlencode($this->get_permalink()), $gcal_url); //calculate URL length so we know how much we can work with to make a description. if (!empty($this->post_excerpt)) { $gcal_url_description = $this->post_excerpt; } else { $matches = explode('<!--more', $this->post_content); $gcal_url_description = wp_kses_data($matches[0]); } $gcal_url_length = strlen($gcal_url) - 9; if (strlen($gcal_url_description) + $gcal_url_length > 1350) { $gcal_url_description = substr($gcal_url_description, 0, 1380 - $gcal_url_length - 3) . '...'; } $gcal_url = str_replace('post_content', urlencode($gcal_url_description), $gcal_url); //get the final url $replace = $gcal_url; if ($result == '#_EVENTGCALLINK') { $img_url = 'www.google.com/calendar/images/ext/gc_button2.gif'; $img_url = is_ssl() ? 'https://' . $img_url : 'http://' . $img_url; $replace = '<a href="' . esc_url($replace) . '" target="_blank"><img src="' . esc_url($img_url) . '" alt="0" border="0"></a>'; } break; default: $replace = $full_result; break; } $replaces[$full_result] = apply_filters('em_event_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('#_NOTES', '#_EVENTNOTES'))) { $event_string = str_replace($full_result, $replacement, $event_string); } else { $new_placeholder = str_replace('#_', '__#', $full_result); //this will avoid repeated filters when locations/categories are parsed $event_string = str_replace($full_result, $new_placeholder, $event_string); $desc_replace[$new_placeholder] = $replacement; } } //Time placeholders foreach ($placeholders[1] as $result) { // matches all PHP START date and time placeholders if (preg_match('/^#[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) { $replace = date_i18n(ltrim($result, "#"), $this->start); $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target); $event_string = str_replace($result, $replace, $event_string); } // matches all PHP END time placeholders for endtime if (preg_match('/^#@[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) { $replace = date_i18n(ltrim($result, "#@"), $this->end); $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target); $event_string = str_replace($result, $replace, $event_string); } } //Now do dependent objects if (!empty($this->location_id) && $this->get_location()->location_status) { $event_string = $this->get_location()->output($event_string, $target); } else { $EM_Location = new EM_Location(); $event_string = $EM_Location->output($event_string, $target); } //for backwards compat and easy use, take over the individual category placeholders with the frirst cat in th elist. $EM_Categories = $this->get_categories(); if (count($EM_Categories->categories) > 0) { $EM_Category = $EM_Categories->get_first(); } if (empty($EM_Category)) { $EM_Category = new EM_Category(); } $event_string = $EM_Category->output($event_string, $target); //Finally, do the event 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) { $event_string = str_replace($full_result, $replacement, $event_string); } } //do some specific formatting //TODO apply this sort of formatting to any output() function if ($target == 'ical') { //strip html and escape characters $event_string = str_replace('\\', '\\\\', strip_tags($event_string)); $event_string = str_replace(';', '\\;', $event_string); $event_string = str_replace(',', '\\,', $event_string); //remove and define line breaks in ical format $event_string = str_replace("\r\n", '\\n', $event_string); $event_string = str_replace("\n", '\\n', $event_string); } return apply_filters('em_event_output', $event_string, $this, $format, $target); }
function output($format, $target = "html") { $location_string = $format; 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_location_output_condition', '', $conditionals[0][$key], $condition, $this), $format); } } //This is for the custom attributes preg_match_all('/#_LATT\\{([^}]+)\\}(\\{([^}]+)\\})?/', $format, $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]+)({([a-zA-Z0-9,]+)})?/", $format, $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->location_id; break; case '#_NAME': //Depreciated //Depreciated case '#_LOCATION': //Depreciated //Depreciated case '#_LOCATIONNAME': $replace = $this->location_name; break; case '#_ADDRESS': //Depreciated //Depreciated case '#_LOCATIONADDRESS': $replace = $this->location_address; break; case '#_TOWN': //Depreciated //Depreciated 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': //Depreciated //Depreciated case '#_LOCATIONMAP': ob_start(); $template = em_locate_template('placeholders/locationmap.php', true, array('EM_Location' => $this)); $replace = ob_get_clean(); break; case '#_DESCRIPTION': //Depreciated //Depreciated case '#_EXCERPT': //Depreciated //Depreciated case '#_LOCATIONNOTES': case '#_LOCATIONEXCERPT': $replace = $this->post_content; if ($result == "#_EXCERPT" || $result == "#_LOCATIONEXCERPT") { if (!empty($this->post_excerpt)) { $replace = $this->post_excerpt; } else { $matches = explode('<!--more', $this->post_content); $replace = $matches[0]; } } 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 ($this->array_is_numeric($image_size) && count($image_size) > 1) { global $blog_id; if (is_multisite() && $blog_id > 0) { $imageParts = explode('/blogs.dir/', $image_url); if (isset($imageParts[1])) { $image_url = network_site_url('/wp-content/blogs.dir/' . $blog_id . '/' . $imageParts[1]); } } $replace = "<img src='" . esc_url(em_get_thumbnail_url($image_url, $image_size[0], $image_size[1])) . "' alt='" . esc_attr($this->location_name) . "'/>"; } else { $replace = "<img src='" . $image_url . "' alt='" . esc_attr($this->location_name) . "'/>"; } } } } break; case '#_LOCATIONURL': case '#_LOCATIONLINK': case '#_LOCATIONPAGEURL': //Depreciated $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': $link = esc_url($this->get_edit_url()); $replace = $result == '#_LOCATIONEDITURL' ? $link : '<a href="' . $link . '" title="' . esc_attr($this->location_name) . '">' . esc_html(sprintf(__('Edit %s', 'dbem'), __('Location', 'dbem'))) . '</a>'; break; case '#_PASTEVENTS': //Depreciated //Depreciated case '#_LOCATIONPASTEVENTS': case '#_NEXTEVENTS': //Depreciated //Depreciated case '#_LOCATIONNEXTEVENTS': case '#_ALLEVENTS': //Depreciated //Depreciated 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 = EM_Events::get(array('location' => $this->location_id, 'scope' => $scope)); if (count($events) > 0) { $replace .= get_option('dbem_location_event_list_item_header_format'); foreach ($events as $event) { $replace .= $event->output(get_option('dbem_location_event_list_item_format')); } $replace .= get_option('dbem_location_event_list_item_footer_format'); } 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_events_message'); foreach ($events as $EM_Event) { $replace = $EM_Event->output('#_EVENTLINK'); } 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) { $location_string = str_replace($full_result, $replacement, $location_string); } return apply_filters('em_location_output', $location_string, $this, $format, $target); }
/** * Will output a event in the format passed in $format by replacing placeholders within the format. * @param string $format * @param string $target * @return string */ function output($format, $target = "html") { $event_string = $format; //Time place holder that doesn't show if empty. //TODO add filter here too preg_match_all('/#@?_\\{[^}]+\\}/', $format, $results); foreach ($results[0] as $result) { if (substr($result, 0, 3) == "#@_") { $date = 'end_date'; $offset = 4; } else { $date = 'start_date'; $offset = 3; } if ($date == 'end_date' && $this->event_end_date == $this->event_start_date) { $replace = __(apply_filters('em_event_output_placeholder', '', $this, $result, $target)); } else { $replace = __(apply_filters('em_event_output_placeholder', mysql2date(substr($result, $offset, strlen($result) - ($offset + 1)), $this->{$date}), $this, $result, $target)); } $event_string = str_replace($result, $replace, $event_string); } //This is for the custom attributes preg_match_all('/#_ATT\\{([^}]+)\\}(\\{([^}]+)\\})?/', $format, $results); foreach ($results[0] as $resultKey => $result) { //Strip string of placeholder and just leave the reference $attRef = substr(substr($result, 0, strpos($result, '}')), 6); $attString = ''; if (is_array($this->event_attributes) && array_key_exists($attRef, $this->event_attributes)) { $attString = $this->event_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_event_output_placeholder', $attString, $this, $result, $target); $event_string = str_replace($result, $attString, $event_string); } //First let's do some conditional placeholder removals for ($i = 0; $i < get_option('dbem_conditional_recursions', 1); $i++) { //you can add nested recursions by modifying this setting in your wp_options table preg_match_all('/\\{([a-zA-Z0-9_]+)\\}(.+?)\\{\\/\\1\\}/s', $event_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_bookings') { //check if there's a booking, if not, remove this section of code. $show_condition = $this->event_rsvp && get_option('dbem_rsvp_enabled'); } elseif ($condition == 'no_bookings') { //check if there's a booking, if not, remove this section of code. $show_condition = !$this->event_rsvp && get_option('dbem_rsvp_enabled'); } elseif ($condition == 'no_location') { //does this event have a valid location? $show_condition = empty($this->location_id) || !$this->get_location()->location_status; } elseif ($condition == 'has_location') { //does this event have a valid location? $show_condition = !empty($this->location_id) && $this->get_location()->location_status; } elseif ($condition == 'has_image') { //does this event have an image? $show_condition = $this->get_image_url() != ''; } elseif ($condition == 'no_image') { //does this event have an image? $show_condition = $this->get_image_url() == ''; } elseif ($condition == 'has_time') { //are the booking times different and not an all-day event $show_condition = $this->start != $this->end && !$this->event_all_day; } elseif ($condition == 'no_time') { //are the booking times exactly the same and it's not an all-day event. $show_condition = $this->event_start_time == $this->event_end_time && !$this->event_all_day; } elseif ($condition == 'all_day') { //is it an all day event $show_condition = !empty($this->event_all_day); } elseif ($condition == 'logged_in') { //user is logged in $show_condition = is_user_logged_in(); } elseif ($condition == 'not_logged_in') { //not logged in $show_condition = !is_user_logged_in(); } elseif ($condition == 'has_spaces') { //is it an all day event $show_condition = $this->event_rsvp && $this->get_bookings()->get_available_spaces() > 0; } elseif ($condition == 'fully_booked') { //is it an all day event $show_condition = $this->event_rsvp && $this->get_bookings()->get_available_spaces() <= 0; } elseif ($condition == 'is_long') { //is it an all day event $show_condition = $this->event_start_date != $this->event_end_date; } elseif ($condition == 'not_long') { //is it an all day event $show_condition = $this->event_start_date == $this->event_end_date; } elseif ($condition == 'is_past') { //if event is past $show_condition = $this->start <= current_time('timestamp'); } elseif ($condition == 'is_future') { //if event is upcoming $show_condition = $this->start > current_time('timestamp'); } $show_condition = apply_filters('em_event_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 = ''; } $event_string = str_replace($conditionals[0][$key], apply_filters('em_event_output_condition', $replacement, $condition, $conditionals[0][$key], $this), $event_string); } } } //Now let's check out the placeholders. 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) { //Event Details case '#_EVENTID': $replace = $this->event_id; break; case '#_EVENTPOSTID': $replace = $this->post_id; break; case '#_NAME': //depreciated //depreciated case '#_EVENTNAME': $replace = $this->event_name; break; case '#_NOTES': //depreciated //depreciated case '#_EXCERPT': //depreciated //depreciated case '#_EVENTNOTES': case '#_EVENTEXCERPT': $replace = $this->post_content; if ($result == "#_EXCERPT" || $result == "#_EVENTEXCERPT") { if (!empty($this->post_excerpt)) { $replace = $this->post_excerpt; } else { $matches = explode('<!--more', $this->post_content); $replace = $matches[0]; } } break; case '#_EVENTIMAGEURL': case '#_EVENTIMAGE': if ($this->get_image_url() != '') { if ($result == '#_EVENTIMAGEURL') { $replace = esc_url($this->image_url); } else { if (empty($placeholders[3][$key])) { $replace = "<img src='" . esc_url($this->image_url) . "' alt='" . esc_attr($this->event_name) . "'/>"; } else { $image_size = explode(',', $placeholders[3][$key]); $image_src = $this->image_url; if ($this->array_is_numeric($image_size) && count($image_size) > 1) { global $blog_id; if (is_multisite() && $blog_id > 0) { $imageParts = explode('/blogs.dir/', $image_src); if (isset($imageParts[1])) { $image_src = network_site_url('/wp-content/blogs.dir/' . $blog_id . '/' . $imageParts[1]); } } $replace = "<img src='" . esc_url(em_get_thumbnail_url($image_src, $image_size[0], $image_size[1])) . "' alt='" . esc_attr($this->event_name) . "'/>"; } else { $replace = "<img src='" . esc_url($image_src) . "' alt='" . esc_attr($this->event_name) . "'/>"; } } } } break; //Times & Dates //Times & Dates case '#_24HSTARTTIME': case '#_24HENDTIME': $time = $result == '#_24HSTARTTIME' ? $this->event_start_time : $this->event_end_time; $replace = substr($time, 0, 5); break; case '#_12HSTARTTIME': case '#_12HENDTIME': $time = $result == '#_12HSTARTTIME' ? $this->event_start_time : $this->event_end_time; $replace = date('g:i A', strtotime($time)); break; case '#_EVENTTIMES': //get format of time to show if (!$this->event_all_day) { $time_format = get_option('dbem_time_format') ? get_option('dbem_time_format') : get_option('time_format'); if ($this->event_start_time != $this->event_end_time) { $replace = date_i18n($time_format, $this->start) . get_option('dbem_times_seperator') . date_i18n($time_format, $this->end); } else { $replace = date_i18n($time_format, $this->start); } } else { $replace = get_option('dbem_event_all_day_message'); } break; case '#_EVENTDATES': //get format of time to show $date_format = get_option('dbem_date_format') ? get_option('dbem_date_format') : get_option('date_format'); if ($this->event_start_date != $this->event_end_date) { $replace = date_i18n($date_format, $this->start) . get_option('dbem_dates_seperator') . date_i18n($date_format, $this->end); } else { $replace = date_i18n($date_format, $this->start); } break; //Links //Links case '#_EVENTPAGEURL': //Depreciated //Depreciated case '#_LINKEDNAME': //Depreciated //Depreciated case '#_EVENTURL': //Just the URL //Just the URL case '#_EVENTLINK': //HTML Link $event_link = esc_url($this->get_permalink()); if ($result == '#_LINKEDNAME' || $result == '#_EVENTLINK') { $replace = '<a href="' . $event_link . '" title="' . esc_attr($this->event_name) . '">' . esc_attr($this->event_name) . '</a>'; } else { $replace = $event_link; } break; case '#_EDITEVENTURL': case '#_EDITEVENTLINK': if ($this->can_manage('edit_events', 'edit_others_events')) { $link = esc_url($this->get_edit_url()); if ($result == '#_EDITEVENTLINK') { $replace = '<a href="' . $link . '">' . esc_html(sprintf(__('Edit %s', 'dbem'), __('Event', 'dbem'))) . '</a>'; } else { $replace = $link; } } break; //Bookings //Bookings case '#_ADDBOOKINGFORM': //Depreciated //Depreciated case '#_REMOVEBOOKINGFORM': //Depreciated //Depreciated case '#_BOOKINGFORM': if (get_option('dbem_rsvp_enabled')) { ob_start(); $template = em_locate_template('placeholders/bookingform.php', true, array('EM_Event' => $this)); if (!defined('EM_BOOKING_JS_LOADED')) { //this kicks off the Javascript required by booking forms. This is fired once for all booking forms on a page load and appears at the bottom of the page //your theme must call the wp_footer() function for this to work (as required by many other plugins too) function em_booking_js_footer() { ?> <script type="text/javascript"> jQuery(document).ready( function($){ <?php //we call the segmented JS files and include them here include WP_PLUGIN_DIR . '/events-manager/includes/js/bookingsform.js'; do_action('em_gateway_js'); ?> }); </script> <?php } add_action('wp_footer', 'em_booking_js_footer'); add_action('admin_footer', 'em_booking_js_footer'); define('EM_BOOKING_JS_LOADED', true); } $replace = ob_get_clean(); } break; case '#_BOOKINGBUTTON': if (get_option('dbem_rsvp_enabled')) { ob_start(); $template = em_locate_template('placeholders/bookingbutton.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); } break; case '#_EVENTPRICERANGE': //get the range of prices $min = false; $max = 0; foreach ($this->get_tickets()->tickets as $EM_Ticket) { if ($EM_Ticket->get_price() > $max) { $max = $EM_Ticket->get_price(); } if ($EM_Ticket->get_price() < $min || $min === false) { $min = $EM_Ticket->get_price(); } } if ($min === false) { $min = 0; } if ($min != $max) { $replace = em_get_currency_formatted($min) . ' - ' . em_get_currency_formatted($max); } else { $replace = em_get_currency_formatted($min); } break; case '#_EVENTPRICEMIN': //get the range of prices $min = false; foreach ($this->get_tickets()->tickets as $EM_Ticket) { if ($EM_Ticket->get_price() < $min || $min === false) { $min = $EM_Ticket->get_price(); } } if ($min === false) { $min = 0; } $replace = em_get_currency_formatted($min); break; case '#_EVENTPRICEMAX': //get the range of prices $max = 0; foreach ($this->get_tickets()->tickets as $EM_Ticket) { if ($EM_Ticket->get_price() > $max) { $max = $EM_Ticket->get_price(); } } $replace = em_get_currency_formatted($max); break; case '#_AVAILABLESEATS': //Depreciated //Depreciated case '#_AVAILABLESPACES': if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_available_spaces(); } else { $replace = "0"; } break; case '#_BOOKEDSEATS': //Depreciated //Depreciated case '#_BOOKEDSPACES': //This placeholder is actually a little misleading, as it'll consider reserved (i.e. pending) bookings as 'booked' if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_booked_spaces(); if (get_option('dbem_bookings_approval_reserved')) { $replace += $this->get_bookings()->get_pending_spaces(); } } else { $replace = "0"; } break; case '#_PENDINGSPACES': if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_pending_spaces(); } else { $replace = "0"; } break; case '#_SEATS': //Depreciated //Depreciated case '#_SPACES': $replace = $this->get_spaces(); break; case '#_BOOKINGSURL': case '#_BOOKINGSLINK': if ($this->can_manage('manage_bookings', 'manage_others_bookings')) { $bookings_link = esc_url($this->get_bookings_url()); if ($result == '#_BOOKINGSLINK') { $replace = '<a href="' . $bookings_link . '" title="' . esc_attr($this->event_name) . '">' . esc_html($this->event_name) . '</a>'; } else { $replace = $bookings_link; } } break; //Contact Person //Contact Person case '#_CONTACTNAME': case '#_CONTACTPERSON': //Depreciated (your call, I think name is better) $replace = $this->get_contact()->display_name; break; case '#_CONTACTUSERNAME': $replace = $this->get_contact()->user_login; break; case '#_CONTACTEMAIL': case '#_CONTACTMAIL': //Depreciated $replace = $this->get_contact()->user_email; break; case '#_CONTACTID': $replace = $this->get_contact()->ID; break; case '#_CONTACTPHONE': $replace = $this->get_contact()->phone != '' ? $this->get_contact()->phone : __('N/A', 'dbem'); break; case '#_CONTACTAVATAR': $replace = get_avatar($this->get_contact()->ID, $size = '50'); break; case '#_CONTACTPROFILELINK': case '#_CONTACTPROFILEURL': if (function_exists('bp_core_get_user_domain')) { $replace = bp_core_get_user_domain($this->get_contact()->ID); if ($result == '#_CONTACTPROFILELINK') { $replace = '<a href="' . esc_url($replace) . '">' . __('Profile', 'dbem') . '</a>'; } } break; case '#_CONTACTMETA': if (!empty($placeholders[3][$key])) { $replace = get_user_meta($this->event_owner, $placeholders[3][$key], true); } break; case '#_ATTENDEES': ob_start(); $template = em_locate_template('placeholders/attendees.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_ATTENDEESLIST': ob_start(); $template = em_locate_template('placeholders/attendeeslist.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; //Categories and Tags //Categories and Tags case '#_EVENTCATEGORIESIMAGES': ob_start(); $template = em_locate_template('placeholders/eventcategoriesimages.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_EVENTTAGS': ob_start(); $template = em_locate_template('placeholders/eventtags.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_CATEGORIES': //depreciated //depreciated case '#_EVENTCATEGORIES': ob_start(); $template = em_locate_template('placeholders/categories.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; //Ical Stuff //Ical Stuff case '#_EVENTICALURL': case '#_EVENTICALLINK': $replace = $this->get_ical_url(); if ($result == '#_EVENTICALLINK') { $replace = '<a href="' . esc_url($replace) . '">iCal</a>'; } break; case '#_EVENTGCALURL': case '#_EVENTGCALLINK': //get dates if ($this->event_all_day && $this->event_start_date == $this->event_end_date) { $dateStart = date('Ymd', $this->start - 60 * 60 * get_option('gmt_offset')); $dateEnd = date('Ymd', $this->start + 60 * 60 * 24 - 60 * 60 * get_option('gmt_offset')); } else { $dateStart = date('Ymd\\THis\\Z', $this->start - 60 * 60 * get_option('gmt_offset')); $dateEnd = date('Ymd\\THis\\Z', $this->end - 60 * 60 * get_option('gmt_offset')); } //build url $gcal_url = 'http://www.google.com/calendar/event?action=TEMPLATE&text=event_name&dates=start_date/end_date&details=post_content&location=location_name&trp=false&sprop=event_url&sprop=name:blog_name'; $gcal_url = str_replace('event_name', urlencode($this->event_name), $gcal_url); $gcal_url = str_replace('start_date', urlencode($dateStart), $gcal_url); $gcal_url = str_replace('end_date', urlencode($dateEnd), $gcal_url); $gcal_url = str_replace('location_name', urlencode($this->output('#_LOCATION')), $gcal_url); $gcal_url = str_replace('blog_name', urlencode(get_bloginfo()), $gcal_url); $gcal_url = str_replace('event_url', urlencode($this->get_permalink()), $gcal_url); //calculate URL length so we know how much we can work with to make a description. if (!empty($this->post_excerpt)) { $gcal_url_description = $this->post_excerpt; } else { $matches = explode('<!--more', $this->post_content); $gcal_url_description = wp_kses_data($matches[0]); } $gcal_url_length = strlen($gcal_url) - 9; if (strlen($gcal_url_description) + $gcal_url_length > 1500) { $gcal_url_description = substr($gcal_url_description, 0, 1530 - $gcal_url_length - 3) . '...'; } $gcal_url = str_replace('post_content', urlencode($gcal_url_description), $gcal_url); //get the final url $replace = $gcal_url; if ($result == '#_EVENTGCALLINK') { $img_url = 'www.google.com/calendar/images/ext/gc_button2.gif'; $img_url = is_ssl() ? 'https://' . $img_url : 'http://' . $img_url; $replace = '<a href="' . esc_url($replace) . '" target="_blank"><img src="' . esc_url($img_url) . '" alt="0" border="0"></a>'; } break; default: $replace = $full_result; break; } $replaces[$full_result] = apply_filters('em_event_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) { $event_string = str_replace($full_result, $replacement, $event_string); } //Time placeholders foreach ($placeholders[1] as $result) { // matches all PHP START date and time placeholders if (preg_match('/^#[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) { $replace = date_i18n(ltrim($result, "#"), $this->start); $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target); $event_string = str_replace($result, $replace, $event_string); } // matches all PHP END time placeholders for endtime if (preg_match('/^#@[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) { $replace = date_i18n(ltrim($result, "#@"), $this->end); $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target); $event_string = str_replace($result, $replace, $event_string); } } //Now do dependent objects if (!empty($this->location_id) && $this->get_location()->location_status) { $event_string = $this->get_location()->output($event_string, $target); } else { $EM_Location = new EM_Location(); $event_string = $EM_Location->output($event_string, $target); } //for backwards compat and easy use, take over the individual category placeholders with the frirst cat in th elist. $EM_Categories = $this->get_categories(); if (count($EM_Categories->categories) > 0) { $EM_Category = $EM_Categories->get_first(); } if (empty($EM_Category)) { $EM_Category = new EM_Category(); } $event_string = $EM_Category->output($event_string, $target); return apply_filters('em_event_output', $event_string, $this, $format, $target); }