3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 require_once INSTALLDIR.'/extlib/facebook/facebook.php';
21 require_once INSTALLDIR.'/lib/noticelist.php';
23 define("FACEBOOK_SERVICE", 2); // Facebook is foreign_service ID 2
24 define("FACEBOOK_NOTICE_PREFIX", 1);
25 define("FACEBOOK_PROMPTED_UPDATE_PREF", 2);
27 // Gets all the notices from users with a Facebook link since a given ID
28 function get_facebook_notices($since)
30 $qry = 'SELECT notice.* ' .
32 'JOIN foreign_link ' .
33 'WHERE notice.profile_id = foreign_link.user_id ' .
34 'AND foreign_link.service = 2';
36 // XXX: What should the limit be?
37 return Notice::getStreamDirect($qry, 0, 100, 0, 0, null, $since);
40 function get_facebook()
42 $apikey = common_config('facebook', 'apikey');
43 $secret = common_config('facebook', 'secret');
44 return new Facebook($apikey, $secret);
47 function start_fbml($indent = true)
50 $xw = new XMLWriter();
51 $xw->openURI('php://output');
52 $xw->setIndent($indent);
55 function update_profile_box($facebook, $fbuid, $user, $notice)
58 // Need to include inline CSS for styling the Profile box
65 list-style-type: none;
67 border-top: 1px solid #dec5b5;
70 text-decoration: underline;
76 padding: 5px 5px 5px 0;
78 font-family: Georgia, "Times New Roman", Times, serif;
81 border-bottom: 1px solid #dec5b5;
82 background-color:#FCFFF5;
85 .notice_single:hover {
86 background-color: #f7ebcc;
96 $xw = new XMLWriter();
99 $item = new FacebookNoticeListItem($notice);
102 $fbml = "<fb:wide>$style " . $xw->outputMemory(false) . "</fb:wide>";
103 $fbml .= "<fb:narrow>$style " . $xw->outputMemory(false) . "</fb:narrow>";
105 $fbml_main = "<fb:narrow>$style " . $xw->outputMemory(false) . "</fb:narrow>";
107 $facebook->api_client->profile_setFBML(null, $fbuid, $fbml, null, null, $fbml_main);
110 function getFacebookCSS()
112 # Add a timestamp to the CSS file so Facebook cache wont ignore our changes
113 $ts = filemtime(theme_file('facebookapp.css'));
114 $cssurl = theme_path('facebookapp.css') . "?ts=$ts";
118 function getFacebookJS() {
120 # Add a timestamp to the FBJS file so Facebook cache wont ignore our changes
121 $ts = filemtime(INSTALLDIR.'/js/facebookapp.js');
122 $jsurl = common_path('js/facebookapp.js') . "?ts=$ts";
127 class FacebookNoticeList extends NoticeList
130 * show the list of notices
132 * "Uses up" the stream by looping through it. So, probably can't
133 * be called twice on the same list.
135 * @return int count of notices listed.
140 common_element_start('div', array('id' =>'notices_primary'));
141 common_element('h2', null, _('Notices'));
142 common_element_start('ul', array('class' => 'notices'));
146 while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
149 if ($cnt > NOTICES_PER_PAGE) {
153 $item = $this->newListItem($this->notice);
157 common_element_end('ul');
158 common_element_end('div');
164 * returns a new list item for the current notice
166 * Overridden to return a Facebook specific list item.
168 * @param Notice $notice the current notice
170 * @return FacebookNoticeListItem a list item for displaying the notice
171 * formatted for display in the Facebook App.
174 function newListItem($notice)
176 return new FacebookNoticeListItem($notice);
181 class FacebookNoticeListItem extends NoticeListItem
184 * recipe function for displaying a single notice in the Facebook App.
186 * Overridden to strip out some of the controls that we don't
187 * want to be available.
196 common_element_start('div', 'entry-title');
198 $this->showContent();
199 common_element_end('div');
201 common_element_start('div', 'entry-content');
202 $this->showNoticeLink();
203 $this->showNoticeSource();
204 $this->showReplyTo();
205 common_element_end('div');
213 // TODO: add notice_type class e.g., notice_video, notice_image
214 common_element_start('li', array('class' => 'hentry notice',
215 'id' => 'notice-' . $this->notice->id));
218 function showNoticeLink()
220 $noticeurl = common_local_url('shownotice',
221 array('notice' => $this->notice->id));
222 // XXX: we need to figure this out better. Is this right?
223 if (strcmp($this->notice->uri, $noticeurl) != 0 &&
224 preg_match('/^http/', $this->notice->uri)) {
225 $noticeurl = $this->notice->uri;
228 common_element_start('dl', 'timestamp');
229 common_element('dt', null, _('Published'));
230 common_element_start('dd', null);
231 common_element_start('a', array('rel' => 'bookmark',
232 'href' => $noticeurl));
233 $dt = common_date_iso8601($this->notice->created);
234 common_element('abbr', array('class' => 'published',
236 common_date_string($this->notice->created));
237 common_element_end('a');
238 common_element_end('dd');
239 common_element_end('dl');