Calendar - Version 1.3.9

Version Description

  • Improved the feed of events to use iCalendar format
Download this release

Release Info

Developer KieranOShea
Plugin Icon 128x128 Calendar
Version 1.3.9
Comparing to
See all releases

Code changes from version 1.3.8 to 1.3.9

Files changed (3) hide show
  1. calendar-feed.php +42 -98
  2. calendar.php +3 -3
  3. readme.txt +5 -2
calendar-feed.php CHANGED
@@ -21,108 +21,52 @@ $sql = "SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_i
21
  $feed_yes = $wpdb->get_var($sql);
22
  if ($feed_yes == 'true') {
23
 
24
- // We need to set a few parameters
25
- // Caution - the further into the future
26
- // you set this, the longer the feed will take
27
- // to show up and the more load will be placed
28
- // on your server. The default value of 30 is
29
- // sensible in this regard
30
- $number_future_days = 30;
31
-
32
- // Create the RSS header
33
- $rss_result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
34
- <rss version=\"2.0\"
35
- xmlns:content=\"http://purl.org/rss/1.0/modules/content/\"
36
- xmlns:wfw=\"http://wellformedweb.org/CommentAPI/\"
37
- xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
38
- >
39
-
40
- <channel>
41
- <title>".get_option('blogname')."</title>
42
- <link>".get_option('home')."</link>
43
- <description>".get_option('blogdescription')."</description>
44
- <language>en-uk</language>
45
- <copyright>(c) Copyright ".date("Y", time())." by ".get_option('blogname')."</copyright>
46
- <managingEditor>".get_option('admin_email')."</managingEditor>
47
- <webMaster>".get_option('admin_email')."</webMaster>
48
- <pubDate>".date('D, d M Y h:i:s O',time())."</pubDate>
49
- <lastBuildDate>".date('D, d M Y h:i:s O',time())."</lastBuildDate>
50
- <docs>http://backend.userland.com/rss</docs>
51
- <generator>Calendar for WordPress</generator>
52
- <ttl>1</ttl>
53
  ";
54
 
55
- // We grab the events into the future by the number of preset days
56
- global $wpdb;
57
-
58
- // Get number of days we should go into the future
59
- $future_days = $number_future_days;
60
- $day_count = 0;
61
-
62
- while ($day_count < $future_days+1)
63
- {
64
- list($y,$m,$d) = explode("-",date("Y-m-d",mktime($day_count*24,0,0,date("m"),date("d"),date("Y"))));
65
- $events = grab_events($y,$m,$d,null);
66
- usort($events, "time_cmp");
67
-
68
- foreach($events as $event)
69
- {
70
- // For each event we need some additional information
71
- $sql = "SELECT category_name FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".$event->event_category;
72
- $this_cat = $wpdb->get_var($sql);
73
- $sql = "SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_author'";
74
- $author_yes = $wpdb->get_var($sql);
75
- $sql = "SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='enable_categories'";
76
- $cat_yes = $wpdb->get_var($sql);
77
-
78
- $e = get_userdata($event->event_author);
79
- $this_author = $e->user_email;
80
-
81
- if ($author_yes == 'true') { $author = '<author>'.$this_author.'</author>'; }
82
- else { $author = ''; }
83
-
84
- if ($cat_yes == 'true') { $category = '<category>'.$this_cat.'</category>'; }
85
- else { $category = ''; }
86
-
87
- if ($event->event_link != '') { $this_link = $event->event_link; }
88
- else { $this_link = get_option('home'); }
89
-
90
  if ($event->event_time == '00:00:00') {
91
- $rss_result .= " <item>
92
- <title>".$event->event_title."</title>
93
- <link>".$this_link."</link>
94
- ".$category."
95
- <description><![CDATA[".utf8_encode($event->event_desc)."]]></description>
96
- ".$author."
97
- <pubDate>".date('D, d M Y h:i:s 0',mktime($day_count*24,0,0,date("m"),date("d"),date("Y")))."</pubDate>
98
- </item>";
99
- }
100
- else {
101
- $rss_result .= " <item>
102
- <title>".$event->event_title."</title>
103
- <link>".$this_link."</link>
104
- ".$category."
105
- <description><![CDATA[".utf8_encode($event->event_desc)."]]></description>
106
- ".$author."
107
- <pubDate>".date('D, d M Y ',mktime($day_count*24,0,0,date("m"),date("d"),date("Y"))).date('h:i:s O',strtotime($event->event_time))."</pubDate>
108
- </item>";
109
  }
110
-
 
 
 
 
 
 
 
 
 
111
  }
112
-
113
- $day_count = $day_count+1;
 
 
 
 
 
 
114
  }
115
-
116
- // Finish it all off
117
- $rss_result .= "
118
- </channel>
119
- </rss>";
120
-
121
- // Spit out the RSS feed to the browser
122
- header("Content-type: text/xml", true);
123
- echo $rss_result;
124
-
125
- // Close the feed check
126
- }
127
-
128
  ?>
21
  $feed_yes = $wpdb->get_var($sql);
