You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // Enable internationalisation $plugin_dir = basename(dirname(__FILE__)); load_plugin_textdomain('calendar', 'wp-content/plugins/' . $plugin_dir, $plugin_dir); // Define the tables used in Calendar global $wpdb; define('WP_CALENDAR_TABLE', $wpdb->prefix . 'calendar'); define('WP_CALENDAR_CONFIG_TABLE', $wpdb->prefix . 'calendar_config'); define('WP_CALENDAR_CATEGORIES_TABLE', $wpdb->prefix . 'calendar_categories'); // Check ensure calendar is installed and install it if not - required for // the successful operation of most functions called from this point on check_calendar(); // Create a master category for Calendar and its sub-pages add_action('admin_menu', 'calendar_menu'); // Enable the ability for the calendar to be loaded from pages add_filter('the_content', 'calendar_insert'); add_filter('the_content', 'minical_insert'); // Enable the ability for the lists to be loaded from pages add_filter('the_content', 'upcoming_insert'); add_filter('the_content', 'todays_insert'); // Add the function that puts style information in the header add_action('wp_head', 'calendar_wp_head'); // Add the function that deals with deleted users add_action('delete_user', 'deal_with_deleted_user'); // Add the widgets if we are using version 2.8 add_action('widgets_init', 'widget_init_calendar_today'); add_action('widgets_init', 'widget_init_calendar_upcoming');
function calendar() { global $wpdb; // First things first, make sure calendar is up to date check_calendar(); // Deal with the week not starting on a monday if (get_option('start_of_week') == 0) { $name_days = array(1 => __('Sunday', 'calendar'), __('Monday', 'calendar'), __('Tuesday', 'calendar'), __('Wednesday', 'calendar'), __('Thursday', 'calendar'), __('Friday', 'calendar'), __('Saturday', 'calendar')); } else { $name_days = array(1 => __('Monday', 'calendar'), __('Tuesday', 'calendar'), __('Wednesday', 'calendar'), __('Thursday', 'calendar'), __('Friday', 'calendar'), __('Saturday', 'calendar'), __('Sunday', 'calendar')); } // Carry on with the script $name_months = array(1 => __('January', 'calendar'), __('February', 'calendar'), __('March', 'calendar'), __('April', 'calendar'), __('May', 'calendar'), __('June', 'calendar'), __('July', 'calendar'), __('August', 'calendar'), __('September', 'calendar'), __('October', 'calendar'), __('November', 'calendar'), __('December', 'calendar')); // If we don't pass arguments we want a calendar that is relevant to today if (empty($_GET['month']) || empty($_GET['yr'])) { $c_year = date("Y"); $c_month = date("m"); $c_day = date("d"); } // Years get funny if we exceed 3000, so we use this check if ($_GET['yr'] <= 3000 && $_GET['yr'] >= 0) { // This is just plain nasty and all because of permalinks // which are no longer used, this will be cleaned up soon if ($_GET['month'] == 'jan' || $_GET['month'] == 'feb' || $_GET['month'] == 'mar' || $_GET['month'] == 'apr' || $_GET['month'] == 'may' || $_GET['month'] == 'jun' || $_GET['month'] == 'jul' || $_GET['month'] == 'aug' || $_GET['month'] == 'sept' || $_GET['month'] == 'oct' || $_GET['month'] == 'nov' || $_GET['month'] == 'dec') { // Again nasty code to map permalinks into something // databases can understand. This will be cleaned up $c_year = mysql_escape_string($_GET['yr']); if ($_GET['month'] == 'jan') { $t_month = 1; } else { if ($_GET['month'] == 'feb') { $t_month = 2; } else { if ($_GET['month'] == 'mar') { $t_month = 3; } else { if ($_GET['month'] == 'apr') { $t_month = 4; } else { if ($_GET['month'] == 'may') { $t_month = 5; } else { if ($_GET['month'] == 'jun') { $t_month = 6; } else { if ($_GET['month'] == 'jul') { $t_month = 7; } else { if ($_GET['month'] == 'aug') { $t_month = 8; } else { if ($_GET['month'] == 'sept') { $t_month = 9; } else { if ($_GET['month'] == 'oct') { $t_month = 10; } else { if ($_GET['month'] == 'nov') { $t_month = 11; } else { if ($_GET['month'] == 'dec') { $t_month = 12; } } } } } } } } } } } } $c_month = $t_month; $c_day = date("d"); } else { $c_year = date("Y"); $c_month = date("m"); $c_day = date("d"); } } else { $c_year = date("Y"); $c_month = date("m"); $c_day = date("d"); } // Fix the days of the week if week start is not on a monday if (get_option('start_of_week') == 0) { $first_weekday = date("w", mktime(0, 0, 0, $c_month, 1, $c_year)); $first_weekday = $first_weekday == 0 ? 1 : $first_weekday + 1; } else { $first_weekday = date("w", mktime(0, 0, 0, $c_month, 1, $c_year)); $first_weekday = $first_weekday == 0 ? 7 : $first_weekday; } $days_in_month = date("t", mktime(0, 0, 0, $c_month, 1, $c_year)); // Start the table and add the header and naviagtion $calendar_body .= ' <table cellspacing="1" cellpadding="0" class="calendar-table"> '; // We want to know if we should display the date switcher $date_switcher = $wpdb->get_var("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_jump'", 0, 0); if ($date_switcher == 'true') { $calendar_body .= '<tr> <td colspan="7" class="calendar-date-switcher"> <form method="GET" action="' . $_SERVER['REQUEST_URI'] . '"> '; $qsa = array(); parse_str($_SERVER['QUERY_STRING'], $qsa); foreach ($qsa as $name => $argument) { if ($name != 'month' && $name != 'yr') { $calendar_body .= '<input type="hidden" name="' . $name . '" value="' . $argument . '" /> '; } } function month_comparison($month) { $current_month = strtolower(date("M", time())); if (isset($_GET['yr']) && isset($_GET['month'])) { if ($month == $_GET['month']) { return ' selected="selected"'; } } elseif ($month == $current_month) { return ' selected="selected"'; } } // We build the months in the switcher $calendar_body .= ' ' . __('Month', 'calendar') . ': <select name="month" style="width:100px;"> <option value="jan"' . month_comparison('jan') . '>' . __('January', 'calendar') . '</option> <option value="feb"' . month_comparison('feb') . '>' . __('February', 'calendar') . '</option> <option value="mar"' . month_comparison('mar') . '>' . __('March', 'calendar') . '</option> <option value="apr"' . month_comparison('apr') . '>' . __('April', 'calendar') . '</option> <option value="may"' . month_comparison('may') . '>' . __('May', 'calendar') . '</option> <option value="jun"' . month_comparison('jun') . '>' . __('June', 'calendar') . '</option> <option value="jul"' . month_comparison('jul') . '>' . __('July', 'calendar') . '</option> <option value="aug"' . month_comparison('aug') . '>' . __('August', 'calendar') . '</option> <option value="sept"' . month_comparison('sept') . '>' . __('September', 'calendar') . '</option> <option value="oct"' . month_comparison('oct') . '>' . __('October', 'calendar') . '</option> <option value="nov"' . month_comparison('nov') . '>' . __('November', 'calendar') . '</option> <option value="dec"' . month_comparison('dec') . '>' . __('December', 'calendar') . '</option> </select> ' . __('Year', 'calendar') . ': <select name="yr" style="width:60px;"> '; // The year builder is string mania. If you can make sense of this, // you know your PHP! function year_comparison($year) { $current_year = strtolower(date("Y", time())); if (isset($_GET['yr']) && isset($_GET['month'])) { if ($year == $_GET['yr']) { return ' selected="selected"'; } } else { if ($year == $current_year) { return ' selected="selected"'; } } } $past = 30; $future = 30; $fut = 1; while ($past > 0) { $p .= ' <option value="'; $p .= date("Y", time()) - $past; $p .= '"' . year_comparison(date("Y", time()) - $past) . '>'; $p .= date("Y", time()) - $past . '</option> '; $past = $past - 1; } while ($fut < $future) { $f .= ' <option value="'; $f .= date("Y", time()) + $fut; $f .= '"' . year_comparison(date("Y", time()) + $fut) . '>'; $f .= date("Y", time()) + $fut . '</option> '; $fut = $fut + 1; } $calendar_body .= $p; $calendar_body .= ' <option value="' . date("Y", time()) . '"' . year_comparison(date("Y", time())) . '>' . date("Y", time()) . '</option> '; $calendar_body .= $f; $calendar_body .= '</select> <input type="submit" value="Go" /> </form> </td> </tr> '; } // The header of the calendar table and the links. Note calls to link functions $calendar_body .= '<tr> <td colspan="7" class="calendar-heading"> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td class="calendar-prev">' . prev_link($c_year, $c_month) . '</td> <td class="calendar-month">' . $name_months[(int) $c_month] . ' ' . $c_year . '</td> <td class="calendar-next">' . next_link($c_year, $c_month) . '</td> </tr> </table> </td> </tr> '; // Print the headings of the days of the week $calendar_body .= '<tr> '; for ($i = 1; $i <= 7; $i++) { // Colours need to be different if the starting day of the week is different if (get_option('start_of_week') == 0) { $calendar_body .= ' <td class="' . ($i < 7 && $i > 1 ? 'normal-day-heading' : 'weekend-heading') . '">' . $name_days[$i] . '</td> '; } else { $calendar_body .= ' <td class="' . ($i < 6 ? 'normal-day-heading' : 'weekend-heading') . '">' . $name_days[$i] . '</td> '; } } $calendar_body .= '</tr> '; for ($i = 1; $i <= $days_in_month;) { $calendar_body .= '<tr> '; for ($ii = 1; $ii <= 7; $ii++) { if ($ii == $first_weekday && $i == 1) { $go = TRUE; } elseif ($i > $days_in_month) { $go = FALSE; } if ($go) { // Colours again, this time for the day numbers if (get_option('start_of_week') == 0) { // This bit of code is for styles believe it or not. $grabbed_events = grab_events($c_year, $c_month, $i); $no_events_class = ''; if (!count($grabbed_events)) { $no_events_class = ' no-events'; } $calendar_body .= ' <td class="' . (date("Ymd", mktime(0, 0, 0, $c_month, $i, $c_year)) == date("Ymd") ? 'current-day' : 'day-with-date') . $no_events_class . '"><span ' . ($ii < 7 && $ii > 1 ? '' : 'class="weekend"') . '>' . $i++ . '</span><span class="event">' . draw_events($grabbed_events) . '</span></td> '; } else { $grabbed_events = grab_events($c_year, $c_month, $i); $no_events_class = ''; if (!count($grabbed_events)) { $no_events_class = ' no-events'; } $calendar_body .= ' <td class="' . (date("Ymd", mktime(0, 0, 0, $c_month, $i, $c_year)) == date("Ymd") ? 'current-day' : 'day-with-date') . $no_events_class . '"><span ' . ($ii < 6 ? '' : 'class="weekend"') . '>' . $i++ . '</span><span class="event">' . draw_events($grabbed_events) . '</span></td> '; } } else { $calendar_body .= ' <td class="day-without-date"> </td> '; } } $calendar_body .= '</tr> '; } $show_cat = $wpdb->get_var("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='enable_categories'", 0, 0); if ($show_cat == 'true') { $sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " ORDER BY category_name ASC"; $cat_details = $wpdb->get_results($sql); $calendar_body .= '<tr><td colspan="7"> <table class="cat-key"> <tr><td colspan="2"><strong>' . __('Category Key', 'calendar') . '</strong></td></tr> '; foreach ($cat_details as $cat_detail) { $calendar_body .= '<tr><td style="background-color:' . $cat_detail->category_colour . '; width:20px; height:20px;"></td><td>' . $cat_detail->category_name . '</td></tr>'; } $calendar_body .= '</table> </td></tr> '; } $calendar_body .= '</table> '; // A little link to yours truely. See the README if you wish to remove this $calendar_body .= '<div class="kjo-link" style="visibility:visible;display:block;"><p>' . __('Calendar developed and supported by ', 'calendar') . '<a href="http://www.kieranoshea.com">Kieran O\'Shea</a></p></div> '; // Phew! After that bit of string building, spit it all out. // The actual printing is done by the calling function. return $calendar_body; }