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