Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/wp-conte.../plugins/wp-file-.../lib/php
File: elFinderVolumeGoogleDrive.class.php
/**
[500] Fix | Delete
* Get thumbnail from GoogleDrive.com.
[501] Fix | Delete
*
[502] Fix | Delete
* @param string $path
[503] Fix | Delete
*
[504] Fix | Delete
* @return string | boolean
[505] Fix | Delete
*/
[506] Fix | Delete
protected function _gd_getThumbnail($path)
[507] Fix | Delete
{
[508] Fix | Delete
list(, $itemId) = $this->_gd_splitPath($path);
[509] Fix | Delete
[510] Fix | Delete
try {
[511] Fix | Delete
$contents = $this->service->files->get($itemId, [
[512] Fix | Delete
'alt' => 'media',
[513] Fix | Delete
]);
[514] Fix | Delete
$contents = $contents->getBody()->detach();
[515] Fix | Delete
rewind($contents);
[516] Fix | Delete
[517] Fix | Delete
return $contents;
[518] Fix | Delete
} catch (Exception $e) {
[519] Fix | Delete
return false;
[520] Fix | Delete
}
[521] Fix | Delete
}
[522] Fix | Delete
[523] Fix | Delete
/**
[524] Fix | Delete
* Publish permissions specified path item.
[525] Fix | Delete
*
[526] Fix | Delete
* @param string $path
[527] Fix | Delete
*
[528] Fix | Delete
* @return bool
[529] Fix | Delete
*/
[530] Fix | Delete
protected function _gd_publish($path)
[531] Fix | Delete
{
[532] Fix | Delete
if ($file = $this->_gd_getFile($path)) {
[533] Fix | Delete
if ($this->_gd_isPublished($file)) {
[534] Fix | Delete
return true;
[535] Fix | Delete
}
[536] Fix | Delete
try {
[537] Fix | Delete
if ($this->service->permissions->create($file->getId(), new \Google_Service_Drive_Permission($this->options['publishPermission']))) {
[538] Fix | Delete
return true;
[539] Fix | Delete
}
[540] Fix | Delete
} catch (Exception $e) {
[541] Fix | Delete
return false;
[542] Fix | Delete
}
[543] Fix | Delete
}
[544] Fix | Delete
[545] Fix | Delete
return false;
[546] Fix | Delete
}
[547] Fix | Delete
[548] Fix | Delete
/**
[549] Fix | Delete
* unPublish permissions specified path.
[550] Fix | Delete
*
[551] Fix | Delete
* @param string $path
[552] Fix | Delete
*
[553] Fix | Delete
* @return bool
[554] Fix | Delete
*/
[555] Fix | Delete
protected function _gd_unPublish($path)
[556] Fix | Delete
{
[557] Fix | Delete
if ($file = $this->_gd_getFile($path)) {
[558] Fix | Delete
if (!$this->_gd_isPublished($file)) {
[559] Fix | Delete
return true;
[560] Fix | Delete
}
[561] Fix | Delete
$permissions = $file->getPermissions();
[562] Fix | Delete
$pType = $this->options['publishPermission']['type'];
[563] Fix | Delete
$pRole = $this->options['publishPermission']['role'];
[564] Fix | Delete
try {
[565] Fix | Delete
foreach ($permissions as $permission) {
[566] Fix | Delete
if ($permission->type === $pType && $permission->role === $pRole) {
[567] Fix | Delete
$this->service->permissions->delete($file->getId(), $permission->getId());
[568] Fix | Delete
[569] Fix | Delete
return true;
[570] Fix | Delete
break;
[571] Fix | Delete
}
[572] Fix | Delete
}
[573] Fix | Delete
} catch (Exception $e) {
[574] Fix | Delete
return false;
[575] Fix | Delete
}
[576] Fix | Delete
}
[577] Fix | Delete
[578] Fix | Delete
return false;
[579] Fix | Delete
}
[580] Fix | Delete
[581] Fix | Delete
/**
[582] Fix | Delete
* Read file chunk.
[583] Fix | Delete
*
[584] Fix | Delete
* @param resource $handle
[585] Fix | Delete
* @param int $chunkSize
[586] Fix | Delete
*
[587] Fix | Delete
* @return string
[588] Fix | Delete
*/
[589] Fix | Delete
protected function _gd_readFileChunk($handle, $chunkSize)
[590] Fix | Delete
{
[591] Fix | Delete
$byteCount = 0;
[592] Fix | Delete
$giantChunk = '';
[593] Fix | Delete
while (!feof($handle)) {
[594] Fix | Delete
// fread will never return more than 8192 bytes if the stream is read buffered and it does not represent a plain file
[595] Fix | Delete
$chunk = fread($handle, 8192);
[596] Fix | Delete
$byteCount += strlen($chunk);
[597] Fix | Delete
$giantChunk .= $chunk;
[598] Fix | Delete
if ($byteCount >= $chunkSize) {
[599] Fix | Delete
return $giantChunk;
[600] Fix | Delete
}
[601] Fix | Delete
}
[602] Fix | Delete
[603] Fix | Delete
return $giantChunk;
[604] Fix | Delete
}
[605] Fix | Delete
[606] Fix | Delete
/*********************************************************************/
[607] Fix | Delete
/* EXTENDED FUNCTIONS */
[608] Fix | Delete
/*********************************************************************/
[609] Fix | Delete
[610] Fix | Delete
/**
[611] Fix | Delete
* Prepare
[612] Fix | Delete
* Call from elFinder::netmout() before volume->mount().
[613] Fix | Delete
*
[614] Fix | Delete
* @return array
[615] Fix | Delete
* @author Naoki Sawada
[616] Fix | Delete
* @author Raja Sharma updating for GoogleDrive
[617] Fix | Delete
**/
[618] Fix | Delete
public function netmountPrepare($options)
[619] Fix | Delete
{
[620] Fix | Delete
if (empty($options['client_id']) && defined('ELFINDER_GOOGLEDRIVE_CLIENTID')) {
[621] Fix | Delete
$options['client_id'] = ELFINDER_GOOGLEDRIVE_CLIENTID;
[622] Fix | Delete
}
[623] Fix | Delete
if (empty($options['client_secret']) && defined('ELFINDER_GOOGLEDRIVE_CLIENTSECRET')) {
[624] Fix | Delete
$options['client_secret'] = ELFINDER_GOOGLEDRIVE_CLIENTSECRET;
[625] Fix | Delete
}
[626] Fix | Delete
if (empty($options['googleApiClient']) && defined('ELFINDER_GOOGLEDRIVE_GOOGLEAPICLIENT')) {
[627] Fix | Delete
$options['googleApiClient'] = ELFINDER_GOOGLEDRIVE_GOOGLEAPICLIENT;
[628] Fix | Delete
include_once $options['googleApiClient'];
[629] Fix | Delete
}
[630] Fix | Delete
[631] Fix | Delete
if (!isset($options['pass'])) {
[632] Fix | Delete
$options['pass'] = '';
[633] Fix | Delete
}
[634] Fix | Delete
[635] Fix | Delete
try {
[636] Fix | Delete
$client = new \Google_Client();
[637] Fix | Delete
$client->setClientId($options['client_id']);
[638] Fix | Delete
$client->setClientSecret($options['client_secret']);
[639] Fix | Delete
[640] Fix | Delete
if ($options['pass'] === 'reauth') {
[641] Fix | Delete
$options['pass'] = '';
[642] Fix | Delete
$this->session->set('GoogleDriveAuthParams', [])->set('GoogleDriveTokens', []);
[643] Fix | Delete
} elseif ($options['pass'] === 'googledrive') {
[644] Fix | Delete
$options['pass'] = '';
[645] Fix | Delete
}
[646] Fix | Delete
[647] Fix | Delete
$options = array_merge($this->session->get('GoogleDriveAuthParams', []), $options);
[648] Fix | Delete
[649] Fix | Delete
if (!isset($options['access_token'])) {
[650] Fix | Delete
$options['access_token'] = $this->session->get('GoogleDriveTokens', []);
[651] Fix | Delete
$this->session->remove('GoogleDriveTokens');
[652] Fix | Delete
}
[653] Fix | Delete
$aToken = $options['access_token'];
[654] Fix | Delete
[655] Fix | Delete
$rootObj = $service = null;
[656] Fix | Delete
if ($aToken) {
[657] Fix | Delete
try {
[658] Fix | Delete
$client->setAccessToken($aToken);
[659] Fix | Delete
if ($client->isAccessTokenExpired()) {
[660] Fix | Delete
$aToken = array_merge($aToken, $client->fetchAccessTokenWithRefreshToken());
[661] Fix | Delete
$client->setAccessToken($aToken);
[662] Fix | Delete
}
[663] Fix | Delete
$service = new \Google_Service_Drive($client);
[664] Fix | Delete
$rootObj = $service->files->get('root');
[665] Fix | Delete
[666] Fix | Delete
$options['access_token'] = $aToken;
[667] Fix | Delete
$this->session->set('GoogleDriveAuthParams', $options);
[668] Fix | Delete
} catch (Exception $e) {
[669] Fix | Delete
$aToken = [];
[670] Fix | Delete
$options['access_token'] = [];
[671] Fix | Delete
if ($options['user'] !== 'init') {
[672] Fix | Delete
$this->session->set('GoogleDriveAuthParams', $options);
[673] Fix | Delete
[674] Fix | Delete
return ['exit' => true, 'error' => elFinder::ERROR_REAUTH_REQUIRE];
[675] Fix | Delete
}
[676] Fix | Delete
}
[677] Fix | Delete
}
[678] Fix | Delete
[679] Fix | Delete
$itpCare = isset($options['code']);
[680] Fix | Delete
$code = $itpCare? $options['code'] : (isset($_GET['code'])? $_GET['code'] : '');
[681] Fix | Delete
if ($code || (isset($options['user']) && $options['user'] === 'init')) {
[682] Fix | Delete
if (empty($options['url'])) {
[683] Fix | Delete
$options['url'] = elFinder::getConnectorUrl();
[684] Fix | Delete
}
[685] Fix | Delete
[686] Fix | Delete
if (isset($options['id'])) {
[687] Fix | Delete
$callback = $options['url']
[688] Fix | Delete
. (strpos($options['url'], '?') !== false? '&' : '?') . 'cmd=netmount&protocol=googledrive&host=' . ($options['id'] === 'elfinder'? '1' : $options['id']);
[689] Fix | Delete
$client->setRedirectUri($callback);
[690] Fix | Delete
}
[691] Fix | Delete
[692] Fix | Delete
if (!$aToken && empty($code)) {
[693] Fix | Delete
$client->setScopes([Google_Service_Drive::DRIVE]);
[694] Fix | Delete
if (!empty($options['offline'])) {
[695] Fix | Delete
$client->setApprovalPrompt('force');
[696] Fix | Delete
$client->setAccessType('offline');
[697] Fix | Delete
}
[698] Fix | Delete
$url = $client->createAuthUrl();
[699] Fix | Delete
[700] Fix | Delete
$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">';
[701] Fix | Delete
$html .= '<script>
[702] Fix | Delete
jQuery("#' . $options['id'] . '").elfinder("instance").trigger("netmount", {protocol: "googledrive", mode: "makebtn", url: "' . $url . '"});
[703] Fix | Delete
</script>';
[704] Fix | Delete
if (empty($options['pass']) && $options['host'] !== '1') {
[705] Fix | Delete
$options['pass'] = 'return';
[706] Fix | Delete
$this->session->set('GoogleDriveAuthParams', $options);
[707] Fix | Delete
[708] Fix | Delete
return ['exit' => true, 'body' => $html];
[709] Fix | Delete
} else {
[710] Fix | Delete
$out = [
[711] Fix | Delete
'node' => $options['id'],
[712] Fix | Delete
'json' => '{"protocol": "googledrive", "mode": "makebtn", "body" : "' . str_replace($html, '"', '\\"') . '", "error" : "' . elFinder::ERROR_ACCESS_DENIED . '"}',
[713] Fix | Delete
'bind' => 'netmount',
[714] Fix | Delete
];
[715] Fix | Delete
[716] Fix | Delete
return ['exit' => 'callback', 'out' => $out];
[717] Fix | Delete
}
[718] Fix | Delete
} else {
[719] Fix | Delete
if ($code) {
[720] Fix | Delete
if (!empty($options['id'])) {
[721] Fix | Delete
$aToken = $client->fetchAccessTokenWithAuthCode($code);
[722] Fix | Delete
$options['access_token'] = $aToken;
[723] Fix | Delete
unset($options['code']);
[724] Fix | Delete
$this->session->set('GoogleDriveTokens', $aToken)->set('GoogleDriveAuthParams', $options);
[725] Fix | Delete
$out = [
[726] Fix | Delete
'node' => $options['id'],
[727] Fix | Delete
'json' => '{"protocol": "googledrive", "mode": "done", "reset": 1}',
[728] Fix | Delete
'bind' => 'netmount',
[729] Fix | Delete
];
[730] Fix | Delete
} else {
[731] Fix | Delete
$nodeid = ($_GET['host'] === '1')? 'elfinder' : $_GET['host'];
[732] Fix | Delete
$out = array(
[733] Fix | Delete
'node' => $nodeid,
[734] Fix | Delete
'json' => json_encode(array(
[735] Fix | Delete
'protocol' => 'googledrive',
[736] Fix | Delete
'host' => $nodeid,
[737] Fix | Delete
'mode' => 'redirect',
[738] Fix | Delete
'options' => array(
[739] Fix | Delete
'id' => $nodeid,
[740] Fix | Delete
'code'=> $code
[741] Fix | Delete
)
[742] Fix | Delete
)),
[743] Fix | Delete
'bind' => 'netmount'
[744] Fix | Delete
);
[745] Fix | Delete
}
[746] Fix | Delete
if (!$itpCare) {
[747] Fix | Delete
return array('exit' => 'callback', 'out' => $out);
[748] Fix | Delete
} else {
[749] Fix | Delete
return array('exit' => true, 'body' => $out['json']);
[750] Fix | Delete
}
[751] Fix | Delete
}
[752] Fix | Delete
$path = $options['path'];
[753] Fix | Delete
if ($path === '/') {
[754] Fix | Delete
$path = 'root';
[755] Fix | Delete
}
[756] Fix | Delete
$folders = [];
[757] Fix | Delete
foreach ($service->files->listFiles([
[758] Fix | Delete
'pageSize' => 1000,
[759] Fix | Delete
'q' => sprintf('trashed = false and "%s" in parents and mimeType = "application/vnd.google-apps.folder"', $path),
[760] Fix | Delete
]) as $f) {
[761] Fix | Delete
$folders[$f->getId()] = $f->getName();
[762] Fix | Delete
}
[763] Fix | Delete
natcasesort($folders);
[764] Fix | Delete
[765] Fix | Delete
if ($options['pass'] === 'folders') {
[766] Fix | Delete
return ['exit' => true, 'folders' => $folders];
[767] Fix | Delete
}
[768] Fix | Delete
[769] Fix | Delete
$folders = ['root' => $rootObj->getName()] + $folders;
[770] Fix | Delete
$folders = json_encode($folders);
[771] Fix | Delete
$expires = empty($aToken['refresh_token']) ? $aToken['created'] + $aToken['expires_in'] - 30 : 0;
[772] Fix | Delete
$mnt2res = empty($aToken['refresh_token']) ? '' : ', "mnt2res": 1';
[773] Fix | Delete
$json = '{"protocol": "googledrive", "mode": "done", "folders": ' . $folders . ', "expires": ' . $expires . $mnt2res . '}';
[774] Fix | Delete
$options['pass'] = 'return';
[775] Fix | Delete
$html = 'Google.com';
[776] Fix | Delete
$html .= '<script>
[777] Fix | Delete
jQuery("#' . $options['id'] . '").elfinder("instance").trigger("netmount", ' . $json . ');
[778] Fix | Delete
</script>';
[779] Fix | Delete
$this->session->set('GoogleDriveAuthParams', $options);
[780] Fix | Delete
[781] Fix | Delete
return ['exit' => true, 'body' => $html];
[782] Fix | Delete
}
[783] Fix | Delete
}
[784] Fix | Delete
} catch (Exception $e) {
[785] Fix | Delete
$this->session->remove('GoogleDriveAuthParams')->remove('GoogleDriveTokens');
[786] Fix | Delete
if (empty($options['pass'])) {
[787] Fix | Delete
return ['exit' => true, 'body' => '{msg:' . elFinder::ERROR_ACCESS_DENIED . '}' . ' ' . $e->getMessage()];
[788] Fix | Delete
} else {
[789] Fix | Delete
return ['exit' => true, 'error' => [elFinder::ERROR_ACCESS_DENIED, $e->getMessage()]];
[790] Fix | Delete
}
[791] Fix | Delete
}
[792] Fix | Delete
[793] Fix | Delete
if (!$aToken) {
[794] Fix | Delete
return ['exit' => true, 'error' => elFinder::ERROR_REAUTH_REQUIRE];
[795] Fix | Delete
}
[796] Fix | Delete
[797] Fix | Delete
if ($options['path'] === '/') {
[798] Fix | Delete
$options['path'] = 'root';
[799] Fix | Delete
}
[800] Fix | Delete
[801] Fix | Delete
try {
[802] Fix | Delete
$file = $service->files->get($options['path']);
[803] Fix | Delete
$options['alias'] = sprintf($this->options['gdAlias'], $file->getName());
[804] Fix | Delete
} catch (Google_Service_Exception $e) {
[805] Fix | Delete
$err = json_decode($e->getMessage(), true);
[806] Fix | Delete
if (isset($err['error']) && $err['error']['code'] == 404) {
[807] Fix | Delete
return ['exit' => true, 'error' => [elFinder::ERROR_TRGDIR_NOT_FOUND, $options['path']]];
[808] Fix | Delete
} else {
[809] Fix | Delete
return ['exit' => true, 'error' => $e->getMessage()];
[810] Fix | Delete
}
[811] Fix | Delete
} catch (Exception $e) {
[812] Fix | Delete
return ['exit' => true, 'error' => $e->getMessage()];
[813] Fix | Delete
}
[814] Fix | Delete
[815] Fix | Delete
foreach (['host', 'user', 'pass', 'id', 'offline'] as $key) {
[816] Fix | Delete
unset($options[$key]);
[817] Fix | Delete
}
[818] Fix | Delete
[819] Fix | Delete
return $options;
[820] Fix | Delete
}
[821] Fix | Delete
[822] Fix | Delete
/**
[823] Fix | Delete
* process of on netunmount
[824] Fix | Delete
* Drop `googledrive` & rm thumbs.
[825] Fix | Delete
*
[826] Fix | Delete
* @param $netVolumes
[827] Fix | Delete
* @param $key
[828] Fix | Delete
*
[829] Fix | Delete
* @return bool
[830] Fix | Delete
*/
[831] Fix | Delete
public function netunmount($netVolumes, $key)
[832] Fix | Delete
{
[833] Fix | Delete
if (!$this->options['useGoogleTmb']) {
[834] Fix | Delete
if ($tmbs = glob(rtrim($this->options['tmbPath'], '\\/') . DIRECTORY_SEPARATOR . $this->netMountKey . '*.png')) {
[835] Fix | Delete
foreach ($tmbs as $file) {
[836] Fix | Delete
unlink($file);
[837] Fix | Delete
}
[838] Fix | Delete
}
[839] Fix | Delete
}
[840] Fix | Delete
$this->session->remove($this->id . $this->netMountKey);
[841] Fix | Delete
[842] Fix | Delete
return true;
[843] Fix | Delete
}
[844] Fix | Delete
[845] Fix | Delete
/**
[846] Fix | Delete
* Return fileinfo based on filename
[847] Fix | Delete
* For item ID based path file system
[848] Fix | Delete
* Please override if needed on each drivers.
[849] Fix | Delete
*
[850] Fix | Delete
* @param string $path file cache
[851] Fix | Delete
*
[852] Fix | Delete
* @return array
[853] Fix | Delete
*/
[854] Fix | Delete
protected function isNameExists($path)
[855] Fix | Delete
{
[856] Fix | Delete
list($parentId, $name) = $this->_gd_splitPath($path);
[857] Fix | Delete
$opts = [
[858] Fix | Delete
'q' => sprintf('trashed=false and "%s" in parents and name="%s"', $parentId, $name),
[859] Fix | Delete
'fields' => self::FETCHFIELDS_LIST,
[860] Fix | Delete
];
[861] Fix | Delete
$srcFile = $this->_gd_query($opts);
[862] Fix | Delete
[863] Fix | Delete
return empty($srcFile) ? false : $this->_gd_parseRaw($srcFile[0]);
[864] Fix | Delete
}
[865] Fix | Delete
[866] Fix | Delete
/*********************************************************************/
[867] Fix | Delete
/* INIT AND CONFIGURE */
[868] Fix | Delete
/*********************************************************************/
[869] Fix | Delete
[870] Fix | Delete
/**
[871] Fix | Delete
* Prepare FTP connection
[872] Fix | Delete
* Connect to remote server and check if credentials are correct, if so, store the connection id in $ftp_conn.
[873] Fix | Delete
*
[874] Fix | Delete
* @return bool
[875] Fix | Delete
* @author Dmitry (dio) Levashov
[876] Fix | Delete
* @author Cem (DiscoFever)
[877] Fix | Delete
**/
[878] Fix | Delete
protected function init()
[879] Fix | Delete
{
[880] Fix | Delete
$serviceAccountConfig = '';
[881] Fix | Delete
if (empty($this->options['serviceAccountConfigFile'])) {
[882] Fix | Delete
if (empty($options['client_id'])) {
[883] Fix | Delete
if (defined('ELFINDER_GOOGLEDRIVE_CLIENTID') && ELFINDER_GOOGLEDRIVE_CLIENTID) {
[884] Fix | Delete
$this->options['client_id'] = ELFINDER_GOOGLEDRIVE_CLIENTID;
[885] Fix | Delete
} else {
[886] Fix | Delete
return $this->setError('Required option "client_id" is undefined.');
[887] Fix | Delete
}
[888] Fix | Delete
}
[889] Fix | Delete
if (empty($options['client_secret'])) {
[890] Fix | Delete
if (defined('ELFINDER_GOOGLEDRIVE_CLIENTSECRET') && ELFINDER_GOOGLEDRIVE_CLIENTSECRET) {
[891] Fix | Delete
$this->options['client_secret'] = ELFINDER_GOOGLEDRIVE_CLIENTSECRET;
[892] Fix | Delete
} else {
[893] Fix | Delete
return $this->setError('Required option "client_secret" is undefined.');
[894] Fix | Delete
}
[895] Fix | Delete
}
[896] Fix | Delete
if (!$this->options['access_token'] && !$this->options['refresh_token']) {
[897] Fix | Delete
return $this->setError('Required option "access_token" or "refresh_token" is undefined.');
[898] Fix | Delete
}
[899] Fix | Delete
} else {
[900] Fix | Delete
if (!is_readable($this->options['serviceAccountConfigFile'])) {
[901] Fix | Delete
return $this->setError('Option "serviceAccountConfigFile" file is not readable.');
[902] Fix | Delete
}
[903] Fix | Delete
$serviceAccountConfig = $this->options['serviceAccountConfigFile'];
[904] Fix | Delete
}
[905] Fix | Delete
[906] Fix | Delete
try {
[907] Fix | Delete
if (!$serviceAccountConfig) {
[908] Fix | Delete
$aTokenFile = '';
[909] Fix | Delete
if ($this->options['refresh_token']) {
[910] Fix | Delete
// permanent mount
[911] Fix | Delete
$aToken = $this->options['refresh_token'];
[912] Fix | Delete
$this->options['access_token'] = '';
[913] Fix | Delete
$tmp = elFinder::getStaticVar('commonTempPath');
[914] Fix | Delete
if (!$tmp) {
[915] Fix | Delete
$tmp = $this->getTempPath();
[916] Fix | Delete
}
[917] Fix | Delete
if ($tmp) {
[918] Fix | Delete
$aTokenFile = $tmp . DIRECTORY_SEPARATOR . md5($this->options['client_id'] . $this->options['refresh_token']) . '.gtoken';
[919] Fix | Delete
if (is_file($aTokenFile)) {
[920] Fix | Delete
$this->options['access_token'] = json_decode(file_get_contents($aTokenFile), true);
[921] Fix | Delete
}
[922] Fix | Delete
}
[923] Fix | Delete
} else {
[924] Fix | Delete
// make net mount key for network mount
[925] Fix | Delete
if (is_array($this->options['access_token'])) {
[926] Fix | Delete
$aToken = !empty($this->options['access_token']['refresh_token'])
[927] Fix | Delete
? $this->options['access_token']['refresh_token']
[928] Fix | Delete
: $this->options['access_token']['access_token'];
[929] Fix | Delete
} else {
[930] Fix | Delete
return $this->setError('Required option "access_token" is not Array or empty.');
[931] Fix | Delete
}
[932] Fix | Delete
}
[933] Fix | Delete
}
[934] Fix | Delete
[935] Fix | Delete
$errors = [];
[936] Fix | Delete
if ($this->needOnline && !$this->service) {
[937] Fix | Delete
if (($this->options['googleApiClient'] || defined('ELFINDER_GOOGLEDRIVE_GOOGLEAPICLIENT')) && !class_exists('Google_Client')) {
[938] Fix | Delete
include_once $this->options['googleApiClient'] ? $this->options['googleApiClient'] : ELFINDER_GOOGLEDRIVE_GOOGLEAPICLIENT;
[939] Fix | Delete
}
[940] Fix | Delete
if (!class_exists('Google_Client')) {
[941] Fix | Delete
return $this->setError('Class Google_Client not found.');
[942] Fix | Delete
}
[943] Fix | Delete
[944] Fix | Delete
$this->client = new \Google_Client();
[945] Fix | Delete
[946] Fix | Delete
$client = $this->client;
[947] Fix | Delete
[948] Fix | Delete
if (!$serviceAccountConfig) {
[949] Fix | Delete
if ($this->options['access_token']) {
[950] Fix | Delete
$client->setAccessToken($this->options['access_token']);
[951] Fix | Delete
$access_token = $this->options['access_token'];
[952] Fix | Delete
}
[953] Fix | Delete
if ($client->isAccessTokenExpired()) {
[954] Fix | Delete
$client->setClientId($this->options['client_id']);
[955] Fix | Delete
$client->setClientSecret($this->options['client_secret']);
[956] Fix | Delete
$access_token = $client->fetchAccessTokenWithRefreshToken($this->options['refresh_token'] ?: null);
[957] Fix | Delete
$client->setAccessToken($access_token);
[958] Fix | Delete
if ($aTokenFile) {
[959] Fix | Delete
file_put_contents($aTokenFile, json_encode($access_token));
[960] Fix | Delete
} else {
[961] Fix | Delete
$access_token['refresh_token'] = $this->options['access_token']['refresh_token'];
[962] Fix | Delete
}
[963] Fix | Delete
if (!empty($this->options['netkey'])) {
[964] Fix | Delete
elFinder::$instance->updateNetVolumeOption($this->options['netkey'], 'access_token', $access_token);
[965] Fix | Delete
}
[966] Fix | Delete
$this->options['access_token'] = $access_token;
[967] Fix | Delete
}
[968] Fix | Delete
$this->expires = empty($access_token['refresh_token']) ? $access_token['created'] + $access_token['expires_in'] - 30 : 0;
[969] Fix | Delete
} else {
[970] Fix | Delete
$client->setAuthConfigFile($serviceAccountConfig);
[971] Fix | Delete
$client->setScopes([Google_Service_Drive::DRIVE]);
[972] Fix | Delete
$aToken = $client->getClientId();
[973] Fix | Delete
}
[974] Fix | Delete
$this->service = new \Google_Service_Drive($client);
[975] Fix | Delete
}
[976] Fix | Delete
[977] Fix | Delete
if ($this->needOnline) {
[978] Fix | Delete
$this->netMountKey = md5($aToken . '-' . $this->options['path']);
[979] Fix | Delete
}
[980] Fix | Delete
} catch (InvalidArgumentException $e) {
[981] Fix | Delete
$errors[] = $e->getMessage();
[982] Fix | Delete
} catch (Google_Service_Exception $e) {
[983] Fix | Delete
$errors[] = $e->getMessage();
[984] Fix | Delete
}
[985] Fix | Delete
[986] Fix | Delete
if ($this->needOnline && !$this->service) {
[987] Fix | Delete
$this->session->remove($this->id . $this->netMountKey);
[988] Fix | Delete
if ($aTokenFile) {
[989] Fix | Delete
if (is_file($aTokenFile)) {
[990] Fix | Delete
unlink($aTokenFile);
[991] Fix | Delete
}
[992] Fix | Delete
}
[993] Fix | Delete
$errors[] = 'Google Drive Service could not be loaded.';
[994] Fix | Delete
[995] Fix | Delete
return $this->setError($errors);
[996] Fix | Delete
}
[997] Fix | Delete
[998] Fix | Delete
// normalize root path
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function