function form($tag)
    {
        $category_color = '#FFFFFF';
        $category_image = '';
        if ($tag != EM_TAXONOMY_CATEGORY) {
            //not an add new tag form
            $EM_Category = new EM_Category($tag);
            $category_color = $EM_Category->get_color();
            $category_image = $EM_Category->get_image_url();
            $category_image_id = $EM_Category->get_image_id();
        }
        ?>
	    <tr class="form-field">
	        <th scope="row" valign="top"><label for="category-bgcolor">Calendar Color</label></th>
	        <td>
	            <input type="text" name="category_bgcolor" id="category-bgcolor" class="colorwell" value="<?php 
        echo esc_attr($category_color);
        ?>
" style="width:100px;"/><br />
	            <p class="description"><?php 
        echo sprintf(__('Choose a color for your category. You can access this using the %s placeholder.', 'dbem'), '<code>#_CATEGORYCOLOR</code>');
        ?>
</p>
	            <div id="picker" style="position:absolute; display:none; background:#DEDEDE"></div>
	        </td>
	    </tr>
	    <tr class="form-field">
	        <th scope="row" valign="top"><label for="category-image">Image</label></th>
	        <td>
	        	<?php 
        if (!empty($category_image)) {
            ?>
	        	<p><img src="<?php 
            echo $category_image;
            ?>
" /></p>
	        	<?php 
        }
        ?>
	            <input type="text" name="category_image" id="category-image" value="<?php 
        echo esc_attr($category_image);
        ?>
" style="width:300px;" />
	            <input type="hidden" name="category_image_id" id="category-image-id" value="<?php 
        echo esc_attr($category_image);
        ?>
" />
	            <input id="upload_image_button" type="button" value="<?php 
        _e('Choose/Upload Image', 'dbem');
        ?>
" class="button-secondary" style="width:auto;" /><br />
	            <p class="description"><?php 
        echo sprintf(__('Choose an image for your category, which can be displayed using the %s placeholder.', 'dbem'), '<code>#_CATEGORYIMAGE</code>');
        ?>
</p>
	        </td>
	    </tr>
	    <?php 
    }
Exemple #2
0
 function get($args = array())
 {
     global $wpdb;
     $categories_table = $wpdb->prefix . EM_CATEGORIES_TABLE;
     $events_table = $wpdb->prefix . EM_EVENTS_TABLE;
     //Quick version, we can accept an array of IDs, which is easy to retrieve
     if (self::array_is_numeric($args)) {
         //Array of numbers, assume they are event IDs to retreive
         //We can just get all the events here and return them
         $sql = "SELECT * FROM {$categories_table} WHERE category_id=" . implode(" OR category_id=", $args);
         $results = $wpdb->get_results(apply_filters('em_categories_get_sql', $sql), ARRAY_A);
         $categories = array();
         foreach ($results as $result) {
             $categories[$result['category_id']] = new EM_Category($result);
         }
         return $categories;
         //We return all the categories matched as an EM_Event array.
     }
     //We assume it's either an empty array or array of search arguments to merge with defaults
     $args = self::get_default_search($args);
     $limit = $args['limit'] && is_numeric($args['limit']) ? "LIMIT {$args['limit']}" : '';
     $offset = $limit != "" && is_numeric($args['offset']) ? "OFFSET {$args['offset']}" : '';
     //Get the default conditions
     $conditions = self::build_sql_conditions($args);
     //Put it all together
     $where = count($conditions) > 0 ? " WHERE " . implode(" AND ", $conditions) : '';
     //Get ordering instructions
     $EM_Category = new EM_Category();
     $accepted_fields = $EM_Category->get_fields(true);
     $orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_categories_default_order'));
     //Now, build orderby sql
     $orderby_sql = count($orderby) > 0 ? 'ORDER BY ' . implode(', ', $orderby) : '';
     //Create the SQL statement and execute
     $sql = "\n\t\t\tSELECT * FROM {$categories_table}\n\t\t\tLEFT JOIN {$events_table} ON {$events_table}.event_category_id={$categories_table}.category_id\n\t\t\t{$where}\n\t\t\tGROUP BY category_id\n\t\t\t{$orderby_sql}\n\t\t\t{$limit} {$offset}\n\t\t";
     $results = $wpdb->get_results(apply_filters('em_categories_get_sql', $sql, $args), ARRAY_A);
     //If we want results directly in an array, why not have a shortcut here?
     if ($args['array'] == true) {
         return $results;
     }
     //Make returned results EM_Event objects
     $results = is_array($results) ? $results : array();
     $categories = array();
     foreach ($results as $category_array) {
         $categories[$category_array['category_id']] = new EM_Category($category_array);
     }
     return apply_filters('em_categories_get', $categories);
 }
