function dbem_replace_placeholders($format, $event, $target = "html")
{
    $event_string = $format;
    preg_match_all("/#@?_?[A-Za-z0-9]+/", $format, $placeholders);
    foreach ($placeholders[0] as $result) {
        // echo "RESULT: $result <br>";
        // matches alla fields placeholder
        //TODO CUSTOM FIX FOR Brian
        // EVENTUALLY REMOVE
        if (preg_match('/#_JCCSTARTTIME/', $result)) {
            $time = substr($event['event_start_time'], 0, 5);
            $event_string = str_replace($result, $time, $event_string);
        }
        // END of REMOVE
        if (preg_match('/#_24HSTARTTIME/', $result)) {
            $time = substr($event['event_start_time'], 0, 5);
            $event_string = str_replace($result, $time, $event_string);
        }
        if (preg_match('/#_24HENDTIME/', $result)) {
            $time = substr($event['event_end_time'], 0, 5);
            $event_string = str_replace($result, $time, $event_string);
        }
        if (preg_match('/#_12HSTARTTIME/', $result)) {
            $AMorPM = "AM";
            $hour = substr($event['event_start_time'], 0, 2);
            $minute = substr($event['event_start_time'], 3, 2);
            if ($hour > 12) {
                $hour = $hour - 12;
                $AMorPM = "PM";
            }
            $time = "{$hour}:{$minute} {$AMorPM}";
            $event_string = str_replace($result, $time, $event_string);
        }
        if (preg_match('/#_12HENDTIME/', $result)) {
            $AMorPM = "AM";
            $hour = substr($event['event_end_time'], 0, 2);
            $minute = substr($event['event_end_time'], 3, 2);
            if ($hour > 12) {
                $hour = $hour - 12;
                $AMorPM = "PM";
            }
            $time = "{$hour}:{$minute} {$AMorPM}";
            $event_string = str_replace($result, $time, $event_string);
        }
        if (preg_match('/#_MAP/', $result)) {
            $location = dbem_get_location($event['location_id']);
            $map_div = dbem_single_location_map($location);
            $event_string = str_replace($result, $map_div, $event_string);
        }
        if (preg_match('/#_ADDBOOKINGFORM/', $result)) {
            $rsvp_is_active = get_option('dbem_gmap_is_active');
            if ($event['event_rsvp']) {
                $rsvp_add_module .= dbem_add_booking_form();
            } else {
                $rsvp_add_module .= "";
            }
            $event_string = str_replace($result, $rsvp_add_module, $event_string);
        }
        if (preg_match('/#_REMOVEBOOKINGFORM/', $result)) {
            $rsvp_is_active = get_option('dbem_gmap_is_active');
            if ($event['event_rsvp']) {
                $rsvp_delete_module .= dbem_delete_booking_form();
            } else {
                $rsvp_delete_module .= "";
            }
            $event_string = str_replace($result, $rsvp_delete_module, $event_string);
        }
        if (preg_match('/#_AVAILABLESEATS/', $result)) {
            $rsvp_is_active = get_option('dbem_gmap_is_active');
            if ($event['event_rsvp']) {
                $availble_seats .= dbem_get_available_seats($event['event_id']);
            } else {
                $availble_seats .= "";
            }
            $event_string = str_replace($result, $availble_seats, $event_string);
        }
        if (preg_match('/#_LINKEDNAME/', $result)) {
            $events_page_id = get_option('dbem_events_page');
            $event_page_link = get_permalink($events_page_id);
            if (stristr($event_page_link, "?")) {
                $joiner = "&amp;";
            } else {
                $joiner = "?";
            }
            $event_string = str_replace($result, "<a href='" . get_permalink($events_page_id) . $joiner . "event_id=" . $event['event_id'] . "'   title='" . $event['event_name'] . "'>" . $event['event_name'] . "</a>", $event_string);
        }
        if (preg_match('/#_EVENTPAGEURL/', $result)) {
            $events_page_id = get_option('dbem_events_page');
            $event_page_link = get_permalink($events_page_id);
            if (stristr($event_page_link, "?")) {
                $joiner = "&amp;";
            } else {
                $joiner = "?";
            }
            $event_string = str_replace($result, get_permalink($events_page_id) . $joiner . "event_id=" . $event['event_id'], $event_string);
        }
        if (preg_match('/#_(NAME|NOTES|SEATS)/', $result)) {
            $field = "event_" . ltrim(strtolower($result), "#_");
            $field_value = $event[$field];
            if ($field == "event_notes") {
                if ($target == "html") {
                    $field_value = apply_filters('dbem_notes', $field_value);
                } else {
                    if ($target == "map") {
                        $field_value = apply_filters('dbem_notes_map', $field_value);
                    } else {
                        $field_value = apply_filters('dbem_notes_rss', $field_value);
                    }
                }
            } else {
                if ($target == "html") {
                    $field_value = apply_filters('dbem_general', $field_value);
                } else {
                    $field_value = apply_filters('dbem_general_rss', $field_value);
                }
            }
            $event_string = str_replace($result, $field_value, $event_string);
        }
        if (preg_match('/#_(ADDRESS|TOWN|PROVINCE)/', $result)) {
            $field = "location_" . ltrim(strtolower($result), "#_");
            $field_value = $event[$field];
            if ($field == "event_notes") {
                if ($target == "html") {
                    $field_value = apply_filters('dbem_notes', $field_value);
                } else {
                    if ($target == "map") {
                        $field_value = apply_filters('dbem_notes_map', $field_value);
                    } else {
                        $field_value = apply_filters('dbem_notes_rss', $field_value);
                    }
                }
            } else {
                if ($target == "html") {
                    $field_value = apply_filters('dbem_general', $field_value);
                } else {
                    $field_value = apply_filters('dbem_general_rss', $field_value);
                }
            }
            $event_string = str_replace($result, $field_value, $event_string);
        }
        if (preg_match('/#_(LOCATION)$/', $result)) {
            $field = "location_name";
            $field_value = $event[$field];
            if ($target == "html") {
                $field_value = apply_filters('dbem_general', $field_value);
            } else {
                $field_value = apply_filters('dbem_general_rss', $field_value);
            }
            $event_string = str_replace($result, $field_value, $event_string);
        }
        if (preg_match('/#_CONTACTNAME$/', $result)) {
            $event['event_contactperson_id'] ? $user_id = $event['event_contactperson_id'] : ($user_id = get_option('dbem_default_contact_person'));
            $name = dbem_get_user_name($user_id);
            $event_string = str_replace($result, $name, $event_string);
        }
        if (preg_match('/#_CONTACTEMAIL$/', $result)) {
            $event['event_contactperson_id'] ? $user_id = $event['event_contactperson_id'] : ($user_id = get_option('dbem_default_contact_person'));
            $email = dbem_get_user_email($user_id);
            $event_string = str_replace($result, dbem_ascii_encode($email), $event_string);
        }
        if (preg_match('/#_CONTACTPHONE$/', $result)) {
            $event['event_contactperson_id'] ? $user_id = $event['event_contactperson_id'] : ($user_id = get_option('dbem_default_contact_person'));
            $phone = dbem_get_user_phone($user_id);
            $event_string = str_replace($result, dbem_ascii_encode($phone), $event_string);
        }
        if (preg_match('/#_(IMAGE)/', $result)) {
            if ($event['location_image_url'] != '') {
                $location_image = "<img src='" . $event['location_image_url'] . "' alt='" . $event['location_name'] . "'/>";
            } else {
                $location_image = "";
            }
            $event_string = str_replace($result, $location_image, $event_string);
        }
        if (preg_match('/#_(LOCATIONPAGEURL)/', $result)) {
            $events_page_link = dbem_get_events_page(true, false);
            if (stristr($events_page_link, "?")) {
                $joiner = "&amp;";
            } else {
                $joiner = "?";
            }
            $venue_page_link = $events_page_link . $joiner . "location_id=" . $event['location_id'];
            $event_string = str_replace($result, $venue_page_link, $event_string);
        }
        // matches all PHP time placeholders for endtime
        if (preg_match('/^#@[dDjlNSwzWFmMntLoYy]$/', $result)) {
            $event_string = str_replace($result, mysql2date(ltrim($result, "#@"), $event['event_end_date']), $event_string);
        }
        // matches all PHP date placeholders
        if (preg_match('/^#[dDjlNSwzWFmMntLoYy]$/', $result)) {
            // echo "-inizio-";
            $event_string = str_replace($result, mysql2date(ltrim($result, "#"), $event['event_start_date']), $event_string);
            // echo $event_string;
        }
        // matches all PHP time placeholders
        if (preg_match('/^#@[aABgGhHisueIOPTZcrU]$/', $result)) {
            $event_string = str_replace($result, mysql2date(ltrim($result, "#@"), "0000-00-00 " . $event['event_end_time']), $event_string);
            // echo $event_string;
        }
        if (preg_match('/^#[aABgGhHisueIOPTZcrU]$/', $result)) {
            $event_string = str_replace($result, mysql2date(ltrim($result, "#"), "0000-00-00 " . $event['event_start_time']), $event_string);
            // echo $event_string;
        }
        /* Marcus/ROR Begin Edit*/
        //Add a placeholder for categories
        if (preg_match('/#_CATEGORY$/', $result)) {
            $category = dbem_get_event_category($event['event_id']);
            if (stristr($event_page_link, "?")) {
                $joiner = "&amp;";
            } else {
                $joiner = "?";
            }
            $event_string = str_replace($result, "<a href='" . get_permalink($events_page_id) . $joiner . "category=" . $category['category_id'] . "'   title='" . $category['category_name'] . "'>" . $category['category_name'] . "</a>", $event_string);
        }
        /* Marcus/ROR End Edit */
    }
    /* Marcus Begin Edit */
    preg_match_all("/#@?_\\{[A-Za-z0-9 -\\/,\\.\\\\]+\\}/", $format, $placeholders);
    foreach ($placeholders[0] as $result) {
        if (substr($result, 0, 3) == "#@_") {
            $date = 'event_end_date';
            $offset = 4;
        } else {
            $date = 'event_start_date';
            $offset = 3;
        }
        $event_string = str_replace($result, mysql2date(substr($result, $offset, strlen($result) - ($offset + 1)), $event[$date]), $event_string);
    }
    /* Marcus End Edit */
    return $event_string;
}
function dbem_printable_booking_report($event_id)
{
    $event = dbem_get_event($event_id);
    $bookings = dbem_get_bookings_for($event_id);
    $available_seats = dbem_get_available_seats($event_id);
    $booked_seats = dbem_get_booked_seats($event_id);
    $stylesheet = get_bloginfo('url') . "/wp-content/plugins/events-manager/events_manager.css";
    ?>
		<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
			"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
		<html>
		<head>
			<meta http-equiv="Content-type" content="text/html; charset=utf-8">
			<title>Bookings for <?php 
    echo $event['event_name'];
    ?>
</title>
			 <link rel="stylesheet" href="<?php 
    echo $stylesheet;
    ?>
" type="text/css" media="screen" />
			
		</head>
		<body id="printable">
			<div id="container">
			<h1>Bookings for <?php 
    echo $event['event_name'];
    ?>
</h1> 
			<p><?php 
    echo dbem_replace_placeholders("#d #M #Y", $event);
    ?>
</p>
			<p><?php 
    echo dbem_replace_placeholders("#_LOCATION, #_ADDRESS, #_TOWN", $event);
    ?>
</p>   
			<h2><?php 
    _e('Bookings data', 'dbem');
    ?>
</h2>
			<table id="bookings-table">
				<tr>
					<th scope='col'><?php 
    _e('Name', 'dbem');
    ?>
</th>
					<th scope='col'><?php 
    _e('E-mail', 'dbem');
    ?>
</th>
					<th scope='col'><?php 
    _e('Phone number', 'dbem');
    ?>
</th> 
					<th scope='col'><?php 
    _e('Seats', 'dbem');
    ?>
</th> 
				<?php 
    foreach ($bookings as $booking) {
        ?>
				<tr>
					
					<td><?php 
        echo $booking['person_name'];
        ?>
</td> 
					<td><?php 
        echo $booking['person_email'];
        ?>
</td>
					<td><?php 
        echo $booking['person_phone'];
        ?>
</td>
					<td class='seats-number'><?php 
        echo $booking['booking_seats'];
        ?>
</td> 
				</tr>
			   <?php 
    }
    ?>
			  	<tr id='booked-seats'>
					<td colspan='2'>&nbsp;</td>
					<td class='total-label'><?php 
    _e('Booked', 'dbem');
    ?>
:</td>
					<td class='seats-number'><?php 
    echo $booked_seats;
    ?>
</td>
				</tr>
				<tr id='available-seats'>
					<td colspan='2'>&nbsp;</td> 
					<td class='total-label'><?php 
    _e('Available', 'dbem');
    ?>
:</td>  
					<td class='seats-number'><?php 
    echo $available_seats;
    ?>
</td>
				</tr>
			</table>  
			</div>
		</body>
		</html>
		<?php 
    die;
}
function dbem_email_rsvp_booking()
{
    $booker = array();
    $bookerName = $_POST['bookerName'];
    $bookerEmail = $_POST['bookerEmail'];
    $bookerPhone = $_POST['bookerPhone'];
    $bookedSeats = $_POST['bookedSeats'];
    $event_id = $_GET['event_id'];
    $event = dbem_get_event($event_id);
    $available_seats = dbem_get_available_seats($event_id);
    $reserved_seats = dbem_get_booked_seats($event_id);
    if ($event['event_contactperson_id'] != "") {
        $contact_id = $event['event_contactperson_id'];
    } else {
        $contact_id = get_option('dbem_default_contact_person');
    }
    $contact_name = dbem_get_user_name($contact_id);
    $contact_body = dbem_replace_placeholders(get_option('dbem_contactperson_email_body'), $event);
    $booker_body = dbem_replace_placeholders(get_option('dbem_respondent_email_body'), $event);
    // email specific placeholders
    $placeholders = array('#_CONTACTPERSON' => $contact_name, '#_RESPNAME' => $bookerName, '#_RESPEMAIL' => $bookerEmail, '#_SPACES' => $bookedSeats, '#_RESERVEDSPACES' => $reserved_seats, '#_AVAILABLESPACES' => $available_seats);
    foreach ($placeholders as $key => $value) {
        $contact_body = str_replace($key, $value, $contact_body);
        $booker_body = str_replace($key, $value, $booker_body);
    }
    $contact_email = dbem_get_user_email($contact_id);
    dbem_send_mail(__("New booking", 'dbem'), $contact_body, $contact_email);
    dbem_send_mail(__('Reservation confirmed', 'dbem'), $booker_body, $bookerEmail);
}
Esempio n. 4
0
function dbem_replace_placeholders($format, $event, $target = "html")
{
    $event_string = $format;
    preg_match_all("/#@?_?[A-Za-z0-9]+/", $format, $placeholders);
    foreach ($placeholders[0] as $result) {
        // echo "RESULT: $result <br>";
        // matches alla fields placeholder
        //TODO CUSTOM FIX FOR Brian
        // EVENTUALLY REMOVE
        if (preg_match('/#_JCCSTARTTIME/', $result)) {
            $time = substr($event['event_start_time'], 0, 5);
            $event_string = str_replace($result, $time, $event_string);
        }
        // END of REMOVE
        if (preg_match('/#_24HSTARTTIME/', $result)) {
            $time = substr($event['event_start_time'], 0, 5);
            $event_string = str_replace($result, $time, $event_string);
        }
        if (preg_match('/#_24HENDTIME/', $result)) {
            $time = substr($event['event_end_time'], 0, 5);
            $event_string = str_replace($result, $time, $event_string);
        }
        if (preg_match('/#_12HSTARTTIME/', $result)) {
            $AMorPM = "AM";
            $hour = substr($event['event_start_time'], 0, 2);
            $minute = substr($event['event_start_time'], 3, 2);
            if ($hour > 12) {
                $hour = $hour - 12;
                $AMorPM = "PM";
            }
            $time = "{$hour}:{$minute} {$AMorPM}";
            $event_string = str_replace($result, $time, $event_string);
        }
        if (preg_match('/#_12HENDTIME/', $result)) {
            $AMorPM = "AM";
            $hour = substr($event['event_end_time'], 0, 2);
            $minute = substr($event['event_end_time'], 3, 2);
            if ($hour > 12) {
                $hour = $hour - 12;
                $AMorPM = "PM";
            }
            $time = "{$hour}:{$minute} {$AMorPM}";
            $event_string = str_replace($result, $time, $event_string);
        }
        if (preg_match('/#_MAP/', $result)) {
            $location = dbem_get_location($event['location_id']);
            $map_div = dbem_single_location_map($location);
            $event_string = str_replace($result, $map_div, $event_string);
        }
        if (preg_match('/#_ADDBOOKINGFORM/', $result)) {
            $rsvp_is_active = get_option('dbem_gmap_is_active');
            if ($event['event_rsvp']) {
                $rsvp_add_module .= dbem_add_booking_form();
            } else {
                $rsvp_add_module .= "";
            }
            $event_string = str_replace($result, $rsvp_add_module, $event_string);
        }
        if (preg_match('/#_REMOVEBOOKINGFORM/', $result)) {
            $rsvp_is_active = get_option('dbem_gmap_is_active');
            if ($event['event_rsvp']) {
                $rsvp_delete_module .= dbem_delete_booking_form();
            } else {
                $rsvp_delete_module .= "";
            }
            $event_string = str_replace($result, $rsvp_delete_module, $event_string);
        }
        if (preg_match('/#_AVAILABLESEATS/', $result)) {
            $rsvp_is_active = get_option('dbem_gmap_is_active');
            if ($event['event_rsvp']) {
                $availble_seats .= dbem_get_available_seats($event['event_id']);
            } else {
                $availble_seats .= "";
            }
            $event_string = str_replace($result, $availble_seats, $event_string);
        }
        if (preg_match('/#_LINKEDNAME/', $result)) {
            $events_page_id = get_option('dbem_events_page');
            $event_page_link = get_permalink($events_page_id);
            if (stristr($event_page_link, "?")) {
                $joiner = "&amp;";
            } else {
                $joiner = "?";
            }
            $event_string = str_replace($result, "<a href='" . get_permalink($events_page_id) . $joiner . "event_id=" . $event['event_id'] . "'   title='" . $event['event_name'] . "'>" . $event['event_name'] . "</a>", $event_string);
        }
        if (preg_match('/#_EVENTPAGEURL(\\[(.+\\)]))?/', $result)) {
            $events_page_id = get_option('dbem_events_page');
            if (stristr($event_page_link, "?")) {
                $joiner = "&amp;";
            } else {
                $joiner = "?";
            }
            $event_string = str_replace($result, get_permalink($events_page_id) . $joiner . "event_id=" . $event['event_id'], $event_string);
        }
        if (preg_match('/#_(NAME|NOTES|SEATS|EXCERPT)/', $result)) {
            $field = "event_" . ltrim(strtolower($result), "#_");
            $field_value = $event[$field];
            if ($field == "event_notes" || $field == "event_excerpt") {
                /* Marcus Begin Edit */
                if ($target == "html") {
                    //If excerpt, we use more link text
                    if ($field == "event_excerpt") {
                        $matches = explode('<!--more-->', $event['event_notes']);
                        $field_value = $matches[0];
                        $field_value = apply_filters('dbem_notes_excerpt', $field_value);
                    } else {
                        $field_value = apply_filters('dbem_notes', $field_value);
                    }
                    //$field_value = apply_filters('the_content', $field_value); - chucks a wobbly if we do this.
                } else {
                    if ($target == "map") {
                        $field_value = apply_filters('dbem_notes_map', $field_value);
                    } else {
                        if ($field == "event_excerpt") {
                            $matches = explode('<!--more-->', $event['event_notes']);
                            $field_value = htmlentities($matches[0]);
                            $field_value = apply_filters('dbem_notes_rss', $field_value);
                        } else {
                            $field_value = apply_filters('dbem_notes_rss', $field_value);
                        }
                        $field_value = apply_filters('the_content_rss', $field_value);
                    }
                }
                /* Marcus End Edit */
            } else {
                if ($target == "html") {
                    $field_value = apply_filters('dbem_general', $field_value);
                } else {
                    $field_value = apply_filters('dbem_general_rss', $field_value);
                }
            }
            $event_string = str_replace($result, $field_value, $event_string);
        }
        if (preg_match('/#_(ADDRESS|TOWN|PROVINCE)/', $result)) {
            $field = "location_" . ltrim(strtolower($result), "#_");
            $field_value = $event[$field];
            if ($field == "event_notes") {
                if ($target == "html") {
                    $field_value = apply_filters('dbem_notes', $field_value);
                } else {
                    if ($target == "map") {
                        $field_value = apply_filters('dbem_notes_map', $field_value);
                    } else {
                        $field_value = apply_filters('dbem_notes_rss', $field_value);
                    }
                }
            } else {
                if ($target == "html") {
                    $field_value = apply_filters('dbem_general', $field_value);
                } else {
                    $field_value = apply_filters('dbem_general_rss', $field_value);
                }
            }
            $event_string = str_replace($result, $field_value, $event_string);
        }
        if (preg_match('/#_(LOCATION)$/', $result)) {
            $field = "location_name";
            $field_value = $event[$field];
            if ($target == "html") {
                $field_value = apply_filters('dbem_general', $field_value);
            } else {
                $field_value = apply_filters('dbem_general_rss', $field_value);
            }
            $event_string = str_replace($result, $field_value, $event_string);
        }
        if (preg_match('/#_CONTACTNAME$/', $result)) {
            $event['event_contactperson_id'] ? $user_id = $event['event_contactperson_id'] : ($user_id = get_option('dbem_default_contact_person'));
            $name = dbem_get_user_name($user_id);
            $event_string = str_replace($result, $name, $event_string);
        }
        if (preg_match('/#_CONTACTEMAIL$/', $result)) {
            $event['event_contactperson_id'] ? $user_id = $event['event_contactperson_id'] : ($user_id = get_option('dbem_default_contact_person'));
            $email = dbem_get_user_email($user_id);
            $event_string = str_replace($result, dbem_ascii_encode($email), $event_string);
        }
        if (preg_match('/#_CONTACTPHONE$/', $result)) {
            $event['event_contactperson_id'] ? $user_id = $event['event_contactperson_id'] : ($user_id = get_option('dbem_default_contact_person'));
            $phone = dbem_get_user_phone($user_id);
            $event_string = str_replace($result, dbem_ascii_encode($phone), $event_string);
        }
        if (preg_match('/#_(IMAGE)/', $result)) {
            if ($event['location_image_url'] != '') {
                $location_image = "<img src='" . $event['location_image_url'] . "' alt='" . $event['location_name'] . "'/>";
            } else {
                $location_image = "";
            }
            $event_string = str_replace($result, $location_image, $event_string);
        }
        if (preg_match('/#_(LOCATIONPAGEURL)/', $result)) {
            $events_page_link = dbem_get_events_page(true, false);
            if (stristr($events_page_link, "?")) {
                $joiner = "&amp;";
            } else {
                $joiner = "?";
            }
            $venue_page_link = $events_page_link . $joiner . "location_id=" . $event['location_id'];
            $event_string = str_replace($result, $venue_page_link, $event_string);
        }
        // matches all PHP time placeholders for endtime
        if (preg_match('/^#@[dDjlNSwzWFmMntLoYy]$/', $result)) {
            $event_string = str_replace($result, mysql2date(ltrim($result, "#@"), $event['event_end_date']), $event_string);
        }
        // matches all PHP date placeholders
        if (preg_match('/^#[dDjlNSwzWFmMntLoYy]$/', $result)) {
            // echo "-inizio-";
            $event_string = str_replace($result, mysql2date(ltrim($result, "#"), $event['event_start_date']), $event_string);
            // echo $event_string;
        }
        // matches all PHP time placeholders
        if (preg_match('/^#@[aABgGhHisueIOPTZcrU]$/', $result)) {
            $event_string = str_replace($result, mysql2date(ltrim($result, "#@"), "2000-10-10 " . $event['event_end_time']), $event_string);
            // echo $event_string;
        }
        if (preg_match('/^#[aABgGhHisueIOPTZcrU]$/', $result)) {
            $event_string = str_replace($result, mysql2date(ltrim($result, "#"), "2000-10-10 " . $event['event_start_time']), $event_string);
            //echo $event['event_start_time'];
            //echo mysql2date('h:i A', '2010-10-10 23:35:00')."<br/>";
            // echo $event_string;
        }
        /* Marcus Begin Edit*/
        //Add a placeholder for categories
        if (preg_match('/^#_CATEGORY$/', $result)) {
            $category = dbem_get_event_category($event['event_id']);
            $event_string = str_replace($result, $category['category_name'], $event_string);
        }
        /* Marcus End Edit */
    }
    /* Marcus Begin Edit */
    preg_match_all("/#@?_\\{[A-Za-z0-9 -\\/,\\.\\\\]+\\}/", $format, $results);
    foreach ($results[0] as $result) {
        if (substr($result, 0, 3) == "#@_") {
            $date = 'event_end_date';
            $offset = 4;
        } else {
            $date = 'event_start_date';
            $offset = 3;
        }
        if ($date == 'event_end_date' && $event[$date] == $event['event_start_date']) {
            $event_string = str_replace($result, '', $event_string);
        } else {
            $event_string = str_replace($result, mysql2date(substr($result, $offset, strlen($result) - ($offset + 1)), $event[$date]), $event_string);
        }
    }
    /* Marcus End Edit */
    /* Marcus Begin Edit */
    //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 = $event['event_attributes'][$attRef];
        if (trim($attString) == '' && $results[1][$resultKey] != '') {
            //Check to see if we have a second set of braces;
            $attString = substr($results[1][$resultKey], 1, strlen(trim($results[1][$resultKey])) - 2);
        }
        $event_string = str_replace($result, $attString, $event_string);
    }
    /* Marcus End Edit */
    return $event_string;
}