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