-
Notifications
You must be signed in to change notification settings - Fork 1
/
gcalendar-wrapper-tsubaki.php
389 lines (341 loc) · 10.4 KB
/
gcalendar-wrapper-tsubaki.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<?php
/**
* Embedded Google Calendar customization wrapper script
*
* Applies a custom color scheme to an embedded Google Calendar.
*
* Usage:
*
* Replace standard Google Calendar embedding code, e.g.:
*
* <iframe src="http://www.google.com/calendar/embed?src=..."></iframe>
*
* with a reference to this script:
*
* <iframe src="gcalendar-wrapper.php?src=..."></iframe>
*
* @author Chris Dornfeld <dornfeld (at) unitz.com>
* @version $Id: gcalendar-wrapper.php 1571 2010-11-15 07:08:05Z dornfeld $
* @link http://www.unitz.com/gcalendar-wrapper/
*/
/**
* Set your color scheme below
*/
$calColorBgDark = '#C5C5C5'; // dark background color
$calColorTextOnDark = '#000000'; // text appearing on top of dark bg color
$calColorBgLight = '#eeeeee'; // light background color
$calColorTextOnLight = '#000000'; // text appearing on top of light bg color
$calColorBgToday = '#ffffcc'; // background color for "today" box
define('GOOGLE_CALENDAR_BASE', 'https://www.google.com/');
define('GOOGLE_CALENDAR_EMBED_URL', GOOGLE_CALENDAR_BASE . 'calendar/embed');
/**
* Prepare stylesheet customizations
*/
$calCustomStyle =<<<EOT
/* misc interface */
.cc-titlebar {
background-color: {$calColorBgLight} !important;
}
.date-picker-arrow-on,
.drag-lasso,
.agenda-scrollboxBoundary {
background-color: {$calColorBgDark} !important;
}
td#timezone {
color: {$calColorTextOnDark} !important;
}
/* tabs */
td#calendarTabs1 div.ui-rtsr-selected,
div.view-cap,
div.view-container-border {
background-color: {$calColorBgDark} !important;
}
td#calendarTabs1 div.ui-rtsr-selected {
color: {$calColorTextOnDark} !important;
}
td#calendarTabs1 div.ui-rtsr-unselected {
background-color: {$calColorBgLight} !important;
color: {$calColorTextOnLight} !important;
}
/* week view */
table.wk-weektop,
th.wk-dummyth {
/* days of the week */
background-color: {$calColorBgDark} !important;
}
div.wk-dayname {
color: {$calColorTextOnDark} !important;
}
div.wk-today {
background-color: {$calColorBgLight} !important;
border: 1px solid #EEEEEE !important;
color: {$calColorTextOnLight} !important;
}
td.wk-allday {
background-color: #EEEEEE !important;
}
td.tg-times {
background-color: {$calColorBgLight} !important;
color: {$calColorTextOnLight} !important;
}
div.tg-today {
background-color: {$calColorBgToday} !important;
}
/* month view */
table.mv-daynames-table {
background-color: {$calColorBgDark} !important;
/* days of the week */
color: {$calColorTextOnDark} !important;
}
td.st-bg,
td.st-dtitle {
/* cell borders */
border-left: 1px solid {$calColorBgDark} !important;
}
td.st-dtitle {
/* days of the month */
background-color: {$calColorBgLight} !important;
color: {$calColorTextOnLight} !important;
/* cell borders */
border-top: 1px solid {$calColorBgDark} !important;
}
td.st-bg-today {
background-color: {$calColorBgToday} !important;
}
/* agenda view */
div.scrollbox {
border-top: 1px solid {$calColorBgDark} !important;
border-left: 1px solid {$calColorBgDark} !important;
}
div.underflow-top {
border-bottom: 1px solid {$calColorBgDark} !important;
}
div.date-label {
background-color: {$calColorBgLight} !important;
color: {$calColorTextOnLight} !important;
}
div.event {
border-top: 1px solid {$calColorBgDark} !important;
}
div.day {
border-bottom: 1px solid {$calColorBgDark} !important;
}
/* ボディ */
body { background-color:transparent !important; }
/*カレンダー*/
.mv-event-container {
border-top: 1px solid #41A587;
border-bottom: 1px solid #41A587; }
td.st-bg-today { background-color:inherit; }
.t2-embed { margin: 0px; }
.t1-embed { margin: 0px; }
.rb-n { -webkit-border-radius: 0px; } /*終日イベント*/
.view-container { overflow:visible !important; }
/*ボタン*/
.bubble-closebutton,
.cc-close,
.navForward,
.navBack { background-image: url(http://curioustander.com/vocalendar/images/combined_v22.png); }
.navbutton { padding: 0px; }
.today-button {
border: none;
color: #41A587;
cursor: pointer;
margin: 0;
padding: 0px 5px;
background-color: #C3EEE4; }
/*タブ
.nav-table tr {
height: 28px;
}
#calendarTabs1 {
display: block;
position: absolute;
right: 121px; top: -2px;
padding-left: 10px; }
#calendarTabs1 tr td {
height: 28px;}
.header { padding: 0px; }
.ui-rtsr-name { cursor: pointer; }
td#calendarTabs1 div.ui-rtsr-unselected,
td#calendarTabs1 div.ui-rtsr-selected {
height: 20px; }
.t1-embed, .t2-embed {
height: 1px !important; }
*/
.ui-rtsr { padding-left: 1px; }
/*ポップアップカレンダー*/
.date-picker-on { border: 1px solid #C3EEE4;}
.dp-popup { background-color: #C3EEE4; }
.dp-weekend-selected { background-color: #C3EEE4; }
.dp-weekday-selected { background-color: #C3EEE4; }
.dp-popup { border: none; box-shadow: 0px 0px 20px #666666; }
/*ポップアップイベントリスト*/
.cc { box-shadow: 0px 0px 20px #666666; border: 1px solid #ababab; }
/*ポップアップイベント*/
.bubble-sprite { background-image: url(http://curioustander.com/vocalendar/images/bubble_combined_v2.png); }
.bubble-table { box-shadow: 0px 0px 20px #666666; }
/*テキスト*/
.rb-n,
.te-s { font-size: 11px; letter-spacing: -1px; }
th.mv-dayname { color: #666666; }
.dp-cur, .dp-prev, .dp-next { color:#41A587; }
/* リンク */
.agenda-more,
.st-more { color: #41A587; }
/* カレンダーセレクタ */
.calendar-nav {
display: block;
position: absolute;
right: 140px; top: 0px;
padding-top: 5px;
text-align: right; }
.calendar-list {
box-shadow: 0px 0px 20px #666666;
border: 1px solid #ababab;
padding: 10px; }
.calendar-row {
padding: 2px 0px; }
.calendar-list input {
margin-right: 1em; }
#calendarListButton1 {
margin-top: -3px; }
/*
.calendar-nav:before {
font-size: 12px;
color: black;
content: "表示切り替え";
margin-right: 5px; }
*/
EOT;
$calCustomScript =<<<EOT
<script src="http://www.google.com/jsapi"></script>
<script>google.load("jquery", "1.7.0");</script>
<script type="text/javascript">
<!-- Google Analytics //-->
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-28637999-1']);
_gaq.push(['_setDomainName', 'vocalendar.jp']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
jQuery(function() {
/* click tracking google ana */
jQuery(".subscribe-image").click(function(e) {
_gaq.push(['_trackEvent', 'gcal', 'subscribe']);
});
});
</script>
EOT;
$calCustomStyle = '<style type="text/css">'.$calCustomStyle.'</style>';
$calCustomStyle .= $calCustomScript;
/**
* Construct calendar URL
*/
$calQuery = '';
if (isset($_SERVER['QUERY_STRING'])) {
$calQuery = $_SERVER['QUERY_STRING'];
} else if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$calQuery = $HTTP_SERVER_VARS['QUERY_STRING'];
}
$calUrl = GOOGLE_CALENDAR_EMBED_URL.'?'.$calQuery;
/**
* Retrieve calendar embedding code
*/
$calRaw = '';
if (in_array('curl', get_loaded_extensions())) {
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, $calUrl);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
// trust any SSL certificate (we're only retrieving public data)
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYHOST, FALSE);
if (function_exists('curl_version')) {
$curlVer = curl_version();
if (is_array($curlVer)) {
if (!in_array('https', $curlVer['protocols'])) {
trigger_error("Can't use https protocol with cURL to retrieve Google Calendar", E_USER_ERROR);
}
if (!empty($curlVer['version']) &&
version_compare($curlVer['version'], '7.15.2', '>=') &&
!ini_get('open_basedir') && !ini_get('safe_mode')) {
// enable HTTP redirect following for cURL:
// - CURLOPT_FOLLOWLOCATION is disabled when PHP is in safe mode
// - cURL versions before 7.15.2 had a bug that lumped
// redirected page content with HTTP headers
// http://simplepie.org/support/viewtopic.php?id=1004
curl_setopt($curlObj, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curlObj, CURLOPT_MAXREDIRS, 5);
}
}
}
$calRaw = curl_exec($curlObj);
curl_close($curlObj);
} else if (ini_get('allow_url_fopen')) {
if (function_exists('stream_get_wrappers')) {
if (!in_array('https', stream_get_wrappers())) {
trigger_error("Can't use https protocol with fopen to retrieve Google Calendar", E_USER_ERROR);
}
} else if (!in_array('openssl', get_loaded_extensions())) {
trigger_error("Can't use https protocol with fopen to retrieve Google Calendar", E_USER_ERROR);
}
// fopen should follow HTTP redirects in recent versions
$fp = fopen($calUrl, 'r');
while (!feof($fp)) {
$calRaw .= fread($fp, 8192);
}
fclose($fp);
} else {
trigger_error("Can't use cURL or fopen to retrieve Google Calendar", E_USER_ERROR);
}
/**
* Insert BASE tag to accommodate relative paths
*/
$titleTag = '<title>';
$baseTag = '<base href="'.GOOGLE_CALENDAR_EMBED_URL.'">';
$calCustomized = preg_replace("/".preg_quote($titleTag,'/')."/i", $baseTag.$titleTag, $calRaw);
/**
* Insert custom styles
*/
$headEndTag = '</head>';
$calCustomized = preg_replace("/".preg_quote($headEndTag,'/')."/i", $calCustomStyle.$headEndTag, $calCustomized);
/**
* Extract and modify calendar setup data
*/
$calSettingsPattern = "(\{\s*window\._init\(\s*)(\{.+\})(\s*\)\;\s*\})";
if (preg_match("/$calSettingsPattern/", $calCustomized, $matches)) {
$calSettingsJson = $matches[2];
$pearJson = null;
if (!function_exists('json_encode')) {
// no built-in JSON support, attempt to use PEAR::Services_JSON library
if (!class_exists('Services_JSON')) {
require_once('Services/JSON.php');
}
$pearJson = new Services_JSON();
}
if (function_exists('json_decode')) {
$calSettings = json_decode($calSettingsJson);
} else {
$calSettings = $pearJson->decode($calSettingsJson);
}
// set base URL to accommodate relative paths
$calSettings->baseUrl = GOOGLE_CALENDAR_BASE;
// splice in updated calendar setup data
if (function_exists('json_encode')) {
$calSettingsJson = json_encode($calSettings);
} else {
$calSettingsJson = $pearJson->encode($calSettings);
}
// prevent unwanted variable substitutions within JSON data
// preg_quote() results in excessive escaping
$calSettingsJson = str_replace('$', '\\$', $calSettingsJson);
$calCustomized = preg_replace("/$calSettingsPattern/", "\\1$calSettingsJson\\3", $calCustomized);
}
/**
* Show output
*/
header('Content-type: text/html');
print $calCustomized;