| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Calendar |
| 4 |
Plugin URI: http://www.kieranoshea.com |
| 5 |
Description: This plugin allows you to display a calendar of all your events and appointments as a page on your site. |
| 6 |
Author: Kieran O'Shea |
| 7 |
Author URI: http://www.kieranoshea.com |
| 8 |
Text Domain: calendar |
| 9 |
Domain Path: /languages |
| 10 |
Version: 1.3.8 |
| 11 |
*/ |
| 12 |
|
| 13 |
/* Copyright 2008 Kieran O'Shea (email : kieran@kieranoshea.com) |
| 14 |
|
| 15 |
This program is free software; you can redistribute it and/or modify |
| 16 |
it under the terms of the GNU General Public License as published by |
| 17 |
the Free Software Foundation; either version 2 of the License, or |
| 18 |
(at your option) any later version. |
| 19 |
|
| 20 |
This program is distributed in the hope that it will be useful, |
| 21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
GNU General Public License for more details. |
| 24 |
|
| 25 |
You should have received a copy of the GNU General Public License |
| 26 |
along with this program; if not, write to the Free Software |
| 27 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 28 |
*/ |
| 29 |
|
| 30 |
// Enable internationalisation |
| 31 |
$plugin_dir = plugin_basename(dirname(__FILE__)); |
| 32 |
load_plugin_textdomain( 'calendar',false, $plugin_dir.'/languages'); |
| 33 |
|
| 34 |
// Define the tables used in Calendar |
| 35 |
global $wpdb; |
| 36 |
define('WP_CALENDAR_TABLE', $wpdb->prefix . 'calendar'); |
| 37 |
define('WP_CALENDAR_CONFIG_TABLE', $wpdb->prefix . 'calendar_config'); |
| 38 |
define('WP_CALENDAR_CATEGORIES_TABLE', $wpdb->prefix . 'calendar_categories'); |
| 39 |
|
| 40 |
// Check ensure calendar is installed and install it if not - required for |
| 41 |
// the successful operation of most functions called from this point on |
| 42 |
check_calendar(); |
| 43 |
|
| 44 |
// Create a master category for Calendar and its sub-pages |
| 45 |
add_action('admin_menu', 'calendar_menu'); |
| 46 |
|
| 47 |
// Enable the ability for the calendar to be loaded from pages |
| 48 |
add_filter('the_content','calendar_insert'); |
| 49 |
add_filter('the_content','minical_insert'); |
| 50 |
|
| 51 |
// Enable the ability for the lists to be loaded from pages |
| 52 |
add_filter('the_content','upcoming_insert'); |
| 53 |
add_filter('the_content','todays_insert'); |
| 54 |
|
| 55 |
// Add the function that puts style information in the header |
| 56 |
add_action('wp_head', 'calendar_wp_head'); |
| 57 |
|
| 58 |
// Add the function that deals with deleted users |
| 59 |
add_action('delete_user', 'deal_with_deleted_user'); |
| 60 |
|
| 61 |
// Add the widgets if we are using version 2.8 |
| 62 |
add_action('widgets_init', 'widget_init_calendar_today'); |
| 63 |
add_action('widgets_init', 'widget_init_calendar_upcoming'); |
| 64 |
add_action('widgets_init', 'widget_init_events_calendar'); |
| 65 |
|
| 66 |
// Add the short code |
| 67 |
add_shortcode( 'calendar', 'calendar_shortcode_insert' ); |
| 68 |
add_filter('widget_text', 'do_shortcode'); |
| 69 |
|
| 70 |
// Add feed functionality from separate file |
| 71 |
add_action( 'init', 'calendar_feed_init_internal' ); |
| 72 |
function calendar_feed_init_internal() |
| 73 |
{ |
| 74 |
add_rewrite_rule( 'calendar-feed$', 'index.php?calendar_feed=1', 'top' ); |
| 75 |
} |
| 76 |
|
| 77 |
add_filter( 'query_vars', 'calendar_feed_query_vars' ); |
| 78 |
function calendar_feed_query_vars( $query_vars ) |
| 79 |
{ |
| 80 |
$query_vars[] = 'calendar_feed'; |
| 81 |
return $query_vars; |
| 82 |
} |
| 83 |
|
| 84 |
add_action( 'parse_request', 'calendar_feed_parse_request' ); |
| 85 |
function calendar_feed_parse_request( &$wp ) |
| 86 |
{ |
| 87 |
if ( array_key_exists( 'calendar_feed', $wp->query_vars ) ) { |
| 88 |
global $wpdb; |
| 89 |
include 'calendar-feed.php'; |
| 90 |
exit(); |
| 91 |
} |
| 92 |
return; |
| 93 |
} |
| 94 |
|
| 95 |
// Function to deal with events posted by a user when that user is deleted |
| 96 |
function deal_with_deleted_user($id) |
| 97 |
{ |
| 98 |
global $wpdb; |
| 99 |
|
| 100 |
// Do the query |
| 101 |
$wpdb->get_results($wpdb->prepare("UPDATE ".WP_CALENDAR_TABLE." SET event_author=".$wpdb->get_var("SELECT MIN(ID) FROM ".$wpdb->prefix."users",0,0)." WHERE event_author=%d",$id)); |
| 102 |
} |
| 103 |
|
| 104 |
// Function to display a warning on the admin panel if the calendar plugin is mising setup |
| 105 |
add_action( 'admin_notices', 'calendar_setup_incomplete_warning' ); |
| 106 |
function calendar_setup_incomplete_warning() { |
| 107 |
global $wpdb; |
| 108 |
$incomplete_check = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='show_attribution_link'"); |
| 109 |
if (empty($incomplete_check) && !(isset($_GET['page']) && $_GET['page'] == 'calendar-config')) { |
| 110 |
$args = array( 'page' => 'calendar-config'); |
| 111 |
$url = add_query_arg( $args, admin_url( 'admin.php' ) ); |
| 112 |
?> |
| 113 |
<div class="update-nag"><p><strong><?php _e('Warning','calendar'); ?>:</strong> <?php _e("Calendar setup incomplete. Go to the <a href=\"$url\">calendar plugin settings</a> to complete setup.",'calendar'); ?></p></div> |
| 114 |
<?php |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
// Function to provide time with WordPress offset, localy replaces time() |
| 119 |
function ctwo() |
| 120 |
{ |
| 121 |
return (time()+(3600*(get_option('gmt_offset')))); |
| 122 |
} |
| 123 |
|
| 124 |
// Function to add the calendar style into the header |
| 125 |
function calendar_wp_head() |
| 126 |
{ |
| 127 |
global $wpdb; |
| 128 |
|
| 129 |
$style = $wpdb->get_var("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='calendar_style'"); |
| 130 |
if ($style != '') |
| 131 |
{ |
| 132 |
echo '<style type="text/css"> |
| 133 |
'; |
| 134 |
echo stripslashes($style).' |
| 135 |
'; |
| 136 |
echo '</style> |
| 137 |
'; |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
// Function to deal with adding the calendar menus |
| 142 |
function calendar_menu() |
| 143 |
{ |
| 144 |
global $wpdb; |
| 145 |
|
| 146 |
// Set admin as the only one who can use Calendar for security |
| 147 |
$allowed_group = 'manage_options'; |
| 148 |
|
| 149 |
// Use the database to *potentially* override the above if allowed |
| 150 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='can_manage_events'"); |
| 151 |
if (!empty($configs)) |
| 152 |
{ |
| 153 |
foreach ($configs as $config) |
| 154 |
{ |
| 155 |
$allowed_group = $config->config_value; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
// Add the admin panel pages for Calendar. Use permissions pulled from above |
| 160 |
if (function_exists('add_menu_page')) |
| 161 |
{ |
| 162 |
add_menu_page(__('Calendar','calendar'), __('Calendar','calendar'), $allowed_group, 'calendar', 'edit_calendar'); |
| 163 |
} |
| 164 |
if (function_exists('add_submenu_page')) |
| 165 |
{ |
| 166 |
$calendar_manage_menu = add_submenu_page('calendar', __('Manage Calendar','calendar'), __('Manage Calendar','calendar'), $allowed_group, 'calendar', 'edit_calendar'); |
| 167 |
add_action( "admin_head-".$calendar_manage_menu, 'calendar_add_javascript' ); |
| 168 |
// Note only admin can change calendar options |
| 169 |
add_submenu_page('calendar', __('Manage Categories','calendar'), __('Manage Categories','calendar'), 'manage_options', 'calendar-categories', 'manage_categories'); |
| 170 |
add_submenu_page('calendar', __('Calendar Config','calendar'), __('Calendar Options','calendar'), 'manage_options', 'calendar-config', 'edit_calendar_config'); |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
// Function to add the javascript to the admin header |
| 175 |
function calendar_add_javascript() |
| 176 |
{ |
| 177 |
echo '<script type="text/javascript" src="'; |
| 178 |
bloginfo('wpurl'); |
| 179 |
echo '/wp-content/plugins/calendar/javascript.js"></script> |
| 180 |
<style type="text/css"> |
| 181 |
.bcal-container{ |
| 182 |
background-color: #fff; |
| 183 |
border-radius: 4px; |
| 184 |
-moz-border-radius: 4px; |
| 185 |
-webkit-border-radius: 4px; |
| 186 |
float: left; |
| 187 |
padding: 5px; |
| 188 |
border: solid 1px #ccc; |
| 189 |
box-shadow: 0 0 3px #C0C0C0; |
| 190 |
} |
| 191 |
.bcal-table{ |
| 192 |
border-collapse: separate; |
| 193 |
border-spacing: 0; |
| 194 |
border: solid 1px #A2A6AF; |
| 195 |
font-family: Tahoma, sans-serif; |
| 196 |
font-size: 11px; |
| 197 |
font-weight: normal; |
| 198 |
float: left; |
| 199 |
margin: 1px; |
| 200 |
padding: 0; |
| 201 |
width: 200px; |
| 202 |
} |
| 203 |
.bcal-table, |
| 204 |
.bcal-table th, |
| 205 |
.bcal-table td { |
| 206 |
box-sizing: border-box; |
| 207 |
-moz-box-sizing: border-box; |
| 208 |
-webkit-box-sizing: border-box; |
| 209 |
} |
| 210 |
.bcal-table thead tr{ |
| 211 |
background-color: #CECED2; |
| 212 |
border: 1px solid #A2A6AF; |
| 213 |
background-image: linear-gradient(bottom, rgb(206,206,210) 37%, rgb(241,240,242) 69%); |
| 214 |
background-image: -o-linear-gradient(bottom, rgb(206,206,210) 37%, rgb(241,240,242) 69%); |
| 215 |
background-image: -moz-linear-gradient(bottom, rgb(206,206,210) 37%, rgb(241,240,242) 69%); |
| 216 |
background-image: -webkit-linear-gradient(bottom, rgb(206,206,210) 37%, rgb(241,240,242) 69%); |
| 217 |
background-image: -ms-linear-gradient(bottom, rgb(206,206,210) 37%, rgb(241,240,242) 69%); |
| 218 |
background-image: -webkit-gradient( |
| 219 |
linear, |
| 220 |
left bottom, |
| 221 |
left top, |
| 222 |
color-stop(0.37, rgb(206,206,210)), |
| 223 |
color-stop(0.69, rgb(241,240,242)) |
| 224 |
); |
| 225 |
} |
| 226 |
.bcal-table thead tr:first-child{ |
| 227 |
line-height: 23px; |
| 228 |
} |
| 229 |
.bcal-table thead th{ |
| 230 |
font-weight: bold; |
| 231 |
color: #404D5D; |
| 232 |
height: 20px; |
| 233 |
text-align: center; |
| 234 |
} |
| 235 |
.bcal-table tbody td{ |
| 236 |
color: #3B4959; |
| 237 |
cursor: pointer; |
| 238 |
font-weight: normal; |
| 239 |
height: 25px; |
| 240 |
padding: 0 0 1px 1px; |
| 241 |
width: 25px; |
| 242 |
text-align: center; |
| 243 |
} |
| 244 |
.bcal-table tbody tr:first-child td{ |
| 245 |
border-top: solid 1px #fff; |
| 246 |
} |
| 247 |
.bcal-table tbody td:first-child{ |
| 248 |
border-left: none; |
| 249 |
padding: 0 0 1px; |
| 250 |
} |
| 251 |
.bcal-table .bcal-wday, |
| 252 |
.bcal-table .bcal-wnum{ |
| 253 |
font-weight: normal; |
| 254 |
border-right: 1px solid #A2A6AF; |
| 255 |
border-top: 1px solid #A2A6AF; |
| 256 |
border-bottom: 1px solid #A2A6AF; |
| 257 |
padding: 1px 1px 2px 2px; |
| 258 |
} |
| 259 |
.bcal-table .bcal-wnum{ |
| 260 |
border-right: 1px solid #A2A6AF; |
| 261 |
border-bottom: 1px solid #A2A6AF; |
| 262 |
color: #CC6600; |
| 263 |
background-image: linear-gradient(bottom, rgb(255,225,159) 23%, rgb(255,250,234) 62%); |
| 264 |
background-image: -o-linear-gradient(bottom, rgb(255,225,159) 23%, rgb(255,250,234) 62%); |
| 265 |
background-image: -moz-linear-gradient(bottom, rgb(255,225,159) 23%, rgb(255,250,234) 62%); |
| 266 |
background-image: -webkit-linear-gradient(bottom, rgb(255,225,159) 23%, rgb(255,250,234) 62%); |
| 267 |
background-image: -ms-linear-gradient(bottom, rgb(255,225,159) 23%, rgb(255,250,234) 62%); |
| 268 |
background-image: -webkit-gradient( |
| 269 |
linear, |
| 270 |
left bottom, |
| 271 |
left top, |
| 272 |
color-stop(0.23, rgb(255,225,159)), |
| 273 |
color-stop(0.62, rgb(255,250,234)) |
| 274 |
); |
| 275 |
} |
| 276 |
.bcal-table .bcal-wday:last-child{ |
| 277 |
border-right: none; |
| 278 |
} |
| 279 |
.bcal-table .bcal-empty{ |
| 280 |
background-color: #F6F6F7; |
| 281 |
border-right: solid 1px #fff; |
| 282 |
border-bottom: solid 1px #fff; |
| 283 |
color: #999; |
| 284 |
cursor: default; |
| 285 |
} |
| 286 |
.bcal-table tr:last-child .bcal-empty, |
| 287 |
.bcal-table tr:last-child .bcal-week, |
| 288 |
.bcal-table tr:last-child .bcal-date{ |
| 289 |
border-bottom: none; |
| 290 |
} |
| 291 |
.bcal-table .bcal-date{ |
| 292 |
border-right: solid 1px #fff; |
| 293 |
border-bottom: solid 1px #fff; |
| 294 |
background-color: #ECECEE; |
| 295 |
} |
| 296 |
.bcal-table .bcal-past{ |
| 297 |
background-color: #e6e6e6; |
| 298 |
color: #999; |
| 299 |
cursor: default; |
| 300 |
} |
| 301 |
.bcal-table .bcal-today{ |
| 302 |
background-color: #D6D6D1; |
| 303 |
color: #333; |
| 304 |
} |
| 305 |
.bcal-table .bcal-week{ |
| 306 |
background-color: #FEF3DA; |
| 307 |
border-right: solid 1px #fff; |
| 308 |
border-bottom: solid 1px #fff; |
| 309 |
color: #CC6600; |
| 310 |
cursor: default; |
| 311 |
} |
| 312 |
.bcal-table .bcal-selected{ |
| 313 |
background-color: #BDBDBD; |
| 314 |
color: #F2F2F2; |
| 315 |
} |
| 316 |
.bcal-table .bcal-over, |
| 317 |
.bcal-table .bcal-date:hover{ |
| 318 |
background-color: #B2B2A9; |
| 319 |
color: #fff; |
| 320 |
} |
| 321 |
.bcal-table .bcal-date:last-child, |
| 322 |
.bcal-table .bcal-empty:last-child{ |
| 323 |
border-right: none; |
| 324 |
} |
| 325 |
.bcal-table .bcal-past:hover{ |
| 326 |
background-color: #e0e0e0; |
| 327 |
color: #666; |
| 328 |
} |
| 329 |
.bcal-table .bcal-month, |
| 330 |
.bcal-table .bcal-navi, |
| 331 |
.bcal-table .bcal-wnum, |
| 332 |
.bcal-table .bcal-wday, |
| 333 |
.bcal-table .bcal-week{ |
| 334 |
cursor: text; |
| 335 |
} |
| 336 |
</style> |
| 337 |
'; |
| 338 |
} |
| 339 |
|
| 340 |
// Function to deal with loading the calendar into pages |
| 341 |
function calendar_shortcode_insert($atts) { |
| 342 |
$a = shortcode_atts( array( |
| 343 |
'categories' => '', |
| 344 |
'type' => '' |
| 345 |
), $atts ); |
| 346 |
if ($a['categories'] == '') { |
| 347 |
if ($a['type'] == 'mini') { |
| 348 |
return minical(); |
| 349 |
} else { |
| 350 |
return calendar(); |
| 351 |
} |
| 352 |
} else { |
| 353 |
if ($a['type'] == 'mini') { |
| 354 |
return minical(); |
| 355 |
} else { |
| 356 |
return calendar( $a['categories'] ); |
| 357 |
} |
| 358 |
} |
| 359 |
} |
| 360 |
function calendar_insert($content) |
| 361 |
{ |
| 362 |
if (preg_match('/\{CALENDAR*.+\}/',$content)) |
| 363 |
{ |
| 364 |
$cat_list = preg_split('/\{CALENDAR\;/',$content); |
| 365 |
if (sizeof($cat_list) > 1) { |
| 366 |
$cat_list = preg_split('/\}/',$cat_list[1]); |
| 367 |
$cat_list = $cat_list[0]; |
| 368 |
$cal_output = calendar($cat_list); |
| 369 |
} else { |
| 370 |
$cal_output = calendar(); |
| 371 |
} |
| 372 |
$content = preg_replace('/\{CALENDAR*.+\}/',preg_replace('/\$(\d)/','\\\$$1',$cal_output),$content); |
| 373 |
} |
| 374 |
return $content; |
| 375 |
} |
| 376 |
|
| 377 |
// Function to show a mini calendar in pages |
| 378 |
function minical_insert($content) |
| 379 |
{ |
| 380 |
if (preg_match('/\{MINICAL*.+\}/',$content)) |
| 381 |
{ |
| 382 |
$cat_list= preg_split('/\{MINICAL\;/',$content); |
| 383 |
if (sizeof($cat_list) > 1) { |
| 384 |
$cat_list = preg_split('/\}/',$cat_list[1]); |
| 385 |
$cat_list= $cat_list[0]; |
| 386 |
$cal_output = minical($cat_list); |
| 387 |
} else { |
| 388 |
$cal_output = minical(); |
| 389 |
} |
| 390 |
$content = preg_replace('/\{MINICAL*.+\}/',preg_replace('/\$(\d)/','\\\$$1',$cal_output),$content); |
| 391 |
} |
| 392 |
return $content; |
| 393 |
} |
| 394 |
|
| 395 |
// Functions to allow the widgets to be inserted into posts and pages |
| 396 |
function upcoming_insert($content) |
| 397 |
{ |
| 398 |
if (preg_match('/\{UPCOMING_EVENTS*.+\}/',$content)) |
| 399 |
{ |
| 400 |
$cat_list= preg_split('/\{UPCOMING_EVENTS\;/',$content); |
| 401 |
if (sizeof($cat_list) > 1) { |
| 402 |
$cat_list = preg_split('/\}/',$cat_list[1]); |
| 403 |
$cat_list= $cat_list[0]; |
| 404 |
$cal_output = '<span class="page-upcoming-events">'.upcoming_events($cat_list).'</span>'; |
| 405 |
} else { |
| 406 |
$cal_output = '<span class="page-upcoming-events">'.upcoming_events().'</span>'; |
| 407 |
} |
| 408 |
$content = preg_replace('/\{UPCOMING_EVENTS*.+\}/',preg_replace('/\$(\d)/','\\\$$1',$cal_output),$content); |
| 409 |
} |
| 410 |
return $content; |
| 411 |
} |
| 412 |
function todays_insert($content) |
| 413 |
{ |
| 414 |
if (preg_match('/\{TODAYS_EVENTS*.+\}/',$content)) |
| 415 |
{ |
| 416 |
$cat_list= preg_split('/\{TODAYS_EVENTS\;/',$content); |
| 417 |
if (sizeof($cat_list) > 1) { |
| 418 |
$cat_list = preg_split('/\}/',$cat_list[1]); |
| 419 |
$cat_list= $cat_list[0]; |
| 420 |
$cal_output = '<span class="page-todays-events">'.todays_events($cat_list).'</span>'; |
| 421 |
} else { |
| 422 |
$cal_output = '<span class="page-todays-events">'.todays_events().'</span>'; |
| 423 |
} |
| 424 |
$content = preg_replace('/\{TODAYS_EVENTS*.+\}/',preg_replace('/\$(\d)/','\\\$$1',$cal_output),$content); |
| 425 |
} |
| 426 |
return $content; |
| 427 |
} |
| 428 |
|
| 429 |
// Function to check what version of Calendar is installed and install if needed |
| 430 |
function check_calendar() |
| 431 |
{ |
| 432 |
// Checks to make sure Calendar is installed, if not it adds the default |
| 433 |
// database tables and populates them with test data. If it is, then the |
| 434 |
// version is checked through various means and if it is not up to date |
| 435 |
// then it is upgraded. |
| 436 |
|
| 437 |
// Lets see if this is first run and create us a table if it is! |
| 438 |
global $wpdb, $initial_style; |
| 439 |
|
| 440 |
// Version info |
| 441 |
$calendar_version_option = 'calendar_version'; |
| 442 |
$calendar_version = '1.3.8'; |
| 443 |
|
| 444 |
// All this style info will go into the database on a new install |
| 445 |
// This looks nice in the TwentyTen theme |
| 446 |
$initial_style = " .calnk a:hover { |
| 447 |
background-position:0 0; |
| 448 |
text-decoration:none; |
| 449 |
color:#000000; |
| 450 |
border-bottom:1px dotted #000000; |
| 451 |
} |
| 452 |
.calnk a:visited { |
| 453 |
text-decoration:none; |
| 454 |
color:#000000; |
| 455 |
border-bottom:1px dotted #000000; |
| 456 |
} |
| 457 |
.calnk a { |
| 458 |
text-decoration:none; |
| 459 |
color:#000000; |
| 460 |
border-bottom:1px dotted #000000; |
| 461 |
} |
| 462 |
.calnk a span { |
| 463 |
display:none; |
| 464 |
} |
| 465 |
.calnk a:hover span { |
| 466 |
color:#333333; |
| 467 |
background:#F6F79B; |
| 468 |
display:block; |
| 469 |
position:absolute; |
| 470 |
margin-top:1px; |
| 471 |
padding:5px; |
| 472 |
width:150px; |
| 473 |
z-index:100; |
| 474 |
line-height:1.2em; |
| 475 |
} |
| 476 |
.calendar-table { |
| 477 |
border:0 !important; |
| 478 |
width:100% !important; |
| 479 |
border-collapse:separate !important; |
| 480 |
border-spacing:2px !important; |
| 481 |
} |
| 482 |
.calendar-heading { |
| 483 |
height:25px; |
| 484 |
text-align:center; |
| 485 |
background-color:#E4EBE3; |
| 486 |
} |
| 487 |
.calendar-next { |
| 488 |
width:20%; |
| 489 |
text-align:center; |
| 490 |
border:none; |
| 491 |
} |
| 492 |
.calendar-prev { |
| 493 |
width:20%; |
| 494 |
text-align:center; |
| 495 |
border:none; |
| 496 |
} |
| 497 |
.calendar-month { |
| 498 |
width:60%; |
| 499 |
text-align:center; |
| 500 |
font-weight:bold; |
| 501 |
border:none; |
| 502 |
} |
| 503 |
.normal-day-heading { |
| 504 |
text-align:center; |
| 505 |
width:25px; |
| 506 |
height:25px; |
| 507 |
font-size:0.8em; |
| 508 |
border:1px solid #DFE6DE; |
| 509 |
background-color:#EBF2EA; |
| 510 |
} |
| 511 |
.weekend-heading { |
| 512 |
text-align:center; |
| 513 |
width:25px; |
| 514 |
height:25px; |
| 515 |
font-size:0.8em; |
| 516 |
border:1px solid #DFE6DE; |
| 517 |
background-color:#EBF2EA; |
| 518 |
color:#FF0000; |
| 519 |
} |
| 520 |
.day-with-date { |
| 521 |
vertical-align:text-top; |
| 522 |
text-align:left; |
| 523 |
width:60px; |
| 524 |
height:60px; |
| 525 |
border:1px solid #DFE6DE; |
| 526 |
} |
| 527 |
.no-events { |
| 528 |
|
| 529 |
} |
| 530 |
.day-without-date { |
| 531 |
width:60px; |
| 532 |
height:60px; |
| 533 |
border:1px solid #E9F0E8; |
| 534 |
} |
| 535 |
span.weekend { |
| 536 |
color:#FF0000; |
| 537 |
} |
| 538 |
.current-day { |
| 539 |
vertical-align:text-top; |
| 540 |
text-align:left; |
| 541 |
width:60px; |
| 542 |
height:60px; |
| 543 |
border:1px solid #BFBFBF; |
| 544 |
background-color:#E4EBE3; |
| 545 |
} |
| 546 |
span.event { |
| 547 |
font-size:0.75em; |
| 548 |
} |
| 549 |
.kjo-link { |
| 550 |
font-size:0.75em; |
| 551 |
text-align:center; |
| 552 |
} |
| 553 |
.calendar-date-switcher { |
| 554 |
height:25px; |
| 555 |
text-align:center; |
| 556 |
border:1px solid #D6DED5; |
| 557 |
background-color:#E4EBE3; |
| 558 |
} |
| 559 |
.calendar-date-switcher form { |
| 560 |
margin:2px; |
| 561 |
} |
| 562 |
.calendar-date-switcher input { |
| 563 |
border:1px #D6DED5 solid; |
| 564 |
margin:0; |
| 565 |
} |
| 566 |
.calendar-date-switcher input[type=submit] { |
| 567 |
padding:3px 10px; |
| 568 |
} |
| 569 |
.calendar-date-switcher select { |
| 570 |
border:1px #D6DED5 solid; |
| 571 |
margin:0; |
| 572 |
} |
| 573 |
.calnk a:hover span span.event-title { |
| 574 |
padding:0; |
| 575 |
text-align:center; |
| 576 |
font-weight:bold; |
| 577 |
font-size:1.2em; |
| 578 |
margin-left:0px; |
| 579 |
} |
| 580 |
.calnk a:hover span span.event-title-break { |
| 581 |
width:96%; |
| 582 |
text-align:center; |
| 583 |
height:1px; |
| 584 |
margin-top:5px; |
| 585 |
margin-right:2%; |
| 586 |
padding:0; |
| 587 |
background-color:#000000; |
| 588 |
margin-left:0px; |
| 589 |
} |
| 590 |
.calnk a:hover span span.event-content-break { |
| 591 |
width:96%; |
| 592 |
text-align:center; |
| 593 |
height:1px; |
| 594 |
margin-top:5px; |
| 595 |
margin-right:2%; |
| 596 |
padding:0; |
| 597 |
background-color:#000000; |
| 598 |
margin-left:0px; |
| 599 |
} |
| 600 |
.page-upcoming-events { |
| 601 |
font-size:80%; |
| 602 |
} |
| 603 |
.page-todays-events { |
| 604 |
font-size:80%; |
| 605 |
} |
| 606 |
.calendar-table table,tbody,tr,td { |
| 607 |
margin:0 !important; |
| 608 |
padding:0 !important; |
| 609 |
} |
| 610 |
table.calendar-table { |
| 611 |
margin-bottom:5px !important; |
| 612 |
} |
| 613 |
.cat-key { |
| 614 |
width:100%; |
| 615 |
margin-top:30px; |
| 616 |
padding:5px; |
| 617 |
border:0 !important; |
| 618 |
} |
| 619 |
.cal-separate { |
| 620 |
border:0 !important; |
| 621 |
margin-top:10px; |
| 622 |
} |
| 623 |
table.cat-key { |
| 624 |
margin-top:5px !important; |
| 625 |
border:1px solid #DFE6DE !important; |
| 626 |
border-collapse:separate !important; |
| 627 |
border-spacing:4px !important; |
| 628 |
margin-left:2px !important; |
| 629 |
width:99.5% !important; |
| 630 |
margin-bottom:5px !important; |
| 631 |
} |
| 632 |
.minical-day { |
| 633 |
background-color:#F6F79B; |
| 634 |
} |
| 635 |
.cat-key td { |
| 636 |
border:0 !important; |
| 637 |
}"; |
| 638 |
|
| 639 |
if (get_option($calendar_version_option) != $calendar_version) { |
| 640 |
// Assume this is not a new install until we prove otherwise |
| 641 |
$new_install = false; |
| 642 |
$vone_point_one_upgrade = false; |
| 643 |
$vone_point_two_beta_upgrade = false; |
| 644 |
|
| 645 |
$wp_calendar_exists = false; |
| 646 |
$wp_calendar_config_exists = false; |
| 647 |
$wp_calendar_config_version_number_exists = false; |
| 648 |
|
| 649 |
// Determine the calendar version |
| 650 |
$tables = $wpdb->get_results("show tables"); |
| 651 |
foreach ($tables as $table) { |
| 652 |
foreach ($table as $value) { |
| 653 |
if ($value == WP_CALENDAR_TABLE) { |
| 654 |
$wp_calendar_exists = true; |
| 655 |
} |
| 656 |
if ($value == WP_CALENDAR_CONFIG_TABLE) { |
| 657 |
$wp_calendar_config_exists = true; |
| 658 |
|
| 659 |
// We now try and find the calendar version number |
| 660 |
// This will be a lot easier than finding other stuff |
| 661 |
// in the future. |
| 662 |
$version_number = $wpdb->get_var("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='calendar_version'"); |
| 663 |
if ($version_number == "1.2") { |
| 664 |
$wp_calendar_config_version_number_exists = true; |
| 665 |
} |
| 666 |
} |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
if ($wp_calendar_exists == false && $wp_calendar_config_exists == false) { |
| 671 |
$new_install = true; |
| 672 |
} else if ($wp_calendar_exists == true && $wp_calendar_config_exists == false) { |
| 673 |
$vone_point_one_upgrade = true; |
| 674 |
} else if ($wp_calendar_exists == true && $wp_calendar_config_exists == true && $wp_calendar_config_version_number_exists == false) { |
| 675 |
$vone_point_two_beta_upgrade = true; |
| 676 |
} |
| 677 |
|
| 678 |
// Now we've determined what the current install is or isn't |
| 679 |
// we perform operations according to the findings |
| 680 |
if ($new_install == true) { |
| 681 |
$sql = "CREATE TABLE " . WP_CALENDAR_TABLE . " ( |
| 682 |
event_id INT(11) NOT NULL AUTO_INCREMENT , |
| 683 |
event_begin DATE NOT NULL , |
| 684 |
event_end DATE NOT NULL , |
| 685 |
event_title VARCHAR(30) NOT NULL , |
| 686 |
event_desc TEXT NOT NULL , |
| 687 |
event_time TIME , |
| 688 |
event_recur CHAR(1) , |
| 689 |
event_repeats INT(3) , |
| 690 |
event_author BIGINT(20) UNSIGNED , |
| 691 |
event_category BIGINT(20) UNSIGNED NOT NULL DEFAULT 1 , |
| 692 |
event_link TEXT , |
| 693 |
PRIMARY KEY (event_id) |
| 694 |
)"; |
| 695 |
$wpdb->get_results($sql); |
| 696 |
$sql = "CREATE TABLE " . WP_CALENDAR_CONFIG_TABLE . " ( |
| 697 |
config_item VARCHAR(30) NOT NULL , |
| 698 |
config_value TEXT NOT NULL , |
| 699 |
PRIMARY KEY (config_item) |
| 700 |
)"; |
| 701 |
$wpdb->get_results($sql); |
| 702 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='can_manage_events', config_value='edit_posts'"; |
| 703 |
$wpdb->get_results($sql); |
| 704 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='calendar_style', config_value='" . $initial_style . "'"; |
| 705 |
$wpdb->get_results($sql); |
| 706 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='display_author', config_value='false'"; |
| 707 |
$wpdb->get_results($sql); |
| 708 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='display_jump', config_value='false'"; |
| 709 |
$wpdb->get_results($sql); |
| 710 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='display_todays', config_value='true'"; |
| 711 |
$wpdb->get_results($sql); |
| 712 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='display_upcoming', config_value='true'"; |
| 713 |
$wpdb->get_results($sql); |
| 714 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='display_upcoming_days', config_value=7"; |
| 715 |
$wpdb->get_results($sql); |
| 716 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='calendar_version', config_value='1.2'"; |
| 717 |
$wpdb->get_results($sql); |
| 718 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='enable_categories', config_value='false'"; |
| 719 |
$wpdb->get_results($sql); |
| 720 |
$sql = "CREATE TABLE " . WP_CALENDAR_CATEGORIES_TABLE . " ( |
| 721 |
category_id INT(11) NOT NULL AUTO_INCREMENT, |
| 722 |
category_name VARCHAR(30) NOT NULL , |
| 723 |
category_colour VARCHAR(30) NOT NULL , |
| 724 |
PRIMARY KEY (category_id) |
| 725 |
)"; |
| 726 |
$wpdb->get_results($sql); |
| 727 |
$sql = "INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_id=1, category_name='General', category_colour='#F6F79B'"; |
| 728 |
$wpdb->get_results($sql); |
| 729 |
} else if ($vone_point_one_upgrade == true) { |
| 730 |
$sql = "ALTER TABLE " . WP_CALENDAR_TABLE . " ADD COLUMN event_author BIGINT(20) UNSIGNED"; |
| 731 |
$wpdb->get_results($sql); |
| 732 |
$sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_author=" . $wpdb->get_var("SELECT MIN(ID) FROM " . $wpdb->prefix . "users", 0, 0); |
| 733 |
$wpdb->get_results($sql); |
| 734 |
$sql = "ALTER TABLE " . WP_CALENDAR_TABLE . " MODIFY event_desc TEXT NOT NULL"; |
| 735 |
$wpdb->get_results($sql); |
| 736 |
$sql = "CREATE TABLE " . WP_CALENDAR_CONFIG_TABLE . " ( |
| 737 |
config_item VARCHAR(30) NOT NULL , |
| 738 |
config_value TEXT NOT NULL , |
| 739 |
PRIMARY KEY (config_item) |
| 740 |
)"; |
| 741 |
$wpdb->get_results($sql); |
| 742 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='can_manage_events', config_value='edit_posts'"; |
| 743 |
$wpdb->get_results($sql); |
| 744 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='calendar_style', config_value='" . $initial_style . "'"; |
| 745 |
$wpdb->get_results($sql); |
| 746 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='display_author', config_value='false'"; |
| 747 |
$wpdb->get_results($sql); |
| 748 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='display_jump', config_value='false'"; |
| 749 |
$wpdb->get_results($sql); |
| 750 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='display_todays', config_value='true'"; |
| 751 |
$wpdb->get_results($sql); |
| 752 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='display_upcoming', config_value='true'"; |
| 753 |
$wpdb->get_results($sql); |
| 754 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='display_upcoming_days', config_value=7"; |
| 755 |
$wpdb->get_results($sql); |
| 756 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='calendar_version', config_value='1.2'"; |
| 757 |
$wpdb->get_results($sql); |
| 758 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='enable_categories', config_value='false'"; |
| 759 |
$wpdb->get_results($sql); |
| 760 |
$sql = "ALTER TABLE " . WP_CALENDAR_TABLE . " ADD COLUMN event_category BIGINT(20) UNSIGNED NOT NULL DEFAULT 1"; |
| 761 |
$wpdb->get_results($sql); |
| 762 |
$sql = "ALTER TABLE " . WP_CALENDAR_TABLE . " ADD COLUMN event_link TEXT"; |
| 763 |
$wpdb->get_results($sql); |
| 764 |
$sql = "CREATE TABLE " . WP_CALENDAR_CATEGORIES_TABLE . " ( |
| 765 |
category_id INT(11) NOT NULL AUTO_INCREMENT, |
| 766 |
category_name VARCHAR(30) NOT NULL , |
| 767 |
category_colour VARCHAR(30) NOT NULL , |
| 768 |
PRIMARY KEY (category_id) |
| 769 |
)"; |
| 770 |
$wpdb->get_results($sql); |
| 771 |
$sql = "INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_id=1, category_name='General', category_colour='#F6F79B'"; |
| 772 |
$wpdb->get_results($sql); |
| 773 |
} else if ($vone_point_two_beta_upgrade == true) { |
| 774 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='calendar_version', config_value='1.2'"; |
| 775 |
$wpdb->get_results($sql); |
| 776 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='enable_categories', config_value='false'"; |
| 777 |
$wpdb->get_results($sql); |
| 778 |
$sql = "ALTER TABLE " . WP_CALENDAR_TABLE . " ADD COLUMN event_category BIGINT(20) UNSIGNED NOT NULL DEFAULT 1"; |
| 779 |
$wpdb->get_results($sql); |
| 780 |
$sql = "ALTER TABLE " . WP_CALENDAR_TABLE . " ADD COLUMN event_link TEXT "; |
| 781 |
$wpdb->get_results($sql); |
| 782 |
$sql = "CREATE TABLE " . WP_CALENDAR_CATEGORIES_TABLE . " ( |
| 783 |
category_id INT(11) NOT NULL AUTO_INCREMENT, |
| 784 |
category_name VARCHAR(30) NOT NULL , |
| 785 |
category_colour VARCHAR(30) NOT NULL , |
| 786 |
PRIMARY KEY (category_id) |
| 787 |
)"; |
| 788 |
$wpdb->get_results($sql); |
| 789 |
$sql = "INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_id=1, category_name='General', category_colour='#F6F79B'"; |
| 790 |
$wpdb->get_results($sql); |
| 791 |
$sql = "UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value='" . $initial_style . "' WHERE config_item='calendar_style'"; |
| 792 |
$wpdb->get_results($sql); |
| 793 |
} |
| 794 |
// We've installed/upgraded now, just need to ensure the correct charsets |
| 795 |
$wpdb->get_results("ALTER TABLE " . WP_CALENDAR_TABLE . " CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci"); |
| 796 |
$wpdb->get_results("ALTER TABLE " . WP_CALENDAR_CONFIG_TABLE . " CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci"); |
| 797 |
$wpdb->get_results("ALTER TABLE " . WP_CALENDAR_CATEGORIES_TABLE . " CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci"); |
| 798 |
|
| 799 |
// We have feed for the first time, add the config option |
| 800 |
if ($calendar_version == '1.3.8') { |
| 801 |
$sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='enable_feed', config_value='false'"; |
| 802 |
$wpdb->get_results($sql); |
| 803 |
} |
| 804 |
|
| 805 |
// Mark the version as latest |
| 806 |
update_option($calendar_version_option, $calendar_version, 'yes'); |
| 807 |
} |
| 808 |
} |
| 809 |
|
| 810 |
// Used on the manage events admin page to display a list of events |
| 811 |
function wp_events_display_list(){ |
| 812 |
|
| 813 |
global $wpdb; |
| 814 |
|
| 815 |
$events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " ORDER BY event_begin DESC"); |
| 816 |
|
| 817 |
if ( !empty($events) ) |
| 818 |
{ |
| 819 |
?> |
| 820 |
<table class="widefat page fixed" width="100%" cellpadding="3" cellspacing="3"> |
| 821 |
<thead> |
| 822 |
<tr> |
| 823 |
<th class="manage-column" scope="col"><?php _e('ID','calendar') ?></th> |
| 824 |
<th class="manage-column" scope="col"><?php _e('Title','calendar') ?></th> |
| 825 |
<th class="manage-column" scope="col"><?php _e('Start Date','calendar') ?></th> |
| 826 |
<th class="manage-column" scope="col"><?php _e('End Date','calendar') ?></th> |
| 827 |
<th class="manage-column" scope="col"><?php _e('Time','calendar') ?></th> |
| 828 |
<th class="manage-column" scope="col"><?php _e('Recurs','calendar') ?></th> |
| 829 |
<th class="manage-column" scope="col"><?php _e('Repeats','calendar') ?></th> |
| 830 |
<th class="manage-column" scope="col"><?php _e('Author','calendar') ?></th> |
| 831 |
<th class="manage-column" scope="col"><?php _e('Category','calendar') ?></th> |
| 832 |
<th class="manage-column" scope="col"><?php _e('Edit','calendar') ?></th> |
| 833 |
<th class="manage-column" scope="col"><?php _e('Delete','calendar') ?></th> |
| 834 |
</tr> |
| 835 |
</thead> |
| 836 |
<?php |
| 837 |
$class = ''; |
| 838 |
foreach ( $events as $event ) |
| 839 |
{ |
| 840 |
$class = ($class == 'alternate') ? '' : 'alternate'; |
| 841 |
?> |
| 842 |
<tr class="<?php echo $class; ?>"> |
| 843 |
<th scope="row"><?php echo stripslashes($event->event_id); ?></th> |
| 844 |
<td><?php echo stripslashes($event->event_title); ?></td> |
| 845 |
<td><?php echo stripslashes($event->event_begin); ?></td> |
| 846 |
<td><?php echo stripslashes($event->event_end); ?></td> |
| 847 |
<td><?php if ($event->event_time == '00:00:00') { echo __('N/A','calendar'); } else { echo stripslashes($event->event_time); } ?></td> |
| 848 |
<td> |
| 849 |
<?php |
| 850 |
// Interpret the DB values into something human readable |
| 851 |
if ($event->event_recur == 'S') { echo __('Never','calendar'); } |
| 852 |
else if ($event->event_recur == 'W') { echo __('Weekly','calendar'); } |
| 853 |
else if ($event->event_recur == 'M') { echo __('Monthly (date)','calendar'); } |
| 854 |
else if ($event->event_recur == 'U') { echo __('Monthly (day)','calendar'); } |
| 855 |
else if ($event->event_recur == 'Y') { echo __('Yearly','calendar'); } |
| 856 |
?> |
| 857 |
</td> |
| 858 |
<td> |
| 859 |
<?php |
| 860 |
// Interpret the DB values into something human readable |
| 861 |
if ($event->event_recur == 'S') { echo __('N/A','calendar'); } |
| 862 |
else if ($event->event_repeats == 0) { echo __('Forever','calendar'); } |
| 863 |
else if ($event->event_repeats > 0) { echo stripslashes($event->event_repeats).' '.__('Times','calendar'); } |
| 864 |
?> |
| 865 |
</td> |
| 866 |
<td><?php $e = get_userdata($event->event_author); echo $e->display_name; ?></td> |
| 867 |
<?php |
| 868 |
$sql = $wpdb->prepare("SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=%d",$event->event_category); |
| 869 |
$this_cat = $wpdb->get_row($sql); |
| 870 |
?> |
| 871 |
<td style="background-color:<?php echo stripslashes($this_cat->category_colour);?>;"><?php echo stripslashes($this_cat->category_name); ?></td> |
| 872 |
<?php unset($this_cat); ?> |
| 873 |
<td><a href="<?php echo bloginfo('wpurl') ?>/wp-admin/admin.php?page=calendar&action=edit&event_id=<?php echo stripslashes($event->event_id);?>" class='edit'><?php echo __('Edit','calendar'); ?></a></td> |
| 874 |
<td><a href=" |
| 875 |
<?php echo wp_nonce_url(bloginfo('wpurl').'/wp-admin/admin.php?page=calendar&action=delete&event_id='.stripslashes($event->event_id),'calendar-delete_'.stripslashes($event->event_id)); ?>" class="delete" onclick="return confirm('<?php _e('Are you sure you want to delete this event?','calendar'); ?>')"><?php echo __('Delete','calendar'); ?></a></td> |
| 876 |
</tr> |
| 877 |
<?php |
| 878 |
} |
| 879 |
?> |
| 880 |
</table> |
| 881 |
<?php |
| 882 |
} |
| 883 |
else |
| 884 |
{ |
| 885 |
?> |
| 886 |
<p><?php _e("There are no events in the database!",'calendar') ?></p> |
| 887 |
<?php |
| 888 |
} |
| 889 |
} |
| 890 |
|
| 891 |
|
| 892 |
// The event edit form for the manage events admin page |
| 893 |
function wp_events_edit_form($mode='add', $event_id=false) |
| 894 |
{ |
| 895 |
global $wpdb,$users_entries; |
| 896 |
$data = false; |
| 897 |
|
| 898 |
if ( $event_id !== false ) |
| 899 |
{ |
| 900 |
if ( intval($event_id) != $event_id ) |
| 901 |
{ |
| 902 |
echo "<div class=\"error\"><p>".__('Bad Monkey! No banana!','calendar')."</p></div>"; |
| 903 |
return; |
| 904 |
} |
| 905 |
else |
| 906 |
{ |
| 907 |
$data = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_id='%d' LIMIT 1",$event_id)); |
| 908 |
if ( empty($data) ) |
| 909 |
{ |
| 910 |
echo "<div class=\"error\"><p>".__("An event with that ID couldn't be found",'calendar')."</p></div>"; |
| 911 |
return; |
| 912 |
} |
| 913 |
$data = $data[0]; |
| 914 |
} |
| 915 |
// Recover users entries if they exist; in other words if editing an event went wrong |
| 916 |
if (!empty($users_entries)) |
| 917 |
{ |
| 918 |
$data = $users_entries; |
| 919 |
} |
| 920 |
} |
| 921 |
// Deal with possibility that form was submitted but not saved due to error - recover user's entries here |
| 922 |
else |
| 923 |
{ |
| 924 |
$data = $users_entries; |
| 925 |
} |
| 926 |
|
| 927 |
?> |
| 928 |
<div id="pop_up_cal" style="position:absolute;margin-left:150px;visibility:hidden;background-color:white;layer-background-color:white;z-index:1;"></div> |
| 929 |
<form name="quoteform" id="quoteform" class="wrap" method="post" action="<?php echo bloginfo('wpurl'); ?>/wp-admin/admin.php?page=calendar"> |
| 930 |
<input type="hidden" name="action" value="<?php echo $mode; ?>"> |
| 931 |
<input type="hidden" name="event_id" value="<?php echo stripslashes($event_id); ?>"> |
| 932 |
<?php |
| 933 |
if (stripslashes($event_id) != "") { |
| 934 |
$nonce_string = 'calendar-'.$mode.'_'.stripslashes($event_id); |
| 935 |
} else { |
| 936 |
$nonce_string = 'calendar-'.$mode; |
| 937 |
} |
| 938 |
wp_nonce_field($nonce_string); |
| 939 |
?> |
| 940 |
|
| 941 |
<div id="linkadvanceddiv" class="postbox"> |
| 942 |
<div style="float: left; width: 98%; clear: both;" class="inside"> |
| 943 |
<table cellpadding="5" cellspacing="5"> |
| 944 |
<tr> |
| 945 |
<td><legend><?php _e('Event Title','calendar'); ?></legend></td> |
| 946 |
<td><input type="text" name="event_title" class="input" size="40" maxlength="30" |
| 947 |
value="<?php if ( !empty($data) ) echo htmlspecialchars(stripslashes($data->event_title)); ?>" /></td> |
| 948 |
</tr> |
| 949 |
<tr> |
| 950 |
<td style="vertical-align:top;"><legend><?php _e('Event Description','calendar'); ?></legend></td> |
| 951 |
<td><textarea name="event_desc" class="input" rows="5" cols="50"><?php if ( !empty($data) ) echo htmlspecialchars(stripslashes($data->event_desc)); ?></textarea></td> |
| 952 |
</tr> |
| 953 |
<tr> |
| 954 |
<td><legend><?php _e('Event Category','calendar'); ?></legend></td> |
| 955 |
<td> <select name="event_category"> |
| 956 |
<?php |
| 957 |
// Grab all the categories and list them |
| 958 |
$sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE; |
| 959 |
$cats = $wpdb->get_results($sql); |
| 960 |
foreach($cats as $cat) |
| 961 |
{ |
| 962 |
echo '<option value="'.stripslashes($cat->category_id).'"'; |
| 963 |
if (!empty($data)) |
| 964 |
{ |
| 965 |
if ($data->event_category == $cat->category_id) |
| 966 |
{ |
| 967 |
echo 'selected="selected"'; |
| 968 |
} |
| 969 |
} |
| 970 |
echo '>'.stripslashes($cat->category_name).'</option> |
| 971 |
'; |
| 972 |
} |
| 973 |
?> |
| 974 |
</select> |
| 975 |
</td> |
| 976 |
</tr> |
| 977 |
<tr> |
| 978 |
<td><legend><?php _e('Event Link (Optional)','calendar'); ?></legend></td> |
| 979 |
<td><input type="text" name="event_link" class="input" size="40" value="<?php if ( !empty($data) ) echo htmlspecialchars(stripslashes($data->event_link)); ?>" /></td> |
| 980 |
</tr> |
| 981 |
<tr> |
| 982 |
<td><legend><?php _e('Start Date','calendar'); ?></legend></td> |
| 983 |
<td> |
| 984 |
<input type="text" name="event_begin" id="event_begin" class="input" size="12" |
| 985 |
value="<?php |
| 986 |
if ( !empty($data) ) |
| 987 |
{ |
| 988 |
echo htmlspecialchars(stripslashes($data->event_begin)); |
| 989 |
} |
| 990 |
else |
| 991 |
{ |
| 992 |
echo date("Y-m-d",ctwo()); |
| 993 |
} |
| 994 |
?>" /> |
| 995 |
<script type="text/javascript"> |
| 996 |
var cal_1 = new Calendar({ |
| 997 |
element: 'event_begin', |
| 998 |
startDay: <?php echo get_option('start_of_week'); ?>, |
| 999 |
onSelect: function unifydates(element) { |
| 1000 |
document.forms['quoteform'].event_end.value = document.forms['quoteform'].event_begin.value; |
| 1001 |
} |
| 1002 |
}); |
| 1003 |
</script> |
| 1004 |
</td> |
| 1005 |
</tr> |
| 1006 |
<tr> |
| 1007 |
<td><legend><?php _e('End Date','calendar'); ?></legend></td> |
| 1008 |
<td> |
| 1009 |
<input type="text" name="event_end" id="event_end" class="input" size="12" |
| 1010 |
value="<?php |
| 1011 |
if ( !empty($data) ) |
| 1012 |
{ |
| 1013 |
echo htmlspecialchars(stripslashes($data->event_end)); |
| 1014 |
} |
| 1015 |
else |
| 1016 |
{ |
| 1017 |
echo date("Y-m-d",ctwo()); |
| 1018 |
} |
| 1019 |
?>" /> |
| 1020 |
<script type="text/javascript"> |
| 1021 |
var cal_2 = new Calendar({ |
| 1022 |
element: 'event_end', |
| 1023 |
startDay: <?php echo get_option('start_of_week'); ?>, |
| 1024 |
minDate: new Date(parseInt(document.forms['quoteform'].event_begin.value.split('-')[0]),parseInt(document.forms['quoteform'].event_begin.value.split('-')[1]-1),parseInt(document.forms['quoteform'].event_begin.value.split('-')[2])) |
| 1025 |
}); |
| 1026 |
</script> |
| 1027 |
</td> |
| 1028 |
</tr> |
| 1029 |
<tr> |
| 1030 |
<td><legend><?php _e('Time (hh:mm)','calendar'); ?></legend></td> |
| 1031 |
<td> <input type="text" name="event_time" class="input" size=12 |
| 1032 |
value="<?php |
| 1033 |
if ( !empty($data) ) |
| 1034 |
{ |
| 1035 |
if ($data->event_time == "00:00:00") |
| 1036 |
{ |
| 1037 |
echo ''; |
| 1038 |
} |
| 1039 |
else |
| 1040 |
{ |
| 1041 |
echo date("H:i",strtotime(htmlspecialchars(stripslashes($data->event_time)))); |
| 1042 |
} |
| 1043 |
} |
| 1044 |
else |
| 1045 |
{ |
| 1046 |
echo date("H:i",ctwo()); |
| 1047 |
} |
| 1048 |
?>" /> <?php _e('Optional, set blank if not required.','calendar'); ?> <?php _e('Current time difference from GMT is ','calendar'); echo get_option('gmt_offset'); _e(' hour(s)','calendar'); ?> |
| 1049 |
</td> |
| 1050 |
</tr> |
| 1051 |
<tr> |
| 1052 |
<td><legend><?php _e('Recurring Events','calendar'); ?></legend></td> |
| 1053 |
<td> <?php |
| 1054 |
if (isset($data)) { |
| 1055 |
if ($data->event_repeats != NULL) |
| 1056 |
{ |
| 1057 |
$repeats = $data->event_repeats; |
| 1058 |
} |
| 1059 |
else |
| 1060 |
{ |
| 1061 |
$repeats = 0; |
| 1062 |
} |
| 1063 |
} |
| 1064 |
else |
| 1065 |
{ |
| 1066 |
$repeats = 0; |
| 1067 |
} |
| 1068 |
|
| 1069 |
$selected_s = ''; |
| 1070 |
$selected_w = ''; |
| 1071 |
$selected_m = ''; |
| 1072 |
$selected_y = ''; |
| 1073 |
$selected_u = ''; |
| 1074 |
if (isset($data)) { |
| 1075 |
if ($data->event_recur == "S") |
| 1076 |
{ |
| 1077 |
$selected_s = 'selected="selected"'; |
| 1078 |
} |
| 1079 |
else if ($data->event_recur == "W") |
| 1080 |
{ |
| 1081 |
$selected_w = 'selected="selected"'; |
| 1082 |
} |
| 1083 |
else if ($data->event_recur == "M") |
| 1084 |
{ |
| 1085 |
$selected_m = 'selected="selected"'; |
| 1086 |
} |
| 1087 |
else if ($data->event_recur == "Y") |
| 1088 |
{ |
| 1089 |
$selected_y = 'selected="selected"'; |
| 1090 |
} |
| 1091 |
else if ($data->event_recur == "U") |
| 1092 |
{ |
| 1093 |
$selected_u = 'selected="selected"'; |
| 1094 |
} |
| 1095 |
} |
| 1096 |
?> |
| 1097 |
<?php _e('Repeats for','calendar'); ?> |
| 1098 |
<input type="text" name="event_repeats" class="input" size="1" value="<?php echo $repeats; ?>" /> |
| 1099 |
<select name="event_recur" class="input"> |
| 1100 |
<option class="input" <?php echo $selected_s; ?> value="S"><?php _e('None') ?></option> |
| 1101 |
<option class="input" <?php echo $selected_w; ?> value="W"><?php _e('Weeks') ?></option> |
| 1102 |
<option class="input" <?php echo $selected_m; ?> value="M"><?php _e('Months (date)') ?></option> |
| 1103 |
<option class="input" <?php echo $selected_u; ?> value="U"><?php _e('Months (day)') ?></option> |
| 1104 |
<option class="input" <?php echo $selected_y; ?> value="Y"><?php _e('Years') ?></option> |
| 1105 |
</select><br /> |
| 1106 |
<?php _e('Entering 0 means forever. Where the recurrance interval is left at none, the event will not reoccur.','calendar'); ?> |
| 1107 |
</td> |
| 1108 |
</tr> |
| 1109 |
</table> |
| 1110 |
</div> |
| 1111 |
<div style="clear:both; height:1px;"> </div> |
| 1112 |
</div> |
| 1113 |
<input type="submit" name="save" class="button bold" value="<?php _e('Save','calendar'); ?> »" /> |
| 1114 |
</form> |
| 1115 |
<?php |
| 1116 |
} |
| 1117 |
|
| 1118 |
// The actual function called to render the manage events page and |
| 1119 |
// to deal with posts |
| 1120 |
function edit_calendar() |
| 1121 |
{ |
| 1122 |
global $current_user, $wpdb, $users_entries; |
| 1123 |
?> |
| 1124 |
<style type="text/css"> |
| 1125 |
<!-- |
| 1126 |
.error { |
| 1127 |
background: lightcoral; |
| 1128 |
border: 1px solid #e64f69; |
| 1129 |
margin: 1em 5% 10px; |
| 1130 |
padding: 0 1em 0 1em; |
| 1131 |
} |
| 1132 |
|
| 1133 |
.center { |
| 1134 |
text-align: center; |
| 1135 |
} |
| 1136 |
.right { text-align: right; |
| 1137 |
} |
| 1138 |
.left { |
| 1139 |
text-align: left; |
| 1140 |
} |
| 1141 |
.top { |
| 1142 |
vertical-align: top; |
| 1143 |
} |
| 1144 |
.bold { |
| 1145 |
font-weight: bold; |
| 1146 |
} |
| 1147 |
.private { |
| 1148 |
color: #e64f69; |
| 1149 |
} |
| 1150 |
//--> |
| 1151 |
</style> |
| 1152 |
|
| 1153 |
<?php |
| 1154 |
|
| 1155 |
// First some quick cleaning up |
| 1156 |
$edit = $create = $save = $delete = false; |
| 1157 |
|
| 1158 |
// Make sure we are collecting the variables we need to select years and months |
| 1159 |
$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
| 1160 |
$event_id = !empty($_REQUEST['event_id']) ? $_REQUEST['event_id'] : ''; |
| 1161 |
|
| 1162 |
// Deal with adding an event to the database |
| 1163 |
if ( $action == 'add' ) |
| 1164 |
{ |
| 1165 |
$title = !empty($_REQUEST['event_title']) ? $_REQUEST['event_title'] : ''; |
| 1166 |
$desc = !empty($_REQUEST['event_desc']) ? $_REQUEST['event_desc'] : ''; |
| 1167 |
$begin = !empty($_REQUEST['event_begin']) ? $_REQUEST['event_begin'] : ''; |
| 1168 |
$end = !empty($_REQUEST['event_end']) ? $_REQUEST['event_end'] : ''; |
| 1169 |
$time = !empty($_REQUEST['event_time']) ? $_REQUEST['event_time'] : ''; |
| 1170 |
$recur = !empty($_REQUEST['event_recur']) ? $_REQUEST['event_recur'] : ''; |
| 1171 |
$repeats = !empty($_REQUEST['event_repeats']) ? $_REQUEST['event_repeats'] : ''; |
| 1172 |
$category = !empty($_REQUEST['event_category']) ? $_REQUEST['event_category'] : ''; |
| 1173 |
$linky = !empty($_REQUEST['event_link']) ? $_REQUEST['event_link'] : ''; |
| 1174 |
|
| 1175 |
if (wp_verify_nonce($_POST['_wpnonce'],'calendar-add') == false) { |
| 1176 |
?> |
| 1177 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e("Security check failure, try adding the event again",'calendar'); ?></p></div> |
| 1178 |
<?php |
| 1179 |
} else { |
| 1180 |
|
| 1181 |
// Perform some validation on the submitted dates - this checks for valid years and months |
| 1182 |
$date_format_one = '/^([0-9]{4})-([0][1-9])-([0-3][0-9])$/'; |
| 1183 |
$date_format_two = '/^([0-9]{4})-([1][0-2])-([0-3][0-9])$/'; |
| 1184 |
if ((preg_match($date_format_one,$begin) || preg_match($date_format_two,$begin)) && (preg_match($date_format_one,$end) || preg_match($date_format_two,$end))) |
| 1185 |
{ |
| 1186 |
// We know we have a valid year and month and valid integers for days so now we do a final check on the date |
| 1187 |
$begin_split = explode('-',$begin); |
| 1188 |
$begin_y = $begin_split[0]; |
| 1189 |
$begin_m = $begin_split[1]; |
| 1190 |
$begin_d = $begin_split[2]; |
| 1191 |
$end_split = explode('-',$end); |
| 1192 |
$end_y = $end_split[0]; |
| 1193 |
$end_m = $end_split[1]; |
| 1194 |
$end_d = $end_split[2]; |
| 1195 |
if (checkdate($begin_m,$begin_d,$begin_y) && checkdate($end_m,$end_d,$end_y)) |
| 1196 |
{ |
| 1197 |
// Ok, now we know we have valid dates, we want to make sure that they are either equal or that the end date is later than the start date |
| 1198 |
if (strtotime($end) >= strtotime($begin)) |
| 1199 |
{ |
| 1200 |
$start_date_ok = 1; |
| 1201 |
$end_date_ok = 1; |
| 1202 |
} |
| 1203 |
else |
| 1204 |
{ |
| 1205 |
?> |
| 1206 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('Your event end date must be either after or the same as your event begin date','calendar'); ?></p></div> |
| 1207 |
<?php |
| 1208 |
} |
| 1209 |
} |
| 1210 |
else |
| 1211 |
{ |
| 1212 |
?> |
| 1213 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('Your date formatting is correct but one or more of your dates is invalid. Check for number of days in month and leap year related errors.','calendar'); ?></p></div> |
| 1214 |
<?php |
| 1215 |
} |
| 1216 |
} |
| 1217 |
else |
| 1218 |
{ |
| 1219 |
?> |
| 1220 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('Both start and end dates must be entered and be in the format YYYY-MM-DD','calendar'); ?></p></div> |
| 1221 |
<?php |
| 1222 |
} |
| 1223 |
// We check for a valid time, or an empty one |
| 1224 |
$time_format_one = '/^([0-1][0-9]):([0-5][0-9])$/'; |
| 1225 |
$time_format_two = '/^([2][0-3]):([0-5][0-9])$/'; |
| 1226 |
if (preg_match($time_format_one,$time) || preg_match($time_format_two,$time) || $time == '') |
| 1227 |
{ |
| 1228 |
$time_ok = 1; |
| 1229 |
if ($time == '') |
| 1230 |
{ |
| 1231 |
$time_to_use = '00:00:00'; |
| 1232 |
} |
| 1233 |
else if ($time == '00:00') |
| 1234 |
{ |
| 1235 |
$time_to_use = '00:00:01'; |
| 1236 |
} |
| 1237 |
else |
| 1238 |
{ |
| 1239 |
$time_to_use = $time; |
| 1240 |
} |
| 1241 |
} |
| 1242 |
else |
| 1243 |
{ |
| 1244 |
?> |
| 1245 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('The time field must either be blank or be entered in the format hh:mm','calendar'); ?></p></div> |
| 1246 |
<?php |
| 1247 |
} |
| 1248 |
// We check to make sure the URL is alright |
| 1249 |
if (preg_match('/^(http)(s?)(:)\/\//',$linky) || $linky == '') |
| 1250 |
{ |
| 1251 |
$url_ok = 1; |
| 1252 |
} |
| 1253 |
else |
| 1254 |
{ |
| 1255 |
?> |
| 1256 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('The URL entered must either be prefixed with http:// or be completely blank','calendar'); ?></p></div> |
| 1257 |
<?php |
| 1258 |
} |
| 1259 |
// The title must be at least one character in length and no more than 30 |
| 1260 |
if (preg_match('/^.{1,30}$/',$title)) |
| 1261 |
{ |
| 1262 |
$title_ok =1; |
| 1263 |
} |
| 1264 |
else |
| 1265 |
{ |
| 1266 |
?> |
| 1267 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('The event title must be between 1 and 30 characters in length','calendar'); ?></p></div> |
| 1268 |
<?php |
| 1269 |
} |
| 1270 |
// We run some checks on recurrance |
| 1271 |
$repeats = (int)$repeats; |
| 1272 |
if (($repeats == 0 && $recur == 'S') || (($repeats >= 0) && ($recur == 'W' || $recur == 'M' || $recur == 'Y' || $recur == 'U'))) |
| 1273 |
{ |
| 1274 |
$recurring_ok = 1; |
| 1275 |
} |
| 1276 |
else |
| 1277 |
{ |
| 1278 |
?> |
| 1279 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('The repetition value must be 0 unless a type of recurrance is selected in which case the repetition value must be 0 or higher','calendar'); ?></p></div> |
| 1280 |
<?php |
| 1281 |
} |
| 1282 |
if (isset($start_date_ok) && isset($end_date_ok) && isset($time_ok) && isset($url_ok) && isset($title_ok) && isset($recurring_ok)) |
| 1283 |
{ |
| 1284 |
$sql = $wpdb->prepare("INSERT INTO " . WP_CALENDAR_TABLE . " SET event_title='%s', event_desc='%s', event_begin='%s', event_end='%s', event_time='%s', event_recur='%s', event_repeats='%s', event_author=%d, event_category=%d, event_link='%s'",$title,$desc,$begin,$end,$time_to_use,$recur,$repeats,$current_user->ID,$category,$linky); |
| 1285 |
|
| 1286 |
$wpdb->get_results($sql); |
| 1287 |
|
| 1288 |
$sql = $wpdb->prepare("SELECT event_id FROM " . WP_CALENDAR_TABLE . " WHERE event_title='%s' AND event_desc='%s' AND event_begin='%s' AND event_end='%s' AND event_recur='%s' AND event_repeats='%s' LIMIT 1",$title,$desc,$begin,$end,$recur,$repeats); |
| 1289 |
$result = $wpdb->get_results($sql); |
| 1290 |
|
| 1291 |
if ( empty($result) || empty($result[0]->event_id) ) |
| 1292 |
{ |
| 1293 |
?> |
| 1294 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('An event with the details you submitted could not be found in the database. This may indicate a problem with your database or the way in which it is configured.','calendar'); ?></p></div> |
| 1295 |
<?php |
| 1296 |
} |
| 1297 |
else |
| 1298 |
{ |
| 1299 |
do_action('add_calendar_entry', 'add'); |
| 1300 |
?> |
| 1301 |
<div class="updated"><p><?php _e('Event added. It will now show in your calendar.','calendar'); ?></p></div> |
| 1302 |
<?php |
| 1303 |
} |
| 1304 |
} |
| 1305 |
else |
| 1306 |
{ |
| 1307 |
// The form is going to be rejected due to field validation issues, so we preserve the users entries here |
| 1308 |
$users_entries->event_title = $title; |
| 1309 |
$users_entries->event_desc = $desc; |
| 1310 |
$users_entries->event_begin = $begin; |
| 1311 |
$users_entries->event_end = $end; |
| 1312 |
$users_entries->event_time = $time; |
| 1313 |
$users_entries->event_recur = $recur; |
| 1314 |
$users_entries->event_repeats = $repeats; |
| 1315 |
$users_entries->event_category = $category; |
| 1316 |
$users_entries->event_link = $linky; |
| 1317 |
} |
| 1318 |
} |
| 1319 |
} |
| 1320 |
// Permit saving of events that have been edited |
| 1321 |
elseif ( $action == 'edit_save' ) |
| 1322 |
{ |
| 1323 |
$title = !empty($_REQUEST['event_title']) ? $_REQUEST['event_title'] : ''; |
| 1324 |
$desc = !empty($_REQUEST['event_desc']) ? $_REQUEST['event_desc'] : ''; |
| 1325 |
$begin = !empty($_REQUEST['event_begin']) ? $_REQUEST['event_begin'] : ''; |
| 1326 |
$end = !empty($_REQUEST['event_end']) ? $_REQUEST['event_end'] : ''; |
| 1327 |
$time = !empty($_REQUEST['event_time']) ? $_REQUEST['event_time'] : ''; |
| 1328 |
$recur = !empty($_REQUEST['event_recur']) ? $_REQUEST['event_recur'] : ''; |
| 1329 |
$repeats = !empty($_REQUEST['event_repeats']) ? $_REQUEST['event_repeats'] : ''; |
| 1330 |
$category = !empty($_REQUEST['event_category']) ? $_REQUEST['event_category'] : ''; |
| 1331 |
$linky = !empty($_REQUEST['event_link']) ? $_REQUEST['event_link'] : ''; |
| 1332 |
|
| 1333 |
if ( empty($event_id) ) |
| 1334 |
{ |
| 1335 |
?> |
| 1336 |
<div class="error"><p><strong><?php _e('Failure','calendar'); ?>:</strong> <?php _e("You can't update an event if you haven't submitted an event id",'calendar'); ?></p></div> |
| 1337 |
<?php |
| 1338 |
} |
| 1339 |
elseif (wp_verify_nonce($_POST['_wpnonce'],'calendar-edit_save_'.$event_id) == false) { |
| 1340 |
?> |
| 1341 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e("Security check failure, try editing the event again",'calendar'); ?></p></div> |
| 1342 |
<?php |
| 1343 |
} |
| 1344 |
else |
| 1345 |
{ |
| 1346 |
// Perform some validation on the submitted dates - this checks for valid years and months |
| 1347 |
$date_format_one = '/^([0-9]{4})-([0][1-9])-([0-3][0-9])$/'; |
| 1348 |
$date_format_two = '/^([0-9]{4})-([1][0-2])-([0-3][0-9])$/'; |
| 1349 |
if ((preg_match($date_format_one,$begin) || preg_match($date_format_two,$begin)) && (preg_match($date_format_one,$end) || preg_match($date_format_two,$end))) |
| 1350 |
{ |
| 1351 |
// We know we have a valid year and month and valid integers for days so now we do a final check on the date |
| 1352 |
$begin_split = explode('-',$begin); |
| 1353 |
$begin_y = $begin_split[0]; |
| 1354 |
$begin_m = $begin_split[1]; |
| 1355 |
$begin_d = $begin_split[2]; |
| 1356 |
$end_split = explode('-',$end); |
| 1357 |
$end_y = $end_split[0]; |
| 1358 |
$end_m = $end_split[1]; |
| 1359 |
$end_d = $end_split[2]; |
| 1360 |
if (checkdate($begin_m,$begin_d,$begin_y) && checkdate($end_m,$end_d,$end_y)) |
| 1361 |
{ |
| 1362 |
// Ok, now we know we have valid dates, we want to make sure that they are either equal or that the end date is later than the start date |
| 1363 |
if (strtotime($end) >= strtotime($begin)) |
| 1364 |
{ |
| 1365 |
$start_date_ok = 1; |
| 1366 |
$end_date_ok = 1; |
| 1367 |
} |
| 1368 |
else |
| 1369 |
{ |
| 1370 |
?> |
| 1371 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('Your event end date must be either after or the same as your event begin date','calendar'); ?></p></div> |
| 1372 |
<?php |
| 1373 |
} |
| 1374 |
} |
| 1375 |
else |
| 1376 |
{ |
| 1377 |
?> |
| 1378 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('Your date formatting is correct but one or more of your dates is invalid. Check for number of days in month and leap year related errors.','calendar'); ?></p></div> |
| 1379 |
<?php |
| 1380 |
} |
| 1381 |
} |
| 1382 |
else |
| 1383 |
{ |
| 1384 |
?> |
| 1385 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('Both start and end dates must be entered and be in the format YYYY-MM-DD','calendar'); ?></p></div> |
| 1386 |
<?php |
| 1387 |
} |
| 1388 |
// We check for a valid time, or an empty one |
| 1389 |
$time_format_one = '/^([0-1][0-9]):([0-5][0-9])$/'; |
| 1390 |
$time_format_two = '/^([2][0-3]):([0-5][0-9])$/'; |
| 1391 |
if (preg_match($time_format_one,$time) || preg_match($time_format_two,$time) || $time == '') |
| 1392 |
{ |
| 1393 |
$time_ok = 1; |
| 1394 |
if ($time == '') |
| 1395 |
{ |
| 1396 |
$time_to_use = '00:00:00'; |
| 1397 |
} |
| 1398 |
else if ($time == '00:00') |
| 1399 |
{ |
| 1400 |
$time_to_use = '00:00:01'; |
| 1401 |
} |
| 1402 |
else |
| 1403 |
{ |
| 1404 |
$time_to_use = $time; |
| 1405 |
} |
| 1406 |
} |
| 1407 |
else |
| 1408 |
{ |
| 1409 |
?> |
| 1410 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('The time field must either be blank or be entered in the format hh:mm','calendar'); ?></p></div> |
| 1411 |
<?php |
| 1412 |
} |
| 1413 |
// We check to make sure the URL is alright |
| 1414 |
if (preg_match('/^(http)(s?)(:)\/\//',$linky) || $linky == '') |
| 1415 |
{ |
| 1416 |
$url_ok = 1; |
| 1417 |
} |
| 1418 |
else |
| 1419 |
{ |
| 1420 |
?> |
| 1421 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('The URL entered must either be prefixed with http:// or be completely blank','calendar'); ?></p></div> |
| 1422 |
<?php |
| 1423 |
} |
| 1424 |
// The title must be at least one character in length and no more than 30 |
| 1425 |
if (preg_match('/^.{1,30}$/',$title)) |
| 1426 |
{ |
| 1427 |
$title_ok =1; |
| 1428 |
} |
| 1429 |
else |
| 1430 |
{ |
| 1431 |
?> |
| 1432 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('The event title must be between 1 and 30 characters in length','calendar'); ?></p></div> |
| 1433 |
<?php |
| 1434 |
} |
| 1435 |
// We run some checks on recurrance |
| 1436 |
$repeats = (int)$repeats; |
| 1437 |
if (($repeats == 0 && $recur == 'S') || (($repeats >= 0) && ($recur == 'W' || $recur == 'M' || $recur == 'Y' || $recur == 'U'))) |
| 1438 |
{ |
| 1439 |
$recurring_ok = 1; |
| 1440 |
} |
| 1441 |
else |
| 1442 |
{ |
| 1443 |
?> |
| 1444 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('The repetition value must be 0 unless a type of recurrance is selected in which case the repetition value must be 0 or higher','calendar'); ?></p></div> |
| 1445 |
<?php |
| 1446 |
} |
| 1447 |
if (isset($start_date_ok) && isset($end_date_ok) && isset($time_ok) && isset($url_ok) && isset($title_ok) && isset($recurring_ok)) |
| 1448 |
{ |
| 1449 |
$sql = $wpdb->prepare("UPDATE " . WP_CALENDAR_TABLE . " SET event_title='%s', event_desc='%s', event_begin='%s', event_end='%s', event_time='%s', event_recur='%s', event_repeats='%s', event_author=%d, event_category=%d, event_link='%s' WHERE event_id='%s'",$title,$desc,$begin,$end,$time_to_use,$recur,$repeats,$current_user->ID,$category,$linky,$event_id); |
| 1450 |
$wpdb->get_results($sql); |
| 1451 |
$sql = $wpdb->prepare("SELECT event_id FROM " . WP_CALENDAR_TABLE . " WHERE event_title='%s' AND event_desc='%s' AND event_begin='%s' AND event_end='%s' AND event_recur='%s' AND event_repeats='%s' LIMIT 1",$title,$desc,$begin,$end,$recur,$repeats); |
| 1452 |
$result = $wpdb->get_results($sql); |
| 1453 |
|
| 1454 |
if ( empty($result) || empty($result[0]->event_id) ) |
| 1455 |
{ |
| 1456 |
?> |
| 1457 |
<div class="error"><p><strong><?php _e('Failure','calendar'); ?>:</strong> <?php _e('The database failed to return data to indicate the event has been updated sucessfully. This may indicate a problem with your database or the way in which it is configured.','calendar'); ?></p></div> |
| 1458 |
<?php |
| 1459 |
} |
| 1460 |
else |
| 1461 |
{ |
| 1462 |
do_action('add_calendar_entry', 'edit'); |
| 1463 |
?> |
| 1464 |
<div class="updated"><p><?php _e('Event updated successfully','calendar'); ?></p></div> |
| 1465 |
<?php |
| 1466 |
} |
| 1467 |
} |
| 1468 |
else |
| 1469 |
{ |
| 1470 |
// The form is going to be rejected due to field validation issues, so we preserve the users entries here |
| 1471 |
$users_entries->event_title = $title; |
| 1472 |
$users_entries->event_desc = $desc; |
| 1473 |
$users_entries->event_begin = $begin; |
| 1474 |
$users_entries->event_end = $end; |
| 1475 |
$users_entries->event_time = $time; |
| 1476 |
$users_entries->event_recur = $recur; |
| 1477 |
$users_entries->event_repeats = $repeats; |
| 1478 |
$users_entries->event_category = $category; |
| 1479 |
$users_entries->event_link = $linky; |
| 1480 |
$error_with_saving = 1; |
| 1481 |
} |
| 1482 |
} |
| 1483 |
} |
| 1484 |
// Deal with deleting an event from the database |
| 1485 |
elseif ( $action == 'delete' ) |
| 1486 |
{ |
| 1487 |
if ( empty($event_id) ) |
| 1488 |
{ |
| 1489 |
?> |
| 1490 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e("You can't delete an event if you haven't submitted an event id",'calendar'); ?></p></div> |
| 1491 |
<?php |
| 1492 |
} |
| 1493 |
elseif (wp_verify_nonce($_GET['_wpnonce'],'calendar-delete_'.$event_id) == false) { |
| 1494 |
?> |
| 1495 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e("Security check failure, try deleting the event again",'calendar'); ?></p></div> |
| 1496 |
<?php |
| 1497 |
} |
| 1498 |
else |
| 1499 |
{ |
| 1500 |
$sql = $wpdb->prepare("DELETE FROM " . WP_CALENDAR_TABLE . " WHERE event_id='%s'",$event_id); |
| 1501 |
$wpdb->get_results($sql); |
| 1502 |
|
| 1503 |
$sql = $wpdb->prepare("SELECT event_id FROM " . WP_CALENDAR_TABLE . " WHERE event_id='%s'",$event_id); |
| 1504 |
$result = $wpdb->get_results($sql); |
| 1505 |
|
| 1506 |
if ( empty($result) || empty($result[0]->event_id) ) |
| 1507 |
{ |
| 1508 |
do_action('add_calendar_entry', 'delete'); |
| 1509 |
?> |
| 1510 |
<div class="updated"><p><?php _e('Event deleted successfully','calendar'); ?></p></div> |
| 1511 |
<?php |
| 1512 |
} |
| 1513 |
else |
| 1514 |
{ |
| 1515 |
?> |
| 1516 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e('Despite issuing a request to delete, the event still remains in the database. Please investigate.','calendar'); ?></p></div> |
| 1517 |
<?php |
| 1518 |
|
| 1519 |
} |
| 1520 |
} |
| 1521 |
} |
| 1522 |
|
| 1523 |
// Now follows a little bit of code that pulls in the main |
| 1524 |
// components of this page; the edit form and the list of events |
| 1525 |
?> |
| 1526 |
|
| 1527 |
<div class="wrap"> |
| 1528 |
<?php |
| 1529 |
if ( $action == 'edit' || ($action == 'edit_save' && isset($error_with_saving))) |
| 1530 |
{ |
| 1531 |
?> |
| 1532 |
<h2><?php _e('Edit Event','calendar'); ?></h2> |
| 1533 |
<?php |
| 1534 |
if ( empty($event_id) ) |
| 1535 |
{ |
| 1536 |
echo "<div class=\"error\"><p>".__("You must provide an event id in order to edit it",'calendar')."</p></div>"; |
| 1537 |
} |
| 1538 |
else |
| 1539 |
{ |
| 1540 |
wp_events_edit_form('edit_save', $event_id); |
| 1541 |
} |
| 1542 |
} |
| 1543 |
else |
| 1544 |
{ |
| 1545 |
?> |
| 1546 |
<h2><?php _e('Add Event','calendar'); ?></h2> |
| 1547 |
<?php wp_events_edit_form(); ?> |
| 1548 |
|
| 1549 |
<h2><?php _e('Manage Events','calendar'); ?></h2> |
| 1550 |
<?php |
| 1551 |
wp_events_display_list(); |
| 1552 |
} |
| 1553 |
?> |
| 1554 |
</div> |
| 1555 |
|
| 1556 |
<?php |
| 1557 |
|
| 1558 |
} |
| 1559 |
|
| 1560 |
// Display the admin configuration page |
| 1561 |
function edit_calendar_config() |
| 1562 |
{ |
| 1563 |
global $wpdb, $initial_style; |
| 1564 |
|
| 1565 |
if (isset($_POST['permissions']) && isset($_POST['style']) && wp_verify_nonce($_POST['_wpnonce'],'calendar-config') == false) { |
| 1566 |
?> |
| 1567 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e("Security check failure, try editing the config again",'calendar'); ?></p></div> |
| 1568 |
<?php |
| 1569 |
} |
| 1570 |
elseif (isset($_POST['permissions']) && isset($_POST['style'])) |
| 1571 |
{ |
| 1572 |
if ($_POST['permissions'] == 'subscriber') { $new_perms = 'read'; } |
| 1573 |
else if ($_POST['permissions'] == 'contributor') { $new_perms = 'edit_posts'; } |
| 1574 |
else if ($_POST['permissions'] == 'author') { $new_perms = 'publish_posts'; } |
| 1575 |
else if ($_POST['permissions'] == 'editor') { $new_perms = 'moderate_comments'; } |
| 1576 |
else if ($_POST['permissions'] == 'admin') { $new_perms = 'manage_options'; } |
| 1577 |
else { $new_perms = 'manage_options'; } |
| 1578 |
|
| 1579 |
$calendar_style = $_POST['style']; // Escape done in query below |
| 1580 |
$display_upcoming_days = $_POST['display_upcoming_days']; // Escape done in query below |
| 1581 |
|
| 1582 |
if ($_POST['display_author'] == 'on') |
| 1583 |
{ |
| 1584 |
$disp_author = 'true'; |
| 1585 |
} |
| 1586 |
else |
| 1587 |
{ |
| 1588 |
$disp_author = 'false'; |
| 1589 |
} |
| 1590 |
|
| 1591 |
if ($_POST['display_jump'] == 'on') |
| 1592 |
{ |
| 1593 |
$disp_jump = 'true'; |
| 1594 |
} |
| 1595 |
else |
| 1596 |
{ |
| 1597 |
$disp_jump = 'false'; |
| 1598 |
} |
| 1599 |
|
| 1600 |
if ($_POST['display_todays'] == 'on') |
| 1601 |
{ |
| 1602 |
$disp_todays = 'true'; |
| 1603 |
} |
| 1604 |
else |
| 1605 |
{ |
| 1606 |
$disp_todays = 'false'; |
| 1607 |
} |
| 1608 |
|
| 1609 |
if ($_POST['display_upcoming'] == 'on') |
| 1610 |
{ |
| 1611 |
$disp_upcoming = 'true'; |
| 1612 |
} |
| 1613 |
else |
| 1614 |
{ |
| 1615 |
$disp_upcoming = 'false'; |
| 1616 |
} |
| 1617 |
|
| 1618 |
if ($_POST['enable_categories'] == 'on') |
| 1619 |
{ |
| 1620 |
$enable_categories = 'true'; |
| 1621 |
} |
| 1622 |
else |
| 1623 |
{ |
| 1624 |
$enable_categories = 'false'; |
| 1625 |
} |
| 1626 |
|
| 1627 |
if ($_POST['enable_feed'] == 'on') |
| 1628 |
{ |
| 1629 |
$enable_feed = 'true'; |
| 1630 |
} |
| 1631 |
else |
| 1632 |
{ |
| 1633 |
$enable_feed = 'false'; |
| 1634 |
} |
| 1635 |
|
| 1636 |
if ($_POST['show_attribution_link'] == 'on') { |
| 1637 |
$show_attribution_link = 'true'; |
| 1638 |
} else { |
| 1639 |
$show_attribution_link = 'false'; |
| 1640 |
} |
| 1641 |
|
| 1642 |
$wpdb->get_results($wpdb->prepare("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '%s' WHERE config_item='can_manage_events'",$new_perms)); |
| 1643 |
$wpdb->get_results($wpdb->prepare("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '%s' WHERE config_item='calendar_style'",$calendar_style)); |
| 1644 |
$wpdb->get_results($wpdb->prepare("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '%s' WHERE config_item='display_author'",$disp_author)); |
| 1645 |
$wpdb->get_results($wpdb->prepare("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '%s' WHERE config_item='display_jump'",$disp_jump)); |
| 1646 |
$wpdb->get_results($wpdb->prepare("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '%s' WHERE config_item='display_todays'",$disp_todays)); |
| 1647 |
$wpdb->get_results($wpdb->prepare("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '%s' WHERE config_item='display_upcoming'",$disp_upcoming)); |
| 1648 |
$wpdb->get_results($wpdb->prepare("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '%d' WHERE config_item='display_upcoming_days'",$display_upcoming_days)); |
| 1649 |
$wpdb->get_results($wpdb->prepare("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '%s' WHERE config_item='enable_categories'",$enable_categories)); |
| 1650 |
$wpdb->get_results($wpdb->prepare("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '%s' WHERE config_item='enable_feed'",$enable_feed)); |
| 1651 |
$attribution_present = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='show_attribution_link'"); |
| 1652 |
if (empty($attribution_present)) { |
| 1653 |
$wpdb->get_results("INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='show_attribution_link', config_value='false'"); |
| 1654 |
} |
| 1655 |
$wpdb->get_results($wpdb->prepare("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '%s' WHERE config_item='show_attribution_link'",$show_attribution_link)); |
| 1656 |
|
| 1657 |
// Check to see if we are replacing the original style |
| 1658 |
if (isset($_POST['reset_styles'])) { |
| 1659 |
if ($_POST['reset_styles'] == 'on') |
| 1660 |
{ |
| 1661 |
$wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$initial_style."' WHERE config_item='calendar_style'"); |
| 1662 |
} |
| 1663 |
} |
| 1664 |
|
| 1665 |
echo "<div class=\"updated\"><p><strong>".__('Settings saved','calendar').".</strong></p></div>"; |
| 1666 |
} |
| 1667 |
|
| 1668 |
// Pull the values out of the database that we need for the form |
| 1669 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='can_manage_events'"); |
| 1670 |
if (!empty($configs)) |
| 1671 |
{ |
| 1672 |
foreach ($configs as $config) |
| 1673 |
{ |
| 1674 |
$allowed_group = stripslashes($config->config_value); |
| 1675 |
} |
| 1676 |
} |
| 1677 |
|
| 1678 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='calendar_style'"); |
| 1679 |
if (!empty($configs)) |
| 1680 |
{ |
| 1681 |
foreach ($configs as $config) |
| 1682 |
{ |
| 1683 |
$calendar_style = stripslashes($config->config_value); |
| 1684 |
} |
| 1685 |
} |
| 1686 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_author'"); |
| 1687 |
$yes_disp_author = ''; |
| 1688 |
$no_disp_author = ''; |
| 1689 |
if (!empty($configs)) |
| 1690 |
{ |
| 1691 |
foreach ($configs as $config) |
| 1692 |
{ |
| 1693 |
if ($config->config_value == 'true') |
| 1694 |
{ |
| 1695 |
$yes_disp_author = 'selected="selected"'; |
| 1696 |
} |
| 1697 |
else |
| 1698 |
{ |
| 1699 |
$no_disp_author = 'selected="selected"'; |
| 1700 |
} |
| 1701 |
} |
| 1702 |
} |
| 1703 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_jump'"); |
| 1704 |
$yes_disp_jump = ''; |
| 1705 |
$no_disp_jump = ''; |
| 1706 |
if (!empty($configs)) |
| 1707 |
{ |
| 1708 |
foreach ($configs as $config) |
| 1709 |
{ |
| 1710 |
if ($config->config_value == 'true') |
| 1711 |
{ |
| 1712 |
$yes_disp_jump = 'selected="selected"'; |
| 1713 |
} |
| 1714 |
else |
| 1715 |
{ |
| 1716 |
$no_disp_jump = 'selected="selected"'; |
| 1717 |
} |
| 1718 |
} |
| 1719 |
} |
| 1720 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_todays'"); |
| 1721 |
$yes_disp_todays = ''; |
| 1722 |
$no_disp_todays = ''; |
| 1723 |
if (!empty($configs)) |
| 1724 |
{ |
| 1725 |
foreach ($configs as $config) |
| 1726 |
{ |
| 1727 |
if ($config->config_value == 'true') |
| 1728 |
{ |
| 1729 |
$yes_disp_todays = 'selected="selected"'; |
| 1730 |
} |
| 1731 |
else |
| 1732 |
{ |
| 1733 |
$no_disp_todays = 'selected="selected"'; |
| 1734 |
} |
| 1735 |
} |
| 1736 |
} |
| 1737 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_upcoming'"); |
| 1738 |
$yes_disp_upcoming = ''; |
| 1739 |
$no_disp_upcoming = ''; |
| 1740 |
if (!empty($configs)) |
| 1741 |
{ |
| 1742 |
foreach ($configs as $config) |
| 1743 |
{ |
| 1744 |
if ($config->config_value == 'true') |
| 1745 |
{ |
| 1746 |
$yes_disp_upcoming = 'selected="selected"'; |
| 1747 |
} |
| 1748 |
else |
| 1749 |
{ |
| 1750 |
$no_disp_upcoming = 'selected="selected"'; |
| 1751 |
} |
| 1752 |
} |
| 1753 |
} |
| 1754 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_upcoming_days'"); |
| 1755 |
if (!empty($configs)) |
| 1756 |
{ |
| 1757 |
foreach ($configs as $config) |
| 1758 |
{ |
| 1759 |
$upcoming_days = stripslashes($config->config_value); |
| 1760 |
} |
| 1761 |
} |
| 1762 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='enable_categories'"); |
| 1763 |
$yes_enable_categories = ''; |
| 1764 |
$no_enable_categories = ''; |
| 1765 |
if (!empty($configs)) |
| 1766 |
{ |
| 1767 |
foreach ($configs as $config) |
| 1768 |
{ |
| 1769 |
if ($config->config_value == 'true') |
| 1770 |
{ |
| 1771 |
$yes_enable_categories = 'selected="selected"'; |
| 1772 |
} |
| 1773 |
else |
| 1774 |
{ |
| 1775 |
$no_enable_categories = 'selected="selected"'; |
| 1776 |
} |
| 1777 |
} |
| 1778 |
} |
| 1779 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='enable_feed'"); |
| 1780 |
$yes_enable_feed = ''; |
| 1781 |
$no_enable_feed = ''; |
| 1782 |
if (!empty($configs)) |
| 1783 |
{ |
| 1784 |
foreach ($configs as $config) |
| 1785 |
{ |
| 1786 |
if ($config->config_value == 'true') |
| 1787 |
{ |
| 1788 |
$yes_enable_feed = 'selected="selected"'; |
| 1789 |
} |
| 1790 |
else |
| 1791 |
{ |
| 1792 |
$no_enable_feed = 'selected="selected"'; |
| 1793 |
} |
| 1794 |
} |
| 1795 |
} |
| 1796 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='show_attribution_link'"); |
| 1797 |
$yes_show_attribution_link = ''; |
| 1798 |
$no_show_attribution_link = ''; |
| 1799 |
if (!empty($configs)) |
| 1800 |
{ |
| 1801 |
foreach ($configs as $config) |
| 1802 |
{ |
| 1803 |
if ($config->config_value == 'true') |
| 1804 |
{ |
| 1805 |
$yes_show_attribution_link = 'selected="selected"'; |
| 1806 |
} |
| 1807 |
else |
| 1808 |
{ |
| 1809 |
$no_show_attribution_link = 'selected="selected"'; |
| 1810 |
} |
| 1811 |
} |
| 1812 |
} |
| 1813 |
$subscriber_selected = ''; |
| 1814 |
$contributor_selected = ''; |
| 1815 |
$author_selected = ''; |
| 1816 |
$editor_selected = ''; |
| 1817 |
$admin_selected = ''; |
| 1818 |
if ($allowed_group == 'read') { $subscriber_selected='selected="selected"';} |
| 1819 |
else if ($allowed_group == 'edit_posts') { $contributor_selected='selected="selected"';} |
| 1820 |
else if ($allowed_group == 'publish_posts') { $author_selected='selected="selected"';} |
| 1821 |
else if ($allowed_group == 'moderate_comments') { $editor_selected='selected="selected"';} |
| 1822 |
else if ($allowed_group == 'manage_options') { $admin_selected='selected="selected"';} |
| 1823 |
|
| 1824 |
// Now we render the form |
| 1825 |
?> |
| 1826 |
<style type="text/css"> |
| 1827 |
<!-- |
| 1828 |
.error { |
| 1829 |
background: lightcoral; |
| 1830 |
border: 1px solid #e64f69; |
| 1831 |
margin: 1em 5% 10px; |
| 1832 |
padding: 0 1em 0 1em; |
| 1833 |
} |
| 1834 |
|
| 1835 |
.center { |
| 1836 |
text-align: center; |
| 1837 |
} |
| 1838 |
.right { |
| 1839 |
text-align: right; |
| 1840 |
} |
| 1841 |
.left { |
| 1842 |
text-align: left; |
| 1843 |
} |
| 1844 |
.top { |
| 1845 |
vertical-align: top; |
| 1846 |
} |
| 1847 |
.bold { |
| 1848 |
font-weight: bold; |
| 1849 |
} |
| 1850 |
.private { |
| 1851 |
color: #e64f69; |
| 1852 |
} |
| 1853 |
//--> |
| 1854 |
</style> |
| 1855 |
|
| 1856 |
<div class="wrap"> |
| 1857 |
<h2><?php _e('Calendar Options','calendar'); ?></h2> |
| 1858 |
<form name="quoteform" id="quoteform" class="wrap" method="post" action="<?php echo bloginfo('wpurl'); ?>/wp-admin/admin.php?page=calendar-config"> |
| 1859 |
<?php wp_nonce_field('calendar-config'); ?> |
| 1860 |
<div id="linkadvanceddiv" class="postbox"> |
| 1861 |
<div style="float: left; width: 98%; clear: both;" class="inside"> |
| 1862 |
<table cellpadding="5" cellspacing="5"> |
| 1863 |
<tr> |
| 1864 |
<td><legend><?php _e('Choose the lowest user group that may manage events','calendar'); ?></legend></td> |
| 1865 |
<td> <select name="permissions"> |
| 1866 |
<option value="subscriber"<?php echo $subscriber_selected ?>><?php _e('Subscriber','calendar')?></option> |
| 1867 |
<option value="contributor" <?php echo $contributor_selected ?>><?php _e('Contributor','calendar')?></option> |
| 1868 |
<option value="author" <?php echo $author_selected ?>><?php _e('Author','calendar')?></option> |
| 1869 |
<option value="editor" <?php echo $editor_selected ?>><?php _e('Editor','calendar')?></option> |
| 1870 |
<option value="admin" <?php echo $admin_selected ?>><?php _e('Administrator','calendar')?></option> |
| 1871 |
</select> |
| 1872 |
</td> |
| 1873 |
</tr> |
| 1874 |
<tr> |
| 1875 |
<td><legend><?php _e('Do you want to display the author name on events?','calendar'); ?></legend></td> |
| 1876 |
<td> <select name="display_author"> |
| 1877 |
<option value="on" <?php echo $yes_disp_author ?>><?php _e('Yes','calendar') ?></option> |
| 1878 |
<option value="off" <?php echo $no_disp_author ?>><?php _e('No','calendar') ?></option> |
| 1879 |
</select> |
| 1880 |
</td> |
| 1881 |
</tr> |
| 1882 |
<tr> |
| 1883 |
<td><legend><?php _e('Display a jumpbox for changing month and year quickly?','calendar'); ?></legend></td> |
| 1884 |
<td> <select name="display_jump"> |
| 1885 |
<option value="on" <?php echo $yes_disp_jump ?>><?php _e('Yes','calendar') ?></option> |
| 1886 |
<option value="off" <?php echo $no_disp_jump ?>><?php _e('No','calendar') ?></option> |
| 1887 |
</select> |
| 1888 |
</td> |
| 1889 |
</tr> |
| 1890 |
<tr> |
| 1891 |
<td><legend><?php _e('Display todays events?','calendar'); ?></legend></td> |
| 1892 |
<td> <select name="display_todays"> |
| 1893 |
<option value="on" <?php echo $yes_disp_todays ?>><?php _e('Yes','calendar') ?></option> |
| 1894 |
<option value="off" <?php echo $no_disp_todays ?>><?php _e('No','calendar') ?></option> |
| 1895 |
</select> |
| 1896 |
</td> |
| 1897 |
</tr> |
| 1898 |
<tr> |
| 1899 |
<td><legend><?php _e('Display upcoming events?','calendar'); ?></legend></td> |
| 1900 |
<td> <select name="display_upcoming"> |
| 1901 |
<option value="on" <?php echo $yes_disp_upcoming ?>><?php _e('Yes','calendar') ?></option> |
| 1902 |
<option value="off" <?php echo $no_disp_upcoming ?>><?php _e('No','calendar') ?></option> |
| 1903 |
</select> |
| 1904 |
<?php _e('for','calendar'); ?> <input type="text" name="display_upcoming_days" value="<?php echo $upcoming_days ?>" size="1" maxlength="2" /> <?php _e('days into the future','calendar'); ?> |
| 1905 |
</td> |
| 1906 |
</tr> |
| 1907 |
<tr> |
| 1908 |
<td><legend><?php _e('Enable event categories?','calendar'); ?></legend></td> |
| 1909 |
<td> <select name="enable_categories"> |
| 1910 |
<option value="on" <?php echo $yes_enable_categories ?>><?php _e('Yes','calendar') ?></option> |
| 1911 |
<option value="off" <?php echo $no_enable_categories ?>><?php _e('No','calendar') ?></option> |
| 1912 |
</select> |
| 1913 |
</td> |
| 1914 |
</tr> |
| 1915 |
<tr> |
| 1916 |
<td><legend><?php _e('Enable iCalendar feed?','calendar'); ?></legend></td> |
| 1917 |
<td> <select name="enable_feed"> |
| 1918 |
<option value="on" <?php echo $yes_enable_feed ?>><?php _e('Yes','calendar') ?></option> |
| 1919 |
<option value="off" <?php echo $no_enable_feed ?>><?php _e('No','calendar') ?></option> |
| 1920 |
</select> |
| 1921 |
</td> |
| 1922 |
</tr> |
| 1923 |
<tr> |
| 1924 |
<td><legend><?php _e('Enable attribution link?','calendar'); ?></legend></td> |
| 1925 |
<td> <select name="show_attribution_link"> |
| 1926 |
<?php if ($yes_show_attribution_link == '' && $yes_show_attribution_link == '') { ?> |
| 1927 |
<option value="on" selected="selected"></option> |
| 1928 |
<?php } ?> |
| 1929 |
<option value="on" <?php echo $yes_show_attribution_link ?>><?php _e('Yes','calendar') ?></option> |
| 1930 |
<option value="off" <?php echo $no_show_attribution_link ?>><?php _e('No','calendar') ?></option> |
| 1931 |
</select> |
| 1932 |
</td> |
| 1933 |
</tr> |
| 1934 |
<tr> |
| 1935 |
<td style="vertical-align:top;"><legend><?php _e('Configure the stylesheet for Calendar','calendar'); ?></legend></td> |
| 1936 |
<td><textarea name="style" rows="10" cols="60" tabindex="2"><?php echo $calendar_style; ?></textarea><br /> |
| 1937 |
<input type="checkbox" name="reset_styles" /> <?php _e('Tick this box if you wish to reset the Calendar style to default','calendar'); ?></td> |
| 1938 |
</tr> |
| 1939 |
</table> |
| 1940 |
</div> |
| 1941 |
<div style="clear:both; height:1px;"> </div> |
| 1942 |
</div> |
| 1943 |
<input type="submit" name="save" class="button bold" value="<?php _e('Save','calendar'); ?> »" /> |
| 1944 |
</form> |
| 1945 |
</div> |
| 1946 |
<?php |
| 1947 |
|
| 1948 |
|
| 1949 |
} |
| 1950 |
|
| 1951 |
// Function to handle the management of categories |
| 1952 |
function manage_categories() |
| 1953 |
{ |
| 1954 |
global $wpdb; |
| 1955 |
|
| 1956 |
?> |
| 1957 |
<style type="text/css"> |
| 1958 |
<!-- |
| 1959 |
.error { |
| 1960 |
background: lightcoral; |
| 1961 |
border: 1px solid #e64f69; |
| 1962 |
margin: 1em 5% 10px; |
| 1963 |
padding: 0 1em 0 1em; |
| 1964 |
} |
| 1965 |
|
| 1966 |
.center { |
| 1967 |
text-align: center; |
| 1968 |
} |
| 1969 |
.right { |
| 1970 |
text-align: right; |
| 1971 |
} |
| 1972 |
.left { |
| 1973 |
text-align: left; |
| 1974 |
} |
| 1975 |
.top { |
| 1976 |
vertical-align: top; |
| 1977 |
} |
| 1978 |
.bold { |
| 1979 |
font-weight: bold; |
| 1980 |
} |
| 1981 |
.private { |
| 1982 |
color: #e64f69; |
| 1983 |
} |
| 1984 |
//--> |
| 1985 |
|
| 1986 |
</style> |
| 1987 |
<?php |
| 1988 |
// We do some checking to see what we're doing |
| 1989 |
if (isset($_POST['mode']) && $_POST['mode'] == 'add') |
| 1990 |
{ |
| 1991 |
if (wp_verify_nonce($_POST['_wpnonce'],'calendar-category_add') == false) { |
| 1992 |
?> |
| 1993 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e("Security check failure, try adding the category again",'calendar'); ?></p></div> |
| 1994 |
<?php |
| 1995 |
} else { |
| 1996 |
// Proceed with the save |
| 1997 |
$sql = $wpdb->prepare("INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_name='%s', category_colour='%s'",$_POST['category_name'],$_POST['category_colour']); |
| 1998 |
$wpdb->get_results($sql); |
| 1999 |
echo "<div class=\"updated\"><p><strong>".__('Category added successfully','calendar')."</strong></p></div>"; |
| 2000 |
} |
| 2001 |
} |
| 2002 |
else if (isset($_GET['mode']) && isset($_GET['category_id']) && $_GET['mode'] == 'delete') |
| 2003 |
{ |
| 2004 |
if (wp_verify_nonce($_GET['_wpnonce'],'calendar-category_delete_'.$_GET['category_id']) == false) { |
| 2005 |
?> |
| 2006 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e("Security check failure, try deleting the category again",'calendar'); ?></p></div> |
| 2007 |
<?php |
| 2008 |
} else { |
| 2009 |
$sql = $wpdb->prepare("DELETE FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=%d",$_GET['category_id']); |
| 2010 |
$wpdb->get_results($sql); |
| 2011 |
$sql = $wpdb->prepare("UPDATE " . WP_CALENDAR_TABLE . " SET event_category=1 WHERE event_category=%d",$_GET['category_id']); |
| 2012 |
$wpdb->get_results($sql); |
| 2013 |
echo "<div class=\"updated\"><p><strong>".__('Category deleted successfully','calendar')."</strong></p></div>"; |
| 2014 |
} |
| 2015 |
} |
| 2016 |
else if (isset($_GET['mode']) && isset($_GET['category_id']) && $_GET['mode'] == 'edit' && !isset($_POST['mode'])) |
| 2017 |
{ |
| 2018 |
$sql = $wpdb->prepare("SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=%d",$_GET['category_id']); |
| 2019 |
$cur_cat = $wpdb->get_row($sql); |
| 2020 |
?> |
| 2021 |
<div class="wrap"> |
| 2022 |
<h2><?php _e('Edit Category','calendar'); ?></h2> |
| 2023 |
<form name="catform" id="catform" class="wrap" method="post" action="<?php echo bloginfo('wpurl'); ?>/wp-admin/admin.php?page=calendar-categories"> |
| 2024 |
<input type="hidden" name="mode" value="edit" /> |
| 2025 |
<input type="hidden" name="category_id" value="<?php echo stripslashes($cur_cat->category_id) ?>" /> |
| 2026 |
<?php wp_nonce_field('calendar-category_edit_'.stripslashes($cur_cat->category_id)); ?> |
| 2027 |
<div id="linkadvanceddiv" class="postbox"> |
| 2028 |
<div style="float: left; width: 98%; clear: both;" class="inside"> |
| 2029 |
<table cellpadding="5" cellspacing="5"> |
| 2030 |
<tr> |
| 2031 |
<td><legend><?php _e('Category Name','calendar'); ?>:</legend></td> |
| 2032 |
<td><input type="text" name="category_name" class="input" size="30" maxlength="30" value="<?php echo stripslashes($cur_cat->category_name) ?>" /></td> |
| 2033 |
</tr> |
| 2034 |
<tr> |
| 2035 |
<td><legend><?php _e('Category Colour (Hex format)','calendar'); ?>:</legend></td> |
| 2036 |
<td><input type="text" name="category_colour" class="input" size="10" maxlength="7" value="<?php echo stripslashes($cur_cat->category_colour) ?>" /></td> |
| 2037 |
</tr> |
| 2038 |
</table> |
| 2039 |
</div> |
| 2040 |
<div style="clear:both; height:1px;"> </div> |
| 2041 |
</div> |
| 2042 |
<input type="submit" name="save" class="button bold" value="<?php _e('Save','calendar'); ?> »" /> |
| 2043 |
</form> |
| 2044 |
</div> |
| 2045 |
<?php |
| 2046 |
} |
| 2047 |
else if (isset($_POST['mode']) && isset($_POST['category_id']) && isset($_POST['category_name']) && isset($_POST['category_colour']) && $_POST['mode'] == 'edit') |
| 2048 |
{ |
| 2049 |
if (wp_verify_nonce($_POST['_wpnonce'],'calendar-category_edit_'.$_POST['category_id']) == false) { |
| 2050 |
?> |
| 2051 |
<div class="error"><p><strong><?php _e('Error','calendar'); ?>:</strong> <?php _e("Security check failure, try editing the category again",'calendar'); ?></p></div> |
| 2052 |
<?php |
| 2053 |
} else { |
| 2054 |
// Proceed with the save |
| 2055 |
$sql = $wpdb->prepare("UPDATE " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_name='%s', category_colour='%s' WHERE category_id=%d",$_POST['category_name'],$_POST['category_colour'],$_POST['category_id']); |
| 2056 |
$wpdb->get_results($sql); |
| 2057 |
echo "<div class=\"updated\"><p><strong>".__('Category edited successfully','calendar')."</strong></p></div>"; |
| 2058 |
} |
| 2059 |
} |
| 2060 |
|
| 2061 |
$get_mode = 0; |
| 2062 |
$post_mode = 0; |
| 2063 |
if (isset($_GET['mode'])) { |
| 2064 |
if ($_GET['mode'] == 'edit') { |
| 2065 |
$get_mode = 1; |
| 2066 |
} |
| 2067 |
} |
| 2068 |
if (isset($_POST['mode'])) { |
| 2069 |
if ($_POST['mode'] == 'edit') { |
| 2070 |
$post_mode = 1; |
| 2071 |
} |
| 2072 |
} |
| 2073 |
if ($get_mode != 1 || $post_mode == 1) |
| 2074 |
{ |
| 2075 |
?> |
| 2076 |
|
| 2077 |
<div class="wrap"> |
| 2078 |
<h2><?php _e('Add Category','calendar'); ?></h2> |
| 2079 |
<form name="catform" id="catform" class="wrap" method="post" action="<?php echo bloginfo('wpurl'); ?>/wp-admin/admin.php?page=calendar-categories"> |
| 2080 |
<input type="hidden" name="mode" value="add" /> |
| 2081 |
<input type="hidden" name="category_id" value=""> |
| 2082 |
<?php wp_nonce_field('calendar-category_add'); ?> |
| 2083 |
<div id="linkadvanceddiv" class="postbox"> |
| 2084 |
<div style="float: left; width: 98%; clear: both;" class="inside"> |
| 2085 |
<table cellspacing="5" cellpadding="5"> |
| 2086 |
<tr> |
| 2087 |
<td><legend><?php _e('Category Name','calendar'); ?>:</legend></td> |
| 2088 |
<td><input type="text" name="category_name" class="input" size="30" maxlength="30" value="" /></td> |
| 2089 |
</tr> |
| 2090 |
<tr> |
| 2091 |
<td><legend><?php _e('Category Colour (Hex format)','calendar'); ?>:</legend></td> |
| 2092 |
<td><input type="text" name="category_colour" class="input" size="10" maxlength="7" value="" /></td> |
| 2093 |
</tr> |
| 2094 |
</table> |
| 2095 |
</div> |
| 2096 |
<div style="clear:both; height:1px;"> </div> |
| 2097 |
</div> |
| 2098 |
<input type="submit" name="save" class="button bold" value="<?php _e('Save','calendar'); ?> »" /> |
| 2099 |
</form> |
| 2100 |
<h2><?php _e('Manage Categories','calendar'); ?></h2> |
| 2101 |
<?php |
| 2102 |
|
| 2103 |
// We pull the categories from the database |
| 2104 |
$categories = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " ORDER BY category_id ASC"); |
| 2105 |
|
| 2106 |
if ( !empty($categories) ) |
| 2107 |
{ |
| 2108 |
?> |
| 2109 |
<table class="widefat page fixed" width="50%" cellpadding="3" cellspacing="3"> |
| 2110 |
<thead> |
| 2111 |
<tr> |
| 2112 |
<th class="manage-column" scope="col"><?php _e('ID','calendar') ?></th> |
| 2113 |
<th class="manage-column" scope="col"><?php _e('Category Name','calendar') ?></th> |
| 2114 |
<th class="manage-column" scope="col"><?php _e('Category Colour','calendar') ?></th> |
| 2115 |
<th class="manage-column" scope="col"><?php _e('Edit','calendar') ?></th> |
| 2116 |
<th class="manage-column" scope="col"><?php _e('Delete','calendar') ?></th> |
| 2117 |
</tr> |
| 2118 |
</thead> |
| 2119 |
<?php |
| 2120 |
$class = ''; |
| 2121 |
foreach ( $categories as $category ) |
| 2122 |
{ |
| 2123 |
$class = ($class == 'alternate') ? '' : 'alternate'; |
| 2124 |
?> |
| 2125 |
<tr class="<?php echo $class; ?>"> |
| 2126 |
<th scope="row"><?php echo stripslashes($category->category_id); ?></th> |
| 2127 |
<td><?php echo stripslashes($category->category_name); ?></td> |
| 2128 |
<td style="background-color:<?php echo stripslashes($category->category_colour); ?>;"> </td> |
| 2129 |
<td><a href="<?php echo bloginfo('wpurl') ?>/wp-admin/admin.php?page=calendar-categories&mode=edit&category_id=<?php echo stripslashes($category->category_id);?>" class='edit'><?php echo __('Edit','calendar'); ?></a></td> |
| 2130 |
<?php |
| 2131 |
if ($category->category_id == 1) |
| 2132 |
{ |
| 2133 |
echo '<td>'.__('N/A','calendar').'</td>'; |
| 2134 |
} |
| 2135 |
else |
| 2136 |
{ |
| 2137 |
?> |
| 2138 |
<td><a href="<?php echo wp_nonce_url(bloginfo('wpurl').'/wp-admin/admin.php?page=calendar-categories&mode=delete&category_id='.stripslashes($category->category_id), 'calendar-category_delete_'.stripslashes($category->category_id)); ?>" class="delete" onclick="return confirm('<?php echo __('Are you sure you want to delete this category?','calendar'); ?>')"><?php echo __('Delete','calendar'); ?></a></td> |
| 2139 |
<?php |
| 2140 |
} |
| 2141 |
?> |
| 2142 |
</tr> |
| 2143 |
<?php |
| 2144 |
} |
| 2145 |
?> |
| 2146 |
</table> |
| 2147 |
<?php |
| 2148 |
} |
| 2149 |
else |
| 2150 |
{ |
| 2151 |
echo '<p>'.__('There are no categories in the database - something has gone wrong!','calendar').'</p>'; |
| 2152 |
} |
| 2153 |
|
| 2154 |
?> |
| 2155 |
</div> |
| 2156 |
|
| 2157 |
<?php |
| 2158 |
} |
| 2159 |
} |
| 2160 |
|
| 2161 |
// Function to indicate the number of the day passed, eg. 1st or 2nd Sunday |
| 2162 |
function np_of_day($date) |
| 2163 |
{ |
| 2164 |
$instance = 0; |
| 2165 |
$dom = date('j',strtotime($date)); |
| 2166 |
if (($dom-7) <= 0) { $instance = 1; } |
| 2167 |
else if (($dom-7) > 0 && ($dom-7) <= 7) { $instance = 2; } |
| 2168 |
else if (($dom-7) > 7 && ($dom-7) <= 14) { $instance = 3; } |
| 2169 |
else if (($dom-7) > 14 && ($dom-7) <= 21) { $instance = 4; } |
| 2170 |
else if (($dom-7) > 21 && ($dom-7) < 28) { $instance = 5; } |
| 2171 |
return $instance; |
| 2172 |
} |
| 2173 |
|
| 2174 |
// Function to provide date of the nth day passed (eg. 2nd Sunday) |
| 2175 |
function dt_of_sun($date,$instance,$day) |
| 2176 |
{ |
| 2177 |
$plan = array(); |
| 2178 |
$plan['Mon'] = 1; |
| 2179 |
$plan['Tue'] = 2; |
| 2180 |
$plan['Wed'] = 3; |
| 2181 |
$plan['Thu'] = 4; |
| 2182 |
$plan['Fri'] = 5; |
| 2183 |
$plan['Sat'] = 6; |
| 2184 |
$plan['Sun'] = 7; |
| 2185 |
$proper_date = date('Y-m-d',strtotime($date)); |
| 2186 |
$begin_month = substr($proper_date,0,8).'01'; |
| 2187 |
$offset = $plan[date('D',strtotime($begin_month))]; |
| 2188 |
$result_day = 0; |
| 2189 |
$recon = 0; |
| 2190 |
if (($day-($offset)) < 0) { $recon = 7; } |
| 2191 |
if ($instance == 1) { $result_day = $day-($offset-1)+$recon; } |
| 2192 |
else if ($instance == 2) { $result_day = $day-($offset-1)+$recon+7; } |
| 2193 |
else if ($instance == 3) { $result_day = $day-($offset-1)+$recon+14; } |
| 2194 |
else if ($instance == 4) { $result_day = $day-($offset-1)+$recon+21; } |
| 2195 |
else if ($instance == 5) { $result_day = $day-($offset-1)+$recon+28; } |
| 2196 |
return substr($proper_date,0,8).$result_day; |
| 2197 |
} |
| 2198 |
|
| 2199 |
// Function to return a prefix which will allow the correct |
| 2200 |
// placement of arguments into the query string. |
| 2201 |
function permalink_prefix() |
| 2202 |
{ |
| 2203 |
// Get the permalink structure from WordPress |
| 2204 |
if (is_home()) { |
| 2205 |
$p_link = get_bloginfo('url'); |
| 2206 |
if ($p_link[strlen($p_link)-1] != '/') { $p_link = $p_link.'/'; } |
| 2207 |
} else { |
| 2208 |
$p_link = get_permalink(); |
| 2209 |
} |
| 2210 |
|
| 2211 |
// Based on the structure, append the appropriate ending |
| 2212 |
if (!(strstr($p_link,'?'))) { $link_part = $p_link.'?'; } else { $link_part = $p_link.'&'; } |
| 2213 |
|
| 2214 |
return $link_part; |
| 2215 |
} |
| 2216 |
|
| 2217 |
// Configure the "Next" link in the calendar |
| 2218 |
function next_link($cur_year,$cur_month,$minical = false) |
| 2219 |
{ |
| 2220 |
$mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'); |
| 2221 |
$next_year = $cur_year + 1; |
| 2222 |
|
| 2223 |
if ($cur_month == 12) |
| 2224 |
{ |
| 2225 |
if ($minical) { $rlink = ''; } else { $rlink = __('Next','calendar'); } |
| 2226 |
return '<a href="' . permalink_prefix() . 'month=jan&yr=' . $next_year . '">'.$rlink.' »</a>'; |
| 2227 |
} |
| 2228 |
else |
| 2229 |
{ |
| 2230 |
$next_month = $cur_month + 1; |
| 2231 |
$month = $mod_rewrite_months[$next_month]; |
| 2232 |
if ($minical) { $rlink = ''; } else { $rlink = __('Next','calendar'); } |
| 2233 |
return '<a href="' . permalink_prefix() . 'month='.$month.'&yr=' . $cur_year . '">'.$rlink.' »</a>'; |
| 2234 |
} |
| 2235 |
} |
| 2236 |
|
| 2237 |
// Configure the "Previous" link in the calendar |
| 2238 |
function prev_link($cur_year,$cur_month,$minical = false) |
| 2239 |
{ |
| 2240 |
$mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'); |
| 2241 |
$last_year = $cur_year - 1; |
| 2242 |
|
| 2243 |
if ($cur_month == 1) |
| 2244 |
{ |
| 2245 |
if ($minical) { $llink = ''; } else { $llink = __('Prev','calendar'); } |
| 2246 |
return '<a href="' . permalink_prefix() . 'month=dec&yr='. $last_year .'">« '.$llink.'</a>'; |
| 2247 |
} |
| 2248 |
else |
| 2249 |
{ |
| 2250 |
$next_month = $cur_month - 1; |
| 2251 |
$month = $mod_rewrite_months[$next_month]; |
| 2252 |
if ($minical) { $llink = ''; } else { $llink = __('Prev','calendar'); } |
| 2253 |
return '<a href="' . permalink_prefix() . 'month='.$month.'&yr=' . $cur_year . '">« '.$llink.'</a>'; |
| 2254 |
} |
| 2255 |
} |
| 2256 |
|
| 2257 |
// Print upcoming events |
| 2258 |
function upcoming_events($cat_list = '') |
| 2259 |
{ |
| 2260 |
global $wpdb; |
| 2261 |
|
| 2262 |
// Find out if we should be displaying upcoming events |
| 2263 |
$display = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_upcoming'",0,0); |
| 2264 |
|
| 2265 |
if ($display == 'true') |
| 2266 |
{ |
| 2267 |
// Get number of days we should go into the future |
| 2268 |
$future_days = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_upcoming_days'",0,0); |
| 2269 |
$day_count = 1; |
| 2270 |
|
| 2271 |
$output = ''; |
| 2272 |
while ($day_count < $future_days+1) |
| 2273 |
{ |
| 2274 |
list($y,$m,$d) = explode("-",date("Y-m-d",mktime($day_count*24,0,0,date("m",ctwo()),date("d",ctwo()),date("Y",ctwo())))); |
| 2275 |
$events = grab_events($y,$m,$d,'upcoming',$cat_list); |
| 2276 |
usort($events, "time_cmp"); |
| 2277 |
if (count($events) != 0) { |
| 2278 |
$output .= '<li>'.date_i18n(get_option('date_format'),mktime($day_count*24,0,0,date("m",ctwo()),date("d",ctwo()),date("Y",ctwo()))).'<ul>'; |
| 2279 |
} |
| 2280 |
foreach($events as $event) |
| 2281 |
{ |
| 2282 |
if ($event->event_time == '00:00:00') { |
| 2283 |
$time_string = ' '.__('all day','calendar'); |
| 2284 |
} |
| 2285 |
else { |
| 2286 |
$time_string = ' '.__('at','calendar').' '.date(get_option('time_format'), strtotime(stripslashes($event->event_time))); |
| 2287 |
} |
| 2288 |
$output .= '<li>'.draw_event($event).$time_string.'</li>'; |
| 2289 |
} |
| 2290 |
if (count($events) != 0) { |
| 2291 |
$output .= '</ul></li>'; |
| 2292 |
} |
| 2293 |
$day_count = $day_count+1; |
| 2294 |
} |
| 2295 |
|
| 2296 |
if ($output != '') |
| 2297 |
{ |
| 2298 |
$visual = '<ul>'; |
| 2299 |
$visual .= $output; |
| 2300 |
$visual .= '</ul>'; |
| 2301 |
return $visual; |
| 2302 |
} |
| 2303 |
} |
| 2304 |
} |
| 2305 |
|
| 2306 |
// Print todays events |
| 2307 |
function todays_events($cat_list = '') |
| 2308 |
{ |
| 2309 |
global $wpdb; |
| 2310 |
|
| 2311 |
// Find out if we should be displaying todays events |
| 2312 |
$display = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_todays'",0,0); |
| 2313 |
|
| 2314 |
if ($display == 'true') |
| 2315 |
{ |
| 2316 |
$output = '<ul>'; |
| 2317 |
$events = grab_events(date("Y",ctwo()),date("m",ctwo()),date("d",ctwo()),'todays',$cat_list); |
| 2318 |
usort($events, "time_cmp"); |
| 2319 |
foreach($events as $event) |
| 2320 |
{ |
| 2321 |
if ($event->event_time == '00:00:00') { |
| 2322 |
$time_string = ' '.__('all day','calendar'); |
| 2323 |
} |
| 2324 |
else { |
| 2325 |
$time_string = ' '.__('at','calendar').' '.date(get_option('time_format'), strtotime(stripslashes($event->event_time))); |
| 2326 |
} |
| 2327 |
$output .= '<li>'.draw_event($event).$time_string.'</li>'; |
| 2328 |
} |
| 2329 |
$output .= '</ul>'; |
| 2330 |
if (count($events) != 0) |
| 2331 |
{ |
| 2332 |
return $output; |
| 2333 |
} |
| 2334 |
} |
| 2335 |
} |
| 2336 |
|
| 2337 |
// Function to compare time in event objects |
| 2338 |
function time_cmp($a, $b) |
| 2339 |
{ |
| 2340 |
if ($a->event_time == $b->event_time) { |
| 2341 |
return 0; |
| 2342 |
} |
| 2343 |
return ($a->event_time < $b->event_time) ? -1 : 1; |
| 2344 |
} |
| 2345 |
|
| 2346 |
// Used to draw multiple events |
| 2347 |
function draw_events($events) |
| 2348 |
{ |
| 2349 |
// We need to sort arrays of objects by time |
| 2350 |
usort($events, "time_cmp"); |
| 2351 |
$output = ''; |
| 2352 |
// Now process the events |
| 2353 |
foreach($events as $event) |
| 2354 |
{ |
| 2355 |
$output .= '* '.draw_event($event).'<br />'; |
| 2356 |
} |
| 2357 |
return $output; |
| 2358 |
} |
| 2359 |
|
| 2360 |
// The widget to show the mini calendar |
| 2361 |
function widget_init_events_calendar() { |
| 2362 |
// Check for required functions |
| 2363 |
if (!function_exists('wp_register_sidebar_widget')) |
| 2364 |
return; |
| 2365 |
|
| 2366 |
function widget_events_calendar($args) { |
| 2367 |
extract($args); |
| 2368 |
$the_title = stripslashes(get_option('events_calendar_widget_title')); |
| 2369 |
$the_cats = stripslashes(get_option('events_calendar_widget_cats')); |
| 2370 |
$widget_title = empty($the_title) ? __('Calendar','calendar') : $the_title; |
| 2371 |
$the_events = minical($the_cats); |
| 2372 |
if ($the_events != '') { |
| 2373 |
echo $before_widget; |
| 2374 |
echo $before_title . $widget_title . $after_title; |
| 2375 |
echo '<br />'.$the_events; |
| 2376 |
echo $after_widget; |
| 2377 |
} |
| 2378 |
} |
| 2379 |
|
| 2380 |
function widget_events_calendar_control() { |
| 2381 |
$widget_title = stripslashes(get_option('events_calendar_widget_title')); |
| 2382 |
$widget_cats = stripslashes(get_option('events_calendar_widget_cats')); |
| 2383 |
if (isset($_POST['events_calendar_widget_title']) || isset($_POST['events_calendar_widget_cats'])) { |
| 2384 |
update_option('events_calendar_widget_title',strip_tags($_POST['events_calendar_widget_title'])); |
| 2385 |
update_option('events_calendar_widget_cats',strip_tags($_POST['events_calendar_widget_cats'])); |
| 2386 |
} |
| 2387 |
?> |
| 2388 |
<p> |
| 2389 |
<label for="events_calendar_widget_title"><?php _e('Title','calendar'); ?>:<br /> |
| 2390 |
<input class="widefat" type="text" id="events_calendar_widget_title" name="events_calendar_widget_title" value="<?php echo $widget_title; ?>"/></label> |
| 2391 |
<label for="events_calendar_widget_cats"><?php _e('Comma separated category id list','calendar'); ?>:<br /> |
| 2392 |
<input class="widefat" type="text" id="events_calendar_widget_cats" name="events_calendar_widget_cats" value="<?php echo $widget_cats; ?>"/></label> |
| 2393 |
</p> |
| 2394 |
<?php |
| 2395 |
} |
| 2396 |
|
| 2397 |
wp_register_sidebar_widget('events_calendar',__('Calendar','calendar'),'widget_events_calendar',array('description'=>'A calendar of your events')); |
| 2398 |
wp_register_widget_control('events_calendar','events_calendar','widget_events_calendar_control'); |
| 2399 |
} |
| 2400 |
|
| 2401 |
// The widget to show todays events in the sidebar |
| 2402 |
function widget_init_calendar_today() { |
| 2403 |
// Check for required functions |
| 2404 |
if (!function_exists('wp_register_sidebar_widget')) |
| 2405 |
return; |
| 2406 |
|
| 2407 |
function widget_calendar_today($args) { |
| 2408 |
extract($args); |
| 2409 |
$the_title = stripslashes(get_option('calendar_today_widget_title')); |
| 2410 |
$the_cats = stripslashes(get_option('calendar_today_widget_cats')); |
| 2411 |
$widget_title = empty($the_title) ? __('Today\'s Events','calendar') : $the_title; |
| 2412 |
$the_events = todays_events($the_cats); |
| 2413 |
if ($the_events != '') { |
| 2414 |
echo $before_widget; |
| 2415 |
echo $before_title . $widget_title . $after_title; |
| 2416 |
echo $the_events; |
| 2417 |
echo $after_widget; |
| 2418 |
} |
| 2419 |
} |
| 2420 |
|
| 2421 |
function widget_calendar_today_control() { |
| 2422 |
$widget_title = stripslashes(get_option('calendar_today_widget_title')); |
| 2423 |
$widget_cats = stripslashes(get_option('calendar_today_widget_cats')); |
| 2424 |
if (isset($_POST['calendar_today_widget_title']) || isset($_POST['calendar_today_widget_cats'])) { |
| 2425 |
update_option('calendar_today_widget_title',strip_tags($_POST['calendar_today_widget_title'])); |
| 2426 |
update_option('calendar_today_widget_cats',strip_tags($_POST['calendar_today_widget_cats'])); |
| 2427 |
} |
| 2428 |
?> |
| 2429 |
<p> |
| 2430 |
<label for="calendar_today_widget_title"><?php _e('Title','calendar'); ?>:<br /> |
| 2431 |
<input class="widefat" type="text" id="calendar_today_widget_title" name="calendar_today_widget_title" value="<?php echo $widget_title; ?>"/></label> |
| 2432 |
<label for="calendar_today_widget_cats"><?php _e('Comma separated category id list','calendar'); ?>:<br /> |
| 2433 |
<input class="widefat" type="text" id="calendar_today_widget_cats" name="calendar_today_widget_cats" value="<?php echo $widget_cats; ?>"/></label> |
| 2434 |
</p> |
| 2435 |
<?php |
| 2436 |
} |
| 2437 |
|
| 2438 |
wp_register_sidebar_widget('todays_events_calendar',__('Today\'s Events','calendar'),'widget_calendar_today',array('description'=>'A list of your events today')); |
| 2439 |
wp_register_widget_control('todays_events_calendar','todays_events_calendar','widget_calendar_today_control'); |
| 2440 |
} |
| 2441 |
|
| 2442 |
// The widget to show todays events in the sidebar |
| 2443 |
function widget_init_calendar_upcoming() { |
| 2444 |
// Check for required functions |
| 2445 |
if (!function_exists('wp_register_sidebar_widget')) |
| 2446 |
return; |
| 2447 |
|
| 2448 |
function widget_calendar_upcoming($args) { |
| 2449 |
extract($args); |
| 2450 |
$the_title = stripslashes(get_option('calendar_upcoming_widget_title')); |
| 2451 |
$the_cats = stripslashes(get_option('calendar_upcoming_widget_cats')); |
| 2452 |
$widget_title = empty($the_title) ? __('Upcoming Events','calendar') : $the_title; |
| 2453 |
$the_events = upcoming_events($the_cats); |
| 2454 |
if ($the_events != '') { |
| 2455 |
echo $before_widget; |
| 2456 |
echo $before_title . $widget_title . $after_title; |
| 2457 |
echo $the_events; |
| 2458 |
echo $after_widget; |
| 2459 |
} |
| 2460 |
} |
| 2461 |
|
| 2462 |
function widget_calendar_upcoming_control() { |
| 2463 |
$widget_title = stripslashes(get_option('calendar_upcoming_widget_title')); |
| 2464 |
$widget_cats = stripslashes(get_option('calendar_upcoming_widget_cats')); |
| 2465 |
if (isset($_POST['calendar_upcoming_widget_title']) || isset($_POST['calendar_upcoming_widget_cats'])) { |
| 2466 |
update_option('calendar_upcoming_widget_title',strip_tags($_POST['calendar_upcoming_widget_title'])); |
| 2467 |
update_option('calendar_upcoming_widget_cats',strip_tags($_POST['calendar_upcoming_widget_cats'])); |
| 2468 |
} |
| 2469 |
?> |
| 2470 |
<p> |
| 2471 |
<label for="calendar_upcoming_widget_title"><?php _e('Title','calendar'); ?>:<br /> |
| 2472 |
<input class="widefat" type="text" id="calendar_upcoming_widget_title" name="calendar_upcoming_widget_title" value="<?php echo $widget_title; ?>"/></label> |
| 2473 |
<label for="calendar_upcoming_widget_cats"><?php _e('Comma separated category id list','calendar'); ?>:<br /> |
| 2474 |
<input class="widefat" type="text" id="calendar_upcoming_widget_cats" name="calendar_upcoming_widget_cats" value="<?php echo $widget_cats; ?>"/></label> |
| 2475 |
</p> |
| 2476 |
<?php |
| 2477 |
} |
| 2478 |
|
| 2479 |
wp_register_sidebar_widget('upcoming_events_calendar',__('Upcoming Events','calendar'),'widget_calendar_upcoming',array('description'=>'A list of your upcoming events')); |
| 2480 |
wp_register_widget_control('upcoming_events_calendar','upcoming_events_calendar','widget_calendar_upcoming_control'); |
| 2481 |
} |
| 2482 |
|
| 2483 |
// Used to draw an event to the screen |
| 2484 |
function draw_event($event) |
| 2485 |
{ |
| 2486 |
global $wpdb; |
| 2487 |
|
| 2488 |
// Before we do anything we want to know if we |
| 2489 |
// should display the author and/or show categories. |
| 2490 |
// We check for this later |
| 2491 |
$display_author = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_author'",0,0); |
| 2492 |
$show_cat = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='enable_categories'",0,0); |
| 2493 |
$style = ''; |
| 2494 |
if ($show_cat == 'true') |
| 2495 |
{ |
| 2496 |
$sql = $wpdb->prepare("SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=%d",$event->event_category); |
| 2497 |
$cat_details = $wpdb->get_row($sql); |
| 2498 |
$style = 'style="background-color:'.stripslashes($cat_details->category_colour).';"'; |
| 2499 |
} |
| 2500 |
|
| 2501 |
$header_details = '<span class="event-title" '.$style.'>'.stripslashes($event->event_title).'</span><br /> |
| 2502 |
<span class="event-title-break"></span><br />'; |
| 2503 |
if ($event->event_time != "00:00:00") |
| 2504 |
{ |
| 2505 |
$header_details .= '<strong>'.__('Time','calendar').':</strong> ' . date(get_option('time_format'), strtotime(stripslashes($event->event_time))) . '<br />'; |
| 2506 |
} |
| 2507 |
if ($display_author == 'true') |
| 2508 |
{ |
| 2509 |
$e = get_userdata(stripslashes($event->event_author)); |
| 2510 |
$header_details .= '<strong>'.__('Posted by', 'calendar').':</strong> '.$e->display_name.'<br />'; |
| 2511 |
} |
| 2512 |
if ($display_author == 'true' || $event->event_time != "00:00:00") |
| 2513 |
{ |
| 2514 |
$header_details .= '<span class="event-content-break"></span><br />'; |
| 2515 |
} |
| 2516 |
if ($event->event_link != '') { $linky = stripslashes($event->event_link); } |
| 2517 |
else { $linky = '#'; } |
| 2518 |
|
| 2519 |
$linky = apply_filters('modify_calendar_link', $linky, $event); |
| 2520 |
|
| 2521 |
$details = '<span class="calnk"><a href="'.$linky.'" '.$style.'>' . stripslashes($event->event_title) . '<span '.$style.'>' . $header_details . '' . stripslashes($event->event_desc) . '</span></a></span>'; |
| 2522 |
|
| 2523 |
return $details; |
| 2524 |
} |
| 2525 |
|
| 2526 |
// Grab all events for the requested date from calendar |
| 2527 |
function grab_events($y,$m,$d,$typing,$cat_list = '') |
| 2528 |
{ |
| 2529 |
global $wpdb; |
| 2530 |
|
| 2531 |
$arr_events = array(); |
| 2532 |
|
| 2533 |
// Get the date format right |
| 2534 |
$date = $y . '-' . $m . '-' . $d; |
| 2535 |
|
| 2536 |
// Format the category list |
| 2537 |
if ($cat_list == '') { $cat_sql = ''; } |
| 2538 |
else { $cat_sql = 'AND event_category in ('.$cat_list.')'; } |
| 2539 |
|
| 2540 |
// The collated SQL code |
| 2541 |
$sql = "SELECT a.*,'Normal' AS type FROM " . WP_CALENDAR_TABLE . " AS a WHERE a.event_begin <= '$date' AND a.event_end >= '$date' AND a.event_recur = 'S' ".$cat_sql." |
| 2542 |
UNION ALL |
| 2543 |
SELECT b.*,'Yearly' AS type FROM " . WP_CALENDAR_TABLE . " AS b WHERE b.event_recur = 'Y' AND EXTRACT(YEAR FROM '$date') >= EXTRACT(YEAR FROM b.event_begin) AND b.event_repeats = 0 ".$cat_sql." |
| 2544 |
UNION ALL |
| 2545 |
SELECT c.*,'Yearly' AS type FROM " . WP_CALENDAR_TABLE . " AS c WHERE c.event_recur = 'Y' AND EXTRACT(YEAR FROM '$date') >= EXTRACT(YEAR FROM c.event_begin) AND c.event_repeats != 0 AND (EXTRACT(YEAR FROM '$date')-EXTRACT(YEAR FROM c.event_begin)) <= c.event_repeats ".$cat_sql." |
| 2546 |
UNION ALL |
| 2547 |
SELECT d.*,'Monthly' AS type FROM " . WP_CALENDAR_TABLE . " AS d WHERE d.event_recur = 'M' AND EXTRACT(YEAR FROM '$date') >= EXTRACT(YEAR FROM d.event_begin) AND d.event_repeats = 0 ".$cat_sql." |
| 2548 |
UNION ALL |
| 2549 |
SELECT e.*,'Monthly' AS type FROM " . WP_CALENDAR_TABLE . " AS e WHERE e.event_recur = 'M' AND EXTRACT(YEAR FROM '$date') >= EXTRACT(YEAR FROM e.event_begin) AND e.event_repeats != 0 AND (PERIOD_DIFF(EXTRACT(YEAR_MONTH FROM '$date'),EXTRACT(YEAR_MONTH FROM e.event_begin))) <= e.event_repeats ".$cat_sql." |
| 2550 |
UNION ALL |
| 2551 |
SELECT f.*,'MonthSun' AS type FROM " . WP_CALENDAR_TABLE . " AS f WHERE f.event_recur = 'U' AND EXTRACT(YEAR FROM '$date') >= EXTRACT(YEAR FROM f.event_begin) AND f.event_repeats = 0 ".$cat_sql." |
| 2552 |
UNION ALL |
| 2553 |
SELECT g.*,'MonthSun' AS type FROM " . WP_CALENDAR_TABLE . " AS g WHERE g.event_recur = 'U' AND EXTRACT(YEAR FROM '$date') >= EXTRACT(YEAR FROM g.event_begin) AND g.event_repeats != 0 AND (PERIOD_DIFF(EXTRACT(YEAR_MONTH FROM '$date'),EXTRACT(YEAR_MONTH FROM g.event_begin))) <= g.event_repeats ".$cat_sql." |
| 2554 |
UNION ALL |
| 2555 |
SELECT h.*,'Weekly' AS type FROM " . WP_CALENDAR_TABLE . " AS h WHERE h.event_recur = 'W' AND '$date' >= h.event_begin AND h.event_repeats = 0 ".$cat_sql." |
| 2556 |
UNION ALL |
| 2557 |
SELECT i.*,'Weekly' AS type FROM " . WP_CALENDAR_TABLE . " AS i WHERE i.event_recur = 'W' AND '$date' >= i.event_begin AND i.event_repeats != 0 AND (i.event_repeats*7) >= (TO_DAYS('$date') - TO_DAYS(i.event_end)) ".$cat_sql." |
| 2558 |
ORDER BY event_id"; |
| 2559 |
|
| 2560 |
// Run the collated code |
| 2561 |
$events =$wpdb->get_results($sql); |
| 2562 |
if (!empty($events)) |
| 2563 |
{ |
| 2564 |
foreach($events as $event) |
| 2565 |
{ |
| 2566 |
if ($event->type == 'Normal') |
| 2567 |
{ |
| 2568 |
array_push($arr_events, $event); |
| 2569 |
} |
| 2570 |
else if ($event->type == 'Yearly') |
| 2571 |
{ |
| 2572 |
// This is going to get complex so lets setup what we would place in for |
| 2573 |
// an event so we can drop it in with ease |
| 2574 |
|
| 2575 |
// Technically we don't care about the years, but we need to find out if the |
| 2576 |
// event spans the turn of a year so we can deal with it appropriately. |
| 2577 |
$year_begin = date('Y',strtotime($event->event_begin)); |
| 2578 |
$year_end = date('Y',strtotime($event->event_end)); |
| 2579 |
|
| 2580 |
if ($year_begin == $year_end) |
| 2581 |
{ |
| 2582 |
if (date('m-d',strtotime($event->event_begin)) <= date('m-d',strtotime($date)) && |
| 2583 |
date('m-d',strtotime($event->event_end)) >= date('m-d',strtotime($date))) |
| 2584 |
{ |
| 2585 |
array_push($arr_events, $event); |
| 2586 |
} |
| 2587 |
} |
| 2588 |
else if ($year_begin < $year_end) |
| 2589 |
{ |
| 2590 |
if (date('m-d',strtotime($event->event_begin)) <= date('m-d',strtotime($date)) || |
| 2591 |
date('m-d',strtotime($event->event_end)) >= date('m-d',strtotime($date))) |
| 2592 |
{ |
| 2593 |
array_push($arr_events, $event); |
| 2594 |
} |
| 2595 |
} |
| 2596 |
} |
| 2597 |
else if ($event->type == 'Monthly') |
| 2598 |
{ |
| 2599 |
// This is going to get complex so lets setup what we would place in for |
| 2600 |
// an event so we can drop it in with ease |
| 2601 |
|
| 2602 |
// Technically we don't care about the years or months, but we need to find out if the |
| 2603 |
// event spans the turn of a year or month so we can deal with it appropriately. |
| 2604 |
$month_begin = date('m',strtotime($event->event_begin)); |
| 2605 |
$month_end = date('m',strtotime($event->event_end)); |
| 2606 |
|
| 2607 |
if (($month_begin == $month_end) && (strtotime($event->event_begin) <= strtotime($date))) |
| 2608 |
{ |
| 2609 |
if (date('d',strtotime($event->event_begin)) <= date('d',strtotime($date)) && |
| 2610 |
date('d',strtotime($event->event_end)) >= date('d',strtotime($date))) |
| 2611 |
{ |
| 2612 |
array_push($arr_events, $event); |
| 2613 |
} |
| 2614 |
} |
| 2615 |
else if (($month_begin < $month_end) && (strtotime($event->event_begin) <= strtotime($date))) |
| 2616 |
{ |
| 2617 |
if ( ($event->event_begin <= date('Y-m-d',strtotime($date))) && (date('d',strtotime($event->event_begin)) <= date('d',strtotime($date)) || |
| 2618 |
date('d',strtotime($event->event_end)) >= date('d',strtotime($date))) ) |
| 2619 |
{ |
| 2620 |
array_push($arr_events, $event); |
| 2621 |
} |
| 2622 |
} |
| 2623 |
} |
| 2624 |
else if ($event->type == 'MonthSun') |
| 2625 |
{ |
| 2626 |
// This used to be complex but writing the dt_of_sun() function helped loads! |
| 2627 |
|
| 2628 |
// Technically we don't care about the years or months, but we need to find out if the |
| 2629 |
// event spans the turn of a year or month so we can deal with it appropriately. |
| 2630 |
$month_begin = date('m',strtotime($event->event_begin)); |
| 2631 |
$month_end = date('m',strtotime($event->event_end)); |
| 2632 |
|
| 2633 |
// Setup some variables and get some values |
| 2634 |
$dow = date('w',strtotime($event->event_begin)); |
| 2635 |
if ($dow == 0) { $dow = 7; } |
| 2636 |
$start_ent_this = dt_of_sun($date,np_of_day($event->event_begin),$dow); |
| 2637 |
$start_ent_prev = dt_of_sun(date('Y-m-d',strtotime($date.'-1 month')),np_of_day($event->event_begin),$dow); |
| 2638 |
$len_ent = strtotime($event->event_end)-strtotime($event->event_begin); |
| 2639 |
|
| 2640 |
// The grunt work |
| 2641 |
if (($month_begin == $month_end) && (strtotime($event->event_begin) <= strtotime($date))) |
| 2642 |
{ |
| 2643 |
// The checks |
| 2644 |
if (strtotime($event->event_begin) <= strtotime($date) && strtotime($event->event_end) >= strtotime($date)) // Handle the first occurance |
| 2645 |
{ |
| 2646 |
array_push($arr_events, $event); |
| 2647 |
} |
| 2648 |
else if (strtotime($start_ent_this) <= strtotime($date) && strtotime($date) <= strtotime($start_ent_this)+$len_ent) // Now remaining items |
| 2649 |
{ |
| 2650 |
array_push($arr_events, $event); |
| 2651 |
} |
| 2652 |
} |
| 2653 |
else if (($month_begin < $month_end) && (strtotime($event->event_begin) <= strtotime($date))) |
| 2654 |
{ |
| 2655 |
// The checks |
| 2656 |
if (strtotime($event->event_begin) <= strtotime($date) && strtotime($event->event_end) >= strtotime($date)) // Handle the first occurance |
| 2657 |
{ |
| 2658 |
array_push($arr_events, $event); |
| 2659 |
} |
| 2660 |
else if (strtotime($start_ent_prev) <= strtotime($date) && strtotime($date) <= strtotime($start_ent_prev)+$len_ent) // Remaining items from prev month |
| 2661 |
{ |
| 2662 |
array_push($arr_events, $event); |
| 2663 |
} |
| 2664 |
else if (strtotime($start_ent_this) <= strtotime($date) && strtotime($date) <= strtotime($start_ent_this)+$len_ent) // Remaining items starting this month |
| 2665 |
{ |
| 2666 |
array_push($arr_events, $event); |
| 2667 |
} |
| 2668 |
} |
| 2669 |
} |
| 2670 |
else if ($event->type == 'Weekly') |
| 2671 |
{ |
| 2672 |
// This is going to get complex so lets setup what we would place in for |
| 2673 |
// an event so we can drop it in with ease |
| 2674 |
|
| 2675 |
// Now we are going to check to see what day the original event |
| 2676 |
// fell on and see if the current date is both after it and on |
| 2677 |
// the correct day. If it is, display the event! |
| 2678 |
$day_start_event = date('D',strtotime($event->event_begin)); |
| 2679 |
$day_end_event = date('D',strtotime($event->event_end)); |
| 2680 |
$current_day = date('D',strtotime($date)); |
| 2681 |
|
| 2682 |
$plan = array(); |
| 2683 |
$plan['Mon'] = 1; |
| 2684 |
$plan['Tue'] = 2; |
| 2685 |
$plan['Wed'] = 3; |
| 2686 |
$plan['Thu'] = 4; |
| 2687 |
$plan['Fri'] = 5; |
| 2688 |
$plan['Sat'] = 6; |
| 2689 |
$plan['Sun'] = 7; |
| 2690 |
|
| 2691 |
if ($plan[$day_start_event] > $plan[$day_end_event]) |
| 2692 |
{ |
| 2693 |
if (($plan[$day_start_event] <= $plan[$current_day]) || ($plan[$current_day] <= $plan[$day_end_event])) |
| 2694 |
{ |
| 2695 |
array_push($arr_events, $event); |
| 2696 |
} |
| 2697 |
} |
| 2698 |
else if (($plan[$day_start_event] < $plan[$day_end_event]) || ($plan[$day_start_event]== $plan[$day_end_event])) |
| 2699 |
{ |
| 2700 |
if (($plan[$day_start_event] <= $plan[$current_day]) && ($plan[$current_day] <= $plan[$day_end_event])) |
| 2701 |
{ |
| 2702 |
array_push($arr_events, $event); |
| 2703 |
} |
| 2704 |
} |
| 2705 |
} |
| 2706 |
} |
| 2707 |
} |
| 2708 |
|
| 2709 |
return $arr_events; |
| 2710 |
} |
| 2711 |
|
| 2712 |
// Setup comparison functions for building the calendar later |
| 2713 |
function calendar_month_comparison($month) |
| 2714 |
{ |
| 2715 |
$get_year = (isset($_GET['yr']) ? $_GET['yr'] : null); |
| 2716 |
$get_month = (isset($_GET['month']) ? $_GET['month'] : null); |
| 2717 |
$current_month = strtolower(date("M", ctwo())); |
| 2718 |
if (isset($get_year) && isset($get_month)) |
| 2719 |
{ |
| 2720 |
if ($month == $get_month) |
| 2721 |
{ |
| 2722 |
return ' selected="selected"'; |
| 2723 |
} |
| 2724 |
} |
| 2725 |
elseif ($month == $current_month) |
| 2726 |
{ |
| 2727 |
return ' selected="selected"'; |
| 2728 |
} |
| 2729 |
} |
| 2730 |
function calendar_year_comparison($year) |
| 2731 |
{ |
| 2732 |
$get_year = (isset($_GET['yr']) ? $_GET['yr'] : null); |
| 2733 |
$get_month = (isset($_GET['month']) ? $_GET['month'] : null); |
| 2734 |
$current_year = strtolower(date("Y", ctwo())); |
| 2735 |
if (isset($get_year) && isset($get_month)) |
| 2736 |
{ |
| 2737 |
if ($year == $get_year) |
| 2738 |
{ |
| 2739 |
return ' selected="selected"'; |
| 2740 |
} |
| 2741 |
} |
| 2742 |
else if ($year == $current_year) |
| 2743 |
{ |
| 2744 |
return ' selected="selected"'; |
| 2745 |
} |
| 2746 |
} |
| 2747 |
|
| 2748 |
// Actually do the printing of the calendar |
| 2749 |
// Compared to searching for and displaying events |
| 2750 |
// this bit is really rather easy! |
| 2751 |
function calendar($cat_list = '') |
| 2752 |
{ |
| 2753 |
global $wpdb; |
| 2754 |
|
| 2755 |
$get_year = (isset($_GET['yr']) ? $_GET['yr'] : null); |
| 2756 |
$get_month = (isset($_GET['month']) ? $_GET['month'] : null); |
| 2757 |
|
| 2758 |
// Deal with the week not starting on a monday |
| 2759 |
if (get_option('start_of_week') == 0) |
| 2760 |
{ |
| 2761 |
$name_days = array(1=>__('Sunday','calendar'),__('Monday','calendar'),__('Tuesday','calendar'),__('Wednesday','calendar'),__('Thursday','calendar'),__('Friday','calendar'),__('Saturday','calendar')); |
| 2762 |
} |
| 2763 |
// Choose Monday if anything other than Sunday is set |
| 2764 |
else |
| 2765 |
{ |
| 2766 |
$name_days = array(1=>__('Monday','calendar'),__('Tuesday','calendar'),__('Wednesday','calendar'),__('Thursday','calendar'),__('Friday','calendar'),__('Saturday','calendar'),__('Sunday','calendar')); |
| 2767 |
} |
| 2768 |
|
| 2769 |
// Carry on with the script |
| 2770 |
$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')); |
| 2771 |
|
| 2772 |
// If we don't pass arguments we want a calendar that is relevant to today |
| 2773 |
if (empty($get_month) || empty($get_year)) |
| 2774 |
{ |
| 2775 |
$c_year = date("Y",ctwo()); |
| 2776 |
$c_month = date("m",ctwo()); |
| 2777 |
$c_day = date("d",ctwo()); |
| 2778 |
} |
| 2779 |
|
| 2780 |
// Years get funny if we exceed 3000, so we use this check |
| 2781 |
if (isset($get_year)) |
| 2782 |
{ |
| 2783 |
if ($get_year <= 3000 && $get_year >= 0 && (int)$get_year != 0) |
| 2784 |
{ |
| 2785 |
// This is just plain nasty and all because of permalinks |
| 2786 |
// which are no longer used, this will be cleaned up soon |
| 2787 |
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 == 'sep' || $get_month == 'oct' || $get_month == 'nov' || $get_month == 'dec') |
| 2788 |
{ |
| 2789 |
|
| 2790 |
// Again nasty code to map permalinks into something |
| 2791 |
// databases can understand. This will be cleaned up |
| 2792 |
$c_year = $wpdb->prepare("%d",$get_year); |
| 2793 |
if ($get_month == 'jan') { $t_month = 1; } |
| 2794 |
else if ($get_month == 'feb') { $t_month = 2; } |
| 2795 |
else if ($get_month == 'mar') { $t_month = 3; } |
| 2796 |
else if ($get_month == 'apr') { $t_month = 4; } |
| 2797 |
else if ($get_month == 'may') { $t_month = 5; } |
| 2798 |
else if ($get_month == 'jun') { $t_month = 6; } |
| 2799 |
else if ($get_month == 'jul') { $t_month = 7; } |
| 2800 |
else if ($get_month == 'aug') { $t_month = 8; } |
| 2801 |
else if ($get_month == 'sep') { $t_month = 9; } |
| 2802 |
else if ($get_month == 'oct') { $t_month = 10; } |
| 2803 |
else if ($get_month == 'nov') { $t_month = 11; } |
| 2804 |
else if ($get_month == 'dec') { $t_month = 12; } |
| 2805 |
$c_month = $t_month; |
| 2806 |
$c_day = date("d",ctwo()); |
| 2807 |
} |
| 2808 |
// No valid month causes the calendar to default to today |
| 2809 |
else |
| 2810 |
{ |
| 2811 |
$c_year = date("Y",ctwo()); |
| 2812 |
$c_month = date("m",ctwo()); |
| 2813 |
$c_day = date("d",ctwo()); |
| 2814 |
} |
| 2815 |
} |
| 2816 |
} |
| 2817 |
// No valid year causes the calendar to default to today |
| 2818 |
else |
| 2819 |
{ |
| 2820 |
$c_year = date("Y",ctwo()); |
| 2821 |
$c_month = date("m",ctwo()); |
| 2822 |
$c_day = date("d",ctwo()); |
| 2823 |
} |
| 2824 |
|
| 2825 |
// Fix the days of the week if week start is not on a monday |
| 2826 |
if (get_option('start_of_week') == 0) |
| 2827 |
{ |
| 2828 |
$first_weekday = date("w",mktime(0,0,0,$c_month,1,$c_year)); |
| 2829 |
$first_weekday = ($first_weekday==0?1:$first_weekday+1); |
| 2830 |
} |
| 2831 |
// Otherwise assume the week starts on a Monday. Anything other |
| 2832 |
// than Sunday or Monday is just plain odd |
| 2833 |
else |
| 2834 |
{ |
| 2835 |
$first_weekday = date("w",mktime(0,0,0,$c_month,1,$c_year)); |
| 2836 |
$first_weekday = ($first_weekday==0?7:$first_weekday); |
| 2837 |
} |
| 2838 |
|
| 2839 |
$days_in_month = date("t", mktime (0,0,0,$c_month,1,$c_year)); |
| 2840 |
|
| 2841 |
// Start the table and add the header and naviagtion |
| 2842 |
$calendar_body = ''; |
| 2843 |
$calendar_body .= ' |
| 2844 |
<table cellspacing="1" cellpadding="0" class="calendar-table"> |
| 2845 |
'; |
| 2846 |
|
| 2847 |
// We want to know if we should display the date switcher |
| 2848 |
$date_switcher = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_jump'",0,0); |
| 2849 |
|
| 2850 |
if ($date_switcher == 'true') |
| 2851 |
{ |
| 2852 |
$calendar_body .= '<tr> |
| 2853 |
<td colspan="7" class="calendar-date-switcher"> |
| 2854 |
<form method="get" action="'.htmlspecialchars($_SERVER['REQUEST_URI']).'"> |
| 2855 |
'; |
| 2856 |
$qsa = array(); |
| 2857 |
parse_str($_SERVER['QUERY_STRING'],$qsa); |
| 2858 |
foreach ($qsa as $name => $argument) |
| 2859 |
{ |
| 2860 |
if ($name != 'month' && $name != 'yr' && preg_match("/^[A-Za-z0-9\-\_]+$/",$name) && preg_match("/^[A-Za-z0-9\-\_]+$/",$argument)) |
| 2861 |
{ |
| 2862 |
$calendar_body .= '<input type="hidden" name="'.strip_tags($name).'" value="'.strip_tags($argument).'" /> |
| 2863 |
'; |
| 2864 |
} |
| 2865 |
} |
| 2866 |
|
| 2867 |
// We build the months in the switcher |
| 2868 |
$calendar_body .= ' |
| 2869 |
'.__('Month','calendar').': <select name="month" style="width:100px;"> |
| 2870 |
<option value="jan"'.calendar_month_comparison('jan').'>'.__('January','calendar').'</option> |
| 2871 |
<option value="feb"'.calendar_month_comparison('feb').'>'.__('February','calendar').'</option> |
| 2872 |
<option value="mar"'.calendar_month_comparison('mar').'>'.__('March','calendar').'</option> |
| 2873 |
<option value="apr"'.calendar_month_comparison('apr').'>'.__('April','calendar').'</option> |
| 2874 |
<option value="may"'.calendar_month_comparison('may').'>'.__('May','calendar').'</option> |
| 2875 |
<option value="jun"'.calendar_month_comparison('jun').'>'.__('June','calendar').'</option> |
| 2876 |
<option value="jul"'.calendar_month_comparison('jul').'>'.__('July','calendar').'</option> |
| 2877 |
<option value="aug"'.calendar_month_comparison('aug').'>'.__('August','calendar').'</option> |
| 2878 |
<option value="sep"'.calendar_month_comparison('sep').'>'.__('September','calendar').'</option> |
| 2879 |
<option value="oct"'.calendar_month_comparison('oct').'>'.__('October','calendar').'</option> |
| 2880 |
<option value="nov"'.calendar_month_comparison('nov').'>'.__('November','calendar').'</option> |
| 2881 |
<option value="dec"'.calendar_month_comparison('dec').'>'.__('December','calendar').'</option> |
| 2882 |
</select> |
| 2883 |
'.__('Year','calendar').': <select name="yr" style="width:60px;"> |
| 2884 |
'; |
| 2885 |
|
| 2886 |
// The year builder is string mania. If you can make sense of this, you know your PHP! |
| 2887 |
|
| 2888 |
$past = 30; |
| 2889 |
$future = 30; |
| 2890 |
$fut = 1; |
| 2891 |
$f = ''; |
| 2892 |
$p = ''; |
| 2893 |
while ($past > 0) |
| 2894 |
{ |
| 2895 |
$p .= ' <option value="'; |
| 2896 |
$p .= date("Y",ctwo())-$past; |
| 2897 |
$p .= '"'.calendar_year_comparison(date("Y",ctwo())-$past).'>'; |
| 2898 |
$p .= date("Y",ctwo())-$past.'</option> |
| 2899 |
'; |
| 2900 |
$past = $past - 1; |
| 2901 |
} |
| 2902 |
while ($fut < $future) |
| 2903 |
{ |
| 2904 |
$f .= ' <option value="'; |
| 2905 |
$f .= date("Y",ctwo())+$fut; |
| 2906 |
$f .= '"'.calendar_year_comparison(date("Y",ctwo())+$fut).'>'; |
| 2907 |
$f .= date("Y",ctwo())+$fut.'</option> |
| 2908 |
'; |
| 2909 |
$fut = $fut + 1; |
| 2910 |
} |
| 2911 |
$calendar_body .= $p; |
| 2912 |
$calendar_body .= ' <option value="'.date("Y",ctwo()).'"'.calendar_year_comparison(date("Y",ctwo())).'>'.date("Y",ctwo()).'</option> |
| 2913 |
'; |
| 2914 |
$calendar_body .= $f; |
| 2915 |
$calendar_body .= '</select> |
| 2916 |
<input type="submit" value="'.__('Go','calendar').'" /> |
| 2917 |
</form> |
| 2918 |
</td> |
| 2919 |
</tr> |
| 2920 |
'; |
| 2921 |
} |
| 2922 |
|
| 2923 |
// The header of the calendar table and the links. Note calls to link functions |
| 2924 |
$calendar_body .= '<tr> |
| 2925 |
<td colspan="7" class="calendar-heading"> |
| 2926 |
<table border="0" cellpadding="0" cellspacing="0" width="100%"> |
| 2927 |
<tr> |
| 2928 |
<td class="calendar-prev">' . prev_link($c_year,$c_month) . '</td> |
| 2929 |
<td class="calendar-month">'.$name_months[(int)$c_month].' '.$c_year.'</td> |
| 2930 |
<td class="calendar-next">' . next_link($c_year,$c_month) . '</td> |
| 2931 |
</tr> |
| 2932 |
</table> |
| 2933 |
</td> |
| 2934 |
</tr> |
| 2935 |
'; |
| 2936 |
|
| 2937 |
// Print the headings of the days of the week |
| 2938 |
$calendar_body .= '<tr> |
| 2939 |
'; |
| 2940 |
for ($i=1; $i<=7; $i++) |
| 2941 |
{ |
| 2942 |
// Colours need to be different if the starting day of the week is different |
| 2943 |
if (get_option('start_of_week') == 0) |
| 2944 |
{ |
| 2945 |
$calendar_body .= ' <td class="'.($i<7&&$i>1?'normal-day-heading':'weekend-heading').'">'.$name_days[$i].'</td> |
| 2946 |
'; |
| 2947 |
} |
| 2948 |
else |
| 2949 |
{ |
| 2950 |
$calendar_body .= ' <td class="'.($i<6?'normal-day-heading':'weekend-heading').'">'.$name_days[$i].'</td> |
| 2951 |
'; |
| 2952 |
} |
| 2953 |
} |
| 2954 |
$calendar_body .= '</tr> |
| 2955 |
'; |
| 2956 |
$go = FALSE; |
| 2957 |
for ($i=1; $i<=$days_in_month;) |
| 2958 |
{ |
| 2959 |
$calendar_body .= '<tr> |
| 2960 |
'; |
| 2961 |
for ($ii=1; $ii<=7; $ii++) |
| 2962 |
{ |
| 2963 |
if ($ii==$first_weekday && $i==1) |
| 2964 |
{ |
| 2965 |
$go = TRUE; |
| 2966 |
} |
| 2967 |
elseif ($i > $days_in_month ) |
| 2968 |
{ |
| 2969 |
$go = FALSE; |
| 2970 |
} |
| 2971 |
if ($go) |
| 2972 |
{ |
| 2973 |
// Colours again, this time for the day numbers |
| 2974 |
if (get_option('start_of_week') == 0) |
| 2975 |
{ |
| 2976 |
// This bit of code is for styles believe it or not. |
| 2977 |
$grabbed_events = grab_events($c_year,$c_month,$i,'calendar',$cat_list); |
| 2978 |
$no_events_class = ''; |
| 2979 |
if (!count($grabbed_events)) |
| 2980 |
{ |
| 2981 |
$no_events_class = ' no-events'; |
| 2982 |
} |
| 2983 |
$calendar_body .= ' <td class="'.(date("Ymd", mktime (0,0,0,$c_month,$i,$c_year))==date("Ymd",ctwo())?'current-day':'day-with-date').$no_events_class.'"><span '.($ii<7&&$ii>1?'':'class="weekend"').'>'.$i++.'</span><span class="event"><br />' . draw_events($grabbed_events) . '</span></td> |
| 2984 |
'; |
| 2985 |
} |
| 2986 |
else |
| 2987 |
{ |
| 2988 |
$grabbed_events = grab_events($c_year,$c_month,$i,'calendar',$cat_list); |
| 2989 |
$no_events_class = ''; |
| 2990 |
if (!count($grabbed_events)) |
| 2991 |
{ |
| 2992 |
$no_events_class = ' no-events'; |
| 2993 |
} |
| 2994 |
$calendar_body .= ' <td class="'.(date("Ymd", mktime (0,0,0,$c_month,$i,$c_year))==date("Ymd",ctwo())?'current-day':'day-with-date').$no_events_class.'"><span '.($ii<6?'':'class="weekend"').'>'.$i++.'</span><span class="event"><br />' . draw_events($grabbed_events) . '</span></td> |
| 2995 |
'; |
| 2996 |
} |
| 2997 |
} |
| 2998 |
else |
| 2999 |
{ |
| 3000 |
$calendar_body .= ' <td class="day-without-date"> </td> |
| 3001 |
'; |
| 3002 |
} |
| 3003 |
} |
| 3004 |
$calendar_body .= '</tr> |
| 3005 |
'; |
| 3006 |
} |
| 3007 |
$calendar_body .= '</table> |
| 3008 |
'; |
| 3009 |
$show_cat = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='enable_categories'",0,0); |
| 3010 |
|
| 3011 |
if ($show_cat == 'true') |
| 3012 |
{ |
| 3013 |
$cat_filter_sql = ''; |
| 3014 |
if ($cat_list != '') { |
| 3015 |
$cat_filter_sql = 'where category_id in ('.$cat_list.') '; |
| 3016 |
} |
| 3017 |
$sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " ".$cat_filter_sql."ORDER BY category_name ASC"; |
| 3018 |
$cat_details = $wpdb->get_results($sql); |
| 3019 |
$calendar_body .= '<table class="cat-key"> |
| 3020 |
<tr><td colspan="2" class="cat-key-cell"><strong>'.__('Category Key','calendar').'</strong></td></tr> |
| 3021 |
'; |
| 3022 |
foreach($cat_details as $cat_detail) |
| 3023 |
{ |
| 3024 |
$calendar_body .= '<tr><td style="background-color:'.$cat_detail->category_colour.'; width:20px; height:20px;" class="cat-key-cell"></td> |
| 3025 |
<td class="cat-key-cell"> '.$cat_detail->category_name.'</td></tr>'; |
| 3026 |
} |
| 3027 |
$calendar_body .= '</table> |
| 3028 |
'; |
| 3029 |
} |
| 3030 |
|
| 3031 |
// A little link to yours truly |
| 3032 |
$link_approved = 'false'; |
| 3033 |
$link_approved_results = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='show_attribution_link'"); |
| 3034 |
foreach ($link_approved_results as $link_approved_item) |
| 3035 |
{ |
| 3036 |
if ($link_approved_item->config_value == 'true') |
| 3037 |
{ |
| 3038 |
$link_approved = 'true'; |
| 3039 |
} |
| 3040 |
} |
| 3041 |
if ($link_approved == 'true') { |
| 3042 |
$linkback_url = '<div class="kjo-link" style="visibility:visible !important;display:block !important;"><p>'.__('Calendar developed and supported by ', 'calendar').'<a href="http://www.kieranoshea.com">Kieran O\'Shea</a></p></div> |
| 3043 |
'; |
| 3044 |
} else { |
| 3045 |
$linkback_url = ''; |
| 3046 |
} |
| 3047 |
$calendar_body .= $linkback_url; |
| 3048 |
|
| 3049 |
// Phew! After that bit of string building, spit it all out. |
| 3050 |
// The actual printing is done by the calling function. |
| 3051 |
return $calendar_body; |
| 3052 |
} |
| 3053 |
|
| 3054 |
// Used to create a hover will all a day's events in for minical |
| 3055 |
function minical_draw_events($events,$day_of_week = '') |
| 3056 |
{ |
| 3057 |
// We need to sort arrays of objects by time |
| 3058 |
usort($events, "time_cmp"); |
| 3059 |
// Only show anything if there are events |
| 3060 |
$output = ''; |
| 3061 |
if (count($events)) { |
| 3062 |
// Setup the wrapper |
| 3063 |
$output = '<span class="calnk"><a href="#" class="minical-day">'.$day_of_week.'<span>'; |
| 3064 |
// Now process the events |
| 3065 |
foreach($events as $event) |
| 3066 |
{ |
| 3067 |
if ($event->event_time == '00:00:00') { $the_time = __('all day','calendar'); } else { $the_time = __('at','calendar').' '.date(get_option('time_format'), strtotime(stripslashes($event->event_time))); } |
| 3068 |
$output .= '* <strong>'.$event->event_title.'</strong> '.$the_time.'<br />'; |
| 3069 |
} |
| 3070 |
// The tail |
| 3071 |
$output .= '</span></a></span>'; |
| 3072 |
} else { |
| 3073 |
$output .= $day_of_week; |
| 3074 |
} |
| 3075 |
return $output; |
| 3076 |
} |
| 3077 |
|
| 3078 |
function minical($cat_list = '') { |
| 3079 |
|
| 3080 |
global $wpdb; |
| 3081 |
|
| 3082 |
$get_year = (isset($_GET['yr']) ? $_GET['yr'] : null); |
| 3083 |
$get_month = (isset($_GET['month']) ? $_GET['month'] : null); |
| 3084 |
|
| 3085 |
// Deal with the week not starting on a monday |
| 3086 |
if (get_option('start_of_week') == 0) |
| 3087 |
{ |
| 3088 |
$name_days = array(1=>__('Su','calendar'),__('Mo','calendar'),__('Tu','calendar'),__('We','calendar'),__('Th','calendar'),__('Fr','calendar'),__('Sa','calendar')); |
| 3089 |
} |
| 3090 |
// Choose Monday if anything other than Sunday is set |
| 3091 |
else |
| 3092 |
{ |
| 3093 |
$name_days = array(1=>__('Mo','calendar'),__('Tu','calendar'),__('We','calendar'),__('Th','calendar'),__('Fr','calendar'),__('Sa','calendar'),__('Su','calendar')); |
| 3094 |
} |
| 3095 |
|
| 3096 |
// Carry on with the script |
| 3097 |
$name_months = array(1=>__('January','calendar'),__('February','calendar'),__('March','calendar'),__('April','calendar'),__('May','calendar'),__('June','calendar'),__('July','\ |
| 3098 |
calendar'),__('August','calendar'),__('September','calendar'),__('October','calendar'),__('November','calendar'),__('December','calendar')); |
| 3099 |
|
| 3100 |
// If we don't pass arguments we want a calendar that is relevant to today |
| 3101 |
if (empty($get_month) || empty($get_year)) |
| 3102 |
{ |
| 3103 |
$c_year = date("Y",ctwo()); |
| 3104 |
$c_month = date("m",ctwo()); |
| 3105 |
$c_day = date("d",ctwo()); |
| 3106 |
} |
| 3107 |
|
| 3108 |
// Years get funny if we exceed 3000, so we use this check |
| 3109 |
if (isset($get_year)) |
| 3110 |
{ |
| 3111 |
if ($get_year <= 3000 && $get_year >= 0 && (int)$get_year != 0) |
| 3112 |
{ |
| 3113 |
// This is just plain nasty and all because of permalinks |
| 3114 |
// which are no longer used, this will be cleaned up soon |
| 3115 |
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 == 'sep' || $get_month == 'oct' || $get_month == 'nov' || $get_month == 'dec') |
| 3116 |
{ |
| 3117 |
|
| 3118 |
// Again nasty code to map permalinks into something |
| 3119 |
// databases can understand. This will be cleaned up |
| 3120 |
$c_year = $wpdb->prepare("%d",$get_year); |
| 3121 |
if ($get_month == 'jan') { $t_month = 1; } |
| 3122 |
else if ($get_month == 'feb') { $t_month = 2; } |
| 3123 |
else if ($get_month == 'mar') { $t_month = 3; } |
| 3124 |
else if ($get_month == 'apr') { $t_month = 4; } |
| 3125 |
else if ($get_month == 'may') { $t_month = 5; } |
| 3126 |
else if ($get_month == 'jun') { $t_month = 6; } |
| 3127 |
else if ($get_month == 'jul') { $t_month = 7; } |
| 3128 |
else if ($get_month == 'aug') { $t_month = 8; } |
| 3129 |
else if ($get_month == 'sep') { $t_month = 9; } |
| 3130 |
else if ($get_month == 'oct') { $t_month = 10; } |
| 3131 |
else if ($get_month == 'nov') { $t_month = 11; } |
| 3132 |
else if ($get_month == 'dec') { $t_month = 12; } |
| 3133 |
$c_month = $t_month; |
| 3134 |
$c_day = date("d",ctwo()); |
| 3135 |
} |
| 3136 |
// No valid month causes the calendar to default to today |
| 3137 |
else |
| 3138 |
{ |
| 3139 |
$c_year = date("Y",ctwo()); |
| 3140 |
$c_month = date("m",ctwo()); |
| 3141 |
$c_day = date("d",ctwo()); |
| 3142 |
} |
| 3143 |
} |
| 3144 |
} |
| 3145 |
// No valid year causes the calendar to default to today |
| 3146 |
else |
| 3147 |
{ |
| 3148 |
$c_year = date("Y",ctwo()); |
| 3149 |
$c_month = date("m",ctwo()); |
| 3150 |
$c_day = date("d",ctwo()); |
| 3151 |
} |
| 3152 |
|
| 3153 |
// Fix the days of the week if week start is not on a monday |
| 3154 |
if (get_option('start_of_week') == 0) |
| 3155 |
{ |
| 3156 |
$first_weekday = date("w",mktime(0,0,0,$c_month,1,$c_year)); |
| 3157 |
$first_weekday = ($first_weekday==0?1:$first_weekday+1); |
| 3158 |
} |
| 3159 |
// Otherwise assume the week starts on a Monday. Anything other |
| 3160 |
// than Sunday or Monday is just plain odd |
| 3161 |
else |
| 3162 |
{ |
| 3163 |
$first_weekday = date("w",mktime(0,0,0,$c_month,1,$c_year)); |
| 3164 |
$first_weekday = ($first_weekday==0?7:$first_weekday); |
| 3165 |
} |
| 3166 |
|
| 3167 |
$days_in_month = date("t", mktime (0,0,0,$c_month,1,$c_year)); |
| 3168 |
|
| 3169 |
// Start the table and add the header and naviagtion |
| 3170 |
$calendar_body = ''; |
| 3171 |
$calendar_body .= '<div style="width:200px;"><table cellspacing="1" cellpadding="0" class="calendar-table"> |
| 3172 |
'; |
| 3173 |
|
| 3174 |
|
| 3175 |
// The header of the calendar table and the links. Note calls to link functions |
| 3176 |
$calendar_body .= '<tr> |
| 3177 |
<td colspan="7" class="calendar-heading" style="height:0;"> |
| 3178 |
<table border="0" cellpadding="0" cellspacing="0" width="100%"> |
| 3179 |
<tr> |
| 3180 |
<td class="calendar-prev">' . prev_link($c_year,$c_month,true) . '</td> |
| 3181 |
<td class="calendar-month">'.$name_months[(int)$c_month].' '.$c_year.'</td> |
| 3182 |
<td class="calendar-next">' . next_link($c_year,$c_month,true) . '</td> |
| 3183 |
</tr> |
| 3184 |
</table> |
| 3185 |
</td> |
| 3186 |
</tr> |
| 3187 |
'; |
| 3188 |
|
| 3189 |
// Print the headings of the days of the week |
| 3190 |
$calendar_body .= '<tr> |
| 3191 |
'; |
| 3192 |
for ($i=1; $i<=7; $i++) |
| 3193 |
{ |
| 3194 |
// Colours need to be different if the starting day of the week is different |
| 3195 |
if (get_option('start_of_week') == 0) |
| 3196 |
{ |
| 3197 |
$calendar_body .= ' <td class="'.($i<7&&$i>1?'normal-day-heading':'weekend-heading').'" style="height:0;">'.$name_days[$i].'</td> |
| 3198 |
'; |
| 3199 |
} |
| 3200 |
else |
| 3201 |
{ |
| 3202 |
$calendar_body .= ' <td class="'.($i<6?'normal-day-heading':'weekend-heading').'" style="height:0;">'.$name_days[$i].'</td> |
| 3203 |
'; |
| 3204 |
} |
| 3205 |
} |
| 3206 |
$calendar_body .= '</tr> |
| 3207 |
'; |
| 3208 |
$go = FALSE; |
| 3209 |
for ($i=1; $i<=$days_in_month;) |
| 3210 |
{ |
| 3211 |
$calendar_body .= '<tr> |
| 3212 |
'; |
| 3213 |
for ($ii=1; $ii<=7; $ii++) |
| 3214 |
{ |
| 3215 |
if ($ii==$first_weekday && $i==1) |
| 3216 |
{ |
| 3217 |
$go = TRUE; |
| 3218 |
} |
| 3219 |
elseif ($i > $days_in_month ) |
| 3220 |
{ |
| 3221 |
$go = FALSE; |
| 3222 |
} |
| 3223 |
if ($go) |
| 3224 |
{ |
| 3225 |
// Colours again, this time for the day numbers |
| 3226 |
if (get_option('start_of_week') == 0) |
| 3227 |
{ |
| 3228 |
// This bit of code is for styles believe it or not. |
| 3229 |
$grabbed_events = grab_events($c_year,$c_month,$i,'calendar',$cat_list); |
| 3230 |
$no_events_class = ''; |
| 3231 |
if (!count($grabbed_events)) |
| 3232 |
{ |
| 3233 |
$no_events_class = ' no-events'; |
| 3234 |
} |
| 3235 |
$calendar_body .= ' <td class="'.(date("Ymd", mktime (0,0,0,$c_month,$i,$c_year))==date("Ymd",ctwo())?'current-day':'day-with-date').$no_events_class.'" style="height:0;"><span '.($ii<7&&$ii>1?'':'class="weekend"').'>'.minical_draw_events($grabbed_events,$i++).'</span></td> |
| 3236 |
'; |
| 3237 |
} |
| 3238 |
else |
| 3239 |
{ |
| 3240 |
$grabbed_events = grab_events($c_year,$c_month,$i,'calendar',$cat_list); |
| 3241 |
$no_events_class = ''; |
| 3242 |
if (!count($grabbed_events)) |
| 3243 |
{ |
| 3244 |
$no_events_class = ' no-events'; |
| 3245 |
} |
| 3246 |
$calendar_body .= ' <td class="'.(date("Ymd", mktime (0,0,0,$c_month,$i,$c_year))==date("Ymd",ctwo())?'current-day':'day-with-date').$no_events_class.'" style="height:0;"><span '.($ii<6?'':'class="weekend"').'>'.minical_draw_events($grabbed_events,$i++).'</span></td> |
| 3247 |
'; |
| 3248 |
} |
| 3249 |
} |
| 3250 |
else |
| 3251 |
{ |
| 3252 |
$calendar_body .= ' <td class="day-without-date" style="height:0;"> </td> |
| 3253 |
'; |
| 3254 |
} |
| 3255 |
} |
| 3256 |
$calendar_body .= '</tr> |
| 3257 |
'; |
| 3258 |
} |
| 3259 |
$calendar_body .= '</table> |
| 3260 |
'; |
| 3261 |
|
| 3262 |
// A little link to yours truly |
| 3263 |
$link_approved = 'false'; |
| 3264 |
$link_approved_results = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='show_attribution_link'"); |
| 3265 |
foreach ($link_approved_results as $link_approved_item) |
| 3266 |
{ |
| 3267 |
if ($link_approved_item->config_value == 'true') |
| 3268 |
{ |
| 3269 |
$link_approved = 'true'; |
| 3270 |
} |
| 3271 |
} |
| 3272 |
if ($link_approved == 'true') { |
| 3273 |
$linkback_url = '<div class="kjo-link" style="visibility:visible !important;display:block !important;"><p>'.__('Calendar by ', 'calendar').'<a href="http://www.kieranoshea.com">Kieran O\'Shea</a></p></div> |
| 3274 |
'; |
| 3275 |
} else { |
| 3276 |
$linkback_url = ''; |
| 3277 |
} |
| 3278 |
$calendar_body .= $linkback_url; |
| 3279 |
|
| 3280 |
// Closing div |
| 3281 |
$calendar_body .= '</div> |
| 3282 |
'; |
| 3283 |
// Phew! After that bit of string building, spit it all out. |
| 3284 |
// The actual printing is done by the calling function. |
| 3285 |
return $calendar_body; |
| 3286 |
|
| 3287 |
} |
| 3288 |
|
| 3289 |
?> |
| 3290 |
|