diff --git a/common.php b/common.php index 7f3bb59..2967e4b 100644 --- a/common.php +++ b/common.php @@ -45,7 +45,7 @@ $CommonEnv = [ 'disktag', 'function_name', // used in heroku. 'hideFunctionalityFile', - 'language', + //'language', 'passfile', 'sitename', 'theme', @@ -62,7 +62,7 @@ $ShowedCommonEnv = [ //'disktag', //'function_name', // used in heroku. 'hideFunctionalityFile', - 'language', + //'language', 'passfile', 'sitename', 'theme', @@ -113,8 +113,11 @@ function main($path) global $exts; global $constStr; - if (isset($_COOKIE['language'])) $constStr['language'] = $_COOKIE['language']; - if (!$constStr['language']) $constStr['language'] = getConfig('language'); + if (in_array($_SERVER['firstacceptlanguage'], array_keys($constStr['languages']))) $constStr['language'] = $_SERVER['firstacceptlanguage']; + if (isset($_COOKIE['language'])&&$_COOKIE['language']!='') $constStr['language'] = $_COOKIE['language']; + //if (!$constStr['language']) $constStr['language'] = getConfig('language'); + /*echo 'firstacceptlanguage:'.$_SERVER['firstacceptlanguage'].' + '.'lan:'.$constStr['language'];*/ if ($constStr['language']=='') $constStr['language'] = 'en-us'; $_SERVER['language'] = $constStr['language']; $_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path); @@ -274,28 +277,7 @@ function main($path) function get_access_token($refresh_token) { if (getConfig('Drive_ver')=='shareurl') { - -//if (!$files) $files['body'] = $arr['body']; - //$files['returnhead'] = $arr['returnhead']; - //$files['cookie'] = $arr['returnhead']['Set-Cookie']; -//return $files; - - /*$files['get'] = curl_request( - "https://mfedu-my.sharepoint.com/personal/ysun_ac_stu_office_gy/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='%2Fpersonal%2Fysun_ac_stu_office_gy%2FDocuments'&RootFolder=%2Fpersonal%2Fysun_ac_stu_office_gy%2FDocuments%2F&TryNewExperienceSingle=TRUE", - '{"parameters":{"__metadata":{"type":"SP.RenderListDataParameters"},"RenderOptions":136967,"AllowMultipleValueFilterForTaxonomyFields":true,"AddRequiredFields":true}}', - ['Accept' => 'application/json;odata=verbose', 'Content-Type' => 'application/json;odata=verbose', 'origin' => 'https://mfedu-my.sharepoint.com', 'Cookie' => $arr['returnhead']['Set-Cookie']], - 1); - $files['get']['body'] = json_decode($files['get']['body'], true); - $_SERVER['access_token'] = splitlast($files['get']['body']['ListSchema']['.driveAccessToken'],'=')[1]; - $_SERVER['api_url'] = $files['get']['body']['ListSchema']['.driveUrl'].'/root'; - - $files = json_decode( curl_request( $_SERVER['api_url'].'?expand=children(select=name,size,file,folder,parentReference,lastModifiedDateTime,@microsoft.graph.downloadUrl,@content.downloadUrl)', false, ['Authorization' => 'Bearer ' . $_SERVER['access_token'], 'Accept' => 'application/json'] )['body'], true); - $files['children']['a']['file'] = $_SERVER['api_url']; - $files['children']['a']['name'] = $_SERVER['api_url']; -*/ $shareurl = getConfig('shareurl'); - //$url = 'https://mfedu-my.sharepoint.com/:f:/g/personal/ysun_ac_stu_office_gy/EpDIBOaYyExHjfu-PJA46icB40X0FKVwmn_9UDJsRvu3Ug?e=XyRZxP'; - //$url = 'https://2d2-my.sharepoint.com/:f:/g/personal/ysun_host_ac_cn/Ehy8pjSQSoZOtLDs4ZKPiGUBYFt26CjEwG6bw7W5vleNNQ?e=DLZcWF'; $tmp1 = splitlast($shareurl, '/')[0]; $account = splitlast($tmp1, '/')[1]; $tmp1 = splitlast($shareurl, ':')[0]; @@ -311,8 +293,8 @@ function get_access_token($refresh_token) $_SERVER['api_url'] = $ret['ListSchema']['.driveUrl'].'/root'; if (!$_SERVER['access_token']) { error_log($domain . "/personal/" . $account . "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='" . urlencode("/personal/" . $account . "/Documents") . "'&RootFolder=" . urlencode("/personal/" . $account . "/Documents/") . "&TryNewExperienceSingle=TRUE"); - error_log('failed to get access_token. response' . json_encode($ret)); - throw new Exception($response['stat'].', failed to get access_token.'.$response['body']); + error_log('failed to get share access_token. response' . json_encode($ret)); + throw new Exception($response['stat'].', failed to get share access_token.'.$response['body']); } error_log('Get access token:'.json_encode($ret, JSON_PRETTY_PRINT)); savecache('access_token', $_SERVER['access_token']); @@ -362,14 +344,12 @@ function isHideFile($name) function getcache($str) { - //$cache = null; $cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'/Onedrive/'.$_SERVER['disktag']); return $cache->fetch($str); } function savecache($key, $value, $exp = 1800) { - //$cache = null; $cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'/Onedrive/'.$_SERVER['disktag']); $cache->save($key, $value, $exp); } @@ -434,8 +414,6 @@ function get_siteid($access_token) while ($url!=''&&$response['stat']!=200&&$i<4) { $response = curl_request($url, false, ['Authorization' => 'Bearer ' . $access_token]); $i++; - //echo 'https://graph.microsoft.com/v1.0/sites/root:/sites/'.getConfig('sharepointname').$response['stat'].$response['body'].' - //'; } if ($response['stat']!=200) { error_log('failed to get siteid. response' . json_encode($response)); @@ -505,7 +483,9 @@ function equal_replace($str, $add = false) function is_guestup_path($path) { - if (path_format('/'.path_format(urldecode($_SERVER['list_path'].path_format($path))).'/')==path_format('/'.path_format(getConfig('guestup_path')).'/')&&getConfig('guestup_path')!='') return 1; + $a1 = path_format(path_format(urldecode($_SERVER['list_path'].path_format($path))).'/') + $a2 = path_format(path_format(getConfig('guestup_path')).'/') + if (getConfig('guestup_path')!=''&&strtolower($a1)==strtolower($a2)) return 1; return 0; } @@ -957,18 +937,36 @@ function adminoperate($path) return $tmparr; } +function splitfirst($str, $split) +{ + $len = strlen($split); + $pos = strpos($str, $split); + if ($pos===false) { + $tmp[0] = $str; + $tmp[1] = ''; + } elseif ($pos>0) { + $tmp[0] = substr($str, 0, $pos); + $tmp[1] = substr($str, $pos+$len); + } else { + $tmp[0] = ''; + $tmp[1] = substr($str, $len); + } + return $tmp; +} + function splitlast($str, $split) { + $len = strlen($split); $pos = strrpos($str, $split); if ($pos===false) { $tmp[0] = $str; $tmp[1] = ''; } elseif ($pos>0) { $tmp[0] = substr($str, 0, $pos); - $tmp[1] = substr($str, $pos+1); + $tmp[1] = substr($str, $pos+$len); } else { $tmp[0] = ''; - $tmp[1] = substr($str, 1); + $tmp[1] = substr($str, $len); } return $tmp; } @@ -1612,14 +1610,14 @@ function EnvOpt($needUpdate = 0) '.getconstStr('AddDisk').'

'; if (!((isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud')||(isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app'))) { $html .= ' -In VPS can not update by a click!
'; +'.getconstStr('VPSnotupdate').'
'; } else { $html .= '
- - + +