22
  if ($feed_yes == 'true') {
23
 
24
+ // Head up the file
25
+ $ical_result = "BEGIN:VCALENDAR
26
+ VERSION:2.0
27
+ METHOD:PUBLISH
28
+ PRODID:-//wordpress.org/plugins calendar//EN
29
+ CALSCALE:GREGORIAN
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  ";
31
 
32
+ // Hard code future days to protect server load
33
+ $future_days = 30;
34
+ $day_count = 0;
35
+ while ($day_count < $future_days+1)
36
+ {
37
+ // Craft our days into the future with the current one as a reference, get the eligible event on that day
38
+ list($y,$m,$d) = explode("-",date("Y-m-d",mktime($day_count*24,0,0,date("m"),date("d"),date("Y"))));
39
+ $events = grab_events($y,$m,$d,null);
40
+ usort($events, "time_cmp");
41
+
42
+ // Iterate through the events list and define a iCalendar VEVENT for each
43
+ foreach($events as $event) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  if ($event->event_time == '00:00:00') {
45
+ $start = date('Ymd',mktime($day_count*24,0,0,date("m"),date("d"),date("Y")));
46
+ $end = date('Ymd',mktime(($day_count+1)*24,0,0,date("m"),date("d"),date("Y")));;
47
+ } else {
48
+ // A little fudge on the end time here; we assume all events are 1 hour as end time isn't a field in calendar
49
+ $start = date('Ymd',mktime($day_count*24,0,0,date("m"),date("d"),date("Y")))."T".date('His',strtotime($event->event_time))."Z";
50
+ $end = date('Ymd',mktime($day_count*24,0,0,date("m"),date("d"),date("Y")))."T".date('His',strtotime($event->event_time)+3600)."Z";
 
 
 
 
 
 
 
 
 
 
 
 
51
  }
52
+ $ical_result .= "BEGIN:VEVENT
53
+ DTSTART:".$start."
54
+ DTEND:".$end."
55
+ SUMMARY:".$event->event_title."
56
+ DESCRIPTION:".$event->event_desc."
57
+ UID:".$event->event_id."@".$_SERVER['SERVER_NAME']."
58
+ SEQUENCE:0
59
+ DTSTAMP:".date("YmdTHisZ")."
60
+ END:VEVENT
61
+ "; // Note the UID definition; event id is unique per install, each install has it's own domain (in theory)
62
  }
63
+ $day_count++;
64
+ }
65
+
66
+ // Tail of the file, the mime type and return
67
+ $ical_result .= "END:VCALENDAR";
68
+ header("Content-type: text/calendar", true);
69
+ header('Content-Disposition: attachment; filename="calendar.ics"');
70
+ echo $ical_result;
71
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  ?>
calendar.php CHANGED
@@ -7,7 +7,7 @@ Author: Kieran O'Shea
7
  Author URI: http://www.kieranoshea.com
8
  Text Domain: calendar
9
  Domain Path: /languages
10
- Version: 1.3.8
11
  */
12
 
13
  /* Copyright 2008 Kieran O'Shea (email : kieran@kieranoshea.com)
@@ -439,7 +439,7 @@ function check_calendar()
439
 
440
  // Version info
441
  $calendar_version_option = 'calendar_version';
442
- $calendar_version = '1.3.8';
443
 
444
  // All this style info will go into the database on a new install
445
  // This looks nice in the TwentyTen theme
@@ -797,7 +797,7 @@ function check_calendar()
797
  $wpdb->get_results("ALTER TABLE " . WP_CALENDAR_CATEGORIES_TABLE . " CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci");
798
 
799
  // We have feed for the first time, add the config option
800
- if ($calendar_version == '1.3.8') {
801
  $sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='enable_feed', config_value='false'";
802
  $wpdb->get_results($sql);
803
  }
7
  Author URI: http://www.kieranoshea.com
8
  Text Domain: calendar
9
  Domain Path: /languages
10
+ Version: 1.3.9
11
  */
12
 
13
  /* Copyright 2008 Kieran O'Shea (email : kieran@kieranoshea.com)
439
 
440
  // Version info
441
  $calendar_version_option = 'calendar_version';
442
+ $calendar_version = '1.3.9';
443
 
444
  // All this style info will go into the database on a new install
445
  // This looks nice in the TwentyTen theme
797
  $wpdb->get_results("ALTER TABLE " . WP_CALENDAR_CATEGORIES_TABLE . " CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci");
798
 
799
  // We have feed for the first time, add the config option
800
+ if ($wpdb->get_var("SELECT count(*) FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='enable_feed'") == 0) {
801
  $sql = "INSERT INTO " . WP_CALENDAR_CONFIG_TABLE . " SET config_item='enable_feed', config_value='false'";
802
  $wpdb->get_results($sql);
803
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.kieranoshea.com
4
  Tags: calendar, dates, times, events
5
  Requires at least: 4.3.1
6
  Tested up to: 4.6
7
- Stable tag: 1.3.8
8
 
9
  A simple but effective Calendar plugin for WordPress that allows you to
10
  manage your events and appointments and display them to the world.
@@ -227,9 +227,12 @@ You've not called wp_head() in your theme's header and/or wp_footer() in your th
227
 
228
  == Changelog ==
229
 
 
 
 
230
  = 1.3.8 =
231
  * Fixed a reported XSS issue with the date switcher
232
- * Added a iCalendar feed of events
233
 
234
  = 1.3.7 =
235
  * Added a further fix for dollar signs in event titles and descriptions
4
  Tags: calendar, dates, times, events
5
  Requires at least: 4.3.1
6
  Tested up to: 4.6
7
+ Stable tag: 1.3.9
8
 
9
  A simple but effective Calendar plugin for WordPress that allows you to
10
  manage your events and appointments and display them to the world.
227
 
228
  == Changelog ==
229
 
230
+ = 1.3.9 =
231
+ * Improved the feed of events to use iCalendar format
232
+
233
  = 1.3.8 =
234
  * Fixed a reported XSS issue with the date switcher
235
+ * Added a RSS feed of events
236
 
237
  = 1.3.7 =
238
  * Added a further fix for dollar signs in event titles and descriptions