-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrsvpmaker-ical.php
136 lines (86 loc) · 3.08 KB
/
rsvpmaker-ical.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
function rsvpmaker_to_ical_email( $post_id = 0, $from_email = '', $rsvp_email ='', $description = '', $rsvp_id=0 ) {
global $post;
$backslash = '\\';
global $rsvp_options;
if(!$post_id)
return;
if ( $post_id > 0 ) {
$post = get_post( $post_id );
}
global $wpdb;
if ( ( $post->post_type != 'rsvpmaker' ) ) {
return;
}
$event = get_rsvpmaker_event( $post_id );
if($rsvp_id) {
$receipt_code = get_post_meta($event->ID,'rsvpmaker_receipt_'.$rsvp_id,true);
if(!$receipt_code) {
$receipt_code = wp_generate_password(20,false,false);
update_post_meta($event->ID,'rsvpmaker_receipt_'.$rsvp_id,$receipt_code);
}
$rsvp_receipt_link = add_query_arg(array('rsvp_receipt'=>$rsvp_id,'receipt'=>$receipt_code,'t'=>time()),get_permalink($event->ID));
$description = "See receipt ".$rsvp_receipt_link;
}
if ( ! empty( $hangout ) ) {
$description .= 'Google Hangout: ' . $hangout . "\n";
}
if(empty($description))
$description .= 'Event info: ' . get_permalink( $post->ID );
$summary = $post->post_title;
$venue_meta = get_post_meta( $post->ID, 'venue', true );
$venue = ( empty( $venue_meta ) ) ? 'See: ' . get_permalink( $post->ID ) : $venue_meta;
$dtstamp = gmdate( 'Ymd' ) . 'T' . gmdate( 'His' ) . 'Z';
$start = gmdate( 'Ymd', $event->ts_start );
$start_time = gmdate( 'His', $event->ts_start );
$end = gmdate( 'Ymd', $event->ts_end );
$end_time = gmdate( 'His', $event->ts_end );
$event_id = $post->ID;
$sequence = 0;
$status = 'CONFIRMED';
$ical[] = 'BEGIN:VCALENDAR';
$ical[] = 'VERSION:2.0';
$ical[] = 'CALSCALE:GREGORIAN';
$ical[] = 'PRODID:-//WordPress//RSVPMaker//EN';
$ical[] = 'METHOD:REQUEST';
$ical[] = 'BEGIN:VEVENT';
$ical[] = 'DTSTAMP:' . $dtstamp;
if($from_email)
$ical[] = 'ORGANIZER;SENT-BY="MAILTO:' . $from_email . '":MAILTO:' . $from_email;
//$ical[] = 'ORGANIZER;CN=' . get_bloginfo('name') . '":MAILTO:' . $from_email;
if($rsvp_email)
$ical[] = 'ATTENDEE;CN=' . $rsvp_email . ';ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;' . 'RSVP=TRUE:mailto:' . $from_email;
$ical[] = 'UID:' . strtoupper( md5( $event_id ) ) . '@rsvpmaker.com';
$ical[] = 'SEQUENCE:' . $sequence;
$ical[] = 'STATUS:' . $status;
$ical[] = 'DTSTART:' . $start . 'T' . $start_time . 'Z';
$ical[] = 'DTEND:' . $end . 'T' . $end_time . 'Z';
$ical[] = 'LOCATION:' . rsvpmaker_ical_escape($venue);
$ical[] = 'SUMMARY:' . $summary;
$ical[] = 'DESCRIPTION:' . rsvpmaker_ical_escape($description);
/*
$ical[] = 'BEGIN:VALARM';
$ical[] = 'TRIGGER:-PT15M';
$ical[] = 'ACTION:DISPLAY';
$ical[] = 'END:VALARM';
*/
$ical[] = 'END:VEVENT';
$ical[] = 'END:VCALENDAR';
$icalstring = '';
foreach ( $ical as $line ) {
if ( strlen( $line ) >= 70 ) {
$line = trim( chunk_split( $line, 70, "\r\n" ) );
$line = str_replace("\n","\n ",$line);
}
$icalstring .= $line . "\r\n";
}
return trim( $icalstring );
}
function rsvpmaker_ical_escape($text) {
$text = addslashes($text);
$text = str_replace(':','\:',$text);
$text = str_replace(';','\;',$text);
$text = str_replace(',','\,',$text);
$text = str_replace("\n","\\n",$text);
return $text;
}