PageRenderTime 24ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/resources/calendar.php

http://tastemakers.googlecode.com/
PHP | 63 lines | 54 code | 6 blank | 3 comment | 5 complexity | ceb4879bfa0d8ba3fc38fbc7b86e9142 MD5 | raw file
  1. <?php
  2. class calendar {
  3. private $endpoint = 'https://www.google.com/calendar/feeds';
  4. private $user_id = 'eomohssl9vmhvtrj8tarm0evb4%40group.calendar.google.com';
  5. private $magic_cookie = 'private-ac09e0346b3fc6fe63b70880c2d2727b';
  6. // queries google calendar and returns formatted jsonc result
  7. private function get_events($args) {
  8. $args = http_build_query($args);
  9. $json_url = "{$this->endpoint}/{$this->user_id}/{$this->magic_cookie}/full?alt=jsonc&$args";
  10. return json_decode(file_get_contents($json_url));
  11. }
  12. public function render() {
  13. // sets start-max to one month in the future, sets start-min to 15 days ago
  14. $args = array(
  15. 'start-min' => date("Y-m-d", strtotime("today", time())),
  16. 'start-max' => date("Y-m-d", strtotime("+60 days", time())),
  17. 'orderby' => 'starttime',
  18. 'sortorder' => 'a',
  19. 'max-results' => '70'
  20. );
  21. $calendar_json = $this->get_events($args);
  22. if ($calendar_json->data->items) {
  23. foreach($calendar_json->data->items as $item) {
  24. $start_time = new DateTime($item->when['0']->start);
  25. $end_time = new DateTime($item->when['0']->end);
  26. $start_timestamp = $start_time->format('U');
  27. if ($start_timestamp < time()) {
  28. echo '<div class="post row past">';
  29. } else {
  30. echo '<div class="post row">';
  31. }
  32. echo '<div class="twocol">';
  33. echo '<p class="date"><span class="day">'.$start_time->format('l').' </span><span>'.$start_time->format('M d').'</span> '.$start_time->format('Y').'</p>';
  34. echo '</div>';
  35. echo '<div class="tencol last">';
  36. // echo "<h1><a href=\"{$item->alternateLink}\">{$item->title}</a></h1>";
  37. echo "<h1>{$item->title}</h1>";
  38. echo '<p>';
  39. echo 'from ' . $start_time->format("h:ia") . ' until ' . $end_time->format("h:ia");
  40. echo " &ndash; at {$item->location}";
  41. echo '</p>';
  42. if (!empty($item->details))
  43. echo "<p>{$item->details}</p>";
  44. echo '</div>';
  45. echo '</div>';
  46. }
  47. } else {
  48. echo '<div class="post row">';
  49. echo '<div class="twelvecol last">';
  50. echo "<h1>No events yet</h1>";
  51. echo '<p>Check back for updates. We\'ll keep this calendar updated with tastemakers related events. We promise.</p>';
  52. echo '</div>';
  53. echo '</div>';
  54. }
  55. }
  56. }
  57. ?>