Exemple #3
0
function em_admin_categories_page()
{
    global $wpdb, $EM_Category;
    if (!empty($_REQUEST['action'])) {
        if ($_REQUEST['action'] == "save") {
            // save (add/update) category
            if (empty($EM_Category) || !is_object($EM_Category)) {
                $EM_Category = new EM_Category();
                //blank category
                $success_message = __('The category has been added.', 'dbem');
            } else {
                $success_message = __('The category has been updated.', 'dbem');
            }
            $EM_Category->get_post();
            if ($EM_Category->validate()) {
                $EM_Category->save();
                //FIXME better handling of db write fails when saving category
                em_categories_table_layout($success_message);
            } else {
                ?>
				<div id='message' class='error '>
					<p>
						<strong><?php 
                _e("Ach, there's a problem here:", "dbem");
                ?>
</strong><br /><br /><?php 
                echo implode('<br />', $EM_Category->errors);
                ?>
					</p>
				</div>
				<?php 
                em_categories_edit_layout();
            }
        } elseif ($_REQUEST['action'] == "edit") {
            em_categories_edit_layout();
        } elseif ($_REQUEST['action'] == "delete") {
            //delelte category
            EM_Categories::delete($_REQUEST['categories']);
            //FIXME no result verification when deleting various categories
            $message = __('Categories Deleted', "dbem");
            em_categories_table_layout($message);
        }
    } else {
        em_categories_table_layout($message);
    }
}
Exemple #4
0
function em_admin_categories_page()
{
    global $wpdb, $EM_Category, $EM_Notices;
    //Take actions
    if (!empty($_REQUEST['action']) && ($_REQUEST['action'] == "edit" && !empty($_REQUEST['category_id']) || $_REQUEST['action'] == "add")) {
        em_categories_edit_layout();
    } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == "category_save") {
        em_categories_edit_layout();
    } else {
        // no action, just a locations list
        em_categories_table_layout();
    }
    return;
    //TODO move categories action logic to em-actions.php
    if (!empty($_REQUEST['action'])) {
        if ($_REQUEST['action'] == "save") {
            // save (add/update) category
            if (empty($EM_Category) || !is_object($EM_Category)) {
                $EM_Category = new EM_Category();
                //blank category
                $success_message = __('The category has been added.', 'dbem');
            } else {
                $success_message = __('The category has been updated.', 'dbem');
            }
            if ($EM_Category->get_post() && $EM_Category->save()) {
                $EM_Notices->add_confirm($EM_Category->feedback_message);
                em_categories_table_layout();
            } else {
                $EM_Notices->add_error($EM_Category->errors);
                em_categories_edit_layout();
            }
        } elseif ($_REQUEST['action'] == "edit") {
            em_categories_edit_layout();
        } elseif ($_REQUEST['action'] == "delete") {
            //delelte category
            EM_Categories::delete($_REQUEST['categories']);
            //FIXME no result verification when deleting various categories
            $message = __('Categories Deleted', "dbem");
            em_categories_table_layout($message);
        }
    } else {
        em_categories_table_layout();
    }
}
Exemple #5
0
 /**
  * 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(']]>', ']]&gt;', $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_url = $this->image_url;
                             if (self::array_is_numeric($image_size) && count($image_size) > 1) {
                                 //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->event_name) . "' {$image_attr} />";
                                 } else {
                                     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 = "<img src='" . esc_url($image_url) . "' 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 in UTC/GMT time
                 if ($this->event_all_day && $this->event_start_date == $this->event_end_date) {
                     $dateStart = get_gmt_from_date(date('Y-m-d H:i:s', $this->start), 'Ymd');
                     $dateEnd = get_gmt_from_date(date('Y-m-d H:i:s', $this->start + 60 * 60 * 24), 'Ymd');
                 } else {
                     $dateStart = get_gmt_from_date(date('Y-m-d H:i:s', $this->start), 'Ymd\\THis\\Z');
                     $dateEnd = get_gmt_from_date(date('Y-m-d H:i:s', $this->end), 'Ymd\\THis\\Z');
                 }
                 //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('\\\\n', '\\n', $event_string);
         $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);
 }
/**
 * Shows a single location according to given specifications. Accepts any event query attribute.
 * @param array $atts
 * @return string
 */
