Skip to content

Instantly share code, notes, and snippets.

@fed51
Forked from dawoodman71/google_calendar.css
Last active November 2, 2016 05:10
Show Gist options
  • Save fed51/e845526f696ce348b07462964c27464f to your computer and use it in GitHub Desktop.
Save fed51/e845526f696ce348b07462964c27464f to your computer and use it in GitHub Desktop.
PHP Solution for adding a Google Calendar, injecting styles and changing options dynamically.
.dp-cur, .chip dt, .te, .te-t, .te-rev-s, .rb-n, .rb-i, .agenda, .event-title{
white-space:normal !important;
}
#calendarTitle,
.tab-name,
img[title="Print my calendar (shows preview)"],
.footer img,
.details .links a:last-child,
.event-links a:last-child
{display:none;}
.mv-event-container
{border-color:#999;}
.navBack,
.navForward
{ background-image: url(images/combined_v22.png); }
.agenda-more
{ color:#0D75BB; }
.agenda .date-label
{ padding:5px 0px; }
.dp-popup
{background:#fff;}
.view-cap, .view-container-border,
.mv-daynames-table,
.ui-rtsr-selected,
.wk-weektop,
.wk-dummyth,
.date-picker-arrow-on,
.dp-weekend-selected
{
/* background-color:#dfdfdf; */
Background-color:#439f55;
}
.ui-rtsr-unselected,
.mv-daynames-table,
.wk-daynames,
.wk-dayname,
.dp-prev,
.dp-cur,
.dp-next
{ color:#666; }
.ui-rtsr-unselected
{ background-color:transparent;}
.dp-weekday-selected,
.agenda .date-label
{background-color:#efefef;}
.dp-today-selected
{background-color:#fad163;}
.mv-daynames-table,
.wk-daynames
{height:30px; font-size:14px;}
.mv-event-container
{ top:30px;}
<!-- by default the iframe shows the month view -->
<iframe id="googleCalendar" style="border: 0;"
src="google_calendar.php"
height="600" width="100%"
frameborder="0" scrolling="no"></iframe>
<!-- add ?v=[VIEW] to the path to force a view -->
<!-- views include month, week, agenda -->
<iframe id="googleCalendar?v=agenda" style="border: 0;"
src="google_calendar.php"
height="300" width="400"
frameborder="0" scrolling="no"></iframe>
<?php
// determine path, css filename and view mode
$calendarpath="https://www.google.com/calendar/embed?src=[YOUR GOOGLE CALENDAR ID]&ctz=America/New_York"
$newcss="google_calendar.css";
$defaultview=($_GET["v"]) ? $_GET["v"] : "month";
// import the contents of the Google Calendar page into a string
$contents = file_get_contents($calendarpath);
// add secure Google address to root relative links
$contents = str_replace('<link type="text/css" rel="stylesheet" href="//calendar.google.com/calendar/', '<link type="text/css" rel="stylesheet" href="https://www.google.com/calendar/', $contents );
$contents = str_replace('<script type="text/javascript" src="//calendar.google.com/calendar/', '<script type="text/javascript" src="https://www.google.com/calendar/' , $contents );
// inject css file reference
$contents = str_replace('<script>function _onload()', '<link rel="stylesheet" type="text/css" href="'.$newcss.'" /><script>function _onload()', $contents );
// update settings found in javascript _onload() function
$contents = str_replace('"view":"month"', '"view":"'.$defaultview.'"', $contents);
$contents = str_replace('"showCalendarMenu":true', '"showCalendarMenu":false', $contents);
if($defaultview == "month") $contents = str_replace('"showDateMarker":true', '"showDateMarker":false', $contents);
if($defaultview != "month") $contents = str_replace('"showTabs":true', '"showTabs":false', $contents);
echo $contents;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment