function handle_dropbox_auth($dropbox)
{
    // first try to load existing access token
    $access_token = load_token("access");
    if (!empty($access_token)) {
        $dropbox->SetAccessToken($access_token);
    } elseif (!empty($_GET['auth_callback'])) {
        // then load our previosly created request token
        $request_token = load_token($_GET['oauth_token']);
        if (empty($request_token)) {
            die('Request token not found!');
        }
        // get & store access token, the request token is not needed anymore
        $access_token = $dropbox->GetAccessToken($request_token);
        store_token($access_token, "access");
        delete_token($_GET['oauth_token']);
    }
    // checks if access token is required
    if (!$dropbox->IsAuthorized()) {
        // redirect user to dropbox auth page
        $return_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . "?auth_callback=1";
        $auth_url = $dropbox->BuildAuthorizeUrl($return_url);
        $request_token = $dropbox->GetRequestToken();
        store_token($request_token, $request_token['t']);
        die("Authentication required. <a href='{$auth_url}'>Click here.</a>");
    }
}
function handle_dropbox_auth($dropbox)
{
    // first try to load existing access token
    $access_token = load_token("access");
    if (!empty($access_token)) {
        $dropbox->SetAccessToken($access_token);
    } elseif (!empty($_GET['auth_callback'])) {
        // then load our previosly created request token
        $request_token = load_token($_GET['oauth_token']);
        if (empty($request_token)) {
            die('Request token not found!');
        }
        // get & store access token, the request token is not needed anymore
        $access_token = $dropbox->GetAccessToken($request_token);
        store_token($access_token, "access");
        delete_token($_GET['oauth_token']);
    }
    // checks if access token is required
    if ($dropbox->IsAuthorized()) {
        $dropb_autho = "yes";
        update_option('dropb_autho', $dropb_autho);
        echo '<h3>Dropbox Account Details</h3>';
        $account_info = $dropbox->GetAccountInfo();
        $used = round(($account_info->quota_info->quota - ($account_info->quota_info->normal + $account_info->quota_info->shared)) / 1073741824, 1);
        $quota = round($account_info->quota_info->quota / 1073741824, 1);
        echo $account_info->display_name . ', ' . 'you have' . ' ' . $used . 'GB' . 'of' . ' ' . $quota . 'GB (' . round($used / $quota * 100, 0) . '%) ' . 'free';
        echo '</br><p>Unlink Account for local backups</p></br>';
        echo '<td><a href="' . site_url() . '/wp-admin/tools.php?page=wp-database-backup&action=unlink" class="btn btn-primary">Unlink Account<a/>';
    } else {
        $dropb_autho = "no";
        update_option('dropb_autho', $dropb_autho);
        // redirect user to dropbox oauth page
        $return_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . "?page=wp-database-backup&auth_callback=1";
        $auth_url = $dropbox->BuildAuthorizeUrl($return_url);
        $request_token = $dropbox->GetRequestToken();
        store_token($request_token, $request_token['t']);
        ?>
    <style>
    #adminmenuwrap {
        padding-bottom: 838px;
    }
</style>
    <h3>Dropbox</h3>
    <p>Define an Dropbox destination connection.</p>
    <p>In order to use Dropbox destination you will need to authorized it with your Dropbox account</p>
    <p>Please click the authorize button below and follow the instructions inside the pop up window</p>
    <p>For local backup leave the setting as it is</p>
          <p>
    <form action="" method="get">
        <a href="<?php 
        echo $auth_url;
        ?>
"><input type="button" name="authorize" id="authorize" value="Authorize"
               class="btn btn-primary" /></a><br/>
         </form>
    </p>
    <?php 
        die;
        //die("Authentication required".$auth_url);
    }
}
Beispiel #3
0
<?php

/** This is the callback, what we do is take 'oauth_verifier' from our $_REQUEST, and pass this back
 *  to trademe who will give us another token, an access token, which we can use to make actual useful
 *  requests in future.
 */