function em_get_event_category_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['category']) && is_numeric($atts['category'])) {
        $EM_Category = new EM_Category($atts['category']);
        return !empty($atts['format']) ? $EM_Category->output($atts['format']) : $EM_Category->output_single();
    } elseif (!empty($atts['post_id']) && is_numeric($atts['post_id'])) {
        $EM_Category = new EM_Category($atts['post_id'], 'post_id');
        return !empty($atts['format']) ? $EM_Category->output($atts['format']) : $EM_Category->output_single();
    }
}
Exemple #7
0
 /**
  * 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")
 {
     //First let's do some conditional placeholder removals
     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) {
             $replacement = $conditionals[0][$key];
             if ($condition == 'has_bookings') {
                 //check if there's a booking, if not, remove this section of code.
                 if ($this->rsvp) {
                     $replacement = substr($conditionals[0][$key], 14, strlen($conditionals[0][$key]) - 29);
                     //29 = (15+14)
                 } else {
                     $replacement = '';
                 }
             }
             if ($condition == 'no_bookings') {
                 //check if there's a booking, if not, remove this section of code.
                 if (!$this->rsvp) {
                     $replacement = substr($conditionals[0][$key], 13, strlen($conditionals[0][$key]) - 28);
                     //28 = (13+14)
                 } else {
                     $replacement = '';
                 }
                 str_replace($conditionals[0][$key], $replacement, $format);
             }
             $format = str_replace($conditionals[0][$key], apply_filters('em_event_output_condition', $replacement, $condition, $conditionals[0][$key], $this), $format);
         }
     }
     $event_string = $format;
     //Now let's check out the placeholders.
     preg_match_all("/#@?_?[A-Za-z0-9]+/", $format, $placeholders);
     foreach ($placeholders[0] as $result) {
         $match = true;
         $replace = '';
         switch ($result) {
             //Event Details
             case '#_EVENTID':
                 $replace = $this->id;
                 break;
             case '#_NAME':
                 $replace = $this->name;
                 break;
             case '#_NOTES':
             case '#_EXCERPT':
                 //SEE AT BOTTOM OF FILE FOR OLD TARGET FILTERS FROM 2.x
                 $replace = $this->notes;
                 if ($result == "#_EXCERPT") {
                     $matches = explode('<!--more', $this->notes);
                     $replace = $matches[0];
                 }
                 break;
             case '#_EVENTIMAGEURL':
             case '#_EVENTIMAGE':
                 if ($this->image_url != '') {
                     $replace = $result == '#_EVENTIMAGEURL' ? $this->image_url : "<img src='" . $this->image_url . "' alt='" . $this->name . "'/>";
                 }
                 break;
                 //Times
             //Times
             case '#_24HSTARTTIME':
             case '#_24HENDTIME':
                 $time = $result == '#_24HSTARTTIME' ? $this->start_time : $this->end_time;
                 $replace = substr($time, 0, 5);
                 break;
             case '#_12HSTARTTIME':
             case '#_12HENDTIME':
                 $time = $result == '#_12HSTARTTIME' ? $this->start_time : $this->end_time;
                 $replace = date('g:i A', strtotime($time));
                 break;
                 //Links
             //Links
             case '#_EVENTPAGEURL':
                 //Depreciated
             //Depreciated
             case '#_LINKEDNAME':
                 //Depreciated
             //Depreciated
             case '#_EVENTURL':
                 //Just the URL
             //Just the URL
             case '#_EVENTLINK':
                 //HTML Link
                 //If this event is not of this blog, we need a new URL
                 $EM_URI = EM_URI;
                 if (is_multisite() && get_site_option('dbem_ms_global_events') && get_site_option('dbem_ms_global_events_links') && !empty($this->blog_id) && is_main_site() && $this->blog_id != get_current_blog_id()) {
                     $EM_URI = get_blog_permalink($this->blog_id, get_blog_option($this->blog_id, 'dbem_events_page'));
                 }
                 $joiner = stristr($EM_URI, "?") ? "&amp;" : "?";
                 $event_link = $EM_URI . $joiner . "event_id=" . $this->id;
                 if ($result == '#_LINKEDNAME' || $result == '#_EVENTLINK') {
                     $replace = "<a href='{$event_link}' title='{$this->name}'>{$this->name}</a>";
                 } else {
                     $replace = $event_link;
                 }
                 break;
             case '#_EDITEVENTURL':
             case '#_EDITEVENTLINK':
                 if ($this->can_manage('edit_events', 'edit_others_events')) {
                     if (is_multisite() && get_site_option('dbem_ms_global_events') && get_site_option('dbem_ms_global_events_links') && !empty($this->blog_id) && is_main_site() && $this->blog_id != get_current_blog_id()) {
                         $replace = get_site_url($this->blog_id, "/wp-admin/admin.php?page=events-manager-event&amp;event_id={$this->id}");
                     } else {
                         $replace = get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-event&amp;event_id={$this->id}";
                     }
                     if ($result == '#_EDITEVENTLINK') {
                         $replace = "<a href='{$replace}'>" . __('Edit') . ' ' . __('Event', 'dbem') . "</a>";
                     }
                 }
                 break;
                 //Bookings
             //Bookings
             case '#_ADDBOOKINGFORM':
                 //Depreciated
             //Depreciated
             case '#_REMOVEBOOKINGFORM':
                 //Depreciated
             //Depreciated
             case '#_BOOKINGFORM':
                 ob_start();
                 $template = em_locate_template('placeholders/bookingform.php', true, array('EM_Event' => $this));
                 $replace = ob_get_clean();
                 break;
             case '#_BOOKINGBUTTON':
                 ob_start();
                 $template = em_locate_template('placeholders/bookingbutton.php', true, array('EM_Event' => $this));
                 $replace = ob_get_clean();
                 break;
             case '#_AVAILABLESEATS':
                 //Depreciated
             //Depreciated
             case '#_AVAILABLESPACES':
                 if ($this->rsvp && get_option('dbem_rsvp_enabled')) {
                     $replace = $this->get_bookings()->get_available_spaces();
                 } else {
                     $replace = "0";
                 }
                 break;
             case '#_BOOKEDSEATS':
                 //Depreciated
             //Depreciated
             case '#_BOOKEDSPACES':
                 if ($this->rsvp && get_option('dbem_rsvp_enabled')) {
                     $replace = $this->get_bookings()->get_booked_spaces();
                 } else {
                     $replace = "0";
                 }
                 break;
             case '#_PENDINGSPACES':
                 if ($this->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':
                 $bookings_link = get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-bookings&amp;event_id=" . $this->id;
                 if ($result == '#_BOOKINGSLINK') {
                     $replace = "<a href='{$bookings_link}' title='{$this->name}'>{$this->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->contact->display_name;
                 break;
             case '#_CONTACTUSERNAME':
                 $replace = $this->contact->user_login;
                 break;
             case '#_CONTACTEMAIL':
             case '#_CONTACTMAIL':
                 //Depreciated
                 $replace = $this->contact->user_email;
                 break;
             case '#_CONTACTID':
                 $replace = $this->contact->ID;
                 break;
             case '#_CONTACTPHONE':
                 $replace = $this->contact->phone != '' ? $this->contact->phone : __('N/A', 'dbem');
                 break;
             case '#_CONTACTAVATAR':
                 $replace = get_avatar($this->contact->ID, $size = '50');
                 break;
             case '#_CONTACTPROFILELINK':
             case '#_CONTACTPROFILEURL':
                 if (function_exists('bp_core_get_user_domain')) {
                     $replace = bp_core_get_user_domain($this->contact->ID);
                     if ($result == '#_CONTACTPROFILELINK') {
                         $replace = '<a href="' . $replace . '">' . __('Profile') . '</a>';
                     }
                 }
                 break;
             case '#_CONTACTPROFILELINK':
             case '#_CONTACTPROFILEURL':
                 if (function_exists('bp_core_get_user_domain')) {
                     $replace = bp_core_get_user_domain($this->contact->ID);
                     if ($result == '#_CONTACTPROFILELINK') {
                         $replace = '<a href="' . $replace . '">' . __('Profile') . '</a>';
                     }
                 }
                 break;
             case '#_ATTENDEES':
                 ob_start();
                 $template = em_locate_template('placeholders/attendees.php', true, array('EM_Event' => $this));
                 $replace = ob_get_clean();
                 break;
             case '#_CATEGORIES':
                 ob_start();
                 $template = em_locate_template('placeholders/categories.php', true, array('EM_Event' => $this));
                 $replace = ob_get_clean();
                 break;
             default:
                 $replace = $result;
                 break;
         }
         $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target);
         $event_string = str_replace($result, $replace, $event_string);
     }
     //Time placeholders
     foreach ($placeholders[0] 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);
         }
     }
     //Time place holder that doesn't show if empty.
     //TODO add filter here too
     preg_match_all('/#@?_\\{[A-Za-z0-9 -\\/,\\.\\\\]+\\}/', $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->end_date == $this->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->attributes) && array_key_exists($attRef, $this->attributes)) {
             $attString = $this->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);
     }
     //Now do dependent objects
     $event_string = $this->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->categories[0];
     }
     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, $target);
 }
Exemple #8
0
/**
 * Performs actions on init. This works for both ajax and normal requests, the return results depends if an em_ajax flag is passed via POST or GET.
 */
function em_init_actions()
{
    global $wpdb, $EM_Notices, $EM_Event;
    //NOTE - No EM objects are globalized at this point, as we're hitting early init mode.
    //TODO Clean this up.... use a uniformed way of calling EM Ajax actions
    if (!empty($_REQUEST['em_ajax']) || !empty($_REQUEST['em_ajax_action'])) {
        if (isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'get_location') {
            if (isset($_REQUEST['id'])) {
                $EM_Location = new EM_Location($_REQUEST['id']);
                $location_array = $EM_Location->to_array();
                $location_array['location_balloon'] = $EM_Location->output(get_option('dbem_location_baloon_format'));
                echo EM_Object::json_encode($location_array);
            }
            die;
        }
        if (isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'delete_ticket') {
            if (isset($_REQUEST['id'])) {
                $EM_Ticket = new EM_Ticket($_REQUEST['id']);
                $result = $EM_Ticket->delete();
                if ($result) {
                    $result = array('result' => true);
                } else {
                    $result = array('result' => false, 'error' => $EM_Ticket->feedback_message);
                }
            } else {
                $result = array('result' => false, 'error' => __('No ticket id provided', 'dbem'));
            }
            echo EM_Object::json_encode($result);
            die;
        }
        if (isset($_REQUEST['query']) && $_REQUEST['query'] == 'GlobalMapData') {
            $EM_Locations = EM_Locations::get($_REQUEST);
            $json_locations = array();
            foreach ($EM_Locations as $location_key => $EM_Location) {
                $json_locations[$location_key] = $EM_Location->to_array();
                $json_locations[$location_key]['location_balloon'] = $EM_Location->output(get_option('dbem_map_text_format'));
            }
            echo EM_Object::json_encode($json_locations);
            die;
        }
        if (isset($_REQUEST['ajaxCalendar']) && $_REQUEST['ajaxCalendar']) {
            //FIXME if long events enabled originally, this won't show up on ajax call
            echo EM_Calendar::output($_REQUEST);
            die;
        }
    }
    //Event Actions
    if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 5) == 'event') {
        //Load the event object, with saved event if requested
        if (!empty($_REQUEST['event_id'])) {
            $EM_Event = new EM_Event($_REQUEST['event_id']);
        } else {
            $EM_Event = new EM_Event();
        }
        if ($_REQUEST['action'] == 'event_save' && current_user_can('edit_events')) {
            //Check Nonces
            if (is_admin()) {
                if (!wp_verify_nonce($_REQUEST['_wpnonce'] && 'event_save')) {
                    check_admin_referer('trigger_error');
                }
            } else {
                if (!wp_verify_nonce($_REQUEST['_wpnonce'] && 'event_save')) {
                    exit('Trying to perform an illegal action.');
                }
            }
            //Grab and validate submitted data
            if ($EM_Event->get_post() && $EM_Event->save()) {
                //EM_Event gets the event if submitted via POST and validates it (safer than to depend on JS)
                $EM_Notices->add_confirm($EM_Event->feedback_message);
                if (is_admin()) {
                    $page = !empty($_REQUEST['pno']) ? $_REQUEST['pno'] : '';
                    $scope = !empty($_REQUEST['scope']) ? $_REQUEST['scope'] : '';
                    //wp_redirect( get_bloginfo('wpurl').'/wp-admin/admin.php?page=events-manager&pno='.$page.'&scope='.$scope.'&message='.urlencode($EM_Event->feedback_message));
                } else {
                    $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer();
                    wp_redirect($redirect);
                }
                $events_result = true;
            } else {
                $EM_Notices->add_error($EM_Event->get_errors());
                $events_result = false;
            }
        }
        if ($_REQUEST['action'] == 'event_duplicate') {
            global $EZSQL_ERROR;
            $EM_Event = $EM_Event->duplicate();
            if ($EM_Event === false) {
                $EM_Notices->add_error($EM_Event->errors, true);
            } else {
                if ($EM_Event->id == $_REQUEST['event_id']) {
                    $EM_Notices->add_confirm($EM_Event->feedback_message . " " . sprintf(__('You are now viewing the duplicated %s.', 'dbem'), __('event', 'dbem')), true);
                } else {
                    $EM_Notices->add_confirm($EM_Event->feedback_message, true);
                }
            }
        }
        if ($_REQUEST['action'] == 'event_delete') {
            //DELETE action
            $selectedEvents = !empty($_REQUEST['events']) ? $_REQUEST['events'] : '';
            if (EM_Object::array_is_numeric($selectedEvents)) {
                $events_result = EM_Events::delete($selectedEvents);
            } elseif (is_object($EM_Event)) {
                $events_result = $EM_Event->delete();
            }
            $plural = count($selectedEvents) > 1 ? __('Events', 'dbem') : __('Event', 'dbem');
            if ($events_result) {
                $message = is_object($EM_Event) ? $EM_Event->feedback_message : sprintf(__('%s successfully deleted.', 'dbem'), $plural);
                $EM_Notices->add_confirm($message);
            } else {
                $message = is_object($EM_Event) ? $EM_Event->errors : sprintf(__('%s could not be deleted.', 'dbem'), $plural);
                $EM_Notices->add_confirm($message);
            }
        } elseif ($_REQUEST['action'] == 'event_approve') {
            //Approve Action
            $events_result = $EM_Event->approve();
            if ($events_result) {
                $EM_Notices->add_confirm($EM_Event->feedback_message);
            } else {
                $EM_Notices->add_error($EM_Event->errors);
            }
        }
        //AJAX Exit
        if (isset($events_result) && !empty($_REQUEST['em_ajax'])) {
            if ($events_result) {
                $return = array('result' => true, 'message' => $EM_Event->feedback_message);
            } else {
                $return = array('result' => false, 'message' => $EM_Event->feedback_message, 'errors' => $EM_Event->errors);
            }
        }
    }
    //Location Actions
    if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 8) == 'location') {
        global $EM_Location, $EM_Notices;
        //Load the location object, with saved event if requested
        if (!empty($_REQUEST['location_id'])) {
            $EM_Location = new EM_Location($_REQUEST['location_id']);
        } else {
            $EM_Location = new EM_Location();
        }
        if ($_REQUEST['action'] == 'location_save' && current_user_can('edit_locations')) {
            //Check Nonces
            em_verify_nonce('location_save');
            //Grab and validate submitted data
            if ($EM_Location->get_post() && $EM_Location->save()) {
                //EM_location gets the location if submitted via POST and validates it (safer than to depend on JS)
                $EM_Notices->add_confirm($EM_Location->feedback_message);
                $result = true;
            } else {
                $EM_Notices->add_error($EM_Location->get_errors());
                $result = false;
            }
        } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == "location_delete") {
            //delete location
            //get object or objects
            if (!empty($_REQUEST['locations']) || !empty($_REQUEST['location_id'])) {
                $args = !empty($_REQUEST['locations']) ? $_REQUEST['locations'] : $_REQUEST['location_id'];
                $locations = EM_Locations::get($args);
                foreach ($locations as $location) {
                    if (!$location->delete()) {
                        $EM_Notices->add_error($location->get_errors());
                        $errors = true;
                    }
                }
                if (empty($errors)) {
                    $result = true;
                    $location_term = count($locations) > 1 ? __('Locations', 'dbem') : __('Location', 'dbem');
                    $EM_Notices->add_confirm(sprintf(__('%s successfully deleted', 'dbem'), $location_term));
                } else {
                    $result = false;
                }
            }
        }
        if (isset($result) && $result && !empty($_REQUEST['em_ajax'])) {
            $return = array('result' => true, 'message' => $EM_Location->feedback_message);
            echo EM_Object::json_encode($return);
            die;
        } elseif (isset($result) && !$result && !empty($_REQUEST['em_ajax'])) {
            $return = array('result' => false, 'message' => $EM_Location->feedback_message, 'errors' => $EM_Notices->get_errors());
            echo EM_Object::json_encode($return);
            die;
        }
    }
    //Category Actions
    if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 8) == 'category') {
        global $EM_Category, $EM_Notices;
        //Load the category object, with saved event if requested
        if (!empty($_REQUEST['category_id'])) {
            $EM_Category = new EM_Category($_REQUEST['category_id']);
        } else {
            $EM_Category = new EM_Category();
        }
        if ($_REQUEST['action'] == 'category_save' && current_user_can('edit_categories')) {
            //Check Nonces
            em_verify_nonce('category_save');
            //Grab and validate submitted data
            if ($EM_Category->get_post() && $EM_Category->save()) {
                //EM_Category gets the category if submitted via POST and validates it (safer than to depend on JS)
                $EM_Notices->add_confirm($EM_Category->feedback_message);
                $result = true;
            } else {
                $EM_Notices->add_error($EM_Category->get_errors());
                $result = false;
            }
        } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == "category_delete") {
            //delete category
            //get object or objects
            if (!empty($_REQUEST['categories']) || !empty($_REQUEST['category_id'])) {
                $args = !empty($_REQUEST['categories']) ? $_REQUEST['categories'] : $_REQUEST['category_id'];
                $categories = EM_Categories::get($args);
                foreach ($categories as $category) {
                    if (!$category->delete()) {
                        $EM_Notices->add_error($category->get_errors());
                        $errors = true;
                    }
                }
                if (empty($errors)) {
                    $result = true;
                    $category_term = count($categories) > 1 ? __('EM_Categories', 'dbem') : __('Category', 'dbem');
                    $EM_Notices->add_confirm(sprintf(__('%s successfully deleted', 'dbem'), $category_term));
                } else {
                    $result = false;
                }
            }
        }
        if (isset($result) && $result && !empty($_REQUEST['em_ajax'])) {
            $return = array('result' => true, 'message' => $EM_Category->feedback_message);
            echo EM_Object::json_encode($return);
            die;
        } elseif (isset($result) && !$result && !empty($_REQUEST['em_ajax'])) {
            $return = array('result' => false, 'message' => $EM_Category->feedback_message, 'errors' => $EM_Notices->get_errors());
            echo EM_Object::json_encode($return);
            die;
        }
    }
    //Booking Actions
    if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 7) == 'booking' && (is_user_logged_in() || $_REQUEST['action'] == 'booking_add' && get_option('dbem_bookings_anonymous'))) {
        global $EM_Event, $EM_Booking, $EM_Person;
        //Load the event object, with saved event if requested
        $EM_Event = !empty($_REQUEST['event_id']) ? new EM_Event($_REQUEST['event_id']) : new EM_Event();
        //Load the booking object, with saved booking if requested
        $EM_Booking = !empty($_REQUEST['booking_id']) ? new EM_Booking($_REQUEST['booking_id']) : new EM_Booking();
        $allowed_actions = array('bookings_approve' => 'approve', 'bookings_reject' => 'reject', 'bookings_unapprove' => 'unapprove', 'bookings_delete' => 'delete');
        $result = false;
        if ($_REQUEST['action'] == 'booking_add') {
            //ADD/EDIT Booking
            em_verify_nonce('booking_add');
            do_action('em_booking_add', $EM_Event, $EM_Booking);
            if ($EM_Booking->get_post()) {
                //Does this user need to be registered first?
                $registration = true;
                //TODO do some ticket validation before registering the user
                if ($_REQUEST['register_user'] && get_option('dbem_bookings_anonymous')) {
                    //find random username - less options for user, less things go wrong
                    $username_root = explode('@', $_REQUEST['user_email']);
                    $username_rand = $username_root[0] . rand(1, 1000);
                    while (username_exists($username_root[0] . rand(1, 1000))) {
                        $username_rand = $username_root[0] . rand(1, 1000);
                    }
                    $id = em_register_new_user($username_rand, $_REQUEST['user_email'], $_REQUEST['user_name'], $_REQUEST['user_phone']);
                    if (is_numeric($id)) {
                        $EM_Person = new EM_Person($id);
                        $EM_Booking->person_id = $id;
                        $EM_Notices->add_confirm(__('A new user account has been created for you. Please check your email for access details.', 'dbem'));
                    } else {
                        $registration = false;
                        if (is_object($id) && get_class($id) == 'WP_Error') {
                            /* @var $id WP_Error */
                            if ($id->get_error_code() == 'email_exists') {
                                $EM_Notices->add_error(__('This email already exists in our system, please log in to register to proceed with your booking.', 'dbem'));
                            } else {
                                $EM_Notices->add_error($id->get_error_messages());
                            }
                        } else {
                            $EM_Notices->add_error(__('There was a problem creating a user account, please contact a website administrator.', 'dbem'));
                        }
                    }
                }
                if ($EM_Event->get_bookings()->add($EM_Booking) && $registration) {
                    $result = true;
                    $EM_Notices->add_confirm($EM_Event->get_bookings()->feedback_message);
                } else {
                    ob_start();
                    echo "<pre>";
                    print_r($id);
                    echo "</pre>";
                    $EM_Booking->feedback_message = ob_get_clean();
                    $EM_Notices->add_error($EM_Event->get_bookings()->get_errors());
                }
            } else {
                $result = false;
                $EM_Notices->add_error($EM_Booking->get_errors());
            }
        } elseif ($_REQUEST['action'] == 'booking_add_one' && is_object($EM_Event) && is_user_logged_in()) {
            //ADD/EDIT Booking
            em_verify_nonce('booking_add_one');
            $EM_Booking = new EM_Booking(array('person_id' => get_current_user_id(), 'event_id' => $EM_Event->id));
            //new booking
            //get first ticket in this event and book one place there.
            $EM_Ticket = $EM_Event->get_bookings()->get_tickets()->get_first();
            $EM_Ticket_Booking = new EM_Ticket_Booking(array('ticket_id' => $EM_Ticket->id, 'ticket_booking_spaces' => 1));
            $EM_Booking->get_tickets_bookings();
            $EM_Booking->tickets_bookings->tickets_bookings[] = $EM_Ticket_Booking;
            //Now save booking
            if ($EM_Event->get_bookings()->add($EM_Booking)) {
                $EM_Booking = $booking;
                $result = true;
                $EM_Notices->add_confirm($EM_Event->get_bookings()->feedback_message);
            } else {
                $EM_Notices->add_error($EM_Event->get_bookings()->get_errors());
            }
        } elseif ($_REQUEST['action'] == 'booking_cancel') {
            //Cancel Booking
            em_verify_nonce('booking_cancel');
            if ($EM_Booking->can_manage() || $EM_Booking->person->ID == get_current_user_id()) {
                if ($EM_Booking->cancel()) {
                    $result = true;
                    if (!defined('DOING_AJAX')) {
                        if ($EM_Booking->person->ID == get_current_user_id()) {
                            $EM_Notices->add_confirm(sprintf(__('Booking %s', 'dbem'), __('Cancelled', 'dbem')), true);
                        } else {
                            $EM_Notices->add_confirm($EM_Booking->feedback_message, true);
                        }
                        wp_redirect($_SERVER['HTTP_REFERER']);
                        exit;
                    }
                } else {
                    $EM_Notices->add_error($EM_Booking->get_errors());
                }
            } else {
                $EM_Notices->add_error(__('You must log in to cancel your booking.', 'dbem'));
            }
        } elseif (array_key_exists($_REQUEST['action'], $allowed_actions) && $EM_Event->can_manage('manage_bookings', 'manage_others_bookings')) {
            //Event Admin only actions
            $action = $allowed_actions[$_REQUEST['action']];
            //Just do it here, since we may be deleting bookings of different events.
            if (!empty($_REQUEST['bookings']) && EM_Object::array_is_numeric($_REQUEST['bookings'])) {
                $results = array();
                foreach ($_REQUEST['bookings'] as $booking_id) {
                    $EM_Booking = new EM_Booking($booking_id);
                    $result = $EM_Booking->{$action}();
                    $results[] = $result;
                    if (!in_array(false, $results) && !$result) {
                        $feedback = $EM_Booking->feedback_message;
                    }
                }
                $result = !in_array(false, $results);
            } elseif (is_object($EM_Booking)) {
                $result = $EM_Booking->{$action}();
                $feedback = $EM_Booking->feedback_message;
            }
            //FIXME not adhereing to object's feedback or error message, like other bits in this file.
            //TODO multiple deletion won't work in ajax
            if (isset($result) && !empty($_REQUEST['em_ajax'])) {
                if ($result) {
                    echo $feedback;
                } else {
                    echo '<span style="color:red">' . $feedback . '</span>';
                }
                die;
            }
        }
        if ($result && defined('DOING_AJAX')) {
            $return = array('result' => true, 'message' => $EM_Booking->feedback_message);
            echo EM_Object::json_encode($return);
            die;
        } elseif (!$result && defined('DOING_AJAX')) {
            $return = array('result' => false, 'message' => $EM_Booking->feedback_message, 'errors' => $EM_Notices->get_errors());
            echo EM_Object::json_encode($return);
            die;
        }
    } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'booking_add' && !is_user_logged_in() && !get_option('dbem_bookings_anonymous')) {
        $EM_Notices->add_error(__('You must log in before you make a booking.', 'dbem'));
        if (!$result && defined('DOING_AJAX')) {
            $return = array('result' => false, 'message' => $EM_Booking->feedback_message, 'errors' => $EM_Notices->get_errors());
            echo EM_Object::json_encode($return);
        }
        die;
    }
    //AJAX call for searches
    if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 6) == 'search') {
        if ($_REQUEST['action'] == 'search_states' && wp_verify_nonce($_REQUEST['_wpnonce'], 'search_states')) {
            if (!empty($_REQUEST['country'])) {
                $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_state AS value, location_country AS country, CONCAT(location_state, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_state IS NOT NULL AND location_state != '' AND location_country=%s", $_REQUEST['country']));
            } elseif (!empty($_REQUEST['region'])) {
                $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_state AS value, location_country AS country, CONCAT(location_state, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_state IS NOT NULL AND location_state != '' AND location_region=%s", $_REQUEST['region']));
            } else {
                $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_state AS value, location_country AS country, CONCAT(location_state, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE, $_REQUEST['country'] . "WHERE  location_state IS NOT NULL AND location_state != ''"));
            }
            if ($_REQUEST['return_html']) {
                //quick shortcut for quick html form manipulation
                ob_start();
                ?>
				<option value=''><?php 
                _e('All States', 'dbem');
                ?>
</option>
				<?php 
                foreach ($results as $result) {
                    echo "<option>{$result->value}</option>";
                }
                $return = ob_get_clean();
                echo apply_filters('em_ajax_search_states', $return);
                exit;
            } else {
                echo EM_Object::json_encode($results);
                exit;
            }
        }
        if ($_REQUEST['action'] == 'search_regions' && wp_verify_nonce($_REQUEST['_wpnonce'], 'search_regions')) {
            if (!empty($_REQUEST['country'])) {
                $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_region AS value, location_country AS country, CONCAT(location_region, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_region IS NOT NULL AND location_region != '' AND location_country=%s", $_REQUEST['country']));
            } else {
                $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_region AS value, location_country AS country, CONCAT(location_region, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_region IS NOT NULL AND location_region != ''", $_REQUEST['country']));
            }
            if ($_REQUEST['return_html']) {
                //quick shortcut for quick html form manipulation
                ob_start();
                ?>
				<option value=''><?php 
                _e('All Regions', 'dbem');
                ?>
</option>
				<?php 
                foreach ($results as $result) {
                    echo "<option>{$result->value}</option>";
                }
                $return = ob_get_clean();
                echo apply_filters('em_ajax_search_regions', $return);
                exit;
            } else {
                echo EM_Object::json_encode($results);
                exit;
            }
        } elseif ($_REQUEST['action'] == 'search_events' && wp_verify_nonce($_POST['_wpnonce'], 'search_events') && get_option('dbem_events_page_search')) {
            $args = EM_Events::get_post_search();
            ob_start();
            em_locate_template('templates/events-list.php', true, array('args' => $args));
            //if successful, this template overrides the settings and defaults, including search
            echo apply_filters('em_ajax_search_events', ob_get_clean(), $args);
            exit;
        }
    }
    //EM Ajax requests require this flag.
    if (is_admin() && is_user_logged_in()) {
        //Admin operations
        //Specific Oject Ajax
        if (!empty($_REQUEST['em_obj'])) {
            switch ($_REQUEST['em_obj']) {
                case 'em_bookings_events_table':
                case 'em_bookings_pending_table':
                case 'em_bookings_confirmed_table':
                    call_user_func($_REQUEST['em_obj']);
                    break;
            }
            die;
        }
    }
}
Exemple #9
0
 /**
  * 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;
     preg_match_all("/#@?_?[A-Za-z0-9]+/", $format, $placeholders);
     foreach ($placeholders[0] as $result) {
         $match = true;
         $replace = '';
         switch ($result) {
             //Event Details
             case '#_EVENTID':
                 $replace = $this->id;
                 break;
             case '#_NAME':
                 $replace = $this->name;
                 break;
             case '#_NOTES':
             case '#_EXCERPT':
                 //SEE AT BOTTOM OF FILE FOR OLD TARGET FILTERS FROM 2.x
                 $replace = $this->notes;
                 if ($result == "#_EXCERPT") {
                     $matches = explode('<!--more', $this->notes);
                     $replace = $matches[0];
                 }
                 break;
                 //Times
             //Times
             case '#_24HSTARTTIME':
             case '#_24HENDTIME':
                 $time = $result == '#_24HSTARTTIME' ? $this->start_time : $this->end_time;
                 $replace = substr($time, 0, 5);
                 break;
             case '#_12HSTARTTIME':
             case '#_12HENDTIME':
                 $time = $result == '#_12HSTARTTIME' ? $this->start_time : $this->end_time;
                 $replace = date('g:i A', strtotime($time));
                 break;
                 //Links
             //Links
             case '#_EVENTPAGEURL':
                 //Depreciated
             //Depreciated
             case '#_LINKEDNAME':
                 //Depreciated
             //Depreciated
             case '#_EVENTURL':
                 //Just the URL
             //Just the URL
             case '#_EVENTLINK':
                 //HTML Link
                 $joiner = stristr(EM_URI, "?") ? "&amp;" : "?";
                 $event_link = EM_URI . $joiner . "event_id=" . $this->id;
                 if ($result == '#_LINKEDNAME' || $result == '#_EVENTLINK') {
                     $replace = "<a href='{$event_link}' title='{$this->name}'>{$this->name}</a>";
                 } else {
                     $replace = $event_link;
                 }
                 break;
             case '#_EDITEVENTLINK':
                 if ($this->can_manage()) {
                     //TODO user should have permission to edit the event
                     $replace = "<a href='" . get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-event&amp;event_id={$this->id}'>" . __('Edit') . ' ' . __('Event', 'dbem') . "</a>";
                 }
                 break;
                 //Bookings
             //Bookings
             case '#_ADDBOOKINGFORM':
             case '#_REMOVEBOOKINGFORM':
             case '#_BOOKINGFORM':
                 if ($this->rsvp && get_option('dbem_rsvp_enabled')) {
                     if ($result == '#_BOOKINGFORM') {
                         $replace = em_add_booking_form() . em_delete_booking_form();
                     } else {
                         $replace = $result == '#_ADDBOOKINGFORM' ? em_add_booking_form() : em_delete_booking_form();
                     }
                 }
                 break;
             case '#_AVAILABLESEATS':
                 //Depreciated
             //Depreciated
             case '#_AVAILABLESPACES':
                 if ($this->rsvp && get_option('dbem_rsvp_enabled')) {
                     $replace = $this->get_bookings()->get_available_seats();
                 } else {
                     $replace = "0";
                 }
                 break;
             case '#_BOOKEDSEATS':
                 //Depreciated
             //Depreciated
             case '#_BOOKEDSPACES':
                 if ($this->rsvp && get_option('dbem_rsvp_enabled')) {
                     $replace = $this->get_bookings()->get_booked_seats();
                 } else {
                     $replace = "0";
                 }
                 break;
             case '#_SEATS':
                 //Depreciated
             //Depreciated
             case '#_SPACES':
                 $replace = $this->seats;
                 break;
                 //Contact Person
             //Contact Person
             case '#_CONTACTNAME':
             case '#_CONTACTPERSON':
                 //Depreciated (your call, I think name is better)
                 $replace = $this->contact->display_name;
                 break;
             case '#_CONTACTUSERNAME':
                 $replace = $this->contact->user_login;
                 break;
             case '#_CONTACTEMAIL':
             case '#_CONTACTMAIL':
                 //Depreciated
                 $replace = $this->contact->user_email;
                 break;
             case '#_CONTACTID':
                 $replace = $this->contact->ID;
                 break;
             case '#_CONTACTPHONE':
                 $replace = $this->contact->phone != '' ? $this->contact->phone : __('N/A', 'dbem');
                 break;
             case '#_CONTACTAVATAR':
                 $replace = get_avatar($this->contact->ID, $size = '50');
                 break;
             case '#_CONTACTPROFILELINK':
             case '#_CONTACTPROFILEURL':
                 if (function_exists('bp_core_get_user_domain')) {
                     $replace = bp_core_get_user_domain($this->contact->ID);
                     if ($result == '#_CONTACTPROFILELINK') {
                         $replace = '<a href="' . $replace . '">' . __('Profile') . '</a>';
                     }
                 }
                 break;
             default:
                 $replace = $result;
                 break;
         }
         $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target);
         $event_string = str_replace($result, $replace, $event_string);
     }
     //Time placeholders
     foreach ($placeholders[0] 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);
         }
     }
     //Time place holder that doesn't show if empty.
     //TODO add filter here too
     preg_match_all('/#@?_\\{[A-Za-z0-9 -\\/,\\.\\\\]+\\}/', $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->end_date == $this->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->attributes) && array_key_exists($attRef, $this->attributes)) {
             $attString = $this->attributes[$attRef];
         } elseif (!empty($results[2][$resultKey])) {
             //Check to see if we have a second set of braces;
             $attString = $results[2][$resultKey];
         }
         $attString = apply_filters('em_event_output_placeholder', $attString, $this, $result, $target);
         $event_string = str_replace($result, $attString, $event_string);
     }
     //Now do dependent objects
     $event_string = $this->location->output($event_string, $target);
     $event_string = $this->category->output($event_string, $target);
     return apply_filters('em_event_output', $event_string, $this, $target);
 }
Exemple #10
0
    /**
     * 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);
    }