function pumpio_connect(&$a) { // Start a session. This is necessary to hold on to a few keys the callback script will also need session_start(); // Define the needed keys $consumer_key = get_pconfig(local_user(), 'pumpio', 'consumer_key'); $consumer_secret = get_pconfig(local_user(), 'pumpio', 'consumer_secret'); $hostname = get_pconfig(local_user(), 'pumpio', 'host'); if (($consumer_key == "" or $consumer_secret == "") and $hostname != "") { logger("pumpio_connect: register client"); $clientdata = pumpio_registerclient($a, $hostname); set_pconfig(local_user(), 'pumpio', 'consumer_key', $clientdata->client_id); set_pconfig(local_user(), 'pumpio', 'consumer_secret', $clientdata->client_secret); $consumer_key = get_pconfig(local_user(), 'pumpio', 'consumer_key'); $consumer_secret = get_pconfig(local_user(), 'pumpio', 'consumer_secret'); logger("pumpio_connect: ckey: " . $consumer_key . " csecrect: " . $consumer_secret, LOGGER_DEBUG); } if ($consumer_key == "" or $consumer_secret == "") { logger("pumpio_connect: " . sprintf("Unable to register the client at the pump.io server '%s'.", $hostname)); $o .= sprintf(t("Unable to register the client at the pump.io server '%s'."), $hostname); return $o; } // The callback URL is the script that gets called after the user authenticates with pumpio $callback_url = $a->get_baseurl() . "/pumpio/connect"; // Let's begin. First we need a Request Token. The request token is required to send the user // to pumpio's login page. // Create a new instance of the TumblrOAuth library. For this step, all we need to give the library is our // Consumer Key and Consumer Secret $client = new oauth_client_class(); $client->debug = 1; $client->server = ''; $client->oauth_version = '1.0a'; $client->request_token_url = 'https://' . $hostname . '/oauth/request_token'; $client->dialog_url = 'https://' . $hostname . '/oauth/authorize'; $client->access_token_url = 'https://' . $hostname . '/oauth/access_token'; $client->url_parameters = false; $client->authorization_header = true; $client->redirect_uri = $callback_url; $client->client_id = $consumer_key; $client->client_secret = $consumer_secret; if ($success = $client->Initialize()) { if ($success = $client->Process()) { if (strlen($client->access_token)) { logger("pumpio_connect: otoken: " . $client->access_token . " osecrect: " . $client->access_token_secret, LOGGER_DEBUG); set_pconfig(local_user(), "pumpio", "oauth_token", $client->access_token); set_pconfig(local_user(), "pumpio", "oauth_token_secret", $client->access_token_secret); } } $success = $client->Finalize($success); } if ($client->exit) { $o = 'Could not connect to pumpio. Refresh the page or try again later.'; } if ($success) { logger("pumpio_connect: authenticated"); $o .= t("You are now authenticated to pumpio."); $o .= '<br /><a href="' . $a->get_baseurl() . '/settings/connectors">' . t("return to the connector page") . '</a>'; } else { logger("pumpio_connect: could not connect"); $o = 'Could not connect to pumpio. Refresh the page or try again later.'; } return $o; }
function pumpio_connect($a) { // Define the needed keys $consumer_key = get_pconfig(local_channel(), 'pumpio', 'consumer_key'); $consumer_secret = get_pconfig(local_channel(), 'pumpio', 'consumer_secret'); $hostname = get_pconfig(local_channel(), 'pumpio', 'host'); if (($consumer_key == "" || $consumer_secret == "") && $hostname != "") { $clientdata = pumpio_registerclient($a, $hostname); set_pconfig(local_channel(), 'pumpio', 'consumer_key', $clientdata['client_id']); set_pconfig(local_channel(), 'pumpio', 'consumer_secret', $clientdata['client_secret']); $consumer_key = get_pconfig(local_channel(), 'pumpio', 'consumer_key'); $consumer_secret = get_pconfig(local_channel(), 'pumpio', 'consumer_secret'); } if ($consumer_key == "" || $consumer_secret == "") { return; } // The callback URL is the script that gets called after the user authenticates with pumpio $callback_url = z_root() . '/pumpio/connect'; // Let's begin. First we need a Request Token. The request token is required to send the user // to pumpio's login page. // Create a new instance of the TumblrOAuth library. For this step, all we need to give the library is our // Consumer Key and Consumer Secret $client = new oauth_client_class(); $client->debug = 1; $client->server = ''; $client->oauth_version = '1.0a'; $client->request_token_url = 'https://' . $hostname . '/oauth/request_token'; $client->dialog_url = 'https://' . $hostname . '/oauth/authorize'; $client->access_token_url = 'https://' . $hostname . '/oauth/access_token'; $client->url_parameters = false; $client->authorization_header = true; $client->redirect_uri = $callback_url; $client->client_id = $consumer_key; $client->client_secret = $consumer_secret; if ($success = $client->Initialize()) { if ($success = $client->Process()) { if (strlen($client->access_token)) { set_pconfig(local_channel(), "pumpio", "oauth_token", $client->access_token); set_pconfig(local_channel(), "pumpio", "oauth_token_secret", $client->access_token_secret); } } $success = $client->Finalize($success); } if ($client->exit) { $o = 'Could not connect to pumpio. Refresh the page or try again later.'; } if ($success) { $o .= t('You are now authenticated to pumpio.'); $o .= '<br /><a href="' . z_root() . '/settings/featured">' . t('return to the featured settings page') . '</a>'; } return $o; }