[php] session handling wrapper replaceable

This commit is contained in:
nao-pon
2016-02-25 17:39:14 +09:00
parent c0fda8074d
commit 78452f3429
7 changed files with 378 additions and 65 deletions
+11 -11
View File
@@ -164,10 +164,10 @@ class elFinderVolumeDropbox extends elFinderVolumeDriver {
if ($options['pass'] === 'init') {
$html = '';
if (isset($_SESSION['elFinderDropboxTokens'])) {
if ($sessionToken = $this->session->get('DropboxTokens')) {
// token check
try {
list(, $accessToken, $accessTokenSecret) = $_SESSION['elFinderDropboxTokens'];
list(, $accessToken, $accessTokenSecret) = $sessionToken;
$this->oauth->setToken($accessToken, $accessTokenSecret);
$this->dropbox = new Dropbox_API($this->oauth, $this->options['root']);
$this->dropbox->getAccountInfo();
@@ -176,7 +176,7 @@ class elFinderVolumeDropbox extends elFinderVolumeDriver {
</script>';
$html = $script;
} catch (Dropbox_Exception $e) {
unset($_SESSION['elFinderDropboxTokens']);
$this->session->remove('DropboxTokens');
}
}
if (! $html) {
@@ -202,7 +202,7 @@ class elFinderVolumeDropbox extends elFinderVolumeDriver {
return array('exit' => true, 'body' => '{msg:errAccess}');
}
$_SESSION['elFinderDropboxAuthTokens'] = $tokens;
$this->session->set('DropboxAuthTokens', $tokens);
$html = '<input id="elf-volumedriver-dropbox-host-btn" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" value="{msg:btnApprove}" type="button" onclick="window.open(\''.$url.'\')">';
$html .= '<script>
$("#'.$options['id'].'").elfinder("instance").trigger("netmount", {protocol: "dropbox", mode: "makebtn"});
@@ -210,10 +210,10 @@ class elFinderVolumeDropbox extends elFinderVolumeDriver {
}
return array('exit' => true, 'body' => $html);
} else {
$this->oauth->setToken($_SESSION['elFinderDropboxAuthTokens']);
unset($_SESSION['elFinderDropboxAuthTokens']);
$this->oauth->setToken($this->session->get('DropboxAuthTokens'));
$this->session->remove('DropboxAuthTokens');
$tokens = $this->oauth->getAccessToken();
$_SESSION['elFinderDropboxTokens'] = array($_GET['uid'], $tokens['token'], $tokens['token_secret']);
$this->session->set('DropboxTokens', array($_GET['uid'], $tokens['token'], $tokens['token_secret']));
$out = array(
'node' => $_GET['node'],
@@ -224,8 +224,8 @@ class elFinderVolumeDropbox extends elFinderVolumeDriver {
return array('exit' => 'callback', 'out' => $out);
}
}
if (isset($_SESSION['elFinderDropboxTokens'])) {
list($options['dropboxUid'], $options['accessToken'], $options['accessTokenSecret']) = $_SESSION['elFinderDropboxTokens'];
if ($sessionToken = $this->session->get('DropboxTokens')) {
list($options['dropboxUid'], $options['accessToken'], $options['accessTokenSecret']) = $sessionToken;
}
unset($options['user'], $options['pass']);
return $options;
@@ -339,7 +339,7 @@ class elFinderVolumeDropbox extends elFinderVolumeDriver {
$this->oauth->setToken($this->options['accessToken'], $this->options['accessTokenSecret']);
$this->dropbox = new Dropbox_API($this->oauth, $this->options['root']);
} catch (Dropbox_Exception $e) {
unset($_SESSION['elFinderDropboxTokens']);
$this->session->remove('DropboxTokens');
return $this->setError('Dropbox error: '.$e->getMessage());
}
@@ -349,7 +349,7 @@ class elFinderVolumeDropbox extends elFinderVolumeDriver {
$res = $this->dropbox->getAccountInfo();
$this->options['dropboxUid'] = $res['uid'];
} catch (Dropbox_Exception $e) {
unset($_SESSION['elFinderDropboxTokens']);
$this->session->remove('DropboxTokens');
return $this->setError('Dropbox error: '.$e->getMessage());
}
}