| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | <?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 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  |  * GNU Affero General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |  * along with this program.     If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (!defined('LACONICA')) { exit(1); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require_once(INSTALLDIR.'/lib/facebookaction.php'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:49:23 -05:00
										 |  |  | class FacebookhomeAction extends FacebookAction | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:33:23 -05:00
										 |  |  |     function handle($args) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         parent::handle($args); | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-04 20:04:07 -05:00
										 |  |  |         $facebook = get_facebook(); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         $fbuid = $facebook->require_login(); | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |         // Check to see whether there's already a Facebook link for this user
 | 
					
						
							|  |  |  |         $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE); | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         if ($flink) { | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |             $this->showHome($flink, null); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |             $this->login($fbuid); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |     function login($fbuid) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $nickname = common_canonical_nickname($this->trimmed('nickname')); | 
					
						
							|  |  |  |         $password = $this->arg('password'); | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |         $msg = null; | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |         if ($nickname) { | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |             if (common_check_user($nickname, $password)) { | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |                 $user = User::staticGet('nickname', $nickname); | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |                 if (!$user) { | 
					
						
							|  |  |  |                     $this->showLoginForm(_("Server error - couldn't get user!")); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |                 $flink = DB_DataObject::factory('foreign_link'); | 
					
						
							|  |  |  |                 $flink->user_id = $user->id; | 
					
						
							|  |  |  |                 $flink->foreign_id = $fbuid; | 
					
						
							|  |  |  |                 $flink->service = FACEBOOK_SERVICE; | 
					
						
							|  |  |  |                 $flink->created = common_sql_now(); | 
					
						
							|  |  |  |                 $flink->set_flags(true, false, false); | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |                 $flink_id = $flink->insert(); | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |                 // XXX: Do some error handling here
 | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 05:25:07 +00:00
										 |  |  |                 $this->setDefaults(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |                 $this->showHome($flink, _('You can now use Identi.ca from Facebook!')); | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |             } else { | 
					
						
							|  |  |  |                 $msg = _('Incorrect username or password.'); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |         $this->showLoginForm($msg); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 05:25:07 +00:00
										 |  |  |     function setDefaults() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $facebook = get_facebook(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // A default prefix string for notices
 | 
					
						
							|  |  |  |         $facebook->api_client->data_setUserPreference(1, 'dented: '); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |     function showHome($flink, $msg) | 
					
						
							| 
									
										
										
										
											2008-12-23 14:33:23 -05:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-01-12 05:25:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 08:33:28 +00:00
										 |  |  |         $facebook = get_facebook(); | 
					
						
							|  |  |  |         $fbuid = $facebook->require_login(); | 
					
						
							| 
									
										
										
										
											2009-01-12 05:25:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 08:33:28 +00:00
										 |  |  |         $user = $flink->getUser(); | 
					
						
							| 
									
										
										
										
											2009-01-12 05:25:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 08:33:28 +00:00
										 |  |  |         $notice = $user->getCurrentNotice(); | 
					
						
							|  |  |  |         update_profile_box($facebook, $fbuid, $user, $notice); | 
					
						
							| 
									
										
										
										
											2009-01-12 05:25:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         $this->show_header('Home'); | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |         if ($msg) { | 
					
						
							|  |  |  |             common_element('fb:success', array('message' => $msg)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         echo $this->show_notices($user); | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         $this->show_footer(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:33:23 -05:00
										 |  |  |     function show_notices($user) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         $page = $this->trimmed('page'); | 
					
						
							|  |  |  |         if (!$page) { | 
					
						
							|  |  |  |             $page = 1; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |         $cnt = $this->show_notice_list($notice); | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |         common_pagination($page > 1, $cnt > NOTICES_PER_PAGE, | 
					
						
							|  |  |  |                           $page, 'all', array('nickname' => $user->nickname)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-12-07 18:59:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-11 07:03:59 +00:00
										 |  |  |     function show_notice_list($notice) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $nl = new NoticeList($notice); | 
					
						
							|  |  |  |         return $nl->show(); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-12-05 22:01:32 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |