| @@ -1,15 +1,19 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: Calendar |
| 4 | -Plugin URI: http://www.kjowebservices.co.uk | |
| 4 | +Plugin URI: http://www.kieranoshea.com | |
| 5 | 5 | Description: This plugin allows you to display a calendar of all your events and appointments as a page on your site. |
| 6 | 6 | Author: Kieran O'Shea |
| 7 | -Author URI: http://www.kjowebservices.co.uk | |
| 8 | -Version: 1.2 | |
| 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 | |
| 9 | 13 | */ |
| 10 | 14 | |
| 11 | -/* Copyright 2008 KJO Web Services (email : sales@kjowebservices.co.uk) | |
| 15 | +/* Copyright 2008 Kieran O'Shea (email : kieran@kieranoshea.com) | |
| 12 | 16 | |
| 13 | 17 | This program is free software; you can redistribute it and/or modify |
| 14 | 18 | it under the terms of the GNU General Public License as published by |
| 15 | 19 | the Free Software Foundation; either version 2 of the License, or |
| @@ -24,65 +28,115 @@ | ||
| 24 | 28 | along with this program; if not, write to the Free Software |
| 25 | 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 26 | 30 | */ |
| 27 | 31 | |
| 28 | -// Define the tables used in Calendar | |
| 29 | -define('WP_CALENDAR_TABLE', $table_prefix . 'calendar'); | |
| 30 | -define('WP_CALENDAR_CONFIG_TABLE', $table_prefix . 'calendar_config'); | |
| 31 | -define('WP_CALENDAR_CATEGORIES_TABLE', $table_prefix . 'calendar_categories'); | |
| 32 | +// Direct access shouldn't be allowed | |
| 33 | +if ( ! defined( 'ABSPATH' ) ) exit; | |
| 32 | 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 | + | |
| 33 | 53 | // Create a master category for Calendar and its sub-pages |
| 54 | +add_action('admin_enqueue_scripts', 'calendar_add_javascript'); | |
| 34 | 55 | add_action('admin_menu', 'calendar_menu'); |
| 35 | 56 | |
| 36 | 57 | // Enable the ability for the calendar to be loaded from pages |
| 37 | 58 | add_filter('the_content','calendar_insert'); |
| 59 | +add_filter('the_content','calendar_minical_insert'); | |
| 38 | 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 | + | |
| 39 | 65 | // Add the function that puts style information in the header |
| 40 | -add_action('wp_head', 'calendar_wp_head'); | |
| 66 | +add_action('wp_enqueue_scripts', 'calendar_wp_head'); | |
| 41 | 67 | |
| 42 | 68 | // Add the function that deals with deleted users |
| 43 | -add_action('delete_user', 'deal_with_deleted_user'); | |
| 69 | +add_action('delete_user', 'calendar_deal_with_deleted_user'); | |
| 44 | 70 | |
| 45 | -// Add the widgets if we are using version 2.5 | |
| 46 | -add_action('widgets_init', 'widget_init_calendar_today'); | |
| 47 | -add_action('widgets_init', 'widget_init_calendar_upcoming'); | |
| 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'); | |
| 48 | 75 | |
| 49 | -// Before we get on with the functions, we need to define the initial style used for Calendar | |
| 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 | +} | |
| 50 | 83 | |
| 51 | -// Function to deal with events posted by a user when that user is deleted | |
| 52 | -function deal_with_deleted_user($id) | |
| 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() | |
| 53 | 91 | { |
| 54 | - global $wpdb; | |
| 92 | + add_rewrite_rule( 'calendar-feed$', 'index.php?calendar_feed=1', 'top' ); | |
| 93 | +} | |
| 55 | 94 | |
| 56 | - // This wouldn't work unless the database was up to date. Lets check. | |
| 57 | - check_calendar(); | |
| 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 | +} | |
| 58 | 101 | |
| 59 | - // Do the query | |
| 60 | - $wpdb->get_results("UPDATE ".WP_CALENDAR_TABLE." SET event_author=".$wpdb->get_var("SELECT MIN(ID) FROM ".$wpdb->prefix."users",0,0)." WHERE event_author=".$id); | |
| 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; | |
| 61 | 110 | } |
| 62 | 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 | + | |
| 63 | 131 | // Function to add the calendar style into the header |
| 64 | 132 | function calendar_wp_head() |
| 65 | 133 | { |
| 66 | - global $wpdb; | |
| 67 | - | |
| 68 | - // If the calendar isn't installed or upgraded this won't work | |
| 69 | - check_calendar(); | |
| 70 | - | |
| 71 | - $styles = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='calendar_style'"); | |
| 72 | - if (!empty($styles)) | |
| 73 | - { | |
| 74 | - foreach ($styles as $style) | |
| 75 | - { | |
| 76 | - echo '<style type="text/css"> | |
| 77 | -<!-- | |
| 78 | -'; | |
| 79 | - echo $style->config_value.' | |
| 80 | -'; | |
| 81 | - echo '//--> | |
| 82 | -</style> | |
| 83 | -'; | |
| 84 | - } | |
| 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); | |
| 85 | 139 | } |
| 86 | 140 | } |
| 87 | 141 | |
| 88 | 142 | // Function to deal with adding the calendar menus |
| @@ -87,65 +141,137 @@ | ||
| 87 | 141 | |
| 88 | 142 | // Function to deal with adding the calendar menus |
| 89 | 143 | function calendar_menu() |
| 90 | 144 | { |
| 91 | - global $wpdb; | |
| 92 | - | |
| 93 | - // We make use of the Calendar tables so we must have installed Calendar | |
| 94 | - check_calendar(); | |
| 95 | - | |
| 96 | 145 | // Set admin as the only one who can use Calendar for security |
| 97 | 146 | $allowed_group = 'manage_options'; |
| 98 | 147 | |
| 99 | 148 | // Use the database to *potentially* override the above if allowed |
| 100 | - $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='can_manage_events'"); | |
| 101 | - if (!empty($configs)) | |
| 102 | - { | |
| 103 | - foreach ($configs as $config) | |
| 104 | - { | |
| 105 | - $allowed_group = $config->config_value; | |
| 106 | - } | |
| 107 | - } | |
| 149 | + $configs = calendar_get_config_value('can_manage_events'); | |
| 150 | + if (!empty($configs)) { | |
| 151 | + $allowed_group = $configs; | |
| 152 | + } | |
| 108 | 153 | |
| 109 | 154 | // Add the admin panel pages for Calendar. Use permissions pulled from above |
| 110 | 155 | if (function_exists('add_menu_page')) |
| 111 | 156 | { |
| 112 | - add_menu_page(__('Calendar'), __('Calendar'), $allowed_group, basename(__FILE__), 'edit_calendar'); | |
| 157 | + add_menu_page(__('Calendar','calendar'), __('Calendar','calendar'), $allowed_group, 'calendar', 'calendar_edit'); | |
| 113 | 158 | } |
| 114 | 159 | if (function_exists('add_submenu_page')) |
| 115 | 160 | { |
| 116 | - add_submenu_page('calendar.php', __('Manage Calendar'), __('Manage Calendar'), $allowed_group, basename(__FILE__), 'edit_calendar'); | |
| 117 | - add_action( "admin_print_scripts", 'calendar_add_javascript' ); | |
| 161 | + add_submenu_page('calendar', __('Manage Calendar','calendar'), __('Manage Calendar','calendar'), $allowed_group, 'calendar', 'calendar_edit'); | |
| 118 | 162 | // Note only admin can change calendar options |
| 119 | - add_submenu_page('calendar.php', __('Manage Categories'), __('Manage Categories'), 'manage_options', 'manage-categories', 'manage_categories'); | |
| 120 | - add_submenu_page('calendar.php', __('Calendar Config'), __('Calendar Options'), 'manage_options', 'calendar-config', 'edit_calendar_config'); | |
| 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'); | |
| 121 | 165 | } |
| 122 | 166 | } |
| 123 | 167 | |
| 124 | 168 | // Function to add the javascript to the admin header |
| 125 | 169 | function calendar_add_javascript() |
| 126 | -{ | |
| 127 | - //echo '<script type="text/javascript">'; | |
| 128 | - //echo include('javascript.js'); | |
| 129 | - //echo '</script>'; | |
| 130 | - echo '<script type="text/javascript" src="'; | |
| 131 | - bloginfo('url'); | |
| 132 | - echo '/wp-content/plugins/calendar/javascript.js"></script> | |
| 133 | -<script type="text/javascript">document.write(getCalendarStyles());</script>'; | |
| 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' ); | |
| 134 | 173 | } |
| 135 | 174 | |
| 136 | 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 | +} | |
| 137 | 203 | function calendar_insert($content) |
| 138 | 204 | { |
| 139 | - if (preg_match('{CALENDAR}',$content)) | |
| 205 | + if (preg_match('/\{CALENDAR*.+\}/',$content)) | |
| 140 | 206 | { |
| 141 | - $content = str_replace('{CALENDAR}',calendar(),$content); | |
| 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); | |
| 142 | 216 | } |
| 143 | 217 | return $content; |
| 144 | 218 | } |
| 145 | 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 | + | |
| 146 | 272 | // Function to check what version of Calendar is installed and install if needed |
| 147 | -function check_calendar() | |
| 273 | +function calendar_check() | |
| 148 | 274 | { |
| 149 | 275 | // Checks to make sure Calendar is installed, if not it adds the default |
| 150 | 276 | // database tables and populates them with test data. If it is, then the |
| 151 | 277 | // version is checked through various means and if it is not up to date |
| @@ -151,32 +277,36 @@ | ||
| 151 | 277 | // version is checked through various means and if it is not up to date |
| 152 | 278 | // then it is upgraded. |
| 153 | 279 | |
| 154 | 280 | // Lets see if this is first run and create us a table if it is! |
| 155 | - global $wpdb, $initial_style; | |
| 281 | + global $calendar_initial_style; | |
| 156 | 282 | |
| 283 | + // Version info | |
| 284 | + $calendar_version_option = 'calendar_version'; | |
| 285 | + $calendar_version = '1.3.16'; | |
| 286 | + | |
| 157 | 287 | // All this style info will go into the database on a new install |
| 158 | - // This looks nice in the Kubrick theme | |
| 159 | - $initial_style = " .calnk a:hover { | |
| 160 | - background-position:0 0; | |
| 161 | - text-decoration:none; | |
| 162 | - color:#000000; | |
| 163 | - border-bottom:1px dotted #000000; | |
| 164 | - } | |
| 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 | + } | |
| 165 | 295 | .calnk a:visited { |
| 166 | - text-decoration:none; | |
| 167 | - color:#000000; | |
| 168 | - border-bottom:1px dotted #000000; | |
| 169 | - } | |
| 296 | + text-decoration:none; | |
| 297 | + color:#000000; | |
| 298 | + border-bottom:1px dotted #000000; | |
| 299 | + } | |
| 170 | 300 | .calnk a { |
| 171 | 301 | text-decoration:none; |
| 172 | 302 | color:#000000; |
| 173 | 303 | border-bottom:1px dotted #000000; |
| 174 | - } | |
| 175 | - .calnk a span { | |
| 304 | + } | |
| 305 | + .calnk a > span { | |
| 176 | 306 | display:none; |
| 177 | - } | |
| 178 | - .calnk a:hover span { | |
| 307 | + } | |
| 308 | + .calnk a:hover > span { | |
| 179 | 309 | color:#333333; |
| 180 | 310 | background:#F6F79B; |
| 181 | 311 | display:block; |
| 182 | 312 | position:absolute; |
| @@ -181,35 +311,40 @@ | ||
| 181 | 311 | display:block; |
| 182 | 312 | position:absolute; |
| 183 | 313 | margin-top:1px; |
| 184 | 314 | padding:5px; |
| 185 | - width:150px; | |
| 315 | + width:auto; | |
| 186 | 316 | z-index:100; |
| 187 | - } | |
| 188 | - .calendar-table { | |
| 189 | - border:none; | |
| 190 | - width:100%; | |
| 191 | - } | |
| 192 | - .calendar-heading { | |
| 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 { | |
| 193 | 326 | height:25px; |
| 194 | - align:center; | |
| 195 | - border:1px solid #D6DED5; | |
| 327 | + text-align:center; | |
| 196 | 328 | background-color:#E4EBE3; |
| 197 | - } | |
| 198 | - .calendar-next { | |
| 199 | - width:25%; | |
| 329 | + } | |
| 330 | + .calendar-next { | |
| 331 | + width:20%; | |
| 200 | 332 | text-align:center; |
| 201 | - } | |
| 202 | - .calendar-prev { | |
| 203 | - width:25%; | |
| 333 | + border:none; | |
| 334 | + } | |
| 335 | + .calendar-prev { | |
| 336 | + width:20%; | |
| 204 | 337 | text-align:center; |
| 205 | - } | |
| 206 | - .calendar-month { | |
| 207 | - width:50%; | |
| 338 | + border:none; | |
| 339 | + } | |
| 340 | + .calendar-month { | |
| 341 | + width:60%; | |
| 208 | 342 | text-align:center; |
| 209 | 343 | font-weight:bold; |
| 210 | - } | |
| 211 | - .normal-day-heading { | |
| 344 | + border:none; | |
| 345 | + } | |
| 346 | + .normal-day-heading { | |
| 212 | 347 | text-align:center; |
| 213 | 348 | width:25px; |
| 214 | 349 | height:25px; |
| 215 | 350 | font-size:0.8em; |
| @@ -214,10 +349,10 @@ | ||
| 214 | 349 | height:25px; |
| 215 | 350 | font-size:0.8em; |
| 216 | 351 | border:1px solid #DFE6DE; |
| 217 | 352 | background-color:#EBF2EA; |
| 218 | - } | |
| 219 | - .weekend-heading { | |
| 353 | + } | |
| 354 | + .weekend-heading { | |
| 220 | 355 | text-align:center; |
| 221 | 356 | width:25px; |
| 222 | 357 | height:25px; |
| 223 | 358 | font-size:0.8em; |
| @@ -223,28 +358,28 @@ | ||
| 223 | 358 | font-size:0.8em; |
| 224 | 359 | border:1px solid #DFE6DE; |
| 225 | 360 | background-color:#EBF2EA; |
| 226 | 361 | color:#FF0000; |
| 227 | - } | |
| 228 | - .day-with-date { | |
| 362 | + } | |
| 363 | + .day-with-date { | |
| 229 | 364 | vertical-align:text-top; |
| 230 | 365 | text-align:left; |
| 231 | 366 | width:60px; |
| 232 | 367 | height:60px; |
| 233 | 368 | border:1px solid #DFE6DE; |
| 234 | - } | |
| 235 | - .no-events { | |
| 369 | + } | |
| 370 | + .no-events { | |
| 236 | 371 | |
| 237 | - } | |
| 238 | - .day-without-date { | |
| 372 | + } | |
| 373 | + .day-without-date { | |
| 239 | 374 | width:60px; |
| 240 | 375 | height:60px; |
| 241 | 376 | border:1px solid #E9F0E8; |
| 242 | - } | |
| 243 | - span.weekend { | |
| 377 | + } | |
| 378 | + span.weekend { | |
| 244 | 379 | color:#FF0000; |
| 245 | - } | |
| 246 | - .current-day { | |
| 380 | + } | |
| 381 | + .current-day { | |
| 247 | 382 | vertical-align:text-top; |
| 248 | 383 | text-align:left; |
| 249 | 384 | width:60px; |
| 250 | 385 | height:60px; |
| @@ -249,314 +384,259 @@ | ||
| 249 | 384 | width:60px; |
| 250 | 385 | height:60px; |
| 251 | 386 | border:1px solid #BFBFBF; |
| 252 | 387 | background-color:#E4EBE3; |
| 253 | - } | |
| 254 | - span.event { | |
| 388 | + } | |
| 389 | + span.event { | |
| 255 | 390 | font-size:0.75em; |
| 256 | - } | |
| 257 | - .kjo-link { | |
| 391 | + } | |
| 392 | + .kjo-link { | |
| 258 | 393 | font-size:0.75em; |
| 259 | 394 | text-align:center; |
| 260 | - } | |
| 261 | - .event-title { | |
| 395 | + } | |
| 396 | + .calendar-date-switcher { | |
| 397 | + height:25px; | |
| 262 | 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; | |
| 263 | 419 | font-weight:bold; |
| 264 | 420 | font-size:1.2em; |
| 265 | - } | |
| 266 | - .event-title-break { | |
| 421 | + margin-left:0px; | |
| 422 | + } | |
| 423 | + .calnk a:hover span span.event-title-break { | |
| 424 | + display:block; | |
| 267 | 425 | width:96%; |
| 268 | - margin-left:2%; | |
| 269 | - margin-right:2%; | |
| 270 | - margin-top:5px; | |
| 271 | - margin-bottom:5px; | |
| 272 | 426 | text-align:center; |
| 273 | 427 | height:1px; |
| 428 | + margin-top:5px; | |
| 429 | + margin-right:2%; | |
| 430 | + padding:0; | |
| 274 | 431 | background-color:#000000; |
| 275 | - } | |
| 276 | - .event-content-break { | |
| 432 | + margin-left:0px; | |
| 433 | + } | |
| 434 | + .calnk a:hover span span.event-content-break { | |
| 435 | + display:block; | |
| 277 | 436 | width:96%; |
| 278 | - margin-left:2%; | |
| 279 | - margin-right:2%; | |
| 280 | - margin-top:5px; | |
| 281 | - margin-bottom:5px; | |
| 282 | 437 | text-align:center; |
| 283 | 438 | height:1px; |
| 439 | + margin-top:5px; | |
| 440 | + margin-right:2%; | |
| 441 | + padding:0; | |
| 284 | 442 | background-color:#000000; |
| 285 | - } | |
| 286 | - .calendar-date-switcher { | |
| 287 | - height:25px; | |
| 288 | - align:center; | |
| 289 | - border:1px solid #D6DED5; | |
| 290 | - background-color:#E4EBE3; | |
| 291 | - } | |
| 292 | - .calendar-date-switcher form { | |
| 293 | - margin:0; | |
| 294 | - padding:0; | |
| 295 | - } | |
| 296 | - .calendar-date-switcher input { | |
| 297 | - border:1px #D6DED5 solid; | |
| 298 | - } | |
| 299 | - .calendar-date-switcher select { | |
| 300 | - border:1px #D6DED5 solid; | |
| 301 | - } | |
| 302 | - .cat-key { | |
| 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 { | |
| 303 | 462 | width:100%; |
| 304 | - margin-top:10px; | |
| 463 | + margin-top:30px; | |
| 305 | 464 | padding:5px; |
| 306 | - border:1px solid #D6DED5; | |
| 307 | - }"; | |
| 308 | - | |
| 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 | + }"; | |
| 309 | 486 | |
| 310 | - // Assume this is not a new install until we prove otherwise | |
| 311 | - $new_install = false; | |
| 312 | - $vone_point_one_upgrade = false; | |
| 313 | - $vone_point_two_beta_upgrade = false; | |
| 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; | |
| 314 | 492 | |
| 315 | - $wp_calendar_exists = false; | |
| 316 | - $wp_calendar_config_exists = false; | |
| 317 | - $wp_calendar_config_version_number_exists = false; | |
| 493 | + $wp_calendar_exists = false; | |
| 494 | + $wp_calendar_config_exists = false; | |
| 495 | + $wp_calendar_config_version_number_exists = false; | |
| 318 | 496 | |
| 319 | - // Determine the calendar version | |
| 320 | - $tables = $wpdb->get_results("show tables;"); | |
| 321 | - foreach ( $tables as $table ) | |
| 322 | - { | |
| 323 | - foreach ( $table as $value ) | |
| 324 | - { | |
| 325 | - if ( $value == WP_CALENDAR_TABLE ) | |
| 326 | - { | |
| 327 | - $wp_calendar_exists = true; | |
| 328 | - } | |
| 329 | - if ( $value == WP_CALENDAR_CONFIG_TABLE ) | |
| 330 | - { | |
| 331 | - $wp_calendar_config_exists = true; | |
| 332 | - | |
| 333 | - // We now try and find the calendar version number | |
| 334 | - // This will be a lot easier than finding other stuff | |
| 335 | - // in the future. | |
| 336 | - $version_number = $wpdb->get_var("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='calendar_version'"); | |
| 337 | - if ($version_number == "1.2") | |
| 338 | - { | |
| 339 | - $wp_calendar_config_version_number_exists = true; | |
| 340 | - } | |
| 341 | - } | |
| 342 | - } | |
| 343 | - } | |
| 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; | |
| 344 | 506 | |
| 345 | - if ($wp_calendar_exists == false && $wp_calendar_config_exists == false) | |
| 346 | - { | |
| 347 | - $new_install = true; | |
| 348 | - } | |
| 349 | - else if ($wp_calendar_exists == true && $wp_calendar_config_exists == false) | |
| 350 | - { | |
| 351 | - $vone_point_one_upgrade = true; | |
| 352 | - } | |
| 353 | - else if ($wp_calendar_exists == true && $wp_calendar_config_exists == true && $wp_calendar_config_version_number_exists == false) | |
| 354 | - { | |
| 355 | - $vone_point_two_beta_upgrade = true; | |
| 356 | - } | |
| 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 | + } | |
| 357 | 517 | |
| 358 | - // Now we've determined what the current install is or isn't | |
| 359 | - // we perform operations according to the findings | |
| 360 | - if ( $new_install == true ) | |
| 361 | - { | |
| 362 | - $sql = "CREATE TABLE " . WP_CALENDAR_TABLE . " ( | |
| 363 | - event_id INT(11) NOT NULL AUTO_INCREMENT , | |
| 364 | - event_begin DATE NOT NULL , | |
| 365 | - event_end DATE NOT NULL , | |
| 366 | - event_title VARCHAR(30) NOT NULL , | |
| 367 | - event_desc TEXT NOT NULL , | |
| 368 | - event_time TIME , | |
| 369 | - event_recur CHAR(1) , | |
| 370 | - event_repeats INT(3) , | |
| 371 | - event_author BIGINT(20) UNSIGNED, | |
| 372 | - PRIMARY KEY (event_id) | |
| 373 | - )"; | |
| 374 | - $wpdb->get_results($sql); | |
| 375 | - $sql = "CREATE TABLE " . WP_CALENDAR_CONFIG_TABLE . " ( | |
| 376 | - config_item VARCHAR(30) NOT NULL , | |
| 377 | - config_value TEXT NOT NULL , | |
| 378 | - PRIMARY KEY (config_item) | |
| 379 | - )"; | |
| 380 | - $wpdb->get_results($sql); | |
| 381 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='can_manage_events', config_value='edit_posts'"; | |
| 382 | - $wpdb->get_results($sql); | |
| 383 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='calendar_style', config_value='".$initial_style."'"; | |
| 384 | - $wpdb->get_results($sql); | |
| 385 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_author', config_value='false'"; | |
| 386 | - $wpdb->get_results($sql); | |
| 387 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_jump', config_value='false'"; | |
| 388 | - $wpdb->get_results($sql); | |
| 389 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_todays', config_value='true'"; | |
| 390 | - $wpdb->get_results($sql); | |
| 391 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_upcoming', config_value='true'"; | |
| 392 | - $wpdb->get_results($sql); | |
| 393 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_upcoming_days', config_value=7"; | |
| 394 | - $wpdb->get_results($sql); | |
| 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 | + } | |
| 395 | 525 | |
| 396 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='calendar_version', config_value='1.2'"; | |
| 397 | - $wpdb->get_results($sql); | |
| 398 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='enable_categories', config_value='false'"; | |
| 399 | - $wpdb->get_results($sql); | |
| 400 | - $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_category BIGINT(20) UNSIGNED"; | |
| 401 | - $wpdb->get_results($sql); | |
| 402 | - $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_category=1"; | |
| 403 | - $wpdb->get_results($sql); | |
| 404 | - $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_link TEXT"; | |
| 405 | - $wpdb->get_results($sql); | |
| 406 | - $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_link=''"; | |
| 407 | - $wpdb->get_results($sql); | |
| 408 | - $sql = "CREATE TABLE " . WP_CALENDAR_CATEGORIES_TABLE . " ( | |
| 409 | - category_id INT(11) NOT NULL AUTO_INCREMENT, | |
| 410 | - category_name VARCHAR(30) NOT NULL , | |
| 411 | - category_colour VARCHAR(30) NOT NULL , | |
| 412 | - PRIMARY KEY (category_id) | |
| 413 | - )"; | |
| 414 | - $wpdb->get_results($sql); | |
| 415 | - $sql = "INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_id=0, category_name='General', category_colour='#F6F79B'"; | |
| 416 | - $wpdb->get_results($sql); | |
| 417 | - } | |
| 418 | - else if ($vone_point_one_upgrade == true) | |
| 419 | - { | |
| 420 | - $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_author BIGINT(20) UNSIGNED"; | |
| 421 | - $wpdb->get_results($sql); | |
| 422 | - $sql = "UPDATE ".WP_CALENDAR_TABLE." SET event_author=".$wpdb->get_var("SELECT MIN(ID) FROM ".$wpdb->prefix."users",0,0); | |
| 423 | - $wpdb->get_results($sql); | |
| 424 | - $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." MODIFY event_desc TEXT NOT NULL"; | |
| 425 | - $wpdb->get_results($sql); | |
| 426 | - $sql = "CREATE TABLE " . WP_CALENDAR_CONFIG_TABLE . " ( | |
| 427 | - config_item VARCHAR(30) NOT NULL , | |
| 428 | - config_value TEXT NOT NULL , | |
| 429 | - PRIMARY KEY (config_item) | |
| 430 | - )"; | |
| 431 | - $wpdb->get_results($sql); | |
| 432 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='can_manage_events', config_value='edit_posts'"; | |
| 433 | - $wpdb->get_results($sql); | |
| 434 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='calendar_style', config_value='".$initial_style."'"; | |
| 435 | - $wpdb->get_results($sql); | |
| 436 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_author', config_value='false'"; | |
| 437 | - $wpdb->get_results($sql); | |
| 438 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_jump', config_value='false'"; | |
| 439 | - $wpdb->get_results($sql); | |
| 440 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_todays', config_value='true'"; | |
| 441 | - $wpdb->get_results($sql); | |
| 442 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_upcoming', config_value='true'"; | |
| 443 | - $wpdb->get_results($sql); | |
| 444 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_upcoming_days', config_value=7"; | |
| 445 | - $wpdb->get_results($sql); | |
| 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); | |
| 446 | 566 | |
| 447 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='calendar_version', config_value='1.2'"; | |
| 448 | - $wpdb->get_results($sql); | |
| 449 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='enable_categories', config_value='false'"; | |
| 450 | - $wpdb->get_results($sql); | |
| 451 | - $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_category BIGINT(20) UNSIGNED"; | |
| 452 | - $wpdb->get_results($sql); | |
| 453 | - $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_category=1"; | |
| 454 | - $wpdb->get_results($sql); | |
| 455 | - $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_link TEXT"; | |
| 456 | - $wpdb->get_results($sql); | |
| 457 | - $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_link=''"; | |
| 458 | - $wpdb->get_results($sql); | |
| 459 | - $sql = "CREATE TABLE " . WP_CALENDAR_CATEGORIES_TABLE . " ( | |
| 460 | - category_id INT(11) NOT NULL AUTO_INCREMENT, | |
| 461 | - category_name VARCHAR(30) NOT NULL , | |
| 462 | - category_colour VARCHAR(30) NOT NULL , | |
| 463 | - PRIMARY KEY (category_id) | |
| 464 | - )"; | |
| 465 | - $wpdb->get_results($sql); | |
| 466 | - $sql = "INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_id=0, category_name='General', category_colour='#F6F79B'"; | |
| 467 | - $wpdb->get_results($sql); | |
| 468 | - } | |
| 469 | - else if ($vone_point_two_beta_upgrade == true) | |
| 470 | - { | |
| 471 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='calendar_version', config_value='1.2'"; | |
| 472 | - $wpdb->get_results($sql); | |
| 473 | - $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='enable_categories', config_value='false'"; | |
| 474 | - $wpdb->get_results($sql); | |
| 475 | - $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_category BIGINT(20) UNSIGNED"; | |
| 476 | - $wpdb->get_results($sql); | |
| 477 | - $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_category=1"; | |
| 478 | - $wpdb->get_results($sql); | |
| 479 | - $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_link TEXT"; | |
| 480 | - $wpdb->get_results($sql); | |
| 481 | - $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_link=''"; | |
| 482 | - $wpdb->get_results($sql); | |
| 483 | - $sql = "CREATE TABLE " . WP_CALENDAR_CATEGORIES_TABLE . " ( | |
| 484 | - category_id INT(11) NOT NULL AUTO_INCREMENT, | |
| 485 | - category_name VARCHAR(30) NOT NULL , | |
| 486 | - category_colour VARCHAR(30) NOT NULL , | |
| 487 | - PRIMARY KEY (category_id) | |
| 488 | - )"; | |
| 489 | - $wpdb->get_results($sql); | |
| 490 | - $sql = "INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_id=1, category_name='General', category_colour='#F6F79B'"; | |
| 491 | - $wpdb->get_results($sql); | |
| 492 | - $sql = "UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value='".$initial_style."' WHERE config_item='calendar_style'"; | |
| 493 | - $wpdb->get_results($sql); | |
| 494 | - } | |
| 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 | + } | |
| 495 | 575 | } |
| 496 | 576 | |
| 497 | 577 | // Used on the manage events admin page to display a list of events |
| 498 | -function wp_events_display_list() | |
| 499 | -{ | |
| 500 | - global $wpdb; | |
| 501 | - | |
| 502 | - $events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " ORDER BY event_begin DESC"); | |
| 503 | - | |
| 578 | +function calendar_events_display_list(){ | |
| 579 | + | |
| 580 | + $events = calendar_db_get_all_events(); | |
| 504 | 581 | if ( !empty($events) ) |
| 505 | 582 | { |
| 506 | - ?> | |
| 507 | - <table width="100%" cellpadding="3" cellspacing="3"> | |
| 508 | - <tr> | |
| 509 | - <th scope="col"><?php _e('ID') ?></th> | |
| 510 | - <th scope="col"><?php _e('Title') ?></th> | |
| 511 | - <th scope="col"><?php _e('Description') ?></th> | |
| 512 | - <th scope="col"><?php _e('Start Date') ?></th> | |
| 513 | - <th scope="col"><?php _e('End Date') ?></th> | |
| 514 | - <th scope="col"><?php _e('Recurs') ?></th> | |
| 515 | - <th scope="col"><?php _e('Repeats') ?></th> | |
| 516 | - <th scope="col"><?php _e('Author') ?></th> | |
| 517 | - <th scope="col"><?php _e('Category') ?></th> | |
| 518 | - <th scope="col"><?php _e('Edit') ?></th> | |
| 519 | - <th scope="col"><?php _e('Delete') ?></th> | |
| 520 | - </tr> | |
| 521 | - <?php | |
| 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 | |
| 522 | 601 | $class = ''; |
| 523 | 602 | foreach ( $events as $event ) |
| 524 | 603 | { |
| 525 | 604 | $class = ($class == 'alternate') ? '' : 'alternate'; |
| 526 | 605 | ?> |
| 527 | - <tr class="<?php echo $class; ?>"> | |
| 528 | - <th scope="row"><?php echo $event->event_id; ?></th> | |
| 529 | - <td><?php echo $event->event_title; ?></td> | |
| 530 | - <td><?php echo $event->event_desc; ?></td> | |
| 531 | - <td><?php echo $event->event_begin; ?></td> | |
| 532 | - <td><?php echo $event->event_end; ?></td> | |
| 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> | |
| 533 | 612 | <td> |
| 534 | 613 | <?php |
| 535 | 614 | // Interpret the DB values into something human readable |
| 536 | - if ($event->event_recur == 'S') { echo 'Never'; } | |
| 537 | - else if ($event->event_recur == 'W') { echo 'Weekly'; } | |
| 538 | - else if ($event->event_recur == 'M') { echo 'Monthly'; } | |
| 539 | - else if ($event->event_recur == 'Y') { echo 'Yearly'; } | |
| 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'); } | |
| 540 | 620 | ?> |
| 541 | 621 | </td> |
| 542 | 622 | <td> |
| 543 | 623 | <?php |
| 544 | 624 | // Interpret the DB values into something human readable |
| 545 | - if ($event->event_recur == 'S') { echo 'N/A'; } | |
| 546 | - else if ($event->event_repeats == 0) { echo 'Forever'; } | |
| 547 | - else if ($event->event_repeats > 0) { echo $event->event_repeats.' Times'; } | |
| 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'); } | |
| 548 | 628 | ?> |
| 549 | 629 | </td> |
| 550 | - <td><?php $e = get_userdata($event->event_author); echo $e->display_name; ?></td> | |
| 630 | + <td><?php $e = get_userdata($event->event_author); echo esc_html($e->display_name); ?></td> | |
| 551 | 631 | <?php |
| 552 | - $sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".$event->event_category; | |
| 553 | - $this_cat = $wpdb->get_row($sql); | |
| 632 | + $this_cat = calendar_db_get_category_row_by_id($event->event_category); | |
| 554 | 633 | ?> |
| 555 | - <td style="background-color:<?php echo $this_cat->category_colour;?>;"><?php echo $this_cat->category_name; ?></td> | |
| 634 | + <td style="background-color:<?php echo esc_html($this_cat->category_colour);?>;"><?php echo esc_html($this_cat->category_name); ?></td> | |
| 556 | 635 | <?php unset($this_cat); ?> |
| 557 | - <td><a href="<?php echo $_SERVER['REQUEST_URI'] ?>&action=edit&event_id=<?php echo $event->event_id;?>" class='edit'><?php echo __('Edit'); ?></a></td> | |
| 558 | - <td><a href="<?php echo $_SERVER['REQUEST_URI'] ?>&action=delete&event_id=<?php echo $event->event_id;?>" class="delete" onclick="return confirm('Are you sure you want to delete this event?')"><?php echo __('Delete'); ?></a></td> | |
| 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> | |
| 559 | 639 | </tr> |
| 560 | 640 | <?php |
| 561 | 641 | } |
| 562 | 642 | ?> |
| @@ -565,9 +645,9 @@ | ||
| 565 | 645 | } |
| 566 | 646 | else |
| 567 | 647 | { |
| 568 | 648 | ?> |
| 569 | - <p><?php _e("There are no events in the database!") ?></p> | |
| 649 | + <p><?php esc_html_e("There are no events in the database!",'calendar') ?></p> | |
| 570 | 650 | <?php |
| 571 | 651 | } |
| 572 | 652 | } |
| 573 | 653 | |
| @@ -572,11 +652,11 @@ | ||
| 572 | 652 | } |
| 573 | 653 | |
| 574 | 654 | |
| 575 | 655 | // The event edit form for the manage events admin page |
| 576 | -function wp_events_edit_form($mode='add', $event_id=false) | |
| 656 | +function calendar_events_edit_form($mode='add', $event_id=false) | |
| 577 | 657 | { |
| 578 | - global $wpdb; | |
| 658 | + global $calendar_users_entries; | |
| 579 | 659 | $data = false; |
| 580 | 660 | |
| 581 | 661 | if ( $event_id !== false ) |
| 582 | 662 | { |
| @@ -581,50 +661,68 @@ | ||
| 581 | 661 | if ( $event_id !== false ) |
| 582 | 662 | { |
| 583 | 663 | if ( intval($event_id) != $event_id ) |
| 584 | 664 | { |
| 585 | - echo "<div class=\"error\"><p>Bad Monkey! No banana!</p></div>"; | |
| 665 | + echo "<div class=\"error\"><p>".esc_html__('Bad Monkey! No banana!','calendar')."</p></div>"; | |
| 586 | 666 | return; |
| 587 | 667 | } |
| 588 | 668 | else |
| 589 | 669 | { |
| 590 | - $data = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_id='" . mysql_escape_string($event_id) . "' LIMIT 1"); | |
| 670 | + $data = calendar_db_get_events_by_id($event_id); | |
| 591 | 671 | if ( empty($data) ) |
| 592 | 672 | { |
| 593 | - echo "<div class=\"error\"><p>An event with that ID couldn't be found</p></div>"; | |
| 673 | + echo "<div class=\"error\"><p>".esc_html__("An event with that ID couldn't be found",'calendar')."</p></div>"; | |
| 594 | 674 | return; |
| 595 | 675 | } |
| 596 | 676 | $data = $data[0]; |
| 597 | - } | |
| 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 | + } | |
| 598 | 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 | + } | |
| 599 | 689 | |
| 600 | 690 | ?> |
| 601 | - <div id="pop_up_cal" style="position:absolute;margin-left:150px;visibility:hidden;background-color:white;layer-background-color:white;"></div> | |
| 602 | - <form name="quoteform" id="quoteform" class="wrap" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> | |
| 603 | - <input type="hidden" name="action" value="<?php echo $mode; ?>"> | |
| 604 | - <input type="hidden" name="event_id" value="<?php echo $event_id; ?>"> | |
| 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 | + ?> | |
| 605 | 703 | |
| 606 | - <div id="item_manager"> | |
| 607 | - <div style="float: left; width: 98%; clear: both;" class="top"> | |
| 608 | - <!-- List URL --> | |
| 609 | - <fieldset class="small"><legend><?php _e('Event Title'); ?></legend> | |
| 610 | - <input type="text" name="event_title" class="input" size="40" maxlength="30" | |
| 611 | - value="<?php if ( !empty($data) ) echo htmlspecialchars($data->event_title); ?>" /> | |
| 612 | - </fieldset> | |
| 613 | - | |
| 614 | - <fieldset class="small"><legend><?php _e('Event Description'); ?></legend> | |
| 615 | - <textarea name="event_desc" class="input" rows="5" cols="50"><?php if ( !empty($data) ) echo htmlspecialchars($data->event_desc); ?></textarea> | |
| 616 | - </fieldset> | |
| 617 | - | |
| 618 | - <fieldset class="small"><legend><?php _e('Event Category'); ?></legend> | |
| 619 | - <select name="event_category"> | |
| 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"> | |
| 620 | 719 | <?php |
| 621 | 720 | // Grab all the categories and list them |
| 622 | - $sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE; | |
| 623 | - $cats = $wpdb->get_results($sql); | |
| 721 | + $cats = calendar_db_get_all_categories(); | |
| 624 | 722 | foreach($cats as $cat) |
| 625 | 723 | { |
| 626 | - echo '<option value="'.$cat->category_id.'"'; | |
| 724 | + echo '<option value="'.esc_attr($cat->category_id).'"'; | |
| 627 | 725 | if (!empty($data)) |
| 628 | 726 | { |
| 629 | 727 | if ($data->event_category == $cat->category_id) |
| 630 | 728 | { |
| @@ -630,64 +728,70 @@ | ||
| 630 | 728 | { |
| 631 | 729 | echo 'selected="selected"'; |
| 632 | 730 | } |
| 633 | 731 | } |
| 634 | - echo '>'.$cat->category_name.'</option> | |
| 732 | + echo '>'.esc_html($cat->category_name).'</option> | |
| 635 | 733 | '; |
| 636 | 734 | } |
| 637 | 735 | ?> |
| 638 | 736 | </select> |
| 639 | - </fieldset> | |
| 640 | - | |
| 641 | - <fieldset class="small"><legend><?php _e('Event Link (Optional)'); ?></legend> | |
| 642 | - <input type="text" name="event_link" class="input" size="40" value="<?php if ( !empty($data) ) echo htmlspecialchars($data->event_link); ?>" /> | |
| 643 | - </fieldset> | |
| 644 | - | |
| 645 | - <fieldset class="small"><legend><?php _e('Start Date'); ?></legend> | |
| 646 | - <script type="text/javascript"> | |
| 647 | - var cal_begin = new CalendarPopup('pop_up_cal'); | |
| 648 | - cal_begin.showNavigationDropdowns(); | |
| 649 | - </script> | |
| 650 | - <input type="text" name="event_begin" class="input" size=12 | |
| 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" | |
| 651 | 747 | value="<?php |
| 652 | 748 | if ( !empty($data) ) |
| 653 | 749 | { |
| 654 | - echo htmlspecialchars($data->event_begin); | |
| 750 | + echo esc_attr($data->event_begin); | |
| 655 | 751 | } |
| 656 | 752 | else |
| 657 | 753 | { |
| 658 | - echo date("Y-m-d"); | |
| 754 | + echo esc_attr(gmdate("Y-m-d",calendar_ctwo())); | |
| 659 | 755 | } |
| 660 | - ?>" /> <a href="#" onClick="cal_begin.select(document.forms['quoteform'].event_begin,'event_begin_anchor','yyyy-MM-dd'); return false;" name="event_begin_anchor" id="event_begin_anchor">Select Date</a> | |
| 661 | - </fieldset> | |
| 662 | - | |
| 663 | - <fieldset class="small"><legend><?php _e('End Date'); ?></legend> | |
| 664 | - <script type="text/javascript"> | |
| 665 | - function check_and_print() { | |
| 666 | - var cal_end = new CalendarPopup('pop_up_cal'); | |
| 667 | - var newDate = new Date(); | |
| 668 | - newDate.setFullYear(document.forms['quoteform'].event_begin.value.split('-')[0],document.forms['quoteform'].event_begin.value.split('-')[1]-1,document.forms['quoteform'].event_begin.value.split('-')[2]); | |
| 669 | - newDate.setDate(newDate.getDate()-1); | |
| 670 | - cal_end.addDisabledDates(null, formatDate(newDate, "yyyy-MM-dd")); | |
| 671 | - cal_end.showNavigationDropdowns(); | |
| 672 | - cal_end.select(document.forms['quoteform'].event_end,'event_end_anchor','yyyy-MM-dd'); | |
| 673 | - } | |
| 674 | - </script> | |
| 675 | - <input type="text" name="event_end" class="input" size=12 | |
| 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" | |
| 676 | 772 | value="<?php |
| 677 | 773 | if ( !empty($data) ) |
| 678 | 774 | { |
| 679 | - echo htmlspecialchars($data->event_end); | |
| 775 | + echo esc_attr($data->event_end); | |
| 680 | 776 | } |
| 681 | 777 | else |
| 682 | 778 | { |
| 683 | - echo date("Y-m-d"); | |
| 779 | + echo esc_attr(gmdate("Y-m-d",calendar_ctwo())); | |
| 684 | 780 | } |
| 685 | - ?>" /> <a href="#" onClick="check_and_print(); return false;" name="event_end_anchor" id="event_end_anchor">Select Date</a> | |
| 686 | - </fieldset> | |
| 687 | - | |
| 688 | - <fieldset class="small"><legend><?php _e('Time (hh:mm)(optional, set blank if not required)'); ?></legend> | |
| 689 | - <input type="text" name="event_time" class="input" size=12 | |
| 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 | |
| 690 | 794 | value="<?php |
| 691 | 795 | if ( !empty($data) ) |
| 692 | 796 | { |
| 693 | 797 | if ($data->event_time == "00:00:00") |
| @@ -695,23 +799,30 @@ | ||
| 695 | 799 | echo ''; |
| 696 | 800 | } |
| 697 | 801 | else |
| 698 | 802 | { |
| 699 | - echo date("H:i",strtotime(htmlspecialchars($data->event_time))); | |
| 803 | + echo esc_attr(gmdate("H:i",strtotime($data->event_time))); | |
| 700 | 804 | } |
| 701 | 805 | } |
| 702 | 806 | else |
| 703 | 807 | { |
| 704 | - echo date("H:i"); | |
| 808 | + echo esc_attr(gmdate("H:i",calendar_ctwo())); | |
| 705 | 809 | } |
| 706 | - ?>" /> <?php _e('Current time difference from GMT is '); echo get_option('gmt_offset'); _e(' hour(s)'); ?> | |
| 707 | - </fieldset> | |
| 708 | - | |
| 709 | - <fieldset class="small"><legend><?php _e('Recurring Events'); ?></legend> | |
| 710 | - <?php | |
| 711 | - if ($data->event_repeats != NULL) | |
| 712 | - { | |
| 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 | + { | |
| 713 | 819 | $repeats = $data->event_repeats; |
| 820 | + } | |
| 821 | + else | |
| 822 | + { | |
| 823 | + $repeats = 0; | |
| 824 | + } | |
| 714 | 825 | } |
| 715 | 826 | else |
| 716 | 827 | { |
| 717 | 828 | $repeats = 0; |
| @@ -716,8 +827,14 @@ | ||
| 716 | 827 | { |
| 717 | 828 | $repeats = 0; |
| 718 | 829 | } |
| 719 | 830 | |
| 831 | + $selected_s = ''; | |
| 832 | + $selected_w = ''; | |
| 833 | + $selected_m = ''; | |
| 834 | + $selected_y = ''; | |
| 835 | + $selected_u = ''; | |
| 836 | + if (isset($data)) { | |
| 720 | 837 | if ($data->event_recur == "S") |
| 721 | 838 | { |
| 722 | 839 | $selected_s = 'selected="selected"'; |
| 723 | 840 | } |
| @@ -732,25 +849,31 @@ | ||
| 732 | 849 | else if ($data->event_recur == "Y") |
| 733 | 850 | { |
| 734 | 851 | $selected_y = 'selected="selected"'; |
| 735 | 852 | } |
| 853 | + else if ($data->event_recur == "U") | |
| 854 | + { | |
| 855 | + $selected_u = 'selected="selected"'; | |
| 856 | + } | |
| 857 | + } | |
| 736 | 858 | ?> |
| 737 | - Repeats for | |
| 738 | - <input type="text" name="event_repeats" class="input" size="1" value="<?php echo $repeats; ?>" /> | |
| 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); ?>" /> | |
| 739 | 861 | <select name="event_recur" class="input"> |
| 740 | - <option class="input" <?php echo $selected_s; ?> value="S">None</option> | |
| 741 | - <option class="input" <?php echo $selected_w; ?> value="W">Weeks</option> | |
| 742 | - <option class="input" <?php echo $selected_m; ?> value="M">Months</option> | |
| 743 | - <option class="input" <?php echo $selected_y; ?> value="Y">Years</option> | |
| 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> | |
| 744 | 867 | </select><br /> |
| 745 | - Entering 0 means forever. Where the recurrance interval <br /> | |
| 746 | - is left at none, the event will not reoccur. | |
| 747 | - </fieldset> | |
| 748 | - <br /> | |
| 749 | - <input type="submit" name="save" class="button bold" value="Save »" /> | |
| 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> | |
| 750 | 872 | </div> |
| 751 | 873 | <div style="clear:both; height:1px;"> </div> |
| 752 | 874 | </div> |
| 875 | + <input type="submit" name="save" class="button bold" value="<?php esc_attr_e('Save','calendar'); ?> »" /> | |
| 753 | 876 | </form> |
| 754 | 877 | <?php |
| 755 | 878 | } |
| 756 | 879 | |
| @@ -755,190 +878,364 @@ | ||
| 755 | 878 | } |
| 756 | 879 | |
| 757 | 880 | // The actual function called to render the manage events page and |
| 758 | 881 | // to deal with posts |
| 759 | -function edit_calendar() | |
| 882 | +function calendar_edit() | |
| 760 | 883 | { |
| 761 | - global $current_user, $wpdb; | |
| 762 | - ?> | |
| 763 | - <style type="text/css"> | |
| 764 | -<!-- | |
| 765 | - .error { | |
| 766 | - background: lightcoral; | |
| 767 | - border: 1px solid #e64f69; | |
| 768 | - margin: 1em 5% 10px; | |
| 769 | - padding: 0 1em 0 1em; | |
| 770 | - } | |
| 884 | + global $current_user, $calendar_users_entries; | |
| 771 | 885 | |
| 772 | - .center { | |
| 773 | - text-align: center; | |
| 774 | - } | |
| 775 | - .right { text-align: right; | |
| 776 | - } | |
| 777 | - .left { | |
| 778 | - text-align: left; | |
| 779 | - } | |
| 780 | - .top { | |
| 781 | - vertical-align: top; | |
| 782 | - } | |
| 783 | - .bold { | |
| 784 | - font-weight: bold; | |
| 785 | - } | |
| 786 | - .private { | |
| 787 | - color: #e64f69; | |
| 788 | - } | |
| 789 | -//--> | |
| 790 | -</style> | |
| 791 | - | |
| 792 | -<?php | |
| 793 | - | |
| 794 | -// First some quick cleaning up | |
| 886 | +// First some quick cleaning up | |
| 795 | 887 | $edit = $create = $save = $delete = false; |
| 796 | 888 | |
| 797 | -// Make sure we are collecting the variables we need to select years and months | |
| 798 | -$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; | |
| 799 | -$event_id = !empty($_REQUEST['event_id']) ? $_REQUEST['event_id'] : ''; | |
| 800 | - | |
| 801 | - | |
| 802 | -// Lets see if this is first run and create us a table if it is! | |
| 803 | -check_calendar(); | |
| 804 | - | |
| 805 | 889 | // Deal with adding an event to the database |
| 806 | -if ( $action == 'add' ) | |
| 890 | +if ( isset($_REQUEST['action']) && $_REQUEST['action'] == 'add' ) | |
| 807 | 891 | { |
| 808 | - $title = !empty($_REQUEST['event_title']) ? $_REQUEST['event_title'] : ''; | |
| 809 | - $desc = !empty($_REQUEST['event_desc']) ? $_REQUEST['event_desc'] : ''; | |
| 810 | - $begin = !empty($_REQUEST['event_begin']) ? $_REQUEST['event_begin'] : ''; | |
| 811 | - $end = !empty($_REQUEST['event_end']) ? $_REQUEST['event_end'] : ''; | |
| 812 | - $time = !empty($_REQUEST['event_time']) ? $_REQUEST['event_time'] : ''; | |
| 813 | - $recur = !empty($_REQUEST['event_recur']) ? $_REQUEST['event_recur'] : ''; | |
| 814 | - $repeats = !empty($_REQUEST['event_repeats']) ? $_REQUEST['event_repeats'] : ''; | |
| 815 | - $category = !empty($_REQUEST['event_category']) ? $_REQUEST['event_category'] : ''; | |
| 816 | - $linky = !empty($_REQUEST['event_link']) ? $_REQUEST['event_link'] : ''; | |
| 817 | - | |
| 818 | - // Deal with the fools who have left magic quotes turned on | |
| 819 | - if ( ini_get('magic_quotes_gpc') ) | |
| 820 | - { | |
| 821 | - $title = stripslashes($title); | |
| 822 | - $desc = stripslashes($desc); | |
| 823 | - $begin = stripslashes($begin); | |
| 824 | - $end = stripslashes($end); | |
| 825 | - $time = stripslashes($time); | |
| 826 | - $recur = stripslashes($recur); | |
| 827 | - $repeats = stripslashes($repeats); | |
| 828 | - $category = stripslashes($category); | |
| 829 | - $linky = stripslashes($linky); | |
| 830 | - } | |
| 831 | - | |
| 832 | - $sql = "INSERT INTO " . WP_CALENDAR_TABLE . " SET event_title='" . mysql_escape_string($title) | |
| 833 | - . "', event_desc='" . mysql_escape_string($desc) . "', event_begin='" . mysql_escape_string($begin) | |
| 834 | - . "', event_end='" . mysql_escape_string($end) . "', event_time='" . mysql_escape_string($time) . "', event_recur='" . mysql_escape_string($recur) . "', event_repeats='" . mysql_escape_string($repeats) . "', event_author=".$current_user->ID.", event_category=".mysql_escape_string($category).", event_link='".mysql_escape_string($linky)."'"; | |
| 835 | - | |
| 836 | - $wpdb->get_results($sql); | |
| 837 | - | |
| 838 | - $sql = "SELECT event_id FROM " . WP_CALENDAR_TABLE . " WHERE event_title='" . mysql_escape_string($title) . "'" | |
| 839 | - . " AND event_desc='" . mysql_escape_string($desc) . "' AND event_begin='" . mysql_escape_string($begin) . "' AND event_end='" . mysql_escape_string($end) . "' AND event_recur='" . mysql_escape_string($recur) . "' AND event_repeats='" . mysql_escape_string($repeats) . "' LIMIT 1"; | |
| 840 | - $result = $wpdb->get_results($sql); | |
| 841 | - | |
| 842 | - if ( empty($result) || empty($result[0]->event_id) ) | |
| 843 | - { | |
| 892 | + if (!isset($_POST['_wpnonce']) || wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_wpnonce'])),'calendar-add') == false) { | |
| 844 | 893 | ?> |
| 845 | - <div class="error"><p><strong>Error:</strong> For some bizare reason your event was not added. Why not try again?</p></div> | |
| 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> | |
| 846 | 895 | <?php |
| 847 | - } | |
| 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 | + } | |
| 848 | 944 | else |
| 849 | - { | |
| 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'); | |
| 850 | 1023 | ?> |
| 851 | - <div class="updated"><p>Event added. It will now show in your calendar.</p></div> | |
| 1024 | + <div class="updated"><p><?php esc_html_e('Event added. It will now show in your calendar.','calendar'); ?></p></div> | |
| 852 | 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 | + } | |
| 853 | 1042 | } |
| 854 | 1043 | } |
| 855 | 1044 | // Permit saving of events that have been edited |
| 856 | -elseif ( $action == 'edit_save' ) | |
| 1045 | +else if ( isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit_save' ) | |
| 857 | 1046 | { |
| 858 | - $title = !empty($_REQUEST['event_title']) ? $_REQUEST['event_title'] : ''; | |
| 859 | - $desc = !empty($_REQUEST['event_desc']) ? $_REQUEST['event_desc'] : ''; | |
| 860 | - $begin = !empty($_REQUEST['event_begin']) ? $_REQUEST['event_begin'] : ''; | |
| 861 | - $end = !empty($_REQUEST['event_end']) ? $_REQUEST['event_end'] : ''; | |
| 862 | - $time = !empty($_REQUEST['event_time']) ? $_REQUEST['event_time'] : ''; | |
| 863 | - $recur = !empty($_REQUEST['event_recur']) ? $_REQUEST['event_recur'] : ''; | |
| 864 | - $repeats = !empty($_REQUEST['event_repeats']) ? $_REQUEST['event_repeats'] : ''; | |
| 865 | - $category = !empty($_REQUEST['event_category']) ? $_REQUEST['event_category'] : ''; | |
| 866 | - $linky = !empty($_REQUEST['event_link']) ? $_REQUEST['event_link'] : ''; | |
| 867 | - | |
| 868 | - // Deal with the fools who have left magic quotes turned on | |
| 869 | - if ( ini_get('magic_quotes_gpc') ) | |
| 870 | - { | |
| 871 | - $title = stripslashes($title); | |
| 872 | - $desc = stripslashes($desc); | |
| 873 | - $begin = stripslashes($begin); | |
| 874 | - $end = stripslashes($end); | |
| 875 | - $time = stripslashes($time); | |
| 876 | - $recur = stripslashes($recur); | |
| 877 | - $repeats = stripslashes($repeats); | |
| 878 | - $category = stripslashes($category); | |
| 879 | - $linky = stripslashes($linky); | |
| 880 | - } | |
| 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'])) : ''; | |
| 881 | 1056 | |
| 882 | - if ( empty($event_id) ) | |
| 1057 | + if ( !isset($_REQUEST['event_id']) ) | |
| 883 | 1058 | { |
| 884 | 1059 | ?> |
| 885 | - <div class="error"><p><strong>Failure:</strong> You can't update an event if you haven't submitted an event id</p></div> | |
| 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> | |
| 886 | 1061 | <?php |
| 887 | 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 | + } | |
| 888 | 1068 | else |
| 889 | 1069 | { |
| 890 | - $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_title='" . mysql_escape_string($title) | |
| 891 | - . "', event_desc='" . mysql_escape_string($desc) . "', event_begin='" . mysql_escape_string($begin) | |
| 892 | - . "', event_end='" . mysql_escape_string($end) . "', event_time='" . mysql_escape_string($time) . "', event_recur='" . mysql_escape_string($recur) . "', event_repeats='" . mysql_escape_string($repeats) . "', event_author=".$current_user->ID . ", event_category=".mysql_escape_string($category).", event_link='".mysql_escape_string($linky)."' WHERE event_id='" . mysql_escape_string($event_id) . "'"; | |
| 893 | - | |
| 894 | - $wpdb->get_results($sql); | |
| 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); | |
| 895 | 1176 | |
| 896 | - $sql = "SELECT event_id FROM " . WP_CALENDAR_TABLE . " WHERE event_title='" . mysql_escape_string($title) . "'" | |
| 897 | - . " AND event_desc='" . mysql_escape_string($desc) . "' AND event_begin='" . mysql_escape_string($begin) . "' AND event_end='" . mysql_escape_string($end) . "' AND event_recur='" . mysql_escape_string($recur) . "' AND event_repeats='" . mysql_escape_string($repeats) . "' LIMIT 1"; | |
| 898 | - $result = $wpdb->get_results($sql); | |
| 899 | - | |
| 900 | 1177 | if ( empty($result) || empty($result[0]->event_id) ) |
| 901 | 1178 | { |
| 902 | 1179 | ?> |
| 903 | - <div class="error"><p><strong>Failure:</strong> For some reason the event didnt update. Why not try again? </p></div> | |
| 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> | |
| 904 | 1181 | <?php |
| 905 | 1182 | } |
| 906 | 1183 | else |
| 907 | 1184 | { |
| 1185 | + do_action('calendar_add_entry', 'edit'); | |
| 908 | 1186 | ?> |
| 909 | - <div class="updated"><p>Event updated successfully</p></div> | |
| 1187 | + <div class="updated"><p><?php esc_html_e('Event updated successfully','calendar'); ?></p></div> | |
| 910 | 1188 | <?php |
| 911 | - } | |
| 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 | + } | |
| 912 | 1206 | } |
| 913 | 1207 | } |
| 914 | 1208 | // Deal with deleting an event from the database |
| 915 | -elseif ( $action == 'delete' ) | |
| 1209 | +else if ( isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete' ) | |
| 916 | 1210 | { |
| 917 | - if ( empty($event_id) ) | |
| 1211 | + if ( !isset($_REQUEST['event_id']) ) | |
| 918 | 1212 | { |
| 919 | 1213 | ?> |
| 920 | - <div class="error"><p><strong>Error:</strong> Good Lord you gave me nothing to delete, nothing I tell you!</p></div> | |
| 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> | |
| 921 | 1215 | <?php |
| 922 | 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 | + } | |
| 923 | 1222 | else |
| 924 | 1223 | { |
| 925 | - $sql = "DELETE FROM " . WP_CALENDAR_TABLE . " WHERE event_id='" . mysql_escape_string($event_id) . "'"; | |
| 926 | - $wpdb->get_results($sql); | |
| 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']))); | |
| 927 | 1226 | |
| 928 | - $sql = "SELECT event_id FROM " . WP_CALENDAR_TABLE . " WHERE event_id='" . mysql_escape_string($event_id) . "'"; | |
| 929 | - $result = $wpdb->get_results($sql); | |
| 930 | - | |
| 931 | 1227 | if ( empty($result) || empty($result[0]->event_id) ) |
| 932 | 1228 | { |
| 1229 | + do_action('calendar_add_entry', 'delete'); | |
| 933 | 1230 | ?> |
| 934 | - <div class="updated"><p>Event deleted successfully</p></div> | |
| 1231 | + <div class="updated"><p><?php esc_html_e('Event deleted successfully','calendar'); ?></p></div> | |
| 935 | 1232 | <?php |
| 936 | 1233 | } |
| 937 | 1234 | else |
| 938 | 1235 | { |
| 939 | 1236 | ?> |
| 940 | - <div class="error"><p><strong>Error:</strong> For some bizare reason the event could not be deleted. Why not try again?</p></div> | |
| 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> | |
| 941 | 1238 | <?php |
| 942 | 1239 | |
| 943 | 1240 | } |
| 944 | 1241 | } |
| @@ -949,31 +1246,31 @@ | ||
| 949 | 1246 | ?> |
| 950 | 1247 | |
| 951 | 1248 | <div class="wrap"> |
| 952 | 1249 | <?php |
| 953 | - if ( $action == 'edit' ) | |
| 1250 | + if ( (isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit') || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit_save' && isset($error_with_saving))) | |
| 954 | 1251 | { |
| 955 | 1252 | ?> |
| 956 | - <h2><?php _e('Edit Event'); ?></h2> | |
| 1253 | + <h2><?php esc_html_e('Edit Event','calendar'); ?></h2> | |
| 957 | 1254 | <?php |
| 958 | - if ( empty($event_id) ) | |
| 1255 | + if ( !isset($_REQUEST['event_id']) ) | |
| 959 | 1256 | { |
| 960 | - echo "<div class=\"error\"><p>Good lord you didn't provide an event id to edit, what were you thinking?</p></div>"; | |
| 1257 | + echo "<div class=\"error\"><p>".esc_html__("You must provide an event id in order to edit it",'calendar')."</p></div>"; | |
| 961 | 1258 | } |
| 962 | 1259 | else |
| 963 | 1260 | { |
| 964 | - wp_events_edit_form('edit_save', $event_id); | |
| 1261 | + calendar_events_edit_form('edit_save', sanitize_text_field(wp_unslash($_REQUEST['event_id']))); | |
| 965 | 1262 | } |
| 966 | 1263 | } |
| 967 | 1264 | else |
| 968 | 1265 | { |
| 969 | 1266 | ?> |
| 970 | - <h2><?php _e('Add Event'); ?></h2> | |
| 971 | - <?php wp_events_edit_form(); ?> | |
| 1267 | + <h2><?php esc_html_e('Add Event','calendar'); ?></h2> | |
| 1268 | + <?php calendar_events_edit_form(); ?> | |
| 972 | 1269 | |
| 973 | - <h2><?php _e('Manage Events'); ?></h2> | |
| 1270 | + <h2><?php esc_html_e('Manage Events','calendar'); ?></h2> | |
| 974 | 1271 | <?php |
| 975 | - wp_events_display_list(); | |
| 1272 | + calendar_events_display_list(); | |
| 976 | 1273 | } |
| 977 | 1274 | ?> |
| 978 | 1275 | </div> |
| 979 | 1276 | |
| @@ -981,16 +1278,18 @@ | ||
| 981 | 1278 | |
| 982 | 1279 | } |
| 983 | 1280 | |
| 984 | 1281 | // Display the admin configuration page |
| 985 | -function edit_calendar_config() | |
| 1282 | +function calendar_config_edit() | |
| 986 | 1283 | { |
| 987 | - global $wpdb, $initial_style; | |
| 1284 | + global $calendar_initial_style; | |
| 988 | 1285 | |
| 989 | - // We can't use this page unless Calendar is installed/upgraded | |
| 990 | - check_calendar(); | |
| 991 | - | |
| 992 | - if (isset($_POST['permissions']) && isset($_POST['style'])) | |
| 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'])) | |
| 993 | 1292 | { |
| 994 | 1293 | if ($_POST['permissions'] == 'subscriber') { $new_perms = 'read'; } |
| 995 | 1294 | else if ($_POST['permissions'] == 'contributor') { $new_perms = 'edit_posts'; } |
| 996 | 1295 | else if ($_POST['permissions'] == 'author') { $new_perms = 'publish_posts'; } |
| @@ -997,21 +1296,22 @@ | ||
| 997 | 1296 | else if ($_POST['permissions'] == 'editor') { $new_perms = 'moderate_comments'; } |
| 998 | 1297 | else if ($_POST['permissions'] == 'admin') { $new_perms = 'manage_options'; } |
| 999 | 1298 | else { $new_perms = 'manage_options'; } |
| 1000 | 1299 | |
| 1001 | - $calendar_style = mysql_escape_string($_POST['style']); | |
| 1002 | - $display_upcoming_days = mysql_escape_string($_POST['display_upcoming_days']); | |
| 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; | |
| 1003 | 1303 | |
| 1004 | - if (mysql_escape_string($_POST['display_author']) == 'on') | |
| 1005 | - { | |
| 1006 | - $disp_author = 'true'; | |
| 1007 | - } | |
| 1304 | + if (isset($_POST['display_author']) && $_POST['display_author'] == 'on') | |
| 1305 | + { | |
| 1306 | + $disp_author = 'true'; | |
| 1307 | + } | |
| 1008 | 1308 | else |
| 1009 | - { | |
| 1010 | - $disp_author = 'false'; | |
| 1011 | - } | |
| 1309 | + { | |
| 1310 | + $disp_author = 'false'; | |
| 1311 | + } | |
| 1012 | 1312 | |
| 1013 | - if (mysql_escape_string($_POST['display_jump']) == 'on') | |
| 1313 | + if (isset($_POST['display_jump']) && $_POST['display_jump'] == 'on') | |
| 1014 | 1314 | { |
| 1015 | 1315 | $disp_jump = 'true'; |
| 1016 | 1316 | } |
| 1017 | 1317 | else |
| @@ -1018,9 +1318,9 @@ | ||
| 1018 | 1318 | { |
| 1019 | 1319 | $disp_jump = 'false'; |
| 1020 | 1320 | } |
| 1021 | 1321 | |
| 1022 | - if (mysql_escape_string($_POST['display_todays']) == 'on') | |
| 1322 | + if (isset($_POST['display_todays']) && $_POST['display_todays'] == 'on') | |
| 1023 | 1323 | { |
| 1024 | 1324 | $disp_todays = 'true'; |
| 1025 | 1325 | } |
| 1026 | 1326 | else |
| @@ -1027,9 +1327,9 @@ | ||
| 1027 | 1327 | { |
| 1028 | 1328 | $disp_todays = 'false'; |
| 1029 | 1329 | } |
| 1030 | 1330 | |
| 1031 | - if (mysql_escape_string($_POST['display_upcoming']) == 'on') | |
| 1331 | + if (isset($_POST['display_upcoming']) && $_POST['display_upcoming'] == 'on') | |
| 1032 | 1332 | { |
| 1033 | 1333 | $disp_upcoming = 'true'; |
| 1034 | 1334 | } |
| 1035 | 1335 | else |
| @@ -1036,136 +1336,133 @@ | ||
| 1036 | 1336 | { |
| 1037 | 1337 | $disp_upcoming = 'false'; |
| 1038 | 1338 | } |
| 1039 | 1339 | |
| 1040 | - if (mysql_escape_string($_POST['enable_categories']) == 'on') | |
| 1340 | + if (isset($_POST['enable_categories']) && $_POST['enable_categories'] == 'on') | |
| 1041 | 1341 | { |
| 1042 | 1342 | $enable_categories = 'true'; |
| 1043 | 1343 | } |
| 1044 | 1344 | else |
| 1045 | 1345 | { |
| 1046 | - $enable_categories = 'false'; | |
| 1346 | + $enable_categories = 'false'; | |
| 1047 | 1347 | } |
| 1048 | 1348 | |
| 1049 | - $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$new_perms."' WHERE config_item='can_manage_events'"); | |
| 1050 | - $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$calendar_style."' WHERE config_item='calendar_style'"); | |
| 1051 | - $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$disp_author."' WHERE config_item='display_author'"); | |
| 1052 | - $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$disp_jump."' WHERE config_item='display_jump'"); | |
| 1053 | - $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$disp_todays."' WHERE config_item='display_todays'"); | |
| 1054 | - $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$disp_upcoming."' WHERE config_item='display_upcoming'"); | |
| 1055 | - $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$display_upcoming_days."' WHERE config_item='display_upcoming_days'"); | |
| 1056 | - $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$enable_categories."' WHERE config_item='enable_categories'"); | |
| 1349 | + if (isset($_POST['enable_feed']) && $_POST['enable_feed'] == 'on') | |
| 1350 | + { | |
| 1351 | + $enable_feed = 'true'; | |
| 1352 | + } | |
| 1353 | + else | |
| 1354 | + { | |
| 1355 | + $enable_feed = 'false'; | |
| 1356 | + } | |
| 1057 | 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 | + | |
| 1058 | 1389 | // Check to see if we are replacing the original style |
| 1059 | - if (mysql_escape_string($_POST['reset_styles']) == 'on') | |
| 1060 | - { | |
| 1061 | - $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$initial_style."' WHERE config_item='calendar_style'"); | |
| 1062 | - } | |
| 1390 | + if (isset($_POST['reset_styles'])) { | |
| 1391 | + if ($_POST['reset_styles'] == 'on') { | |
| 1392 | + calendar_update_config_value('calendar_style',$calendar_initial_style); | |
| 1393 | + } | |
| 1394 | + } | |
| 1063 | 1395 | |
| 1064 | - echo "<div class=\"updated\"><p><strong>Settings saved.</strong></p></div>"; | |
| 1396 | + echo "<div class=\"updated\"><p><strong>".esc_html__('Settings saved','calendar').".</strong></p></div>"; | |
| 1065 | 1397 | } |
| 1066 | 1398 | |
| 1067 | 1399 | // Pull the values out of the database that we need for the form |
| 1068 | - $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='can_manage_events'"); | |
| 1069 | - if (!empty($configs)) | |
| 1070 | - { | |
| 1071 | - foreach ($configs as $config) | |
| 1072 | - { | |
| 1073 | - $allowed_group = $config->config_value; | |
| 1074 | - } | |
| 1075 | - } | |
| 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 | + } | |
| 1076 | 1459 | |
| 1077 | - $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='calendar_style'"); | |
| 1078 | - if (!empty($configs)) | |
| 1079 | - { | |
| 1080 | - foreach ($configs as $config) | |
| 1081 | - { | |
| 1082 | - $calendar_style = $config->config_value; | |
| 1083 | - } | |
| 1084 | - } | |
| 1085 | - $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_author'"); | |
| 1086 | - if (!empty($configs)) | |
| 1087 | - { | |
| 1088 | - foreach ($configs as $config) | |
| 1089 | - { | |
| 1090 | - if ($config->config_value == 'true') | |
| 1091 | - { | |
| 1092 | - $yes_disp_author = 'selected="selected"'; | |
| 1093 | - } | |
| 1094 | - else | |
| 1095 | - { | |
| 1096 | - $no_disp_author = 'selected="selected"'; | |
| 1097 | - } | |
| 1098 | - } | |
| 1099 | - } | |
| 1100 | - $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_jump'"); | |
| 1101 | - if (!empty($configs)) | |
| 1102 | - { | |
| 1103 | - foreach ($configs as $config) | |
| 1104 | - { | |
| 1105 | - if ($config->config_value == 'true') | |
| 1106 | - { | |
| 1107 | - $yes_disp_jump = 'selected="selected"'; | |
| 1108 | - } | |
| 1109 | - else | |
| 1110 | - { | |
| 1111 | - $no_disp_jump = 'selected="selected"'; | |
| 1112 | - } | |
| 1113 | - } | |
| 1114 | - } | |
| 1115 | - $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_todays'"); | |
| 1116 | - if (!empty($configs)) | |
| 1117 | - { | |
| 1118 | - foreach ($configs as $config) | |
| 1119 | - { | |
| 1120 | - if ($config->config_value == 'true') | |
| 1121 | - { | |
| 1122 | - $yes_disp_todays = 'selected="selected"'; | |
| 1123 | - } | |
| 1124 | - else | |
| 1125 | - { | |
| 1126 | - $no_disp_todays = 'selected="selected"'; | |
| 1127 | - } | |
| 1128 | - } | |
| 1129 | - } | |
| 1130 | - $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_upcoming'"); | |
| 1131 | - if (!empty($configs)) | |
| 1132 | - { | |
| 1133 | - foreach ($configs as $config) | |
| 1134 | - { | |
| 1135 | - if ($config->config_value == 'true') | |
| 1136 | - { | |
| 1137 | - $yes_disp_upcoming = 'selected="selected"'; | |
| 1138 | - } | |
| 1139 | - else | |
| 1140 | - { | |
| 1141 | - $no_disp_upcoming = 'selected="selected"'; | |
| 1142 | - } | |
| 1143 | - } | |
| 1144 | - } | |
| 1145 | - $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_upcoming_days'"); | |
| 1146 | - if (!empty($configs)) | |
| 1147 | - { | |
| 1148 | - foreach ($configs as $config) | |
| 1149 | - { | |
| 1150 | - $upcoming_days = $config->config_value; | |
| 1151 | - } | |
| 1152 | - } | |
| 1153 | - $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='enable_categories'"); | |
| 1154 | - if (!empty($configs)) | |
| 1155 | - { | |
| 1156 | - foreach ($configs as $config) | |
| 1157 | - { | |
| 1158 | - if ($config->config_value == 'true') | |
| 1159 | - { | |
| 1160 | - $yes_enable_categories = 'selected="selected"'; | |
| 1161 | - } | |
| 1162 | - else | |
| 1163 | - { | |
| 1164 | - $no_enable_categories = 'selected="selected"'; | |
| 1165 | - } | |
| 1166 | - } | |
| 1167 | - } | |
| 1460 | + $subscriber_selected = ''; | |
| 1461 | + $contributor_selected = ''; | |
| 1462 | + $author_selected = ''; | |
| 1463 | + $editor_selected = ''; | |
| 1464 | + $admin_selected = ''; | |
| 1168 | 1465 | if ($allowed_group == 'read') { $subscriber_selected='selected="selected"';} |
| 1169 | 1466 | else if ($allowed_group == 'edit_posts') { $contributor_selected='selected="selected"';} |
| 1170 | 1467 | else if ($allowed_group == 'publish_posts') { $author_selected='selected="selected"';} |
| 1171 | 1468 | else if ($allowed_group == 'moderate_comments') { $editor_selected='selected="selected"';} |
| @@ -1172,95 +1469,106 @@ | ||
| 1172 | 1469 | else if ($allowed_group == 'manage_options') { $admin_selected='selected="selected"';} |
| 1173 | 1470 | |
| 1174 | 1471 | // Now we render the form |
| 1175 | 1472 | ?> |
| 1176 | - <style type="text/css"> | |
| 1177 | - <!-- | |
| 1178 | - .error { | |
| 1179 | - background: lightcoral; | |
| 1180 | - border: 1px solid #e64f69; | |
| 1181 | - margin: 1em 5% 10px; | |
| 1182 | - padding: 0 1em 0 1em; | |
| 1183 | - } | |
| 1184 | - | |
| 1185 | - .center { | |
| 1186 | - text-align: center; | |
| 1187 | - } | |
| 1188 | - .right { | |
| 1189 | - text-align: right; | |
| 1190 | - } | |
| 1191 | - .left { | |
| 1192 | - text-align: left; | |
| 1193 | - } | |
| 1194 | - .top { | |
| 1195 | - vertical-align: top; | |
| 1196 | - } | |
| 1197 | - .bold { | |
| 1198 | - font-weight: bold; | |
| 1199 | - } | |
| 1200 | - .private { | |
| 1201 | - color: #e64f69; | |
| 1202 | - } | |
| 1203 | - //--> | |
| 1204 | - </style> | |
| 1205 | - | |
| 1206 | 1473 | <div class="wrap"> |
| 1207 | - <h2><?php _e('Calendar Options'); ?></h2> | |
| 1208 | - <form name="quoteform" id="quoteform" class="wrap" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> | |
| 1209 | - <div id="item_manager"> | |
| 1210 | - <div style="float: left; width: 98%; clear: both;" class="top"> | |
| 1211 | - <fieldset class="small"><legend><?php _e('Choose the lowest user group that may manage events'); ?></legend> | |
| 1212 | - <select name="permissions"> | |
| 1213 | - <option value="subscriber"<?php echo $subscriber_seletced ?>><?php _e('Subscriber')?></option> | |
| 1214 | - <option value="contributor" <?php echo $contributor_selected ?>><?php _e('Contributor')?></option> | |
| 1215 | - <option value="author" <?php echo $author_selected ?>><?php _e('Author')?></option> | |
| 1216 | - <option value="editor" <?php echo $editor_selected ?>><?php _e('Editor')?></option> | |
| 1217 | - <option value="admin" <?php echo $admin_selected ?>><?php _e('Administrator')?></option> | |
| 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> | |
| 1218 | 1488 | </select> |
| 1219 | - </fieldset> | |
| 1220 | - <fieldset class="small"><legend><?php _e('Do you want to display the author name on events?'); ?></legend> | |
| 1221 | - <select name="display_author"> | |
| 1222 | - <option value="on" <?php echo $yes_disp_author ?>><?php _e('Yes') ?></option> | |
| 1223 | - <option value="off" <?php echo $no_disp_author ?>><?php _e('No') ?></option> | |
| 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> | |
| 1224 | 1496 | </select> |
| 1225 | - </fieldset> | |
| 1226 | - <fieldset class="small"><legend><?php _e('Display a jumpbox for changing month and year quickly?'); ?></legend> | |
| 1227 | - <select name="display_jump"> | |
| 1228 | - <option value="on" <?php echo $yes_disp_jump ?>><?php _e('Yes') ?></option> | |
| 1229 | - <option value="off" <?php echo $no_disp_jump ?>><?php _e('No') ?></option> | |
| 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> | |
| 1230 | 1504 | </select> |
| 1231 | - </fieldset> | |
| 1232 | - <fieldset class="small"><legend><?php _e('Display todays events?'); ?></legend> | |
| 1233 | - <select name="display_todays"> | |
| 1234 | - <option value="on" <?php echo $yes_disp_todays ?>><?php _e('Yes') ?></option> | |
| 1235 | - <option value="off" <?php echo $no_disp_todays ?>><?php _e('No') ?></option> | |
| 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> | |
| 1236 | 1512 | </select> |
| 1237 | - </fieldset> | |
| 1238 | - <fieldset class="small"><legend><?php _e('Display upcoming events? If yes, state for how many days into the future'); ?></legend> | |
| 1239 | - <select name="display_upcoming"> | |
| 1240 | - <option value="on" <?php echo $yes_disp_upcoming ?>><?php _e('Yes') ?></option> | |
| 1241 | - <option value="off" <?php echo $no_disp_upcoming ?>><?php _e('No') ?></option> | |
| 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> | |
| 1242 | 1520 | </select> |
| 1243 | - for <input type="text" name="display_upcoming_days" value="<?php echo $upcoming_days ?>" size="1" maxlength="2" /> days into the future | |
| 1244 | - </fieldset> | |
| 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> | |
| 1245 | 1540 | |
| 1246 | - <fieldset class="small"><legend><?php _e('Enable event categories?'); ?></legend> | |
| 1247 | - <select name="enable_categories"> | |
| 1248 | - <option value="on" <?php echo $yes_enable_categories ?>><?php _e('Yes') ?></option> | |
| 1249 | - <option value="off" <?php echo $no_enable_categories ?>><?php _e('No') ?></option> | |
| 1250 | - </select> | |
| 1251 | - </fieldset> | |
| 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> | |
| 1252 | 1549 | |
| 1253 | - <fieldset class="small"><legend><?php _e('Configure the stylesheet for Calendar'); ?></legend> | |
| 1254 | - <textarea name="style" rows="10" cols="60" tabindex="2"><?php echo $calendar_style; ?></textarea> | |
| 1255 | - </fieldset> | |
| 1256 | - <fieldset class="small"><legend><?php _e('Reset Styles'); ?></legend> | |
| 1257 | - <input type="checkbox" name="reset_styles" /> <?php _e('Tick this box if you wish to reset the Calendar style to default'); ?> | |
| 1258 | - </fieldset> | |
| 1259 | - <br /> | |
| 1260 | - <input type="submit" name="save" class="button bold" value="Save »" /> | |
| 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> | |
| 1261 | 1567 | </div> |
| 1568 | + <div style="clear:both; height:1px;"> </div> | |
| 1262 | 1569 | </div> |
| 1570 | + <input type="submit" name="save" class="button bold" value="<?php esc_attr_e('Save','calendar'); ?> »" /> | |
| 1263 | 1571 | </form> |
| 1264 | 1572 | </div> |
| 1265 | 1573 | <?php |
| 1266 | 1574 | |
| @@ -1267,83 +1575,64 @@ | ||
| 1267 | 1575 | |
| 1268 | 1576 | } |
| 1269 | 1577 | |
| 1270 | 1578 | // Function to handle the management of categories |
| 1271 | -function manage_categories() | |
| 1579 | +function calendar_manage_categories() | |
| 1272 | 1580 | { |
| 1273 | - global $wpdb; | |
| 1274 | 1581 | |
| 1275 | - // Calendar must be installed and upgraded before this will work | |
| 1276 | - check_calendar(); | |
| 1277 | - | |
| 1278 | -?> | |
| 1279 | -<style type="text/css"> | |
| 1280 | - <!-- | |
| 1281 | - .error { | |
| 1282 | - background: lightcoral; | |
| 1283 | - border: 1px solid #e64f69; | |
| 1284 | - margin: 1em 5% 10px; | |
| 1285 | - padding: 0 1em 0 1em; | |
| 1286 | - } | |
| 1287 | - | |
| 1288 | - .center { | |
| 1289 | - text-align: center; | |
| 1290 | - } | |
| 1291 | - .right { | |
| 1292 | - text-align: right; | |
| 1293 | - } | |
| 1294 | - .left { | |
| 1295 | - text-align: left; | |
| 1296 | - } | |
| 1297 | - .top { | |
| 1298 | - vertical-align: top; | |
| 1299 | - } | |
| 1300 | - .bold { | |
| 1301 | - font-weight: bold; | |
| 1302 | - } | |
| 1303 | - .private { | |
| 1304 | - color: #e64f69; | |
| 1305 | - } | |
| 1306 | - //--> | |
| 1307 | -</style> | |
| 1308 | -<?php | |
| 1309 | 1582 | // We do some checking to see what we're doing |
| 1310 | 1583 | if (isset($_POST['mode']) && $_POST['mode'] == 'add') |
| 1311 | 1584 | { |
| 1312 | - $sql = "INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_name='".mysql_escape_string($_POST['category_name'])."', category_colour='".mysql_escape_string($_POST['category_colour'])."'"; | |
| 1313 | - $wpdb->get_results($sql); | |
| 1314 | - echo "<div class=\"updated\"><p><strong>Category added successfully</strong></p></div>"; | |
| 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 | + } | |
| 1315 | 1596 | } |
| 1316 | 1597 | else if (isset($_GET['mode']) && isset($_GET['category_id']) && $_GET['mode'] == 'delete') |
| 1317 | 1598 | { |
| 1318 | - $sql = "DELETE FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".mysql_escape_string($_GET['category_id']); | |
| 1319 | - $wpdb->get_results($sql); | |
| 1320 | - $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_category=1 WHERE event_category=".mysql_escape_string($_GET['category_id']); | |
| 1321 | - $wpdb->get_results($sql); | |
| 1322 | - echo "<div class=\"updated\"><p><strong>Category deleted successfully</strong></p></div>"; | |
| 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 | + } | |
| 1323 | 1608 | } |
| 1324 | 1609 | else if (isset($_GET['mode']) && isset($_GET['category_id']) && $_GET['mode'] == 'edit' && !isset($_POST['mode'])) |
| 1325 | 1610 | { |
| 1326 | - $sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".mysql_escape_string($_GET['category_id']); | |
| 1327 | - $cur_cat = $wpdb->get_row($sql); | |
| 1611 | + $cur_cat = calendar_db_get_category_row_by_id(sanitize_text_field(wp_unslash($_GET['category_id']))); | |
| 1328 | 1612 | ?> |
| 1329 | 1613 | <div class="wrap"> |
| 1330 | - <h2><?php _e('Edit Category'); ?></h2> | |
| 1331 | - <form name="catform" id="catform" class="wrap" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> | |
| 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')); ?>"> | |
| 1332 | 1616 | <input type="hidden" name="mode" value="edit" /> |
| 1333 | - <input type="hidden" name="category_id" value="<?php echo $cur_cat->category_id ?>" /> | |
| 1334 | - <div id="item_manager"> | |
| 1335 | - <div style="float: left; width: 98%; clear: both;" class="top"> | |
| 1336 | - <fieldset class="small"><legend><?php _e('Category Name:'); ?></legend> | |
| 1337 | - <input type="text" name="category_name" class="input" size="30" maxlength="30" value="<?php echo $cur_cat->category_name ?>" /> | |
| 1338 | - </fieldset> | |
| 1339 | - <fieldset class="small"><legend><?php _e('Category Colour (Hex format):'); ?></legend> | |
| 1340 | - <input type="text" name="category_colour" class="input" size="10" maxlength="7" value="<?php echo $cur_cat->category_colour ?>" /> | |
| 1341 | - </fieldset> | |
| 1342 | - <br /> | |
| 1343 | - <input type="submit" name="save" class="button bold" value="Save »" /> | |
| 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> | |
| 1344 | 1631 | </div> |
| 1632 | + <div style="clear:both; height:1px;"> </div> | |
| 1345 | 1633 | </div> |
| 1634 | + <input type="submit" name="save" class="button bold" value="<?php esc_attr_e('Save','calendar'); ?> »" /> | |
| 1346 | 1635 | </form> |
| 1347 | 1636 | </div> |
| 1348 | 1637 | <?php |
| 1349 | 1638 | } |
| @@ -1348,52 +1637,80 @@ | ||
| 1348 | 1637 | <?php |
| 1349 | 1638 | } |
| 1350 | 1639 | else if (isset($_POST['mode']) && isset($_POST['category_id']) && isset($_POST['category_name']) && isset($_POST['category_colour']) && $_POST['mode'] == 'edit') |
| 1351 | 1640 | { |
| 1352 | - $sql = "UPDATE " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_name='".mysql_escape_string($_POST['category_name'])."', category_colour='".mysql_escape_string($_POST['category_colour'])."' WHERE category_id=".mysql_escape_string($_POST['category_id']); | |
| 1353 | - $wpdb->get_results($sql); | |
| 1354 | - echo "<div class=\"updated\"><p><strong>Category edited successfully</strong></p></div>"; | |
| 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 | + } | |
| 1355 | 1653 | } |
| 1356 | 1654 | |
| 1357 | - if ($_GET['mode'] != 'edit' || $_POST['mode'] == 'edit') | |
| 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) | |
| 1358 | 1668 | { |
| 1359 | 1669 | ?> |
| 1360 | 1670 | |
| 1361 | 1671 | <div class="wrap"> |
| 1362 | - <h2><?php _e('Add Category'); ?></h2> | |
| 1363 | - <form name="catform" id="catform" class="wrap" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> | |
| 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')); ?>"> | |
| 1364 | 1674 | <input type="hidden" name="mode" value="add" /> |
| 1365 | 1675 | <input type="hidden" name="category_id" value=""> |
| 1366 | - <div id="item_manager"> | |
| 1367 | - <div style="float: left; width: 98%; clear: both;" class="top"> | |
| 1368 | - <fieldset class="small"><legend><?php _e('Category Name:'); ?></legend> | |
| 1369 | - <input type="text" name="category_name" class="input" size="30" maxlength="30" value="" /> | |
| 1370 | - </fieldset> | |
| 1371 | - <fieldset class="small"><legend><?php _e('Category Colour (Hex format):'); ?></legend> | |
| 1372 | - <input type="text" name="category_colour" class="input" size="10" maxlength="7" value="" /> | |
| 1373 | - </fieldset> | |
| 1374 | - <br /> | |
| 1375 | - <input type="submit" name="save" class="button bold" value="Save »" /> | |
| 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> | |
| 1376 | 1689 | </div> |
| 1690 | + <div style="clear:both; height:1px;"> </div> | |
| 1377 | 1691 | </div> |
| 1692 | + <input type="submit" name="save" class="button bold" value="<?php esc_attr_e('Save','calendar'); ?> »" /> | |
| 1378 | 1693 | </form> |
| 1379 | - <h2><?php _e('Manage Categories'); ?></h2> | |
| 1694 | + <h2><?php esc_html_e('Manage Categories','calendar'); ?></h2> | |
| 1380 | 1695 | <?php |
| 1381 | 1696 | |
| 1382 | 1697 | // We pull the categories from the database |
| 1383 | - $categories = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " ORDER BY category_id ASC"); | |
| 1698 | + $categories = calendar_db_get_all_categories(); | |
| 1384 | 1699 | |
| 1385 | 1700 | if ( !empty($categories) ) |
| 1386 | 1701 | { |
| 1387 | 1702 | ?> |
| 1388 | - <table width="50%" cellpadding="3" cellspacing="3"> | |
| 1703 | + <table class="widefat page fixed" width="50%" cellpadding="3" cellspacing="3"> | |
| 1704 | + <thead> | |
| 1389 | 1705 | <tr> |
| 1390 | - <th scope="col"><?php _e('ID') ?></th> | |
| 1391 | - <th scope="col"><?php _e('Category Name') ?></th> | |
| 1392 | - <th scope="col"><?php _e('Category Colour') ?></th> | |
| 1393 | - <th scope="col"><?php _e('Edit') ?></th> | |
| 1394 | - <th scope="col"><?php _e('Delete') ?></th> | |
| 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> | |
| 1395 | 1711 | </tr> |
| 1712 | + </thead> | |
| 1396 | 1713 | <?php |
| 1397 | 1714 | $class = ''; |
| 1398 | 1715 | foreach ( $categories as $category ) |
| 1399 | 1716 | { |
| @@ -1398,24 +1715,22 @@ | ||
| 1398 | 1715 | foreach ( $categories as $category ) |
| 1399 | 1716 | { |
| 1400 | 1717 | $class = ($class == 'alternate') ? '' : 'alternate'; |
| 1401 | 1718 | ?> |
| 1402 | - <tr class="<?php echo $class; ?>"> | |
| 1403 | - <th scope="row"><?php echo $category->category_id; ?></th> | |
| 1404 | - <td><?php echo $category->category_name; ?></td> | |
| 1405 | - <td style="background-color:<?php echo $category->category_colour; ?>;"> </td> | |
| 1406 | - <td><a href="<?php echo $_SERVER['REQUEST_URI'] ?>&mode=edit&category_id=<?php echo $category->category_id;?>" class='edit'><?php echo __('Edit'); ?></a></td> | |
| 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> | |
| 1407 | 1724 | <?php |
| 1408 | 1725 | if ($category->category_id == 1) |
| 1409 | 1726 | { |
| 1410 | - ?> | |
| 1411 | - <td>N/A</td> | |
| 1412 | - <?php | |
| 1727 | + echo '<td>'.esc_html__('N/A','calendar').'</td>'; | |
| 1413 | 1728 | } |
| 1414 | 1729 | else |
| 1415 | 1730 | { |
| 1416 | 1731 | ?> |
| 1417 | - <td><a href="<?php echo $_SERVER['REQUEST_URI'] ?>&mode=delete&category_id=<?php echo $category->category_id;?>" class="delete" onclick="return confirm('Are you sure you want to delete this category?')"><?php echo __('Delete'); ?></a></td> | |
| 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> | |
| 1418 | 1733 | <?php |
| 1419 | 1734 | } |
| 1420 | 1735 | ?> |
| 1421 | 1736 | </tr> |
| @@ -1426,143 +1741,142 @@ | ||
| 1426 | 1741 | <?php |
| 1427 | 1742 | } |
| 1428 | 1743 | else |
| 1429 | 1744 | { |
| 1430 | - ?> | |
| 1431 | - <p><?php _e("There are no categories in the database - something has gone wrong!") ?></p> | |
| 1432 | - <?php | |
| 1745 | + echo '<p>'.esc_html__('There are no categories in the database - something has gone wrong!','calendar').'</p>'; | |
| 1433 | 1746 | } |
| 1434 | 1747 | |
| 1435 | -?> | |
| 1748 | + ?> | |
| 1436 | 1749 | </div> |
| 1437 | 1750 | |
| 1438 | -<?php | |
| 1751 | + <?php | |
| 1439 | 1752 | } |
| 1440 | 1753 | } |
| 1441 | 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 | + | |
| 1442 | 1793 | // Function to return a prefix which will allow the correct |
| 1443 | 1794 | // placement of arguments into the query string. |
| 1444 | -function permalink_prefix() | |
| 1795 | +function calendar_permalink_prefix() | |
| 1445 | 1796 | { |
| 1446 | 1797 | // Get the permalink structure from WordPress |
| 1447 | - $p_link = get_permalink(); | |
| 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 | + } | |
| 1448 | 1804 | |
| 1449 | - // Work out what the real URL we are viewing is | |
| 1450 | - $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; | |
| 1451 | - $protocol = substr(strtolower($_SERVER["SERVER_PROTOCOL"]), 0, strpos(strtolower($_SERVER["SERVER_PROTOCOL"]), "/")).$s; | |
| 1452 | - $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); | |
| 1453 | - $real_link = $protocol.'://'.$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; | |
| 1805 | + // Based on the structure, append the appropriate ending | |
| 1806 | + if (!(strstr($p_link,'?'))) { $link_part = $p_link.'?'; } else { $link_part = $p_link.'&'; } | |
| 1454 | 1807 | |
| 1455 | - // Now use all of that to get the correctly craft the Calendar link prefix | |
| 1456 | - if (strstr($p_link, '?') && $p_link == $real_link) | |
| 1457 | - { | |
| 1458 | - $link_part = $p_link.'&'; | |
| 1459 | - } | |
| 1460 | - else if ($p_link == $real_link) | |
| 1461 | - { | |
| 1462 | - $link_part = $p_link.'?'; | |
| 1463 | - } | |
| 1464 | - else if (strstr($real_link, '?')) | |
| 1465 | - { | |
| 1466 | - if (isset($_GET['month']) && isset($_GET['yr'])) | |
| 1467 | - { | |
| 1468 | - $new_tail = split("&", $real_link); | |
| 1469 | - foreach ($new_tail as $item) | |
| 1470 | - { | |
| 1471 | - if (!strstr($item, 'month') && !strstr($item, 'yr')) | |
| 1472 | - { | |
| 1473 | - $link_part .= $item.'&'; | |
| 1474 | - } | |
| 1475 | - } | |
| 1476 | - if (!strstr($link_part, '?')) | |
| 1477 | - { | |
| 1478 | - $new_tail = split("month", $link_part); | |
| 1479 | - $link_part = $new_tail[0].'?'.$new_tail[1]; | |
| 1480 | - } | |
| 1481 | - } | |
| 1482 | - else | |
| 1483 | - { | |
| 1484 | - $link_part = $real_link.'&'; | |
| 1485 | - } | |
| 1486 | - } | |
| 1487 | - else | |
| 1488 | - { | |
| 1489 | - $link_part = $real_link.'?'; | |
| 1490 | - } | |
| 1491 | - | |
| 1492 | 1808 | return $link_part; |
| 1493 | 1809 | } |
| 1494 | 1810 | |
| 1495 | 1811 | // Configure the "Next" link in the calendar |
| 1496 | -function next_link($cur_year,$cur_month) | |
| 1812 | +function calendar_next_link($cur_year,$cur_month,$minical = false) | |
| 1497 | 1813 | { |
| 1498 | - $mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sept','oct','nov','dec'); | |
| 1814 | + $mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'); | |
| 1499 | 1815 | $next_year = $cur_year + 1; |
| 1500 | 1816 | |
| 1501 | 1817 | if ($cur_month == 12) |
| 1502 | 1818 | { |
| 1503 | - return '<a href="' . permalink_prefix() . 'month=jan&yr=' . $next_year . '">Next »</a>'; | |
| 1819 | + if ($minical) { $rlink = ''; } else { $rlink = __('Next','calendar'); } | |
| 1820 | + return '<a href="' . calendar_permalink_prefix() . 'calendar_month=jan&calendar_yr=' . $next_year . '">'.$rlink.' »</a>'; | |
| 1504 | 1821 | } |
| 1505 | 1822 | else |
| 1506 | 1823 | { |
| 1507 | 1824 | $next_month = $cur_month + 1; |
| 1508 | 1825 | $month = $mod_rewrite_months[$next_month]; |
| 1509 | - return '<a href="' . permalink_prefix() . 'month='.$month.'&yr=' . $cur_year . '">Next »</a>'; | |
| 1826 | + if ($minical) { $rlink = ''; } else { $rlink = __('Next','calendar'); } | |
| 1827 | + return '<a href="' . calendar_permalink_prefix() . 'calendar_month='.$month.'&calendar_yr=' . $cur_year . '">'.$rlink.' »</a>'; | |
| 1510 | 1828 | } |
| 1511 | 1829 | } |
| 1512 | 1830 | |
| 1513 | 1831 | // Configure the "Previous" link in the calendar |
| 1514 | -function prev_link($cur_year,$cur_month) | |
| 1832 | +function calendar_prev_link($cur_year,$cur_month,$minical = false) | |
| 1515 | 1833 | { |
| 1516 | - $mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sept','oct','nov','dec'); | |
| 1834 | + $mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'); | |
| 1517 | 1835 | $last_year = $cur_year - 1; |
| 1518 | 1836 | |
| 1519 | 1837 | if ($cur_month == 1) |
| 1520 | 1838 | { |
| 1521 | - return '<a href="' . permalink_prefix() . 'month=dec&yr='. $last_year .'">« Prev</a>'; | |
| 1839 | + if ($minical) { $llink = ''; } else { $llink = __('Prev','calendar'); } | |
| 1840 | + return '<a href="' . calendar_permalink_prefix() . 'calendar_month=dec&calendar_yr='. $last_year .'">« '.$llink.'</a>'; | |
| 1522 | 1841 | } |
| 1523 | 1842 | else |
| 1524 | 1843 | { |
| 1525 | 1844 | $next_month = $cur_month - 1; |
| 1526 | 1845 | $month = $mod_rewrite_months[$next_month]; |
| 1527 | - return '<a href="' . permalink_prefix() . 'month='.$month.'&yr=' . $cur_year . '">« Prev</a>'; | |
| 1846 | + if ($minical) { $llink = ''; } else { $llink = __('Prev','calendar'); } | |
| 1847 | + return '<a href="' . calendar_permalink_prefix() . 'calendar_month='.$month.'&calendar_yr=' . $cur_year . '">« '.$llink.'</a>'; | |
| 1528 | 1848 | } |
| 1529 | 1849 | } |
| 1530 | 1850 | |
| 1531 | 1851 | // Print upcoming events |
| 1532 | -function upcoming_events() | |
| 1852 | +function calendar_upcoming_events($cat_list = '') | |
| 1533 | 1853 | { |
| 1534 | - global $wpdb; | |
| 1535 | - | |
| 1536 | - // This function cannot be called unless calendar is up to date | |
| 1537 | - check_calendar(); | |
| 1538 | - | |
| 1539 | - // Find out if we should be displaying upcoming events | |
| 1540 | - $display = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_upcoming'",0,0); | |
| 1541 | - | |
| 1542 | - if ($display == 'true') | |
| 1854 | + // Find out if we should be displaying upcoming events | |
| 1855 | + if (calendar_get_config_value('display_upcoming') == 'true') | |
| 1543 | 1856 | { |
| 1544 | 1857 | // Get number of days we should go into the future |
| 1545 | - $future_days = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_upcoming_days'",0,0); | |
| 1858 | + $future_days = calendar_get_config_value('display_upcoming_days'); | |
| 1546 | 1859 | $day_count = 1; |
| 1547 | - | |
| 1860 | + | |
| 1861 | + $output = ''; | |
| 1548 | 1862 | while ($day_count < $future_days+1) |
| 1549 | 1863 | { |
| 1550 | - list($y,$m,$d) = split("-",date("Y-m-d",mktime($day_count*24,0,0,date("m"),date("d"),date("Y")))); | |
| 1551 | - $events = grab_events($y,$m,$d); | |
| 1552 | - usort($events, "time_cmp"); | |
| 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"); | |
| 1553 | 1867 | if (count($events) != 0) { |
| 1554 | - $output .= '<li>'.date(get_option('date_format'),mktime($day_count*24,0,0,date("m"),date("d"),date("Y"))).'<ul>'; | |
| 1555 | - } | |
| 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 | + } | |
| 1556 | 1870 | foreach($events as $event) |
| 1557 | 1871 | { |
| 1558 | 1872 | if ($event->event_time == '00:00:00') { |
| 1559 | - $time_string = ' all day'; | |
| 1873 | + $time_string = ' <span class="calendar_time all_day" style="position:relative;display:inline;width:unset;background:none;">'.esc_html__('all day','calendar').'</span>'; | |
| 1560 | 1874 | } |
| 1561 | 1875 | else { |
| 1562 | - $time_string = ' at '.date(get_option('time_format'), strtotime($event->event_time)); | |
| 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>'; | |
| 1563 | 1877 | } |
| 1564 | - $output .= '<li>'.draw_widget_event($event).$time_string.'</li>'; | |
| 1878 | + $output .= '<li>'.calendar_draw_event($event).$time_string.'</li>'; | |
| 1565 | 1879 | } |
| 1566 | 1880 | if (count($events) != 0) { |
| 1567 | 1881 | $output .= '</ul></li>'; |
| 1568 | 1882 | } |
| @@ -1570,11 +1884,11 @@ | ||
| 1570 | 1884 | } |
| 1571 | 1885 | |
| 1572 | 1886 | if ($output != '') |
| 1573 | 1887 | { |
| 1574 | - $visual = '<li class="upcoming-events"><h2>Upcoming Events</h2><ul>'; | |
| 1888 | + $visual = '<ul>'; | |
| 1575 | 1889 | $visual .= $output; |
| 1576 | - $visual .= '</ul></li>'; | |
| 1890 | + $visual .= '</ul>'; | |
| 1577 | 1891 | return $visual; |
| 1578 | 1892 | } |
| 1579 | 1893 | } |
| 1580 | 1894 | } |
| @@ -1579,34 +1893,27 @@ | ||
| 1579 | 1893 | } |
| 1580 | 1894 | } |
| 1581 | 1895 | |
| 1582 | 1896 | // Print todays events |
| 1583 | -function todays_events() | |
| 1897 | +function calendar_todays_events($cat_list = '') | |
| 1584 | 1898 | { |
| 1585 | - global $wpdb; | |
| 1586 | - | |
| 1587 | - // This function cannot be called unless calendar is up to date | |
| 1588 | - check_calendar(); | |
| 1589 | - | |
| 1590 | 1899 | // Find out if we should be displaying todays events |
| 1591 | - $display = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_todays'",0,0); | |
| 1592 | - | |
| 1593 | - if ($display == 'true') | |
| 1900 | + if (calendar_get_config_value('display_todays') == 'true') | |
| 1594 | 1901 | { |
| 1595 | - $output = '<li class="todays-events"><h2>Todays Events</h2><ul>'; | |
| 1596 | - $events = grab_events(date("Y"),date("m"),date("d")); | |
| 1597 | - usort($events, "time_cmp"); | |
| 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"); | |
| 1598 | 1905 | foreach($events as $event) |
| 1599 | 1906 | { |
| 1600 | 1907 | if ($event->event_time == '00:00:00') { |
| 1601 | - $time_string = ' all day'; | |
| 1908 | + $time_string = ' <span class="calendar_time all_day" style="position:relative;display:inline;width:unset;background:none;">'.esc_html__('all day','calendar').'</span>'; | |
| 1602 | 1909 | } |
| 1603 | 1910 | else { |
| 1604 | - $time_string = ' at '.date(get_option('time_format'), strtotime($event->event_time)); | |
| 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>'; | |
| 1605 | 1912 | } |
| 1606 | - $output .= '<li>'.draw_widget_event($event).$time_string.'</li>'; | |
| 1913 | + $output .= '<li>'.calendar_draw_event($event).$time_string.'</li>'; | |
| 1607 | 1914 | } |
| 1608 | - $output .= '</ul></li>'; | |
| 1915 | + $output .= '</ul>'; | |
| 1609 | 1916 | if (count($events) != 0) |
| 1610 | 1917 | { |
| 1611 | 1918 | return $output; |
| 1612 | 1919 | } |
| @@ -1613,9 +1920,9 @@ | ||
| 1613 | 1920 | } |
| 1614 | 1921 | } |
| 1615 | 1922 | |
| 1616 | 1923 | // Function to compare time in event objects |
| 1617 | -function time_cmp($a, $b) | |
| 1924 | +function calendar_time_cmp($a, $b) | |
| 1618 | 1925 | { |
| 1619 | 1926 | if ($a->event_time == $b->event_time) { |
| 1620 | 1927 | return 0; |
| 1621 | 1928 | } |
| @@ -1622,488 +1929,519 @@ | ||
| 1622 | 1929 | return ($a->event_time < $b->event_time) ? -1 : 1; |
| 1623 | 1930 | } |
| 1624 | 1931 | |
| 1625 | 1932 | // Used to draw multiple events |
| 1626 | -function draw_events($events) | |
| 1933 | +function calendar_draw_events($events) | |
| 1627 | 1934 | { |
| 1628 | 1935 | // We need to sort arrays of objects by time |
| 1629 | - usort($events, "time_cmp"); | |
| 1630 | - | |
| 1936 | + usort($events, "calendar_time_cmp"); | |
| 1937 | + $output = ''; | |
| 1631 | 1938 | // Now process the events |
| 1632 | 1939 | foreach($events as $event) |
| 1633 | 1940 | { |
| 1634 | - $output .= draw_event($event); | |
| 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); | |
| 1635 | 1943 | } |
| 1636 | 1944 | return $output; |
| 1637 | 1945 | } |
| 1638 | 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 | +} | |
| 1639 | 1991 | |
| 1992 | +function calendar_register_minical_widget() { | |
| 1993 | + register_widget('calendar_minical_widget'); | |
| 1994 | +} | |
| 1995 | + | |
| 1640 | 1996 | // The widget to show todays events in the sidebar |
| 1641 | -function widget_init_calendar_today() { | |
| 1642 | - // Check for required functions | |
| 1643 | - if (!function_exists('register_sidebar_widget')) | |
| 1644 | - return; | |
| 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 | +} | |
| 1645 | 2040 | |
| 1646 | - function widget_calendar_today($args) { | |
| 1647 | - extract($args); | |
| 1648 | - ?> | |
| 1649 | - <?php echo todays_events(); ?> | |
| 1650 | - <?php | |
| 1651 | - } | |
| 1652 | - | |
| 1653 | - register_sidebar_widget('Todays Events','widget_calendar_today'); | |
| 1654 | - } | |
| 1655 | - | |
| 1656 | -// The widget to show todays events in the sidebar | |
| 1657 | -function widget_init_calendar_upcoming() { | |
| 1658 | - // Check for required functions | |
| 1659 | - if (!function_exists('register_sidebar_widget')) | |
| 1660 | - return; | |
| 1661 | - | |
| 1662 | - function widget_calendar_upcoming($args) { | |
| 1663 | - extract($args); | |
| 1664 | - ?> | |
| 1665 | - <?php echo upcoming_events(); ?> | |
| 1666 | - <?php | |
| 1667 | - } | |
| 1668 | - | |
| 1669 | - register_sidebar_widget('Upcoming Events','widget_calendar_upcoming'); | |
| 2041 | +function calendar_register_today_widget() { | |
| 2042 | + register_widget('calendar_today_widget'); | |
| 1670 | 2043 | } |
| 1671 | 2044 | |
| 1672 | - | |
| 1673 | -// Used to draw an event to the screen | |
| 1674 | -function draw_event($event) | |
| 1675 | -{ | |
| 1676 | - global $wpdb; | |
| 1677 | - | |
| 1678 | - // Calendar must be updated to run this function | |
| 1679 | - check_calendar(); | |
| 1680 | - | |
| 1681 | - // Before we do anything we want to know if we | |
| 1682 | - // should display the author and/or show categories. | |
| 1683 | - // We check for this later | |
| 1684 | - $display_author = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_author'",0,0); | |
| 1685 | - $show_cat = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='enable_categories'",0,0); | |
| 1686 | - | |
| 1687 | - if ($show_cat == 'true') | |
| 1688 | - { | |
| 1689 | - $sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".$event->event_category; | |
| 1690 | - $cat_details = $wpdb->get_row($sql); | |
| 1691 | - $style = "background-color:".$cat_details->category_colour.";"; | |
| 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 ); | |
| 1692 | 2053 | } |
| 1693 | - | |
| 1694 | - $header_details .= '<div class="event-title">'.$event->event_title.'</div><div class="event-title-break"></div>'; | |
| 1695 | - if ($event->event_time != "00:00:00") | |
| 1696 | - { | |
| 1697 | - $header_details .= '<strong>Time:</strong> ' . date(get_option('time_format'), strtotime($event->event_time)) . '<br />'; | |
| 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 | + } | |
| 1698 | 2067 | } |
| 1699 | - if ($display_author == 'true') | |
| 1700 | - { | |
| 1701 | - $e = get_userdata($event->event_author); | |
| 1702 | - $header_details .= '<strong>Posted by:</strong> '.$e->display_name.'<br />'; | |
| 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 | |
| 1703 | 2080 | } |
| 1704 | - if ($display_author == 'true' || $event->event_time != "00:00:00") | |
| 1705 | - { | |
| 1706 | - $header_details .= '<div class="event-content-break"></div>'; | |
| 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; | |
| 1707 | 2087 | } |
| 1708 | - if ($event->event_link != '') { $linky = $event->event_link; } | |
| 1709 | - else { $linky = '#'; } | |
| 2088 | +} | |
| 1710 | 2089 | |
| 1711 | - $details = '<br /> | |
| 1712 | -* <span class="calnk" nowrap="nowrap"><a href="'.$linky.'" style="'.$style.'">' . $event->event_title . '<span style="'.$style.'">' . $header_details . '' . $event->event_desc . '</span></a></span>'; | |
| 2090 | +function calendar_register_upcoming_widget() { | |
| 2091 | + register_widget('calendar_upcoming_widget'); | |
| 2092 | +} | |
| 1713 | 2093 | |
| 1714 | - return $details; | |
| 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 | + } | |
| 1715 | 2114 | } |
| 1716 | 2115 | |
| 1717 | -// Draw an event but customise the HTML for use in the widget | |
| 1718 | -function draw_widget_event($event) | |
| 2116 | +// Used to draw an event to the screen | |
| 2117 | +function calendar_draw_event($event) | |
| 1719 | 2118 | { |
| 1720 | - global $wpdb; | |
| 1721 | 2119 | |
| 1722 | - // Calendar must be updated to run this function | |
| 1723 | - check_calendar(); | |
| 1724 | - | |
| 1725 | - // Before we do anything we want to know if we | |
| 1726 | - // should display the author and/or show categories. | |
| 1727 | - // We check for this later | |
| 1728 | - $display_author = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_author'",0,0); | |
| 1729 | - $show_cat = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='enable_categories'",0,0); | |
| 1730 | - | |
| 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 = ''; | |
| 1731 | 2127 | if ($show_cat == 'true') |
| 1732 | 2128 | { |
| 1733 | - $sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".$event->event_category; | |
| 1734 | - $cat_details = $wpdb->get_row($sql); | |
| 1735 | - $style = "background-color:".$cat_details->category_colour.";"; | |
| 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 | + | |
| 1736 | 2137 | } |
| 1737 | 2138 | |
| 1738 | - $header_details .= '<div class="event-title">'.$event->event_title.'</div><div class="event-title-break"></div>'; | |
| 2139 | + $header_details = '<span class="event-title" '.$style.'>'.$event->event_title.'</span><br /> | |
| 2140 | +<span class="event-title-break"></span><br />'; | |
| 1739 | 2141 | if ($event->event_time != "00:00:00") |
| 1740 | 2142 | { |
| 1741 | - $header_details .= '<strong>Time:</strong> ' . date(get_option('time_format'), strtotime($event->event_time)) . '<br />'; | |
| 2143 | + $header_details .= '<strong>'.esc_html__('Time','calendar').':</strong> ' . gmdate(get_option('time_format'), strtotime($event->event_time)) . '<br />'; | |
| 1742 | 2144 | } |
| 1743 | 2145 | if ($display_author == 'true') |
| 1744 | 2146 | { |
| 1745 | 2147 | $e = get_userdata($event->event_author); |
| 1746 | - $header_details .= '<strong>Posted by:</strong> '.$e->display_name.'<br />'; | |
| 2148 | + $header_details .= '<strong>'.esc_html__('Posted by', 'calendar').':</strong> '.$e->display_name.'<br />'; | |
| 1747 | 2149 | } |
| 1748 | 2150 | if ($display_author == 'true' || $event->event_time != "00:00:00") |
| 1749 | 2151 | { |
| 1750 | - $header_details .= '<div class="event-content-break"></div>'; | |
| 2152 | + $header_details .= '<span class="event-content-break"></span><br />'; | |
| 1751 | 2153 | } |
| 1752 | 2154 | if ($event->event_link != '') { $linky = $event->event_link; } |
| 1753 | 2155 | else { $linky = '#'; } |
| 2156 | + | |
| 2157 | + $linky = apply_filters('calendar_modify_link', $linky, $event); | |
| 1754 | 2158 | |
| 1755 | - $details = '<span class="calnk" nowrap="nowrap"><a href="'.$linky.'">' . $event->event_title . '<span style="'.$style.'">' . $header_details . '' . $event->event_desc . '</span></a></span>'; | |
| 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>'; | |
| 1756 | 2160 | |
| 1757 | 2161 | return $details; |
| 1758 | 2162 | } |
| 1759 | 2163 | |
| 1760 | 2164 | // Grab all events for the requested date from calendar |
| 1761 | -function grab_events($y,$m,$d) | |
| 2165 | +function calendar_grab_events($y,$m,$d,$typing,$cat_list = '') | |
| 1762 | 2166 | { |
| 1763 | - global $wpdb; | |
| 2167 | + global $wpdb; | |
| 1764 | 2168 | |
| 1765 | 2169 | $arr_events = array(); |
| 1766 | 2170 | |
| 1767 | 2171 | // Get the date format right |
| 1768 | 2172 | $date = $y . '-' . $m . '-' . $d; |
| 1769 | - | |
| 1770 | - // Firstly we check for conventional events. These will form the first instance of a recurring event | |
| 1771 | - // or the only instance of a one-off event | |
| 1772 | - $events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_begin <= '$date' AND event_end >= '$date' AND event_recur = 'S' ORDER BY event_id"); | |
| 1773 | - if (!empty($events)) | |
| 1774 | - { | |
| 1775 | - foreach($events as $event) | |
| 1776 | - { | |
| 1777 | - array_push($arr_events, $event); | |
| 1778 | - } | |
| 1779 | - } | |
| 1780 | 2173 | |
| 1781 | - // Even if there were results for that query, we may still have events recurring | |
| 1782 | - // from the past on this day. We now methodically check the for these events | |
| 2174 | + // Query the events | |
| 2175 | + $events = calendar_db_fetch_events_for_date($date, $cat_list); | |
| 1783 | 2176 | |
| 1784 | - /* | |
| 1785 | - The yearly code - easy because the day and month will be the same, so we return all yearly | |
| 1786 | - events that match the date part. Out of these we show those with a repeat of 0, and fast-foward | |
| 1787 | - a number of years for those with a value more than 0. Those that land in the future are displayed. | |
| 1788 | - */ | |
| 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 | |
| 1789 | 2189 | |
| 1790 | - | |
| 1791 | - // Deal with forever recurring year events | |
| 1792 | - $events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_recur = 'Y' AND EXTRACT(YEAR FROM '$date') >= EXTRACT(YEAR FROM event_begin) AND event_repeats = 0 ORDER BY event_id"); | |
| 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)); | |
| 1793 | 2194 | |
| 1794 | - if (!empty($events)) | |
| 1795 | - { | |
| 1796 | - foreach($events as $event) | |
| 1797 | - { | |
| 1798 | - // This is going to get complex so lets setup what we would place in for | |
| 1799 | - // an event so we can drop it in with ease | |
| 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 | |
| 1800 | 2216 | |
| 1801 | - // Technically we don't care about the years, but we need to find out if the | |
| 1802 | - // event spans the turn of a year so we can deal with it appropriately. | |
| 1803 | - $year_begin = date('Y',strtotime($event->event_begin)); | |
| 1804 | - $year_end = date('Y',strtotime($event->event_end)); | |
| 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)); | |
| 1805 | 2221 | |
| 1806 | - if ($year_begin == $year_end) | |
| 1807 | - { | |
| 1808 | - if (date('m-d',strtotime($event->event_begin)) <= date('m-d',strtotime($date)) && | |
| 1809 | - date('m-d',strtotime($event->event_end)) >= date('m-d',strtotime($date))) | |
| 1810 | - { | |
| 1811 | - array_push($arr_events, $event); | |
| 1812 | - } | |
| 1813 | - } | |
| 1814 | - else if ($year_begin < $year_end) | |
| 1815 | - { | |
| 1816 | - if (date('m-d',strtotime($event->event_begin)) <= date('m-d',strtotime($date)) || | |
| 1817 | - date('m-d',strtotime($event->event_end)) >= date('m-d',strtotime($date))) | |
| 1818 | - { | |
| 1819 | - array_push($arr_events, $event); | |
| 1820 | - } | |
| 1821 | - } | |
| 1822 | - } | |
| 1823 | - } | |
| 1824 | - | |
| 1825 | - // Now the ones that happen a finite number of times | |
| 1826 | - $events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_recur = 'Y' AND EXTRACT(YEAR FROM '$date') >= EXTRACT(YEAR FROM event_begin) AND event_repeats != 0 AND (EXTRACT(YEAR FROM '$date')-EXTRACT(YEAR FROM event_begin)) <= event_repeats ORDER BY event_id"); | |
| 1827 | - if (!empty($events)) | |
| 1828 | - { | |
| 1829 | - foreach($events as $event) | |
| 1830 | - { | |
| 1831 | - // This is going to get complex so lets setup what we would place in for | |
| 1832 | - // an event so we can drop it in with ease | |
| 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! | |
| 1833 | 2242 | |
| 1834 | - // Technically we don't care about the years, but we need to find out if the | |
| 1835 | - // event spans the turn of a year so we can deal with it appropriately. | |
| 1836 | - $year_begin = date('Y',strtotime($event->event_begin)); | |
| 1837 | - $year_end = date('Y',strtotime($event->event_end)); | |
| 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)); | |
| 1838 | 2247 | |
| 1839 | - if ($year_begin == $year_end) | |
| 1840 | - { | |
| 1841 | - if (date('m-d',strtotime($event->event_begin)) <= date('m-d',strtotime($date)) && | |
| 1842 | - date('m-d',strtotime($event->event_end)) >= date('m-d',strtotime($date))) | |
| 1843 | - { | |
| 1844 | - array_push($arr_events, $event); | |
| 1845 | - } | |
| 1846 | - } | |
| 1847 | - else if ($year_begin < $year_end) | |
| 1848 | - { | |
| 1849 | - if (date('m-d',strtotime($event->event_begin)) <= date('m-d',strtotime($date)) || | |
| 1850 | - date('m-d',strtotime($event->event_end)) >= date('m-d',strtotime($date))) | |
| 1851 | - { | |
| 1852 | - array_push($arr_events, $event); | |
| 1853 | - } | |
| 1854 | - } | |
| 1855 | - } | |
| 1856 | - } | |
| 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); | |
| 1857 | 2254 | |
| 1858 | - /* | |
| 1859 | - The monthly code - just as easy because as long as the day of the month is correct, then we | |
| 1860 | - show the event | |
| 1861 | - */ | |
| 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 | |
| 1862 | 2289 | |
| 1863 | - // The monthly events that never stop recurring | |
| 1864 | - $events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_recur = 'M' AND EXTRACT(YEAR FROM '$date') >= EXTRACT(YEAR FROM event_begin) AND event_repeats = 0 ORDER BY event_id"); | |
| 1865 | - if (!empty($events)) | |
| 1866 | - { | |
| 1867 | - foreach($events as $event) | |
| 1868 | - { | |
| 1869 | - // This is going to get complex so lets setup what we would place in for | |
| 1870 | - // an event so we can drop it in with ease | |
| 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)); | |
| 1871 | 2296 | |
| 1872 | - // Technically we don't care about the years or months, but we need to find out if the | |
| 1873 | - // event spans the turn of a year or month so we can deal with it appropriately. | |
| 1874 | - $month_begin = date('m',strtotime($event->event_begin)); | |
| 1875 | - $month_end = date('m',strtotime($event->event_end)); | |
| 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; | |
| 1876 | 2305 | |
| 1877 | - if ($month_begin == $month_end) | |
| 1878 | - { | |
| 1879 | - if (date('d',strtotime($event->event_begin)) <= date('d',strtotime($date)) && | |
| 1880 | - date('d',strtotime($event->event_end)) >= date('d',strtotime($date))) | |
| 1881 | - { | |
| 1882 | - array_push($arr_events, $event); | |
| 1883 | - } | |
| 1884 | - } | |
| 1885 | - else if ($month_begin < $month_end) | |
| 1886 | - { | |
| 1887 | - if ( ($event->event_begin <= date('Y-m-d',strtotime($date))) && (date('d',strtotime($event->event_begin)) <= date('d',strtotime($date)) || | |
| 1888 | - date('d',strtotime($event->event_end)) >= date('d',strtotime($date))) ) | |
| 1889 | - { | |
| 1890 | - array_push($arr_events, $event); | |
| 1891 | - } | |
| 1892 | - } | |
| 1893 | - } | |
| 1894 | - } | |
| 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 | + } | |
| 1895 | 2323 | |
| 1896 | - | |
| 1897 | - // Now the ones that happen a finite number of times | |
| 1898 | - $events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_recur = 'M' AND EXTRACT(YEAR FROM '$date') >= EXTRACT(YEAR FROM event_begin) AND event_repeats != 0 AND (PERIOD_DIFF(EXTRACT(YEAR_MONTH FROM '$date'),EXTRACT(YEAR_MONTH FROM event_begin))) <= event_repeats ORDER BY event_id"); | |
| 1899 | - if (!empty($events)) | |
| 1900 | - { | |
| 1901 | - foreach($events as $event) | |
| 1902 | - { | |
| 1903 | - // This is going to get complex so lets setup what we would place in for | |
| 1904 | - // an event so we can drop it in with ease | |
| 1905 | - | |
| 1906 | - // Technically we don't care about the years or months, but we need to find out if the | |
| 1907 | - // event spans the turn of a year or month so we can deal with it appropriately. | |
| 1908 | - $month_begin = date('m',strtotime($event->event_begin)); | |
| 1909 | - $month_end = date('m',strtotime($event->event_end)); | |
| 1910 | - | |
| 1911 | - if ($month_begin == $month_end) | |
| 1912 | - { | |
| 1913 | - if (date('d',strtotime($event->event_begin)) <= date('d',strtotime($date)) && | |
| 1914 | - date('d',strtotime($event->event_end)) >= date('d',strtotime($date))) | |
| 1915 | - { | |
| 1916 | - array_push($arr_events, $event); | |
| 1917 | - } | |
| 1918 | - } | |
| 1919 | - else if ($month_begin < $month_end) | |
| 1920 | - { | |
| 1921 | - if ( ($event->event_begin <= date('Y-m-d',strtotime($date))) && (date('d',strtotime($event->event_begin)) <= date('d',strtotime($date)) || | |
| 1922 | - date('d',strtotime($event->event_end)) >= date('d',strtotime($date))) ) | |
| 1923 | - { | |
| 1924 | - array_push($arr_events, $event); | |
| 1925 | - } | |
| 1926 | - } | |
| 1927 | - } | |
| 1928 | - } | |
| 1929 | - | |
| 1930 | - | |
| 1931 | - /* | |
| 1932 | - Weekly - well isn't this fun! We need to scan all weekly events, find what day they fell on | |
| 1933 | - and see if that matches the current day. If it does, we check to see if the repeats are 0. | |
| 1934 | - If they are, display the event, if not, we fast forward from the original day in week blocks | |
| 1935 | - until the number is exhausted. If the date we arrive at is in the future, display the event. | |
| 1936 | - */ | |
| 1937 | - | |
| 1938 | - // The weekly events that never stop recurring | |
| 1939 | - $events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_recur = 'W' AND '$date' >= event_begin AND event_repeats = 0 ORDER BY event_id"); | |
| 1940 | - if (!empty($events)) | |
| 1941 | - { | |
| 1942 | - foreach($events as $event) | |
| 1943 | - { | |
| 1944 | - // This is going to get complex so lets setup what we would place in for | |
| 1945 | - // an event so we can drop it in with ease | |
| 1946 | - | |
| 1947 | - // Now we are going to check to see what day the original event | |
| 1948 | - // fell on and see if the current date is both after it and on | |
| 1949 | - // the correct day. If it is, display the event! | |
| 1950 | - $day_start_event = date('D',strtotime($event->event_begin)); | |
| 1951 | - $day_end_event = date('D',strtotime($event->event_end)); | |
| 1952 | - $current_day = date('D',strtotime($date)); | |
| 1953 | - | |
| 1954 | - $plan = array(); | |
| 1955 | - $plan['Mon'] = 1; | |
| 1956 | - $plan['Tue'] = 2; | |
| 1957 | - $plan['Wed'] = 3; | |
| 1958 | - $plan['Thu'] = 4; | |
| 1959 | - $plan['Fri'] = 5; | |
| 1960 | - $plan['Sat'] = 6; | |
| 1961 | - $plan['Sun'] = 7; | |
| 1962 | - | |
| 1963 | - if ($plan[$day_start_event] > $plan[$day_end_event]) | |
| 1964 | - { | |
| 1965 | - if (($plan[$day_start_event] <= $plan[$current_day]) || ($plan[$current_day] <= $plan[$day_end_event])) | |
| 1966 | - { | |
| 1967 | - array_push($arr_events, $event); | |
| 1968 | - } | |
| 1969 | - } | |
| 1970 | - else if (($plan[$day_start_event] < $plan[$day_end_event]) || ($plan[$day_start_event]== $plan[$day_end_event])) | |
| 1971 | - { | |
| 1972 | - if (($plan[$day_start_event] <= $plan[$current_day]) && ($plan[$current_day] <= $plan[$day_end_event])) | |
| 1973 | - { | |
| 1974 | - array_push($arr_events, $event); | |
| 1975 | - } | |
| 1976 | - } | |
| 1977 | - | |
| 1978 | - } | |
| 1979 | - } | |
| 1980 | - | |
| 1981 | - // The weekly events that have a limit on how many times they occur | |
| 1982 | - $events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_recur = 'W' AND '$date' >= event_begin AND event_repeats != 0 AND (event_repeats*7) >= (TO_DAYS('$date') - TO_DAYS(event_end)) ORDER BY event_id"); | |
| 1983 | - if (!empty($events)) | |
| 1984 | - { | |
| 1985 | - foreach($events as $event) | |
| 1986 | - { | |
| 1987 | - // This is going to get complex so lets setup what we would place in for | |
| 1988 | - // an event so we can drop it in with ease | |
| 1989 | - | |
| 1990 | - // Now we are going to check to see what day the original event | |
| 1991 | - // fell on and see if the current date is both after it and on | |
| 1992 | - // the correct day. If it is, display the event! | |
| 1993 | - $day_start_event = date('D',strtotime($event->event_begin)); | |
| 1994 | - $day_end_event = date('D',strtotime($event->event_end)); | |
| 1995 | - $current_day = date('D',strtotime($date)); | |
| 1996 | - | |
| 1997 | - $plan = array(); | |
| 1998 | - $plan['Mon'] = 1; | |
| 1999 | - $plan['Tue'] = 2; | |
| 2000 | - $plan['Wed'] = 3; | |
| 2001 | - $plan['Thu'] = 4; | |
| 2002 | - $plan['Fri'] = 5; | |
| 2003 | - $plan['Sat'] = 6; | |
| 2004 | - $plan['Sun'] = 7; | |
| 2005 | - | |
| 2006 | - if ($plan[$day_start_event] > $plan[$day_end_event]) | |
| 2007 | - { | |
| 2008 | - if (($plan[$day_start_event] <= $plan[$current_day]) || ($plan[$current_day] <= $plan[$day_end_event])) | |
| 2009 | - { | |
| 2010 | - array_push($arr_events, $event); | |
| 2011 | - } | |
| 2012 | - } | |
| 2013 | - else if (($plan[$day_start_event] < $plan[$day_end_event]) || ($plan[$day_start_event]== $plan[$day_end_event])) | |
| 2014 | - { | |
| 2015 | - if (($plan[$day_start_event] <= $plan[$current_day]) && ($plan[$current_day] <= $plan[$day_end_event])) | |
| 2016 | - { | |
| 2017 | - array_push($arr_events, $event); | |
| 2018 | - } | |
| 2019 | - } | |
| 2020 | - | |
| 2021 | - } | |
| 2022 | - } | |
| 2023 | - | |
| 2024 | 2324 | return $arr_events; |
| 2025 | 2325 | } |
| 2026 | 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 | +} | |
| 2027 | 2362 | |
| 2028 | 2363 | // Actually do the printing of the calendar |
| 2029 | 2364 | // Compared to searching for and displaying events |
| 2030 | 2365 | // this bit is really rather easy! |
| 2031 | -function calendar() | |
| 2366 | +function calendar($cat_list = '') | |
| 2032 | 2367 | { |
| 2033 | - global $wpdb; | |
| 2368 | + global $wpdb; | |
| 2034 | 2369 | |
| 2035 | - // First things first, make sure calendar is up to date | |
| 2036 | - check_calendar(); | |
| 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); | |
| 2037 | 2372 | |
| 2038 | 2373 | // Deal with the week not starting on a monday |
| 2039 | 2374 | if (get_option('start_of_week') == 0) |
| 2040 | 2375 | { |
| 2041 | - $name_days = array(1=>'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); | |
| 2376 | + $name_days = array(1=>__('Sunday','calendar'),__('Monday','calendar'),__('Tuesday','calendar'),__('Wednesday','calendar'),__('Thursday','calendar'),__('Friday','calendar'),__('Saturday','calendar')); | |
| 2042 | 2377 | } |
| 2043 | 2378 | // Choose Monday if anything other than Sunday is set |
| 2044 | 2379 | else |
| 2045 | 2380 | { |
| 2046 | - $name_days = array(1=>'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'); | |
| 2381 | + $name_days = array(1=>__('Monday','calendar'),__('Tuesday','calendar'),__('Wednesday','calendar'),__('Thursday','calendar'),__('Friday','calendar'),__('Saturday','calendar'),__('Sunday','calendar')); | |
| 2047 | 2382 | } |
| 2048 | 2383 | |
| 2049 | 2384 | // Carry on with the script |
| 2050 | - $name_months = array(1=>'January','February','March','April','May','June','July','August','September','October','November','December'); | |
| 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')); | |
| 2051 | 2386 | |
| 2052 | 2387 | // If we don't pass arguments we want a calendar that is relevant to today |
| 2053 | - if (empty($_GET['month']) || empty($_GET['yr'])) | |
| 2388 | + if (empty($get_month) || empty($get_year)) | |
| 2054 | 2389 | { |
| 2055 | - $c_year = date("Y"); | |
| 2056 | - $c_month = date("m"); | |
| 2057 | - $c_day = date("d"); | |
| 2390 | + $c_year = gmdate("Y",calendar_ctwo()); | |
| 2391 | + $c_month = gmdate("m",calendar_ctwo()); | |
| 2392 | + $c_day = gmdate("d",calendar_ctwo()); | |
| 2058 | 2393 | } |
| 2059 | 2394 | |
| 2060 | 2395 | // Years get funny if we exceed 3000, so we use this check |
| 2061 | - if ($_GET['yr'] <= 3000 && $_GET['yr'] >= 0) | |
| 2396 | + if (isset($get_year)) | |
| 2397 | + { | |
| 2398 | + if ($get_year <= 3000 && $get_year >= 0 && (int)$get_year != 0) | |
| 2062 | 2399 | { |
| 2063 | 2400 | // This is just plain nasty and all because of permalinks |
| 2064 | 2401 | // which are no longer used, this will be cleaned up soon |
| 2065 | - if ($_GET['month'] == 'jan' || $_GET['month'] == 'feb' || $_GET['month'] == 'mar' || $_GET['month'] == 'apr' || $_GET['month'] == 'may' || $_GET['month'] == 'jun' || $_GET['month'] == 'jul' || $_GET['month'] == 'aug' || $_GET['month'] == 'sept' || $_GET['month'] == 'oct' || $_GET['month'] == 'nov' || $_GET['month'] == 'dec') | |
| 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') | |
| 2066 | 2403 | { |
| 2067 | 2404 | |
| 2068 | 2405 | // Again nasty code to map permalinks into something |
| 2069 | 2406 | // databases can understand. This will be cleaned up |
| 2070 | - $c_year = mysql_escape_string($_GET['yr']); | |
| 2071 | - if ($_GET['month'] == 'jan') { $t_month = 1; } | |
| 2072 | - else if ($_GET['month'] == 'feb') { $t_month = 2; } | |
| 2073 | - else if ($_GET['month'] == 'mar') { $t_month = 3; } | |
| 2074 | - else if ($_GET['month'] == 'apr') { $t_month = 4; } | |
| 2075 | - else if ($_GET['month'] == 'may') { $t_month = 5; } | |
| 2076 | - else if ($_GET['month'] == 'jun') { $t_month = 6; } | |
| 2077 | - else if ($_GET['month'] == 'jul') { $t_month = 7; } | |
| 2078 | - else if ($_GET['month'] == 'aug') { $t_month = 8; } | |
| 2079 | - else if ($_GET['month'] == 'sept') { $t_month = 9; } | |
| 2080 | - else if ($_GET['month'] == 'oct') { $t_month = 10; } | |
| 2081 | - else if ($_GET['month'] == 'nov') { $t_month = 11; } | |
| 2082 | - else if ($_GET['month'] == 'dec') { $t_month = 12; } | |
| 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; } | |
| 2083 | 2420 | $c_month = $t_month; |
| 2084 | - $c_day = date("d"); | |
| 2421 | + $c_day = gmdate("d",calendar_ctwo()); | |
| 2085 | 2422 | } |
| 2086 | 2423 | // No valid month causes the calendar to default to today |
| 2087 | 2424 | else |
| 2088 | 2425 | { |
| 2089 | - $c_year = date("Y"); | |
| 2090 | - $c_month = date("m"); | |
| 2091 | - $c_day = date("d"); | |
| 2426 | + $c_year = gmdate("Y",calendar_ctwo()); | |
| 2427 | + $c_month = gmdate("m",calendar_ctwo()); | |
| 2428 | + $c_day = gmdate("d",calendar_ctwo()); | |
| 2092 | 2429 | } |
| 2093 | 2430 | } |
| 2431 | + } | |
| 2094 | 2432 | // No valid year causes the calendar to default to today |
| 2095 | 2433 | else |
| 2096 | 2434 | { |
| 2097 | - $c_year = date("Y"); | |
| 2098 | - $c_month = date("m"); | |
| 2099 | - $c_day = date("d"); | |
| 2435 | + $c_year = gmdate("Y",calendar_ctwo()); | |
| 2436 | + $c_month = gmdate("m",calendar_ctwo()); | |
| 2437 | + $c_day = gmdate("d",calendar_ctwo()); | |
| 2100 | 2438 | } |
| 2101 | 2439 | |
| 2102 | 2440 | // Fix the days of the week if week start is not on a monday |
| 2103 | 2441 | if (get_option('start_of_week') == 0) |
| 2104 | 2442 | { |
| 2105 | - $first_weekday = date("w",mktime(0,0,0,$c_month,1,$c_year)); | |
| 2443 | + $first_weekday = gmdate("w",mktime(0,0,0,$c_month,1,$c_year)); | |
| 2106 | 2444 | $first_weekday = ($first_weekday==0?1:$first_weekday+1); |
| 2107 | 2445 | } |
| 2108 | 2446 | // Otherwise assume the week starts on a Monday. Anything other |
| 2109 | 2447 | // than Sunday or Monday is just plain odd |
| @@ -2108,99 +2446,74 @@ | ||
| 2108 | 2446 | // Otherwise assume the week starts on a Monday. Anything other |
| 2109 | 2447 | // than Sunday or Monday is just plain odd |
| 2110 | 2448 | else |
| 2111 | 2449 | { |
| 2112 | - $first_weekday = date("w",mktime(0,0,0,$c_month,1,$c_year)); | |
| 2450 | + $first_weekday = gmdate("w",mktime(0,0,0,$c_month,1,$c_year)); | |
| 2113 | 2451 | $first_weekday = ($first_weekday==0?7:$first_weekday); |
| 2114 | 2452 | } |
| 2115 | 2453 | |
| 2116 | - $days_in_month = date("t", mktime (0,0,0,$c_month,1,$c_year)); | |
| 2454 | + $days_in_month = gmdate("t", mktime (0,0,0,$c_month,1,$c_year)); | |
| 2117 | 2455 | |
| 2118 | 2456 | // Start the table and add the header and naviagtion |
| 2457 | + $calendar_body = ''; | |
| 2119 | 2458 | $calendar_body .= ' |
| 2120 | 2459 | <table cellspacing="1" cellpadding="0" class="calendar-table"> |
| 2121 | 2460 | '; |
| 2122 | 2461 | |
| 2123 | 2462 | // We want to know if we should display the date switcher |
| 2124 | - $date_switcher = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_jump'",0,0); | |
| 2125 | - | |
| 2463 | + $date_switcher = calendar_get_config_value('display_jump'); | |
| 2126 | 2464 | if ($date_switcher == 'true') |
| 2127 | 2465 | { |
| 2466 | + $request_uri = isset($_SERVER['REQUEST_URI']) ? sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'])) : ''; | |
| 2128 | 2467 | $calendar_body .= '<tr> |
| 2129 | 2468 | <td colspan="7" class="calendar-date-switcher"> |
| 2130 | - <form method="GET" action="'.$_SERVER['REQUEST_URI'].'"> | |
| 2469 | + <form method="get" action="'.$request_uri.'"> | |
| 2131 | 2470 | '; |
| 2132 | 2471 | $qsa = array(); |
| 2133 | - parse_str($_SERVER['QUERY_STRING'],$qsa); | |
| 2472 | + if (isset($_SERVER['QUERY_STRING'])) { | |
| 2473 | + parse_str(sanitize_text_field(wp_unslash($_SERVER['QUERY_STRING'])),$qsa); | |
| 2474 | + } | |
| 2134 | 2475 | foreach ($qsa as $name => $argument) |
| 2135 | 2476 | { |
| 2136 | - if ($name != 'month' && $name != 'yr') | |
| 2477 | + if ($name != 'calendar_month' && $name != 'calendar_yr' && preg_match("/^[A-Za-z0-9\-\_]+$/",$name) && preg_match("/^[A-Za-z0-9\-\_]+$/",$argument)) | |
| 2137 | 2478 | { |
| 2138 | - $calendar_body .= '<input type="hidden" name="'.$name.'" value="'.$argument.'" /> | |
| 2479 | + $calendar_body .= '<input type="hidden" name="'.wp_strip_all_tags($name).'" value="'.wp_strip_all_tags($argument).'" /> | |
| 2139 | 2480 | '; |
| 2140 | 2481 | } |
| 2141 | 2482 | } |
| 2142 | - function month_comparison($month) | |
| 2143 | - { | |
| 2144 | - $current_month = strtolower(date("M", time())); | |
| 2145 | - if (isset($_GET['yr']) && isset($_GET['month'])) | |
| 2146 | - { | |
| 2147 | - if ($month == $_GET['month']) | |
| 2148 | - { | |
| 2149 | - return ' selected="selected"'; | |
| 2150 | - } | |
| 2151 | - } | |
| 2152 | - elseif ($month == $current_month) | |
| 2153 | - { | |
| 2154 | - return ' selected="selected"'; | |
| 2155 | - } | |
| 2156 | - } | |
| 2483 | + | |
| 2157 | 2484 | // We build the months in the switcher |
| 2158 | 2485 | $calendar_body .= ' |
| 2159 | - Month: <select name="month" style="width:100px;"> | |
| 2160 | - <option value="jan"'.month_comparison('jan').'>January</option> | |
| 2161 | - <option value="feb"'.month_comparison('feb').'>February</option> | |
| 2162 | - <option value="mar"'.month_comparison('mar').'>March</option> | |
| 2163 | - <option value="apr"'.month_comparison('apr').'>April</option> | |
| 2164 | - <option value="may"'.month_comparison('may').'>May</option> | |
| 2165 | - <option value="jun"'.month_comparison('jun').'>June</option> | |
| 2166 | - <option value="jul"'.month_comparison('jul').'>July</option> | |
| 2167 | - <option value="aug"'.month_comparison('aug').'>August</option> | |
| 2168 | - <option value="sept"'.month_comparison('sept').'>September</option> | |
| 2169 | - <option value="oct"'.month_comparison('oct').'>October</option> | |
| 2170 | - <option value="nov"'.month_comparison('nov').'>November</option> | |
| 2171 | - <option value="dec"'.month_comparison('dec').'>December</option> | |
| 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> | |
| 2172 | 2499 | </select> |
| 2173 | - Year: <select name="yr" style="width:60px;"> | |
| 2500 | + '.esc_html__('Year','calendar').': <select name="calendar_yr" style="width:60px;"> | |
| 2174 | 2501 | '; |
| 2175 | 2502 | |
| 2176 | - // The year builder is string mania. If you can make sense of this, | |
| 2177 | - // you know your PHP! | |
| 2178 | - function year_comparison($year) | |
| 2179 | - { | |
| 2180 | - $current_year = strtolower(date("Y", time())); | |
| 2181 | - if (isset($_GET['yr']) && isset($_GET['month'])) | |
| 2182 | - { | |
| 2183 | - if ($year == $_GET['yr']) | |
| 2184 | - { | |
| 2185 | - return ' selected="selected"'; | |
| 2186 | - } | |
| 2187 | - } | |
| 2188 | - else if ($year == $current_year) | |
| 2189 | - { | |
| 2190 | - return ' selected="selected"'; | |
| 2191 | - } | |
| 2192 | - } | |
| 2503 | + // The year builder is string mania. If you can make sense of this, you know your PHP! | |
| 2193 | 2504 | |
| 2194 | 2505 | $past = 30; |
| 2195 | 2506 | $future = 30; |
| 2196 | 2507 | $fut = 1; |
| 2508 | + $f = ''; | |
| 2509 | + $p = ''; | |
| 2197 | 2510 | while ($past > 0) |
| 2198 | 2511 | { |
| 2199 | 2512 | $p .= ' <option value="'; |
| 2200 | - $p .= date("Y",time())-$past; | |
| 2201 | - $p .= '"'.year_comparison(date("Y",time())-$past).'>'; | |
| 2202 | - $p .= date("Y",time())-$past.'</option> | |
| 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> | |
| 2203 | 2516 | '; |
| 2204 | 2517 | $past = $past - 1; |
| 2205 | 2518 | } |
| 2206 | 2519 | while ($fut < $future) |
| @@ -2205,20 +2518,20 @@ | ||
| 2205 | 2518 | } |
| 2206 | 2519 | while ($fut < $future) |
| 2207 | 2520 | { |
| 2208 | 2521 | $f .= ' <option value="'; |
| 2209 | - $f .= date("Y",time())+$fut; | |
| 2210 | - $f .= '"'.year_comparison(date("Y",time())+$fut).'>'; | |
| 2211 | - $f .= date("Y",time())+$fut.'</option> | |
| 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> | |
| 2212 | 2525 | '; |
| 2213 | 2526 | $fut = $fut + 1; |
| 2214 | 2527 | } |
| 2215 | 2528 | $calendar_body .= $p; |
| 2216 | - $calendar_body .= ' <option value="'.date("Y",time()).'"'.year_comparison(date("Y",time())).'>'.date("Y",time()).'</option> | |
| 2529 | + $calendar_body .= ' <option value="'.gmdate("Y",calendar_ctwo()).'"'.calendar_year_comparison(gmdate("Y",calendar_ctwo())).'>'.gmdate("Y",calendar_ctwo()).'</option> | |
| 2217 | 2530 | '; |
| 2218 | 2531 | $calendar_body .= $f; |
| 2219 | 2532 | $calendar_body .= '</select> |
| 2220 | - <input type="submit" value="Go" /> | |
| 2533 | + <input type="submit" value="'.esc_html__('Go','calendar').'" /> | |
| 2221 | 2534 | </form> |
| 2222 | 2535 | </td> |
| 2223 | 2536 | </tr> |
| 2224 | 2537 | '; |
| @@ -2228,11 +2541,11 @@ | ||
| 2228 | 2541 | $calendar_body .= '<tr> |
| 2229 | 2542 | <td colspan="7" class="calendar-heading"> |
| 2230 | 2543 | <table border="0" cellpadding="0" cellspacing="0" width="100%"> |
| 2231 | 2544 | <tr> |
| 2232 | - <td class="calendar-prev">' . prev_link($c_year,$c_month) . '</td> | |
| 2545 | + <td class="calendar-prev">' . calendar_prev_link($c_year,$c_month) . '</td> | |
| 2233 | 2546 | <td class="calendar-month">'.$name_months[(int)$c_month].' '.$c_year.'</td> |
| 2234 | - <td class="calendar-next">' . next_link($c_year,$c_month) . '</td> | |
| 2547 | + <td class="calendar-next">' . calendar_next_link($c_year,$c_month) . '</td> | |
| 2235 | 2548 | </tr> |
| 2236 | 2549 | </table> |
| 2237 | 2550 | </td> |
| 2238 | 2551 | </tr> |
| @@ -2256,9 +2569,9 @@ | ||
| 2256 | 2569 | } |
| 2257 | 2570 | } |
| 2258 | 2571 | $calendar_body .= '</tr> |
| 2259 | 2572 | '; |
| 2260 | - | |
| 2573 | + $go = FALSE; | |
| 2261 | 2574 | for ($i=1; $i<=$days_in_month;) |
| 2262 | 2575 | { |
| 2263 | 2576 | $calendar_body .= '<tr> |
| 2264 | 2577 | '; |
| @@ -2269,11 +2582,10 @@ | ||
| 2269 | 2582 | $go = TRUE; |
| 2270 | 2583 | } |
| 2271 | 2584 | elseif ($i > $days_in_month ) |
| 2272 | 2585 | { |
| 2273 | - $go = FALSE; | |
| 2586 | + $go = FALSE; | |
| 2274 | 2587 | } |
| 2275 | - | |
| 2276 | 2588 | if ($go) |
| 2277 | 2589 | { |
| 2278 | 2590 | // Colours again, this time for the day numbers |
| 2279 | 2591 | if (get_option('start_of_week') == 0) |
| @@ -2278,26 +2590,26 @@ | ||
| 2278 | 2590 | // Colours again, this time for the day numbers |
| 2279 | 2591 | if (get_option('start_of_week') == 0) |
| 2280 | 2592 | { |
| 2281 | 2593 | // This bit of code is for styles believe it or not. |
| 2282 | - $grabbed_events = grab_events($c_year,$c_month,$i); | |
| 2594 | + $grabbed_events = calendar_grab_events($c_year,$c_month,$i,'calendar',$cat_list); | |
| 2283 | 2595 | $no_events_class = ''; |
| 2284 | 2596 | if (!count($grabbed_events)) |
| 2285 | 2597 | { |
| 2286 | 2598 | $no_events_class = ' no-events'; |
| 2287 | 2599 | } |
| 2288 | - $calendar_body .= ' <td class="'.(date("Ymd", mktime (0,0,0,$c_month,$i,$c_year))==date("Ymd")?'current-day':'day-with-date').$no_events_class.'"><span '.($ii<7&&$ii>1?'':'class="weekend"').'>'.$i++.'</span><span class="event">' . draw_events($grabbed_events) . '</span></td> | |
| 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> | |
| 2289 | 2601 | '; |
| 2290 | 2602 | } |
| 2291 | 2603 | else |
| 2292 | 2604 | { |
| 2293 | - $grabbed_events = grab_events($c_year,$c_month,$i); | |
| 2605 | + $grabbed_events = calendar_grab_events($c_year,$c_month,$i,'calendar',$cat_list); | |
| 2294 | 2606 | $no_events_class = ''; |
| 2295 | 2607 | if (!count($grabbed_events)) |
| 2296 | 2608 | { |
| 2297 | 2609 | $no_events_class = ' no-events'; |
| 2298 | 2610 | } |
| 2299 | - $calendar_body .= ' <td class="'.(date("Ymd", mktime (0,0,0,$c_month,$i,$c_year))==date("Ymd")?'current-day':'day-with-date').$no_events_class.'"><span '.($ii<6?'':'class="weekend"').'>'.$i++.'</span><span class="event">' . draw_events($grabbed_events) . '</span></td> | |
| 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> | |
| 2300 | 2612 | '; |
| 2301 | 2613 | } |
| 2302 | 2614 | } |
| 2303 | 2615 | else |
| @@ -2308,35 +2620,446 @@ | ||
| 2308 | 2620 | } |
| 2309 | 2621 | $calendar_body .= '</tr> |
| 2310 | 2622 | '; |
| 2311 | 2623 | } |
| 2312 | - $show_cat = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='enable_categories'",0,0); | |
| 2313 | - | |
| 2624 | + $calendar_body .= '</table> | |
| 2625 | +'; | |
| 2626 | + | |
| 2627 | + $show_cat = calendar_get_config_value('enable_categories'); | |
| 2314 | 2628 | if ($show_cat == 'true') |
| 2315 | 2629 | { |
| 2316 | - $sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " ORDER BY category_name ASC"; | |
| 2317 | - $cat_details = $wpdb->get_results($sql); | |
| 2318 | - $calendar_body .= '<tr><td colspan="7"> | |
| 2319 | -<table class="cat-key"> | |
| 2320 | -<tr><td colspan="2"><strong>Category Key</strong></td></tr> | |
| 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> | |
| 2321 | 2633 | '; |
| 2322 | 2634 | foreach($cat_details as $cat_detail) |
| 2323 | 2635 | { |
| 2324 | - $calendar_body .= '<tr><td style="background-color:'.$cat_detail->category_colour.'; width:20px; height:20px;"></td><td>'.$cat_detail->category_name.'</td></tr>'; | |
| 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>'; | |
| 2325 | 2638 | } |
| 2326 | 2639 | $calendar_body .= '</table> |
| 2327 | -</td></tr> | |
| 2328 | 2640 | '; |
| 2329 | 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 | + } | |
| 2330 | 2885 | $calendar_body .= '</table> |
| 2331 | 2886 | '; |
| 2332 | 2887 | |
| 2333 | - // A little link to yours truely. See the README if you wish to remove this | |
| 2334 | - $calendar_body .= '<div class="kjo-link"><p>Web development and hosting from <a href="http://www.kjowebservices.co.uk">KJO Web Services</a></p></div> | |
| 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> | |
| 2335 | 2896 | '; |
| 2897 | + } else { | |
| 2898 | + $linkback_url = ''; | |
| 2899 | + } | |
| 2900 | + $calendar_body .= $linkback_url; | |
| 2336 | 2901 | |
| 2902 | + // Closing div | |
| 2903 | + $calendar_body .= '</div> | |
| 2904 | +'; | |
| 2337 | 2905 | // Phew! After that bit of string building, spit it all out. |
| 2338 | 2906 | // The actual printing is done by the calling function. |
| 2339 | 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 | + } | |
| 2340 | 3063 | } |
| 2341 | 3064 | |
| 2342 | 3065 | ?> |