+ }
+
+ function show_twitter_xml_user($twitter_user, $role='user') {
+ common_element_start($role);
+ foreach($twitter_user as $element => $value) {
+ if ($element == 'status') {
+ $this->show_twitter_xml_status($twitter_user['status']);
+ } else {
+ common_element($element, NULL, $value);
+ }
+ }
+ common_element_end($role);
+ }
+
+ function show_twitter_rss_item($entry) {
+ common_element_start('item');
+ common_element('title', NULL, $entry['title']);
+ common_element('description', NULL, $entry['description']);
+ common_element('pubDate', NULL, $entry['pubDate']);
+ common_element('guid', NULL, $entry['guid']);
+ common_element('link', NULL, $entry['link']);
+ common_element_end('item');
+ }
+
+ function show_twitter_atom_entry($entry) {
+ common_element_start('entry');
+ common_element('title', NULL, $entry['title']);
+ common_element('content', array('type' => 'html'), $entry['title']);
+ common_element('id', NULL, $entry['id']);
+ common_element('published', NULL, $entry['published']);
+ common_element('updated', NULL, $entry['updated']);
+ common_element('link', array('href' => $entry['link'], 'rel' => 'alternate', 'type' => 'text/html'), NULL);
+ common_element_end('entry');
+ }
+
+ function show_json_objects($objects) {
+ print(json_encode($objects));
+ }
+
+ function show_single_xml_status($notice) {
+ $this->init_document('xml');
+ $twitter_status = $this->twitter_status_array($notice);
+ $this->show_twitter_xml_status($twitter_status);
+ $this->end_document('xml');
+ }
+
+ function show_single_json_status($notice) {
+ $this->init_document('json');
+ $status = $this->twitter_status_array($notice);
+ $this->show_json_objects($status);
+ $this->end_document('json');
+ }
+
+ function show_single_xml_dmsg($message) {
+ $this->init_document('xml');
+ $dmsg = $this->twitter_dmsg_array($message);
+ $this->show_twitter_xml_dmsg($dmsg);
+ $this->end_document('xml');
+ }
+
+ function show_single_json_dmsg($message) {
+ $this->init_document('json');
+ $dmsg = $this->twitter_dmsg_array($message);
+ $this->show_json_objects($dmsg);
+ $this->end_document('json');
+ }
+
+ function show_twitter_xml_dmsg($twitter_dm) {
+ common_element_start('direct_message');
+ foreach($twitter_dm as $element => $value) {
+ if ($element == 'sender' || $element == 'recipient') {
+ $this->show_twitter_xml_user($value, $element);
+ } else {
+ common_element($element, NULL, $value);
+ }
+ }
+ common_element_end('direct_message');
+ }
+
+ function show_xml_timeline($notice) {
+
+ $this->init_document('xml');
+ common_element_start('statuses', array('type' => 'array'));
+
+ if (is_array($notice)) {
+ foreach ($notice as $n) {
+ $twitter_status = $this->twitter_status_array($n);
+ $this->show_twitter_xml_status($twitter_status);
+ }
+ } else {
+ while ($notice->fetch()) {
+ $twitter_status = $this->twitter_status_array($notice);
+ $this->show_twitter_xml_status($twitter_status);
+ }
+ }
+
+ common_element_end('statuses');
+ $this->end_document('xml');
+ }
+
+ function show_rss_timeline($notice, $title, $link, $subtitle, $suplink=NULL) {
+
+ $this->init_document('rss');
+
+ common_element_start('channel');
+ common_element('title', NULL, $title);
+ common_element('link', NULL, $link);
+ if (!is_null($suplink)) {
+ # For FriendFeed's SUP protocol
+ common_element('link', array('xmlns' => 'http://www.w3.org/2005/Atom',
+ 'rel' => 'http://api.friendfeed.com/2008/03#sup',
+ 'href' => $suplink,
+ 'type' => 'application/json'));
+ }
+ common_element('description', NULL, $subtitle);
+ common_element('language', NULL, 'en-us');
+ common_element('ttl', NULL, '40');
+
+
+ if (is_array($notice)) {
+ foreach ($notice as $n) {
+ $entry = $this->twitter_rss_entry_array($n);
+ $this->show_twitter_rss_item($entry);
+ }
+ } else {
+ while ($notice->fetch()) {
+ $entry = $this->twitter_rss_entry_array($notice);
+ $this->show_twitter_rss_item($entry);
+ }
+ }
+
+ common_element_end('channel');
+ $this->end_twitter_rss();
+ }
+
+ function show_atom_timeline($notice, $title, $id, $link, $subtitle=NULL, $suplink=NULL) {
+
+ $this->init_document('atom');
+
+ common_element('title', NULL, $title);
+ common_element('id', NULL, $id);
+ common_element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), NULL);
+ if (!is_null($suplink)) {
+ # For FriendFeed's SUP protocol
+ common_element('link', array('rel' => 'http://api.friendfeed.com/2008/03#sup',
+ 'href' => $suplink,
+ 'type' => 'application/json'));
+ }
+ common_element('subtitle', NULL, $subtitle);
+
+ if (is_array($notice)) {
+ foreach ($notice as $n) {
+ $entry = $this->twitter_rss_entry_array($n);
+ $this->show_twitter_atom_entry($entry);
+ }
+ } else {
+ while ($notice->fetch()) {
+ $entry = $this->twitter_rss_entry_array($notice);
+ $this->show_twitter_atom_entry($entry);
+ }
+ }
+
+ $this->end_document('atom');
+
+ }
+
+ function show_json_timeline($notice) {
+
+ $this->init_document('json');