]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/facebookaction.php
8872934aaec1ba10d3d038170fa05c8908dc5e27
[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
37         # Display methods
38
39         function show_header($selected ='Home') {
40
41          $header = '<link rel="stylesheet" type="text/css" href="'. theme_path('facebookapp.css') . '" />';
42          # $header .='<script src="" ></script>';
43           $header .= '<fb:dashboard/>';
44
45           $header .=
46                 '<fb:tabs>'
47                 .'<fb:tab-item title="Home" href="index.php" selected="' . ($selected == 'Home') .'" />'
48                 .'<fb:tab-item title="Invite Friends"  href="invite.php" selected="' . ($selected == 'Invite') . '" />'
49                 .'<fb:tab-item title="Settings"  href="settings.php" selected="' . ($selected == 'Settings') . '" />'
50                 .'</fb:tabs>';
51           $header .= '<div id="main_body">';
52
53           echo $header;
54
55         }
56
57         function show_footer() {
58           $footer = '</div>';
59           echo $footer;
60         }
61
62         function show_login_form() {
63
64                 $loginform =
65                         ' <h2>To add the Identi.ca application, you need to log into your Identi.ca account.</h2>'
66                         .'<a href="http://identi.ca/">'
67                         .'      <img src="http://theme.identi.ca/identica/logo.png" alt="Identi.ca" id="logo"/>'
68                         .'</a>'
69                         .'<h1 class="pagetitle">Login</h1>'
70                         .'<div class="instructions">'
71                         .'      <p>Login with your username and password. Don\'t have a username yet?'
72                         .'        <a href="http://identi.ca/main/register">Register</a> a new account.'
73                         .'      </p>'
74                         .'</div>'
75                         .'<div id="content">'
76                         .'      <form method="post" id="login">'
77                         .'        <p>'
78                         .'              <label for="nickname">Nickname</label>'
79                         .'              <input name="nickname" type="text" class="input_text" id="nickname"/>'
80                         .'        </p>'
81                         .'        <p>'
82                         .'                <label for="password">Password</label>'
83                         .'              <input name="password" type="password" class="password" id="password"/>'
84                         .'        </p>'
85                         .'        <p>'
86                         .'              <input type="submit" id="submit" name="submit" class="submit" value="Login"/>'
87                         .'        </p>'
88                         .'      </form>'
89                         .'      <p>'
90                         .'        <a href="http://identi.ca/main/recoverpassword">Lost or forgotten password?</a>'
91                         .'      </p>'
92                         .'</div';
93
94                         echo $loginform;
95         }
96
97         function render_notice($notice) {
98
99                 global $config;
100
101                 $profile = $notice->getProfile();
102                 $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
103
104                 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
105
106                 # XXX: we need to figure this out better. Is this right?
107                 if (strcmp($notice->uri, $noticeurl) != 0 && preg_match('/^http/', $notice->uri)) {
108                         $noticeurl = $notice->uri;
109                 }
110
111                 $html =
112                 '<li class="notice_single" id="' . $notice->id . '">'
113                 .'<a href="' . $profile->profileurl . '">'
114                 .'<img src="';
115
116                 if ($avatar) {
117                         $html .= common_avatar_display_url($avatar);
118                 } else {
119                         $html .= common_default_avatar(AVATAR_STREAM_SIZE);
120                 }
121
122                 $html .=
123                 '" class="avatar stream" width="'
124                 . AVATAR_STREAM_SIZE . '" height="' . AVATAR_STREAM_SIZE .'"'
125                 .' alt="';
126
127                 if ($profile->fullname) {
128                         $html .= $profile->fullname;
129                 } else {
130                         $html .= $profile->nickname;
131                 }
132
133                 $html .=
134                 '"></a>'
135                 .'<a href="' .  $profile->profileurl . '" class="nickname">' . $profile->nickname . '</a>'
136                 .'<p class="content">' . $notice->rendered . '</p>'
137                 .'<p class="time">'
138                 .'<a class="permalink" href="' . $noticeurl . '" title="' . common_exact_date($notice->created) . '">' . common_date_string($notice->created) . '</a>';
139
140                 if ($notice->source) {
141                         $html .= _(' from ');
142                         $html .= $this->source_link($notice->source);
143                 }
144
145                 if ($notice->reply_to) {
146                         $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
147                         $html .=
148                         ' (<a class="inreplyto" href="' . $replyurl . '">' . _('in reply to...') . ')';
149                 }
150
151                 $html .= '</p></li>';
152
153                 return $html;
154         }
155
156         function source_link($source) {
157                 $source_name = _($source);
158
159                 $html = '<span class="noticesource">';
160
161                 switch ($source) {
162                  case 'web':
163                  case 'xmpp':
164                  case 'mail':
165                  case 'omb':
166                  case 'api':
167                         $html .= $source_name;
168                         break;
169                  default:
170                         $ns = Notice_source::staticGet($source);
171                         if ($ns) {
172                                 $html .= '<a href="' . $ns->url . '">' . $ns->name . '</a>';
173                         } else {
174                                 $html .= $source_name;
175                         }
176                         break;
177                 }
178
179                 $html .= '</span>';
180
181                 return $html;
182         }
183         
184         function pagination($have_before, $have_after, $page, $fbaction, $args=NULL) {
185
186                 $html = '';
187
188                 if ($have_before || $have_after) {
189                         $html = '<div id="pagination">';
190                         $html .'<ul id="nav_pagination">';                      
191                 }
192
193                 if ($have_before) {
194                         $pargs = array('page' => $page-1);
195                         $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
196                         $html .= '<li class="before">';
197                         $html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('« After') . '</a>';
198                         $html .'</li>';
199                 }
200
201                 if ($have_after) {
202                         $pargs = array('page' => $page+1);
203                         $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
204                         $html .= '<li class="after">';
205                         $html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('Before »') . '</a>';
206                         $html .'</li>';
207                 }
208
209                 if ($have_before || $have_after) {
210                         $html .= '<ul>';
211                         $html .'<div>';
212                 }
213         }
214
215         function pagination_url($fbaction, $args=NULL) {
216                 global $config;
217
218                 $extra = '';
219
220                 if ($args) {
221                         foreach ($args as $key => $value) {
222                                 $extra .= "&${key}=${value}";
223                         }
224                 }
225
226                 return "$fbaction?${extra}";
227         }
228         
229 }