1: <?php
2:
3: namespace webfilesframework\core\datasystem\file\system\dropbox;
4:
5: 6: 7: 8: 9: 10:
11: class MDropboxAccount
12: {
13:
14: private $consumerKey = '...';
15: private $consumerSecret = '...';
16:
17: private $callback = 'http://localhost/webdev/source';
18:
19: private $storage;
20: private $OAuth;
21: private $dropboxApi;
22:
23: public function __construct($consumerKey, $consumerSecret, $callback)
24: {
25:
26: $this->storage = new \Dropbox\OAuth\Storage\Session;
27:
28: $this->consumerKey = $consumerKey;
29: $this->consumerSecret = $consumerSecret;
30: $this->callback = $callback;
31:
32: $oauthAccessTokenFile = "tmp/dropbox-oauth-access.token";
33: $oauthRequestTokenFile = "tmp/dropbox-oauth-request.token";
34:
35: if (file_exists($oauthAccessTokenFile) && file_exists($oauthRequestTokenFile)) {
36:
37:
38:
39: $acc_token = unserialize(file_get_contents($oauthAccessTokenFile));
40: $this->storage->set($acc_token, 'access_token');
41: $req_token = unserialize(file_get_contents($oauthRequestTokenFile));
42: $this->storage->set($req_token, 'request_token');
43:
44: $this->OAuth = new \Dropbox\OAuth\Consumer\Curl(
45: $this->consumerKey,
46: $this->consumerSecret,
47: $this->storage,
48: $this->callback);
49: $this->dropboxApi = new \Dropbox\API($this->OAuth, 'dropbox');
50:
51: } else {
52:
53:
54:
55: $this->OAuth = new \Dropbox\OAuth\Consumer\Curl(
56: $this->consumerKey,
57: $this->consumerSecret,
58: $this->storage,
59: $this->callback);
60: $this->dropboxApi = new \Dropbox\API($this->OAuth, 'dropbox');
61:
62: $acc_token = serialize($this->storage->get('access_token'));
63: file_put_contents($oauthAccessTokenFile, $acc_token);
64:
65: $req_token = serialize($this->storage->get('request_token'));
66: file_put_contents($oauthRequestTokenFile, $req_token);
67:
68: }
69:
70: }
71:
72: 73: 74: 75:
76: public function getDropboxApi()
77: {
78: return $this->dropboxApi;
79: }
80:
81: 82: 83: 84:
85: public function getOAuth()
86: {
87: return $this->OAuth;
88: }
89:
90: 91: 92: 93:
94: public function getStorage()
95: {
96: return $this->storage;
97: }
98:
99: }
100: