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 startFBML($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 getFacebookBaseCSS()
112 # Add a timestamp to the CSS file so Facebook cache wont ignore our changes
113 $ts = filemtime(INSTALLDIR.'/theme/base/css/facebookapp.base.css');
114 $cssurl = INSTALLDIR.'/theme/base/css/facebookapp.base.css' . "?ts=$ts";
118 function getFacebookThemeCSS()
120 # Add a timestamp to the CSS file so Facebook cache wont ignore our changes
121 $ts = filemtime(theme_file('css/facebookapp.theme.css'));
122 $cssurl = theme_path('css/facebookapp.theme.css') . "?ts=$ts";
126 function getFacebookJS() {
128 # Add a timestamp to the FBJS file so Facebook cache wont ignore our changes
129 $ts = filemtime(INSTALLDIR.'/js/facebookapp.js');
130 $jsurl = common_path('js/facebookapp.js') . "?ts=$ts";
135 // Does a little before-after block for next/prev page
137 function facebookPagination($have_before, $have_after, $page, $action, $args=null)
140 if ($have_before || $have_after) {
141 common_element_start('div', array('id' => 'pagination'));
142 common_element_start('ul', array('id' => 'nav_pagination'));
146 $pargs = array('page' => $page-1);
147 $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
149 common_element_start('li', 'before');
150 common_element('a', array('href' => "index.php?page=$newargs[page]", 'rel' => 'prev'),
152 common_element_end('li');
156 $pargs = array('page' => $page+1);
157 $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
158 common_element_start('li', 'after');
159 common_element('a', array('href' => "index.php?page=$newargs[page]", 'rel' => 'next'),
161 common_element_end('li');
164 if ($have_before || $have_after) {
165 common_element_end('ul');
166 common_element_end('div');
171 class FacebookNoticeList extends NoticeList
174 * show the list of notices
176 * "Uses up" the stream by looping through it. So, probably can't
177 * be called twice on the same list.
179 * @return int count of notices listed.
184 common_element_start('div', array('id' =>'notices_primary'));
185 common_element('h2', null, _('Notices'));
186 common_element_start('ul', array('class' => 'notices'));
190 while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
193 if ($cnt > NOTICES_PER_PAGE) {
197 $item = $this->newListItem($this->notice);
201 common_element_end('ul');
202 common_element_end('div');
208 * returns a new list item for the current notice
210 * Overridden to return a Facebook specific list item.
212 * @param Notice $notice the current notice
214 * @return FacebookNoticeListItem a list item for displaying the notice
215 * formatted for display in the Facebook App.
218 function newListItem($notice)
220 return new FacebookNoticeListItem($notice);
225 class FacebookNoticeListItem extends NoticeListItem
228 * recipe function for displaying a single notice in the Facebook App.
230 * Overridden to strip out some of the controls that we don't
231 * want to be available.
240 common_element_start('div', 'entry-title');
242 $this->showContent();
243 common_element_end('div');
245 common_element_start('div', 'entry-content');
246 $this->showNoticeLink();
247 $this->showNoticeSource();
248 $this->showReplyTo();
249 common_element_end('div');
257 // TODO: add notice_type class e.g., notice_video, notice_image
258 common_element_start('li', array('class' => 'hentry notice',
259 'id' => 'notice-' . $this->notice->id));
262 function showNoticeLink()
264 $noticeurl = common_local_url('shownotice',
265 array('notice' => $this->notice->id));
266 // XXX: we need to figure this out better. Is this right?
267 if (strcmp($this->notice->uri, $noticeurl) != 0 &&
268 preg_match('/^http/', $this->notice->uri)) {
269 $noticeurl = $this->notice->uri;
272 common_element_start('dl', 'timestamp');
273 common_element('dt', null, _('Published'));
274 common_element_start('dd', null);
275 common_element_start('a', array('rel' => 'bookmark',
276 'href' => $noticeurl));
277 $dt = common_date_iso8601($this->notice->created);
278 common_element('abbr', array('class' => 'published',
280 common_date_string($this->notice->created));
281 common_element_end('a');
282 common_element_end('dd');
283 common_element_end('dl');