Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. <?php
  2. // error_reporting(E_ALL);
  3. include_once('../../../../../../wp-load.php');
  4.  
  5. $obj_id = $_GET['obj_id'];
  6.  
  7. $fb_pages = scj_database::get_app_data($modules = array('facebook_pages'), scj_getter::get('app_config'));
  8. $fb_page = $fb_pages['facebook_pages']['id'][$obj_id];
  9.  
  10. $fb_app = scj_database::get_results(SCJ_DB_PREFIX, SCJ_DB_TABLE_FB_APPS, null, $args = array('id'=>$fb_page['fb_app']), $return = 'ARRAY_A');
  11.  
  12. if ( is_array($fb_app) )
  13. $fb_app = $fb_app[0];
  14. else{
  15. echo "The FB app selected no longer exists. Please choose a different app, save and then try again.";
  16. exit;
  17. }
  18.  
  19. if ( !$fb_app ){
  20. echo "Please select one of your Facebook apps from the dropdown to the left and save these settings. Once saved, follow the instructions which will appear here to authorize your app to post to your page.";
  21. exit;
  22. }
  23.  
  24.  
  25.  
  26. $facebook = new Facebook(array(
  27. 'appId' => $fb_app['app_id'],
  28. 'secret' => $fb_app['app_secret'],
  29. ));
  30.  
  31.  
  32. if ( $fb_page['access_token'] )
  33. {
  34. $facebook->setAccessToken($fb_page['access_token']);
  35. $facebook->setExtendedAccessToken();
  36. }else{
  37. $token = $fb_app['access_token'];
  38. $facebook->setAccessToken($token);
  39. }
  40.  
  41. try {
  42. $user_profile = $facebook->api('/me');
  43. } catch (FacebookApiException $e) {
  44. // echo "<pre>";var_dump($e);echo "</pre>";
  45. error_log($e);
  46. $user = null;
  47. }
  48.  
  49. //Empty out params
  50. $params = array();
  51.  
  52. // Get User ID
  53. $user = $facebook->getUser();
  54.  
  55. $page_id = $fb_page['fb_page_id'];
  56.  
  57. if ($user) {
  58. try {
  59. $page_info = $facebook->api("/$page_id?fields=access_token");
  60. if( !empty($page_info['access_token']) ) {
  61. $args = array(
  62. 'access_token' => $page_info['access_token'],
  63. 'message' => $message
  64. );
  65. if ( $facebook->getAccessToken() ){
  66.  
  67. //echo '<a href="$logoutUrl;">Log Out</a>';
  68. echo "<p>You have successfully connected to your Facebook page.</p>";
  69. echo "<p>Please add your access token to the left and save your app</p>";
  70. $token = $facebook->getAccessToken();
  71. echo "<p>Access token: <input onClick='this.select()' style='width: 100%;font-family: arial, sans-serif;padding: 5px;font-size: 12px; margin-top:8px;' type='text' value='$token' /></p>";
  72. }else{
  73. echo "<p>You have successfully granted permissions. You can now close this window and got back to the plugin screen.</p>";
  74. }
  75. $facebook->setExtendedAccessToken();
  76.  
  77. // $post_id = $facebook->api("/$page_id/feed","post",$args);
  78.  
  79. } else {
  80. $permissions = $facebook->api("/me/permissions");
  81. if( !array_key_exists('publish_stream', $permissions['data'][0]) ||
  82. // !array_key_exists('publish_actions', $permissions['data'][0]) ||
  83. !array_key_exists('manage_pages', $permissions['data'][0]) ) {
  84. // We don't have one of the permissions
  85. // Alert the admin or ask for the permission!
  86. // header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream, manage_pages")) );
  87. $loginUrl = $facebook->getLoginUrl(array('scope'=>'manage_pages,publish_stream,publish_actions'));
  88. ?>
  89. <p>1. Click the link below:</p>
  90. <p><a href="<?php echo $loginUrl; ?>" target="_blank">Please Grant Permissions</a></p>
  91. <p>2. When you receive a message that you've successfully logged in, refresh this page to see the updated status of your connection.</p>
  92. <?php
  93. }
  94. }
  95. } catch (FacebookApiException $e) {
  96. error_log($e);
  97. $user = null;
  98. }
  99. }else{
  100. $loginUrl = $facebook->getLoginUrl(array('scope'=>'manage_pages,publish_stream'));
  101. ?>
  102. <p>1. Click the link below:</p>
  103. <p><a href="<?php echo $loginUrl; ?>" target="_blank">Please Grant Permissions</a></p>
  104. <p>2. When you receive a message that you've successfully logged in, refresh this page to see the updated status of your connection.</p>
  105. <?php
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement