]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/facebookaction.php
Merge branch 'master' of http://goukihq.org/misc/git/laconica-locales
[quix0rs-gnu-social.git] / lib / facebookaction.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/extlib/facebook/facebook.php');
23
24 class FacebookAction extends Action {
25
26         function handle($args) {
27                 parent::handle($args);
28         }
29
30         function get_facebook() {
31                 $apikey = common_config('facebook', 'apikey');
32                 $secret = common_config('facebook', 'secret');
33                 return new Facebook($apikey, $secret);
34         }
35
36         function update_profile_box($facebook, $fbuid, $user) {
37
38                 $notice = $user->getCurrentNotice();
39
40                 # Need to include inline CSS for styling the Profile box
41
42                 $style = '<style>
43                 #notices {
44                 clear: both;
45                 margin: 0 auto;
46                 padding: 0;
47                 list-style-type: none;
48                 width: 600px;
49                 border-top: 1px solid #dec5b5;
50                 }
51                 #notices a:hover {
52                 text-decoration: underline;
53                 }
54                 .notice_single {
55                 clear: both;
56                 display: block;
57                 margin: 0;
58                 padding: 5px 5px 5px 0;
59                 min-height: 48px;
60                 font-family: Georgia, "Times New Roman", Times, serif;
61                 font-size: 13px;
62                 line-height: 16px;
63                 border-bottom: 1px solid #dec5b5;
64                 background-color:#FCFFF5;
65                 opacity:1;
66                 }
67                 .notice_single:hover {
68                 background-color: #f7ebcc;
69                 }
70                 .notice_single p {
71                 display: inline;
72                 margin: 0;
73                 padding: 0;
74                 }
75                 </style>';
76
77                 $html = $this->render_notice($notice);
78
79                 $fbml = "<fb:wide>$content $html</fb:wide>";
80                 $fbml .= "<fb:narrow>$content $html</fb:narrow>";
81
82                 $fbml_main = "<fb:narrow>$content $html</fb:narrow>";
83
84                 $facebook->api_client->profile_setFBML(NULL, $fbuid, $fbml, NULL, NULL, $fbml_main);
85         }
86
87         # Display methods
88
89         function show_header($selected ='Home') {
90
91                 # Add a timestamp to the CSS file so Facebook cache wont ignore our changes
92                 $ts = filemtime(theme_file('facebookapp.css'));
93                 $cssurl = theme_path('facebookapp.css') . "?ts=$ts";
94
95                 $header = '<link rel="stylesheet" type="text/css" href="'. $cssurl . '" />';
96                 # $header .='<script src="" ></script>';
97                 $header .= '<fb:dashboard/>';
98
99                 $header .=
100                         '<fb:tabs>'
101                         .'<fb:tab-item title="Home" href="index.php" selected="' . ($selected == 'Home') .'" />'
102                         .'<fb:tab-item title="Invite Friends"  href="invite.php" selected="' . ($selected == 'Invite') . '" />'
103                         .'<fb:tab-item title="Settings"  href="settings.php" selected="' . ($selected == 'Settings') . '" />'
104                         .'</fb:tabs>';
105                 $header .= '<div id="main_body">';
106
107           echo $header;
108
109         }
110
111         function show_footer() {
112           $footer = '</div>';
113           echo $footer;
114         }
115
116         function show_login_form() {
117
118                 $loginform =
119                         ' <h2>To add the Identi.ca application, you need to log into your Identi.ca account.</h2>'
120                         .'<a href="http://identi.ca/">'
121                         .'      <img src="http://theme.identi.ca/identica/logo.png" alt="Identi.ca" id="logo"/>'
122                         .'</a>'
123                         .'<h1 class="pagetitle">Login</h1>'
124                         .'<div class="instructions">'
125                         .'      <p>Login with your username and password. Don\'t have a username yet?'
126                         .'        <a href="http://identi.ca/main/register">Register</a> a new account.'
127                         .'      </p>'
128                         .'</div>'
129                         .'<div id="content">'
130                         .'      <form method="post" id="login">'
131                         .'        <p>'
132                         .'              <label for="nickname">Nickname</label>'
133                         .'              <input name="nickname" type="text" class="input_text" id="nickname"/>'
134                         .'        </p>'
135                         .'        <p>'
136                         .'                <label for="password">Password</label>'
137                         .'              <input name="password" type="password" class="password" id="password"/>'
138                         .'        </p>'
139                         .'        <p>'
140                         .'              <input type="submit" id="submit" name="submit" class="submit" value="Login"/>'
141                         .'        </p>'
142                         .'      </form>'
143                         .'      <p>'
144                         .'        <a href="http://identi.ca/main/recoverpassword">Lost or forgotten password?</a>'
145                         .'      </p>'
146                         .'</div';
147
148                         echo $loginform;
149         }
150
151         function render_notice($notice) {
152
153                 global $config;
154
155                 $profile = $notice->getProfile();
156                 $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
157
158                 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
159
160                 # XXX: we need to figure this out better. Is this right?
161                 if (strcmp($notice->uri, $noticeurl) != 0 && preg_match('/^http/', $notice->uri)) {
162                         $noticeurl = $notice->uri;
163                 }
164
165                 $html =
166                 '<li class="notice_single" id="' . $notice->id . '">'
167                 .'<a href="' . $profile->profileurl . '">'
168                 .'<img src="';
169
170                 if ($avatar) {
171                         $html .= common_avatar_display_url($avatar);
172                 } else {
173                         $html .= common_default_avatar(AVATAR_STREAM_SIZE);
174                 }
175
176                 $html .=
177                 '" class="avatar stream" width="'
178                 . AVATAR_STREAM_SIZE . '" height="' . AVATAR_STREAM_SIZE .'"'
179                 .' alt="';
180
181                 if ($profile->fullname) {
182                         $html .= $profile->fullname;
183                 } else {
184                         $html .= $profile->nickname;
185                 }
186
187                 $html .=
188                 '"></a>'
189                 .'<a href="' .  $profile->profileurl . '" class="nickname">' . $profile->nickname . '</a>'
190                 .'<p class="content">' . $notice->rendered . '</p>'
191                 .'<p class="time">'
192                 .'<a class="permalink" href="' . $noticeurl . '" title="' . common_exact_date($notice->created) . '">' . common_date_string($notice->created) . '</a>';
193
194                 if ($notice->source) {
195                         $html .= _(' from ');
196                         $html .= $this->source_link($notice->source);
197                 }
198
199                 if ($notice->reply_to) {
200                         $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
201                         $html .=
202                         ' (<a class="inreplyto" href="' . $replyurl . '">' . _('in reply to...') . ')';
203                 }
204
205                 $html .= '</p></li>';
206
207                 return $html;
208         }
209
210         function source_link($source) {
211                 $source_name = _($source);
212
213                 $html = '<span class="noticesource">';
214
215                 switch ($source) {
216                  case 'web':
217                  case 'xmpp':
218                  case 'mail':
219                  case 'omb':
220                  case 'api':
221                         $html .= $source_name;
222                         break;
223                  default:
224                         $ns = Notice_source::staticGet($source);
225                         if ($ns) {
226                                 $html .= '<a href="' . $ns->url . '">' . $ns->name . '</a>';
227                         } else {
228                                 $html .= $source_name;
229                         }
230                         break;
231                 }
232
233                 $html .= '</span>';
234
235                 return $html;
236         }
237
238         function pagination($have_before, $have_after, $page, $fbaction, $args=NULL) {
239
240                 $html = '';
241
242                 if ($have_before || $have_after) {
243                         $html = '<div id="pagination">';
244                         $html .'<ul id="nav_pagination">';
245                 }
246
247                 if ($have_before) {
248                         $pargs = array('page' => $page-1);
249                         $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
250                         $html .= '<li class="before">';
251                         $html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('« After') . '</a>';
252                         $html .'</li>';
253                 }
254
255                 if ($have_after) {
256                         $pargs = array('page' => $page+1);
257                         $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
258                         $html .= '<li class="after">';
259                         $html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('Before »') . '</a>';
260                         $html .'</li>';
261                 }
262
263                 if ($have_before || $have_after) {
264                         $html .= '<ul>';
265                         $html .'<div>';
266                 }
267         }
268
269         function pagination_url($fbaction, $args=NULL) {
270                 global $config;
271
272                 $extra = '';
273
274                 if ($args) {
275                         foreach ($args as $key => $value) {
276                                 $extra .= "&${key}=${value}";
277                         }
278                 }
279
280                 return "$fbaction?${extra}";
281         }
282
283 }