__( 'Display event calendar', 'am-events' )), array('width' => 400)); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { extract( $args ); global $post; /* User-selected settings. */ $title = apply_filters('widget_title', $instance['title'] ); $venue = $instance['venue']; $category = $instance['category']; /* Before widget (defined by themes). */ echo $before_widget; /* Title of widget (before and after defined by themes). */ if ( ! empty( $title ) ) echo $before_title . $title . $after_title; am_get_calendar(true,true,null,null); /* After widget (defined by themes). */ echo $after_widget; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ public function form( $instance ) { $defaults = array( 'title' => __('Upcoming Events', 'am-events'), 'category' => 'all', 'venue' => 'all', ); $instance = wp_parse_args( (array) $instance, $defaults ); $title = $instance[ 'title' ]; $category = $instance[ 'category' ]; $venue = $instance[ 'venue' ]; $args = array( 'hide_empty' => false ); $categories = get_terms('am_event_categories', $args); $venues = get_terms('am_venues', $args); ?>







get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')"); } elseif ( !empty($m) ) { $thisyear = ''.intval(substr($m, 0, 4)); if ( strlen($m) < 6 ) $thismonth = '01'; else $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2); } else { $thisyear = gmdate('Y', current_time('timestamp')); $thismonth = gmdate('m', current_time('timestamp')); } $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); $previous_year = gmdate('Y', strtotime('-1 month', current_time('timestamp'))); $previous_month = gmdate('m', strtotime('-1 month', current_time('timestamp'))); $next_year = gmdate('Y', strtotime('1 month', current_time('timestamp'))); $next_month = gmdate('m', strtotime('1 month', current_time('timestamp'))); /* translators: Calendar caption: 1: month name, 2: 4-digit year */ $calendar_caption = _x('%1$s %2$s', 'calendar caption'); $calendar_output = ''; $myweek = array(); for ( $wdcount=0; $wdcount<=6; $wdcount++ ) { $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7); } foreach ( $myweek as $wd ) { $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd); $wd = esc_attr($wd); $calendar_output .= "\n\t\t"; } $calendar_output .= ' '; $calendar_output .= "\n\t\t".''; $calendar_output .= "\n\t\t".''; $calendar_output .= "\n\t\t".''; $calendar_output .= ' '; $taxQuery = array( 'relation' => 'AND' ); /* Event category filter args */ if ($category) { $taxCategory = array( 'taxonomy' => 'am_event_categories', 'field' => 'slug', 'terms' => $category, ); $taxQuery[] = $taxCategory; } /* Venue filter args */ if ($venue) { $taxVenue = array( 'taxonomy' => 'am_venues', 'field' => 'slug', 'terms' => $venue, ); $taxQuery[] = $taxVenue; } $first_second_of_month = date("Y-$thismonth-01 00:00:00", current_time('timestamp')); $last_second_of_month = date("Y-$thismonth-t 23:59:59", current_time('timestamp')); /* WP_Query args */ $args = array( 'post_type' => 'am_event', // show only am_event cpt 'post_status' => 'publish', // show only published 'tax_query' => $taxQuery, 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'am_startdate', 'value' => $last_second_of_month, 'compare' => "<" ), array( 'key' => 'am_enddate', 'value' => $first_second_of_month, 'compare' => ">" ), ), ); if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false) $ak_title_separator = "\n"; else $ak_title_separator = ', '; $titles_for_day = array(); $query = new WP_Query( $args ); $events = $query->get_posts(); $titles_for_day = array(); if ( $events ) { foreach ( (array) $events as $event ) { /** This filter is documented in wp-includes/post-template.php */ $event_title = esc_attr( apply_filters( 'the_title', $event->post_title, $event->ID ) ); $start_day = intval(am_get_the_startdate('d', $event->ID)); $end_day = intval(am_get_the_enddate('d', $event->ID)); if ( empty($titles_for_day[$start_day]) ) $titles_for_day[$start_day] = ''.$event_title; else $titles_for_day[$start_day] .= $ak_title_separator . $event_title; if ( empty($titles_for_day[$end_day]) ) // first one $titles_for_day[$end_day] = ''.$event_title; else $titles_for_day[$end_day] .= $ak_title_separator . $event_title; } } // See how much we should pad in the beginning $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins); if ( 0 != $pad ) $calendar_output .= "\n\t\t".''; $daysinmonth = intval(date('t', $unixmonth)); for ( $day = 1; $day <= $daysinmonth; ++$day ) { if ( isset($newrow) && $newrow ) $calendar_output .= "\n\t\n\t\n\t\t"; $newrow = false; if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) ) $calendar_output .= ''; if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) ) $newrow = true; } $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins); if ( $pad != 0 && $pad != 7 ) $calendar_output .= "\n\t\t".''; $calendar_output .= "\n\t\n\t\n\t
' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '
$day_name
« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous_month)) . ' ' . $wp_locale->get_month_abbrev($wp_locale->get_month($next_month)) . ' »
 
'; else $calendar_output .= ''; if ( !empty($titles_for_day[$day] )) // any posts today? $calendar_output .= '$day"; else $calendar_output .= $day; $calendar_output .= ' 
"; $cache[ $key ] = $calendar_output; wp_cache_set( 'get_calendar', $cache, 'calendar' ); if ( $echo ) { /** * Filter the HTML calendar output. * * @since 3.0.0 * * @param string $calendar_output HTML output of the calendar. */ echo apply_filters( 'get_calendar', $calendar_output ); } else { /** This filter is documented in wp-includes/general-template.php */ return apply_filters( 'get_calendar', $calendar_output ); } } /** * This allows us to generate any archive link - plain, yearly, monthly, daily * * @param int $year * @param int $month (optional) * @param int $day (optional) * @return string */ function am_get_event_date_archive_link( $year, $month = 0, $day = 0 ) { global $wp_rewrite; $post_type_obj = get_post_type_object( 'am_event' ); $post_type_slug = $post_type_obj->rewrite['slug'] ? $post_type_obj->rewrite['slug'] : $post_type_obj->name; if( $day ) { // day archive link // set to today's values if not provided if ( !$year ) $year = gmdate('Y', current_time('timestamp')); if ( !$month ) $month = gmdate('m', current_time('timestamp')); $link = $wp_rewrite->get_day_permastruct(); } else if ( $month ) { // month archive link if ( !$year ) $year = gmdate('Y', current_time('timestamp')); $link = $wp_rewrite->get_month_permastruct(); } else { // year archive link $link = $wp_rewrite->get_year_permastruct(); } if ( !empty($link) ) { $link = str_replace('%year%', $year, $link); $link = str_replace('%monthnum%', zeroise(intval($month), 2), $link ); $link = str_replace('%day%', zeroise(intval($day), 2), $link ); return home_url( "$post_type_slug$link" ); } return home_url( "$post_type_slug" ); } ?>