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