$time_end) { $output_countdown .= $message; } else if ($days_left == 0) { $output_countdown .= __('in', 'event_espresso') . ' ' . $hours_left . ':' . $minutes_left . ' ' . __('hours', 'event_espresso') . '.'; } else if ($time_end >= $daystart and $time_start <= $dayend) { $output_countdown .= __('today', 'event_espresso') . '. ' . __('in', 'event_espresso') . ' ' . $minutes_left . ' ' . __('minutes', 'event_espresso') . '.'; } else { $output_countdown .= __('in', 'event_espresso') . ' '; if ($days_left == 1) { $output_countdown .= $days_left . ' ' . __('day', 'event_espresso') . ' '; } else { $output_countdown .= $days_left . ' ' . __('days', 'event_espresso') . ' '; } $output_countdown .= __('and', 'event_espresso') . ' ' . $hours_left . ':' . $minutes_left . ' ' . __('hours', 'event_espresso') . '.'; } return $output_countdown; } /* ------------------------------------------------------------- Name: espresso_countup Purpose: Calculates the time since the event Receive: $time_start, $time_end, $message Return: $output_archive ------------------------------------------------------------- */ function espresso_countup($time_start, $time_end, $expired_message) { //If the timezome is set in the wordpress database, then lets use it as the default timezone. if (get_option('timezone_string') != '') { date_default_timezone_set(get_option('timezone_string')); } $present = current_time('timestamp'); $difference = $present - $time_start; $daystart = floor($present / 86400) * 86400; $dayend = $daystart + 86400; if ($difference < 0) $difference = 0; $days_ago = floor($difference / 60 / 60 / 24); $hours_ago = floor(($difference - $days_ago * 60 * 60 * 24) / 60 / 60); $minutes_ago = floor(($difference - $days_ago * 60 * 60 * 24 - $hours_ago * 60 * 60) / 60); if ($minutes_ago < "10") $minutes_ago = "0" . $minutes_ago; if ($hours_ago < "10") $hours_ago = "0" . $hours_ago; $output_archive = ''; if ($days_ago == 0 and $hours_ago == 0 and $minutes_ago == 0 and $present > $time_end) { $output_archive .= $message; } else if ($days_ago == 0) { $output_archive .= $hours_ago . ':' . $minutes_ago . ' ' . __('hours', 'event_espresso') . ' ' . __('ago', 'event_espresso') . '.'; } else { if ($days_ago == 1) { $output_archive .= $days_ago . ' ' . __('day', 'event_espresso') . ' '; } else { $output_archive .= $days_ago . ' ' . __('days', 'event_espresso') . ' '; } $output_archive .=__('and', 'event_espresso') . ' ' . $hours_ago . ':' . $minutes_ago . ' ' . __('hours', 'event_espresso') . ' ' . __('ago', 'event_espresso') . '.'; } return $output_archive; } /* ------------------------------------------------------------- Name: espresso_duration Purpose: Calculates the duration of the event Receive: $event_start, $event_end, $allday Return: $output_duration ------------------------------------------------------------- */ function espresso_duration($event_start, $event_end, $allday) { //If the timezome is set in the wordpress database, then lets use it as the default timezone. if (get_option('timezone_string') != '') { date_default_timezone_set(get_option('timezone_string')); } $difference = $event_end - $event_start; if ($difference < 0) $difference = 0; $days_duration = floor($difference / 60 / 60 / 24); $hours_duration = floor(($difference - $days_duration * 60 * 60 * 24) / 60 / 60); $minutes_duration = floor(($difference - $days_duration * 60 * 60 * 24 - $hours_duration * 60 * 60) / 60); if ($minutes_duration < "10") $minutes_duration = "0" . $minutes_duration; if ($hours_duration < "10") $hours_duration = "0" . $hours_duration; $output_duration = ''; if ($allday == 'Y') { $output_duration .= __('allday', 'event_espresso'); } else if (($days_duration == 0 and $hours_duration == 0 and $minutes_duration == 0) or ($event_start == $event_end)) { $output_duration .= __('duration', 'event_espresso'); } else if ($days_duration == 0) { $output_duration .= $hours_duration . ':' . $minutes_duration . ' ' . __('hours', 'event_espresso') . '.'; } else if ($days_duration == 0 and $hours_duration == 0) { $output_duration .= $minutes_duration . ' ' . __('minutes', 'event_espresso') . '.'; } else { if ($days_duration == 1) { $output_duration .= $days_duration . ' ' . __('day', 'event_espresso') . ' '; } else { $output_duration .= $days_duration . ' ' . __('days', 'event_espresso') . ' '; } $output_duration .= __('and', 'event_espresso') . ' ' . $hours_duration . ':' . $minutes_duration . ' ' . __('hours', 'event_espresso') . '.'; } return $output_duration; } //This function returns the registration limit associated with a time for an event if (!function_exists('espresso_get_time_reg_limit')) { function espresso_get_time_reg_limit($time_id=0) { if ($time_id == 0) return 0; global $wpdb; $sql = "SELECT reg_limit FROM " . EVENTS_START_END_TABLE . " WHERE id='" . $time_id . "' LIMIT 0,1 "; $data = $wpdb->get_results($sql); if ($wpdb->num_rows > 0) return $wpdb->last_result[0]->reg_limit; } } //Creates a dropdown if multiple times are associated with an event if (!function_exists('event_espresso_time_dropdown')) { function event_espresso_time_dropdown($event_id = 'NULL', $label = 1, $multi_reg = 0, $value = '') { global $wpdb, $org_options; $html = ''; //Will make the name an array and put the event id as a key so we //know which event this belongs to $multi_name_adjust = $multi_reg == 1 ? "[$event_id]" : ''; $time_reg_limit = $org_options['time_reg_limit']; //$time_reg_limit = 'Y'; //echo $num_attendees; $sql = "SELECT * FROM " . EVENTS_START_END_TABLE . " WHERE event_id='" . $event_id . "' "; $events = $wpdb->get_results($sql); foreach ($events as $event) { $timezone_string = empty($event->timezone_string) ? '' : $event->timezone_string; } //This is the initial check to see if we time slot are controlled by registration limits. if ($time_reg_limit == 'Y') { //$num_attendees = get_number_of_attendees_reg_limit($event_id, 'num_attendees'); //$sql .= " AND (reg_limit = '0' OR reg_limit >= '" .$num_attendees."') "; $sql = "SELECT es.*, (es.reg_limit - count(ea.id)) as available_spaces FROM " . EVENTS_START_END_TABLE . " es left join " . EVENTS_ATTENDEE_TABLE . " ea on es.event_id = ea.event_id and es.start_time = ea.event_time and es.end_time = ea.end_time where es.event_id= $event_id group by es.id"; } $event_times = $wpdb->get_results($sql); if ($wpdb->num_rows == 1) {//If one result, then display the times. $html .= $label == 1 ? '' . __('Start Time:', 'event_espresso') . ' ' : ''; foreach ($event_times as $time) { $html .= '' . event_date_display($time->start_time, get_option('time_format')) . ''; $html .= $label == 1 ? '
' . __('End Time: ', 'event_espresso') . '' : __(' to ', 'event_espresso'); $html .= '' . event_date_display($time->end_time, get_option('time_format')) . ''; $html .= ''; } } else if ($wpdb->num_rows > 1) {//If more than one result, then display the dropdown //print_r($event_times); $html .= $label == 1 ? '' : ''; $html .= ''; } return $html; } } function espresso_time_id_hidden_field($event_id, $multi_reg = 0) { global $wpdb, $org_options; //Will make the name an array and put the event id as a key so we //know which event this belongs to $multi_name_adjust = $multi_reg == 1 ? "[$event_id]" : ''; $time_reg_limit = $org_options['time_reg_limit']; //$time_reg_limit = 'Y'; //echo $num_attendees; $sql = "SELECT * FROM " . EVENTS_START_END_TABLE . " WHERE event_id='" . $event_id . "' LIMIT 0,1 "; //This is the initial check to see if we time slot are controlled by registration limits. if ($time_reg_limit == 'Y') { //$num_attendees = get_number_of_attendees_reg_limit($event_id, 'num_attendees'); //$sql .= " AND (reg_limit = '0' OR reg_limit >= '" .$num_attendees."') "; $sql = "SELECT es.*, (es.reg_limit - count(ea.id)) as available_spaces FROM " . EVENTS_START_END_TABLE . " es left join " . EVENTS_ATTENDEE_TABLE . " ea on es.event_id = ea.event_id and es.start_time = ea.event_time and es.end_time = ea.end_time where es.event_id= $event_id group by es.id"; } $event_times = $wpdb->get_results($sql); if ($wpdb->num_rows > 0) {//If one result, then display the times. $time_id = $wpdb->last_result[0]->id; return ''; } } //Get a single start or end time // @params $event_id (required) // @params $time (optional, start_time (default) | end_time) if (!function_exists('event_espresso_get_time')) { function event_espresso_get_time($event_id, $format = 'start_time') { global $wpdb; $event_times = $wpdb->get_results("SELECT " . $format . " FROM " . EVENTS_START_END_TABLE . " WHERE event_id='" . $event_id . "' LIMIT 0,1 "); if ($wpdb->num_rows > 0) { foreach ($event_times as $time) { switch ($format) { case 'start_time' : return event_date_display($time->start_time, get_option('time_format')); break; case 'end_time' : return event_date_display($time->end_time, get_option('time_format')); break; } } } } } /* * Time display function * Shows an event time based on time_id * @params string $time_id * @params string $format - format for the time display * start - show the event start time only * end - show the event end time only * default - show the event end and start time */ if (!function_exists('event_espresso_display_selected_time')) { function event_espresso_display_selected_time($time_id = 0, $format = 'NULL') { global $wpdb; $html = ''; $event_times = $wpdb->get_results("SELECT * FROM " . EVENTS_START_END_TABLE . " WHERE id='" . $time_id . "'"); foreach ($event_times as $time) { switch ($format) { case 'start' : $html .= event_date_display($time->start_time, get_option('time_format')); break; case 'end' : $html .= event_date_display($time->end_time, get_option('time_format')); break; default : $html .= ''.__('Time: ', 'event_espresso').''; $html .= event_date_display($time->start_time, get_option('time_format')) . ' - '. event_date_display($time->end_time, get_option('time_format')); break; } $html .= ''; } return $html; } } //Checks if a date is later than another date if (!function_exists('event_espresso_firstdate_later')) { function event_espresso_firstdate_later($first_date, $second_date) { $start = strtotime($first_date); $end = strtotime($second_date); if ($start - $end > 0) return true; else return false; } ; }; /* * Date function without formatting * Formats a date * @params string $date * @params string $format - format for the date */ if (!function_exists('event_espresso_no_format_date')) { function event_espresso_no_format_date($date, $format = '') { $format = $format == '' ? get_option('date_format') : $format; if (empty($date)) { $event_date_display = NULL; } else { $event_date_display = date_i18n($format, strtotime($date)); //Fixed for international use } return $event_date_display; } } /* * Date formatting function * Formats a date * @params string $date * @params string $format - format for the date */ if (!function_exists('event_date_display')) { function event_date_display($date, $format = '') { $format = $format == '' ? get_option('date_format') : $format; if (empty($date)) { $event_date_display = ''; //echo ''.__('NO DATE SUPPLIED','event_espresso').''; } else { $event_date_display = date_i18n($format, strtotime($date)); //Fixed for international use } return $event_date_display; } } //This function just returns an event start date //@param the event id if (!function_exists('event_espresso_event_start_date')) { function event_espresso_event_start_date($event_id) { global $wpdb; $sql = "SELECT e.start_date FROM " . EVENTS_DETAIL_TABLE . " e WHERE e.id = '" . $event_id . "'"; $events = $wpdb->get_results($sql); return event_date_display($wpdb->last_result[0]->start_date); } } function event_espresso_datetime2mysqldatetime($datetime) {// "25.12.2010 12:10:00" -> "2010-12-25 12:10:00" return date('Y-m-d H:i:s', strtotime($datetime)); // "25.12.2010" -> "2010-12-25 00:00:00" } function event_espresso_mysqldatetime2datetime($mysql_datetime) {// "2010-12-25 12:10:00" -> "25.12.2010 12:10:00" $d = split(' ', $mysql_datetime); // "2010-12-25" -> "25.12.2010" if ($d && count($d) > 1) { list($year, $month, $day) = split("-", $d[0]); list($hour, $minute, $second) = split(":", $d[1]); $d = date('d.m.Y H:i:s', mktime($hour, $minute, $second, $month, $day, $year)); } else if ($d && count($d) == 1) { list($year, $month, $day) = split("-", $d[0]); $d = date('d.m.Y', mktime(0, 0, 0, $month, $day, $year)); } else { $d = NULL; } return $d; } //Returns the times and dates of individual events // @params $event_id (required) // @params $format ( start_date_time (default) | end_date_time | start_time | end_time | start_date | end_date | start_timestamp | end_timestamp ) if (!function_exists('espresso_event_time')) { function espresso_event_time($event_id, $type, $format = '') { global $wpdb; $sql = "SELECT e.id, e.start_date start_date, e.end_date end_date, ese.start_time start_time, ese.end_time end_time "; $sql .= "FROM " . EVENTS_DETAIL_TABLE . " e "; $sql .= "LEFT JOIN " . EVENTS_START_END_TABLE . " ese ON ese.event_id = e.id "; $sql .= "WHERE e.id = '" . $event_id . "' LIMIT 0,1"; $date_format = $format == '' ? get_option('date_format') : $format; $time_format = $format == '' ? get_option('time_format') : $format; $wpdb->get_results($sql); //event_date_display($date, $format = 'M d, Y'); switch ($type) { case 'start_time': return event_date_display($wpdb->last_result[0]->start_time, $time_format); break; case 'end_time': return event_date_display($wpdb->last_result[0]->end_time, $time_format); break; case 'start_date': return event_date_display($wpdb->last_result[0]->start_date, $date_format); break; case 'end_date': return event_date_display($wpdb->last_result[0]->end_date, $date_format); break; case 'start_timestamp': return strtotime($wpdb->last_result[0]->start_date . ' ' . $wpdb->last_result[0]->start_time); break; case 'end_timestamp': return strtotime($wpdb->last_result[0]->end_date . ' ' . $wpdb->last_result[0]->end_time); break; case 'end_date_time': return event_date_display($wpdb->last_result[0]->end_date, $date_format) . ' ' . event_date_display($wpdb->last_result[0]->end_time, $time_format); break; case 'start_date_time': default: return event_date_display($wpdb->last_result[0]->start_date, $date_format) . ' ' . event_date_display($wpdb->last_result[0]->start_time, $time_format); break; } } } function eventespresso_ddtimezone($event_id = 0) { global $wpdb; $tz_event = $wpdb->get_var($wpdb->prepare("SELECT timezone_string FROM " . EVENTS_DETAIL_TABLE . " WHERE id = '" . $event_id . "'")); $timezone_format = _x('Y-m-d G:i:s', 'timezone date format'); $current_offset = get_option('gmt_offset'); $tzstring = $tz_event != '' ? $tz_event : get_option('timezone_string'); //echo $tzstring; $check_zone_info = true; // Remove old Etc mappings. Fallback to gmt_offset. if (false !== strpos($tzstring, 'Etc/GMT')) $tzstring = ''; if (empty($tzstring)) { // Create a UTC+- zone if no timezone string exists $check_zone_info = false; if (0 == $current_offset) $tzstring = 'UTC+0'; elseif ($current_offset < 0) $tzstring = 'UTC' . $current_offset; else $tzstring = 'UTC+' . $current_offset; } ?>


UTC time is %s'), date_i18n($timezone_format, false, 'gmt')); ?>
%1$s'), date_i18n($timezone_format)); ?>

$right_now) { $found = true; break; } } if ($found) { echo ' '; $message = $tr['isdst'] ? __('Daylight saving time begins on: %s.') : __('Standard time begins on: %s.'); // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). printf($message, date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $tr['ts'] + ($tz_offset - $tr['offset']))); } else { _e('This timezone does not observe daylight saving time.'); } } // Set back to UTC. date_default_timezone_set('UTC'); ?>

get_var($wpdb->prepare("SELECT timezone_string FROM " . EVENTS_DETAIL_TABLE . " WHERE id = '" . $event_id . "'")); $timezone_format = _x('Y-m-d G:i:s', 'timezone date format'); $current_offset = get_option('gmt_offset'); $tzstring = $tz_event != '' ? $tz_event : get_option('timezone_string'); //echo $tzstring; $check_zone_info = true; // Remove old Etc mappings. Fallback to gmt_offset. if (false !== strpos($tzstring, 'Etc/GMT')) $tzstring = ''; if (empty($tzstring)) { // Create a UTC+- zone if no timezone string exists $check_zone_info = false; if (0 == $current_offset) $tzstring = 'UTC+0'; elseif ($current_offset < 0) $tzstring = 'UTC' . $current_offset; else $tzstring = 'UTC+' . $current_offset; } ?>

$info) { foreach ($info as $zone) { if ( ! empty($zone['timezone_id']) AND ! in_array($zone['timezone_id'], $added) AND in_array($zone['timezone_id'], $idents)) { $z = new DateTimeZone($zone['timezone_id']); $c = new DateTime(null, $z); $zone['time'] = $c->format('h:i A'); $data[] = $zone; $offset[] = $z->getOffset($c); $added[] = $zone['timezone_id']; } } } echo '
'; echo ''; // now you can use $options; } */ function formatOffset($offset) { $hours = $offset / 3600; $remainder = $offset % 3600; $sign = $hours > 0 ? '+' : '-'; $hour = (int) abs($hours); $minutes = (int) abs($remainder / 60); if ($hour == 0 AND $minutes == 0) { $sign = ' '; } return 'GMT' . $sign . str_pad($hour, 2, '0', STR_PAD_LEFT) . ':' . str_pad($minutes, 2, '0'); } function date_at_timezone($format, $locale, $timestamp=null) { //http://php.net/manual/en/function.date.php //Examples //$t = time(); //print date("g:i A T", $t); //4:16 PM PDT //print date_at_timezone("g:i A T", "America/New_York", $t); //7:16 PM EDT //print date_at_timezone("g:i A T", "Pacific/Samoa", $t); //12:16 PM SST //print date("g:i A T", $t); //4:16 PM PDT if (is_null($timestamp)) $timestamp = time(); //Prepare to calculate the time zone offset $current = time(); //Switch to new time zone locale $tz = date_default_timezone_get(); date_default_timezone_set($locale); //Calculate the offset $offset = time() - $current; //Get the date in the new locale $output = date($format, $timestamp - $offset); //Restore the previous time zone date_default_timezone_set($tz); return $output; } //Converts a time to 12 hour format if (!function_exists('time_to_12hr')) { function time_to_12hr($time) { return date("g:i A", strtotime($time)); // 5:02 } } //Converts a time to 24 hour format if (!function_exists('time_to_24hr')) { function time_to_24hr($time) { return date("G:i", strtotime($time)); // 17:02 } } function espresso_event_months_dropdown($current_value='') { global $wpdb; $strQuery = "select id, start_date from " . EVENTS_DETAIL_TABLE . " WHERE event_status != 'D' group by YEAR(start_date), MONTH(start_date) "; //$rsrcResult = mysql_query($strQuery); $data = $wpdb->get_results($strQuery, ARRAY_A); //print_r($data); if ($wpdb->num_rows > 0) { echo '"; } else { _e('No Results', 'event_espresso'); } }