]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/Facebook.php
split is deprecated, replace with explode
[SourceForge/phpwiki.git] / lib / WikiUser / Facebook.php
1 <?php //-*-php-*-
2 // rcs_id('$Id$');
3 /* Copyright (C) 2009 Reini Urban
4  * This file is part of PhpWiki. Terms and Conditions see LICENSE. (GPL2)
5  *
6  * From http://developeronline.blogspot.com/2008/10/using-perl-against-facebook-part-i.html:
7  * GET 'http://www.facebook.com/login.php', and rest our virtual browser there to collect the cookies
8  * POST to 'https://login.facebook.com/login.php' with the proper parameters
9  */
10
11 // requires the openssl extension
12 require_once("lib/HttpClient.php");
13
14 class _FacebookPassUser
15 extends _PassUser {
16     /**
17      * Preferences are handled in _PassUser
18      */
19     function checkPass($password) {
20         $userid = $this->_userid;
21         if (!loadPhpExtension('openssl')) {
22             trigger_error(
23                 (sprintf(_("The PECL %s extension cannot be loaded."), "openssl") 
24                  . sprintf(_(" %s AUTH ignored."), 'Facebook'),
25                  E_USER_WARNING);
26             return $this->_tryNextUser();
27         }
28         $web = new HttpClient("www.facebook.com", 80);
29         if (DEBUG & _DEBUG_LOGIN) $web->setDebug(true);
30         // collect cookies from http://www.facebook.com/login.php
31         $web->persist_cookies = true;
32         $web->cookie_host = 'www.facebook.com';
33         $firstlogin = $web->get("/login.php");
34         if (!$firstlogin) {
35             if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE))
36                 trigger_error(sprintf(_("Facebook connect failed with %d %s"),
37                                       $web->status, $web->errormsg),
38                               E_USER_WARNING);
39         }
40         // Switch from http to https://login.facebook.com/login.php
41         $web->port = 443;
42         $web->host = 'login.facebook.com';
43         if (!($retval = $web->post("/login.php", array('user'=>$userid, 'pass'=>$password)))) {
44             if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE))
45                 trigger_error(sprintf(_("Facebook login failed with %d %s"),
46                                       $web->status, $web->errormsg),
47                               E_USER_WARNING);
48         }
49         $this->_authmethod = 'Facebook';
50         if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this)."::checkPass => $retval",
51                                                 E_USER_WARNING);
52         if ($retval) {
53             $this->_level = WIKIAUTH_USER;
54         } else {
55             $this->_level = WIKIAUTH_ANON;
56         }
57         return $this->_level;
58     }
59
60     // TODO: msearch facebook for the username
61     function userExists() {
62         if (!loadPhpExtension('openssl')) {
63             trigger_error(
64                 (sprintf(_("The PECL %s extension cannot be loaded."), "openssl") 
65                  . sprintf(_(" %s AUTH ignored."), 'Facebook'),
66                  E_USER_WARNING);
67             return $this->_tryNextUser();
68         }
69         if (DEBUG & _DEBUG_LOGIN)
70             trigger_error(get_class($this)."::userExists => true (dummy)", E_USER_WARNING);
71         return true;
72     }
73 }
74
75 // Local Variables:
76 // mode: php
77 // tab-width: 8
78 // c-basic-offset: 4
79 // c-hanging-comment-ender-p: nil
80 // indent-tabs-mode: nil
81 // End:
82 ?>