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