drg_elfinder 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +8 -0
- data/app/assets/config/drg_elfinder_manifest.js +1 -0
- data/app/assets/javascripts/drg_elfinder.js +15 -0
- data/app/assets/javascripts/elfinder/Changelog +1283 -0
- data/app/assets/javascripts/elfinder/LICENSE.md +15 -0
- data/app/assets/javascripts/elfinder/README.md +216 -0
- data/app/assets/javascripts/elfinder/bower.json +28 -0
- data/app/assets/javascripts/elfinder/composer.json +39 -0
- data/app/assets/javascripts/elfinder/css/elfinder.full.css +5350 -0
- data/app/assets/javascripts/elfinder/css/elfinder.min.css +9 -0
- data/app/assets/javascripts/elfinder/css/theme.css +430 -0
- data/app/assets/javascripts/elfinder/elfinder.html +74 -0
- data/app/assets/javascripts/elfinder/elfinder.legacy.html +94 -0
- data/app/assets/javascripts/elfinder/img/arrows-active.png +0 -0
- data/app/assets/javascripts/elfinder/img/arrows-normal.png +0 -0
- data/app/assets/javascripts/elfinder/img/crop.gif +0 -0
- data/app/assets/javascripts/elfinder/img/dialogs.png +0 -0
- data/app/assets/javascripts/elfinder/img/edit_aceeditor.png +0 -0
- data/app/assets/javascripts/elfinder/img/edit_ckeditor.png +0 -0
- data/app/assets/javascripts/elfinder/img/edit_ckeditor5.png +0 -0
- data/app/assets/javascripts/elfinder/img/edit_codemirror.png +0 -0
- data/app/assets/javascripts/elfinder/img/edit_creativecloud.png +0 -0
- data/app/assets/javascripts/elfinder/img/edit_onlineconvert.png +0 -0
- data/app/assets/javascripts/elfinder/img/edit_pixlreditor.png +0 -0
- data/app/assets/javascripts/elfinder/img/edit_pixlrexpress.png +0 -0
- data/app/assets/javascripts/elfinder/img/edit_simplemde.png +0 -0
- data/app/assets/javascripts/elfinder/img/edit_tinymce.png +0 -0
- data/app/assets/javascripts/elfinder/img/edit_tuiimgedit.png +0 -0
- data/app/assets/javascripts/elfinder/img/edit_zohooffice.png +0 -0
- data/app/assets/javascripts/elfinder/img/editor-icons.png +0 -0
- data/app/assets/javascripts/elfinder/img/icons-big.png +0 -0
- data/app/assets/javascripts/elfinder/img/icons-big.svg +1 -0
- data/app/assets/javascripts/elfinder/img/icons-small.png +0 -0
- data/app/assets/javascripts/elfinder/img/logo.png +0 -0
- data/app/assets/javascripts/elfinder/img/progress.gif +0 -0
- data/app/assets/javascripts/elfinder/img/quicklook-bg.png +0 -0
- data/app/assets/javascripts/elfinder/img/quicklook-icons.png +0 -0
- data/app/assets/javascripts/elfinder/img/resize.png +0 -0
- data/app/assets/javascripts/elfinder/img/spinner-mini.gif +0 -0
- data/app/assets/javascripts/elfinder/img/toolbar.png +0 -0
- data/app/assets/javascripts/elfinder/img/trashmesh.png +0 -0
- data/app/assets/javascripts/elfinder/img/tui-icon-a.svg +235 -0
- data/app/assets/javascripts/elfinder/img/tui-icon-b.svg +224 -0
- data/app/assets/javascripts/elfinder/img/tui-icon-c.svg +224 -0
- data/app/assets/javascripts/elfinder/img/tui-icon-d.svg +224 -0
- data/app/assets/javascripts/elfinder/img/ui-icons_ffffff_256x240.png +0 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_box.png +0 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_box.svg +1 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_dropbox.png +0 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_dropbox.svg +1 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_ftp.png +0 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_ftp.svg +1 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_googledrive.png +0 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_googledrive.svg +1 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_local.png +0 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_local.svg +1 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_network.png +0 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_network.svg +1 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_onedrive.png +0 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_onedrive.svg +1 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_sql.png +0 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_sql.svg +1 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_trash.png +0 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_trash.svg +1 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_zip.png +0 -0
- data/app/assets/javascripts/elfinder/img/volume_icon_zip.svg +1 -0
- data/app/assets/javascripts/elfinder/js/elfinder.full.js +36019 -0
- data/app/assets/javascripts/elfinder/js/elfinder.min.js +25 -0
- data/app/assets/javascripts/elfinder/js/extras/editors.default.js +2643 -0
- data/app/assets/javascripts/elfinder/js/extras/editors.default.min.js +2 -0
- data/app/assets/javascripts/elfinder/js/extras/quicklook.googledocs.js +75 -0
- data/app/assets/javascripts/elfinder/js/extras/quicklook.googledocs.min.js +1 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.LANG.js +587 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.ar.js +580 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.bg.js +559 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.ca.js +375 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.cs.js +581 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.da.js +580 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.de.js +582 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.el.js +374 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.es.js +546 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.fa.js +580 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.fallback.js +11 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.fo.js +419 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.fr.js +578 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.fr_CA.js +580 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.he.js +375 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.hr.js +434 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.hu.js +580 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.id.js +498 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.it.js +552 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.ja.js +581 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.ko.js +582 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.nl.js +581 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.no.js +374 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.pl.js +580 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.pt_BR.js +580 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.ro.js +417 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.ru.js +582 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.si.js +537 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.sk.js +581 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.sl.js +374 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.sr.js +374 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.sv.js +375 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.tr.js +583 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.ug_CN.js +374 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.uk.js +580 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.vi.js +579 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.zh_CN.js +585 -0
- data/app/assets/javascripts/elfinder/js/i18n/elfinder.zh_TW.js +582 -0
- data/app/assets/javascripts/elfinder/js/i18n/help/cs.html.js +10 -0
- data/app/assets/javascripts/elfinder/js/i18n/help/de.html.js +15 -0
- data/app/assets/javascripts/elfinder/js/i18n/help/en.html.js +10 -0
- data/app/assets/javascripts/elfinder/js/i18n/help/es.html.js +10 -0
- data/app/assets/javascripts/elfinder/js/i18n/help/ja.html.js +10 -0
- data/app/assets/javascripts/elfinder/js/i18n/help/ko.html.js +10 -0
- data/app/assets/javascripts/elfinder/js/i18n/help/pl.html.js +10 -0
- data/app/assets/javascripts/elfinder/js/i18n/help/ru.html.js +10 -0
- data/app/assets/javascripts/elfinder/js/i18n/help/sk.html.js +10 -0
- data/app/assets/javascripts/elfinder/js/i18n/help/tr.html.js +10 -0
- data/app/assets/javascripts/elfinder/js/proxy/elFinderSupportVer1.js +408 -0
- data/app/assets/javascripts/elfinder/js/worker/calcfilehash.js +20 -0
- data/app/assets/javascripts/elfinder/js/worker/quicklook.tiff.js +7 -0
- data/app/assets/javascripts/elfinder/js/worker/quicklook.unzip.js +55 -0
- data/app/assets/javascripts/elfinder/main.default.js +175 -0
- data/app/assets/javascripts/elfinder/package.json +13 -0
- data/app/assets/javascripts/elfinder/php/MySQLStorage.sql +47 -0
- data/app/assets/javascripts/elfinder/php/autoload.php +56 -0
- data/app/assets/javascripts/elfinder/php/connector.maximal.php-dist +449 -0
- data/app/assets/javascripts/elfinder/php/connector.minimal.php-dist +180 -0
- data/app/assets/javascripts/elfinder/php/editors/OnlineConvert/editor.php +113 -0
- data/app/assets/javascripts/elfinder/php/editors/ZipArchive/editor.php +12 -0
- data/app/assets/javascripts/elfinder/php/editors/ZohoOffice/editor.php +206 -0
- data/app/assets/javascripts/elfinder/php/editors/editor.php +79 -0
- data/app/assets/javascripts/elfinder/php/elFinder.class.php +5401 -0
- data/app/assets/javascripts/elfinder/php/elFinderConnector.class.php +380 -0
- data/app/assets/javascripts/elfinder/php/elFinderFlysystemGoogleDriveNetmount.php +380 -0
- data/app/assets/javascripts/elfinder/php/elFinderPlugin.php +113 -0
- data/app/assets/javascripts/elfinder/php/elFinderSession.php +335 -0
- data/app/assets/javascripts/elfinder/php/elFinderSessionInterface.php +57 -0
- data/app/assets/javascripts/elfinder/php/elFinderVolumeBox.class.php +1972 -0
- data/app/assets/javascripts/elfinder/php/elFinderVolumeDriver.class.php +7651 -0
- data/app/assets/javascripts/elfinder/php/elFinderVolumeDropbox.class.php +1464 -0
- data/app/assets/javascripts/elfinder/php/elFinderVolumeDropbox2.class.php +1516 -0
- data/app/assets/javascripts/elfinder/php/elFinderVolumeFTP.class.php +1810 -0
- data/app/assets/javascripts/elfinder/php/elFinderVolumeGoogleDrive.class.php +2163 -0
- data/app/assets/javascripts/elfinder/php/elFinderVolumeGroup.class.php +315 -0
- data/app/assets/javascripts/elfinder/php/elFinderVolumeLocalFileSystem.class.php +1477 -0
- data/app/assets/javascripts/elfinder/php/elFinderVolumeMySQL.class.php +1022 -0
- data/app/assets/javascripts/elfinder/php/elFinderVolumeOneDrive.class.php +2131 -0
- data/app/assets/javascripts/elfinder/php/elFinderVolumeSFTPphpseclib.class.php +838 -0
- data/app/assets/javascripts/elfinder/php/elFinderVolumeTrash.class.php +51 -0
- data/app/assets/javascripts/elfinder/php/elFinderVolumeTrashMySQL.class.php +51 -0
- data/app/assets/javascripts/elfinder/php/libs/GdBmp.php +473 -0
- data/app/assets/javascripts/elfinder/php/mime.types +781 -0
- data/app/assets/javascripts/elfinder/php/plugins/AutoResize/plugin.php +151 -0
- data/app/assets/javascripts/elfinder/php/plugins/AutoRotate/plugin.php +148 -0
- data/app/assets/javascripts/elfinder/php/plugins/Normalizer/plugin.php +204 -0
- data/app/assets/javascripts/elfinder/php/plugins/Sanitizer/plugin.php +157 -0
- data/app/assets/javascripts/elfinder/php/plugins/Watermark/logo.png +0 -0
- data/app/assets/javascripts/elfinder/php/plugins/Watermark/plugin.php +432 -0
- data/app/assets/javascripts/elfinder/php/plugins/WinRemoveTailDots/plugin.php +114 -0
- data/app/assets/javascripts/elfinder/php/resources/image.png +0 -0
- data/app/assets/javascripts/elfinder/php/resources/video.png +0 -0
- data/app/assets/javascripts/elfinder/sounds/rm.wav +0 -0
- data/app/controllers/dc_elfinder_controller.rb +63 -0
- data/app/models/drgcms_form_fields/elfinder.rb +85 -0
- data/changelog.md +0 -0
- data/lib/drg_elfinder/engine.rb +5 -0
- data/lib/drg_elfinder/version.rb +3 -0
- data/lib/drg_elfinder.rb +9 -0
- data/lib/el_finder/action.rb +19 -0
- data/lib/el_finder/base64.rb +24 -0
- data/lib/el_finder/connector.rb +625 -0
- data/lib/el_finder/image.rb +33 -0
- data/lib/el_finder/mime_type.rb +86 -0
- data/lib/el_finder/pathname.rb +185 -0
- data/lib/el_finder/version.rb +5 -0
- data/lib/el_finder.rb +8 -0
- data/lib/patches/patch_for_elfinder.rb +115 -0
- data/lib/tasks/drg_elfinder_tasks.rake +10 -0
- metadata +245 -0
@@ -0,0 +1,380 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
use League\Flysystem\Filesystem;
|
4
|
+
use League\Flysystem\Adapter\Local;
|
5
|
+
use League\Flysystem\Cached\CachedAdapter;
|
6
|
+
use League\Flysystem\Cached\Storage\Adapter as ACache;
|
7
|
+
use Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter;
|
8
|
+
use Hypweb\Flysystem\Cached\Extra\Hasdir;
|
9
|
+
use Hypweb\Flysystem\Cached\Extra\DisableEnsureParentDirectories;
|
10
|
+
use Hypweb\elFinderFlysystemDriverExt\Driver as ExtDriver;
|
11
|
+
|
12
|
+
elFinder::$netDrivers['googledrive'] = 'FlysystemGoogleDriveNetmount';
|
13
|
+
|
14
|
+
if (!class_exists('elFinderVolumeFlysystemGoogleDriveCache', false)) {
|
15
|
+
class elFinderVolumeFlysystemGoogleDriveCache extends ACache
|
16
|
+
{
|
17
|
+
use Hasdir;
|
18
|
+
use DisableEnsureParentDirectories;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
class elFinderVolumeFlysystemGoogleDriveNetmount extends ExtDriver
|
23
|
+
{
|
24
|
+
|
25
|
+
public function __construct()
|
26
|
+
{
|
27
|
+
parent::__construct();
|
28
|
+
|
29
|
+
$opts = array(
|
30
|
+
'acceptedName' => '#^[^/\\?*:|"<>]*[^./\\?*:|"<>]$#',
|
31
|
+
'rootCssClass' => 'elfinder-navbar-root-googledrive',
|
32
|
+
'gdAlias' => '%s@GDrive',
|
33
|
+
'gdCacheDir' => __DIR__ . '/.tmp',
|
34
|
+
'gdCachePrefix' => 'gd-',
|
35
|
+
'gdCacheExpire' => 600
|
36
|
+
);
|
37
|
+
|
38
|
+
$this->options = array_merge($this->options, $opts);
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Prepare driver before mount volume.
|
43
|
+
* Return true if volume is ready.
|
44
|
+
*
|
45
|
+
* @return bool
|
46
|
+
**/
|
47
|
+
protected function init()
|
48
|
+
{
|
49
|
+
if (empty($this->options['icon'])) {
|
50
|
+
$this->options['icon'] = true;
|
51
|
+
}
|
52
|
+
if ($res = parent::init()) {
|
53
|
+
if ($this->options['icon'] === true) {
|
54
|
+
unset($this->options['icon']);
|
55
|
+
}
|
56
|
+
// enable command archive
|
57
|
+
$this->options['useRemoteArchive'] = true;
|
58
|
+
}
|
59
|
+
return $res;
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Prepare
|
64
|
+
* Call from elFinder::netmout() before volume->mount()
|
65
|
+
*
|
66
|
+
* @param $options
|
67
|
+
*
|
68
|
+
* @return Array
|
69
|
+
* @author Naoki Sawada
|
70
|
+
*/
|
71
|
+
public function netmountPrepare($options)
|
72
|
+
{
|
73
|
+
if (empty($options['client_id']) && defined('ELFINDER_GOOGLEDRIVE_CLIENTID')) {
|
74
|
+
$options['client_id'] = ELFINDER_GOOGLEDRIVE_CLIENTID;
|
75
|
+
}
|
76
|
+
if (empty($options['client_secret']) && defined('ELFINDER_GOOGLEDRIVE_CLIENTSECRET')) {
|
77
|
+
$options['client_secret'] = ELFINDER_GOOGLEDRIVE_CLIENTSECRET;
|
78
|
+
}
|
79
|
+
|
80
|
+
if (!isset($options['pass'])) {
|
81
|
+
$options['pass'] = '';
|
82
|
+
}
|
83
|
+
|
84
|
+
try {
|
85
|
+
$client = new \Google_Client();
|
86
|
+
$client->setClientId($options['client_id']);
|
87
|
+
$client->setClientSecret($options['client_secret']);
|
88
|
+
|
89
|
+
if ($options['pass'] === 'reauth') {
|
90
|
+
$options['pass'] = '';
|
91
|
+
$this->session->set('GoogleDriveAuthParams', [])->set('GoogleDriveTokens', []);
|
92
|
+
} else if ($options['pass'] === 'googledrive') {
|
93
|
+
$options['pass'] = '';
|
94
|
+
}
|
95
|
+
|
96
|
+
$options = array_merge($this->session->get('GoogleDriveAuthParams', []), $options);
|
97
|
+
|
98
|
+
if (!isset($options['access_token'])) {
|
99
|
+
$options['access_token'] = $this->session->get('GoogleDriveTokens', []);
|
100
|
+
$this->session->remove('GoogleDriveTokens');
|
101
|
+
}
|
102
|
+
$aToken = $options['access_token'];
|
103
|
+
|
104
|
+
$rootObj = $service = null;
|
105
|
+
if ($aToken) {
|
106
|
+
try {
|
107
|
+
$client->setAccessToken($aToken);
|
108
|
+
if ($client->isAccessTokenExpired()) {
|
109
|
+
$aToken = array_merge($aToken, $client->fetchAccessTokenWithRefreshToken());
|
110
|
+
$client->setAccessToken($aToken);
|
111
|
+
}
|
112
|
+
$service = new \Google_Service_Drive($client);
|
113
|
+
$rootObj = $service->files->get('root');
|
114
|
+
|
115
|
+
$options['access_token'] = $aToken;
|
116
|
+
$this->session->set('GoogleDriveAuthParams', $options);
|
117
|
+
|
118
|
+
} catch (Exception $e) {
|
119
|
+
$aToken = [];
|
120
|
+
$options['access_token'] = [];
|
121
|
+
if ($options['user'] !== 'init') {
|
122
|
+
$this->session->set('GoogleDriveAuthParams', $options);
|
123
|
+
return array('exit' => true, 'error' => elFinder::ERROR_REAUTH_REQUIRE);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
$itpCare = isset($options['code']);
|
130
|
+
$code = $itpCare? $options['code'] : (isset($_GET['code'])? $_GET['code'] : '');
|
131
|
+
if ($code || $options['user'] === 'init') {
|
132
|
+
if (empty($options['url'])) {
|
133
|
+
$options['url'] = elFinder::getConnectorUrl();
|
134
|
+
}
|
135
|
+
|
136
|
+
if (isset($options['id'])) {
|
137
|
+
$callback = $options['url'] . (strpos($options['url'], '?') !== false? '&' : '?') . 'cmd=netmount&protocol=googledrive&host=' . ($options['id'] === 'elfinder'? '1' : $options['id']);
|
138
|
+
$client->setRedirectUri($callback);
|
139
|
+
}
|
140
|
+
|
141
|
+
if (!$aToken && empty($code)) {
|
142
|
+
$client->setScopes([Google_Service_Drive::DRIVE]);
|
143
|
+
if (!empty($options['offline'])) {
|
144
|
+
$client->setApprovalPrompt('force');
|
145
|
+
$client->setAccessType('offline');
|
146
|
+
}
|
147
|
+
$url = $client->createAuthUrl();
|
148
|
+
|
149
|
+
$html = '<input id="elf-volumedriver-googledrive-host-btn" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" value="{msg:btnApprove}" type="button">';
|
150
|
+
$html .= '<script>
|
151
|
+
$("#' . $options['id'] . '").elfinder("instance").trigger("netmount", {protocol: "googledrive", mode: "makebtn", url: "' . $url . '"});
|
152
|
+
</script>';
|
153
|
+
if (empty($options['pass']) && $options['host'] !== '1') {
|
154
|
+
$options['pass'] = 'return';
|
155
|
+
$this->session->set('GoogleDriveAuthParams', $options);
|
156
|
+
return array('exit' => true, 'body' => $html);
|
157
|
+
} else {
|
158
|
+
$out = array(
|
159
|
+
'node' => $options['id'],
|
160
|
+
'json' => '{"protocol": "googledrive", "mode": "makebtn", "body" : "' . str_replace($html, '"', '\\"') . '", "error" : "' . elFinder::ERROR_ACCESS_DENIED . '"}',
|
161
|
+
'bind' => 'netmount'
|
162
|
+
);
|
163
|
+
return array('exit' => 'callback', 'out' => $out);
|
164
|
+
}
|
165
|
+
} else {
|
166
|
+
if ($code) {
|
167
|
+
if (!empty($options['id'])) {
|
168
|
+
$aToken = $client->fetchAccessTokenWithAuthCode($code);
|
169
|
+
$options['access_token'] = $aToken;
|
170
|
+
unset($options['code']);
|
171
|
+
$this->session->set('GoogleDriveTokens', $aToken)->set('GoogleDriveAuthParams', $options);
|
172
|
+
$out = array(
|
173
|
+
'node' => $options['id'],
|
174
|
+
'json' => '{"protocol": "googledrive", "mode": "done", "reset": 1}',
|
175
|
+
'bind' => 'netmount'
|
176
|
+
);
|
177
|
+
} else {
|
178
|
+
$nodeid = ($_GET['host'] === '1')? 'elfinder' : $_GET['host'];
|
179
|
+
$out = array(
|
180
|
+
'node' => $nodeid,
|
181
|
+
'json' => json_encode(array(
|
182
|
+
'protocol' => 'googledrive',
|
183
|
+
'host' => $nodeid,
|
184
|
+
'mode' => 'redirect',
|
185
|
+
'options' => array(
|
186
|
+
'id' => $nodeid,
|
187
|
+
'code'=> $code
|
188
|
+
)
|
189
|
+
)),
|
190
|
+
'bind' => 'netmount'
|
191
|
+
);
|
192
|
+
}
|
193
|
+
if (!$itpCare) {
|
194
|
+
return array('exit' => 'callback', 'out' => $out);
|
195
|
+
} else {
|
196
|
+
return array('exit' => true, 'body' => $out['json']);
|
197
|
+
}
|
198
|
+
}
|
199
|
+
$folders = [];
|
200
|
+
foreach ($service->files->listFiles([
|
201
|
+
'pageSize' => 1000,
|
202
|
+
'q' => 'trashed = false and mimeType = "application/vnd.google-apps.folder"'
|
203
|
+
]) as $f) {
|
204
|
+
$folders[$f->getId()] = $f->getName();
|
205
|
+
}
|
206
|
+
natcasesort($folders);
|
207
|
+
$folders = ['root' => $rootObj->getName()] + $folders;
|
208
|
+
$folders = json_encode($folders);
|
209
|
+
$json = '{"protocol": "googledrive", "mode": "done", "folders": ' . $folders . '}';
|
210
|
+
$options['pass'] = 'return';
|
211
|
+
$html = 'Google.com';
|
212
|
+
$html .= '<script>
|
213
|
+
$("#' . $options['id'] . '").elfinder("instance").trigger("netmount", ' . $json . ');
|
214
|
+
</script>';
|
215
|
+
$this->session->set('GoogleDriveAuthParams', $options);
|
216
|
+
return array('exit' => true, 'body' => $html);
|
217
|
+
}
|
218
|
+
}
|
219
|
+
} catch (Exception $e) {
|
220
|
+
$this->session->remove('GoogleDriveAuthParams')->remove('GoogleDriveTokens');
|
221
|
+
if (empty($options['pass'])) {
|
222
|
+
return array('exit' => true, 'body' => '{msg:' . elFinder::ERROR_ACCESS_DENIED . '}' . ' ' . $e->getMessage());
|
223
|
+
} else {
|
224
|
+
return array('exit' => true, 'error' => [elFinder::ERROR_ACCESS_DENIED, $e->getMessage()]);
|
225
|
+
}
|
226
|
+
}
|
227
|
+
|
228
|
+
if (!$aToken) {
|
229
|
+
return array('exit' => true, 'error' => elFinder::ERROR_REAUTH_REQUIRE);
|
230
|
+
}
|
231
|
+
|
232
|
+
if ($options['path'] === '/') {
|
233
|
+
$options['path'] = 'root';
|
234
|
+
}
|
235
|
+
|
236
|
+
try {
|
237
|
+
$file = $service->files->get($options['path']);
|
238
|
+
$options['alias'] = sprintf($this->options['gdAlias'], $file->getName());
|
239
|
+
if (!empty($this->options['netkey'])) {
|
240
|
+
elFinder::$instance->updateNetVolumeOption($this->options['netkey'], 'alias', $this->options['alias']);
|
241
|
+
}
|
242
|
+
} catch (Google_Service_Exception $e) {
|
243
|
+
$err = json_decode($e->getMessage(), true);
|
244
|
+
if (isset($err['error']) && $err['error']['code'] == 404) {
|
245
|
+
return array('exit' => true, 'error' => [elFinder::ERROR_TRGDIR_NOT_FOUND, $options['path']]);
|
246
|
+
} else {
|
247
|
+
return array('exit' => true, 'error' => $e->getMessage());
|
248
|
+
}
|
249
|
+
} catch (Exception $e) {
|
250
|
+
return array('exit' => true, 'error' => $e->getMessage());
|
251
|
+
}
|
252
|
+
|
253
|
+
foreach (['host', 'user', 'pass', 'id', 'offline'] as $key) {
|
254
|
+
unset($options[$key]);
|
255
|
+
}
|
256
|
+
|
257
|
+
return $options;
|
258
|
+
}
|
259
|
+
|
260
|
+
/**
|
261
|
+
* process of on netunmount
|
262
|
+
* Drop table `dropbox` & rm thumbs
|
263
|
+
*
|
264
|
+
* @param $netVolumes
|
265
|
+
* @param $key
|
266
|
+
*
|
267
|
+
* @return bool
|
268
|
+
* @internal param array $options
|
269
|
+
*/
|
270
|
+
public function netunmount($netVolumes, $key)
|
271
|
+
{
|
272
|
+
$cache = $this->options['gdCacheDir'] . DIRECTORY_SEPARATOR . $this->options['gdCachePrefix'] . $this->netMountKey;
|
273
|
+
if (file_exists($cache) && is_writeable($cache)) {
|
274
|
+
unlink($cache);
|
275
|
+
}
|
276
|
+
if ($tmbs = glob($this->tmbPath . DIRECTORY_SEPARATOR . $this->netMountKey . '*')) {
|
277
|
+
foreach ($tmbs as $file) {
|
278
|
+
unlink($file);
|
279
|
+
}
|
280
|
+
}
|
281
|
+
return true;
|
282
|
+
}
|
283
|
+
|
284
|
+
/**
|
285
|
+
* "Mount" volume.
|
286
|
+
* Return true if volume available for read or write,
|
287
|
+
* false - otherwise
|
288
|
+
*
|
289
|
+
* @param array $opts
|
290
|
+
*
|
291
|
+
* @return bool
|
292
|
+
* @author Naoki Sawada
|
293
|
+
*/
|
294
|
+
public function mount(array $opts)
|
295
|
+
{
|
296
|
+
$creds = null;
|
297
|
+
if (isset($opts['access_token'])) {
|
298
|
+
$this->netMountKey = md5(join('-', array('googledrive', $opts['path'], (isset($opts['access_token']['refresh_token']) ? $opts['access_token']['refresh_token'] : $opts['access_token']['access_token']))));
|
299
|
+
}
|
300
|
+
|
301
|
+
$client = new \Google_Client();
|
302
|
+
$client->setClientId($opts['client_id']);
|
303
|
+
$client->setClientSecret($opts['client_secret']);
|
304
|
+
|
305
|
+
if (!empty($opts['access_token'])) {
|
306
|
+
$client->setAccessToken($opts['access_token']);
|
307
|
+
}
|
308
|
+
if ($this->needOnline && $client->isAccessTokenExpired()) {
|
309
|
+
try {
|
310
|
+
$creds = $client->fetchAccessTokenWithRefreshToken();
|
311
|
+
} catch (LogicException $e) {
|
312
|
+
$this->session->remove('GoogleDriveAuthParams');
|
313
|
+
throw $e;
|
314
|
+
}
|
315
|
+
}
|
316
|
+
|
317
|
+
$service = new \Google_Service_Drive($client);
|
318
|
+
|
319
|
+
// If path is not set, use the root
|
320
|
+
if (!isset($opts['path']) || $opts['path'] === '') {
|
321
|
+
$opts['path'] = 'root';
|
322
|
+
}
|
323
|
+
|
324
|
+
$googleDrive = new GoogleDriveAdapter($service, $opts['path'], ['useHasDir' => true]);
|
325
|
+
|
326
|
+
$opts['fscache'] = null;
|
327
|
+
if ($this->options['gdCacheDir'] && is_writeable($this->options['gdCacheDir'])) {
|
328
|
+
if ($this->options['gdCacheExpire']) {
|
329
|
+
$opts['fscache'] = new elFinderVolumeFlysystemGoogleDriveCache(new Local($this->options['gdCacheDir']), $this->options['gdCachePrefix'] . $this->netMountKey, $this->options['gdCacheExpire']);
|
330
|
+
}
|
331
|
+
}
|
332
|
+
if ($opts['fscache']) {
|
333
|
+
$filesystem = new Filesystem(new CachedAdapter($googleDrive, $opts['fscache']));
|
334
|
+
} else {
|
335
|
+
$filesystem = new Filesystem($googleDrive);
|
336
|
+
}
|
337
|
+
|
338
|
+
$opts['driver'] = 'FlysystemExt';
|
339
|
+
$opts['filesystem'] = $filesystem;
|
340
|
+
$opts['separator'] = '/';
|
341
|
+
$opts['checkSubfolders'] = true;
|
342
|
+
if (!isset($opts['alias'])) {
|
343
|
+
$opts['alias'] = 'GoogleDrive';
|
344
|
+
}
|
345
|
+
|
346
|
+
if ($res = parent::mount($opts)) {
|
347
|
+
// update access_token of session data
|
348
|
+
if ($creds) {
|
349
|
+
$netVolumes = $this->session->get('netvolume');
|
350
|
+
$netVolumes[$this->netMountKey]['access_token'] = array_merge($netVolumes[$this->netMountKey]['access_token'], $creds);
|
351
|
+
$this->session->set('netvolume', $netVolumes);
|
352
|
+
}
|
353
|
+
}
|
354
|
+
|
355
|
+
return $res;
|
356
|
+
}
|
357
|
+
|
358
|
+
/**
|
359
|
+
* @inheritdoc
|
360
|
+
*/
|
361
|
+
protected function tmbname($stat)
|
362
|
+
{
|
363
|
+
return $this->netMountKey . substr(substr($stat['hash'], strlen($this->id)), -38) . $stat['ts'] . '.png';
|
364
|
+
}
|
365
|
+
|
366
|
+
/**
|
367
|
+
* Return debug info for client.
|
368
|
+
*
|
369
|
+
* @return array
|
370
|
+
**/
|
371
|
+
public function debug()
|
372
|
+
{
|
373
|
+
$res = parent::debug();
|
374
|
+
if (!empty($this->options['netkey']) && empty($this->options['refresh_token']) && $this->options['access_token'] && isset($this->options['access_token']['refresh_token'])) {
|
375
|
+
$res['refresh_token'] = $this->options['access_token']['refresh_token'];
|
376
|
+
}
|
377
|
+
|
378
|
+
return $res;
|
379
|
+
}
|
380
|
+
}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
/**
|
4
|
+
* elFinder Plugin Abstract
|
5
|
+
*
|
6
|
+
* @package elfinder
|
7
|
+
* @author Naoki Sawada
|
8
|
+
* @license New BSD
|
9
|
+
*/
|
10
|
+
class elFinderPlugin
|
11
|
+
{
|
12
|
+
|
13
|
+
/**
|
14
|
+
* This plugin's options
|
15
|
+
*
|
16
|
+
* @var array
|
17
|
+
*/
|
18
|
+
protected $opts = array();
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Get current volume's options
|
22
|
+
*
|
23
|
+
* @param object $volume
|
24
|
+
*
|
25
|
+
* @return array options
|
26
|
+
*/
|
27
|
+
protected function getCurrentOpts($volume)
|
28
|
+
{
|
29
|
+
$name = substr(get_class($this), 14); // remove "elFinderPlugin"
|
30
|
+
$opts = $this->opts;
|
31
|
+
if (is_object($volume)) {
|
32
|
+
$volOpts = $volume->getOptionsPlugin($name);
|
33
|
+
if (is_array($volOpts)) {
|
34
|
+
$opts = array_merge($opts, $volOpts);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
return $opts;
|
38
|
+
}
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Is enabled with options
|
42
|
+
*
|
43
|
+
* @param array $opts
|
44
|
+
* @param elFinder $elfinder
|
45
|
+
*
|
46
|
+
* @return boolean
|
47
|
+
*/
|
48
|
+
protected function iaEnabled($opts, $elfinder = null)
|
49
|
+
{
|
50
|
+
if (!$opts['enable']) {
|
51
|
+
return false;
|
52
|
+
}
|
53
|
+
|
54
|
+
// check post var 'contentSaveId' to disable this plugin
|
55
|
+
if ($elfinder && !empty($opts['disableWithContentSaveId'])) {
|
56
|
+
$session = $elfinder->getSession();
|
57
|
+
$urlContentSaveIds = $session->get('urlContentSaveIds', array());
|
58
|
+
if (!empty(elFinder::$currentArgs['contentSaveId']) && ($contentSaveId = elFinder::$currentArgs['contentSaveId'])) {
|
59
|
+
if (!empty($urlContentSaveIds[$contentSaveId])) {
|
60
|
+
$elfinder->removeUrlContentSaveId($contentSaveId);
|
61
|
+
return false;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
if (isset($opts['onDropWith']) && !is_null($opts['onDropWith'])) {
|
67
|
+
// plugin disabled by default, enabled only if given key is pressed
|
68
|
+
if (isset($_REQUEST['dropWith']) && $_REQUEST['dropWith']) {
|
69
|
+
$onDropWith = $opts['onDropWith'];
|
70
|
+
$action = (int)$_REQUEST['dropWith'];
|
71
|
+
if (!is_array($onDropWith)) {
|
72
|
+
$onDropWith = array($onDropWith);
|
73
|
+
}
|
74
|
+
foreach ($onDropWith as $key) {
|
75
|
+
$key = (int)$key;
|
76
|
+
if (($action & $key) === $key) {
|
77
|
+
return true;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
return false;
|
82
|
+
}
|
83
|
+
|
84
|
+
if (isset($opts['offDropWith']) && !is_null($opts['offDropWith']) && isset($_REQUEST['dropWith'])) {
|
85
|
+
// plugin enabled by default, disabled only if given key is pressed
|
86
|
+
$offDropWith = $opts['offDropWith'];
|
87
|
+
$action = (int)$_REQUEST['dropWith'];
|
88
|
+
if (!is_array($offDropWith)) {
|
89
|
+
$offDropWith = array($offDropWith);
|
90
|
+
}
|
91
|
+
$res = true;
|
92
|
+
foreach ($offDropWith as $key) {
|
93
|
+
$key = (int)$key;
|
94
|
+
if ($key === 0) {
|
95
|
+
if ($action === 0) {
|
96
|
+
$res = false;
|
97
|
+
break;
|
98
|
+
}
|
99
|
+
} else {
|
100
|
+
if (($action & $key) === $key) {
|
101
|
+
$res = false;
|
102
|
+
break;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
if (!$res) {
|
107
|
+
return false;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
return true;
|
112
|
+
}
|
113
|
+
}
|