WordPress.org

Plugin Directory

Changeset 522035


Ignore:
Timestamp:
03/22/12 01:24:19 (2 years ago)
Author:
hd-J
Message:
  1. 0.4.5 - Bug fixes, code cleanup, update to latest FB SDK
Location:
wp-facebook-applications
Files:
2 added
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • wp-facebook-applications/tags/0.4.5/lib/base_facebook.php

    r457938 r522035  
    151151    'api_read'  => 'https://api-read.facebook.com/', 
    152152    'graph'     => 'https://graph.facebook.com/', 
     153    'graph_video' => 'https://graph-video.facebook.com/', 
    153154    'www'       => 'https://www.facebook.com/', 
    154155  ); 
     
    162163 
    163164  /** 
    164    * The Application API Secret. 
     165   * The Application App Secret. 
    165166   * 
    166167   * @var string 
    167168   */ 
    168   protected $apiSecret; 
     169  protected $appSecret; 
    169170 
    170171  /** 
     
    212213  public function __construct($config) { 
    213214    $this->setAppId($config['appId']); 
    214     $this->setApiSecret($config['secret']); 
     215    $this->setAppSecret($config['secret']); 
    215216    if (isset($config['fileUpload'])) { 
    216217      $this->setFileUploadSupport($config['fileUpload']); 
     
    244245 
    245246  /** 
    246    * Set the API Secret. 
    247    * 
    248    * @param string $apiSecret The API Secret 
     247   * Set the App Secret. 
     248   * 
     249   * @param string $apiSecret The App Secret 
    249250   * @return BaseFacebook 
     251   * @deprecated 
    250252   */ 
    251253  public function setApiSecret($apiSecret) { 
    252     $this->apiSecret = $apiSecret; 
     254    $this->setAppSecret($apiSecret); 
    253255    return $this; 
    254256  } 
    255257 
    256258  /** 
    257    * Get the API Secret. 
    258    * 
    259    * @return string the API Secret 
     259   * Set the App Secret. 
     260   * 
     261   * @param string $appSecret The App Secret 
     262   * @return BaseFacebook 
     263   */ 
     264  public function setAppSecret($appSecret) { 
     265    $this->appSecret = $appSecret; 
     266    return $this; 
     267  } 
     268 
     269  /** 
     270   * Get the App Secret. 
     271   * 
     272   * @return string the App Secret 
     273   * @deprecated 
    260274   */ 
    261275  public function getApiSecret() { 
    262     return $this->apiSecret; 
     276    return $this->getAppSecret(); 
     277  } 
     278 
     279  /** 
     280   * Get the App Secret. 
     281   * 
     282   * @return string the App Secret 
     283   */ 
     284  public function getAppSecret() { 
     285    return $this->appSecret; 
    263286  } 
    264287 
     
    279302   * @return boolean true if and only if the server supports file upload. 
    280303   */ 
     304  public function getFileUploadSupport() { 
     305    return $this->fileUploadSupport; 
     306  } 
     307 
     308  /** 
     309   * DEPRECATED! Please use getFileUploadSupport instead. 
     310   * 
     311   * Get the file upload support status. 
     312   * 
     313   * @return boolean true if and only if the server supports file upload. 
     314   */ 
    281315  public function useFileUploadSupport() { 
    282     return $this->fileUploadSupport; 
     316    return $this->getFileUploadSupport(); 
    283317  } 
    284318 
     
    569603 
    570604  /** 
     605   * Constructs and returns the name of the coookie that potentially contain 
     606   * metadata. The cookie is not set by the BaseFacebook class, but it may be 
     607   * set by the JavaScript SDK. 
     608   * 
     609   * @return string the name of the cookie that would house metadata. 
     610   */ 
     611  protected function getMetadataCookieName() { 
     612    return 'fbm_'.$this->getAppId(); 
     613  } 
     614 
     615  /** 
    571616   * Get the authorization code from the query parameters, if it exists, 
    572617   * and otherwise return false to signal no authorization code was 
     
    622667   */ 
    623668  protected function getApplicationAccessToken() { 
    624     return $this->appId.'|'.$this->apiSecret; 
     669    return $this->appId.'|'.$this->appSecret; 
    625670  } 
    626671 
     
    665710          $this->getUrl('graph', '/oauth/access_token'), 
    666711          $params = array('client_id' => $this->getAppId(), 
    667                           'client_secret' => $this->getApiSecret(), 
     712                          'client_secret' => $this->getAppSecret(), 
    668713                          'redirect_uri' => $redirect_uri, 
    669714                          'code' => $code)); 
     
    719764 
    720765  /** 
     766   * Return true if this is video post. 
     767   * 
     768   * @param string $path The path 
     769   * @param string $method The http method (default 'GET') 
     770   * 
     771   * @return boolean true if this is video post 
     772   */ 
     773  protected function isVideoPost($path, $method = 'GET') { 
     774    if ($method == 'POST' && preg_match("/^(\/)(.+)(\/)(videos)$/", $path)) { 
     775      return true; 
     776    } 
     777    return false; 
     778  } 
     779 
     780  /** 
    721781   * Invoke the Graph API. 
    722782   * 
     
    735795    $params['method'] = $method; // method override as we always do a POST 
    736796 
     797    if ($this->isVideoPost($path, $method)) { 
     798      $domainKey = 'graph_video'; 
     799    } else { 
     800      $domainKey = 'graph'; 
     801    } 
     802 
    737803    $result = json_decode($this->_oauthRequest( 
    738       $this->getUrl('graph', $path), 
     804      $this->getUrl($domainKey, $path), 
    739805      $params 
    740806    ), true); 
     
    789855 
    790856    $opts = self::$CURL_OPTS; 
    791     if ($this->useFileUploadSupport()) { 
     857    if ($this->getFileUploadSupport()) { 
    792858      $opts[CURLOPT_POSTFIELDS] = $params; 
    793859    } else { 
     
    852918    // check sig 
    853919    $expected_sig = hash_hmac('sha256', $payload, 
    854                               $this->getApiSecret(), $raw = true); 
     920                              $this->getAppSecret(), $raw = true); 
    855921    if ($sig !== $expected_sig) { 
    856922      self::errorLog('Bad Signed JSON signature!'); 
     
    9691035   */ 
    9701036  protected function getCurrentUrl() { 
    971     if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) 
    972       || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' 
    973     ) { 
     1037    if (isset($_SERVER['HTTPS']) && 
     1038        ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || 
     1039        isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && 
     1040        $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { 
    9741041      $protocol = 'https://'; 
    9751042    } 
     
    10311098   * Analyzes the supplied result to see if it was thrown 
    10321099   * because the access token is no longer valid.  If that is 
    1033    * the case, then the persistent store is cleared. 
     1100   * the case, then we destroy the session. 
    10341101   * 
    10351102   * @param $result array A record storing the error message returned 
     
    10431110        // OAuth 2.0 Draft 10 style 
    10441111      case 'invalid_token': 
     1112        // REST server errors are just Exceptions 
     1113      case 'Exception': 
    10451114        $message = $e->getMessage(); 
    1046       if ((strpos($message, 'Error validating access token') !== false) || 
    1047           (strpos($message, 'Invalid OAuth access token') !== false)) { 
    1048         $this->setAccessToken(null); 
    1049         $this->user = 0; 
    1050         $this->clearAllPersistentData(); 
    1051       } 
     1115        if ((strpos($message, 'Error validating access token') !== false) || 
     1116            (strpos($message, 'Invalid OAuth access token') !== false) || 
     1117            (strpos($message, 'An active access token must be used') !== false) 
     1118        ) { 
     1119          $this->destroySession(); 
     1120        } 
     1121        break; 
    10521122    } 
    10531123 
     
    10891159   */ 
    10901160  public function destroySession() { 
    1091     $this->setAccessToken(null); 
    1092     $this->user = 0; 
     1161    $this->accessToken = null; 
     1162    $this->signedRequest = null; 
     1163    $this->user = null; 
    10931164    $this->clearAllPersistentData(); 
     1165 
     1166    // Javascript sets a cookie that will be used in getSignedRequest that we 
     1167    // need to clear if we can 
     1168    $cookie_name = $this->getSignedRequestCookieName(); 
     1169    if (array_key_exists($cookie_name, $_COOKIE)) { 
     1170      unset($_COOKIE[$cookie_name]); 
     1171      if (!headers_sent()) { 
     1172        // The base domain is stored in the metadata cookie if not we fallback 
     1173        // to the current hostname 
     1174        $base_domain = '.'. $_SERVER['HTTP_HOST']; 
     1175 
     1176        $metadata = $this->getMetadataCookie(); 
     1177        if (array_key_exists('base_domain', $metadata) && 
     1178            !empty($metadata['base_domain'])) { 
     1179          $base_domain = $metadata['base_domain']; 
     1180        } 
     1181 
     1182        setcookie($cookie_name, '', 0, '/', $base_domain); 
     1183      } else { 
     1184        self::errorLog( 
     1185          'There exists a cookie that we wanted to clear that we couldn\'t '. 
     1186          'clear because headers was already sent. Make sure to do the first '. 
     1187          'API call before outputing anything' 
     1188        ); 
     1189      } 
     1190    } 
     1191  } 
     1192 
     1193  /** 
     1194   * Parses the metadata cookie that our Javascript API set 
     1195   * 
     1196   * @return  an array mapping key to value 
     1197   */ 
     1198  protected function getMetadataCookie() { 
     1199    $cookie_name = $this->getMetadataCookieName(); 
     1200    if (!array_key_exists($cookie_name, $_COOKIE)) { 
     1201      return array(); 
     1202    } 
     1203 
     1204    // The cookie value can be wrapped in "-characters so remove them 
     1205    $cookie_value = trim($_COOKIE[$cookie_name], '"'); 
     1206 
     1207    if (empty($cookie_value)) { 
     1208      return array(); 
     1209    } 
     1210 
     1211    $parts = explode('&', $cookie_value); 
     1212    $metadata = array(); 
     1213    foreach ($parts as $part) { 
     1214      $pair = explode('=', $part, 2); 
     1215      if (!empty($pair[0])) { 
     1216        $metadata[urldecode($pair[0])] = 
     1217          (count($pair) > 1) ? urldecode($pair[1]) : ''; 
     1218      } 
     1219    } 
     1220 
     1221    return $metadata; 
    10941222  } 
    10951223 
  • wp-facebook-applications/tags/0.4.5/lib/facebook.php

    r457935 r522035  
    3434   */ 
    3535  public function __construct($config) { 
    36     if (!session_id()) { 
    37       session_start(); 
    38     } 
     36    @session_start(); 
    3937    parent::__construct($config); 
    4038  } 
  • wp-facebook-applications/tags/0.4.5/readme.txt

    r494393 r522035  
    44Tags: facebook, application, campaign, tab, custom post type, custom fields 
    55Requires at least: 3.0 
    6 Tested up to: 3.3 
    7 Stable tag: 0.4.4 
     6Tested up to: 3.4 
     7Stable tag: 0.4.5 
    88 
    99Create custom tabs for your Facebook pages, hosted on your WordPress blog. 
     
    2323This plugin is a work in progress. Do not hesitate to send me your remarks, suggestions and ideas for the future version of this plugin. 
    2424 
    25 Please note that this plugin uses the [Facebook PHP SDK](http://github.com/facebook/php-sdk "Facebook PHP SDK") 
     25Please note that this plugin uses the [Facebook PHP SDK](https://github.com/facebook/facebook-php-sdk "Facebook PHP SDK") 
    2626 
    2727== Installation == 
     
    5555= When viewing my application tab on Facebook, I get a blank page, or a message telling me to switch to a HTTPS connection = 
    5656 
    57 The only way to solve the issue is to buy an SSL certificate for your domain, and once set, fill in the secure URL for your tab in the applications settings. 
     57You MUST have an SSL certificate for your domain, and once set, fill in the secure URL for your tab in the applications settings. You cannot create Facebook applications without it. 
    5858 
    5959= How do I add the application I just created to my page? = 
     
    6262 
    6363== Changelog == 
     64 
     65= 0.4.5 = 
     66* Update to the latest version of Facebook PHP SDK 
     67* Update to the latest recommendations of Facebook for SDK asynchronous call 
     68* Change flush rewrite rules. Now flushing only on plugin activation  
     69* Fix WP_CONFIG warnings 
     70* Fixes session_start issue (headers already sent problem for some users) 
    6471 
    6572= 0.4.4 = 
  • wp-facebook-applications/tags/0.4.5/template.php

    r457935 r522035  
    44 */ 
    55?> 
    6 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/" <?php language_attributes(); ?> > 
     6<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/" <?php language_attributes(); ?>> 
    77<head> 
    88<meta charset="<?php bloginfo( 'charset' ); ?>" /> 
     
    8383 
    8484<div id="fb-root"></div> 
    85     <script> 
    86       window.fbAsyncInit = function() { 
    87         FB.init({ 
    88           appId   : '<?php echo $facebook->getAppId(); ?>', 
    89           session : <?php echo json_encode($session); ?>, // don't refetch the session when PHP already has it 
    90           status  : true, // check login status 
    91           cookie  : true, // enable cookies to allow the server to access the session 
    92           xfbml   : true, // parse XFBML 
    93           oauth   : true 
    94         }); 
    95  
    96         // whenever the user logs in, we refresh the page 
    97         FB.Event.subscribe('auth.login', function() { 
    98           window.location.reload(); 
    99         }); 
    100          
    101         // Auto resize of the page 
    102         FB.Canvas.setAutoResize(); 
    103       }; 
    104        
    105       // Do things that will sometimes call sizeChangeCallback() 
    106       function sizeChangeCallback() { 
     85    <script type="text/javascript"> 
     86        window.fbAsyncInit = function() { 
     87            FB.init({ 
     88                appId      : '<?php echo $facebook->getAppId(); ?>', 
     89                channelUrl : '<?php echo plugins_url( 'wp-facebook-applications/lib/channel.php' , __FILE__ ); ?>', // Channel File 
     90                session    : <?php echo json_encode($session); ?>, // don't refetch the session when PHP already has it 
     91                status     : true, // check login status 
     92                cookie     : true, // enable cookies to allow the server to access the session 
     93                xfbml      : true, // parse XFBML 
     94                oauth      : true 
     95            }); 
     96         
     97            // whenever the user logs in, we refresh the page 
     98            FB.Event.subscribe('auth.login', function() { 
     99                window.location.reload(); 
     100            }); 
     101             
     102            // Auto resize of the page 
    107103            FB.Canvas.setAutoResize(); 
    108       } 
    109  
    110       (function() { 
    111         var e = document.createElement('script'); 
    112         e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; 
    113         e.async = true; 
    114         document.getElementById('fb-root').appendChild(e); 
    115       }()); 
    116     </script>     
     104        }; 
     105             
     106        // Do things that will sometimes call sizeChangeCallback() 
     107        function sizeChangeCallback() { 
     108            FB.Canvas.setAutoResize(); 
     109        } 
     110         
     111        // Load SDK asynchronously 
     112        (function(d){ 
     113            var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
     114            if (d.getElementById(id)) {return;} 
     115            js = d.createElement('script'); js.id = id; js.async = true; 
     116            js.src = "//connect.facebook.net/en_US/all.js"; 
     117            ref.parentNode.insertBefore(js, ref); 
     118        }(document)); 
     119    </script> 
    117120 
    118121<?php wp_footer(); ?> 
  • wp-facebook-applications/tags/0.4.5/wp-fb-applications.php

    r494393 r522035  
    22/* 
    33Plugin Name: WP-Facebook applications 
    4 Version: 0.4.4 
    5 Plugin URI: http://www.werewp.com/my-plugins/wp-facebook-applications/ 
     4Version: 0.4.5 
     5Plugin URI: http://jeremyherve.com/extension-wp-facebook-applications/ 
    66Description: Create custom tabs for your Facebook pages, hosted on your WordPress blog. 
    77Author: Jeremy Herve 
    88Author URI: http://jeremyherve.com 
    99License: GPL2 
    10 */ 
    11 /*  Copyright 2011 Jeremy Herve (email : jeremy@jeremyherve.com) 
    12  
    13     This program is free software; you can redistribute it and/or modify 
    14     it under the terms of the GNU General Public License, version 2, as  
    15     published by the Free Software Foundation. 
    16  
    17     This program is distributed in the hope that it will be useful, 
    18     but WITHOUT ANY WARRANTY; without even the implied warranty of 
    19     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    20     GNU General Public License for more details. 
    21  
    22     You should have received a copy of the GNU General Public License 
    23     along with this program; if not, write to the Free Software 
    24     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    2510*/ 
    2611 
     
    6146        ) 
    6247    ); 
     48} 
     49add_action( 'init', 'werewp_fbapp_post_type' ); 
     50 
     51// Flush rewrite rules when the plugin is activated 
     52function werewp_flush_rewrite() { 
    6353    flush_rewrite_rules(); 
    6454} 
    65 add_action( 'init', 'werewp_fbapp_post_type' ); 
     55register_activation_hook( __FILE__, 'werewp_flush_rewrite' ); 
    6656 
    6757// Add support for thumbnails 
     
    10292function werewp_fbappappparameters() { 
    10393    global $post; 
    104     $custom = get_post_custom($post->ID); 
    105     $appid = $custom['appid'][0]; 
    106     $appsecret = $custom['appsecret'][0]; 
    107     $fbcomments = $custom['fbcomments'][0]; 
     94     
     95    if (isset($post)) { 
     96        $custom = get_post_custom($post->ID); 
     97    } 
    10898    ?> 
    10999    <h3><?php _e( 'Create your application on Facebook', 'werewpfbapps' ); ?></h3> 
     
    114104    <p><?php _e( 'You now have the necessary information to fill in the parameters below:', 'werewpfbapps' ); ?></p> 
    115105    <p><label><strong><?php _e( 'Application ID:', 'werewpfbapps' ); ?></strong></label><br /> 
    116     <textarea cols="50" rows="1" name="appid"><?php echo $appid; ?></textarea></p> 
     106    <textarea cols="50" rows="1" name="appid"><?php if( isset( $custom["appid"][0] ) ) { print $custom["appid"][0]; } ?></textarea></p> 
    117107    <p><label><strong><?php _e( 'Application Secret:', 'werewpfbapps' ); ?></strong></label><br /> 
    118     <textarea cols="50" rows="1" name="appsecret"><?php echo $appsecret; ?></textarea></p> 
     108    <textarea cols="50" rows="1" name="appsecret"><?php if( isset( $custom["appsecret"][0] ) ) { print $custom["appsecret"][0]; } ?></textarea></p> 
    119109    <p><label><strong><?php _e( 'Number of Facebook comments displayed</strong> (leave empty if you do not wish to have this feature enabled):', 'werewpfbapps' ); ?></label><br /> 
    120     <textarea cols="1" rows="1" name="fbcomments"><?php echo $fbcomments; ?></textarea></p> 
     110    <textarea cols="1" rows="1" name="fbcomments"><?php if( isset( $custom["fbcomments"][0] ) ) { print $custom["fbcomments"][0]; } ?></textarea></p> 
    121111    <h3><?php _e( 'Choose the image displayed to the non-fans of your page', 'werewpfbapps' ); ?></h3> 
    122112    <p><?php _e( 'Facebook users who are not fans of your page will see a single image, that you input in the <strong>Featured image</strong> area of this page.<br/>If you don\'t want any specific content for the non-fans, simply leave the Featured Image empty, and all viewers will see all the content.', 'werewpfbapps' ); ?></p> 
     
    131121    global $post; 
    132122 
    133     if ( $post->post_type == 'werewp_fbapp' ) { 
     123    if (isset($post) && $post->post_type == 'werewp_fbapp') { 
    134124        update_post_meta($post->ID, 'appid', $_POST['appid']); 
    135125        update_post_meta($post->ID, 'appsecret', $_POST['appsecret']); 
  • wp-facebook-applications/trunk/lib/base_facebook.php

    r457938 r522035  
    151151    'api_read'  => 'https://api-read.facebook.com/', 
    152152    'graph'     => 'https://graph.facebook.com/', 
     153    'graph_video' => 'https://graph-video.facebook.com/', 
    153154    'www'       => 'https://www.facebook.com/', 
    154155  ); 
     
    162163 
    163164  /** 
    164    * The Application API Secret. 
     165   * The Application App Secret. 
    165166   * 
    166167   * @var string 
    167168   */ 
    168   protected $apiSecret; 
     169  protected $appSecret; 
    169170 
    170171  /** 
     
    212213  public function __construct($config) { 
    213214    $this->setAppId($config['appId']); 
    214     $this->setApiSecret($config['secret']); 
     215    $this->setAppSecret($config['secret']); 
    215216    if (isset($config['fileUpload'])) { 
    216217      $this->setFileUploadSupport($config['fileUpload']); 
     
    244245 
    245246  /** 
    246    * Set the API Secret. 
    247    * 
    248    * @param string $apiSecret The API Secret 
     247   * Set the App Secret. 
     248   * 
     249   * @param string $apiSecret The App Secret 
    249250   * @return BaseFacebook 
     251   * @deprecated 
    250252   */ 
    251253  public function setApiSecret($apiSecret) { 
    252     $this->apiSecret = $apiSecret; 
     254    $this->setAppSecret($apiSecret); 
    253255    return $this; 
    254256  } 
    255257 
    256258  /** 
    257    * Get the API Secret. 
    258    * 
    259    * @return string the API Secret 
     259   * Set the App Secret. 
     260   * 
     261   * @param string $appSecret The App Secret 
     262   * @return BaseFacebook 
     263   */ 
     264  public function setAppSecret($appSecret) { 
     265    $this->appSecret = $appSecret; 
     266    return $this; 
     267  } 
     268 
     269  /** 
     270   * Get the App Secret. 
     271   * 
     272   * @return string the App Secret 
     273   * @deprecated 
    260274   */ 
    261275  public function getApiSecret() { 
    262     return $this->apiSecret; 
     276    return $this->getAppSecret(); 
     277  } 
     278 
     279  /** 
     280   * Get the App Secret. 
     281   * 
     282   * @return string the App Secret 
     283   */ 
     284  public function getAppSecret() { 
     285    return $this->appSecret; 
    263286  } 
    264287 
     
    279302   * @return boolean true if and only if the server supports file upload. 
    280303   */ 
     304  public function getFileUploadSupport() { 
     305    return $this->fileUploadSupport; 
     306  } 
     307 
     308  /** 
     309   * DEPRECATED! Please use getFileUploadSupport instead. 
     310   * 
     311   * Get the file upload support status. 
     312   * 
     313   * @return boolean true if and only if the server supports file upload. 
     314   */ 
    281315  public function useFileUploadSupport() { 
    282     return $this->fileUploadSupport; 
     316    return $this->getFileUploadSupport(); 
    283317  } 
    284318 
     
    569603 
    570604  /** 
     605   * Constructs and returns the name of the coookie that potentially contain 
     606   * metadata. The cookie is not set by the BaseFacebook class, but it may be 
     607   * set by the JavaScript SDK. 
     608   * 
     609   * @return string the name of the cookie that would house metadata. 
     610   */ 
     611  protected function getMetadataCookieName() { 
     612    return 'fbm_'.$this->getAppId(); 
     613  } 
     614 
     615  /** 
    571616   * Get the authorization code from the query parameters, if it exists, 
    572617   * and otherwise return false to signal no authorization code was 
     
    622667   */ 
    623668  protected function getApplicationAccessToken() { 
    624     return $this->appId.'|'.$this->apiSecret; 
     669    return $this->appId.'|'.$this->appSecret; 
    625670  } 
    626671 
     
    665710          $this->getUrl('graph', '/oauth/access_token'), 
    666711          $params = array('client_id' => $this->getAppId(), 
    667                           'client_secret' => $this->getApiSecret(), 
     712                          'client_secret' => $this->getAppSecret(), 
    668713                          'redirect_uri' => $redirect_uri, 
    669714                          'code' => $code)); 
     
    719764 
    720765  /** 
     766   * Return true if this is video post. 
     767   * 
     768   * @param string $path The path 
     769   * @param string $method The http method (default 'GET') 
     770   * 
     771   * @return boolean true if this is video post 
     772   */ 
     773  protected function isVideoPost($path, $method = 'GET') { 
     774    if ($method == 'POST' && preg_match("/^(\/)(.+)(\/)(videos)$/", $path)) { 
     775      return true; 
     776    } 
     777    return false; 
     778  } 
     779 
     780  /** 
    721781   * Invoke the Graph API. 
    722782   * 
     
    735795    $params['method'] = $method; // method override as we always do a POST 
    736796 
     797    if ($this->isVideoPost($path, $method)) { 
     798      $domainKey = 'graph_video'; 
     799    } else { 
     800      $domainKey = 'graph'; 
     801    } 
     802 
    737803    $result = json_decode($this->_oauthRequest( 
    738       $this->getUrl('graph', $path), 
     804      $this->getUrl($domainKey, $path), 
    739805      $params 
    740806    ), true); 
     
    789855 
    790856    $opts = self::$CURL_OPTS; 
    791     if ($this->useFileUploadSupport()) { 
     857    if ($this->getFileUploadSupport()) { 
    792858      $opts[CURLOPT_POSTFIELDS] = $params; 
    793859    } else { 
     
    852918    // check sig 
    853919    $expected_sig = hash_hmac('sha256', $payload, 
    854                               $this->getApiSecret(), $raw = true); 
     920                              $this->getAppSecret(), $raw = true); 
    855921    if ($sig !== $expected_sig) { 
    856922      self::errorLog('Bad Signed JSON signature!'); 
     
    9691035   */ 
    9701036  protected function getCurrentUrl() { 
    971     if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) 
    972       || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' 
    973     ) { 
     1037    if (isset($_SERVER['HTTPS']) && 
     1038        ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || 
     1039        isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && 
     1040        $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { 
    9741041      $protocol = 'https://'; 
    9751042    } 
     
    10311098   * Analyzes the supplied result to see if it was thrown 
    10321099   * because the access token is no longer valid.  If that is 
    1033    * the case, then the persistent store is cleared. 
     1100   * the case, then we destroy the session. 
    10341101   * 
    10351102   * @param $result array A record storing the error message returned 
     
    10431110        // OAuth 2.0 Draft 10 style 
    10441111      case 'invalid_token': 
     1112        // REST server errors are just Exceptions 
     1113      case 'Exception': 
    10451114        $message = $e->getMessage(); 
    1046       if ((strpos($message, 'Error validating access token') !== false) || 
    1047           (strpos($message, 'Invalid OAuth access token') !== false)) { 
    1048         $this->setAccessToken(null); 
    1049         $this->user = 0; 
    1050         $this->clearAllPersistentData(); 
    1051       } 
     1115        if ((strpos($message, 'Error validating access token') !== false) || 
     1116            (strpos($message, 'Invalid OAuth access token') !== false) || 
     1117            (strpos($message, 'An active access token must be used') !== false) 
     1118        ) { 
     1119          $this->destroySession(); 
     1120        } 
     1121        break; 
    10521122    } 
    10531123 
     
    10891159   */ 
    10901160  public function destroySession() { 
    1091     $this->setAccessToken(null); 
    1092     $this->user = 0; 
     1161    $this->accessToken = null; 
     1162    $this->signedRequest = null; 
     1163    $this->user = null; 
    10931164    $this->clearAllPersistentData(); 
     1165 
     1166    // Javascript sets a cookie that will be used in getSignedRequest that we 
     1167    // need to clear if we can 
     1168    $cookie_name = $this->getSignedRequestCookieName(); 
     1169    if (array_key_exists($cookie_name, $_COOKIE)) { 
     1170      unset($_COOKIE[$cookie_name]); 
     1171      if (!headers_sent()) { 
     1172        // The base domain is stored in the metadata cookie if not we fallback 
     1173        // to the current hostname 
     1174        $base_domain = '.'. $_SERVER['HTTP_HOST']; 
     1175 
     1176        $metadata = $this->getMetadataCookie(); 
     1177        if (array_key_exists('base_domain', $metadata) && 
     1178            !empty($metadata['base_domain'])) { 
     1179          $base_domain = $metadata['base_domain']; 
     1180        } 
     1181 
     1182        setcookie($cookie_name, '', 0, '/', $base_domain); 
     1183      } else { 
     1184        self::errorLog( 
     1185          'There exists a cookie that we wanted to clear that we couldn\'t '. 
     1186          'clear because headers was already sent. Make sure to do the first '. 
     1187          'API call before outputing anything' 
     1188        ); 
     1189      } 
     1190    } 
     1191  } 
     1192 
     1193  /** 
     1194   * Parses the metadata cookie that our Javascript API set 
     1195   * 
     1196   * @return  an array mapping key to value 
     1197   */ 
     1198  protected function getMetadataCookie() { 
     1199    $cookie_name = $this->getMetadataCookieName(); 
     1200    if (!array_key_exists($cookie_name, $_COOKIE)) { 
     1201      return array(); 
     1202    } 
     1203 
     1204    // The cookie value can be wrapped in "-characters so remove them 
     1205    $cookie_value = trim($_COOKIE[$cookie_name], '"'); 
     1206 
     1207    if (empty($cookie_value)) { 
     1208      return array(); 
     1209    } 
     1210 
     1211    $parts = explode('&', $cookie_value); 
     1212    $metadata = array(); 
     1213    foreach ($parts as $part) { 
     1214      $pair = explode('=', $part, 2); 
     1215      if (!empty($pair[0])) { 
     1216        $metadata[urldecode($pair[0])] = 
     1217          (count($pair) > 1) ? urldecode($pair[1]) : ''; 
     1218      } 
     1219    } 
     1220 
     1221    return $metadata; 
    10941222  } 
    10951223 
  • wp-facebook-applications/trunk/lib/facebook.php

    r457935 r522035  
    3434   */ 
    3535  public function __construct($config) { 
    36     if (!session_id()) { 
    37       session_start(); 
    38     } 
     36    @session_start(); 
    3937    parent::__construct($config); 
    4038  } 
  • wp-facebook-applications/trunk/readme.txt

    r494393 r522035  
    44Tags: facebook, application, campaign, tab, custom post type, custom fields 
    55Requires at least: 3.0 
    6 Tested up to: 3.3 
    7 Stable tag: 0.4.4 
     6Tested up to: 3.4 
     7Stable tag: 0.4.5 
    88 
    99Create custom tabs for your Facebook pages, hosted on your WordPress blog. 
     
    2323This plugin is a work in progress. Do not hesitate to send me your remarks, suggestions and ideas for the future version of this plugin. 
    2424 
    25 Please note that this plugin uses the [Facebook PHP SDK](http://github.com/facebook/php-sdk "Facebook PHP SDK") 
     25Please note that this plugin uses the [Facebook PHP SDK](https://github.com/facebook/facebook-php-sdk "Facebook PHP SDK") 
    2626 
    2727== Installation == 
     
    5555= When viewing my application tab on Facebook, I get a blank page, or a message telling me to switch to a HTTPS connection = 
    5656 
    57 The only way to solve the issue is to buy an SSL certificate for your domain, and once set, fill in the secure URL for your tab in the applications settings. 
     57You MUST have an SSL certificate for your domain, and once set, fill in the secure URL for your tab in the applications settings. You cannot create Facebook applications without it. 
    5858 
    5959= How do I add the application I just created to my page? = 
     
    6262 
    6363== Changelog == 
     64 
     65= 0.4.5 = 
     66* Update to the latest version of Facebook PHP SDK 
     67* Update to the latest recommendations of Facebook for SDK asynchronous call 
     68* Change flush rewrite rules. Now flushing only on plugin activation  
     69* Fix WP_CONFIG warnings 
     70* Fixes session_start issue (headers already sent problem for some users) 
    6471 
    6572= 0.4.4 = 
  • wp-facebook-applications/trunk/template.php

    r457935 r522035  
    44 */ 
    55?> 
    6 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/" <?php language_attributes(); ?> > 
     6<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/" <?php language_attributes(); ?>> 
    77<head> 
    88<meta charset="<?php bloginfo( 'charset' ); ?>" /> 
     
    8383 
    8484<div id="fb-root"></div> 
    85     <script> 
    86       window.fbAsyncInit = function() { 
    87         FB.init({ 
    88           appId   : '<?php echo $facebook->getAppId(); ?>', 
    89           session : <?php echo json_encode($session); ?>, // don't refetch the session when PHP already has it 
    90           status  : true, // check login status 
    91           cookie  : true, // enable cookies to allow the server to access the session 
    92           xfbml   : true, // parse XFBML 
    93           oauth   : true 
    94         }); 
    95  
    96         // whenever the user logs in, we refresh the page 
    97         FB.Event.subscribe('auth.login', function() { 
    98           window.location.reload(); 
    99         }); 
    100          
    101         // Auto resize of the page 
    102         FB.Canvas.setAutoResize(); 
    103       }; 
    104        
    105       // Do things that will sometimes call sizeChangeCallback() 
    106       function sizeChangeCallback() { 
     85    <script type="text/javascript"> 
     86        window.fbAsyncInit = function() { 
     87            FB.init({ 
     88                appId      : '<?php echo $facebook->getAppId(); ?>', 
     89                channelUrl : '<?php echo plugins_url( 'wp-facebook-applications/lib/channel.php' , __FILE__ ); ?>', // Channel File 
     90                session    : <?php echo json_encode($session); ?>, // don't refetch the session when PHP already has it 
     91                status     : true, // check login status 
     92                cookie     : true, // enable cookies to allow the server to access the session 
     93                xfbml      : true, // parse XFBML 
     94                oauth      : true 
     95            }); 
     96         
     97            // whenever the user logs in, we refresh the page 
     98            FB.Event.subscribe('auth.login', function() { 
     99                window.location.reload(); 
     100            }); 
     101             
     102            // Auto resize of the page 
    107103            FB.Canvas.setAutoResize(); 
    108       } 
    109  
    110       (function() { 
    111         var e = document.createElement('script'); 
    112         e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; 
    113         e.async = true; 
    114         document.getElementById('fb-root').appendChild(e); 
    115       }()); 
    116     </script>     
     104        }; 
     105             
     106        // Do things that will sometimes call sizeChangeCallback() 
     107        function sizeChangeCallback() { 
     108            FB.Canvas.setAutoResize(); 
     109        } 
     110         
     111        // Load SDK asynchronously 
     112        (function(d){ 
     113            var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
     114            if (d.getElementById(id)) {return;} 
     115            js = d.createElement('script'); js.id = id; js.async = true; 
     116            js.src = "//connect.facebook.net/en_US/all.js"; 
     117            ref.parentNode.insertBefore(js, ref); 
     118        }(document)); 
     119    </script> 
    117120 
    118121<?php wp_footer(); ?> 
  • wp-facebook-applications/trunk/wp-fb-applications.php

    r494393 r522035  
    22/* 
    33Plugin Name: WP-Facebook applications 
    4 Version: 0.4.4 
    5 Plugin URI: http://www.werewp.com/my-plugins/wp-facebook-applications/ 
     4Version: 0.4.5 
     5Plugin URI: http://jeremyherve.com/extension-wp-facebook-applications/ 
    66Description: Create custom tabs for your Facebook pages, hosted on your WordPress blog. 
    77Author: Jeremy Herve 
    88Author URI: http://jeremyherve.com 
    99License: GPL2 
    10 */ 
    11 /*  Copyright 2011 Jeremy Herve (email : jeremy@jeremyherve.com) 
    12  
    13     This program is free software; you can redistribute it and/or modify 
    14     it under the terms of the GNU General Public License, version 2, as  
    15     published by the Free Software Foundation. 
    16  
    17     This program is distributed in the hope that it will be useful, 
    18     but WITHOUT ANY WARRANTY; without even the implied warranty of 
    19     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    20     GNU General Public License for more details. 
    21  
    22     You should have received a copy of the GNU General Public License 
    23     along with this program; if not, write to the Free Software 
    24     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    2510*/ 
    2611 
     
    6146        ) 
    6247    ); 
     48} 
     49add_action( 'init', 'werewp_fbapp_post_type' ); 
     50 
     51// Flush rewrite rules when the plugin is activated 
     52function werewp_flush_rewrite() { 
    6353    flush_rewrite_rules(); 
    6454} 
    65 add_action( 'init', 'werewp_fbapp_post_type' ); 
     55register_activation_hook( __FILE__, 'werewp_flush_rewrite' ); 
    6656 
    6757// Add support for thumbnails 
     
    10292function werewp_fbappappparameters() { 
    10393    global $post; 
    104     $custom = get_post_custom($post->ID); 
    105     $appid = $custom['appid'][0]; 
    106     $appsecret = $custom['appsecret'][0]; 
    107     $fbcomments = $custom['fbcomments'][0]; 
     94     
     95    if (isset($post)) { 
     96        $custom = get_post_custom($post->ID); 
     97    } 
    10898    ?> 
    10999    <h3><?php _e( 'Create your application on Facebook', 'werewpfbapps' ); ?></h3> 
     
    114104    <p><?php _e( 'You now have the necessary information to fill in the parameters below:', 'werewpfbapps' ); ?></p> 
    115105    <p><label><strong><?php _e( 'Application ID:', 'werewpfbapps' ); ?></strong></label><br /> 
    116     <textarea cols="50" rows="1" name="appid"><?php echo $appid; ?></textarea></p> 
     106    <textarea cols="50" rows="1" name="appid"><?php if( isset( $custom["appid"][0] ) ) { print $custom["appid"][0]; } ?></textarea></p> 
    117107    <p><label><strong><?php _e( 'Application Secret:', 'werewpfbapps' ); ?></strong></label><br /> 
    118     <textarea cols="50" rows="1" name="appsecret"><?php echo $appsecret; ?></textarea></p> 
     108    <textarea cols="50" rows="1" name="appsecret"><?php if( isset( $custom["appsecret"][0] ) ) { print $custom["appsecret"][0]; } ?></textarea></p> 
    119109    <p><label><strong><?php _e( 'Number of Facebook comments displayed</strong> (leave empty if you do not wish to have this feature enabled):', 'werewpfbapps' ); ?></label><br /> 
    120     <textarea cols="1" rows="1" name="fbcomments"><?php echo $fbcomments; ?></textarea></p> 
     110    <textarea cols="1" rows="1" name="fbcomments"><?php if( isset( $custom["fbcomments"][0] ) ) { print $custom["fbcomments"][0]; } ?></textarea></p> 
    121111    <h3><?php _e( 'Choose the image displayed to the non-fans of your page', 'werewpfbapps' ); ?></h3> 
    122112    <p><?php _e( 'Facebook users who are not fans of your page will see a single image, that you input in the <strong>Featured image</strong> area of this page.<br/>If you don\'t want any specific content for the non-fans, simply leave the Featured Image empty, and all viewers will see all the content.', 'werewpfbapps' ); ?></p> 
     
    131121    global $post; 
    132122 
    133     if ( $post->post_type == 'werewp_fbapp' ) { 
     123    if (isset($post) && $post->post_type == 'werewp_fbapp') { 
    134124        update_post_meta($post->ID, 'appid', $_POST['appid']); 
    135125        update_post_meta($post->ID, 'appsecret', $_POST['appsecret']); 
Note: See TracChangeset for help on using the changeset viewer.