summaryrefslogtreecommitdiff
path: root/lib/facebookaction.php
blob: d5f0adbb88d3e17fdc386e328758f257c9d95708 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?php
/*
 * Laconica - a distributed open-source microblogging tool
 * Copyright (C) 2008, Controlez-Vous, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.	 If not, see <http://www.gnu.org/licenses/>.
 */

if (!defined('LACONICA')) { exit(1); }

require_once(INSTALLDIR.'/extlib/facebook/facebook.php');

class FacebookAction extends Action {

	function handle($args) {
		parent::handle($args);
	}

	function get_facebook() {
		$apikey = common_config('facebook', 'apikey');
		$secret = common_config('facebook', 'secret');
		return new Facebook($apikey, $secret);
	}

	function update_profile_box($facebook, $fbuid, $user) {

		$notice = $user->getCurrentNotice();

		# Need to include inline CSS for styling the Profile box

		$style = '<style>
		#notices {
		clear: both;
		margin: 0 auto;
		padding: 0;
		list-style-type: none;
		width: 600px;
		border-top: 1px solid #dec5b5;
		}
		#notices a:hover {
		text-decoration: underline;
		}
		.notice_single {
		clear: both;
		display: block;
		margin: 0;
		padding: 5px 5px 5px 0;
		min-height: 48px;
		font-family: Georgia, "Times New Roman", Times, serif;
		font-size: 13px;
		line-height: 16px;
		border-bottom: 1px solid #dec5b5;
		background-color:#FCFFF5;
		opacity:1;
		}
		.notice_single:hover {
		background-color: #f7ebcc;
		}
		.notice_single p {
		display: inline;
		margin: 0;
		padding: 0;
		}
		</style>';

		$html = $this->render_notice($notice);

		$fbml = "<fb:wide>$content $html</fb:wide>";
		$fbml .= "<fb:narrow>$content $html</fb:narrow>";

		$fbml_main = "<fb:narrow>$content $html</fb:narrow>";

		$facebook->api_client->profile_setFBML(NULL, $fbuid, $fbml, NULL, NULL, $fbml_main);
	}

	# Display methods

	function show_header($selected ='Home') {

	 $header = '<link rel="stylesheet" type="text/css" href="'. theme_path('facebookapp.css') . '" />';
	 # $header .='<script src="" ></script>';
	  $header .= '<fb:dashboard/>';

	  $header .=
		'<fb:tabs>'
		.'<fb:tab-item title="Home" href="index.php" selected="' . ($selected == 'Home') .'" />'
		.'<fb:tab-item title="Invite Friends"  href="invite.php" selected="' . ($selected == 'Invite') . '" />'
		.'<fb:tab-item title="Settings"	 href="settings.php" selected="' . ($selected == 'Settings') . '" />'
		.'</fb:tabs>';
	  $header .= '<div id="main_body">';

	  echo $header;

	}

	function show_footer() {
	  $footer = '</div>';
	  echo $footer;
	}

	function show_login_form() {

		$loginform =
			' <h2>To add the Identi.ca application, you need to log into your Identi.ca account.</h2>'
			.'<a href="http://identi.ca/">'
			.'	<img src="http://theme.identi.ca/identica/logo.png" alt="Identi.ca" id="logo"/>'
			.'</a>'
			.'<h1 class="pagetitle">Login</h1>'
			.'<div class="instructions">'
			.'	<p>Login with your username and password. Don\'t have a username yet?'
			.'	  <a href="http://identi.ca/main/register">Register</a> a new account.'
			.'	</p>'
			.'</div>'
			.'<div id="content">'
			.'	<form method="post" id="login">'
			.'	  <p>'
			.'		<label for="nickname">Nickname</label>'
			.'		<input name="nickname" type="text" class="input_text" id="nickname"/>'
			.'	  </p>'
			.'	  <p>'
			.'		  <label for="password">Password</label>'
			.'		<input name="password" type="password" class="password" id="password"/>'
			.'	  </p>'
			.'	  <p>'
			.'		<input type="submit" id="submit" name="submit" class="submit" value="Login"/>'
			.'	  </p>'
			.'	</form>'
			.'	<p>'
			.'	  <a href="http://identi.ca/main/recoverpassword">Lost or forgotten password?</a>'
			.'	</p>'
			.'</div';

			echo $loginform;
	}

	function render_notice($notice) {

		global $config;

		$profile = $notice->getProfile();
		$avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);

		$noticeurl = common_local_url('shownotice', array('notice' => $notice->id));

		# XXX: we need to figure this out better. Is this right?
		if (strcmp($notice->uri, $noticeurl) != 0 && preg_match('/^http/', $notice->uri)) {
			$noticeurl = $notice->uri;
		}

		$html =
		'<li class="notice_single" id="' . $notice->id . '">'
		.'<a href="' . $profile->profileurl . '">'
		.'<img src="';

		if ($avatar) {
			$html .= common_avatar_display_url($avatar);
		} else {
			$html .= common_default_avatar(AVATAR_STREAM_SIZE);
		}

		$html .=
		'" class="avatar stream" width="'
		. AVATAR_STREAM_SIZE . '" height="' . AVATAR_STREAM_SIZE .'"'
		.' alt="';

		if ($profile->fullname) {
			$html .= $profile->fullname;
		} else {
			$html .= $profile->nickname;
		}

		$html .=
		'"></a>'
		.'<a href="' .	$profile->profileurl . '" class="nickname">' . $profile->nickname . '</a>'
		.'<p class="content">' . $notice->rendered . '</p>'
		.'<p class="time">'
		.'<a class="permalink" href="' . $noticeurl . '" title="' . common_exact_date($notice->created) . '">' . common_date_string($notice->created) . '</a>';

		if ($notice->source) {
			$html .= _(' from ');
			$html .= $this->source_link($notice->source);
		}

		if ($notice->reply_to) {
			$replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
			$html .=
			' (<a class="inreplyto" href="' . $replyurl . '">' . _('in reply to...') . ')';
		}

		$html .= '</p></li>';

		return $html;
	}

	function source_link($source) {
		$source_name = _($source);

		$html = '<span class="noticesource">';

		switch ($source) {
		 case 'web':
		 case 'xmpp':
		 case 'mail':
		 case 'omb':
		 case 'api':
			$html .= $source_name;
			break;
		 default:
			$ns = Notice_source::staticGet($source);
			if ($ns) {
				$html .= '<a href="' . $ns->url . '">' . $ns->name . '</a>';
			} else {
				$html .= $source_name;
			}
			break;
		}

		$html .= '</span>';

		return $html;
	}

	function pagination($have_before, $have_after, $page, $fbaction, $args=NULL) {

		$html = '';

		if ($have_before || $have_after) {
			$html = '<div id="pagination">';
			$html .'<ul id="nav_pagination">';
		}

		if ($have_before) {
			$pargs = array('page' => $page-1);
			$newargs = ($args) ? array_merge($args,$pargs) : $pargs;
			$html .= '<li class="before">';
			$html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('« After') . '</a>';
			$html .'</li>';
		}

		if ($have_after) {
			$pargs = array('page' => $page+1);
			$newargs = ($args) ? array_merge($args,$pargs) : $pargs;
			$html .= '<li class="after">';
			$html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('Before »') . '</a>';
			$html .'</li>';
		}

		if ($have_before || $have_after) {
			$html .= '<ul>';
			$html .'<div>';
		}
	}

	function pagination_url($fbaction, $args=NULL) {
		global $config;

		$extra = '';

		if ($args) {
			foreach ($args as $key => $value) {
				$extra .= "&${key}=${value}";
			}
		}

		return "$fbaction?${extra}";
	}

}