views:

52

answers:

3

I'm migrating my library's website from webcal to google calendar. The site is written in PHP and HTML4.01 (moving from transitional towards strict). Is there a programatic way that I can generate links to calender days/entries? With webcal a link to the day view was:

www.mylibrary.com/calendar/day.php?YYYYMMDD

And so it was easy to programatically generate a link to a specific day. I've been trying to find a way to do similar stuff w/ the google calendar and haven't had much luck. I'd really like to be able to do something like

<p>The summer reading program kicks off <a href="
<?php echo "http://www.google.com/calendar/event?cid=".$mycalenderid."&amp;eventdate=".$year.$month.$day; ?>
">May 5th</a></p>

Is this even remotely possible?

+1  A: 

This might not be the "easy" solution you were hoping for but the Zend Framework has a gdata component that can do what you'd like.

Eric Butera
Just to add on that, if you didn't already know. You don't need to be using the Zend Framework in order to use one of it's components.
Dean
Would this be something I'd have to install server side? I'm not opposed to a little difficulty up front if it can make things simpler in the long run.
aslum
Here's the documentation for displaying event information: http://code.google.com/apis/calendar/data/1.0/developers_guide_php.html#RetrievingEvents
emmychan
A: 

The simplest way to include the calendar in your site is to use the Google provided embeddable calendar: http://code.google.com/apis/calendar/publish/. The upside is that all you have to do is toss the iframe code into a page and link to it. The downside is that, as far as I can tell, there's no mechanism for linking to a specific day or event.

To do something similar to what you're asking, you'll need to use the zend Gdata component and program it yourself. So, for days.php, you could do something similar to:


<?php
/**
 * Adapted from google API doc example
 */
$day = $_GET['day'];
$nextDay = date('Y-m-d', strtotime($day) + 86400);

$client = new Zend_Gdata_Calendar(); //Not authenticated for public calendar

$query = $gdataCal->newEventQuery($client);
$query->setUser('[email protected]');
$query->setVisibility('public');
$query->setProjection('full');
$query->setOrderby('starttime');
$query->setStartMin($day); //Inclusive
$query->setStartMax($nextDay); //Exclusive
$eventFeed = $gdataCal->getCalendarEventFeed($query);

?>
<h1>
  <?php print $day; ?>
</h1>
<ul id="days-events">
  <?php foreach ($eventFeed as $event): ?>
    <li class="event">
      <?php print $event->title->text ?>
    </li>
  <?php endforeach; ?>
</ul>

Google Documentation: http://code.google.com/apis/calendar/data/1.0/developers_guide_php.html

Zend Documentation: http://framework.zend.com/manual/en/zend.gdata.calendar.html

emmychan
A: 

Much simpler solution:

if($_REQUEST['showday']!='') {$datetoshow=$_REQUEST['showday'];
$datetoshow = $datetoshow."/".$datetoshow;}

Blah blah page content

if ($datetoshow==""){?>
<iframe srtc=""> .... // regular embed text goes here.
<?} else {?>
<iframe src=""> // Add &amp;mode=DAY&amp;dates=<?echo $datetoshow;?> to the SRC code
<?}

Then it's as simple as calling the page w/ day.php?showday=20100205 or whatever day I want. Thanks for all the suggestions though!

aslum