function get_ua_webtide_member_notification() { // Will hold notification string $member_notification_str = NULL; // Are there any overriding notification? Get the most recent if (($member_notification = get_posts(array('post_type' => 'member_notifications', 'posts_per_page' => 1, 'meta_key' => 'override_other_notifications', 'meta_value' => 'yes', 'orderby' => 'post_date', 'order' => 'DESC', 'suppress_filters' => false))) && is_array($member_notification) && ($member_notification = reset($member_notification))) { // Set content $member_notification_str = isset($member_notification->post_content) ? $member_notification->post_content : NULL; } // If there's a webtide meeting today AND non-meeting event(s) // else if there's non-meeting event(s) today // Do we have a meeting today? That takes first priority if (!$member_notification_str && ($next_monthly_meeting = ua_webtide_get_next_monthly_meeting()) && ($start_date_str = isset($next_monthly_meeting->EventStartDate) ? $next_monthly_meeting->EventStartDate : NULL) && strtotime($start_date_str) !== false) { // Set the start date $start_date = new DateTime($start_date_str, new DateTimeZone('America/Chicago')); // What's the current date in our timezone? $current_date = new DateTime(NULL, new DateTimeZone('America/Chicago')); // What's the difference? if ($time_until_meeting = $current_date->diff($start_date)) { // Will lunch be served? $will_lunch_be_served = strcasecmp('yes', get_post_meta($next_monthly_meeting->ID, 'will_lunch_be_served', true)) == 0; // Build time string $meeting_start_time_str = $start_date->format('g'); // What are the minutes? $meeting_start_minute = $start_date->format('i'); // Don't include the minutes on the hour if ('00' != $meeting_start_minute) { $meeting_start_time_str .= ":{$meeting_start_minute}"; } // Add meridian $meeting_start_time_str .= $start_date->format(' a'); // Get the meeting title $meeting_title = get_the_title($next_monthly_meeting->ID); // Make sure the title has less 50 or less characters // Make sure it doesn't have 4 ellipses if (strlen($meeting_title) > 50) { $meeting_title = preg_replace('/[\\.]{4}$/i', '...', substr($meeting_title, 0, 50) . '...'); } // If it's this week... if (!$time_until_meeting->invert && $time_until_meeting->d < 4) { // Start with the closest notification first - its today! if ($time_until_meeting->d == 0 && $time_until_meeting->h < 12) { // Build the notification $member_notification_str = '<strong>IT\'S WEBTIDE DAY!</strong> We\'re looking forward to seeing everyone at ' . $meeting_start_time_str . ' for "<a href="' . get_permalink($next_monthly_meeting->ID) . '">' . $meeting_title . '</a>".'; // It's tomorrow... } else { if ($time_until_meeting->d == 0 || $time_until_meeting->d == 1 && $time_until_meeting->h < 12) { // Build the notification $member_notification_str = '<strong>IT\'S WEBTIDE WEEK!</strong> We\'re looking forward to seeing everyone tomorrow at ' . $meeting_start_time_str . ' for "<a href="' . get_permalink($next_monthly_meeting->ID) . '">' . $meeting_title . '</a>".'; // If it's this week... } else { // Build the notification $member_notification_str = '<strong>IT\'S WEBTIDE WEEK!</strong> We\'re looking forward to seeing everyone on ' . $start_date->format('l') . ' at ' . $meeting_start_time_str . ' for "<a href="' . get_permalink($next_monthly_meeting->ID) . '">' . $meeting_title . '</a>".'; } } // Add whether lunch will be served $member_notification_str .= ' <em><strong>Lunch will ' . (!$will_lunch_be_served ? ' not ' : NULL) . 'be served.</strong></em>'; } } } // If still no notification, get the most recent member notification if (!$member_notification_str && ($member_notification = get_posts(array('post_type' => 'member_notifications', 'posts_per_page' => 1, 'orderby' => 'post_date', 'order' => 'DESC', 'suppress_filters' => false))) && is_array($member_notification) && ($member_notification = reset($member_notification))) { // Set content $member_notification_str = isset($member_notification->post_content) ? $member_notification->post_content : NULL; } // If still no notification, and the user is myBama authenticated, show message about members if (!$member_notification_str && !IS_WEBTIDE_MEMBER && IS_MYBAMA_AUTHENTICATED) { $member_notification_str = '<strong>If you\'re a WebTide member</strong>, and seeing this message, it means you\'re not registered in our system. Please <a href="https://webtide.ua.edu/contact/">contact us</a> and let us know.'; } return apply_filters('ua_webtide_member_notification', $member_notification_str); }
/** * Outputs the content of the widget * * @param array $args * @param array $instance */ public function widget($args, $instance) { // Only for WebTide members if (!IS_WEBTIDE_MEMBER) { return; } // If we have a next meeting... if (!($next_meeting = ua_webtide_get_next_monthly_meeting())) { return; } // Make sure we have a start date if (!(($event_start_date_str = isset($next_meeting->EventStartDate) ? $next_meeting->EventStartDate : NULL) && strtotime($event_start_date_str) !== false)) { return; } // Set the start datetime $event_start_date = new DateTime($event_start_date_str, new DateTimeZone('America/Chicago')); // Get the current date/time in Central time $right_now = new DateTime(); $right_now->setTimeZone(new DateTimeZone('America/Chicago')); // Make sure its in the future if ($event_start_date < $right_now) { return; } // Are we viewing the next meeting? $viewing_next_meeting = is_single($next_meeting->ID); // If we're not a member and viewing it, don't print this if (!IS_WEBTIDE_MEMBER && $viewing_next_meeting) { return; } echo $args['before_widget']; echo $args['before_title'] . 'Our Next Meeting' . $args['after_title']; // If we're looking at it if (IS_WEBTIDE_MEMBER && $viewing_next_meeting) { ?> <p><strong>You're looking at it!</strong><?php // What's the difference $time_until_event = $right_now->diff($event_start_date); // It's today if (!$time_until_event->invert && $time_until_event->d <= 0) { ?> Looks like the meeting will start soon. We hope you'll join us!<?php } else { if (!$time_until_event->invert && $time_until_event->d <= 7) { ?> It's coming up soon. We hope you'll join us!<?php } } ?> </p><?php } else { echo ua_webtide_get_next_monthly_meeting_html(array('event_title_element' => 'h4', 'abbreviate_dt' => true, 'view_details' => false)); } echo $args['after_widget']; }
function ua_webtide_get_next_monthly_meeting_html($args = array()) { // Parse the args $defaults = array('event_title_element' => 'h3', 'abbreviate_dt' => false, 'include_excerpt' => false, 'view_details' => true, 'include_button' => false); $args = wp_parse_args($args, $defaults); // Build the next meeting $next_meeting_html = NULL; // Get the next meeting if ($next_meeting = ua_webtide_get_next_monthly_meeting()) { // Get the permalink $next_meeting_permalink = get_permalink($next_meeting->ID); // Print the event title $next_meeting_html .= '<' . $args['event_title_element'] . ' class="meeting-title"><a href="' . $next_meeting_permalink . '">' . get_the_title($next_meeting->ID) . '</a></' . $args['event_title_element'] . '>'; // Print the details $next_meeting_html .= '<p class="meeting-details">'; // Add members only message if (!IS_WEBTIDE_MEMBER) { $next_meeting_html .= '<span class="members-only">Monthly meetings are for WebTide members only.</span>'; } else { if ($speakers = get_field('speakers', $next_meeting->ID)) { // Add each speaker foreach ($speakers as $speaker) { // Make sure we have a name if (isset($speaker['speaker_name']) && !empty($speaker['speaker_name'])) { $next_meeting_html .= '<span class="meeting-speaker">'; // Print the speaker $next_meeting_html .= $speaker['speaker_name']; // If we have a "from" if (isset($speaker['speaker_from']) && !empty($speaker['speaker_from'])) { $next_meeting_html .= ", <em>{$speaker['speaker_from']}</em>"; } $next_meeting_html .= '</span>'; } } } // False = do not abbreviate stuff if ($dt_string = ua_webtide_get_date_time_string($next_meeting, false)) { $next_meeting_html .= '<span class="meeting-date-time">' . $dt_string . '</span>'; } // Get the venue if ($venue = tribe_get_venue()) { $next_meeting_html .= '<span class="meeting-location">' . $venue . '</span>'; } // Will lunch be served? if (($will_lunch_be_served = get_post_meta($next_meeting->ID, 'will_lunch_be_served', true)) && strcasecmp('yes', $will_lunch_be_served) == 0) { $next_meeting_html .= '<span class="lunch-will-be-served">Lunch will be served!</span>'; } } $next_meeting_html .= '</p>'; // If we're including the excerpt if ($args['include_excerpt']) { // Setup the text $raw_excerpt = $text = $next_meeting->post_excerpt; // If we have no excerpt... if ('' == $text && !empty($next_meeting->post_content)) { // Use content and strip shortcodes $text = strip_shortcodes($next_meeting->post_content); } // Take care of the text $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); // Get excerpt length $excerpt_length = 12; //apply_filters( 'excerpt_length', 10 ); // Filter the string in the "more" link displayed after a trimmed excerpt. $excerpt_more = apply_filters('excerpt_more', '...'); // Trim the text $text = wp_trim_words($text, $excerpt_length, $excerpt_more); // Filter the trimmed excerpt string. $text = apply_filters('wp_trim_excerpt', $text, $raw_excerpt); // Add to HTML if ($text) { $next_meeting_html .= wpautop($text); } } // Show view details link? if ($args['view_details']) { $next_meeting_html .= '<a class="meeting-view-details" href="' . $next_meeting_permalink . '">View details</a>'; } // Show button? if ($args['include_button']) { $next_meeting_html .= '<a class="button expand" href="' . $next_meeting_permalink . '">Learn more about the meeting</a>'; } } return $next_meeting_html; }