Exemple #1
0
/**
 * Display event archive.
 * 
 * @param 	array @args
 * @uses 	em_get_event_date_link()
 * @return 	mixed
 */
function em_display_event_archives($args = array())
{
    global $wp_locale;
    $defaults = array('display_as_dropdown' => false, 'show_post_count' => true, 'type' => 'monthly', 'order' => 'desc', 'limit' => 0);
    $args = apply_filters('em_display_event_archives_args', wp_parse_args($args, $defaults));
    $archives = $counts = array();
    $cut = $args['type'] === 'yearly' ? 4 : 7;
    $events = get_posts(array('post_type' => 'event', 'suppress_filters' => false, 'posts_per_page' => -1));
    foreach ($events as $event) {
        $startdatetime = get_post_meta($event->ID, '_event_start_date', true);
        $enddatetime = get_post_meta($event->ID, '_event_end_date', true);
        if (!empty($startdatetime)) {
            $start_ym = substr($startdatetime, 0, $cut);
            $archives[] = $start_ym;
            if (isset($counts[$start_ym])) {
                $counts[$start_ym]++;
            } else {
                $counts[$start_ym] = 1;
            }
        }
        if (!empty($enddatetime)) {
            $end_ym = substr($enddatetime, 0, $cut);
            $archives[] = $end_ym;
            if ($start_ym !== $end_ym) {
                if (isset($counts[$end_ym])) {
                    $counts[$end_ym]++;
                } else {
                    $counts[$end_ym] = 1;
                }
            }
        }
    }
    $archives = array_unique($archives, SORT_STRING);
    natsort($archives);
    $elem_m = $args['display_as_dropdown'] === true ? 'select' : 'ul';
    $elem_i = $args['display_as_dropdown'] === true ? '<option value="%s">%s%s</option>' : '<li><a href="%s">%s</a>%s</li>';
    $html = sprintf('<%s>', $elem_m);
    foreach (array_slice($args['order'] === 'desc' ? array_reverse($archives) : $archives, 0, $args['limit'] === 0 ? NULL : $args['limit']) as $archive) {
        if ($args['type'] === 'yearly') {
            $link = em_get_event_date_link($archive);
            $display = $archive;
        } else {
            $date = explode('-', $archive);
            $link = em_get_event_date_link($date[0], $date[1]);
            $display = $wp_locale->get_month($date[1]) . ' ' . $date[0];
        }
        $html .= sprintf($elem_i, $link, $display, $args['show_post_count'] === true ? ' (' . $counts[$archive] . ')' : '');
    }
    $html .= sprintf('</%s>', $elem_m);
    return $html;
}
Exemple #2
0
    /**
     * 
     */
    private function display_calendar($options, $start_date, $allevents, $widget_id, $ajax = false)
    {
        $show_occurrences = isset($options['show_occurrences']) ? $options['show_occurrences'] : Events_Maker()->options['general']['show_occurrences'];
        $days_events = array();
        foreach ($allevents as $id => $events) {
            if (!empty($events)) {
                foreach ($events as $event) {
                    // gets start date
                    $s_datetime = explode(' ', $show_occurrences ? $event->event_occurrence_start_date : $event->_event_start_date);
                    $s_date = explode('-', $s_datetime[0]);
                    // gets end date
                    $e_datetime = explode(' ', $show_occurrences ? $event->event_occurrence_end_date : $event->_event_end_date);
                    $e_date = explode('-', $e_datetime[0]);
                    if (count($s_date) === 3 && count($e_date) === 3) {
                        // same years and same months
                        if ($s_date[0] === $e_date[0] && $s_date[1] === $e_date[1]) {
                            for ($i = $s_date[2]; $i <= $e_date[2]; $i++) {
                                $days_events[(int) $i][] = $event;
                            }
                        } else {
                            if ($id === 'start') {
                                $no_days = date('t', strtotime($s_datetime[0]));
                                for ($i = $s_date[2]; $i <= $no_days; $i++) {
                                    $days_events[(int) $i][] = $event;
                                }
                            } else {
                                for ($i = $e_date[2]; $i >= 1; $i--) {
                                    $days_events[(int) $i][] = $event;
                                }
                            }
                        }
                    }
                }
            }
        }
        global $wp_locale;
        $weekdays = array(1 => 7, 2 => 6, 3 => 5, 4 => 4, 5 => 3, 6 => 2, 7 => 1, 8 => 0);
        $date = explode(' ', date('Y m j t', strtotime($start_date . '-02')));
        $month = (int) $date[1] - 1;
        $prev_month = ($a = $month - 1) === -1 ? 11 : $a;
        $prev_month_pad = str_pad($prev_month + 1, 2, '0', STR_PAD_LEFT);
        $next_month = ($month + 1) % 12;
        $next_month_pad = str_pad($next_month + 1, 2, '0', STR_PAD_LEFT);
        $first_day = (($first = date('w', strtotime(date($date[0] . '-' . $date[1] . '-01')))) === '0' ? 7 : $first) + (Events_Maker()->options['general']['first_weekday'] === 7 ? 1 : 0);
        $rel = $widget_id . '|';
        // Polylang and WPML compatibility
        if (defined('ICL_LANGUAGE_CODE')) {
            $rel .= ICL_LANGUAGE_CODE;
        }
        $html = '
		<div id="events-calendar-' . $widget_id . '" class="events-calendar-widget widget_calendar' . (isset($options['css_style']) && $options['css_style'] !== 'basic' ? ' ' . $options['css_style'] : '') . '" rel="' . $rel . '" ' . ($ajax === true ? 'style="display: none;"' : '') . '>
			<span class="active-month">' . $wp_locale->get_month($date[1]) . ' ' . $date[0] . '</span>
			<table class="nav-days">
				<thead>
					<tr>';
        for ($i = 1; $i <= 7; $i++) {
            $html .= '
						<th scope="col">' . $wp_locale->get_weekday_initial($wp_locale->get_weekday(Events_Maker()->options['general']['first_weekday'] === 7 ? $i !== 7 ? $i - 1 : 6 : ($i !== 7 ? $i : 0))) . '</th>';
        }
        $html .= '
					</tr>
				</thead>
				<tbody>';
        $weeks = (int) ceil(($date[3] - $weekdays[$first_day]) / 7) + 1;
        // sunday as first day?
        if (Events_Maker()->options['general']['first_weekday'] === 7 && $first_day === 8) {
            $first_day_sunday_week = true;
        } else {
            $first_day_sunday_week = false;
        }
        $now = date_parse(current_time('mysql'));
        $day = $k = 1;
        for ($i = 1; $i <= $weeks; $i++) {
            $row = '<tr>';
            for ($j = 1; $j <= 7; $j++) {
                $td_class = array();
                $real_day = (bool) ($k++ >= $first_day && $day <= $date[3]);
                if ($real_day === true && in_array($day, array_keys($days_events))) {
                    $td_class[] = 'active';
                }
                if ($day === $now['day'] && $month + 1 === $now['month'] && (int) $date[0] === $now['year']) {
                    $td_class[] = 'today';
                }
                if ($real_day === false) {
                    $td_class[] = 'pad';
                }
                if ($options['highlight_weekends'] === true && (Events_Maker()->options['general']['first_weekday'] === 1 && ($j === 6 || $j === 7)) || Events_Maker()->options['general']['first_weekday'] === 7 && ($j === 1 || $j === 7) && !in_array('pad', $td_class, true)) {
                    $td_class[] = 'weekend';
                }
                $row .= '<td' . (!empty($td_class) ? ' class="' . implode(' ', $td_class) . '"' : '') . '>';
                if ($real_day === true) {
                    if (in_array($day, array_keys($days_events))) {
                        $day_title = array();
                        foreach ($days_events[$day] as $day_event) {
                            $day_title[] = esc_html($day_event->post_title);
                        }
                        $day_content = '<a href="' . esc_url(em_get_event_date_link($date[0], $month + 1, $day)) . '" title="' . implode(', ', $day_title) . '">' . $day . '</a>';
                    } else {
                        $day_content = $day;
                    }
                    $row .= apply_filters('em_widget_calendar_single_day_html', $day_content, $day, $days_events);
                    $day++;
                } else {
                    $row .= '&nbsp';
                }
                $row .= '</td>';
            }
            $row .= '</tr>';
            if ($i === 1 && $first_day_sunday_week) {
                continue;
            } else {
                $html .= $row;
            }
        }
        $html .= '
				</tbody>
			</table>
			<table class="nav-months">
				<tr>
					<td class="prev-month" colspan="2">
						<a rel="' . ($prev_month === 11 ? $date[0] - 1 : $date[0]) . '-' . $prev_month_pad . '" href="#">&laquo; ' . apply_filters('em_calendar_month_name', $wp_locale->get_month($prev_month_pad)) . '</a>
					</td>
					<td class="ajax-spinner" colspan="1"><div></div></td>
					<td class="next-month" colspan="2">
						<a rel="' . ($next_month === 0 ? $date[0] + 1 : $date[0]) . '-' . $next_month_pad . '" href="#">' . apply_filters('em_calendar_month_name', $wp_locale->get_month($next_month_pad)) . ' &raquo;</a>
					</td>
				</tr>
			</table>
		</div>';
        return apply_filters('em_widget_calendar_html', $html);
    }
    /**
     * 
     */
    private function display_calendar($options, $start_date, $events, $widget_id, $ajax = false)
    {
        global $wp_locale;
        $weekdays = array(1 => 7, 2 => 6, 3 => 5, 4 => 4, 5 => 3, 6 => 2, 7 => 1);
        $date = explode(' ', date('Y m j t', strtotime($start_date . '-02')));
        $month = (int) $date[1] - 1;
        $prev_month = ($a = $month - 1) === -1 ? 11 : $a;
        $prev_month_pad = str_pad($prev_month + 1, 2, '0', STR_PAD_LEFT);
        $next_month = ($month + 1) % 12;
        $next_month_pad = str_pad($next_month + 1, 2, '0', STR_PAD_LEFT);
        $first_day = ($first = date('w', strtotime(date($date[0] . '-' . $date[1] . '-01')))) === '0' ? 7 : $first;
        $rel = $widget_id . '|';
        //Polylang and WPML compatibility
        if (defined('ICL_LANGUAGE_CODE')) {
            $rel .= ICL_LANGUAGE_CODE;
        }
        $html = '
		<div id="events-calendar-' . $widget_id . '" class="events-calendar-widget widget_calendar' . (isset($options['css_style']) && $options['css_style'] !== 'basic' ? ' ' . $options['css_style'] : '') . '" rel="' . $rel . '" ' . ($ajax === true ? 'style="display: none;"' : '') . '>
			<span class="active-month">' . $wp_locale->get_month($date[1]) . ' ' . $date[0] . '</span>
			<table class="nav-days">
				<thead>
					<tr>';
        for ($i = 1; $i <= 7; $i++) {
            $html .= '
						<th scope="col">' . $wp_locale->get_weekday_initial($wp_locale->get_weekday($i !== 7 ? $i : 0)) . '</th>';
        }
        $html .= '
					</tr>
				</thead>
				<tbody>';
        $weeks = ceil(($date[3] - $weekdays[$first_day]) / 7) + 1;
        $now = date_parse(current_time('mysql'));
        $day = $k = 1;
        for ($i = 1; $i <= $weeks; $i++) {
            $html .= '<tr>';
            for ($j = 1; $j <= 7; $j++) {
                $td_class = array();
                $real_day = (bool) ($k++ >= $first_day && $day <= $date[3]);
                if ($real_day === true && in_array($day, $events)) {
                    $td_class[] = 'active';
                }
                if ($day === $now['day'] && $month + 1 === $now['month'] && (int) $date[0] === $now['year']) {
                    $td_class[] = 'today';
                }
                if ($real_day === false) {
                    $td_class[] = 'pad';
                }
                if ($options['highlight_weekends'] === true && $j >= 6 && $j <= 7) {
                    $td_class[] = 'weekend';
                }
                $html .= '<td' . (!empty($td_class) ? ' class="' . implode(' ', $td_class) . '"' : '') . '>';
                if ($real_day === true) {
                    $html .= in_array($day, $events) ? '<a href="' . esc_url(em_get_event_date_link($date[0], $month + 1, $day)) . '">' . $day . '</a>' : $day;
                    $day++;
                } else {
                    $html .= '&nbsp';
                }
                $html .= '</td>';
            }
            $html .= '</tr>';
        }
        $html .= '
				</tbody>
			</table>
			<table class="nav-months">
				<tr>
					<td class="prev-month" colspan="2">
						<a rel="' . ($prev_month === 11 ? $date[0] - 1 : $date[0]) . '-' . $prev_month_pad . '" href="#">&laquo; ' . apply_filters('em_calendar_month_name', $wp_locale->get_month($prev_month_pad)) . '</a>
					</td>
					<td class="ajax-spinner" colspan="1"><div></div></td>
					<td class="next-month" colspan="2">
						<a rel="' . ($next_month === 0 ? $date[0] + 1 : $date[0]) . '-' . $next_month_pad . '" href="#">' . apply_filters('em_calendar_month_name', $wp_locale->get_month($next_month_pad)) . ' &raquo;</a>
					</td>
				</tr>
			</table>
		</div>';
        return $html;
    }
 /**
  * Adds new menu item to specified menu or removes it
  */
 public function update_menu($menu_id = NULL, $menu_item_title = '')
 {
     $menu_item_id = $this->options['general']['event_nav_menu']['item_id'];
     if (is_nav_menu_item($menu_item_id)) {
         $nav_menu_item = true;
         if ($menu_id === NULL) {
             wp_delete_post($menu_item_id, true);
             $menu_item_id = 0;
         }
     } else {
         $nav_menu_item = false;
         $menu_item_id = 0;
     }
     if (is_int($menu_id) && !empty($menu_id)) {
         if (($menu = wp_get_nav_menu_object($menu_id)) === false) {
             return false;
         }
         $menu_id = $menu->term_id;
         $menu_item_data = array('menu-item-title' => $menu_item_title, 'menu-item-url' => em_get_event_date_link(), 'menu-item-object' => 'event', 'menu-item-status' => $menu_id == 0 ? '' : 'publish', 'menu-item-type' => 'custom');
         if ($nav_menu_item === true) {
             $menu_item = wp_setup_nav_menu_item(get_post($menu_item_id));
             $menu_item_data['menu-item-parent-id'] = $menu_item->menu_item_parent;
             $menu_item_data['menu-item-position'] = $menu_item->menu_order;
         }
         $menu_item_id = wp_update_nav_menu_item($menu_id, $menu_item_id, $menu_item_data);
     }
     return $menu_item_id;
 }