require_once 'include/init.php';
// We must use the same request token we obtained in connect.php
$RequestToken = retrieve_token('request');
trademe()->set_token($RequestToken);
// And now we get the access token using the verifier
$AccessToken = trademe()->get_access_token($_REQUEST['oauth_verifier']);
// Which we save, because we now can use this to make any future requests
//  until the access token expires, which I believe for TradeMe is a year (?)
store_token($AccessToken);
include '_header.php';
?>

      <h1 class="css-content-legend">We are (in theory) connected To TradeMe</h1>      
         
      <p>
        You don't have to reauthorise unless you lose the Access Token or it expires. So store the Access Token in a database, config file, or whatever so your users don't have to reauthorise all the time.  
      </p>     
      
      <p>This example only stores it in the $_SESSION, that's probably not very useful to you in production but it suffices for the examples :-)</p>
      
      <p>
        Now you can <a href="index.php">try it out with some simple demos</a>.
      </p>
      
    
Beispiel #4
0
    $request_token = load_token($_GET['oauth_token']);
    if (empty($request_token)) {
        die('Request token not found!');
    }
    // get & store access token, the request token is not needed anymore
    $access_token = $dropbox->GetAccessToken($request_token);
    store_token($access_token, "access");
    delete_token($_GET['oauth_token']);
}
// checks if access token is required
if (!$dropbox->IsAuthorized()) {
    // redirect user to dropbox auth page
    $return_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . "?auth_callback=1";
    $auth_url = $dropbox->BuildAuthorizeUrl($return_url);
    $request_token = $dropbox->GetRequestToken();
    store_token($request_token, $request_token['t']);
    die("Authentication required. <a href='{$auth_url}'>Click here.</a>");
}
echo "<pre>";
echo "<b>Account:</b>\r\n";
print_r($dropbox->GetAccountInfo());
$files = $dropbox->GetFiles("", false);
if (empty($files)) {
    $dropbox->UploadFile("leonidas.jpg");
    $files = $dropbox->GetFiles("", false);
}
echo "\r\n\r\n<b>Files:</b>\r\n";
print_r(array_keys($files));
if (!empty($files)) {
    $file = reset($files);
    $test_file = "test_download_" . basename($file->path);
function authorize_dropbox()
{
    global $_CONFIG;
    include_once "classes/DropboxClient.php";
    $access_token = load_token("access");
    if ($_CONFIG["cron_dropbox_active"]) {
        $dropbox = new DropboxClient(array('app_key' => $_CONFIG['cron_dropbox_Key'], 'app_secret' => $_CONFIG['cron_dropbox_Secret'], 'app_full_access' => false), 'en');
        if (!empty($access_token)) {
            $dropbox->SetAccessToken($access_token);
        }
        if ($dropbox->IsAuthorized()) {
            echo "<center><h2>Dropbox Connection Authorized!</h2></center>";
            return;
        }
    } else {
        return;
    }
    if ($_CONFIG["cron_dropbox_active"] and !empty($_GET['auth_callback'])) {
        // then load our previosly created request token
        $request_token = load_token($_GET['oauth_token']);
        if (empty($request_token)) {
            die('Request token not found!');
        }
        // get & store access token, the request token is not needed anymore
        $access_token = $dropbox->GetAccessToken($request_token);
        store_token($access_token, "access");
        delete_token($_GET['oauth_token']);
        echo "<center><h2>Dropbox Connection Authorized!</h2></center>";
        return;
    }
    if (empty($access_token) and $_CONFIG["cron_dropbox_active"]) {
        //$dropbox->SetAccessToken($access_token);
        //print_r($access_token);
        $return_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "&auth_callback=1";
        $auth_url = $dropbox->BuildAuthorizeUrl($return_url);
        $request_token = $dropbox->GetRequestToken();
        store_token($request_token, $request_token['t']);
        ?>
			<script>
				window.location="<?php 
        echo $auth_url;
        ?>
"
			</script>
			<?php 
        exit;
    }
}
function handle_dropbox_auth($dropbox, $option)
{
    // first try to load existing access token
    $access_token = load_token($option['access_token']);
    if (!empty($access_token)) {
        $dropbox->SetAccessToken($access_token);
    } elseif (!empty($_GET['auth_callback'])) {
        // then load our previosly created request token
        $request_token = load_token($_GET['oauth_token']);
        if (empty($request_token)) {
            die('Request token not found!');
        }
        // get & store access token, the request token is not needed anymore
        $access_token = $dropbox->GetAccessToken($request_token);
        store_token($access_token, $option['access_token']);
        delete_token($_GET['oauth_token']);
    }
    // checks if access token is required
    if (!$dropbox->IsAuthorized()) {
        ?>
		<img src="logo.png" class="dropbox">
		<?php 
        // redirect user to dropbox auth page
        $return_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . "?auth_callback=1&check=10&config=30";
        $auth_url = $dropbox->BuildAuthorizeUrl($return_url);
        $request_token = $dropbox->GetRequestToken();
        store_token($request_token, $request_token['t']);
        die("Authentication required. <a onclick=window.open('{$auth_url}','popUpWindow','height=400,width=600,left=10,top=10,,scrollbars=yes,menubar=no') return false;>Click here.</a>");
    }
}
Beispiel #7
0
<?php

/** This is the connector, your user would use this page when they are connecting your application (/website)
 *  to TradeMe, once they have "connected", they don't need to do it again until that "connection" expires
 *  (which is 12 months I think?), or of course, if you forget the "Access Token"!
 */
require_once 'include/init.php';
// This is where the work really starts, if we have been asked to (re)authorise by the user,
if (isset($_REQUEST['Reauthorise'])) {
    // We get a request token, by providing oauth with OUR url which will handle the "verifier callback"
    //   NOTE: in oauth, "callback" means "TradeMe redirects the user to this url", not a server->server request
    $RequestToken = trademe()->get_request_token();
    // We need to get access to this later, so store it however you want to
    store_token($RequestToken);
    // Now we get a URL from oauth to where we need to redirect the user
    $RedirectURL = trademe()->get_authorize_url();
    // And we send them there, and stop processing
    header('location: ' . $RedirectURL);
    exit;
}
include '_header.php';
?>
      <h1 class="css-content-legend">Connect To TradeMe</h1>    
      <p>In order to connect to your TradeMe account you must complete the authorisation process, simply click on the link below and you will be redirected to TradeMe to authorise access to your account.</p>
          
      <p><a href="connect.php?Reauthorise=1">Begin Authorisation</a></p>
<?php 
include '_footer.php';
Beispiel #8
0
    $request_token = load_token($_GET['oauth_token']);
    if (empty($request_token)) {
        die('Request token not found!');
    }
    // get & store access token, the request token is not needed anymore
    $access_token = $dropbox->GetAccessToken($request_token);
    store_token($access_token, "access");
    delete_token($_GET['oauth_token']);
}
// checks if access token is required
if (!$dropbox->IsAuthorized()) {
    // redirect user to dropbox auth page
    $return_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . "?auth_callback=1";
    $auth_url = $dropbox->BuildAuthorizeUrl($return_url);
    $request_token = $dropbox->GetRequestToken();
    store_token($request_token, "access");
    die("Authentication required. <a href='{$auth_url}'>Click here.</a>");
}
echo "<pre>";
echo "<b>Account:</b>\r\n";
print_r($dropbox->GetAccountInfo());
$files = $dropbox->GetFiles("", False);
echo "\r\n\r\n<b>Files:</b>\r\n";
// print_r(array_keys($files));
// print_r($files);
foreach ($files as $file) {
    echo "NAME : " . basename($file->path) . "<br>";
    echo "PATH : " . $file->path . "<br>";
    echo "LAST MODIFIED : " . $file->modified . "<br>";
    if ($file->is_dir) {
        echo "<a href='#'>Open Folder</a><br>";