mysite/code/Page.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
class Page_Controller extends ContentController { 

	function LatestTwitter() {
		try {
			$twitter = new RestfulService("http://twitter.com/statuses/user_timeline/USERNAME.xml", 1800);
			$params = array('count' => 1);
			$twitter->setQueryString($params);
			
			$conn = $twitter->request()->getBody();
			
			$msgs = $twitter->getValues($conn, "status");
			$output = new DataObjectSet();
			foreach($msgs as $msg){
				$output->push(new ArrayData(array(
					"Id" => $msg->id,
					"Text" => $msg->text,
					"CreatedAt" => DBField::Create("SSDatetime", $msg->created_at)->ago(),
					"User" => $msg->user_screen_name
			)));
		}
		return $output;

		} catch(Exception $e) {
			return false;
		}
	}
}

themes/themename/templates/Page.ss

1
2
3
4
<% if LatestTwitter %>
<p>$LatestTwitter.Text posted $LatestTwitter.CreatedAt</p>
<% end_if %>