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