*/ global $pb_hide_test, $pb_hide_save; $pb_hide_test = true; // Always hiding test button for Dropbox. $pb_hide_save = true; $show_config_form = false; if ('add' == $mode) { // ADD mode. $webAuth = new \Dropbox\WebAuthNoRedirect(pb_backupbuddy_destination_dropbox2::$appInfo, 'BackupBuddy v' . pb_backupbuddy::settings('version'), 'en'); $bad_auth_code = false; if ('' != pb_backupbuddy::_POST('dropbox_authorization_code')) { // Authorization code entered. Try it out before showing form or not. $pb_hide_save = false; $authCode = trim(pb_backupbuddy::_POST('dropbox_authorization_code')); try { list($accessToken, $dropboxUserId) = $webAuth->finish($authCode); } catch (\Exception $e) { pb_backupbuddy::alert('<b>Verify you authorized BackupBuddy access in Dropbox and copied the Dropbox authorization code exactly in the BackupBuddy field.</b><br><br>Error details: ' . $e->getMessage(), true); // '<br><br>' . pb_backupbuddy::$ui->button( pb_backupbuddy::page_url(), '← go back & retry' ) $bad_auth_code = true; $pb_hide_save = true; } if (false === $bad_auth_code) { $dropboxClient = new \Dropbox\Client($accessToken, 'BackupBuddy v' . pb_backupbuddy::settings('version')); $accountInfo = $dropboxClient->getAccountInfo(); $show_config_form = true; } } if ('' == pb_backupbuddy::_POST('dropbox_authorization_code') || true === $bad_auth_code) { // No authorization code entered yet so user needs to authorize. try {
require_once dirname(__DIR__) . '/vendor/dropbox/dropbox-sdk/lib/Dropbox/strict.php'; // Include the Dropbox autoloader in case the composer autoloader is not already active if (!class_exists('\\Dropbox\\AppInfo')) { echo "auto\n\n"; require_once dirname(__DIR__) . '/vendor/dropbox/dropbox-sdk/lib/Dropbox/autoload.php'; } list($appInfoJson, $appInfo) = \Dropbox\AppInfo::loadFromJsonFileWithRaw(dirname(__DIR__) . '/config/config.json'); // This is a command-line tool (as opposed to a web app), so we can't supply a redirect URI. $webAuth = new \Dropbox\WebAuthNoRedirect($appInfo, "examples-authorize", "en"); $authorizeUrl = $webAuth->start(); echo "1. Go to: {$authorizeUrl}\n"; echo "2. Click \"Allow\" (you might have to log in first).\n"; echo "3. Copy the authorization code.\n"; echo "Enter the authorization code here: "; $authCode = \trim(\fgets(STDIN)); list($accessToken, $userId) = $webAuth->finish($authCode); echo "Authorization complete.\n"; echo "- User ID: {$userId}\n"; echo "- Access Token: {$accessToken}\n"; $authArr = array('access_token' => $accessToken, 'editorially_prefix' => '/Apps/Editorially', 'leadpub_api_key' => '<YOUR_ACCOUNT_API_KEY>', 'leadpub_prefix' => '/<YOUR_BOOKS_SLUG>', 'leanpub_trigger' => 'preview'); if (array_key_exists('host', $appInfoJson)) { $authArr['host'] = $appInfoJson['host']; } $argAuthFileOutput = dirname(__DIR__) . '/config/access.json'; $json = json_encode($authArr, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0); if (file_put_contents($argAuthFileOutput, $json) !== false) { echo "Saved authorization information to \"{$argAuthFileOutput}\".\n"; } else { throw new \Exception("Error saving to \"{$argAuthFileOutput}\".\nDumping to stderr instead:\n{$json}\n", 3); } // Configuration loading error