public function build_specials_calendar() { global $wtd_plugin, $wtd_connector; $data = $wtd_connector->decrypt_parse_response($_POST['data']); $dates = array(); foreach ($data as $special) { $date = strtotime($special->date); if (empty($dates[date('Y-m-d', $date)])) { $dates[date('Y-m-d', $date)] = array($special); } else { $dates[date('Y-m-d', $date)][] = $special; } } $step = 24 * 60 * 60; $first_day = $_POST['year'] . '-' . $_POST['month'] . '-' . '1'; $first_timestamp = strtotime($first_day); $month = date('m', $first_timestamp); $start = strtotime(date($_POST['year'] . '-' . $_POST['month'] . '-1')); while (date('l', $start) != "Sunday") { $start = $start - $step; } $end = strtotime($_POST['year'] . '-' . $_POST['month'] . '-1'); $end = strtotime(date('Y-m-t', $end)); while (date('l', $end) != "Sunday") { $end = $end + $step; } $temp_time = $start; $month_days = array(); while ($temp_time < $end) { $month_days[date('Y-m-d', $temp_time)] = array(); if (!empty($dates[date('Y-m-d', $temp_time)])) { $month_days[date('Y-m-d', $temp_time)] = $dates[date('Y-m-d', $temp_time)]; } $temp_time += $step; } ob_start(); ?> <div class="month"> <div class="week"><?php $i = 0; $type = $wtd_plugin['calendar_type']; foreach ($month_days as $date => $specials) { $date_timestamp = strtotime($date); if ($i % 7 == 0 && $i != 0) { echo '</div><div class="week">'; } $results = $specials; switch ($type) { case 1: $images = '<div class="small-events" layout="column">'; $count = count($results); if (!empty($results)) { $images .= '<img src="' . wtd_get_image_url($results[0]->image) . '" class="main_thumb"/>'; } else { $count = "No"; } if ($count == 1) { $specials_text = $count . ' Special'; } elseif ($count == "No") { $specials_text = $count . ' Specials'; } else { $specials_text = 'See all ' . $count . ' Specials'; } $images .= '</div>'; break; case 2: $images = '<div class="small-events" layout="column">'; $count = count($results); if (!empty($results)) { for ($k = 0; $k < 4; $k++) { if (!empty($results[$k])) { $images .= '<img src="' . wtd_get_image_url($results[$k]->image) . '"/>'; } } } else { $count = "No"; } if ($count == 1) { $specials_text = $count . ' Special'; } elseif ($count == "No") { $specials_text = $count . ' Specials'; } else { $specials_text = 'See all ' . $count . ' Specials'; } $images .= '</div>'; break; case 3: default: $images = ''; $count = count($results); if (!empty($results)) { $images = '<div class="small-events" layout="column">'; $k = 0; foreach ($results as $key => $row) { $special_url = site_url() . '/' . $wtd_plugin['url_prefix'] . '/special/' . $row->id . '/' . sanitize_title($row->name) . '/'; if ($k == 3) { break; } $images .= '<a href="' . $special_url . '">· ' . $row->name . '</a>'; $k++; } $images .= '</div>'; } else { $count = "No"; } if ($count == 1) { $specials_text = $count . ' Special'; } elseif ($count == "No") { $specials_text = $count . ' Specials'; } else { $specials_text = 'See all ' . $count . ' Specials'; } break; } $not_month = ''; if ($month != date('m', $date_timestamp)) { $not_month = 'not_month '; } ?> <div class="<?php echo $not_month; ?> day type<?php echo $type; ?> " <?php echo empty($not_month) ? '' : 'hide-sm'; ?> flex layout="column" layout-padding><?php if ($count > 0) { ?> <div layout="column" title="See more specials" class="day-list" onclick="showDateDialog(event, <?php echo $date_timestamp; ?> )"><?php } else { ?> <div layout="column" title="No specials" class="day-list"><?php } ?> <span><em> <?php echo date('M jS', $date_timestamp); ?> </em></span><?php echo $images; ?> </div><?php if ($count > 0) { ?> <div flex hide-sm class="cal-day-footer" onclick="showDateDialog(event, <?php echo $date_timestamp; ?> )"> <span class="date-dialog-link"><?php echo $specials_text; ?> </span><?php } else { ?> <div flex hide-sm class="cal-day-footer" > <span class="date-dialog-link"><?php echo $specials_text; ?> </span><?php } ?> </div> </div><?php $i++; } ?> </div> </div><?php $html = ob_get_clean(); $time = $_POST['end']; // take two weeks off the end time as its a 5 week calendar to be sure its the current month $time = $time - 7 * 24 * 60 * 60 * 1000 * 2; // convert time from milliseconds to seconds $time = $time / 1000; $date = new DateTime('@' . $time); $return = array('html' => $html, 'current_month' => $date->format('F')); die(json_encode($return)); }
public function build_content() { global $wtd_connector; $data = $wtd_connector->decrypt_parse_response($_POST['data']); $event = $data->event; $addresses = $data->addresses; $vendor = $data->vendor; if (!empty($data->videos)) { $videos = $data->videos; } ob_start(); ?> <div class="wtd_single_event_container"> <div class="wtd_event_sc_event_list"> <div class="wtd_event_sc_top_content clearfix"> <div class="wtd_single_event_sc_image"> <img src="<?php echo wtd_get_image_url($event->logoUrl); ?> " alt="Vendor Image"/> </div><?php $this->utility->displayVideo($videos); ?> <hr/> <div class="wtd_single_event_sc_left_content"><?php $event_title = $event->name; if (!empty($event_title) && !empty($vendor->displayName) && !substr_count($event_title, $vendor->displayName)) { $event_title .= ', ' . $vendor->displayName; } elseif (!empty($vendor->displayName) && empty($event_title)) { $event_title = $vendor->displayName; } ?> <h2><?php echo $event_title; ?> </h2> <p><?php $eve_timestamp = strtotime($event->eventDate->iso); $eve_date = date('D, M j, Y', $eve_timestamp); echo '<strong>' . $eve_date . '</strong>'; ?> </p><?php if ($event->startTime != "00:00:00" && $event->startTime != "23:59:59" && !empty($event->startTime)) { ?> <p><?php $start = new DateTime(date('Y-m-d ' . $event->startTime)); ?> Start Time: <strong><?php echo $start->format('g:i a'); ?> </strong> </p><?php } if (!empty($event->description)) { ?> <p><?php echo $event->description; ?> </p><?php } ?> <p><strong>Contact Information:</strong><br /><?php if (!empty($event->phone)) { $strevent_phone = $event->phone; if (strlen($strevent_phone) == 10) { $event_phone = ' <a href="tel:' . $strevent_phone . '">(' . substr($strevent_phone, 0, 3) . ') ' . substr($strevent_phone, 3, 3) . '-' . substr($strevent_phone, 6) . '</a>'; } echo "Phone: " . $event_phone . "<br />"; } if (!empty($event->email) && filter_var($event->email, FILTER_VALIDATE_EMAIL)) { ?> Email Us @ <a href="mailto:<?php echo $event->email; ?> "><?php echo $event->email; ?> </a><br/><?php } if (!empty($event->website)) { ?> Visit Us at <a href="<?php echo substr_count($event->website, 'http://') ? $event->website : 'http://' . $event->website; ?> " target="_blank"><?php echo $event->website; ?> </a><br/><?php } ?> </p><?php if (!empty($addresses)) { foreach ($addresses as $address) { $location_display = $address->address; if (!empty($location_display) && !empty($address->city)) { $location_display .= ', ' . $address->city; } elseif (!empty($address->city)) { $location_display = $address->city; } if (!empty($location_display) && !empty($address->state)) { $location_display .= ', ' . $address->state; } elseif (!empty($address->state)) { $location_display = $address->state; } if (!empty($location_display) && !empty($address->postalCode)) { $location_display .= ' ' . $address->postalCode; } elseif (!empty($address->postalCode)) { $location_display = $address->postalCode; } echo '<p>' . $location_display . '</p>'; } } ?> </div> </div><?php $this->utility->displayGallery($data->images); ?> </div> </div><?php die(ob_get_clean()); }
public function build_calendar() { global $wtd_plugin, $wpdb, $wtd_connector; $event_post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wtd_special' LIMIT 1"); $post_url = get_permalink($event_post_id); //Data Mapping $data = $wtd_connector->decrypt_parse_response($_POST['data']); $dates = array(); foreach ($data as $event) { $date = strtotime($event->date); if (empty($dates[date('Y-m-d', $date)])) { $dates[date('Y-m-d', $date)] = array($event); } else { $dates[date('Y-m-d', $date)][] = $event; } } $step = 24 * 60 * 60; $first_day = $_POST['year'] . '-' . $_POST['month'] . '-' . '1'; $first_timestamp = strtotime($first_day); if ($_POST['month'] == 12) { $next_month = 1; $next_year = intval(date('Y', $first_timestamp)) + 1; $prev_month = 11; $prev_year = date('Y', $first_timestamp); } elseif ($_POST['month'] == 1) { $next_month = 2; $next_year = date('Y', $first_timestamp); $prev_month = 12; $prev_year = intval(date('Y', $first_timestamp)) - 1; } else { $next_month = $_POST['month'] + 1; $prev_month = $_POST['month'] - 1; $prev_year = $next_year = date('Y', $first_timestamp); } $next_month_name = date('F', strtotime($next_year . '-' . $next_month . '-1')); $prev_month_name = date('F', strtotime($prev_year . '-' . $prev_month . '-1')); $month = date('m', $first_timestamp); $start = strtotime(date($_POST['year'] . '-' . $_POST['month'] . '-1')); while (date('l', $start) != "Sunday") { $start = $start - $step; } $end = strtotime($_POST['year'] . '-' . $_POST['month'] . '-1'); $end = strtotime(date('Y-m-t', $end)); while (date('l', $end) != "Sunday") { $end = $end + $step; } $temp_time = $start; $month_days = array(); while ($temp_time < $end) { $month_days[date('Y-m-d', $temp_time)] = array(); if (!empty($dates[date('Y-m-d', $temp_time)])) { $month_days[date('Y-m-d', $temp_time)] = $dates[date('Y-m-d', $temp_time)]; } $temp_time += $step; } ob_start(); ?> <div class="wtd_row"><?php //Next Month $next_start = strtotime(date($next_year . '-' . $next_month . '-1')); while (date('l', $next_start) != "Sunday") { $next_start = $next_start - $step; } $next_end = strtotime($next_year . '-' . $next_month . '-1'); $next_end = strtotime(date('Y-m-t', $next_end)); while (date('l', $next_end) != "Sunday") { $next_end = $next_end + $step; } $next_start = date('c', $next_start); $next_end = date('c', $next_end); //Previous Month $prev_start = strtotime(date($prev_year . '-' . $prev_month . '-1')); while (date('l', $prev_start) != "Sunday") { $prev_start = $prev_start - $step; } $prev_end = strtotime($prev_year . '-' . $prev_month . '-1'); $prev_end = strtotime(date('Y-m-t', $prev_end)); while (date('l', $prev_end) != "Sunday") { $prev_end = $prev_end + $step; } $prev_start = date('c', $prev_start); $prev_end = date('c', $prev_end); $i = 0; $type = $wtd_plugin['specials_type']; foreach ($month_days as $date => $events) { $date_timemstamp = strtotime($date); if ($i % 7 == 0 && $i != 0) { echo '</div><div class="wtd_row">'; } $results = $events; $modal = ''; if (!count($results)) { $modal = 'nomodal'; } switch ($type) { case 1: $images = ''; if (!empty($results)) { $images = '<img src="' . wtd_get_image_url($results[0]->image) . '" class="main_thumb"/>'; } $events_text = count($results) . ' Specials'; break; case 2: $images = ''; if (!empty($results)) { for ($k = 0; $k < 4; $k++) { if (!empty($results[$k])) { $images .= '<img src="' . wtd_get_image_url($results[$k]->image) . '"/>'; } } } $events_text = count($results) . ' Specials'; break; case 3: $images = ''; $count = count($results); if (!empty($results)) { $images = '<div class="small-events">'; $k = 0; foreach ($results as $key => $row) { $event_url = $post_url . $row->id . '/' . sanitize_title($row->name); if ($k == 3) { break; } $images .= '<a href="' . $event_url . '">· ' . $row->name . '</a>'; $k++; } $images .= '</div>'; } $events_text = $count . ' Specials'; if (!count($results)) { $modal = 'nomodal'; } break; } $not_month = ''; if ($month != date('m', $date_timemstamp)) { $not_month = 'not_month'; } ?> <div data-i="<?php echo $i; ?> " data-date="<?php echo $date_timemstamp; ?> " class="day type<?php echo $type . ' ' . $not_month . ' ' . $modal; ?> "> <span class="current_date"><?php echo date('M jS', $date_timemstamp); ?> </span> <span><?php echo $events_text; ?> </span><?php echo $images; ?> </div><?php if (!$modal) { ?> <div id="modal_<?php echo $i; ?> " class="wtd_events_modal"> <div class="control"> <h2><?php echo date('l, jS F', $date_timemstamp); ?> </h2> <a href="javascript:void(0);">X</a> </div> <div class="contents"> <div class="wtd_row"><?php $j = 0; foreach ($results as $row) { $event_url = $post_url . $row->id . '/' . sanitize_title($row->name); if ($j % 5 == 0 && $j != 0) { echo '</div><div class="wtd_row">'; } ?> <a href="<?php echo $event_url; ?> " title="<?php echo $row->name; ?> "> <img src="<?php echo wtd_get_image_url($row->image); ?> " alt="<?php echo $row->name; ?> "/> <span class="wtd_event_modal"><?php echo $row->name; ?> <br/><?php echo $row->vendor; ?> </span> </a><?php $j++; } ?> </div> </div> </div><?php } $i++; } ?> </div><?php $html = ob_get_clean(); $return = array('html' => $html, 'prev_month' => $prev_month, 'prev_year' => $prev_year, 'prev_month_text' => '« ' . $prev_month_name, 'next_month' => $next_month, 'next_year' => $next_year, 'next_month_text' => $next_month_name . ' »', 'curent_month' => date('F Y', $first_timestamp), 'next_start' => $next_start, 'next_end' => $next_end, 'prev_start' => $prev_start, 'prev_end' => $prev_end); die(json_encode($return)); }