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