Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

removing outdated word press plugin

  • Loading branch information...
commit 261cc871bac95e2e5f6e1b912aca99bd929b9461 1 parent c073857
Naitik Shah authored June 03, 2010
192  plugins/wp-fbconnect/common.php
... ...
@@ -1,192 +0,0 @@
1  
-<?php
2  
-
3  
-// via
4  
-// http://planetozh.com/blog/2008/07/what-plugin-coders-must-know-about-wordpress-26/
5  
-$root = dirname(dirname(dirname(dirname(__FILE__))));
6  
-if (file_exists($root.'/wp-load.php')) {
7  
-  // WP 2.6
8  
-  require_once($root.'/wp-load.php');
9  
-} else {
10  
-  // Before 2.6
11  
-  require_once($root.'/wp-config.php');
12  
-}
13  
-
14  
-require_once($root . '/wp-includes/registration.php');
15  
-require_once('facebook-client/facebook.php');
16  
-
17  
-
18  
-function _fbc_make_client() {
19  
-  return new Facebook(get_option(FBC_APP_KEY_OPTION),
20  
-                      get_option(FBC_APP_SECRET_OPTION),
21  
-                      false,
22  
-                      'connect.facebook.com');
23  
-}
24  
-
25  
-/*
26  
- * Get the facebook client object for easy access.
27  
- */
28  
-function fbc_facebook_client() {
29  
-  static $facebook = null;
30  
-  if ($facebook === null) {
31  
-    $facebook = _fbc_make_client();
32  
-  }
33  
-  return $facebook;
34  
-}
35  
-
36  
-
37  
-function fbc_api_client() {
38  
-  return fbc_facebook_client()->api_client;
39  
-}
40  
-
41  
-
42  
-/**
43  
-  provides an api client without a user session.
44  
-*/
45  
-function fbc_anon_api_client() {
46  
-  $client = _fbc_make_client();
47  
-  $client->user = 0;
48  
-  $client->api_client->session_key = null;
49  
-  return $client->api_client;
50  
-}
51  
-
52  
-function fbc_get_displayname($userinfo) {
53  
-  if (empty($userinfo['name'])) {
54  
-    // i18n-able
55  
-    return _(FBC_ANONYMOUS_DISPLAYNAME);
56  
-  } else {
57  
-    return $userinfo['name'];
58  
-  }
59  
-}
60  
-
61  
-function fbc_make_public_url($userinfo) {
62  
-  if (empty($userinfo['name'])) {
63  
-    // This user is hidden from search, so they dont get a url either
64  
-    return null;
65  
-  }
66  
-
67  
-  $fbuid = $userinfo['uid'];
68  
-  $name = $userinfo['name'];
69  
-  $under_name = str_replace(" ", "-", $name);
70  
-
71  
-  $clean_name = preg_replace('/[^A-Za-z0-9_\-]+/', '', $under_name);
72  
-
73  
-  $url = 'http://www.facebook.com/people/' . $clean_name . '/' . $fbuid;
74  
-
75  
-  return $url;
76  
-}
77  
-
78  
-
79  
-function render_fb_profile_pic($user) {
80  
-  return <<<EOF
81  
-    <div class="avatar avatar-32">
82  
-    <fb:profile-pic uid="$user" facebook-logo="true" size="square"></fb:profile-pic>
83  
-    </div>
84  
-EOF;
85  
-}
86  
-
87  
-
88  
-function render_fbconnect_button($onlogin=null) {
89  
-  if ($onlogin !== null) {
90  
-    $onlogin_str = ' onlogin="'. $onlogin .'" ';
91  
-  } else {
92  
-    $onlogin_str = '';
93  
-  }
94  
-  return <<<EOF
95  
-<div class="dark">
96  
-  <fb:login-button size="large" background="white" length="short" $onlogin_str>
97  
-  </fb:login-button>
98  
-</div>
99  
-EOF;
100  
-
101  
-}
102  
-
103  
-function get_wpuid_by_fbuid($fbuid) {
104  
-  global $wpdb;
105  
-  $sql = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'fbuid' AND meta_value = %s";
106  
-  $res = $wpdb->get_results($wpdb->prepare($sql, $fbuid), ARRAY_A);
107  
-  if ($res) {
108  
-    return $res['user_id'];
109  
-  } else {
110  
-    return 0;
111  
-  }
112  
-}
113  
-
114  
-define('FBC_ERROR_NO_FB_SESSION', -2);
115  
-define('FBC_ERROR_USERNAME_EXISTS', -1);
116  
-
117  
-function fbc_login_if_necessary() {
118  
-  $fbuid = fbc_facebook_client()->get_loggedin_user();
119  
-  if ($fbuid) {
120  
-    $wpuid = fbc_fbuser_to_wpuser($fbuid);
121  
-    if (!$wpuid) {
122  
-      // There is no wp user associated w/ this fbuid
123  
-
124  
-      $user = wp_get_current_user();
125  
-      $wpuid = $user->ID;
126  
-      if ($wpuid) {
127  
-        // User already has a wordpress account, link to this facebook account
128  
-        update_usermeta($wpuid, 'fbuid', "$fbuid");
129  
-      } else {
130  
-        // Create a new wordpress account
131  
-        $wpuid = fbc_insert_user($fbuid);
132  
-        if ($wpuid === FBC_ERROR_USERNAME_EXISTS) {
133  
-          return FBC_ERROR_USERNAME_EXISTS;
134  
-        }
135  
-      }
136  
-
137  
-    } else {
138  
-      // Already have a linked wordpress account, fall through and set
139  
-      // login cookie
140  
-    }
141  
-
142  
-    wp_set_auth_cookie($wpuid, true, false);
143  
-
144  
-    return $fbuid;
145  
-  } else {
146  
-    return FBC_ERROR_NO_FB_SESSION;
147  
-  }
148  
-}
149  
-
150  
-function get_user_by_meta($meta_key, $meta_value) {
151  
-  global $wpdb;
152  
-  $sql = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '%s' AND meta_value = '%s'";
153  
-  return $wpdb->get_var($wpdb->prepare($sql, $meta_key, $meta_value));
154  
-}
155  
-
156  
-function fbc_fbuser_to_wpuser($fbuid) {
157  
-  return get_user_by_meta('fbuid', $fbuid);
158  
-}
159  
-
160  
-
161  
-function fbc_insert_user($fbuid) {
162  
-
163  
-  $userinfo = fbc_anon_api_client()->users_getInfo(array($fbuid),
164  
-                                              array('name',
165  
-                                              'proxied_email',
166  
-                                              'profile_url'));
167  
-
168  
-  $userinfo = $userinfo[0];
169  
-
170  
-  $fbusername = 'fb' . $fbuid;
171  
-  if (username_exists($fbusername)) {
172  
-    return FBC_ERROR_USERNAME_EXISTS;
173  
-  }
174  
-
175  
-  $userdata = array(
176  
-    'user_pass' => wp_generate_password(),
177  
-    'user_login' => $fbusername,
178  
-    'display_name' => fbc_get_displayname($userinfo),
179  
-    'user_url' => fbc_make_public_url($userinfo),
180  
-    'user_email' => $userinfo['proxied_email']
181  
-  );
182  
-
183  
-  $wpuid = wp_insert_user($userdata);
184  
-  if($wpuid) {
185  
-    update_usermeta($wpuid, 'fbuid', "$fbuid");
186  
-  }
187  
-
188  
-  return $wpuid;
189  
-}
190  
-
191  
-
192  
-?>
29  plugins/wp-fbconnect/config.php
... ...
@@ -1,29 +0,0 @@
1  
-<?php
2  
-
3  
-/* Controls whether the absolutely positioned "Welcome, username"
4  
- window is displayed.  If this is disabled you *must* place equivalent
5  
- information somewhere on your page.  */
6  
-define('FBC_USER_PROFILE_WINDOW', true);
7  
-
8  
-define('FBC_ANONYMOUS_DISPLAYNAME', 'Facebook User');
9  
-
10  
-
11  
-/*
12  
-  In each of the templates below, the first template is for a single
13  
-  story and the second template is for an aggregated story.
14  
- */
15  
-$fbc_one_line_stories = array(
16  
-  '{*actor*} commented on the <a href="{*blog-url*}">{*blog-name*}</a> blog post "<a href="{*post-url*}">{*post-title*}</a>".',
17  
-  '{*actor*} posted comments on <a href="{*blog-url*}">{*blog-name*}</a>.'
18  
-);
19  
-
20  
-
21  
-$fbc_short_story_templates = array(
22  
-  array('template_title' =>
23  
-        '{*actor*} commented on the <a href="{*blog-url*}">{*blog-name*}</a> blog post "<a href="{*post-url*}">{*post-title*}</a>".',
24  
-        'template_body' => ''),
25  
-   array('template_title' =>
26  
-         '{*actor*} posted comments on <a href="{*blog-url*}">{*blog-name*}</a>.',
27  
-         'template_body' => '')
28  
-);
29  
-
465  plugins/wp-fbconnect/facebook-client/facebook.php
... ...
@@ -1,465 +0,0 @@
1  
-<?php
2  
-// Copyright 2004-2008 Facebook. All Rights Reserved.
3  
-//
4  
-// +---------------------------------------------------------------------------+
5  
-// | Facebook Platform PHP5 client                                             |
6  
-// +---------------------------------------------------------------------------+
7  
-// | Copyright (c) 2007 Facebook, Inc.                                         |
8  
-// | All rights reserved.                                                      |
9  
-// |                                                                           |
10  
-// | Redistribution and use in source and binary forms, with or without        |
11  
-// | modification, are permitted provided that the following conditions        |
12  
-// | are met:                                                                  |
13  
-// |                                                                           |
14  
-// | 1. Redistributions of source code must retain the above copyright         |
15  
-// |    notice, this list of conditions and the following disclaimer.          |
16  
-// | 2. Redistributions in binary form must reproduce the above copyright      |
17  
-// |    notice, this list of conditions and the following disclaimer in the    |
18  
-// |    documentation and/or other materials provided with the distribution.   |
19  
-// |                                                                           |
20  
-// | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR      |
21  
-// | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
22  
-// | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.   |
23  
-// | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,          |
24  
-// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT  |
25  
-// | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26  
-// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     |
27  
-// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       |
28  
-// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF  |
29  
-// | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.         |
30  
-// +---------------------------------------------------------------------------+
31  
-// | For help with this library, contact developers-help@facebook.com          |
32  
-// +---------------------------------------------------------------------------+
33  
-//
34  
-include_once 'facebookapi_php5_restlib.php';
35  
-
36  
-define('FACEBOOK_API_VALIDATION_ERROR', 1);
37  
-class Facebook {
38  
-  public $api_client;
39  
-
40  
-  public $api_key;
41  
-  public $secret;
42  
-  public $generate_session_secret;
43  
-  public $session_expires;
44  
-
45  
-  public $fb_params;
46  
-  public $user;
47  
-  public $profile_user;
48  
-  public $canvas_user;
49  
-
50  
-  /*
51  
-   * Create a Facebook client like this:
52  
-   *
53  
-   * $fb = new Facebook(API_KEY, SECRET);
54  
-   *
55  
-   * This will automatically pull in any parameters, validate them against the
56  
-   * session signature, and chuck them in the public $fb_params member variable.
57  
-   *
58  
-   * @param api_key                  your Developer API key
59  
-   * @param secret                   your Developer API secret
60  
-   * @param generate_session_secret  whether to automatically generate a session
61  
-   *                                 if the user doesn't have one, but
62  
-   *                                 there is an auth token present in the url,
63  
-   */
64  
-  public function __construct($api_key, $secret, $generate_session_secret=false) {
65  
-    $this->api_key                 = $api_key;
66  
-    $this->secret                  = $secret;
67  
-    $this->generate_session_secret = $generate_session_secret;
68  
-    $this->api_client = new FacebookRestClient($api_key, $secret);
69  
-
70  
-    $this->validate_fb_params();
71  
-    if (isset($this->fb_params['friends'])) {
72  
-      $this->api_client->friends_list = explode(',', $this->fb_params['friends']);
73  
-    }
74  
-    if (isset($this->fb_params['added'])) {
75  
-      $this->api_client->added = $this->fb_params['added'];
76  
-    }
77  
-    if (isset($this->fb_params['canvas_user'])) {
78  
-      $this->api_client->canvas_user = $this->fb_params['canvas_user'];
79  
-    }
80  
-  }
81  
-
82  
-  /*
83  
-   * Validates that the parameters passed in were sent from Facebook. It does so
84  
-   * by validating that the signature matches one that could only be generated
85  
-   * by using your application's secret key.
86  
-   *
87  
-   * Facebook-provided parameters will come from $_POST, $_GET, or $_COOKIE,
88  
-   * in that order. $_POST and $_GET are always more up-to-date than cookies,
89  
-   * so we prefer those if they are available.
90  
-   *
91  
-   * For nitty-gritty details of when each of these is used, check out
92  
-   * http://wiki.developers.facebook.com/index.php/Verifying_The_Signature
93  
-   *
94  
-   * @param bool  resolve_auth_token  convert an auth token into a session
95  
-   */
96  
-  public function validate_fb_params($resolve_auth_token=true) {
97  
-    $this->fb_params = $this->get_valid_fb_params($_POST, 48*3600, 'fb_sig');
98  
-
99  
-    // note that with preload FQL, it's possible to receive POST params in
100  
-    // addition to GET, so use a different prefix to differentiate them
101  
-    if (!$this->fb_params) {
102  
-      $fb_params = $this->get_valid_fb_params($_GET, 48*3600, 'fb_sig');
103  
-      $fb_post_params = $this->get_valid_fb_params($_POST, 48*3600, 'fb_post_sig');
104  
-      $this->fb_params = array_merge($fb_params, $fb_post_params);
105  
-    }
106  
-
107  
-    // Okay, something came in via POST or GET
108  
-    if ($this->fb_params) {
109  
-      $user               = isset($this->fb_params['user']) ?
110  
-                            $this->fb_params['user'] : null;
111  
-      $this->profile_user = isset($this->fb_params['profile_user']) ?
112  
-                            $this->fb_params['profile_user'] : null;
113  
-      $this->canvas_user  = isset($this->fb_params['canvas_user']) ?
114  
-                            $this->fb_params['canvas_user'] : null;
115  
-
116  
-      if (isset($this->fb_params['session_key'])) {
117  
-        $session_key =  $this->fb_params['session_key'];
118  
-      } else if (isset($this->fb_params['profile_session_key'])) {
119  
-        $session_key =  $this->fb_params['profile_session_key'];
120  
-      } else {
121  
-        $session_key = null;
122  
-      }
123  
-      $expires     = isset($this->fb_params['expires']) ?
124  
-                     $this->fb_params['expires'] : null;
125  
-      $this->set_user($user,
126  
-                      $session_key,
127  
-                      $expires);
128  
-    }
129  
-    // if no Facebook parameters were found in the GET or POST variables,
130  
-    // then fall back to cookies, which may have cached user information
131  
-    // Cookies are also used to receive session data via the Javascript API
132  
-    else if ($cookies =
133  
-             $this->get_valid_fb_params($_COOKIE, null, $this->api_key)) {
134  
-      // use $api_key . '_' as a prefix for the cookies in case there are
135  
-      // multiple facebook clients on the same domain.
136  
-      $expires = isset($cookies['expires']) ? $cookies['expires'] : null;
137  
-      $this->set_user($cookies['user'],
138  
-                      $cookies['session_key'],
139  
-                      $expires);
140  
-    }
141  
-    // finally, if we received no parameters, but the 'auth_token' GET var
142  
-    // is present, then we are in the middle of auth handshake,
143  
-    // so go ahead and create the session
144  
-    else if ($resolve_auth_token && isset($_GET['auth_token']) &&
145  
-             $session = $this->do_get_session($_GET['auth_token'])) {
146  
-      if ($this->generate_session_secret &&
147  
-          !empty($session['secret'])) {
148  
-        $session_secret = $session['secret'];
149  
-      }
150  
-      $this->set_user($session['uid'],
151  
-                      $session['session_key'],
152  
-                      $session['expires'],
153  
-                      $session_secret ? $session_secret : null);
154  
-    }
155  
-
156  
-    return !empty($this->fb_params);
157  
-  }
158  
-
159  
-  // Store a temporary session secret for the current session
160  
-  // for use with the JS client library
161  
-  public function promote_session() {
162  
-    try {
163  
-      $session_secret = $this->api_client->auth_promoteSession();
164  
-      if (!$this->in_fb_canvas()) {
165  
-        $this->set_cookies($this->user, $this->api_client->session_key, $this->session_expires, $session_secret);
166  
-      }
167  
-      return $session_secret;
168  
-    } catch (FacebookRestClientException $e) {
169  
-      // API_EC_PARAM means we don't have a logged in user, otherwise who
170  
-      // knows what it means, so just throw it.
171  
-      if ($e->getCode() != FacebookAPIErrorCodes::API_EC_PARAM) {
172  
-        throw $e;
173  
-      }
174  
-    }
175  
-  }
176  
-
177  
-  public function do_get_session($auth_token) {
178  
-    try {
179  
-      return $this->api_client->auth_getSession($auth_token, $this->generate_session_secret);
180  
-    } catch (FacebookRestClientException $e) {
181  
-      // API_EC_PARAM means we don't have a logged in user, otherwise who
182  
-      // knows what it means, so just throw it.
183  
-      if ($e->getCode() != FacebookAPIErrorCodes::API_EC_PARAM) {
184  
-        throw $e;
185  
-      }
186  
-    }
187  
-  }
188  
-
189  
-  // Invalidate the session currently being used, and clear any state associated with it
190  
-  public function expire_session() {
191  
-    if ($this->api_client->auth_expireSession()) {
192  
-      if (!$this->in_fb_canvas() && isset($_COOKIE[$this->api_key . '_user'])) {
193  
-        $cookies = array('user', 'session_key', 'expires', 'ss');
194  
-        foreach ($cookies as $name) {
195  
-          setcookie($this->api_key . '_' . $name, false, time() - 3600);
196  
-          unset($_COOKIE[$this->api_key . '_' . $name]);
197  
-        }
198  
-        setcookie($this->api_key, false, time() - 3600);
199  
-        unset($_COOKIE[$this->api_key]);
200  
-      }
201  
-
202  
-      // now, clear the rest of the stored state
203  
-      $this->user = 0;
204  
-      $this->api_client->session_key = 0;
205  
-      return true;
206  
-    } else {
207  
-      return false;
208  
-    }
209  
-  }
210  
-
211  
-  public function redirect($url) {
212  
-    if ($this->in_fb_canvas()) {
213  
-      echo '<fb:redirect url="' . $url . '"/>';
214  
-    } else if (preg_match('/^https?:\/\/([^\/]*\.)?facebook\.com(:\d+)?/i', $url)) {
215  
-      // make sure facebook.com url's load in the full frame so that we don't
216  
-      // get a frame within a frame.
217  
-      echo "<script type=\"text/javascript\">\ntop.location.href = \"$url\";\n</script>";
218  
-    } else {
219  
-      header('Location: ' . $url);
220  
-    }
221  
-    exit;
222  
-  }
223  
-
224  
-  public function in_frame() {
225  
-    return isset($this->fb_params['in_canvas']) || isset($this->fb_params['in_iframe']);
226  
-  }
227  
-  public function in_fb_canvas() {
228  
-    return isset($this->fb_params['in_canvas']);
229  
-  }
230  
-
231  
-  public function get_loggedin_user() {
232  
-    return $this->user;
233  
-  }
234  
-
235  
-  public function get_canvas_user() {
236  
-    return $this->canvas_user;
237  
-  }
238  
-
239  
-  public function get_profile_user() {
240  
-    return $this->profile_user;
241  
-  }
242  
-
243  
-  public static function current_url() {
244  
-    return 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
245  
-  }
246  
-
247  
-  // require_add and require_install have been removed.
248  
-  // see http://developer.facebook.com/news.php?blog=1&story=116 for more details
249  
-  public function require_login() {
250  
-    if ($user = $this->get_loggedin_user()) {
251  
-      return $user;
252  
-    }
253  
-    $this->redirect($this->get_login_url(self::current_url(), $this->in_frame()));
254  
-  }
255  
-
256  
-  public function require_frame() {
257  
-    if (!$this->in_frame()) {
258  
-      $this->redirect($this->get_login_url(self::current_url(), true));
259  
-    }
260  
-  }
261  
-
262  
-  public static function get_facebook_url($subdomain='www') {
263  
-    return 'http://' . $subdomain . '.new.facebook.com';
264  
-  }
265  
-
266  
-  public function get_install_url($next=null) {
267  
-    // this was renamed, keeping for compatibility's sake
268  
-    return $this->get_add_url($next);
269  
-  }
270  
-
271  
-  public function get_add_url($next=null) {
272  
-    return self::get_facebook_url().'/add.php?api_key='.$this->api_key .
273  
-      ($next ? '&next=' . urlencode($next) : '');
274  
-  }
275  
-
276  
-  public function get_login_url($next, $canvas) {
277  
-    return self::get_facebook_url().'/login.php?v=1.0&api_key=' . $this->api_key .
278  
-      ($next ? '&next=' . urlencode($next)  : '') .
279  
-      ($canvas ? '&canvas' : '');
280  
-  }
281  
-
282  
-  public function set_user($user, $session_key, $expires=null, $session_secret=null) {
283  
-    if (!$this->in_fb_canvas() && (!isset($_COOKIE[$this->api_key . '_user'])
284  
-                                   || $_COOKIE[$this->api_key . '_user'] != $user)) {
285  
-      $this->set_cookies($user, $session_key, $expires, $session_secret);
286  
-    }
287  
-    $this->user = $user;
288  
-    $this->api_client->session_key = $session_key;
289  
-    $this->session_expires = $expires;
290  
-  }
291  
-
292  
-  public function set_cookies($user, $session_key, $expires=null, $session_secret=null) {
293  
-    $cookies = array();
294  
-    $cookies['user'] = $user;
295  
-    $cookies['session_key'] = $session_key;
296  
-    if ($expires != null) {
297  
-      $cookies['expires'] = $expires;
298  
-    }
299  
-    if ($session_secret != null) {
300  
-      $cookies['ss'] = $session_secret;
301  
-    }
302  
-    foreach ($cookies as $name => $val) {
303  
-      setcookie($this->api_key . '_' . $name, $val, (int)$expires);
304  
-      $_COOKIE[$this->api_key . '_' . $name] = $val;
305  
-    }
306  
-    $sig = self::generate_sig($cookies, $this->secret);
307  
-    setcookie($this->api_key, $sig, (int)$expires);
308  
-    $_COOKIE[$this->api_key] = $sig;
309  
-  }
310  
-
311  
-  /**
312  
-   * Tries to undo the badness of magic quotes as best we can
313  
-   * @param     string   $val   Should come directly from $_GET, $_POST, etc.
314  
-   * @return    string   val without added slashes
315  
-   */
316  
-  public static function no_magic_quotes($val) {
317  
-    if (get_magic_quotes_gpc()) {
318  
-      return stripslashes($val);
319  
-    } else {
320  
-      return $val;
321  
-    }
322  
-  }
323  
-
324  
-  /*
325  
-   * Get the signed parameters that were sent from Facebook. Validates the set
326  
-   * of parameters against the included signature.
327  
-   *
328  
-   * Since Facebook sends data to your callback URL via unsecured means, the
329  
-   * signature is the only way to make sure that the data actually came from
330  
-   * Facebook. So if an app receives a request at the callback URL, it should
331  
-   * always verify the signature that comes with against your own secret key.
332  
-   * Otherwise, it's possible for someone to spoof a request by
333  
-   * pretending to be someone else, i.e.:
334  
-   *      www.your-callback-url.com/?fb_user=10101
335  
-   *
336  
-   * This is done automatically by verify_fb_params.
337  
-   *
338  
-   * @param  assoc  $params     a full array of external parameters.
339  
-   *                            presumed $_GET, $_POST, or $_COOKIE
340  
-   * @param  int    $timeout    number of seconds that the args are good for.
341  
-   *                            Specifically good for forcing cookies to expire.
342  
-   * @param  string $namespace  prefix string for the set of parameters we want
343  
-   *                            to verify. i.e., fb_sig or fb_post_sig
344  
-   *
345  
-   * @return  assoc the subset of parameters containing the given prefix,
346  
-   *                and also matching the signature associated with them.
347  
-   *          OR    an empty array if the params do not validate
348  
-   */
349  
-  public function get_valid_fb_params($params, $timeout=null, $namespace='fb_sig') {
350  
-    $prefix = $namespace . '_';
351  
-    $prefix_len = strlen($prefix);
352  
-    $fb_params = array();
353  
-    if (empty($params)) {
354  
-      return array();
355  
-    }
356  
-
357  
-    foreach ($params as $name => $val) {
358  
-      // pull out only those parameters that match the prefix
359  
-      // note that the signature itself ($params[$namespace]) is not in the list
360  
-      if (strpos($name, $prefix) === 0) {
361  
-        $fb_params[substr($name, $prefix_len)] = self::no_magic_quotes($val);
362  
-      }
363  
-    }
364  
-
365  
-    // validate that the request hasn't expired. this is most likely
366  
-    // for params that come from $_COOKIE
367  
-    if ($timeout && (!isset($fb_params['time']) || time() - $fb_params['time'] > $timeout)) {
368  
-      return array();
369  
-    }
370  
-
371  
-    // validate that the params match the signature
372  
-    $signature = isset($params[$namespace]) ? $params[$namespace] : null;
373  
-    if (!$signature || (!$this->verify_signature($fb_params, $signature))) {
374  
-      return array();
375  
-    }
376  
-    return $fb_params;
377  
-  }
378  
-
379  
-  /*
380  
-   * Validates that a given set of parameters match their signature.
381  
-   * Parameters all match a given input prefix, such as "fb_sig".
382  
-   *
383  
-   * @param $fb_params     an array of all Facebook-sent parameters,
384  
-   *                       not including the signature itself
385  
-   * @param $expected_sig  the expected result to check against
386  
-   */
387  
-  public function verify_signature($fb_params, $expected_sig) {
388  
-    return self::generate_sig($fb_params, $this->secret) == $expected_sig;
389  
-  }
390  
-
391  
-  /*
392  
-   * Generate a signature using the application secret key.
393  
-   *
394  
-   * The only two entities that know your secret key are you and Facebook,
395  
-   * according to the Terms of Service. Since nobody else can generate
396  
-   * the signature, you can rely on it to verify that the information
397  
-   * came from Facebook.
398  
-   *
399  
-   * @param $params_array   an array of all Facebook-sent parameters,
400  
-   *                        NOT INCLUDING the signature itself
401  
-   * @param $secret         your app's secret key
402  
-   *
403  
-   * @return a hash to be checked against the signature provided by Facebook
404  
-   */
405  
-  public static function generate_sig($params_array, $secret) {
406  
-    $str = '';
407  
-
408  
-    ksort($params_array);
409  
-    // Note: make sure that the signature parameter is not already included in
410  
-    //       $params_array.
411  
-    foreach ($params_array as $k=>$v) {
412  
-      $str .= "$k=$v";
413  
-    }
414  
-    $str .= $secret;
415  
-
416  
-    return md5($str);
417  
-  }
418  
-
419  
-  public function encode_validationError($summary, $message) {
420  
-    return json_encode(
421  
-               array('errorCode'    => FACEBOOK_API_VALIDATION_ERROR,
422  
-                     'errorTitle'   => $summary,
423  
-                     'errorMessage' => $message));
424  
-  }
425  
-
426  
-  public function encode_multiFeedStory($feed, $next) {
427  
-    return json_encode(
428  
-               array('method'   => 'multiFeedStory',
429  
-                     'content'  =>
430  
-                     array('next' => $next,
431  
-                           'feed' => $feed)));
432  
-  }
433  
-
434  
-  public function encode_feedStory($feed, $next) {
435  
-    return json_encode(
436  
-               array('method'   => 'feedStory',
437  
-                     'content'  =>
438  
-                     array('next' => $next,
439  
-                           'feed' => $feed)));
440  
-  }
441  
-
442  
-  public function create_templatizedFeedStory($title_template, $title_data=array(),
443  
-                                    $body_template='', $body_data = array(), $body_general=null,
444  
-                                    $image_1=null, $image_1_link=null,
445  
-                                    $image_2=null, $image_2_link=null,
446  
-                                    $image_3=null, $image_3_link=null,
447  
-                                    $image_4=null, $image_4_link=null) {
448  
-    return array('title_template'=> $title_template,
449  
-                 'title_data'   => $title_data,
450  
-                 'body_template'=> $body_template,
451  
-                 'body_data'    => $body_data,
452  
-                 'body_general' => $body_general,
453  
-                 'image_1'      => $image_1,
454  
-                 'image_1_link' => $image_1_link,
455  
-                 'image_2'      => $image_2,
456  
-                 'image_2_link' => $image_2_link,
457  
-                 'image_3'      => $image_3,
458  
-                 'image_3_link' => $image_3_link,
459  
-                 'image_4'      => $image_4,
460  
-                 'image_4_link' => $image_4_link);
461  
-  }
462  
-
463  
-
464  
-}
465  
-
2,082  plugins/wp-fbconnect/facebook-client/facebookapi_php5_restlib.php
... ...
@@ -1,2082 +0,0 @@
1  
-<?php
2  
-//
3  
-// +---------------------------------------------------------------------------+
4  
-// | Facebook Platform PHP5 client                                             |
5  
-// +---------------------------------------------------------------------------+
6  
-// | Copyright (c) 2007-2008 Facebook, Inc.                                    |
7  
-// | All rights reserved.                                                      |
8  
-// |                                                                           |
9  
-// | Redistribution and use in source and binary forms, with or without        |
10  
-// | modification, are permitted provided that the following conditions        |
11  
-// | are met:                                                                  |
12  
-// |                                                                           |
13  
-// | 1. Redistributions of source code must retain the above copyright         |
14  
-// |    notice, this list of conditions and the following disclaimer.          |
15  
-// | 2. Redistributions in binary form must reproduce the above copyright      |
16  
-// |    notice, this list of conditions and the following disclaimer in the    |
17  
-// |    documentation and/or other materials provided with the distribution.   |
18  
-// |                                                                           |
19  
-// | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR      |
20  
-// | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
21  
-// | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.   |
22  
-// | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,          |
23  
-// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT  |
24  
-// | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25  
-// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     |
26  
-// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       |
27  
-// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF  |
28  
-// | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.         |
29  
-// +---------------------------------------------------------------------------+
30  
-// | For help with this library, contact developers-help@facebook.com          |
31  
-// +---------------------------------------------------------------------------+
32  
-//
33  
-
34  
-include_once 'jsonwrapper/jsonwrapper.php';
35  
-class FacebookRestClient {
36  
-  public $secret;
37  
-  public $session_key;
38  
-  public $api_key;
39  
-  public $friends_list; // to save making the friends.get api call, this will get prepopulated on canvas pages
40  
-  public $added;        // to save making the users.isAppAdded api call, this will get prepopulated on canvas pages
41  
-  public $is_user;
42  
-  // we don't pass friends list to iframes, but we want to make
43  
-  // friends_get really simple in the canvas_user (non-logged in) case.
44  
-  // So we use the canvas_user as default arg to friends_get
45  
-  public $canvas_user;
46  
-  public $batch_mode;
47  
-  private $batch_queue;
48  
-  private $call_as_apikey;
49  
-
50  
-  const BATCH_MODE_DEFAULT = 0;
51  
-  const BATCH_MODE_SERVER_PARALLEL = 0;
52  
-  const BATCH_MODE_SERIAL_ONLY = 2;
53  
-
54  
-  /**
55  
-   * Create the client.
56  
-   * @param string $session_key if you haven't gotten a session key yet, leave
57  
-   *                            this as null and then set it later by just
58  
-   *                            directly accessing the $session_key member
59  
-   *                            variable.
60  
-   */
61  
-  public function __construct($api_key, $secret, $session_key=null) {
62  
-    $this->secret       = $secret;
63  
-    $this->session_key  = $session_key;
64  
-    $this->api_key      = $api_key;
65  
-    $this->batch_mode = FacebookRestClient::BATCH_MODE_DEFAULT;
66  
-    $this->last_call_id = 0;
67  
-    $this->call_as_apikey = '';
68  
-      $this->server_addr  = Facebook::get_facebook_url('api') . '/restserver.php';
69  
-    if (!empty($GLOBALS['facebook_config']['debug'])) {
70  
-      $this->cur_id = 0;
71  
-      ?>
72  
-<script type="text/javascript">
73  
-var types = ['params', 'xml', 'php', 'sxml'];
74  
-function getStyle(elem, style) {
75  
-  if (elem.getStyle) {
76  
-    return elem.getStyle(style);
77  
-  } else {
78  
-    return elem.style[style];
79  
-  }
80  
-}
81  
-function setStyle(elem, style, value) {
82  
-  if (elem.setStyle) {
83  
-    elem.setStyle(style, value);
84  
-  } else {
85  
-    elem.style[style] = value;
86  
-  }
87  
-}
88  
-function toggleDisplay(id, type) {
89  
-  for (var i = 0; i < types.length; i++) {
90  
-    var t = types[i];
91  
-    var pre = document.getElementById(t + id);
92  
-    if (pre) {
93  
-      if (t != type || getStyle(pre, 'display') == 'block') {
94  
-        setStyle(pre, 'display', 'none');
95  
-      } else {
96  
-        setStyle(pre, 'display', 'block');
97  
-      }
98  
-    }
99  
-  }
100  
-  return false;
101  
-}
102  
-</script>
103  
-<?php
104  
-    }
105  
-  }
106  
-
107  
-
108  
-  /**
109  
-   * Start a batch operation.
110  
-   */
111  
-  public function begin_batch() {
112  
-    if($this->batch_queue !== null)
113  
-    {
114  
-      throw new FacebookRestClientException(FacebookAPIErrorCodes::API_EC_BATCH_ALREADY_STARTED,
115  
-      FacebookAPIErrorCodes::$api_error_descriptions[FacebookAPIErrorCodes::API_EC_BATCH_ALREADY_STARTED]);
116  
-    }
117  
-
118  
-    $this->batch_queue = array();
119  
-  }
120  
-
121  
-  /*
122  
-   * End current batch operation
123  
-   */
124  
-  public function end_batch() {
125  
-    if($this->batch_queue === null) {
126  
-      throw new FacebookRestClientException(FacebookAPIErrorCodes::API_EC_BATCH_NOT_STARTED,
127  
-      FacebookAPIErrorCodes::$api_error_descriptions[FacebookAPIErrorCodes::API_EC_BATCH_NOT_STARTED]);
128  
-    }
129  
-
130  
-    $this->execute_server_side_batch();
131  
-
132  
-    $this->batch_queue = null;
133  
-  }
134  
-
135  
-
136  
-  private function execute_server_side_batch() {
137  
-
138  
-
139  
-    $item_count = count($this->batch_queue);
140  
-    $method_feed = array();
141  
-    foreach($this->batch_queue as $batch_item) {
142  
-      $method_feed[] = $this->create_post_string($batch_item['m'], $batch_item['p']);
143  
-    }
144  
-
145  
-    $method_feed_json = json_encode($method_feed);
146  
-
147  
-    $serial_only = $this->batch_mode == FacebookRestClient::BATCH_MODE_SERIAL_ONLY ;
148  
-    $params = array('method_feed' => $method_feed_json, 'serial_only' => $serial_only);
149  
-    if ($this->call_as_apikey) {
150  
-      $params['call_as_apikey'] = $this->call_as_apikey;
151  
-    }
152  
-
153  
-    $xml = $this->post_request('batch.run', $params);
154  
-
155  
-    $result = $this->convert_xml_to_result($xml, 'batch.run', $params);
156  
-
157  
-
158  
-    if (is_array($result) && isset($result['error_code'])) {
159  
-      throw new FacebookRestClientException($result['error_msg'], $result['error_code']);
160  
-    }
161  
-
162  
-    for($i = 0; $i < $item_count; $i++) {
163  
-      $batch_item = $this->batch_queue[$i];
164  
-      $batch_item_result_xml = $result[$i];
165  
-      $batch_item_result = $this->convert_xml_to_result($batch_item_result_xml, $batch_item['m'], $batch_item['p']);
166  
-
167  
-      if (is_array($batch_item_result) && isset($batch_item_result['error_code'])) {
168  
-        throw new FacebookRestClientException($batch_item_result['error_msg'], $batch_item_result['error_code']);
169  
-      }
170  
-      $batch_item['r'] = $batch_item_result;
171  
-    }
172  
-  }
173  
-
174  
-  public function begin_permissions_mode($permissions_apikey) {
175  
-    $this->call_as_apikey = $permissions_apikey;
176  
-  }
177  
-
178  
-  public function end_permissions_mode() {
179  
-    $this->call_as_apikey = '';
180  
-  }
181  
-
182  
-  /**
183  
-   * Returns the session information available after current user logs in.
184  
-   * @param string $auth_token the token returned by auth_createToken or
185  
-   *  passed back to your callback_url.
186  
-   * @param bool   $generate_session_secret  whether the session returned should include a session secret
187  
-   *
188  
-   * @return assoc array containing session_key, uid
189  
-   */
190  
-  public function auth_getSession($auth_token, $generate_session_secret=false) {
191  
-    //Check if we are in batch mode
192  
-    if($this->batch_queue === null) {
193  
-      $result = $this->call_method('facebook.auth.getSession',
194  
-          array('auth_token' => $auth_token, 'generate_session_secret' => $generate_session_secret));
195  
-      $this->session_key = $result['session_key'];
196  
-
197  
-    if (!empty($result['secret']) && !$generate_session_secret) {
198  
-      // desktop apps have a special secret
199  
-      $this->secret = $result['secret'];
200  
-    }
201  
-      return $result;
202  
-    }
203  
-  }
204  
-
205  
-  /**
206  
-   * Generates a session specific secret. This is for integration with client-side API calls, such as the
207  
-   * JS library.
208  
-   * @error API_EC_PARAM_SESSION_KEY
209  
-   *        API_EC_PARAM_UNKNOWN
210  
-   * @return session secret for the current promoted session
211  
-   */
212  
-  public function auth_promoteSession() {
213  
-      return $this->call_method('facebook.auth.promoteSession', array());
214  
-  }
215  
-
216  
-  /**
217  
-   * Expires the session that is currently being used.  If this call is successful, no further calls to the
218  
-   * API (which require a session) can be made until a valid session is created.
219  
-   *
220  
-   * @return bool  true if session expiration was successful, false otherwise
221  
-   */
222  
-  public function auth_expireSession() {
223  
-      return $this->call_method('facebook.auth.expireSession', array());
224  
-  }
225  
-
226  
-  /**
227  
-   * Revokes the user's agreement to the Facebook Terms of Service for your application.  If you call this
228  
-   * method for one of your users, you will no longer be able to make API requests on their behalf until
229  
-   * they again authorize your application. Use with care.
230  
-   *
231  
-   *  @return bool  true if revocation succeeds, false otherwise
232  
-   */
233  
-  public function auth_revokeAuthorization() {
234  
-      return $this->call_method('facebook.auth.revokeAuthorization', array());
235  
-  }
236  
-
237  
-  /**
238  
-   * Returns events according to the filters specified.
239  
-   * @param int $uid Optional: User associated with events.
240  
-   *   A null parameter will default to the session user.
241  
-   * @param array $eids Optional: Filter by these event ids.
242  
-   *   A null parameter will get all events for the user.
243  
-   * @param int $start_time Optional: Filter with this unix time as lower bound.
244  
-   *   A null or zero parameter indicates no lower bound.
245  
-   * @param int $end_time Optional: Filter with this UTC as upper bound.
246  
-   *   A null or zero parameter indicates no upper bound.
247  
-   * @param string $rsvp_status Optional: Only show events where the given uid
248  
-   *   has this rsvp status.  This only works if you have specified a value for
249  
-   *   $uid.  Values are as in events.getMembers.  Null indicates to ignore
250  
-   *   rsvp status when filtering.
251  
-   * @return array of events
252  
-   */
253  
-  public function &events_get($uid=null, $eids=null, $start_time=null, $end_time=null, $rsvp_status=null) {
254  
-    return $this->call_method('facebook.events.get',
255  
-        array(
256  
-        'uid' => $uid,
257  
-        'eids' => $eids,
258  
-        'start_time' => $start_time,
259  
-        'end_time' => $end_time,
260  
-        'rsvp_status' => $rsvp_status));
261  
-  }
262  
-
263  
-  /**
264  
-   * Returns membership list data associated with an event
265  
-   * @param int $eid : event id
266  
-   * @return assoc array of four membership lists, with keys 'attending',
267  
-   *  'unsure', 'declined', and 'not_replied'
268  
-   */
269  
-  public function &events_getMembers($eid) {
270  
-    return $this->call_method('facebook.events.getMembers',
271  
-      array('eid' => $eid));
272  
-  }
273  
-
274  
-  /**
275  
-   * RSVPs the current user
276  
-   * @param int $eid : event id
277  
-   * @param string $rsvp_status : 'attending', 'unsure', or 'declined'
278  
-   * @return bool  true if successful
279  
-   */
280  
-  public function &events_rsvp($eid, $rsvp_status) {
281  
-    return $this->call_method('facebook.events.rsvp',
282  
-        array(
283  
-        'eid' => $eid,
284  
-        'rsvp_status' => $rsvp_status));
285  
-  }
286  
-
287  
-  /**
288  
-   * Cancels an event. Only works for events application is admin of.
289  
-   * @param int $eid : event id
290  
-   * @param string $cancel_message : (optional) message to send to members of the event about why it is cancelled
291  
-   * @return bool  true if successful
292  
-   */
293  
-  public function &events_cancel($eid, $cancel_message) {
294  
-    return $this->call_method('facebook.events.cancel',
295  
-        array(
296  
-        'eid' => $eid,
297  
-        'cancel_message' => $cancel_message));
298  
-  }
299  
-
300  
-  /**
301  
-   * Creates an event on behalf of the user is there is a session, otherwise on behalf of app.
302  
-   * Successful creation guarantees app will be admin.
303  
-   * @param assoc array $event_info : json encoded event information
304  
-   * @return int  event id
305  
-   */
306  
-  public function &events_create($event_info) {
307  
-    return $this->call_method('facebook.events.create',
308  
-        array('event_info' => $event_info));
309  
-  }
310  
-
311  
-  /**
312  
-   * Edits an existing event. Only works for events application is admin of.
313  
-   * @param int $eid : event id
314  
-   * @param assoc array $event_info : json encoded event information
315  
-   * @return bool  true if successful
316  
-   */
317  
-  public function &events_edit($eid, $event_info) {
318  
-    return $this->call_method('facebook.events.edit',
319  
-        array(
320  
-        'eid' => $eid,
321  
-        'event_info' => $event_info));
322  
-  }
323  
-
324  
-  /**
325  
-   * Makes an FQL query.  This is a generalized way of accessing all the data
326  
-   * in the API, as an alternative to most of the other method calls.  More
327  
-   * info at http://developers.facebook.com/documentation.php?v=1.0&doc=fql
328  
-   * @param string $query the query to evaluate
329  
-   * @return generalized array representing the results
330  
-   */
331  
-  public function &fql_query($query) {
332  
-    return $this->call_method('facebook.fql.query',
333  
-      array('query' => $query));
334  
-  }
335  
-
336  
-  public function &feed_publishStoryToUser($title, $body,
337  
-                                          $image_1=null, $image_1_link=null,
338  
-                                          $image_2=null, $image_2_link=null,
339  
-                                          $image_3=null, $image_3_link=null,
340  
-                                          $image_4=null, $image_4_link=null) {
341  
-    return $this->call_method('facebook.feed.publishStoryToUser',
342  
-      array('title' => $title,
343  
-            'body' => $body,
344  
-            'image_1' => $image_1,
345  
-            'image_1_link' => $image_1_link,
346  
-            'image_2' => $image_2,
347  
-            'image_2_link' => $image_2_link,
348  
-            'image_3' => $image_3,
349  
-            'image_3_link' => $image_3_link,
350  
-            'image_4' => $image_4,
351  
-            'image_4_link' => $image_4_link));
352  
-  }
353  
-
354  
-  public function &feed_publishActionOfUser($title, $body,
355  
-                                           $image_1=null, $image_1_link=null,
356  
-                                           $image_2=null, $image_2_link=null,
357  
-                                           $image_3=null, $image_3_link=null,
358  
-                                           $image_4=null, $image_4_link=null) {
359  
-    return $this->call_method('facebook.feed.publishActionOfUser',
360  
-      array('title' => $title,
361  
-            'body' => $body,
362  
-            'image_1' => $image_1,
363  
-            'image_1_link' => $image_1_link,
364  
-            'image_2' => $image_2,
365  
-            'image_2_link' => $image_2_link,
366  
-            'image_3' => $image_3,
367  
-            'image_3_link' => $image_3_link,
368  
-            'image_4' => $image_4,
369  
-            'image_4_link' => $image_4_link));
370  
-  }
371  
-
372  
-  public function &feed_publishTemplatizedAction($title_template, $title_data,
373  
-                                                $body_template, $body_data, $body_general,
374  
-                                                $image_1=null, $image_1_link=null,
375  
-                                                $image_2=null, $image_2_link=null,