Closed rajasharma27 closed 8 years ago
/**
* # Google Drive volume driver need "google-api-php-client" package"
* * google-api-php-client: https://github.com/google/google-api-php-client/releases
* * copy directory "google-api-php-client" and paste in elFinder php directory
* * Google Drive developer console: https://console.developers.google.com
* * Create login in google developer console and create app and get clientid, clientsecret, redirecturi
* * create new project ->Enable and manage APIs ->Drive API ->Enable ->Goto Credentials
* * Create Credentials ->oAuth Client ->web Applicaton
* * Application Name Optional, Authorized redirect URIs should be your elFinder connector path
* * copy oAuth client ID and client secret
*/
// Required for drive.google.com connector support
// Required for drive.google.com connector support
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeGoogleDrive.class.php';
// Google Drive driver need next three settings. You can get at https://console.developers.google.com
define('ELFINDER_GOOGLEDRIVE_CLIENTID', ' ');
define('ELFINDER_GOOGLEDRIVE_CLIENTSECRET', ' ');
define('ELFINDER_GOOGLEDRIVE_REDIRECTURI', 'http://localhost:8080/elfinder/php/connector.minimal.php');
if (isset($_GET['code'])) {
$callback = new elFinderVolumeGoogleDrive();
$callback->netmountPrepare(array()); //prepare callback url
exit();
}
Sir, please add this class in your elFinder.
lovesin83@naver.com λκ» λ³΄λ΄μ λ©μΌ <Re: [Studio-42/elFinder] Google Drive for elFinder (#1329)> μ΄ λ€μκ³Ό κ°μ μ΄μ λ‘ μ μ‘ μ€ν¨νμ΅λλ€.
λ°λ μ¬λμ΄ νμλμ λ©μΌμ μμ μ°¨λ¨ νμμ΅λλ€.
Sir, please add this class in elFinder.
@rajasharma27 google-api-php-client-1.x is using Google Drive API V2. Currently, Google Drive API is V3.
google-api-php-client-2.x is using V3. Therefore, I think we should use oogle-api-php-client-2.x.
ok sir I'll upgrade according to v3
sir elFinder version v2.1.11 'cmdgetfile' : 'Select files' not working
sir, I am using now google-php-api-client with composer install v2.0.0RC7 successfully with composer but when i am running api code showing Fatal error
Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in D:\raja\phpgoogle\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:187 Stack trace: #0 D:\raja\phpgoogle\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(150): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array) #1 D:\raja\phpgoogle\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(103): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #2 D:\raja\phpgoogle\vendor\guzzlehttp\guzzle\src\Handler\CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #3 D:\raja\phpgoogle\vendor\guzzlehttp\guzzle\src\Handler\Proxy.php(28 in D:\raja\phpgoogle\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 187
ok , now working
sir, this google drive class working according to Google Drive API V3. and google-api-php-client-2.x
<?php elFinder::$netDrivers['googledrive'] = 'GoogleDrive';
/**
@author Raja Sharma - updating for GoogleDrive **/ class elFinderVolumeGoogleDrive extends elFinderVolumeDriver {
/**
/**
//protected $client = null;
/**
/**
/**
/**
/**
/**
/**
/**
/**
/**
private $tmbPrefix = '';
/**
$opts = array(
'clientId' => '',
'clientSecret' => '',
'redirecturi' => '',
'accessToken' => '',
'accessTokenSecret' => '',
'googledriveUid' => '',
'root' => 'GoogleDrive',
'callback' => 'node=elfinder&protocol=googledrive&host=googledrive.com&cmd=netmount&user=init&pass=return',
'path' => '/',
'childpath' => '',
'separator' => '/',
'treeDeep' => 0,
'tmbPath' => '../files/.tmb',
'tmbURL' => dirname($_SERVER['PHPSELF']) . '/../files/.tmb',
'tmpPath' => '../files/.tmp',
'getTmbSize' => 'large', // small: 32x32, medium or s: 64x64, large or m: 128x128, l: 640x480, xl: 1024x768
'metaCachePath' => '',
'metaCacheTime' => '600', // 10m
'acceptedName' => '#^[^/\?:|"<>]_[^./\?*:|"<>]$#',
'rootCssClass' => 'elfinder-navbar-root-googledrive'
);
$this->options = array_merge($this->options, $opts);
$this->options['mimeDetect'] = 'internal';
}
/**
if (empty($options['clientId']) && defined('ELFINDER_GOOGLEDRIVE_CLIENTID')) $options['clientId'] = ELFINDER_GOOGLEDRIVE_CLIENTID; if (empty($options['clientSecret']) && defined('ELFINDER_GOOGLEDRIVE_CLIENTSECRET')) $options['clientSecret'] = ELFINDER_GOOGLEDRIVE_CLIENTSECRET; if (empty($options['redirecturi']) && defined('ELFINDER_GOOGLEDRIVE_REDIRECTURI')) $options['redirecturi'] = ELFINDER_GOOGLEDRIVE_REDIRECTURI;
if (isset($_GET['code'])) {
$client = new Google_Client();
$client->setClientId($options['clientId']);
$client->setClientSecret($options['clientSecret']);
$client->setRedirectUri($options['redirecturi']);
$client->setScopes(array('https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/userinfo.profile'));
$oauth2 = new Google_Service_Oauth2($client);
$tokens = $client->fetchAccessTokenWithAuthCode($_GET['code']);
$tokens = base64_encode(json_encode($tokens));
$userinfo = $oauth2->userinfo->get();
$callback_url = $options['redirecturi'].'?'.$this->options['callback'].'&oauth_token='.$tokens.'&uid='.$userinfo['id'];
header("Location: ".$callback_url);
exit();
}
if ($options['user'] === 'init') {
if (empty($options['clientId']) || empty($options['clientSecret']) || empty($options['redirecturi'])) {
return array('exit' => true, 'body' => '{msg:errNetMountNoDriver}');
}
try{
$this->oauth = new Google_Client();
}catch (Exception $e){
return array('exit' => true, 'body' => '{msg:errNetMountNoDriver}');
}
if ($options['pass'] === 'init') {
$html = '';
if ($this->session->get('elFinderGoogledriveTokens')!==null) {
// token check
try {
list($options['googledriveUid'], $options['accessToken']) = $this->session->get('elFinderGoogledriveTokens');
$script = '<script>
$("#'.$options['id'].'").elfinder("instance").trigger("netmount", {protocol: "googledrive", mode: "done"});
</script>';
$html = $script;
} catch (GoogleDrive_Exception $e) {
$this->session->remove('elFinderGoogledriveTokens');
$this->session->remove('elFinderGoogleDriveAuthTokens');
}
}
if (! $html) {
// get customdata
$cdata = '';
$innerKeys = array('cmd', 'host', 'options', 'pass', 'protocol', 'user');
$this->ARGS = $_SERVER['REQUEST_METHOD'] === 'POST'? $_POST : $_GET;
foreach($this->ARGS as $k => $v) {
if (! in_array($k, $innerKeys)) {
$cdata .= '&' . $k . '=' . rawurlencode($v);
}
}
if (strpos($options['url'], 'http') !== 0 ) {
$options['url'] = $this->getConnectorUrl();
}
$callback = $options['url']
.'?cmd=netmount&protocol=googledrive&host=googledrive.com&user=init&pass=return&node='.$options['id'].$cdata;
try {
$client = new Google_Client();
// Get your credentials from the console
$client->setClientId($options['clientId']);
$client->setClientSecret($options['clientSecret']);
$client->setRedirectUri($options['redirecturi']);
$client->setScopes(array('https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive.metadata'));
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
$service = new Google_Service_Drive($client);
$this->oauth = $client->createAuthUrl();
$url = $this->oauth.='&oauth_callback='.rawurlencode($callback);
} catch (GoogleDrive_Exception $e) {
return array('exit' => true, 'body' => '{msg:errAccess}');
}
$this->session->set('elFinderGoogleDriveAuthTokens', $tokens);
$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" onclick="window.open(\''.$url.'\')">';
$html .= '<script>
$("#'.$options['id'].'").elfinder("instance").trigger("netmount", {protocol: "googledrive", mode: "makebtn"});
</script>';
}
return array('exit' => true, 'body' => $html);
} else {
if (isset($_GET['oauth_token'])) {
$this->session->set('elFinderGoogleDriveAuthTokens', json_decode(base64_decode($_GET["oauth_token"]),true));
}
$client = new Google_Client();
$client->setAccessToken($this->session->get('elFinderGoogleDriveAuthTokens'));
$oauth2 = new Google_Service_Oauth2($client);
$userid = $oauth2->userinfo->get();
$oauth_token = $this->session->get('elFinderGoogleDriveAuthTokens');
$this->session->set('elFinderGoogledriveTokens', array($userid['id'], $oauth_token));
$out = array(
'node' => $_GET['node'],
'json' => '{"protocol": "googledrive", "mode": "done"}',
'bind' => 'netmount'
);
return array('exit' => 'callback', 'out' => $out);
}
} if ($this->session->get('elFinderGoogledriveTokens')) {
list($options['googledriveUid'], $options['accessToken']) = $this->session->get('elFinderGoogledriveTokens');
$this->session->set('DriveCounter', (int)$this->session->get('DriveCounter')+1);
} unset($options['user'], $options['pass']);
return $options; }
/**
googledrive
& rm thumbs/**
@author Naoki Sawada
*/
private function getConnectorUrl() {
$url = ((isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off')? 'https://' : 'http://')
. $_SERVER['SERVER_NAME'] // host
. ($_SERVER['SERVER_PORT'] == 80 ? '' : ':' . $_SERVER['SERVER_PORT']) // port
. $_SERVER['REQUEST_URI']; // path & query
list($url) = explode('?', $url);
return $url; }
/****/ / INIT AND CONFIGURE */ /*****/
/**
@author Cem (DiscoFever) **/ protected function init() {
if (!$this->options['googledriveUid'] || !$this->options['accessToken']) { return $this->setError('Required options undefined.'); }
// make net mount key $this->netMountKey = md5(join('-', array('googledrive', $this->options['path'])));
if (! $this->oauth) {
$client = new Google_Client();
$client->setAccessToken($this->session->get('elFinderGoogleDriveAuthTokens'));
$this->oauth = new Google_Service_Drive($client);
}
if (! $this->oauth) { return $this->setError('OAuth extension not loaded.'); }
// normalize root path
if($this->options['path'] == '/'){
$this->root = $this->options['path'] = $this->_normpath($this->options['path']);
}else{
$this->options['childpath'] = $this->options['path'];
$this->options['path'] = $this->getRealpath($this->options['path']);
$this->root = $this->options['path'] = $this->_normpath($this->options['path']);
}
if (empty($this->options['alias'])) { $this->options['alias'] = ($this->options['path'] === '/')? 'GoogleDrive.com' : 'GoogleDrive'.$this->options['childpath']; }
$this->rootName = $this->options['alias'];
$this->googledriveUid = $this->options['googledriveUid']; $this->tmbPrefix = 'googledrive'.base_convert($this->googledriveUid, 10, 32);
if (!empty($this->options['tmpPath'])) { if ((is_dir($this->options['tmpPath']) || @mkdir($this->options['tmpPath'])) && is_writable($this->options['tmpPath'])) { $this->tmp = $this->options['tmpPath']; } } if (!$this->tmp && is_writable($this->options['tmbPath'])) { $this->tmp = $this->options['tmbPath']; } if (!$this->tmp && ($tmp = elFinder::getStaticVar('commonTempPath'))) { $this->tmp = $tmp; }
if (!empty($this->options['metaCachePath'])) { if ((is_dir($this->options['metaCachePath']) || @mkdir($this->options['metaCachePath'])) && is_writable($this->options['metaCachePath'])) { $this->metaCache = $this->options['metaCachePath']; } } if (!$this->metaCache && $this->tmp) { $this->metaCache = $this->tmp; }
if (!$this->metaCache) { return $this->setError('Cache dirctory (metaCachePath or tmp) is require.'); }
if (is_null($this->options['syncChkAsTs'])) { $this->options['syncChkAsTs'] = true; } if ($this->options['syncChkAsTs']) { // 'tsPlSleep' minmum 5 sec $this->options['tsPlSleep'] = max(5, $this->options['tsPlSleep']); } else { // 'lsPlSleep' minmum 10 sec $this->options['lsPlSleep'] = max(10, $this->options['lsPlSleep']); }
return true; }
/**
@author Dmitry (dio) Levashov
**/
protected function configure() {
parent::configure();
$this->disabled[] = 'archive';
$this->disabled[] = 'extract';
}
/**
@return boolean|array
*/
private function query($sql) {
//$files = new Google_Service_Drive_DriveFile();
$result = array(); $pageToken = NULL;
do { try { $parameters = array(); if ($pageToken) { $parameters['pageToken'] = $pageToken; } $files = $this->oauth->files->listFiles($sql);
$result = array_merge($result, $files->getFiles());
$pageToken = $files->getNextPageToken();
} catch (GoogleDrive_Exception $e) {
return $e->getMessage();
$pageToken = NULL;
return array();
}
} while ($pageToken); return $result;
//if($file = $this->oauth->files->listFiles($sql)){ // return $file; // }else{ // return array(); // } }
/**
try { $client = new Google_Client();
$client->setClientId($options['clientId']);
$client->setClientSecret($options['clientSecret']);
$access_token = $this->session->get('elFinderGoogleDriveAuthTokens');
$client->setAccessToken($access_token);
if ($client->isAccessTokenExpired()) {
$refresh_token = array_merge($access_token, $client->fetchAccessTokenWithRefreshToken());
$client->setAccessToken($refresh_token);
$this->session->set('elFinderGoogleDriveAuthTokens', $refresh_token);
$this->oauth = new Google_Service_Drive($client);
}
} catch(GoogleDrive_Exception $e) { return $e->getMessage(); } return true; }
/**
if($path == '/'){
return '/';
}
$this->refreshGoogleDriveToken();
//$files = new Google_Service_Drive_DriveFile();
$path== '/' || $path=='root' || $temppath[0]== '' || $temppath[0]== '/'? $itemId= 'root' : $itemId = basename($path);
foreach($temppath as $tpath) {
$opts = [
'fields' => 'files(id,name)',
'pageSize' => 1000,
'spaces' => 'drive',
'q' => sprintf('trashed=false and "%s" in parents', basename($itemId))
];
//$file = $this->oauth->files->listFiles($opts);
$file = $this->query($opts);
foreach($file as $raw) {
if($raw->name == $tpath || $raw->id ==$tpath ){
$itemId = $itemId.'/'.$raw->id;
break;
}
}
}
return $this->_normpath($itemId); }
/**
private function chkDBdat($path){
$files = new Google_Service_Drive_DriveFile();
$this->refreshGoogleDriveToken();
if($path == '/'){
return '/';
}else{
basename(dirname($path)) == '' ? $itemId = 'root' : $itemId = basename(dirname($path));
$opts = [
'fields' => 'files(id,name,mimeType)',
'pageSize' => 1000,
'spaces' => 'drive',
'q' => sprintf('trashed=false and "%s" in parents', $itemId)
];
//$file = $this->oauth->files->listFiles($opts);
$file = $this->query($opts);
foreach($file as $raw){
if($raw->name == basename($path) || $raw->id == basename($path)){
basename(dirname($path)) == '' ? $path = '/'.$raw->id : $path = dirname($path).'/'.$raw->id;
$res = array('path'=>$path, 'id'=>$raw->id, 'name'=>$raw->name, 'mimeType'=>$raw->mimeType);
return $res;
break;
}
}
return false;
}
}
/**
$itemId = $res['id'];
if($path == '/'){
$root = ['mimeType'=>self::DIRMIME];
return $root;
}
elseif($path !=='/' && $res['id'] !== null){
$opts = [
'fields' => self::FETCHFIELDS_GET
];
//$files = new Google_Service_Drive_DriveFile();
$res = $this->oauth->files->get($itemId,$opts);
return $res;
}
else {
return array();
}
}
/****/ / FS API */ /*****/
/**
}
/**
$stat['rev'] = isset($raw['id']) ? $raw['id'] : 'root';
$stat['name'] = $raw['name'];
$stat['mime'] = $raw['mimeType'] == self::DIRMIME ? 'directory' :
($raw['mimeType'] == 'image/bmp' ? 'image/x-ms-bmp' : $raw['mimeType']);
$stat['size'] = $raw['mimeType'] == self::DIRMIME ? 0 : (int)$raw['size'];
$stat['ts'] = isset($raw['modifiedTime']) ? strtotime($raw['modifiedTime']) : $_SERVER['REQUEST_TIME'];
$stat['dirs'] = $raw['mimeType'] == self::DIRMIME ? 1 : 0;
if (!empty($raw['webContentLink']) && (explode('/',$raw['mimeType'])[0] =='image' || explode('/',$raw['mimeType'])[0] =='video')) {
$stat['url'] = str_replace('export=download', 'e=media', $raw['webContentLink']);
} else {
$stat['url'] = '1';
}
if($raw['mimeType'] !== self::DIRMIME){
isset($raw->getImageMediaMetadata()['width']) ? $stat['width'] = $raw->getImageMediaMetadata()['width'] : $stat['width'] = 0;
isset($raw->getImageMediaMetadata()['height'])? $stat['height']= $raw->getImageMediaMetadata()['height']: $stat['height']= 0;
}
return $stat; }
/**
$path = $this->chkDBdat($path)['path'];
$path == '/' || $path =='root' ? $itemId= 'root' : $itemId = basename($path);
$opts = [
'fields' => self::FETCHFIELDS_LIST,
'pageSize' => 1000,
'spaces' => 'drive',
'q' => sprintf('trashed=false and "%s" in parents',$itemId)
];
$this->dirsCache[$path] = array(); $res = $this->query($opts); $path == '/' || $path =='root' ? $mountPath = '/' : $mountPath = $path.'/';
if ($res) {
foreach($res as $raw) {
if ($stat = $this->parseRaw($raw)) {
$stat = $this->updateCache($mountPath.$raw->id, $stat);
if (empty($stat['hidden']) && $path !== $mountPath.$raw->id) {
$this->dirsCache[$path][] = $mountPath.$raw->id;
}
}
}
}
return $this->dirsCache[$path]; }
/**
$mimeType = parent::$mimetypes[strtolower($q)];
if(substr($q,0,1)== '*' || $mimeType !== null){ $mimeType == '' ? $mimeType= parent::$mimetypes[pathinfo(strtolower($q),PATHINFO_EXTENSION)] : $mimeType = $mimeType; $path == '/' ? $q = sprintf('trashed=false and mimeType = "%s"', $mimeType) : $q = sprintf('trashed=false and "%s" in parents and mimeType = "%s"', $itemId, $mimeType);
$opts = [
'fields' => self::FETCHFIELDS_LIST,
'pageSize' => 1000,
'spaces' => 'drive',
'q' => $q
];
}else{
$path == '/' ? $q = sprintf('trashed=false and name = "%s"', strtolower($q)) : $q = sprintf('trashed=false and "%s" in parents and name = "%s"', $itemId, strtolower($q));
$opts = [
'fields' => self::FETCHFIELDS_LIST,
'pageSize' => 1000,
'spaces' => 'drive',
'q' => $q
];
}
$res = $this->query($opts);
$timeout = $this->options['searchTimeout']? $this->searchStart + $this->options['searchTimeout'] : 0; $path == '/' || $path =='root' ? $mountPath = '/' : $mountPath = $path.'/';
if ($res) { foreach($res as $raw) { if ($timeout && $timeout < time()) { $this->setError(elFinder::ERROR_SEARCH_TIMEOUT, $this->path($this->encode($path))); break; }
if ($stat = $this->parseRaw($raw)) {
if (!isset($this->cache[$mountPath.$raw->id])) {
$stat = $this->updateCache($mountPath.$raw->id, $stat);
}
if (!empty($stat['hidden']) || ($mimes && $stat['mime'] === 'directory') || !$this->mimeAccepted($stat['mime'], $mimes)) {
continue;
}
$stat = $this->stat($mountPath.$raw->id);
$stat['path'] = $this->path($stat['hash']);
$result[] = $stat;
}
}
}
return $result; }
/**
if($this->chkDBdat($src)['mimeType'] == self::DIRMIME){
$itemId = basename($this->_mkdir($dst, $name));
$path = $this->_joinPath($dst, $itemId);
$opts = [
'fields' => self::FETCHFIELDS_LIST,
'pageSize' => 1000,
'spaces' => 'drive',
'q' => sprintf('trashed=false and "%s" in parents', basename($src))
];
$res = $this->query($opts);
foreach($res as $raw){
$raw['mimeType'] == self::DIRMIME ? $this->copy($src.'/'.$raw['id'],$path,$raw['name']) : $this->_copy($src.'/'.$raw['id'], $path, $raw['name']);
}
return $itemId
? $this->_joinPath($dst, $itemId)
: $this->setError(elFinder::ERROR_COPY, $this->_path($src));
}else{
$itemId = $this->_copy($src, $dst, $name);
return $itemId
? $this->_joinPath($dst, $itemId)
: $this->setError(elFinder::ERROR_COPY, $this->_path($src));
}
}
/**
if (empty($stat)) { return $this->setError(elFinder::ERROR_RM, $this->_path($path), elFinder::ERROR_FILE_NOT_FOUND); }
if (!$force && !empty($stat['locked'])) { return $this->setError(elFinder::ERROR_LOCKED, $this->_path($path)); }
if ($stat['mime'] == 'directory') { if (!$recursive && !$this->_rmdir($path)) { return $this->setError(elFinder::ERROR_RM, $this->_path($path)); } } else { if (!$recursive && !$this->_unlink($path)) { return $this->setError(elFinder::ERROR_RM, $this->_path($path)); } }
$this->removed[] = $stat; return true; }
/**
if (!$stat || !$this->canCreateTmb($path, $stat)) { return false; }
$name = $this->tmbname($stat); $tmb = $this->tmbPath.DIRECTORY_SEPARATOR.$name;
// copy image into tmbPath so some drivers does not store files on local fs if (! $data = $this->getThumbnail($path)) { return false; } if (! file_put_contents($tmb, $data)) { return false; }
$result = false;
$tmbSize = $this->tmbSize;
if (($s = getimagesize($tmb)) == false) { return false; }
/* If image smaller or equal thumbnail size - just fitting to thumbnail square */ if ($s[0] <= $tmbSize && $s[1] <= $tmbSize) { $result = $this->imgSquareFit($tmb, $tmbSize, $tmbSize, 'center', 'middle', $this->options['tmbBgColor'], 'png' );
} else {
if ($this->options['tmbCrop']) {
/* Resize and crop if image bigger than thumbnail */
if (!(($s[0] > $tmbSize && $s[1] <= $tmbSize) || ($s[0] <= $tmbSize && $s[1] > $tmbSize) ) || ($s[0] > $tmbSize && $s[1] > $tmbSize)) {
$result = $this->imgResize($tmb, $tmbSize, $tmbSize, true, false, 'png');
}
if (($s = getimagesize($tmb)) != false) {
$x = $s[0] > $tmbSize ? intval(($s[0] - $tmbSize)/2) : 0;
$y = $s[1] > $tmbSize ? intval(($s[1] - $tmbSize)/2) : 0;
$result = $this->imgCrop($tmb, $tmbSize, $tmbSize, $x, $y, 'png');
}
} else {
$result = $this->imgResize($tmb, $tmbSize, $tmbSize, true, true, 'png');
}
$result = $this->imgSquareFit($tmb, $tmbSize, $tmbSize, 'center', 'middle', $this->options['tmbBgColor'], 'png' );
}
if (!$result) { unlink($tmb); return false; }
return $name; }
/**
/**
try {
$res = $this->oauth->files->get($itemId, [
'fields' => 'id,thumbnailLink' // contents with thumbnailLink
//'alt' => 'media' // contents with file media
]);
return file_get_contents($res->thumbnailLink); // contents with thumbnailLink
//return $res; // contents with file media
} catch (GoogleDrive_Exception $e) { return false;
} }
/**
if (($file = $this->file($hash)) == false || !$file['url'] || $file['url'] == 1) { $path = $this->decode($hash);
//$files = new Google_Service_Drive_DriveFile();
$itemId = basename($path);
$res = $this->oauth->files->get($itemId, [
'fields' => 'id,webContentLink'
//'alt' => 'media'
]);
$url = str_replace('export=download', 'e=media', $res->webContentLink);
return $url;
} return $file['url']; }
/**
/*** paths/urls *****/
/**
/**
/**
/**
return $path; }
/**
/**
/**
/**
/***** file stat *******/ /*
if ($this->isMyReload()) { $this->refreshGoogleDriveToken(); }
if ($raw = $this->getDBdat($path)) { return $this->parseRaw($raw);; } return false; }
/**
/**
if (strpos($mime, 'image') !== 0) return ''; $cache = $this->getDBdat($path);
if (isset($cache['imageMediaMetadata']['width']) && isset($cache['imageMediaMetadata']['height'])) {
return $cache['imageMediaMetadata']['width'].'x'.$cache['imageMediaMetadata']['height'];
}
$ret = '';
if ($work = $this->getWorkFile($path)) {
if ($size = @getimagesize($work)) {
$cache['width'] = $size[0];
$cache['height'] = $size[1];
$ret = $size[0].'x'.$size[1];
}
}
is_file($work) && @unlink($work);
return $ret;
}
/**** file/dir content *****/
/**
/**
if (($mode == 'rb' || $mode == 'r')) {
try {
//$files = new Google_Service_Drive_DriveFile();
$itemId = basename($path);
$contents = $this->oauth->files->get($itemId, [
//'fields' => 'id,webContentLink',
'alt' => 'media'
]);
$contents = $contents->getBody()->detach();
rewind($contents);
//$fp = tmpfile();
//fputs($fp , $contents);
//while(trim(fgets($fp)) !== ''){};
//rewind($fp);
return $contents;
} catch (GoogleDrive_Exception $e) {
return false;
}
}
if ($this->tmp) { $contents = $this->_getContents($path);
if ($contents === false) {
return false;
}
if ($local = $this->getTempFile($path)) {
if (file_put_contents($local, $contents, LOCK_EX) !== false) {
return @fopen($local, $mode);
}
}
}
return false; }
/**
/**** file/dir manipulations *****/
/**
try { $files = new Google_Service_Drive_DriveFile();
$files->setName($name);
$files->setMimeType(self::DIRMIME);
$files->setParents(array($parentId));
//create the Folder in the Parent
$createdFile = $this->oauth->files->create($files);
basename(dirname($path)) == '' ? $path = '/'.$createdFile['id'] : $path = dirname($path).'/'.$createdFile['id'];
return $path;
} catch (GoogleDrive_Exception $e) {
return $this->setError('GoogleDrive error: '.$e->getMessage());
}
return $path; }
/**
/**
/**
try {
$files = new Google_Service_Drive_DriveFile();
$files->setName($name);
//Set the Parent id
$targetDir == '/' ? $parentId = 'root' : $parentId = basename($targetDir);
$files->setParents(array($parentId));
$file = $this->oauth->files->copy(basename($source), $files,['fields' => self::FETCHFIELDS_GET]);
$itemId = $file->id;
return $itemId;
} catch (GoogleDrive_Exception $e) {
return $this->setError('GoogleDrive error: '.$e->getMessage());
}
return true;
}
/**
//Set new Parent and remove old parent
$targetDir == '/' || $targetDir == 'root' ? $addParents = 'root' : $addParents = basename($targetDir);
basename(dirname($source)) == '/' || basename(dirname($source)) == '' ? $removeParents = 'root' : $removeParents = basename(dirname($source));
$opts = ['addParents'=>$addParents,'removeParents'=>$removeParents];
$file = $this->oauth->files->update(basename($source), $files, $opts);
} catch (GoogleDrive_Exception $e) { return $this->setError('GoogleDrive error: '.$e->getMessage()); }
return $target; }
/**
try {
$files = new Google_Service_Drive_DriveFile();
$files->setTrashed(true);
$opts = ['removeParents'=>basename(dirname($path))];
$this->oauth->files->update(basename($path),$files,$opts);
} catch (GoogleDrive_Exception $e) {
return $this->setError('GoogleDrive error: '.$e->getMessage());
}
return true;
}
/**
/**
if ($name) $path .= '/'.$name; $path = $this->_normpath($path); $res = $this->chkDBdat($path);
try {
//Insert or Update a file
$files = new Google_Service_Drive_DriveFile();
if($res['id'] !== null){
// First retrieve the file from the API.
$itemId = basename($path);
$name = $res['name'];
$mimeType = $res['mimeType'];
$files->setName($name);
$files->setDescription('');
$files->setMimeType($mimeType);
// Send the request to the API for updation contents.
$data= stream_get_contents($fp);
$file = $this->oauth->files->update($itemId, $files, array(
'data' => strlen($data) == 0 ? ' ' : $data,
'mimeType' => $mimeType,
'uploadType' => 'multipart'
));
}else {
$name == '' ? $name = basename($path) : $name = $name;
$files->setName($name);
$files->setDescription('');
$stat['mime'] == '' ? $mimeType= parent::$mimetypes[pathinfo(basename($path),PATHINFO_EXTENSION)] : $mimeType= $stat['mime'];
$files->setMimeType($mimeType);
//Set the Folder Parent
basename(dirname($path)) == '' ? $parentId = 'root' : $parentId = basename(dirname($path));
$files->setParents(array($parentId));
$data= stream_get_contents($fp);
$file = $this->oauth->files->create($files, array(
'data' => strlen($data) == 0 ? ' ' : $data,
'mimeType' => $mimeType,
'uploadType' => 'media'
));
}
} catch (GoogleDrive_Exception $e) {
return $this->setError('GoogleDrive error: '.$e->getMessage());
}
basename(dirname($path)) == '' ? $path = '/'.$file['id'] : $path = dirname($path).'/'.$file['id']; return $path; }
/**
try {
//$files = new Google_Service_Drive_DriveFile();
$itemId = basename($path);
$contents = $this->oauth->files->get($itemId, [
'alt' => 'media'
]);
$contents = (string) $contents->getBody();
} catch (GoogleDrive_Exception $e) {
return $this->setError('GoogleDrive error: '.$e->getMessage());
}
return $contents; }
/**
if ($local = $this->getTempFile($path)) { if (@file_put_contents($local, $content, LOCK_EX) !== false && ($fp = @fopen($local, 'rb'))) {
clearstatcache();
$res = $this->_save($fp, $path, '', array());
@fclose($fp);
}
file_exists($local) && @unlink($local);
}
return $res; }
/**
/**
/**
/**
/**
/**
} // END class
@rajasharma27 Please send pull request. And, let's discuss in there.
ok thank sir
moved to #1361
Sir, my google drive class is working perfectly with stable version is google-api-php-client-1.1.7 please add this class in next version of elFinder
1. elfinder.full.js
2. elFinderVolumeGoogleDrive.class