Simple Calendar – Google Calendar Plugin - Version 0.1

Version Description

Initial release.

=

Download this release

Release Info

Developer rosshanney
Plugin Icon 128x128 Simple Calendar – Google Calendar Plugin
Version 0.1
Comparing to
See all releases

Version 0.1

admin/add.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ //Redirect to the main plugin options page if form has been submitted
3
+ if($_GET['action'] == 'add' && $_GET['updated']){
4
+ wp_redirect(admin_url() . 'options-general.php?page=' . GCE_PLUGIN_NAME . '.php&updated=added');
5
+ }
6
+
7
+ //Main text
8
+ function gce_add_main_text(){
9
+ ?>
10
+ <p><?php _e('Enter the feed details below, then click the Add Feed button.', GCE_TEXT_DOMAIN); ?></p>
11
+ <?php
12
+ }
13
+
14
+ //ID
15
+ function gce_add_id_field(){
16
+ $options = get_option(GCE_OPTIONS_NAME);
17
+ $id = 1;
18
+ if(!empty($options)){ //If there are no saved feeds
19
+ //Go to last saved feed
20
+ end($options);
21
+ //Set id to last feed id + 1
22
+ $id = key($options) + 1;
23
+ }
24
+
25
+ ?>
26
+ <input type="text" disabled="disabled" value="<?php echo $id; ?>" size="3" />
27
+ <input type="hidden" name="gce_options[id]" value="<?php echo $id; ?>" />
28
+ <?php
29
+ }
30
+
31
+ //Title
32
+ function gce_add_title_field(){
33
+ ?>
34
+ <span class="description"><?php _e('Anything you like. \'Upcoming Club Events\', for example.', GCE_TEXT_DOMAIN); ?></span>
35
+ <br />
36
+ <input type="text" name="gce_options[title]" size="50" />
37
+ <?php
38
+ }
39
+
40
+ //URL
41
+ function gce_add_url_field(){
42
+ ?>
43
+ <span class="description"><?php _e('This will probably be something like: \'http://www.google.com/calendar/feeds/your-email@gmail.com/public/full\'.', GCE_TEXT_DOMAIN); ?></span>
44
+ <br />
45
+ <input type="text" name="gce_options[url]" size="100" class="required" />
46
+ <?php
47
+ }
48
+
49
+ //Show past events
50
+ function gce_add_show_past_events_field(){
51
+ ?>
52
+ <span class="description"><?php _e('Select No to retrieve events from now onwards. Select Yes to retrieve events from the first of this month onwards.', GCE_TEXT_DOMAIN); ?></span>
53
+ <fieldset>
54
+ <label><input type="radio" name="gce_options[show_past_events]" value="false" checked="checked" /> <?php _e('No', GCE_TEXT_DOMAIN); ?></label>
55
+ <br />
56
+ <label><input type="radio" name="gce_options[show_past_events]" value="true" /> <?php _e('Yes', GCE_TEXT_DOMAIN); ?></label>
57
+ </fieldset>
58
+ <?php
59
+ }
60
+
61
+ //Max events
62
+ function gce_add_max_events_field(){
63
+ ?>
64
+ <span class="description"><?php _e('The default number of events to retrieve from a Google Calendar feed is 25, but you may want less for a list, or more for a calendar grid.', GCE_TEXT_DOMAIN); ?></span>
65
+ <br />
66
+ <input type="text" name="gce_options[max_events]" value="25" size="3" />
67
+ <?php
68
+ }
69
+
70
+ //Date format
71
+ function gce_add_date_format_field(){
72
+ ?>
73
+ <span class="description"><?php _e('In <a href="http://php.net/manual/en/function.date.php">PHP date format</a>. Leave this blank if you\'d rather stick with the default format for your blog.', GCE_TEXT_DOMAIN); ?></span>
74
+ <br />
75
+ <input type="text" name="gce_options[date_format]" />
76
+ <?php
77
+ }
78
+
79
+ //Time format
80
+ function gce_add_time_format_field(){
81
+ ?>
82
+ <span class="description"><?php _e('In <a href="http://php.net/manual/en/function.date.php">PHP date format</a>. Again, leave this blank to stick with the default.', GCE_TEXT_DOMAIN); ?></span>
83
+ <br />
84
+ <input type="text" name="gce_options[time_format]" />
85
+ <?php
86
+ }
87
+
88
+ //Cache duration
89
+ function gce_add_cache_duration_field(){
90
+ ?>
91
+ <span class="description"><?php _e('The length of time, in seconds, to cache the feed (43200 = 12 hours). If this feed changes regularly, you may want to reduce the cache duration.', GCE_TEXT_DOMAIN); ?></span>
92
+ <br />
93
+ <input type="text" name="gce_options[cache_duration]" value="43200" />
94
+ <?php
95
+ }
96
+ ?>
admin/delete.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ //Redirect to the main plugin options page if form has been submitted
3
+ if($_GET['action'] == 'delete' && $_GET['updated']){
4
+ wp_redirect(admin_url() . 'options-general.php?page=' . GCE_PLUGIN_NAME . '.php&updated=deleted');
5
+ }
6
+
7
+ //Main text
8
+ function gce_delete_main_text(){
9
+ ?>
10
+ <p><?php _e('Are you want you want to delete this feed? (Remember to remove / adjust any widgets or shortcodes associated with this feed).', GCE_TEXT_DOMAIN); ?></p>
11
+ <?php
12
+ }
13
+
14
+ //ID
15
+ function gce_delete_id_field(){
16
+ $options = get_option(GCE_OPTIONS_NAME);
17
+ $options = $options[$_GET['id']];
18
+ ?>
19
+ <input type="text" disabled="disabled" value="<?php echo $options['id']; ?>" size="3" />
20
+ <input type="hidden" name="gce_options[id]" value="<?php echo $options['id']; ?>" />
21
+ <?php
22
+ }
23
+
24
+ //Title
25
+ function gce_delete_title_field(){
26
+ $options = get_option(GCE_OPTIONS_NAME);
27
+ $options = $options[$_GET['id']];
28
+ ?>
29
+ <input type="text" name="gce_options[title]" disabled="disabled" value="<?php echo $options['title']; ?>" size="50" />
30
+ <?php
31
+ }
32
+ ?>
admin/edit.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ //Redirect to the main plugin options page if form has been submitted
3
+ if($_GET['action'] == 'edit' && $_GET['updated']){
4
+ wp_redirect(admin_url() . 'options-general.php?page=' . GCE_PLUGIN_NAME . '.php&updated=edited');
5
+ }
6
+
7
+ //Main text
8
+ function gce_edit_main_text(){
9
+ ?>
10
+ <p><?php _e('Make any changes you require to the feed details below, then click the Save Changes button.', GCE_TEXT_DOMAIN); ?></p>
11
+ <?php
12
+ }
13
+
14
+ //ID
15
+ function gce_edit_id_field(){
16
+ $options = get_option(GCE_OPTIONS_NAME);
17
+ $options = $options[$_GET['id']];
18
+ ?>
19
+ <input type="text" disabled="disabled" value="<?php echo $options['id']; ?>" size="3" />
20
+ <input type="hidden" name="gce_options[id]" value="<?php echo $options['id']; ?>" />
21
+ <?php
22
+ }
23
+
24
+ //Title
25
+ function gce_edit_title_field(){
26
+ $options = get_option(GCE_OPTIONS_NAME);
27
+ $options = $options[$_GET['id']];
28
+ ?>
29
+ <span class="description"><?php _e('Anything you like. \'Upcoming Club Events\', for example.', GCE_TEXT_DOMAIN); ?></span>
30
+ <br />
31
+ <input type="text" name="gce_options[title]" value="<?php echo $options['title']; ?>" size="50" />
32
+ <?php
33
+ }
34
+
35
+ //URL
36
+ function gce_edit_url_field(){
37
+ $options = get_option(GCE_OPTIONS_NAME);
38
+ $options = $options[$_GET['id']];
39
+ ?>
40
+ <span class="description"><?php _e('This will probably be something like: \'http://www.google.com/calendar/feeds/your-email@gmail.com/public/full\'.', GCE_TEXT_DOMAIN); ?></span>
41
+ <br />
42
+ <input type="text" name="gce_options[url]" value="<?php echo $options['url']; ?>" size="100" />
43
+ <?php
44
+ }
45
+
46
+ //Show past events
47
+ function gce_edit_show_past_events_field(){
48
+ $options = get_option(GCE_OPTIONS_NAME);
49
+ $options = $options[$_GET['id']];
50
+ ?>
51
+ <span class="description"><?php _e('Select No to retrieve events from now onwards. Select Yes to retrieve events from the first of this month onwards.', GCE_TEXT_DOMAIN); ?></span>
52
+ <fieldset>
53
+ <label><input type="radio" name="gce_options[show_past_events]" value="false"<?php checked($options['show_past_events'], 'false'); ?> /> <?php _e('No', GCE_TEXT_DOMAIN); ?></label>
54
+ <br />
55
+ <label><input type="radio" name="gce_options[show_past_events]" value="true"<?php checked($options['show_past_events'], 'true'); ?> /> <?php _e('Yes', GCE_TEXT_DOMAIN); ?></label>
56
+ </fieldset>
57
+ <?php
58
+ }
59
+
60
+ //Max events
61
+ function gce_edit_max_events_field(){
62
+ $options = get_option(GCE_OPTIONS_NAME);
63
+ $options = $options[$_GET['id']];
64
+ ?>
65
+ <span class="description"><?php _e('The default number of events to retrieve from a Google Calendar feed is 25, but you may want less for a list, or more for a calendar grid.', GCE_TEXT_DOMAIN); ?></span>
66
+ <br />
67
+ <input type="text" name="gce_options[max_events]" value="<?php echo $options['max_events']; ?>" size="3" />
68
+ <?php
69
+ }
70
+
71
+ //Date format
72
+ function gce_edit_date_format_field(){
73
+ $options = get_option(GCE_OPTIONS_NAME);
74
+ $options = $options[$_GET['id']];
75
+ ?>
76
+ <span class="description"><?php _e('In <a href="http://php.net/manual/en/function.date.php">PHP date format</a>. Leave this blank if you\'d rather stick with the default format for your blog.', GCE_TEXT_DOMAIN); ?></span>
77
+ <br />
78
+ <input type="text" name="gce_options[date_format]" value="<?php echo $options['date_format']; ?>" />
79
+ <?php
80
+ }
81
+
82
+ //Time format
83
+ function gce_edit_time_format_field(){
84
+ $options = get_option(GCE_OPTIONS_NAME);
85
+ $options = $options[$_GET['id']];
86
+ ?>
87
+ <span class="description"><?php _e('In <a href="http://php.net/manual/en/function.date.php">PHP date format</a>. Again, leave this blank to stick with the default.', GCE_TEXT_DOMAIN); ?></span>
88
+ <br />
89
+ <input type="text" name="gce_options[time_format]" value="<?php echo $options['time_format']; ?>" />
90
+ <?php
91
+ }
92
+
93
+ //Cache duration
94
+ function gce_edit_cache_duration_field(){
95
+ $options = get_option(GCE_OPTIONS_NAME);
96
+ $options = $options[$_GET['id']];
97
+ ?>
98
+ <span class="description"><?php _e('The length of time, in seconds, to cache the feed (43200 = 12 hours). If this feed changes regularly, you may want to reduce the cache duration.', GCE_TEXT_DOMAIN); ?></span>
99
+ <br />
100
+ <input type="text" name="gce_options[cache_duration]" value="<?php echo $options['cache_duration']; ?>" />
101
+ <?php
102
+ }
103
+ ?>
admin/main.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap">
2
+ <h3><?php _e('Add a New Feed', GCE_TEXT_DOMAIN); ?></h3>
3
+
4
+ <a href="<?php echo esc_url($_SERVER['PHP_SELF'] . '?page=' . GCE_PLUGIN_NAME . '.php&action=add'); ?>" class="button-secondary" title="<?php _e('Click here to add a new feed', GCE_TEXT_DOMAIN); ?>"><?php _e('Add Feed', GCE_TEXT_DOMAIN); ?></a>
5
+
6
+ <br /><br />
7
+ <h3><?php _e('Current Feeds', GCE_TEXT_DOMAIN); ?></h3>
8
+
9
+ <?php
10
+ //If there are no saved feeds
11
+ $options = get_option(GCE_OPTIONS_NAME);
12
+ if(empty($options)){
13
+ ?>
14
+
15
+ <p><?php _e('You haven\'t added any Google Calendar feeds yet.', GCE_TEXT_DOMAIN); ?></p>
16
+
17
+ <?php //If there are saved feeds, display them ?>
18
+ <?php }else{ ?>
19
+
20
+ <table class="widefat">
21
+ <thead>
22
+ <tr>
23
+ <th scope="col"><?php _e('ID', GCE_TEXT_DOMAIN); ?></th>
24
+ <th scope="col"><?php _e('Title', GCE_TEXT_DOMAIN); ?></th>
25
+ <th scope="col"><?php _e('URL', GCE_TEXT_DOMAIN); ?></th>
26
+ <th scope="col"></th>
27
+ </tr>
28
+ </thead>
29
+ <tfoot>
30
+ <tr>
31
+ <th scope="col"><?php _e('ID', GCE_TEXT_DOMAIN); ?></th>
32
+ <th scope="col"><?php _e('Title', GCE_TEXT_DOMAIN); ?></th>
33
+ <th scope="col"><?php _e('URL', GCE_TEXT_DOMAIN); ?></th>
34
+ <th scope="col"></th>
35
+ </tr>
36
+ </tfoot>
37
+
38
+ <tbody>
39
+ <?php
40
+ foreach($options as $key => $event){ ?>
41
+ <tr>
42
+ <td><?php echo $key; ?></td>
43
+ <td><?php echo $event['title']; ?></td>
44
+ <td><?php echo $event['url']; ?></td>
45
+ <td align="right">
46
+ <a href="<?php echo esc_url($_SERVER['PHP_SELF'] . '?page=' . GCE_PLUGIN_NAME . '.php&action=edit&id=' . $key); ?>"><?php _e('Edit', GCE_TEXT_DOMAIN); ?></a>
47
+ |
48
+ <a href="<?php echo esc_url($_SERVER['PHP_SELF'] . '?page=' . GCE_PLUGIN_NAME . '.php&action=delete&id=' . $key); ?>"><?php _e('Delete', GCE_TEXT_DOMAIN); ?></a>
49
+ </td>
50
+ </tr>
51
+ <?php } ?>
52
+ </tbody>
53
+
54
+ </table>
55
+
56
+ <?php } ?>
57
+
58
+ <br />
59
+ <h3><?php _e('Custom Stylesheet', GCE_TEXT_DOMAIN); ?></h3>
60
+ <p><?php _e('If you would rather use a custom CSS stylesheet than the default, enter the stylesheet URL below. Leave blank to use the default.', GCE_TEXT_DOMAIN); ?></p>
61
+
62
+ <p><input type="text" name="gce_stylesheet" value="<?php echo get_option('gce_stylesheet'); ?>" size="100" /></p>
63
+
64
+ <input type="submit" class="button-primary" value="<?php esc_attr_e('Save URL', GCE_TEXT_DOMAIN); ?>" />
65
+ </div>
css/gce-style.css ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* PAGE GRID */
2
+
3
+ .gce-page-grid .gce-calendar .gce-caption{ /* Caption at top of calendar */
4
+ color:#333333;
5
+ }
6
+
7
+ .gce-page-grid .gce-calendar{ /* Main calendar table */
8
+ width:100%;
9
+ border-collapse:collapse;
10
+ border:1px solid #CCCCCC;
11
+ color:#DDDDDD;
12
+ }
13
+
14
+ .gce-page-grid .gce-calendar th{ /* Day headings (S, M etc.) */
15
+ border:1px solid #CCCCCC;
16
+ text-align:center;
17
+ width:14.29%;
18
+ padding:0 !important;
19
+ }
20
+
21
+ .gce-page-grid .gce-calendar td{ /* Day table cells */
22
+ border:1px solid #CCCCCC;
23
+ text-align:center;
24
+ height:90px;
25
+ vertical-align:middle;
26
+ }
27
+
28
+ .gce-page-grid .gce-calendar .gce-has-events{ /* Table cells with events */
29
+ color:#333333;
30
+ cursor:pointer;
31
+ }
32
+
33
+ .gce-page-grid .gce-calendar .gce-event-info{ /* Event information */
34
+ display:none; /* Important! */
35
+ }
36
+
37
+ .gce-page-grid .gce-calendar .gce-day-number{ /* Day number span */
38
+ font-size:2em;
39
+ }
40
+
41
+ .gce-page-grid .gce-calendar .gce-today{ /* Table cell that represents today */
42
+ background-color:#EEEEEE;
43
+ }
44
+
45
+ .gce-page-grid .gce-calendar .gce-next,
46
+ .gce-page-grid .gce-calendar .gce-prev{
47
+ cursor:pointer;
48
+ display:inline-block;
49
+ width:3%;
50
+ }
51
+
52
+ .gce-page-grid .gce-calendar .gce-month-title{
53
+ display:inline-block;
54
+ width:90%;
55
+ }
56
+
57
+ /* PAGE LIST */
58
+
59
+ .gce-page-list .gce-list .gce-date-time{
60
+ margin:0 !important;
61
+ font-weight:bold;
62
+ }
63
+
64
+ /* WIDGET GRID */
65
+
66
+ .gce-widget-grid .gce-calendar .gce-caption{
67
+ margin:10px 0 5px 0;
68
+ }
69
+
70
+ .gce-widget-grid .gce-calendar{ /* Main calendar table */
71
+ text-align:center;
72
+ width:100%;
73
+ border:1px solid #CCCCCC;
74
+ border-collapse:collapse;
75
+ }
76
+
77
+ .gce-widget-grid .gce-calendar th{ /* Day headings (S, M etc.) */
78
+ width:14.29%;
79
+ border:1px solid #CCCCCC;
80
+ }
81
+
82
+ .gce-widget-grid .gce-calendar td{ /* Day table cells */
83
+ color:#CCCCCC;
84
+ width:14.29%;
85
+ border:1px solid #CCCCCC;
86
+ }
87
+
88
+ .gce-widget-grid .gce-calendar .gce-has-events{ /* Table cells with events */
89
+ cursor:pointer;
90
+ color:#666666;
91
+ }
92
+
93
+ .gce-widget-grid .gce-calendar .gce-today{ /* Table cell that represents today */
94
+ background-color:#DDDDDD;
95
+ }
96
+
97
+ .gce-widget-grid .gce-calendar .gce-event-info{ /* Event information */
98
+ display:none; /* Important! */
99
+ }
100
+
101
+ .gce-widget-grid .gce-calendar .gce-next,
102
+ .gce-widget-grid .gce-calendar .gce-prev{ /* Prev and next month links */
103
+ cursor:pointer;
104
+ display:inline-block;
105
+ width:5%;
106
+ }
107
+
108
+ .gce-widget-grid .gce-calendar .gce-month-title{ /* Month title in caption at top of table */
109
+ display:inline-block;
110
+ width:80%;
111
+ }
112
+
113
+ /* WIDGET LIST */
114
+
115
+ .gce-widget-list .gce-list{
116
+ margin:10px 0 0 0;
117
+ }
118
+
119
+ .gce-widget-list .gce-list .gce-date-time{
120
+ margin:0;
121
+ font-weight:bold;
122
+ }
123
+
124
+ .gce-widget-list .gce-list .gce-event-text{
125
+ margin:0;
126
+ }
127
+
128
+ /* TOOLTIP */
129
+
130
+ #gce-tooltip{ /* Tooltip container */
131
+ position:absolute;
132
+ display:none;
133
+ background-color:#FFFFFF;
134
+ border:1px solid #333333;
135
+ text-align:left;
136
+ max-width:200px;
137
+ }
138
+
139
+ #gce-tooltip p{ /* 'Events on...' text */
140
+ margin:5px !important;
141
+ }
142
+
143
+ #gce-tooltip ul{ /* Events list */
144
+ padding:0 !important;
145
+ margin:5px !important;
146
+ list-style-type:none;
147
+ }
148
+
149
+ #gce-tooltip ul li{ /* Event list item */
150
+ margin:5px 0 0 0;
151
+ }
google-calendar-events.php ADDED
@@ -0,0 +1,329 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Google Calendar Events
4
+ Plugin URI: http://www.rhanney.co.uk/plugins/google-calendar-events
5
+ Description: Parses Google Calendar feeds and displays the events as a calendar grid or list on a page, post or widget.
6
+ Version: 0.1
7
+ Author: Ross Hanney
8
+ Author URI: http://www.rhanney.co.uk
9
+ License: GPL2
10
+
11
+ ---
12
+
13
+ Copyright 2010 Ross Hanney (email: rosshanney@gmail.com)
14
+
15
+ This program is free software; you can redistribute it and/or modify
16
+ it under the terms of the GNU General Public License as published by
17
+ the Free Software Foundation; either version 2 of the License, or
18
+ (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
+ */
29
+
30
+ define('GCE_PLUGIN_NAME', str_replace('.php', '', basename(__FILE__)));
31
+ define('GCE_TEXT_DOMAIN', 'google-calendar-events');
32
+ define('GCE_OPTIONS_NAME', 'gce_options');
33
+
34
+ require_once 'widget/gce-widget.php';
35
+ require_once 'inc/gce-parser.php';
36
+
37
+ if(!class_exists('Google_Calendar_Events')){
38
+ class Google_Calendar_Events{
39
+ //PHP 4 constructor
40
+ function Google_Calendar_Events(){
41
+ $this->__construct();
42
+ }
43
+
44
+ //PHP 5 constructor
45
+ function __construct(){
46
+ //add_action('activate_google-calendar-events/google-calendar-events.php', array($this, 'get_options'));
47
+ add_action('admin_menu', array($this, 'setup_admin'));
48
+ add_action('admin_init', array($this, 'init_admin'));
49
+
50
+ add_action('widgets_init', create_function('', 'return register_widget("GCE_Widget");'));
51
+
52
+ add_shortcode('google-calendar-events', array($this, 'shortcode_handler'));
53
+
54
+ add_action('wp_print_styles', array($this, 'add_styles'));
55
+ add_action('wp_print_scripts', array($this, 'add_scripts'));
56
+ }
57
+
58
+ //Setup admin settings page
59
+ function setup_admin(){
60
+ if(function_exists('add_options_page')) add_options_page('Google Calendar Events', 'Google Calendar Events', 9, basename(__FILE__), array($this, 'admin_page'));
61
+ add_option(GCE_OPTIONS_NAME);
62
+ }
63
+
64
+ //Prints admin settings page
65
+ function admin_page(){
66
+ //Add correct updated message (added / edited / deleted)
67
+ switch($_GET['updated']){
68
+ case 'added':
69
+ ?><div class="updated"><p><strong>New Feed Added Successfully.</strong></p></div><?php
70
+ break;
71
+ case 'edited':
72
+ ?><div class="updated"><p><strong>Feed Details Updated Successfully.</strong></p></div><?php
73
+ break;
74
+ case 'deleted':
75
+ ?><div class="updated"><p><strong>Feed Deleted Successfully.</strong></p></div><?php
76
+ break;
77
+ }?>
78
+
79
+ <div class="wrap">
80
+ <div id="icon-options-general" class="icon32"><br /></div>
81
+
82
+ <h2>Google Calendar Events</h2>
83
+ <form method="post" action="options.php" id="test-form">
84
+ <?php
85
+ settings_fields('gce_options_group');
86
+
87
+ switch($_GET['action']){
88
+ //Add feed section
89
+ case 'add':
90
+ do_settings_sections('add_feed');
91
+ ?><p class="submit"><input type="submit" class="button-primary submit" value="<?php esc_attr_e('Add Feed', GCE_TEXT_DOMAIN); ?>" /></p>
92
+ <p><a href="<?php echo admin_url() . 'options-general.php?page=' . GCE_PLUGIN_NAME . '.php'; ?>" class="button-secondary">Cancel</a></p><?php
93
+ break;
94
+ //Edit feed section
95
+ case 'edit':
96
+ do_settings_sections('edit_feed');
97
+ ?><p class="submit"><input type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes', GCE_TEXT_DOMAIN); ?>" /></p>
98
+ <p><a href="<?php echo admin_url() . 'options-general.php?page=' . GCE_PLUGIN_NAME . '.php'; ?>" class="button-secondary">Cancel</a></p><?php
99
+ break;
100
+ //Delete feed section
101
+ case 'delete':
102
+ do_settings_sections('delete_feed');
103
+ ?><p class="submit"><input type="submit" class="button-primary" name="gce_options[submit_delete]" value="<?php esc_attr_e('Delete Feed', GCE_TEXT_DOMAIN); ?>" /></p>
104
+ <p><a href="<?php echo admin_url() . 'options-general.php?page=' . GCE_PLUGIN_NAME . '.php'; ?>" class="button-secondary">Cancel</a></p><?php
105
+ break;
106
+ //Main admin section
107
+ default:
108
+ settings_fields('gce_stylesheet');
109
+ require_once 'admin/main.php';
110
+ }
111
+ ?>
112
+ </form>
113
+ </div>
114
+ <?php
115
+ }
116
+
117
+ //Initialize admin stuff
118
+ function init_admin(){
119
+ register_setting('gce_options_group', 'gce_options', array($this, 'validate_options'));
120
+ register_setting('gce_stylesheet', 'gce_stylesheet', 'esc_url');
121
+
122
+ //Setup add feed admin section and all fields
123
+ require_once 'admin/add.php';
124
+ add_settings_section('gce_add', __('Add a Feed', GCE_TEXT_DOMAIN), 'gce_add_main_text', 'add_feed');
125
+ //Unique ID //Title //Function //Page //Section ID
126
+ add_settings_field('gce_add_id_field', __('Feed ID', GCE_TEXT_DOMAIN), 'gce_add_id_field', 'add_feed', 'gce_add');
127
+ add_settings_field('gce_add_title_id_field', __('Feed Title', GCE_TEXT_DOMAIN), 'gce_add_title_field', 'add_feed', 'gce_add');
128
+ add_settings_field('gce_add_url_field', __('Feed URL', GCE_TEXT_DOMAIN), 'gce_add_url_field', 'add_feed', 'gce_add');
129
+ add_settings_field('gce_add_show_past_events_field', __('Retrieve past events for current month?', GCE_TEXT_DOMAIN), 'gce_add_show_past_events_field', 'add_feed', 'gce_add');
130
+ add_settings_field('gce_add_max_events_field', __('Maximum number of events to retrieve', GCE_TEXT_DOMAIN), 'gce_add_max_events_field', 'add_feed', 'gce_add');
131
+ add_settings_field('gce_add_date_format_field', __('Date format', GCE_TEXT_DOMAIN), 'gce_add_date_format_field', 'add_feed', 'gce_add');
132
+ add_settings_field('gce_add_time_format_field', __('Time format', GCE_TEXT_DOMAIN), 'gce_add_time_format_field', 'add_feed', 'gce_add');
133
+ add_settings_field('gce_add_cache_duration_field', __('Cache duration', GCE_TEXT_DOMAIN), 'gce_add_cache_duration_field', 'add_feed', 'gce_add');
134
+
135
+ //Setup edit feed admin section and all fields
136
+ require_once 'admin/edit.php';
137
+ add_settings_section('gce_edit', __('Edit Feed', GCE_TEXT_DOMAIN), 'gce_edit_main_text', 'edit_feed');
138
+ //Unique ID //Title //Function //Page //Section ID
139
+ add_settings_field('gce_edit_id_field', __('Feed ID', GCE_TEXT_DOMAIN), 'gce_edit_id_field', 'edit_feed', 'gce_edit');
140
+ add_settings_field('gce_edit_title_field', __('Feed Title', GCE_TEXT_DOMAIN), 'gce_edit_title_field', 'edit_feed', 'gce_edit');
141
+ add_settings_field('gce_edit_url_field', __('Feed URL', GCE_TEXT_DOMAIN), 'gce_edit_url_field', 'edit_feed', 'gce_edit');
142
+ add_settings_field('gce_edit_show_past_events_field', __('Retrieve past events for current month?', GCE_TEXT_DOMAIN), 'gce_edit_show_past_events_field', 'edit_feed', 'gce_edit');
143
+ add_settings_field('gce_edit_max_events_field', __('Maximum number of events to retrieve', GCE_TEXT_DOMAIN), 'gce_edit_max_events_field', 'edit_feed', 'gce_edit');
144
+ add_settings_field('gce_edit_date_format_field', __('Date format', GCE_TEXT_DOMAIN), 'gce_edit_date_format_field', 'edit_feed', 'gce_edit');
145
+ add_settings_field('gce_edit_time_format_field', __('Time format', GCE_TEXT_DOMAIN), 'gce_edit_time_format_field', 'edit_feed', 'gce_edit');
146
+ add_settings_field('gce_edit_cache_duration_field', __('Cache duration', GCE_TEXT_DOMAIN), 'gce_edit_cache_duration_field', 'edit_feed', 'gce_edit');
147
+
148
+ //Setup delete feed admin section and all fields
149
+ require_once 'admin/delete.php';
150
+ add_settings_section('gce_delete', __('Delete Feed', GCE_TEXT_DOMAIN), 'gce_delete_main_text', 'delete_feed');
151
+ //Unique ID //Title //Function //Page //Section ID
152
+ add_settings_field('gce_delete_id_field', __('Feed ID', GCE_TEXT_DOMAIN), 'gce_delete_id_field', 'delete_feed', 'gce_delete');
153
+ add_settings_field('gce_delete_title_field', __('Feed Title', GCE_TEXT_DOMAIN), 'gce_delete_title_field', 'delete_feed', 'gce_delete');
154
+ }
155
+
156
+ //Check / validate submitted data before being stored
157
+ function validate_options($input){
158
+ //Get saved options
159
+ $options = get_option(GCE_OPTIONS_NAME);
160
+
161
+ if(isset($input['submit_delete'])){
162
+ //If delete button was clicked, delete feed from options array
163
+ unset($options[$input['id']]);
164
+ }else{
165
+ //Otherwise, validate options and add / update them
166
+
167
+ //Check id is positive integer
168
+ $id = absint($input['id']);
169
+ //Escape title text
170
+ $title = esc_html($input['title']);
171
+ //Escape feed url
172
+ $url = esc_url($input['url']);
173
+ //Make sure show past events is either true of false
174
+ $show_past_events = ($input['show_past_events'] == 'true' ? 'true' : 'false');
175
+ //Check max events is a positive integer. If absint returns 0, reset to default (25)
176
+ $max_events = (absint($input['max_events']) == 0 ? 25 : absint($input['max_events']));
177
+
178
+ $date_format = $input['date_format'];
179
+ $time_format = $input['time_format'];
180
+
181
+ //Make sure cache duration is a positive integer or 0. If user has typed 0, leave as 0 but if 0 is returned from absint, set to default (43200)
182
+ $cache_duration = $input['cache_duration'];
183
+ if($cache_duration != '0'){
184
+ $cache_duration = (absint($cache_duration) == 0 ? 43200 : absint($cache_duration));
185
+ }
186
+
187
+ //Fill options array with validated values
188
+ $options[$id] = array(
189
+ 'id' => $id,
190
+ 'title' => $title,
191
+ 'url' => $url,
192
+ 'show_past_events' => $show_past_events,
193
+ 'max_events' => $max_events,
194
+ 'date_format' => $date_format,
195
+ 'time_format' => $time_format,
196
+ 'cache_duration' => $cache_duration
197
+ );
198
+ }
199
+
200
+ return $options;
201
+ }
202
+
203
+ //Handles the shortcode stuff
204
+ function shortcode_handler($atts){
205
+ extract(shortcode_atts(array(
206
+ 'id' => '1',
207
+ 'type' => 'grid'
208
+ ), $atts));
209
+
210
+ switch($type){
211
+ case 'grid':
212
+ return gce_print_grid($id);
213
+ break;
214
+ case 'ajax':
215
+ return gce_print_grid($id, true);
216
+ break;
217
+ case 'list':
218
+ return gce_print_list($id);
219
+ break;
220
+ }
221
+ }
222
+
223
+ //Adds the required CSS
224
+ function add_styles(){
225
+ //Don't add styles if on admin screens
226
+ if(!is_admin()){
227
+ //If user has entered a URL to a custom stylesheet, use it. Otherwise use the default
228
+ if((get_option('gce_stylesheet') != false) && (get_option('gce_stylesheet') != '')){
229
+ wp_enqueue_style('gce_styles', get_option('gce_stylesheet'));
230
+ }else{
231
+ wp_enqueue_style('gce_styles', WP_PLUGIN_URL . '/' . GCE_PLUGIN_NAME . '/css/gce-style.css');
232
+ }
233
+ }
234
+ }
235
+
236
+ //Adds the required scripts
237
+ function add_scripts(){
238
+ //Don't add scripts if on admin screens
239
+ if(!is_admin()){
240
+ wp_enqueue_script('jquery');
241
+ wp_enqueue_script('gce_scripts', WP_PLUGIN_URL . '/' . GCE_PLUGIN_NAME . '/js/gce-tooltip-script.js');
242
+ }
243
+ }
244
+ }
245
+ }
246
+
247
+ function gce_print_list($feed_id){
248
+ //Get saved feed options
249
+ $options = get_option(GCE_OPTIONS_NAME);
250
+
251
+ //Set time and date formats to WordPress defaults if not set by user
252
+ $df = $options[$feed_id]['date_format'];
253
+ $tf = $options[$feed_id]['time_format'];
254
+ if($df == '') $df = get_option('date_format');
255
+ if($tf == '') $tf = get_option('time_format');
256
+
257
+ //Creates a new GCE_Parser object for $feed_id
258
+ $feed_data = new GCE_Parser(
259
+ $options[$feed_id]['url'],
260
+ $options[$feed_id]['show_past_events'],
261
+ $options[$feed_id]['max_events'],
262
+ $options[$feed_id]['cache_duration'],
263
+ $df,
264
+ $tf,
265
+ get_option('start_of_week')
266
+ );
267
+
268
+ //If the feed parsed ok
269
+ if($feed_data->parsed_ok()){
270
+ $markup = '<div class="gce-page-list">' . $feed_data->get_list() . '</div>';
271
+
272
+ return $markup;
273
+ }else{
274
+ return 'The Google Calendar feed was not parsed successfully, please check that the feed URL is correct.';
275
+ }
276
+ }
277
+
278
+ function gce_print_grid($feed_id, $ajaxified = false, $month = null, $year = null){
279
+ //Get saved feed options
280
+ $options = get_option(GCE_OPTIONS_NAME);
281
+
282
+ //Set time and date formats to WordPress defaults if not set by user
283
+ $df = $options[$feed_id]['date_format'];
284
+ $tf = $options[$feed_id]['time_format'];
285
+ if($df == '') $df = get_option('date_format');
286
+ if($tf == '') $tf = get_option('time_format');
287
+
288
+ //Creates a new GCE_Parser object for $feed_id
289
+ $feed_data = new GCE_Parser(
290
+ $options[$feed_id]['url'],
291
+ $options[$feed_id]['show_past_events'],
292
+ $options[$feed_id]['max_events'],
293
+ $options[$feed_id]['cache_duration'],
294
+ $df,
295
+ $tf,
296
+ get_option('start_of_week')
297
+ );
298
+
299
+ //If the feed parsed ok
300
+ if($feed_data->parsed_ok()){
301
+ $markup = '<div class="gce-page-grid" id="gce-page-grid-' . $feed_id .'">';
302
+
303
+ //Add AJAX script if required
304
+ if($ajaxified){
305
+ $markup .= '<script type="text/javascript">jQuery(document).ready(function($){gce_ajaxify("gce-page-grid-' . $feed_id . '", "' . $feed_id . '", "page");});</script>';
306
+ }
307
+
308
+ $markup .= $feed_data->get_grid($year, $month, $ajaxified);
309
+
310
+ $markup .= '</div>';
311
+ return $markup;
312
+ }else{
313
+ return 'The Google Calendar feed was not parsed successfully, please check that the feed URL is correct.';
314
+ }
315
+ }
316
+
317
+ function gce_handle_ajax($feed_id, $month = null, $year = null){
318
+ echo gce_print_grid($feed_id, true, $month, $year);
319
+ }
320
+
321
+ if($_GET['gce_type'] == 'page'){
322
+ if(isset($_GET['gce_feed_id'])){
323
+ gce_handle_ajax($_GET['gce_feed_id'], $_GET['gce_month'], $_GET['gce_year']);
324
+ die();
325
+ }
326
+ }
327
+
328
+ $gce = new Google_Calendar_Events();
329
+ ?>
inc/gce-parser.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once(ABSPATH . WPINC . '/class-feed.php');
3
+ require_once('simplepie-gcalendar.php');
4
+
5
+ class GCE_Parser{
6
+ var $feed;
7
+ var $d_format;
8
+ var $t_format;
9
+ var $week_start_day;
10
+
11
+ //PHP 4 constructor
12
+ function GCE_Parser($feed_url = null, $past_events = false, $max_events = 25, $cache_duration = 43200, $date_format = 'F j, Y', $time_format = 'g:i a', $week_start = 0){
13
+ $this->__construct($feed_url, $past_events, $max_events, $cache_duration, $date_format, $week_start);
14
+ }
15
+
16
+ //PHP 5 constructor
17
+ function __construct($feed_url = null, $past_events = false, $max_events = 25, $cache_duration = 43200, $date_format = 'F j, Y', $time_format = 'g:i a', $week_start = 0){
18
+ $new_feed = new SimplePie_GCalendar(null, null, $cache_duration);
19
+ $new_feed->set_cache_class('WP_Feed_Cache');
20
+ $new_feed->set_file_class('WP_SimplePie_File');
21
+
22
+ $new_feed->set_feed_url($feed_url);
23
+
24
+ //Set start date to 1st of this month if $past_events is true (otherwise leave as todays date)
25
+ if($past_events == 'true') $new_feed->set_start_date(mktime(0, 0, 0, date('m'), 1, date('Y')));
26
+
27
+ $new_feed->set_max_events($max_events);
28
+ $new_feed->enable_order_by_date(false);
29
+
30
+ $new_feed->init();
31
+ $new_feed->handle_content_type();
32
+
33
+ $this->feed = $new_feed;
34
+
35
+ $this->d_format = $date_format;
36
+ $this->t_format = $time_format;
37
+ $this->week_start_day = $week_start;
38
+ }
39
+
40
+ //Check for SimplePie errors. Return false if an error occurred, otherwise return true
41
+ function parsed_ok(){
42
+ if($this->feed->error()) return false;
43
+ return true;
44
+ }
45
+
46
+ //Returns array of days with events, with sub-arrays of events for that day
47
+ function get_event_days(){
48
+ $event_days;
49
+
50
+ foreach($this->feed->get_items() as $item){
51
+ $start_date = $item->get_start_date();
52
+
53
+ //Round start date to nearest day
54
+ $start_date = mktime(0, 0, 0, date('m', $start_date), date('d', $start_date) , date('Y', $start_date));
55
+
56
+ if(!$event_days[$start_date]){
57
+ //Create new array in $event_days for this date (only dates with events will go into array, so, for
58
+ //example $event_days[26] will exist if 26th of month has events, but won't if it has no events
59
+ $event_days[$start_date] = array();
60
+ }
61
+
62
+ //Push event into array just created (may be another event for this date later in feed)
63
+ array_push($event_days[$start_date], $item);
64
+ }
65
+
66
+ return $event_days;
67
+ }
68
+
69
+ //Returns list markup
70
+ function get_list(){
71
+ $event_days = $this->get_event_days();
72
+
73
+ $markup = '<ul class="gce-list">';
74
+
75
+ foreach($event_days as $key => $event_day){
76
+ foreach($event_day as $event){
77
+ $markup .=
78
+ '<li>' .
79
+ '<p class="gce-date-time">' .
80
+ '<span class="gce-date">' . date($this->d_format, $key) . '</span>, ' .
81
+ '<span class="gce-time">' . date($this->t_format, $event->get_start_date()) . '</span>' .
82
+ '</p>' .
83
+ '<p class="gce-event-text">' . $event->get_title() . '</p>' .
84
+ '</li>';
85
+ }
86
+ }
87
+
88
+ $markup .= '</ul>';
89
+
90
+ return $markup;
91
+ }
92
+
93
+ //Returns grid markup
94
+ function get_grid($year = null, $month = null, $ajaxified = false){
95
+ require_once('php-calendar.php');
96
+
97
+ //If year and month have not been passed as paramaters, use current month and year
98
+ if($year == null) $year = date('Y');
99
+ if($month == null) $month = date('m');
100
+
101
+ //Month and year to be displayed, in format mY (e.g. 052010)
102
+ $m_y = date('mY', mktime(0, 0, 0, $month, 1, $year));
103
+
104
+ //Get events data
105
+ $event_days = $this->get_event_days();
106
+
107
+ $no_more_events = false;
108
+
109
+ foreach($event_days as $key => $event_day){
110
+ //If event day is in the month and year specified (by $month and $year)
111
+ if(date('mY', $key) == $m_y){
112
+ //If this event day is the last in $event_days, there are no more events so set $no_more_events to true
113
+ if($event_day == end($event_days)) $no_more_events = true;
114
+
115
+ //Create markup for tooltip
116
+ $events_markup = '<div class="gce-event-info"><p>Events on ' . date($this->d_format, $key) . ':</p><ul>';
117
+ foreach($event_day as $event){
118
+ $events_markup .= '<li><strong>' . date($this->t_format, $event->get_start_date()) . '</strong><br />' . $event->get_title() . '</p></li>';
119
+ }
120
+ $events_markup .= '</ul></div>';
121
+
122
+ //If this event day is today, add gce-today class to $css_classes
123
+ $css_classes = 'gce-has-events';
124
+ if($key == mktime(0, 0, 0, date('m'), date('d'), date('Y'))) $css_classes .= ' gce-today';
125
+
126
+ //Change array entry to array of link href, CSS classes, and markup for use in generate_calendar (below)
127
+ $event_days[$key] = array(null, $css_classes, $events_markup);
128
+ }else{
129
+ //Else if event day isn't in month and year specified, remove event day (and all associated events) from the array
130
+ unset($event_days[$key]);
131
+ }
132
+ }
133
+
134
+ //Only add previous / next functionality if AJAX grid is enabled
135
+ if($ajaxified){
136
+ //If the month shown is the current month, don't add previous month link. If it isn't, add previous month link
137
+ $prev_key = ($m_y == date('mY') ? '&nbsp;' : '&laquo;');
138
+ $prev = ($m_y == date('mY') ? null : date('m-Y', mktime(0, 0, 0, $month - 1, 1, $year)));
139
+
140
+ //If $no_more_events don't add next month link. If there are more events, add next month link
141
+ $next_key = ($no_more_events ? '&nbsp;' : '&raquo;');
142
+ $next = ($no_more_events ? null : date('m-Y', mktime(0, 0, 0, $month + 1, 1, $year)));
143
+
144
+ //Array of previous and next link stuff for use in generate_calendar (below)
145
+ $pn = array($prev_key => $prev, $next_key => $next);
146
+ }
147
+
148
+ //Generate the calendar markup and return it
149
+ return generate_calendar($year, $month, $event_days, 1, null, $this->week_start_day, $pn);
150
+ }
151
+ }
152
+ ?>
inc/php-calendar.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ # PHP Calendar (version 2.3), written by Keith Devens
3
+ # http://keithdevens.com/software/php_calendar
4
+ # see example at http://keithdevens.com/weblog
5
+ # License: http://keithdevens.com/software/license
6
+
7
+ /*
8
+ Changes made to original PHP Calendar script by me (Ross Hanney):
9
+
10
+ - Renamed CSS classes to fit with my plugin
11
+ - Slight modification of lines 55-63 to use Unix timestamp rather than day number
12
+ - Other small markup changes
13
+ */
14
+
15
+ function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array()){
16
+ $first_of_month = gmmktime(0, 0, 0, $month, 1, $year);
17
+ #remember that mktime will automatically correct if invalid dates are entered
18
+ # for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
19
+ # this provides a built in "rounding" feature to generate_calendar()
20
+
21
+ $day_names = array(); #generate all the day names according to the current locale
22
+ for($n = 0, $t = (3 + $first_day) * 86400; $n < 7; $n++, $t += 86400){ #January 4, 1970 was a Sunday
23
+ $day_names[$n] = ucfirst(gmstrftime('%A', $t)); #%A means full textual day name
24
+ }
25
+
26
+ list($month, $year, $month_name, $weekday) = explode(',', gmstrftime('%m, %Y, %B, %w', $first_of_month));
27
+ $weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
28
+ $title = htmlentities(ucfirst($month_name)) . '&nbsp;' . $year; #note that some locales don't capitalize month and day names
29
+
30
+ #Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
31
+ @list($p, $pl) = each($pn);
32
+ @list($n, $nl) = each($pn); #previous and next links, if applicable
33
+
34
+ if($p) $p = '<span class="gce-prev">' . ($pl ? '<a class="gce-change-month" title="Previous month" name="' . $pl . '">' . $p . '</a>' : $p) . '</span>&nbsp;';
35
+ if($n) $n = '&nbsp;<span class="gce-next">' . ($nl ? '<a class="gce-change-month" title="Next month" name="' . $nl . '">' . $n . '</a>' : $n) . '</span>';
36
+
37
+ $calendar = '<table class="gce-calendar">' . "\n" . '<caption class="gce-caption">' . $p . '<span class="gce-month-title">' . ($month_href ? '<a href="' . htmlspecialchars($month_href) . '">' . $title . '</a>' : $title) . '</span>' . $n . "</caption>\n<tr>";
38
+
39
+ if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
40
+ #if day_name_length is >3, the full name of the day will be printed
41
+ foreach($day_names as $d){
42
+ $calendar .= '<th abbr="' . htmlentities($d) . '">' . htmlentities($day_name_length < 4 ? substr($d, 0, $day_name_length) : $d) . '</th>';
43
+ }
44
+
45
+ $calendar .= "</tr>\n<tr>";
46
+ }
47
+
48
+ if($weekday > 0) $calendar .= '<td colspan="' . $weekday . '">&nbsp;</td>'; #initial 'empty' days
49
+ for($day = 1, $days_in_month = gmdate('t', $first_of_month); $day <= $days_in_month; $day++, $weekday++){
50
+ if($weekday == 7){
51
+ $weekday = 0; #start a new week
52
+ $calendar .= "</tr>\n<tr>";
53
+ }
54
+
55
+ $timestamp = mktime(0, 0, 0, $month, $day, $year);
56
+
57
+ if(isset($days[$timestamp]) and is_array($days[$timestamp])){
58
+ @list($link, $classes, $content) = $days[$timestamp];
59
+ $calendar .= '<td' . ($classes ? ' class="' . htmlspecialchars($classes) . '">' : '>') . ($link ? '<a href="' . htmlspecialchars($link) . '"><span class="gce-day-number">' . $day . '</span></a>' . $content : '<span class="gce-day-number">' . $day . '</span>' . $content) . '</td>';
60
+ }else{
61
+ $calendar .= '<td><span class="gce-day-number">' . $day . '</span></td>';
62
+ }
63
+ }
64
+
65
+ if($weekday != 7) $calendar .= '<td colspan="' . (7 - $weekday) . '">&nbsp;</td>'; #remaining "empty" days
66
+
67
+ return $calendar . "</tr>\n</table>\n";
68
+ }
69
+ ?>
inc/simplepie-gcalendar.php ADDED
@@ -0,0 +1,468 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * GCalendar is free software: you can redistribute it and/or modify
4
+ * it under the terms of the GNU General Public License as published by
5
+ * the Free Software Foundation, either version 3 of the License, or
6
+ * (at your option) any later version.
7
+ *
8
+ * GCalendar is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ * GNU General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU General Public License
14
+ * along with GCalendar. If not, see <http://www.gnu.org/licenses/>.
15
+ *
16
+ * @author Allon Moritz
17
+ * @copyright 2007-2009 Allon Moritz
18
+ * @version $Revision: 0.4.0 $
19
+ */
20
+
21
+ if (!defined('SIMPLEPIE_NAMESPACE_GOOGLE_CALENDAR_ITEM')) {
22
+ define('SIMPLEPIE_NAMESPACE_GOOGLE_CALENDAR_ITEM', 'http://schemas.google.com/g/2005');
23
+ }
24
+
25
+ if (!defined('SIMPLEPIE_NAMESPACE_GOOGLE_CALENDAR_FEED')) {
26
+ define('SIMPLEPIE_NAMESPACE_GOOGLE_CALENDAR_FEED', 'http://schemas.google.com/gCal/2005');
27
+ }
28
+
29
+ /**
30
+ * SimplePie_GCalendar is the SimplePie extension which provides some
31
+ * helper methods.
32
+ *
33
+ * @see http://code.google.com/apis/calendar/docs/2.0/reference.html
34
+ */
35
+ class SimplePie_GCalendar extends SimplePie {
36
+
37
+ var $show_past_events = FALSE;
38
+ var $sort_ascending = TRUE;
39
+ var $orderby_by_start_date = TRUE;
40
+ var $expand_single_events = TRUE;
41
+ var $cal_language = "";
42
+ var $cal_query = "";
43
+ var $meta_data = array();
44
+ var $start_date = null;
45
+ var $end_date = null;
46
+ var $max_events = 25;
47
+ var $projection = "full";
48
+ var $timezone = "";
49
+
50
+ /**
51
+ * If the method $this->get_items() should include past events.
52
+ */
53
+ function set_show_past_events($value = FALSE){
54
+ $this->show_past_events = $value;
55
+ }
56
+
57
+ /**
58
+ * If is set to true the closest event is the first in the returning items.
59
+ * So it makes sense to call enable_order_by_date(false) before fetching
60
+ * the data to prevent from sorting twice.
61
+ */
62
+ function set_sort_ascending($value = TRUE){
63
+ $this->sort_ascending = $value;
64
+ }
65
+
66
+ /**
67
+ * The method $this->get_items() will return the events ordered by
68
+ * the start date if set to true otherwise by the publish date.
69
+ *
70
+ */
71
+ function set_orderby_by_start_date($value = TRUE){
72
+ $this->orderby_by_start_date = $value;
73
+ }
74
+
75
+ /**
76
+ * If the method $this->get_items() should treat reccuring events
77
+ * as one item.
78
+ */
79
+ function set_expand_single_events($value = TRUE){
80
+ $this->expand_single_events = $value;
81
+ }
82
+
83
+ /**
84
+ * Sets the language of the feed. Something like
85
+ * en or en_GB or de.
86
+ */
87
+ function set_cal_language($value = ""){
88
+ $this->cal_language = $value;
89
+ }
90
+
91
+ /**
92
+ * If this parameter is set the feed will just contain events
93
+ * which contain the given parameter in the titel or the description.
94
+ *
95
+ * @param $value
96
+ */
97
+ function set_cal_query($value = ""){
98
+ $this->cal_query = $value;
99
+ }
100
+
101
+ /**
102
+ * Sets the start date of the events in the feed, set_end_date(...)
103
+ * must also be feeded with a value.
104
+ * If this value is set the set_show_past_events(...)
105
+ * will be ignored.
106
+ *
107
+ * @param $value must php timestamp
108
+ */
109
+ function set_start_date($value = 0){
110
+ $this->start_date = strftime('%Y-%m-%dT%H:%M:%S',$value);
111
+ }
112
+
113
+ /**
114
+ * Sets the end date of the events in the feed, set_start_date(...)
115
+ * must also be feeded with a value.
116
+ * If this value is set the set_show_past_events(...)
117
+ * will be ignored.
118
+ *
119
+ * @param $value must be php timestamp
120
+ */
121
+ function set_end_date($value = 0){
122
+ $this->end_date = strftime('%Y-%m-%dT%H:%M:%S',$value);
123
+ }
124
+
125
+ /**
126
+ * Sets the max events this feed should fetch
127
+ *
128
+ * @param $value the max events
129
+ */
130
+ function set_max_events($value = 25){
131
+ $this->max_events = $value;
132
+ }
133
+
134
+ /**
135
+ * Sets the projection of this feed. The given value must one of the
136
+ * following strings:
137
+ * - full
138
+ * - full-noattendees
139
+ * - composite
140
+ * - attendees-only
141
+ * - free-busy
142
+ * - basic
143
+ * Note if the feed projection is not full, some methodes in the returned
144
+ * items are empty. For example if the feed projection is basic the method
145
+ * SimplePie_Item_GCalendar->get_start_date() returns an empty string,
146
+ * because this information is only included in the full projection.
147
+ * @param $value
148
+ */
149
+ function set_projection($value = "full"){
150
+ if(!empty($value))
151
+ $this->projection = $value;
152
+ }
153
+
154
+ /**
155
+ * Sets the timezone of this feed.
156
+ *
157
+ * @param $value
158
+ */
159
+ function set_timezone($value = "") {
160
+ if(!empty($value))
161
+ $this->timezone = $value;
162
+ }
163
+
164
+ /**
165
+ * Overrides the default ini method and sets automatically
166
+ * SimplePie_Item_GCalendar as item class.
167
+ * It also sets the variables specified in this feed as query
168
+ * parameters.
169
+ */
170
+ function init(){
171
+ $this->set_item_class('SimplePie_Item_GCalendar');
172
+
173
+ $new_url;
174
+ if (!empty($this->multifeed_url)){
175
+ $tmp = array();
176
+ foreach ($this->multifeed_url as $value)
177
+ $tmp[] = $this->check_url($value);
178
+ $new_url = $tmp;
179
+ }else{
180
+ $new_url = $this->check_url($this->feed_url);
181
+ }
182
+ $this->set_feed_url($new_url);
183
+
184
+ parent::init();
185
+ }
186
+
187
+ /**
188
+ * Creates an url depending on the variables $show_past_events, etc.
189
+ * and returns a valid google calendar feed url.
190
+ */
191
+ function check_url($url_to_check){
192
+ $new_url = parse_url($url_to_check);
193
+ $path = $new_url['path'];
194
+ $path = substr($path, 0, strrpos($path, '/')+1).$this->projection;
195
+ $query = '';
196
+ if(isset($new_url['query'])){
197
+ $query = $new_url['query'];
198
+ }
199
+ $tmp = $new_url['scheme'].'://'.$new_url['host'].$path.'?'.$query;
200
+ if(!empty($new_url['query']))
201
+ $tmp = $this->append($tmp,'&');
202
+ if($this->start_date==null && $this->end_date==null){
203
+ if($this->show_past_events )
204
+ $tmp = $this->append($tmp,'futureevents=false&');
205
+ else
206
+ $tmp = $this->append($tmp,'futureevents=true&');
207
+ }
208
+ if($this->start_date!=null){
209
+ $tmp = $this->append($tmp,'start-min='.$this->start_date.'&');
210
+ }
211
+ if( $this->end_date!=null){
212
+ $tmp = $this->append($tmp,'start-max='.$this->end_date.'&');
213
+ }
214
+ if($this->sort_ascending)
215
+ $tmp = $this->append($tmp,'sortorder=ascending&');
216
+ else
217
+ $tmp = $this->append($tmp,'sortorder=descending&');
218
+ if($this->orderby_by_start_date)
219
+ $tmp = $this->append($tmp,'orderby=starttime&');
220
+ else
221
+ $tmp = $this->append($tmp,'orderby=lastmodified&');
222
+ if($this->expand_single_events)
223
+ $tmp = $this->append($tmp,'singleevents=true&');
224
+ else
225
+ $tmp = $this->append($tmp,'singleevents=false&');
226
+ if(!empty($this->cal_language))
227
+ $tmp = $this->append($tmp,'hl='.$this->cal_language.'&');
228
+ if(!empty($this->cal_query))
229
+ $tmp = $this->append($tmp,'q='.urlencode($this->cal_query).'&');
230
+ if(!empty($this->timezone))
231
+ $tmp = $this->append($tmp,'ctz='.$this->timezone.'&');
232
+ $tmp = $this->append($tmp,'max-results='.$this->max_events);
233
+
234
+ return $tmp;
235
+ }
236
+
237
+ /**
238
+ * Internal helper method to append a string to an other one.
239
+ */
240
+ function append($value, $appendix){
241
+ $pos = strpos($value,$appendix);
242
+ if($pos === FALSE)
243
+ $value .= $appendix;
244
+ return $value;
245
+ }
246
+
247
+ /**
248
+ * Returns the timezone of the feed.
249
+ */
250
+ function get_timezone(){
251
+ $tzvalue = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_GOOGLE_CALENDAR_FEED, 'timezone');
252
+ return $tzvalue[0]['attribs']['']['value'];
253
+ }
254
+
255
+ /**
256
+ * Sets the given value for the given key which is accessible in the get(...) method.
257
+ * @param $key
258
+ * @param $value
259
+ */
260
+ function put($key, $value){
261
+ $this->meta_data[$key] = $value;
262
+ }
263
+
264
+ /**
265
+ * Returns the value for the given key which is set in the set(...) method.
266
+ * @param $key
267
+ * @return the value
268
+ */
269
+ function get($key){
270
+ return $this->meta_data[$key];
271
+ }
272
+
273
+ /**
274
+ * Creates a valid feed url for the given email address.
275
+ * If the magic cookie parameter is set it will return the private feed url.
276
+ */
277
+ function create_feed_url($email_address, $magic_cookie = null){
278
+ $type = 'public';
279
+ if($magic_cookie != null)
280
+ $type = 'private-'.$magic_cookie;
281
+
282
+ return 'http://www.google.com/calendar/feeds/'.$email_address.'/'.$type.'/full';
283
+ }
284
+ }
285
+
286
+ /**
287
+ * The GCalendar Item which provides more google calendar specific
288
+ * functions like the location of the event, etc.
289
+ */
290
+ class SimplePie_Item_GCalendar extends SimplePie_Item {
291
+
292
+ // static variables used as return value for get_day_type()
293
+ var $SINGLE_WHOLE_DAY = 1;
294
+ var $SINGLE_PART_DAY = 2;
295
+ var $MULTIPLE_WHOLE_DAY = 3;
296
+ var $MULTIPLE_PART_DAY = 4;
297
+
298
+ //internal cache variables
299
+ var $gc_id;
300
+ var $gc_pub_date;
301
+ var $gc_location;
302
+ var $gc_status;
303
+ var $gc_start_date;
304
+ var $gc_end_date;
305
+ var $gc_day_type;
306
+
307
+ /**
308
+ * Returns the id of the event.
309
+ *
310
+ * @return the id of the event
311
+ */
312
+ function get_id(){
313
+ if(!$this->gc_id){
314
+ $this->gc_id = substr($this->get_link(),strpos(strtolower($this->get_link()),'eid=')+4);
315
+ }
316
+ return $this->gc_id;
317
+ }
318
+
319
+ /**
320
+ * Returns the publish date as unix timestamp of the event.
321
+ *
322
+ * @return the publish date of the event
323
+ */
324
+ function get_publish_date(){
325
+ if(!$this->gc_pub_date){
326
+ $pubdate = $this->get_date('Y-m-d\TH:i:s\Z');
327
+ $this->gc_pub_date = SimplePie_Item_GCalendar::tstamptotime($pubdate);
328
+ }
329
+ return $this->gc_pub_date;
330
+ }
331
+
332
+ /**
333
+ * Returns the location of the event.
334
+ *
335
+ * @return the location of the event
336
+ */
337
+ function get_location(){
338
+ if(!$this->gc_location){
339
+ $gd_where = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GOOGLE_CALENDAR_ITEM, 'where');
340
+ if(isset($gd_where[0]) &&
341
+ isset($gd_where[0]['attribs']) &&
342
+ isset($gd_where[0]['attribs']['']) &&
343
+ isset($gd_where[0]['attribs']['']['valueString']))
344
+ $this->gc_location = $gd_where[0]['attribs']['']['valueString'];
345
+ }
346
+ return $this->gc_location;
347
+ }
348
+
349
+ /**
350
+ * Returns the status of the event.
351
+ *
352
+ * @return the status of the event
353
+ */
354
+ function get_status(){
355
+ if(!$this->gc_status){
356
+ $gd_where = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GOOGLE_CALENDAR_ITEM, 'eventStatus');
357
+ $this->gc_status = substr( $gd_status[0]['attribs']['']['value'], -8);
358
+ }
359
+ return $this->gc_status;
360
+ }
361
+
362
+ /**
363
+ * If the given format (must match the criterias of strftime)
364
+ * is not null a string is returned otherwise a unix timestamp.
365
+ *
366
+ * @see http://www.php.net/mktime
367
+ * @see http://www.php.net/strftime
368
+ * @param $format
369
+ * @return the start date of the event
370
+ */
371
+ function get_start_date($format = null){
372
+ if(!$this->gc_start_date){
373
+ $when = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GOOGLE_CALENDAR_ITEM, 'when');
374
+ $startdate = $when[0]['attribs']['']['startTime'];
375
+ $this->gc_start_date = SimplePie_Item_GCalendar::tstamptotime($startdate);
376
+ }
377
+ if($format != null)
378
+ return strftime($format, $this->gc_start_date);
379
+ return $this->gc_start_date;
380
+ }
381
+
382
+ /**
383
+ * If the given format (must match the criterias of strftime)
384
+ * is not null a string is returned otherwise a unix timestamp.
385
+ *
386
+ * @see http://www.php.net/mktime
387
+ * @see http://www.php.net/strftime
388
+ * @param $format
389
+ * @return the end date of the event
390
+ */
391
+ function get_end_date($format = null){
392
+ if(!$this->gc_end_date){
393
+ $when = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GOOGLE_CALENDAR_ITEM, 'when');
394
+ $enddate = $when[0]['attribs']['']['endTime'];
395
+ $this->gc_end_date = SimplePie_Item_GCalendar::tstamptotime($enddate);
396
+ }
397
+ if($format != null)
398
+ return strftime($format, $this->gc_end_date);
399
+ return $this->gc_end_date;
400
+ }
401
+
402
+ /**
403
+ * Returns the event type. One of the following constants:
404
+ * - SINGLE_WHOLE_DAY
405
+ * - SINGLE_PART_DAY
406
+ * - MULTIPLE_WHOLE_DAY
407
+ * - MULTIPLE_PART_DAY
408
+ *
409
+ * @return the event type
410
+ */
411
+ function get_day_type(){
412
+ if(!$this->gc_day_type){
413
+ $SECSINDAY=86400;
414
+
415
+ if (($this->get_start_date()+ $SECSINDAY) <= $this->get_end_date()) {
416
+ if (($this->get_start_date()+ $SECSINDAY) == $this->get_end_date()) {
417
+ $this->gc_day_type = $this->SINGLE_WHOLE_DAY;
418
+ } else {
419
+ if ((date('g:i a',$this->get_start_date())=='12:00 am')&&(date('g:i a',$this->get_end_date())=='12:00 am')){
420
+ $this->gc_day_type = $this->MULTIPLE_WHOLE_DAY;
421
+ }else{
422
+ $this->gc_day_type = $this->MULTIPLE_PART_DAY;
423
+ }
424
+ }
425
+ }else
426
+ $this->gc_day_type = $this->SINGLE_PART_DAY;
427
+ }
428
+ return $this->gc_day_type;
429
+ }
430
+
431
+ /**
432
+ * Returns a unix timestamp of the given iso date.
433
+ *
434
+ * @param $iso_date
435
+ * @return unix timestamp
436
+ */
437
+ function tstamptotime($iso_date) {
438
+ // converts ISODATE to unix date
439
+ // 1984-09-01T14:21:31Z
440
+ sscanf($iso_date,"%u-%u-%uT%u:%u:%uZ",$year,$month,$day,$hour,$min,$sec);
441
+ $newtstamp = mktime($hour,$min,$sec,$month,$day,$year);
442
+ return $newtstamp;
443
+ }
444
+
445
+ /**
446
+ * Returns an integer less than, equal to, or greater than zero if
447
+ * the first argument is considered to be respectively less than,
448
+ * equal to, or greater than the second.
449
+ * This function can be used to sort an array of SimplePie_Item_GCalendar
450
+ * items with usort.
451
+ *
452
+ * @see http://www.php.net/usort
453
+ * @param $gc_sp_item1
454
+ * @param $gc_sp_item2
455
+ * @return the comparison integer
456
+ */
457
+ function compare($gc_sp_item1, $gc_sp_item2){
458
+ $time1 = $gc_sp_item1->get_start_date();
459
+ $time2 = $gc_sp_item2->get_start_date();
460
+ $feed = $gc_sp_item1->get_feed();
461
+ if(!$feed->orderby_by_start_date){
462
+ $time1 = $gc_sp_item1->get_publish_date();
463
+ $time2 = $gc_sp_item2->get_publish_date();
464
+ }
465
+ return $time1-$time2;
466
+ }
467
+ }
468
+ ?>
js/gce-tooltip-script.js ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function gce_simple_tooltip(target_items){
2
+ if(jQuery('#gce-tooltip').html() == null){
3
+ //Appends a div, which will be used as the tooltip
4
+ jQuery('body').append('<div id="gce-tooltip"></div>');
5
+ };
6
+
7
+ jQuery(target_items).each(function(){
8
+ //Reference to div appended above
9
+ var my_tooltip = jQuery('#gce-tooltip');
10
+
11
+ //On mouse over
12
+ jQuery(this).mouseover(function(){
13
+ //Sets the tooltip to the correct information for the day (hidden in <td>)
14
+ my_tooltip.html(jQuery(this).children('div').html());
15
+ //Shows the tooltip
16
+ my_tooltip.show();
17
+ //On mouse move
18
+ }).mousemove(function(kmouse){
19
+ //All this stuff prevents tooltip going out of viewport
20
+ var border_top = jQuery(window).scrollTop();
21
+ var border_right = jQuery(window).width();
22
+ var left_pos;
23
+ var top_pos;
24
+ var offset = 5; //Offset from mouse pointer
25
+
26
+ if(border_right - (offset * 2) >= my_tooltip.width() + kmouse.pageX){
27
+ left_pos = kmouse.pageX + offset;
28
+ }else{
29
+ left_pos = border_right - my_tooltip.width() - offset;
30
+ }
31
+
32
+ if(border_top + (offset * 2) >= kmouse.pageY - my_tooltip.height()){
33
+ top_pos = border_top + offset;
34
+ }else{
35
+ top_pos = kmouse.pageY - my_tooltip.height() - offset;
36
+ }
37
+
38
+ my_tooltip.css({left:left_pos, top:top_pos});
39
+ //On mouse out
40
+ }).mouseout(function(){
41
+ //Hide the tooltip
42
+ my_tooltip.hide();
43
+ });
44
+ });
45
+ }
46
+
47
+ function gce_ajaxify(target, feed_id, type){
48
+ //Add click event to change month links
49
+ jQuery('#' + target + ' .gce-change-month').click(function(){
50
+ //Extract month and year
51
+ var month_year = jQuery(this).attr('name').split('-', 2);
52
+ //Add loading text to table caption
53
+ jQuery('#' + target + ' caption').html('Loading...');
54
+ //Send AJAX request
55
+ jQuery.get('index.php', {gce_type:type, gce_feed_id:feed_id, gce_widget_id:target, gce_month:month_year[0], gce_year:month_year[1]}, function(data){
56
+ //Replace existing data with returned AJAX data
57
+ if(type == 'widget'){
58
+ jQuery('#' + target).children('.gce-widget-grid').html(data);
59
+ gce_simple_tooltip('.widget_gce_widget .gce-has-events');
60
+ }else{
61
+ jQuery('#' + target).replaceWith(data);
62
+ gce_simple_tooltip('.gce-page-grid .gce-has-events');
63
+ }
64
+ });
65
+ });
66
+ }
67
+
68
+ jQuery(document).ready(function(){
69
+ gce_simple_tooltip('.widget_gce_widget .gce-has-events');
70
+ gce_simple_tooltip('.gce-page-grid .gce-has-events');
71
+ });
readme.txt ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Google Calendar Events ===
2
+ Contributors: rosshanney
3
+ Tags: google, google calendar, calendar, events, ajax, widget
4
+ Requires at least: 2.9.2
5
+ Tested up to: 3.0
6
+ Stable tag: 0.1
7
+
8
+ Parses Google Calendar feeds and displays the events as a calendar grid or list on a page, post or widget.
9
+
10
+ == Description ==
11
+
12
+ Parses Google Calendar feeds and displays the events as a calendar grid or list on a page, post or widget.
13
+
14
+ = Features =
15
+
16
+ * Parses Google Calendar feeds to extract events
17
+ * Displays events as a list or within a calendar grid
18
+ * Lists and grids can be displayed in posts, pages or within a widget
19
+ * Options to change the number of events retrieved, date / time format, cache duration etc.
20
+ * Calendar grids can have the ability to change month, utilising AJAX
21
+
22
+ Please visit the plugin homepage for how to get started and help:
23
+
24
+ * [plugin homepage](http://www.rhanney.co.uk/plugins/google-calendar-events)
25
+
26
+ == Installation ==
27
+
28
+ Use the automatic installer from within the WordPress administration, or:
29
+
30
+ 1. Unzip the `google-calendar-events.zip` file
31
+ 1. Upload the `google-calendar-events` folder to your `plugins` directory
32
+ 1. Go to the Plugins page from within the WordPress administration
33
+ 1. Click Activate for Google Calendar Events
34
+
35
+ After activation a new Google Calendar Events options menu will appear under Settings.
36
+
37
+ You can now start adding feeds. Visit the [plugin homepage](http://www.rhanney.co.uk/plugins/google-calendar-events) for a more in-depth guide on getting started.
38
+
39
+ == Changelog ==
40
+
41
+ = 0.1 =
42
+ Initial release.
43
+
44
+ == Frequently Asked Questions ==
45
+
46
+ Please visit the [plugin homepage](http://www.rhanney.co.uk/plugins/google-calendar-events) and leave a comment for help, or [contact me](http://www.rhanney.co.uk/contact) directly.
widget/gce-widget.php ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once WP_PLUGIN_DIR . '/' . GCE_PLUGIN_NAME . '/inc/gce-parser.php';
3
+
4
+ class GCE_Widget extends WP_Widget{
5
+ function GCE_Widget(){
6
+ parent::WP_Widget(false, $name = 'Google Calendar Events', array('description' => 'Display a list or calendar grid of events from a Google Calendar feed you have added'));
7
+ }
8
+
9
+ function widget($args, $instance){
10
+ extract($args);
11
+
12
+ //Get saved feed options
13
+ $options = get_option(GCE_OPTIONS_NAME);
14
+
15
+ //Output before widget and widget title stuff
16
+ echo $before_widget;
17
+ echo $before_title . $options[$instance['id']]['title'] . $after_title;
18
+
19
+ //Output correct widget content based on display type chosen
20
+ switch($instance['display_type']){
21
+ case 'grid':
22
+ echo '<div class="gce-widget-grid">';
23
+ //Output main widget content as grid (no AJAX)
24
+ gce_widget_content_grid($instance['id'], $args['widget_id']);
25
+ break;
26
+ case 'ajax':
27
+ echo '<div class="gce-widget-grid">';
28
+ //Output main widget content as grid (with AJAX)
29
+ gce_widget_content_grid($instance['id'], $args['widget_id'], true);
30
+ break;
31
+ case 'list':
32
+ echo '<div class="gce-widget-list">';
33
+ //Output main widget content as list
34
+ gce_widget_content_list($instance['id']);
35
+ break;
36
+ }
37
+
38
+ echo '</div>';
39
+
40
+ //Output after widget stuff
41
+ echo $after_widget;
42
+ }
43
+
44
+ function update($new_instance, $old_instance){
45
+ $instance = $old_instance;
46
+ $instance['id'] = $new_instance['id'];
47
+ $instance['display_type'] = $new_instance['display_type'];
48
+ return $instance;
49
+ }
50
+
51
+ function form($instance){
52
+ //Get saved feed options
53
+ $options = get_option(GCE_OPTIONS_NAME);
54
+
55
+ if(empty($options)){
56
+ //If no feeds ?>
57
+ <p><?php _e('No feeds have been added yet. You can add a feed in the Google Calendar Events settings.', GCE_TEXT_DOMAIN); ?></p>
58
+ <?php
59
+ }else{
60
+ //If there are feeds, select a feed ?>
61
+ <p>
62
+ <label for="<?php echo $this->get_field_id('id'); ?>"><?php _e('Select a Feed to Use:', GCE_TEXT_DOMAIN); ?></label>
63
+ <select id="<?php echo $this->get_field_id('id'); ?>" name="<?php echo $this->get_field_name('id'); ?>" class="widefat">
64
+ <?php foreach($options as $key => $feed){ ?>
65
+ <option value="<?php echo $key; ?>"<?php selected($instance['id'], $key);?>><?php echo $key . ' - ' . $feed['title']; ?></option>
66
+ <?php } ?>
67
+ </select>
68
+ </p>
69
+ <?php //Display type (grid / ajax / list) ?>
70
+ <p>
71
+ <label for="<?php echo $this->get_field_id('display_type'); ?>"><?php _e('Display as:', GCE_TEXT_DOMAIN); ?></label>
72
+ <select id="<?php echo $this->get_field_id('display_type'); ?>" name="<?php echo $this->get_field_name('display_type'); ?>" class="widefat">
73
+ <option value="grid"<?php selected($instance['display_type'], 'grid');?>><?php _e('Calendar Grid', GCE_TEXT_DOMAIN); ?></option>
74
+ <option value="ajax"<?php selected($instance['display_type'], 'ajax');?>><?php _e('Calendar Grid - with AJAX', GCE_TEXT_DOMAIN); ?></option>
75
+ <option value="list"<?php selected($instance['display_type'], 'list');?>><?php _e('List', GCE_TEXT_DOMAIN); ?></option>
76
+ </select>
77
+ </p>
78
+ <?php
79
+ }
80
+ }
81
+ }
82
+
83
+ //Outputs the main widget content as a calendar grid
84
+ function gce_widget_content_grid($feed_id, $widget_id, $ajaxified = false, $month = null, $year = null){
85
+ //Get saved feed options
86
+ $options = get_option('gce_options');
87
+
88
+ //Set time and date formats to WordPress defaults if not set by user
89
+ $df = $options[$feed_id]['date_format'];
90
+ $tf = $options[$feed_id]['time_format'];
91
+ if($df == '') $df = get_option('date_format');
92
+ if($tf == '') $tf = get_option('time_format');
93
+
94
+ //Creates a new GCE_Parser object for $feed_id
95
+ $widget_feed_data = new GCE_Parser(
96
+ $options[$feed_id]['url'],
97
+ $options[$feed_id]['show_past_events'],
98
+ $options[$feed_id]['max_events'],
99
+ $options[$feed_id]['cache_duration'],
100
+ $df,
101
+ $tf,
102
+ get_option('start_of_week')
103
+ );
104
+
105
+ //Check that feed parsed ok
106
+ if($widget_feed_data->parsed_ok()){
107
+ //Only add AJAX script if AJAX grid is enabled
108
+ if($ajaxified){
109
+ ?><script type="text/javascript">jQuery(document).ready(function($){gce_ajaxify("<?php echo $widget_id; ?>", "<?php echo $feed_id; ?>", "widget");});</script><?php
110
+ }
111
+
112
+ //Outputs calendar grid for specified month and year
113
+ echo $widget_feed_data->get_grid($year, $month, $ajaxified);
114
+ }else{
115
+ echo 'The Google Calendar feed was not parsed successfully, please check that the feed URL is correct.';
116
+ }
117
+ }
118
+
119
+ //Outputs the main widget content as a list of events
120
+ function gce_widget_content_list($id){
121
+ //Get saved feed options
122
+ $options = get_option(GCE_OPTIONS_NAME);
123
+
124
+ //Set time and date formats to WordPress defaults if not set by user
125
+ $df = $options[$id]['date_format'];
126
+ $tf = $gce_options[$id]['time_format'];
127
+ if($df == '') $df = get_option('date_format');
128
+ if($tf == '') $tf = get_option('time_format');
129
+
130
+ //Creates a new GCE_Parser object for $feed_id
131
+ $widget_feed_data = new GCE_Parser(
132
+ $options[$id]['url'],
133
+ $options[$id]['show_past_events'],
134
+ $options[$id]['max_events'],
135
+ $options[$id]['cache_duration'],
136
+ $df,
137
+ $tf
138
+ );
139
+
140
+ //Check that feed parsed ok
141
+ if($widget_feed_data->parsed_ok()){
142
+ echo $widget_feed_data->get_list();
143
+ }else{
144
+ echo 'The Google Calendar feed was not parsed successfully, please check that the feed URL is correct.';
145
+ }
146
+ }
147
+
148
+ //AJAX stuff. Passes the data from JavaScript to above gce_widget_content_grid function
149
+ if($_GET['gce_type'] == 'widget'){
150
+ if(isset($_GET['gce_feed_id'])){
151
+ gce_widget_content_grid($_GET['gce_feed_id'], $_GET['gce_widget_id'], true, $_GET['gce_month'], $_GET['gce_year']);
152
+ die();
153
+ }
154
+ }
155
+ ?>