/** Template function. Call this from your template to insert a list of * forthcoming events. Available template variables are: * - template_month: %MONTH% * - template_day: %MONTH% %DATE% %SINCE% (only with Time Since plugin) * - template_event: %DATE% %TIME% %LINK% %TITLE% %AUTHOR% */ function ec3_get_events($limit, $template_event = '<a href="%LINK%">%TITLE% (%TIME%)</a>', $template_day = '%DATE%:', $date_format = 'j F', $template_month = '', $month_format = 'F Y') { global $ec3, $wpdb, $tableposts, $tablepost2cat, $tableusers, $wp_version; if (!$date_format) { $date_format = get_settings('date_format'); } // Support older versions of Wordpress. if (ereg('^1[.]', $wp_version)) { $user_nicename = 'user_nickname'; } else { $user_nicename = 'user_nicename'; } // Start at midnight to show all of today's events $now = gmdate('Y-m-d 00:00:00'); $calendar_entries = $wpdb->get_results("SELECT\r\n p.id AS id,\r\n post_title,\r\n post_date,\r\n u.{$user_nicename} AS author\r\n FROM {$tableposts} p, {$tablepost2cat} p2c, {$tableusers} u\r\n WHERE post_status = 'publish'\r\n AND post_date_gmt > '{$now}'\r\n AND p.id = post_id\r\n AND p.post_author = u.id\r\n AND category_id = {$ec3->event_category}\r\n ORDER BY post_date\r\n LIMIT {$limit}"); echo "<ul class='event_list'>"; echo "<!-- Generated by Event Calendar v{$ec3->version} -->\n"; if (count($calendar_entries)) { $time_format = get_settings('time_format'); $current_date = false; $current_month = false; $data = array(); $time_now = time() + 60 * 60 * get_settings("gmt_offset"); foreach ($calendar_entries as $entry) { $data['MONTH'] = mysql2date($month_format, $entry->post_date); if ((!$current_month || $current_month != $data['MONTH']) && $template_month) { if ($current_month) { echo "</ul></li>\n"; } echo "<li class='event_list_month'>" . ec3_format_str($template_month, $data) . "\n<ul>\n"; $current_month = $data['MONTH']; } // To use %SINCE%, you need Dunstan's 'Time Since' plugin. if (function_exists('time_since')) { $data['SINCE'] = time_since($time_now, abs(strtotime($entry->post_date))); } $data['DATE'] = mysql2date($date_format, $entry->post_date); if ((!$current_date || $current_date != $data['DATE']) && $template_day) { if ($current_month || $current_date) { echo "</ul></li>\n"; } echo "<li class='event_list_day'>" . ec3_format_str($template_day, $data) . "\n<ul>\n"; $current_date = $data['DATE']; } $data['TIME'] = mysql2date($time_format, $entry->post_date); $data['TITLE'] = $entry->post_title; $data['LINK'] = get_permalink($entry->id); $data['AUTHOR'] = $entry->author; echo " <li>" . ec3_format_str($template_event, $data) . "</li>\n"; } if ($template_day || $template_month) { echo "</ul></li>\n"; } } else { echo "<li>" . __('No events.', 'ec3') . "</li>\n"; } echo "</ul>\n"; }
/** Template function, for backwards compatibility. * Call this from your template to insert a list of forthcoming events. * Available template variables are: * - template_day: %DATE% %SINCE% (only with Time Since plugin) * - template_event: %DATE% %TIME% %LINK% %TITLE% %AUTHOR% */ function ec3_get_events($limit, $template_event = EC3_DEFAULT_TEMPLATE_EVENT, $template_day = EC3_DEFAULT_TEMPLATE_DAY, $date_format = EC3_DEFAULT_DATE_FORMAT, $template_month = EC3_DEFAULT_TEMPLATE_MONTH, $month_format = EC3_DEFAULT_MONTH_FORMAT) { if (!ec3_check_installed(__('Upcoming Events', 'ec3'))) { return; } // Parse $limit: // NUMBER - limits number of posts // NUMBER days - next NUMBER of days $query = new WP_Query(); if (preg_match('/^ *([0-9]+) *d(ays?)?/', $limit, $matches)) { $query->query('ec3_listing=event&ec3_days=' . intval($matches[1])); } elseif (intval($limit) > 0) { $query->query('ec3_after=today&posts_per_page=' . intval($limit)); } elseif (intval($limit) < 0) { $query->query('ec3_before=today&order=asc&posts_per_page=' . abs(intval($limit))); } else { $query->query('ec3_after=today&posts_per_page=5'); } echo "<ul class='ec3_events'>"; echo '<!-- Generated by Event-Calendar v' . ec3_get_version() . ' -->' . "\n"; if ($query->have_posts()) { $current_month = false; $current_date = false; $data = array(); for ($evt = ec3_iter_all_events_q($query); $evt->valid(); $evt->next()) { $data['SINCE'] = ec3_get_since(); // Month changed? $data['MONTH'] = ec3_get_month($month_format); if ((!$current_month || $current_month != $data['MONTH']) && $template_month) { if ($current_date) { echo "</ul></li>\n"; } if ($current_month) { echo "</ul></li>\n"; } echo "<li class='ec3_list ec3_list_month'>" . ec3_format_str($template_month, $data) . "\n<ul>\n"; $current_month = $data['MONTH']; $current_date = false; } // Date changed? $data['DATE'] = ec3_get_date($date_format); if ((!$current_date || $current_date != $data['DATE']) && $template_day) { if ($current_date) { echo "</ul></li>\n"; } echo "<li class='ec3_list ec3_list_day'>" . ec3_format_str($template_day, $data) . "\n<ul>\n"; $current_date = $data['DATE']; } $data['TIME'] = ec3_get_start_time(); $data['TITLE'] = get_the_title(); $data['LINK'] = get_permalink(); $data['AUTHOR'] = get_the_author(); echo " <li>" . ec3_format_str($template_event, $data) . "</li>\n"; } if ($current_date) { echo "</ul></li>\n"; } if ($current_month) { echo "</ul></li>\n"; } } else { echo "<li>" . __('No events.', 'ec3') . "</li>\n"; } echo "</ul>\n"; }
/** Template function. Call this from your template to insert a list of * forthcoming events. Available template variables are: * - template_day: %DATE% %SINCE% (only with Time Since plugin) * - template_event: %DATE% %TIME% %LINK% %TITLE% %AUTHOR% */ function ec3_get_events($limit, $template_event = EC3_DEFAULT_TEMPLATE_EVENT, $template_day = EC3_DEFAULT_TEMPLATE_DAY, $date_format = EC3_DEFAULT_DATE_FORMAT, $template_month = EC3_DEFAULT_TEMPLATE_MONTH, $month_format = EC3_DEFAULT_MONTH_FORMAT) { if (!ec3_check_installed(__('Upcoming Events', 'ec3'))) { return; } global $ec3, $wpdb, $wp_version; // Parse $limit: // NUMBER - limits number of posts // NUMBER days - next NUMBER of days if (empty($limit)) { $limit_numposts = 'LIMIT 5'; } elseif (preg_match('/^ *([0-9]+) *d(ays?)?/', $limit, $matches)) { $secs = intval($matches[1]) * 24 * 3600; $and_before = "AND start<='" . ec3_strftime('%Y-%m-%d', time() + $secs) . "'"; } elseif (intval($limit) < 1) { $limit_numposts = 'LIMIT 5'; } else { $limit_numposts = 'LIMIT ' . intval($limit); } if (!$date_format) { $date_format = get_option('date_format'); } // Find the upcoming events. $calendar_entries = $wpdb->get_results("SELECT DISTINCT\r\n p.id AS id,\r\n post_title,\r\n start,\r\n u.{$ec3->wp_user_nicename} AS author,\r\n allday\r\n FROM {$ec3->schedule} s\r\n LEFT JOIN {$wpdb->posts} p ON s.post_id=p.id\r\n LEFT JOIN {$wpdb->users} u ON p.post_author = u.id\r\n WHERE p.post_status='publish'\r\n AND end>='{$ec3->today}' {$and_before}\r\n ORDER BY start {$limit_numposts}"); echo "<ul class='ec3_events'>"; echo "<!-- Generated by Event Calendar v{$ec3->version} -->\n"; if ($calendar_entries) { $time_format = get_option('time_format'); $current_month = false; $current_date = false; $data = array(); foreach ($calendar_entries as $entry) { // To use %SINCE%, you need Dunstan's 'Time Since' plugin. if (function_exists('time_since')) { $data['SINCE'] = time_since(time(), ec3_to_time($entry->start)); } // Month changed? $data['MONTH'] = mysql2date($month_format, $entry->start); if ((!$current_month || $current_month != $data['MONTH']) && $template_month) { if ($current_date) { echo "</ul></li>\n"; } if ($current_month) { echo "</ul></li>\n"; } echo "<li class='ec3_list ec3_list_month'>" . ec3_format_str($template_month, $data) . "\n<ul>\n"; $current_month = $data['MONTH']; $current_date = false; } // Date changed? $data['DATE'] = mysql2date($date_format, $entry->start); if ((!$current_date || $current_date != $data['DATE']) && $template_day) { if ($current_date) { echo "</ul></li>\n"; } echo "<li class='ec3_list ec3_list_day'>" . ec3_format_str($template_day, $data) . "\n<ul>\n"; $current_date = $data['DATE']; } if ($entry->allday) { $data['TIME'] = __('all day', 'ec3'); } else { $data['TIME'] = mysql2date($time_format, $entry->start); } $data['TITLE'] = htmlentities(stripslashes(strip_tags($entry->post_title)), ENT_QUOTES, get_option('blog_charset')); $data['LINK'] = get_permalink($entry->id); $data['AUTHOR'] = htmlentities($entry->author, ENT_QUOTES, get_option('blog_charset')); echo " <li>" . ec3_format_str($template_event, $data) . "</li>\n"; } if ($current_date) { echo "</ul></li>\n"; } if ($current_month) { echo "</ul></li>\n"; } } else { echo "<li>" . __('No events.', 'ec3') . "</li>\n"; } echo "</ul>\n"; }