function eme_create_week_scope($count) { global $eme_timezone; $start_of_week = get_option('start_of_week'); $eme_date_obj = new ExpressiveDate(null, $eme_timezone); $eme_date_obj->setWeekStartDay($start_of_week); $scope = array(); $scope[0] = __('Select Week', 'eme'); for ($i = 0; $i < $count; $i++) { $limit_start = $eme_date_obj->copy()->startOfWeek()->format('Y-m-d'); $limit_end = $eme_date_obj->copy()->endOfWeek()->format('Y-m-d'); $this_scope = $limit_start . "--" . $limit_end; $scope_text = eme_localised_date($limit_start . " " . $eme_timezone) . " -- " . eme_localised_date($limit_end . " " . $eme_timezone); $scope[$this_scope] = $scope_text; $eme_date_obj->addOneWeek(); } return $scope; }
function eme_get_recurrence_days($recurrence) { global $eme_timezone; $matching_days = array(); $eme_date_obj = new ExpressiveDate(null, $eme_timezone); if ($recurrence['recurrence_freq'] == 'specific') { $specific_days = explode(",", $recurrence['recurrence_specific_days']); foreach ($specific_days as $day) { $eme_date_obj->setTimestampFromString($day); array_push($matching_days, $eme_date_obj->format('U')); } return $matching_days; } $start_date_obj = new ExpressiveDate($recurrence['recurrence_start_date'], $eme_timezone); $end_date_obj = new ExpressiveDate($recurrence['recurrence_end_date'], $eme_timezone); $last_week_start = array(25, 22, 25, 24, 25, 24, 25, 25, 24, 25, 24, 25); $weekdays = explode(",", $recurrence['recurrence_byday']); $counter = 0; $daycounter = 0; $weekcounter = 0; $monthcounter = 0; $start_monthday = $start_date_obj->format('j'); $cycle_date_obj = $start_date_obj->copy(); while ($cycle_date_obj->lessOrEqualTo($end_date_obj)) { $cycle_date = $cycle_date_obj->format('U'); $style = ""; $monthweek = floor(($cycle_date_obj->format('d') - 1) / 7) + 1; if ($recurrence['recurrence_freq'] == 'daily') { if ($daycounter % $recurrence['recurrence_interval'] == 0) { array_push($matching_days, $cycle_date); } } if ($recurrence['recurrence_freq'] == 'weekly') { if (!$recurrence['recurrence_byday'] && eme_iso_N_date_value($cycle_date_obj) == eme_iso_N_date_value($start_date_obj)) { // no specific days given, so we use 7 days as interval //if($daycounter % 7*$recurrence['recurrence_interval'] == 0 ) { if ($weekcounter % $recurrence['recurrence_interval'] == 0) { array_push($matching_days, $cycle_date); } } elseif (in_array(eme_iso_N_date_value($cycle_date_obj), $weekdays)) { // specific days, so we only check for those days if ($weekcounter % $recurrence['recurrence_interval'] == 0) { array_push($matching_days, $cycle_date); } } } if ($recurrence['recurrence_freq'] == 'monthly') { $monthday = $cycle_date_obj->format('j'); $month = $cycle_date_obj->format('n'); // if recurrence_byweekno=0 ==> means to use the startday as repeating day if ($recurrence['recurrence_byweekno'] == 0) { if ($monthday == $start_monthday) { if ($monthcounter % $recurrence['recurrence_interval'] == 0) { array_push($matching_days, $cycle_date); } $counter++; } } elseif (in_array(eme_iso_N_date_value($cycle_date_obj), $weekdays)) { if ($recurrence['recurrence_byweekno'] == -1 && $monthday >= $last_week_start[$month - 1]) { if ($monthcounter % $recurrence['recurrence_interval'] == 0) { array_push($matching_days, $cycle_date); } } elseif ($recurrence['recurrence_byweekno'] == $monthweek) { if ($monthcounter % $recurrence['recurrence_interval'] == 0) { array_push($matching_days, $cycle_date); } } $counter++; } } $cycle_date_obj->addOneDay(); $daycounter++; if ($daycounter % 7 == 0) { $weekcounter++; } if ($cycle_date_obj->format('j') == 1) { $monthcounter++; } } return $matching_days; }
function eme_delete_booking_form($event_id, $show_message = 1, $registered_only = 0) { global $current_user, $eme_timezone; $form_html = ""; $form_result_message = ""; $event = eme_get_event($event_id); // rsvp not active or no rsvp for this event, then return if (!eme_is_event_rsvp($event)) { return; } $registration_wp_users_only = $event['registration_wp_users_only']; if ($registration_wp_users_only) { // we require a user to be WP registered to be able to book if (!is_user_logged_in()) { return; } $readonly = "disabled='disabled'"; } else { $readonly = ""; } #$destination = eme_event_url($event)."#eme-rsvp-message"; if (isset($_GET['lang'])) { $language = eme_strip_tags($_GET['lang']); $destination = "?lang=" . $language . "#eme-rsvp-message"; } else { $destination = "#eme-rsvp-message"; } if (isset($_POST['eme_eventAction']) && $_POST['eme_eventAction'] == 'delete_booking' && isset($_POST['event_id'])) { $form_result_message = eme_cancel_seats($event); $eme_message_nonce = wp_create_nonce('eme_message' . $form_result_message); // post to a page showing the result of the booking // create the JS array that will be used to post $post_arr = array("eme_eventAction" => 'message', "eme_message" => $form_result_message); $post_string = json_encode($post_arr); ?> <script type="text/javascript"> function postwith (to,p) { var myForm = document.createElement("form"); myForm.method="post" ; myForm.action = to ; for (var k in p) { var myInput = document.createElement("input") ; myInput.setAttribute("name", k) ; myInput.setAttribute("value", p[k]); myForm.appendChild(myInput) ; } document.body.appendChild(myForm) ; myForm.submit() ; document.body.removeChild(myForm) ; } <?php echo "postwith('{$destination}',{$post_string});"; ?> </script> <?php return; } if (isset($_POST['eme_eventAction']) && $_POST['eme_eventAction'] == 'message' && isset($_POST['eme_message'])) { $form_result_message = eme_sanitize_html($_POST['eme_message']); } $event_rsvp_startdatetime = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone); $event_rsvp_enddatetime = new ExpressiveDate($event['event_end_date'] . " " . $event['event_end_time'], $eme_timezone); if ($event['event_properties']['rsvp_end_target'] == 'start') { $event_rsvp_datetime = $event_rsvp_startdatetime->copy(); } else { $event_rsvp_datetime = $event_rsvp_enddatetime->copy(); } $eme_date_obj_now = new ExpressiveDate(null, $eme_timezone); if ($event_rsvp_datetime->lessThan($eme_date_obj_now->copy()->modifyDays($event['rsvp_number_days'])->modifyHours($event['rsvp_number_hours'])) || $event_rsvp_enddatetime->lessOrEqualTo($eme_date_obj_now)) { if (!empty($form_result_message)) { $ret_string .= "<div class='eme-rsvp-message'>{$form_result_message}</div>"; } return $ret_string . "<div class='eme-rsvp-message'>" . __('Bookings no longer allowed on this date.', 'eme') . "</div></div>"; } if ($show_message && !empty($form_result_message)) { $form_html = "<div id='eme-rsvp-message'>"; $form_html .= "<div class='eme-rsvp-message'>{$form_result_message}</div>"; $form_html .= "</div>"; } $current_userid = get_current_user_id(); if (!$registered_only || $registered_only && is_user_logged_in() && eme_get_booking_ids_by_wp_id($current_userid, $event['event_id'])) { $form_html .= "<form id='booking-delete-form' name='booking-delete-form' method='post' action='{$destination}'>\n <input type='hidden' name='eme_eventAction' value='delete_booking' />\n <input type='hidden' name='event_id' value='{$event_id}' />"; $form_html .= wp_nonce_field('del_booking', 'eme_rsvp_nonce', false, false); $form_html .= eme_replace_cancelformfields_placeholders($event); $form_html .= "<span id='honeypot_check'>Keep this field blank: <input type='text' name='honeypot_check' value='' /></span>\n <p id='eme_mark_required_field'>" . __('(* marks a required field)', 'eme') . "</p>"; $form_html .= "</form>"; if (has_filter('eme_delete_booking_form_filter')) { $form_html = apply_filters('eme_delete_booking_form_filter', $form_html); } } return $form_html; }
function eme_get_events($o_limit = 0, $scope = "future", $order = "ASC", $o_offset = 0, $location_id = "", $category = "", $author = "", $contact_person = "", $show_ongoing = 1, $notcategory = "", $show_recurrent_events_once = 0, $extra_conditions = "") { global $wpdb, $eme_timezone; $events_table = $wpdb->prefix . EVENTS_TBNAME; $bookings_table = $wpdb->prefix . BOOKINGS_TBNAME; if (strpos($o_limit, "=")) { // allows the use of arguments $defaults = array('o_limit' => 0, 'scope' => 'future', 'order' => 'ASC', 'o_offset' => 0, 'location_id' => '', 'category' => '', 'author' => '', 'contact_person' => '', 'show_ongoing' => 1, 'notcategory' => '', 'show_recurrent_events_once' => 0, 'extra_conditions' => ''); $r = wp_parse_args($o_limit, $defaults); extract($r); } if ($o_limit === "") { $o_limit = get_option('eme_event_list_number_items'); } if ($o_limit > 0) { $limit = "LIMIT " . intval($o_limit); } else { $limit = ""; } if ($o_offset > 0) { if ($o_limit == 0) { $limit = "LIMIT " . intval($o_offset); } $offset = "OFFSET " . intval($o_offset); } else { $offset = ""; } if ($order != "DESC") { $order = "ASC"; } $eme_date_obj = new ExpressiveDate(null, $eme_timezone); $start_of_week = get_option('start_of_week'); $eme_date_obj->setWeekStartDay($start_of_week); $today = $eme_date_obj->getDate(); $this_time = $eme_date_obj->getTime(); $this_datetime = $eme_date_obj->getDateTime(); $conditions = array(); // extra sql conditions we put in front, most of the time this is the most // effective place if ($extra_conditions != "") { $conditions[] = $extra_conditions; } // if we're not in the admin itf, we don't want draft events if (!is_admin()) { if (is_user_logged_in()) { $conditions[] = "event_status IN (" . STATUS_PUBLIC . "," . STATUS_PRIVATE . ")"; } else { $conditions[] = "event_status=" . STATUS_PUBLIC; } if (get_option('eme_rsvp_hide_full_events')) { // COALESCE is used in case the SUM returns NULL // this is a correlated subquery, so the FROM clause should specify events_table again, so it will search in the outer query for events_table.event_id $conditions[] = "(event_rsvp=0 OR (event_rsvp=1 AND event_seats > (SELECT COALESCE(SUM(booking_seats),0) AS booked_seats FROM {$bookings_table} WHERE {$bookings_table}.event_id = {$events_table}.event_id)))"; } if (get_option('eme_rsvp_hide_rsvp_ended_events')) { $conditions[] = "(event_rsvp=0 OR (event_rsvp=1 AND (event_end_date < '{$today}' OR UNIX_TIMESTAMP(CONCAT(event_start_date,' ',event_start_time))-rsvp_number_days*60*60*24-rsvp_number_hours*60*60 > UNIX_TIMESTAMP()) ))"; } } if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}\$/", $scope)) { //$conditions[] = " event_start_date like '$scope'"; if ($show_ongoing) { $conditions[] = " ((event_start_date LIKE '{$scope}') OR (event_start_date <= '{$scope}' AND event_end_date >= '{$scope}'))"; } else { $conditions[] = " (event_start_date LIKE '{$scope}') "; } } elseif (preg_match("/^--([0-9]{4}-[0-9]{2}-[0-9]{2})\$/", $scope, $matches)) { $limit_start = $matches[1]; if ($show_ongoing) { $conditions[] = " (event_start_date < '{$limit_start}') "; } else { $conditions[] = " (event_end_date < '{$limit_start}') "; } } elseif (preg_match("/^\\+\\+([0-9]{4}-[0-9]{2}-[0-9]{2})\$/", $scope, $matches)) { $limit_start = $matches[1]; $conditions[] = " (event_start_date > '{$limit_start}') "; } elseif (preg_match("/^0000-([0-9]{2})\$/", $scope, $matches)) { $month = $matches[1]; $eme_date_obj->setMonth($month); $number_of_days_month = $eme_date_obj->getDaysInMonth(); $limit_start = "{$year}-{$month}-01"; $limit_end = "{$year}-{$month}-{$number_of_days_month}"; if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif ($scope == "this_week") { // this comes from global wordpress preferences $start_of_week = get_option('start_of_week'); $eme_date_obj->setWeekStartDay($start_of_week); $limit_start = $eme_date_obj->startOfWeek()->format('Y-m-d'); $limit_end = $eme_date_obj->endOfWeek()->format('Y-m-d'); if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif ($scope == "next_week") { // this comes from global wordpress preferences $start_of_week = get_option('start_of_week'); $eme_date_obj->setWeekStartDay($start_of_week); $eme_date_obj->addOneWeek(); $limit_start = $eme_date_obj->startOfWeek()->format('Y-m-d'); $limit_end = $eme_date_obj->endOfWeek()->format('Y-m-d'); if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif ($scope == "this_month") { $limit_start = $eme_date_obj->startOfMonth()->format('Y-m-d'); $limit_end = $eme_date_obj->endOfMonth()->format('Y-m-d'); if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif ($scope == "this_year") { $year = $eme_date_obj->getYear(); $limit_start = "{$year}-01-01"; $limit_end = "{$year}-12-31"; if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif ($scope == "next_month") { $eme_date_obj->addOneMonth(); $limit_start = $eme_date_obj->startOfMonth()->format('Y-m-d'); $limit_end = $eme_date_obj->endOfMonth()->format('Y-m-d'); if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif (preg_match("/^([0-9]{4}-[0-9]{2}-[0-9]{2})--([0-9]{4}-[0-9]{2}-[0-9]{2})\$/", $scope, $matches)) { $limit_start = $matches[1]; $limit_end = $matches[2]; if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif (preg_match("/^([0-9]{4}-[0-9]{2}-[0-9]{2})--today\$/", $scope, $matches)) { $limit_start = $matches[1]; $limit_end = $today; if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif (preg_match("/^today--([0-9]{4}-[0-9]{2}-[0-9]{2})\$/", $scope, $matches)) { $limit_start = $today; $limit_end = $matches[1]; if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif (preg_match("/^\\+(\\d+)d\$/", $scope, $matches)) { $days = $matches[1]; $limit_start = $today; $limit_end = $eme_date_obj->addDays($days)->getDate(); if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif (preg_match("/^\\-(\\d+)d\$/", $scope, $matches)) { $days = $matches[1]; $limit_start = $eme_date_obj->minusDays($days)->getDate(); $limit_end = $today; if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif (preg_match("/^(\\-?\\+?\\d+)d--(\\-?\\+?\\d+)d\$/", $scope, $matches)) { $day1 = $matches[1]; $day2 = $matches[2]; $limit_start = $eme_date_obj->copy()->modifyDays($day1)->getDate(); $limit_end = $eme_date_obj->copy()->modifyDays($day2)->getDate(); if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif (preg_match("/^relative\\-(\\d+)d--([0-9]{4}-[0-9]{2}-[0-9]{2})\$/", $scope, $matches)) { $days = $matches[1]; $limit_end = $matches[2]; $eme_date_obj->setTimestampFromString($limit_end . " " . $eme_timezone); $limit_start = $eme_date_obj->minusDays($days)->getDate() . " " . $eme_timezone; if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif (preg_match("/^([0-9]{4}-[0-9]{2}-[0-9]{2})--relative\\+(\\d+)d\$/", $scope, $matches)) { $limit_start = $matches[1]; $days = $matches[2]; $eme_date_obj->setTimestampFromString($limit_start . " " . $eme_timezone); $limit_end = $eme_date_obj->addDays($days)->getDate() . " " . $eme_timezone; if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif (preg_match("/^\\+(\\d+)m\$/", $scope, $matches)) { $months_in_future = $matches[1]++; $limit_start = $eme_date_obj->startOfMonth()->format('Y-m-d'); $eme_date_obj->addMonths($months_in_future); $limit_end = $eme_date_obj->endOfMonth()->format('Y-m-d'); if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif (preg_match("/^\\-(\\d+)m\$/", $scope, $matches)) { $months_in_past = $matches[1]++; $limit_start = $eme_date_obj->copy()->minusMonths($months_in_past)->startOfMonth()->format('Y-m-d'); $limit_end = $eme_date_obj->copy()->minusOneMonth()->endOfMonth()->format('Y-m-d'); if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif (preg_match("/^(\\-?\\+?\\d+)m--(\\-?\\+?\\d+)m\$/", $scope, $matches)) { $months1 = $matches[1]; $months2 = $matches[2]; $limit_start = $eme_date_obj->copy()->modifyMonths($months1)->startOfMonth()->format('Y-m-d'); $limit_end = $eme_date_obj->copy()->modifyMonths($months2)->endOfMonth()->format('Y-m-d'); if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif ($scope == "today--this_week") { $limit_start = $today; $limit_end = $eme_date_obj->endOfWeek()->format('Y-m-d'); if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif ($scope == "today--this_week_plus_one") { $limit_start = $today; $limit_end = $eme_date_obj->endOfWeek()->addOneDay()->format('Y-m-d'); if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif ($scope == "today--this_month") { $limit_start = $today; $limit_end = $eme_date_obj->endOfMonth()->format('Y-m-d'); if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif ($scope == "today--this_year") { $limit_start = $today; $limit_end = "{$year}-12-31"; if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif ($scope == "this_week--today") { $limit_start = $eme_date_obj->startOfWeek()->format('Y-m-d'); $limit_end = $today; if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif ($scope == "this_month--today") { $limit_start = $eme_date_obj->startOfMonth()->format('Y-m-d'); $limit_end = $today; if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif ($scope == "this_year--today") { $limit_start = "{$year}-01-01"; $limit_end = $today; if ($show_ongoing) { $conditions[] = " ((event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_end_date BETWEEN '{$limit_start}' AND '{$limit_end}') OR (event_start_date <= '{$limit_start}' AND event_end_date >= '{$limit_end}'))"; } else { $conditions[] = " (event_start_date BETWEEN '{$limit_start}' AND '{$limit_end}')"; } } elseif ($scope == "tomorrow--future") { if ($show_ongoing) { $conditions[] = " (event_start_date > '{$today}' OR (event_end_date > '{$today}' AND event_end_date != '0000-00-00' AND event_end_date IS NOT NULL))"; } else { $conditions[] = " (event_start_date > '{$today}')"; } } elseif ($scope == "past") { //$conditions[] = " (event_end_date < '$today' OR (event_end_date = '$today' and event_end_time < '$this_time' )) "; // not taking the hour into account until we can enter timezone info as well if ($show_ongoing) { $conditions[] = " event_end_date < '{$today}'"; } else { $conditions[] = " event_start_date < '{$today}'"; } } elseif ($scope == "today") { if ($show_ongoing) { $conditions[] = " (event_start_date = '{$today}' OR (event_start_date <= '{$today}' AND event_end_date >= '{$today}'))"; } else { $conditions[] = " (event_start_date = '{$today}')"; } } elseif ($scope == "tomorrow") { $tomorrow = $eme_date_obj->addOneDay()->getDate(); if ($show_ongoing) { $conditions[] = " (event_start_date = '{$tomorrow}' OR (event_start_date <= '{$tomorrow}' AND event_end_date >= '{$tomorrow}'))"; } else { $conditions[] = " (event_start_date = '{$tomorrow}')"; } } elseif ($scope == "ongoing") { // only shows ongoing events, for this we try to use the date and time, but it might be incorrect since there's no user timezone info $conditions[] = " (CONCAT(event_start_date,' ',event_start_time)<='{$this_datetime}' AND CONCAT(event_end_date,' ',event_end_time)>= '{$this_datetime}')"; } else { if ($scope != "all") { $scope = "future"; } if ($scope == "future") { //$conditions[] = " ((event_start_date = '$today' AND event_start_time >= '$this_time') OR (event_start_date > '$today') OR (event_end_date > '$today' AND event_end_date != '0000-00-00' AND event_end_date IS NOT NULL) OR (event_end_date = '$today' AND event_end_time >= '$this_time'))"; // not taking the hour into account until we can enter timezone info as well if ($show_ongoing) { $conditions[] = " (event_start_date >= '{$today}' OR (event_end_date >= '{$today}' AND event_end_date != '0000-00-00' AND event_end_date IS NOT NULL))"; } else { $conditions[] = " (event_start_date >= '{$today}')"; } } } // when used inside a location description, you can use this_location to indicate the current location being viewed if ($location_id == "this_location" && get_query_var('location_id')) { $location_id = get_query_var('location_id'); } if (is_numeric($location_id)) { if ($location_id > 0) { $conditions[] = " location_id = {$location_id}"; } } elseif ($location_id == "none") { $conditions[] = " location_id = ''"; } elseif (preg_match('/,/', $location_id)) { $location_ids = explode(',', $location_id); $location_conditions = array(); foreach ($location_ids as $loc) { if (is_numeric($loc) && $loc > 0) { $location_conditions[] = " location_id = {$loc}"; } elseif ($loc == "none") { $location_conditions[] = " location_id = ''"; } } $conditions[] = "(" . implode(' OR', $location_conditions) . ")"; } elseif (preg_match('/\\+/', $location_id)) { $location_ids = explode('+', $location_id); $location_conditions = array(); foreach ($location_ids as $loc) { if (is_numeric($loc) && $loc > 0) { $location_conditions[] = " location_id = {$loc}"; } } $conditions[] = "(" . implode(' AND', $location_conditions) . ")"; } elseif (preg_match('/ /', $location_id)) { // url decoding of '+' is ' ' $location_ids = explode(' ', $location_id); $location_conditions = array(); foreach ($location_ids as $loc) { if (is_numeric($loc) && $loc > 0) { $location_conditions[] = " location_id = {$loc}"; } } $conditions[] = "(" . implode(' AND', $location_conditions) . ")"; } if (get_option('eme_categories_enabled')) { if (is_numeric($category)) { if ($category > 0) { $conditions[] = " FIND_IN_SET({$category},event_category_ids)"; } } elseif ($category == "none") { $conditions[] = "event_category_ids = ''"; } elseif (preg_match('/,/', $category)) { $category = explode(',', $category); $category_conditions = array(); foreach ($category as $cat) { if (is_numeric($cat) && $cat > 0) { $category_conditions[] = " FIND_IN_SET({$cat},event_category_ids)"; } elseif ($cat == "none") { $category_conditions[] = " event_category_ids = ''"; } } $conditions[] = "(" . implode(' OR', $category_conditions) . ")"; } elseif (preg_match('/\\+/', $category)) { $category = explode('+', $category); $category_conditions = array(); foreach ($category as $cat) { if (is_numeric($cat) && $cat > 0) { $category_conditions[] = " FIND_IN_SET({$cat},event_category_ids)"; } } $conditions[] = "(" . implode(' AND ', $category_conditions) . ")"; } elseif (preg_match('/ /', $category)) { // url decoding of '+' is ' ' $category = explode(' ', $category); $category_conditions = array(); foreach ($category as $cat) { if (is_numeric($cat) && $cat > 0) { $category_conditions[] = " FIND_IN_SET({$cat},event_category_ids)"; } } $conditions[] = "(" . implode(' AND ', $category_conditions) . ")"; } } if (get_option('eme_categories_enabled')) { if (is_numeric($notcategory)) { if ($notcategory > 0) { $conditions[] = " NOT FIND_IN_SET({$notcategory},event_category_ids)"; } } elseif ($notcategory == "none") { $conditions[] = "event_category_ids != ''"; } elseif (preg_match('/,/', $notcategory)) { $notcategory = explode(',', $notcategory); $category_conditions = array(); foreach ($notcategory as $cat) { if (is_numeric($cat) && $cat > 0) { $category_conditions[] = " NOT FIND_IN_SET({$cat},event_category_ids)"; } elseif ($cat == "none") { $category_conditions[] = " event_category_ids != ''"; } } $conditions[] = "(" . implode(' OR', $category_conditions) . ")"; } elseif (preg_match('/\\+/', $notcategory)) { $notcategory = explode('+', $notcategory); $category_conditions = array(); foreach ($notcategory as $cat) { if (is_numeric($cat) && $cat > 0) { $category_conditions[] = " NOT FIND_IN_SET({$cat},event_category_ids)"; } } $conditions[] = "(" . implode(' AND ', $category_conditions) . ")"; } elseif (preg_match('/ /', $notcategory)) { // url decoding of '+' is ' ' $notcategory = explode(' ', $notcategory); $category_conditions = array(); foreach ($notcategory as $cat) { if (is_numeric($cat) && $cat > 0) { $category_conditions[] = " NOT FIND_IN_SET({$cat},event_category_ids)"; } } } } // now filter the author ID if ($author != '' && !preg_match('/,/', $author)) { $authinfo = get_user_by('login', $author); $conditions[] = " event_author = " . $authinfo->ID; } elseif (preg_match('/,/', $author)) { $authors = explode(',', $author); $author_conditions = array(); foreach ($authors as $authname) { $authinfo = get_user_by('login', $authname); $author_conditions[] = " event_author = " . $authinfo->ID; } $conditions[] = "(" . implode(' OR ', $author_conditions) . ")"; } // now filter the contact ID if ($contact_person != '' && !preg_match('/,/', $contact_person)) { $authinfo = get_user_by('login', $contact_person); $conditions[] = " event_contactperson_id = " . $authinfo->ID; } elseif (preg_match('/,/', $contact_person)) { $contact_persons = explode(',', $contact_person); $contact_person_conditions = array(); foreach ($contact_persons as $authname) { $authinfo = get_user_by('login', $authname); $contact_person_conditions[] = " event_contactperson_id = " . $authinfo->ID; } $conditions[] = "(" . implode(' OR ', $contact_person_conditions) . ")"; } // extra conditions for authors: if we're in the admin itf, return only the events for which you have the right to change anything $current_userid = get_current_user_id(); if (is_admin() && !current_user_can(get_option('eme_cap_edit_events')) && !current_user_can(get_option('eme_cap_list_events')) && current_user_can(get_option('eme_cap_author_event'))) { $conditions[] = "(event_author = {$current_userid} OR event_contactperson_id= {$current_userid})"; } $where = implode(" AND ", $conditions); if ($show_recurrent_events_once) { if ($where != "") { $where = " AND " . $where; } $sql = "SELECT * FROM {$events_table}\n WHERE (recurrence_id>0 {$where})\n group by recurrence_id union all\n SELECT * FROM {$events_table}\n WHERE (recurrence_id=0 {$where})\n ORDER BY event_start_date {$order} , event_start_time {$order}\n {$limit} \n {$offset}"; } else { if ($where != "") { $where = " WHERE " . $where; } $sql = "SELECT * FROM {$events_table}\n {$where}\n ORDER BY event_start_date {$order} , event_start_time {$order}\n {$limit} \n {$offset}"; } $wpdb->show_errors = true; $events = $wpdb->get_results($sql, ARRAY_A); $inflated_events = array(); if (!empty($events)) { //$wpdb->print_error(); foreach ($events as $this_event) { $this_event = eme_get_event_data($this_event); array_push($inflated_events, $this_event); } if (has_filter('eme_event_list_filter')) { $inflated_events = apply_filters('eme_event_list_filter', $inflated_events); } } return $inflated_events; }
public function testEndOfWeek() { $date = new ExpressiveDate('17 March 2013'); $date->setWeekStartDay(0); $this->assertEquals('2013/03/23', $date->copy()->endOfWeek()->format('Y/m/d')); $this->assertEquals('2013/03/23', $date->copy()->setDay(19)->endOfWeek()->format('Y/m/d')); $this->assertEquals('2013/03/23', $date->copy()->setDay(23)->endOfWeek()->format('Y/m/d')); $this->assertEquals('2013/03/30', $date->copy()->setDay(24)->endOfWeek()->format('Y/m/d')); $date = new ExpressiveDate('18 March 2013'); $date->setWeekStartDay(1); $this->assertEquals('2013/03/24', $date->copy()->setDay(18)->endOfWeek()->format('Y/m/d')); $this->assertEquals('2013/03/24', $date->copy()->setDay(24)->endOfWeek()->format('Y/m/d')); $this->assertEquals('2013/03/31', $date->copy()->setDay(25)->endOfWeek()->format('Y/m/d')); }