diff --git a/common.php b/common.php index 7f3bb59..83658f3 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; } @@ -1395,6 +1393,7 @@ function get_refresh_token()
@@ -1612,14 +1611,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 .= '
- - + + diff --git a/conststr.php b/conststr.php index c4f5df8..f5312b9 100644 --- a/conststr.php +++ b/conststr.php @@ -633,6 +633,10 @@ $constStr = [ 'ko-kr' => '중국 Onedrive', 'fa' => 'Onedrive در چین', ], + 'UseShareLink' => [ + 'en-us' => 'Share a folder in Onedrive (enable EDIT for everyone), input the link url below.', + 'zh-cn' => '对一个Onedrive文件夹共享,允许所有人编辑,然后将共享链接填在下方', + ], 'CustomIdSecret' => [ 'en-us' => 'Use custom client id & secret', 'zh-cn' => '自己申请应用ID与机密', @@ -726,4 +730,12 @@ $constStr = [ 'ko-kr' => '캐시 플러시', 'fa' => 'رفرش cache', ], + 'VPSnotupdate' => [ + 'en-us' => 'In VPS can not update by a click! run update.sh', + 'zh-cn' => '在VPS中不能一键更新,可以运行update.sh', + ], + 'QueryBranchs' => [ + 'en-us' => 'Query Branchs', + 'zh-cn' => '查询分支', + ], ]; diff --git a/platform/heroku.php b/platform/heroku.php index c59425a..26dcf9a 100644 --- a/platform/heroku.php +++ b/platform/heroku.php @@ -2,6 +2,7 @@ function getpath() { + $_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($_SERVER['HTTP_ACCEPT_LANGUAGE'],';')[0],',')[0]); $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR']; $_SERVER['base_path'] = path_format(substr($_SERVER['SCRIPT_NAME'], 0, -10) . '/'); $p = strpos($_SERVER['REQUEST_URI'],'?'); diff --git a/platform/normal.php b/platform/normal.php index 1e4e0d7..d944975 100644 --- a/platform/normal.php +++ b/platform/normal.php @@ -2,6 +2,7 @@ function getpath() { + $_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($_SERVER['HTTP_ACCEPT_LANGUAGE'],';')[0],',')[0]); $_SERVER['base_path'] = path_format(substr($_SERVER['SCRIPT_NAME'], 0, -10) . '/'); $p = strpos($_SERVER['REQUEST_URI'],'?'); if ($p>0) $path = substr($_SERVER['REQUEST_URI'], 0, $p); diff --git a/version b/version index 9bfcb61..e439bf6 100644 --- a/version +++ b/version @@ -1,7 +1,10 @@ +20200402-1830.17 +Oneclick update can select which branch to update. Now use the accept language instead of the language config. +一键更新可以选择哪个分支了。现在开始使用浏览器语言,抛弃language设置。 + 20200326-0001.16 You can add sharepoint site drive as a disk, you must reinstall after update. 可以将sharepoint网站添加成一个盘,由于结构改变,升级后只能重装。 - 20200321-1830.15 本次更新后,'index.html'功能在其它主题会导致bug。 文本类文件将缓存;添加hideFunctionalityFile开关;在添加网盘时会显示已经在用的标签。