OneManager-php/index.php

1759 lines
89 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
include 'vendor/autoload.php';
include 'conststr.php';
include 'functions.php';
//echo '<pre>'. json_encode($_SERVER, JSON_PRETTY_PRINT).'</pre>';
//echo '<pre>'. json_encode($_GET, JSON_PRETTY_PRINT).'</pre>';
if (!isset($_SERVER['REDIRECT_URL'])) $_SERVER['REDIRECT_URL'] = '/index.php';
$path = spurlencode($_SERVER['REDIRECT_URL'], '/');
//echo 'path:'. $path;
$_GET = getGET();
//echo '<pre>'. json_encode($_GET, JSON_PRETTY_PRINT).'</pre>';
$re = main($path);
$sendHeaders = array();
foreach ($re['headers'] as $headerName => $headerVal) {
header($headerName . ': ' . $headerVal, true);
}
http_response_code($re['statusCode']);
echo $re['body'];
function main($path)
{
global $exts;
global $constStr;
config_oauth();
$_SERVER['list_path'] = getListpath($_SERVER['HTTP_HOST']);
if ($_SERVER['list_path']=='') $_SERVER['list_path'] = '/';
$_SERVER['is_guestup_path'] = is_guestup_path($path);
$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
$_SERVER['ajax']=0;
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) if ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest') $_SERVER['ajax']=1;
$refresh_token = getConfig('refresh_token');
if (!$refresh_token) return get_refresh_token();
if (getConfig('adminloginpage')=='') {
$adminloginpage = 'admin';
} else {
$adminloginpage = getConfig('adminloginpage');
}
if ($_GET[$adminloginpage]) {
if ($_GET['preview']) {
$url = $_SERVER['PHP_SELF'] . '?preview';
} else {
$url = path_format($_SERVER['PHP_SELF'] . '/');
}
if (getConfig('admin')!='') {
if ($_POST['password1']==getConfig('admin')) {
return adminform($_SERVER['function_name'].'admin',md5($_POST['password1']),$url);
} else return adminform();
} else {
return output('', 302, [ 'Location' => $url ]);
}
}
if (getConfig('admin')!='')
if ($_COOKIE['admin']==md5(getConfig('admin')) || $_POST['password1']==getConfig('admin') ) {
$_SERVER['admin']=1;
$_SERVER['needUpdate'] = needUpdate();
} else {
$_SERVER['admin']=0;
}
if ($_GET['setup'])
if ($_SERVER['admin']) {
// setup Environments. 设置,对环境变量操作
return EnvOpt($_SERVER['function_name'], $_SERVER['needUpdate']);
} else {
$url = path_format($_SERVER['PHP_SELF'] . '/');
return output('<script>alert(\''.$constStr['SetSecretsFirst'][$constStr['language']].'\');</script>', 302, [ 'Location' => $url ]);
}
$_SERVER['retry'] = 0;
$cache = null;
$cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), '.Onedrive');
if (!($_SERVER['access_token'] = $cache->fetch('access_token'))) {
$ret = json_decode(curl_request(
$_SERVER['oauth_url'] . 'token',
'client_id='. $_SERVER['client_id'] .'&client_secret='. $_SERVER['client_secret'] .'&grant_type=refresh_token&requested_token_use=on_behalf_of&refresh_token=' . $refresh_token
)['body'], true);
if (!isset($ret['access_token'])) {
error_log('failed to get access_token. response' . json_encode($ret));
throw new Exception('failed to get access_token.');
}
$_SERVER['access_token'] = $ret['access_token'];
$cache->save('access_token', $_SERVER['access_token'], $ret['expires_in'] - 60);
}
if ($_SERVER['ajax']) {
if ($_GET['action']=='del_upload_cache'&&substr($_GET['filename'],-4)=='.tmp') {
// del '.tmp' without login. 无需登录即可删除.tmp后缀文件
$tmp = MSAPI('DELETE',path_format(path_format($_SERVER['list_path'] . path_format($path)) . '/' . spurlencode($_GET['filename']) ),'',$_SERVER['access_token']);
return output($tmp['body'],$tmp['stat']);
}
if ($_GET['action']=='uploaded_rename') {
// rename .scfupload file without login.
// 无需登录即可重命名.scfupload后缀文件filemd5为用户提交可被构造问题不大以后处理
$oldname = spurlencode($_GET['filename']);
$pos = strrpos($oldname, '.');
if ($pos>0) $ext = strtolower(substr($oldname, $pos));
$oldname = path_format(path_format($_SERVER['list_path'] . path_format($path)) . '/' . $oldname . '.scfupload' );
$data = '{"name":"' . $_GET['filemd5'] . $ext . '"}';
//echo $oldname .'<br>'. $data;
$tmp = MSAPI('PATCH',$oldname,$data,$_SERVER['access_token']);
if ($tmp['stat']==409) MSAPI('DELETE',$oldname,'',$_SERVER['access_token'])['body'];
return output($tmp['body'],$tmp['stat']);
}
if ($_GET['action']=='upbigfile') return bigfileupload($path);
}
if ($_SERVER['admin']) {
$tmp = adminoperate($path);
if ($tmp['statusCode'] > 0) {
$path1 = path_format($_SERVER['list_path'] . path_format($path));
$cache->save('path_' . $path1, json_decode('{}',true), 1);
return $tmp;
}
} else {
if ($_SERVER['ajax']) return output($constStr['RefleshtoLogin'][$constStr['language']],401);
}
$_SERVER['ishidden'] = passhidden($path);
if ($_GET['thumbnails']) {
if ($_SERVER['ishidden']<4) {
if (in_array(strtolower(substr($path, strrpos($path, '.') + 1)), $exts['img'])) {
return get_thumbnails_url($path);
} else return output(json_encode($exts['img']),400);
} else return output('',401);
}
$files = list_files($path);
if (isset($files['file']) && !$_GET['preview']) {
// is file && not preview mode
if ($_SERVER['ishidden']<4) return output('', 302, [ 'Location' => $files['@microsoft.graph.downloadUrl'] ]);
}
if ( isset($files['folder']) || isset($files['file']) ) {
return render_list($path, $files);
} else {
return output('<div style="margin:8px;">' . $files['error']['message'] . '</div>', 404);
}
}
function list_files($path)
{
$path = path_format($path);
if ($_SERVER['is_guestup_path']&&!$_SERVER['admin']) {
$files = json_decode('{"folder":{}}', true);
} elseif ($_SERVER['ishidden']==4) {
$files = json_decode('{"folder":{}}', true);
} else {
$files = fetch_files($path);
}
if ( isset($files['folder']) || isset($files['file']) || isset($files['error']) ) {
return $files;
} else {
echo 'Error $files' . json_encode($files, JSON_PRETTY_PRINT);
$_SERVER['retry']++;
if ($_SERVER['retry'] < 3) {
return list_files($path);
} else return '';
}
}
function adminform($name = '', $pass = '', $path = '')
{
global $constStr;
$statusCode = 401;
$html = '<html><head><title>'.$constStr['AdminLogin'][$constStr['language']].'</title><meta charset=utf-8></head>';
if ($name!=''&&$pass!='') {
$html .= '<body>'.$constStr['LoginSuccess'][$constStr['language']].'</body></html>';
$statusCode = 302;
date_default_timezone_set('UTC');
$header = [
'Set-Cookie' => $name.'='.$pass.'; path=/; expires='.date(DATE_COOKIE,strtotime('+1hour')),
'Location' => $path,
'Content-Type' => 'text/html'
];
return output($html,$statusCode,$header);
}
$html .= '
<body>
<div>
<center><h4>'.$constStr['InputPassword'][$constStr['language']].'</h4>
<form action="" method="post">
<div>
<input name="password1" type="password"/>
<input type="submit" value="'.$constStr['Login'][$constStr['language']].'">
</div>
</form>
</center>
</div>
';
$html .= '</body></html>';
return output($html,$statusCode);
}
function EnvOpt($function_name, $needUpdate = 0)
{
global $constStr;
$constEnv = [
//'admin',
'adminloginpage', 'domain_path', 'imgup_path', 'passfile', 'private_path', 'public_path', 'sitename', 'language'
];
asort($constEnv);
$html = '<title>Heroku '.$constStr['Setup'][$constStr['language']].'</title>';
/*if ($_POST['updateProgram']==$constStr['updateProgram'][$constStr['language']]) {
$response = json_decode(updataProgram($function_name, $Region, $namespace), true)['Response'];
if (isset($response['Error'])) {
$html = $response['Error']['Code'] . '<br>
' . $response['Error']['Message'] . '<br><br>
function_name:' . $_SERVER['function_name'] . '<br>
Region:' . $_SERVER['Region'] . '<br>
namespace:' . $namespace . '<br>
<button onclick="location.href = location.href;">'.$constStr['Reflesh'][$constStr['language']].'</button>';
$title = 'Error';
} else {
$html .= $constStr['UpdateSuccess'][$constStr['language']] . '<br>
<button onclick="location.href = location.href;">'.$constStr['Reflesh'][$constStr['language']].'</button>';
$title = $constStr['Setup'][$constStr['language']];
}
return message($html, $title);
}*/
if ($_POST['submit1']) {
foreach ($_POST as $k => $v) {
if (in_array($k, $constEnv)) {
//if (!(getConfig($k)==''&&$v==''))
$tmp[$k] = $v;
}
}
$response = setConfig($tmp);
if (isset($response['id'])&&isset($response['message'])) {
$html = $response['id'] . '<br>
' . $response['message'] . '<br><br>
function_name:' . $_SERVER['function_name'] . '<br>
<button onclick="location.href = location.href;">'.$constStr['Reflesh'][$constStr['language']].'</button>';
$title = 'Error';
} else {
$html .= '<script>location.href=location.href</script>';
}
}
if ($_GET['preview']) {
$preurl = $_SERVER['PHP_SELF'] . '?preview';
} else {
$preurl = path_format($_SERVER['PHP_SELF'] . '/');
}
$html .= '
<a href="'.$preurl.'">'.$constStr['Back'][$constStr['language']].'</a>&nbsp;&nbsp;&nbsp;
<a href="https://github.com/qkqpttgf/herokuOnedrive">Github</a><br>';
/*if ($needUpdate) {
$html .= '<pre>' . $_SERVER['github_version'] . '</pre>
<form action="" method="post">
<input type="submit" name="updateProgram" value="'.$constStr['updateProgram'][$constStr['language']].'">
</form>';
} else {
$html .= $constStr['NotNeedUpdate'][$constStr['language']];
}*/
$html .= '
<form action="" method="post">
<table border=1 width=100%>';
foreach ($constEnv as $key) {
if ($key=='language') {
$html .= '
<tr>
<td><label>' . $key . '</label></td>
<td width=100%>
<select name="' . $key .'">';
foreach ($constStr['languages'] as $key1 => $value1) {
$html .= '
<option value="'.$key1.'" '.($key1==getConfig($key)?'selected="selected"':'').'>'.$value1.'</option>';
}
$html .= '
</select>
</td>
</tr>';
} else $html .= '
<tr>
<td><label>' . $key . '</label></td>
<td width=100%><input type="text" name="' . $key .'" value="' . getConfig($key) . '" placeholder="' . $constStr['EnvironmentsDescription'][$key][$constStr['language']] . '" style="width:100%"></td>
</tr>';
}
$html .= '</table>
<input type="submit" name="submit1" value="'.$constStr['Setup'][$constStr['language']].'">
</form>';
return message($html, $constStr['Setup'][$constStr['language']]);
}
function bigfileupload($path)
{
$path1 = path_format($_SERVER['list_path'] . path_format($path));
if (substr($path1,-1)=='/') $path1=substr($path1,0,-1);
if ($_GET['upbigfilename']!=''&&$_GET['filesize']>0) {
$fileinfo['name'] = $_GET['upbigfilename'];
$fileinfo['size'] = $_GET['filesize'];
$fileinfo['lastModified'] = $_GET['lastModified'];
$filename = spurlencode( $fileinfo['name'] );
$cachefilename = '.' . $fileinfo['lastModified'] . '_' . $fileinfo['size'] . '_' . $filename . '.tmp';
$getoldupinfo=fetch_files(path_format($path . '/' . $cachefilename));
//echo json_encode($getoldupinfo, JSON_PRETTY_PRINT);
if (isset($getoldupinfo['file'])&&$getoldupinfo['size']<5120) {
$getoldupinfo_j = curl_request($getoldupinfo['@microsoft.graph.downloadUrl']);
$getoldupinfo = json_decode($getoldupinfo_j , true);
if ( json_decode( curl_request($getoldupinfo['uploadUrl']), true)['@odata.context']!='' ) return output($getoldupinfo_j);
}
if (!$_SERVER['admin']) $filename = spurlencode( $fileinfo['name'] ) . '.scfupload';
$response=MSAPI('createUploadSession',path_format($path1 . '/' . $filename),'{"item": { "@microsoft.graph.conflictBehavior": "fail" }}',$_SERVER['access_token']);
$responsearry = json_decode($response['body'],true);
if (isset($responsearry['error'])) return output($response['body'], $response['stat']);
$fileinfo['uploadUrl'] = $responsearry['uploadUrl'];
MSAPI('PUT', path_format($path1 . '/' . $cachefilename), json_encode($fileinfo, JSON_PRETTY_PRINT), $_SERVER['access_token'])['body'];
return output($response['body'], $response['stat']);
}
return output('error', 400);
}
function adminoperate($path)
{
global $constStr;
$path1 = path_format($_SERVER['list_path'] . path_format($path));
if (substr($path1,-1)=='/') $path1=substr($path1,0,-1);
$tmparr['statusCode'] = 0;
if ($_GET['rename_newname']!=$_GET['rename_oldname'] && $_GET['rename_newname']!='') {
// rename 重命名
$oldname = spurlencode($_GET['rename_oldname']);
$oldname = path_format($path1 . '/' . $oldname);
$data = '{"name":"' . $_GET['rename_newname'] . '"}';
//echo $oldname;
$result = MSAPI('PATCH',$oldname,$data,$_SERVER['access_token']);
return output($result['body'], $result['stat']);
}
if ($_GET['delete_name']!='') {
// delete 删除
$filename = spurlencode($_GET['delete_name']);
$filename = path_format($path1 . '/' . $filename);
//echo $filename;
$result = MSAPI('DELETE', $filename, '', $_SERVER['access_token']);
return output($result['body'], $result['stat']);
}
if ($_GET['operate_action']==$constStr['encrypt'][$constStr['language']]) {
// encrypt 加密
if (getConfig('passfile')=='') return message($constStr['SetpassfileBfEncrypt'][$constStr['language']],'',403);
if ($_GET['encrypt_folder']=='/') $_GET['encrypt_folder']=='';
$foldername = spurlencode($_GET['encrypt_folder']);
$filename = path_format($path1 . '/' . $foldername . '/' . getConfig('passfile'));
//echo $foldername;
$result = MSAPI('PUT', $filename, $_GET['encrypt_newpass'], $_SERVER['access_token']);
return output($result['body'], $result['stat']);
}
if ($_GET['move_folder']!='') {
// move 移动
$moveable = 1;
if ($path == '/' && $_GET['move_folder'] == '/../') $moveable=0;
if ($_GET['move_folder'] == $_GET['move_name']) $moveable=0;
if ($moveable) {
$filename = spurlencode($_GET['move_name']);
$filename = path_format($path1 . '/' . $filename);
$foldername = path_format('/'.urldecode($path1).'/'.$_GET['move_folder']);
$data = '{"parentReference":{"path": "/drive/root:'.$foldername.'"}}';
$result = MSAPI('PATCH', $filename, $data, $_SERVER['access_token']);
return output($result['body'], $result['stat']);
} else {
return output('{"error":"Can not Move!"}', 403);
}
}
if ($_POST['editfile']!='') {
// edit 编辑
$data = $_POST['editfile'];
/*TXT一般不会超过4M不用二段上传
$filename = $path1 . ':/createUploadSession';
$response=MSAPI('POST',$filename,'{"item": { "@microsoft.graph.conflictBehavior": "replace" }}',$_SERVER['access_token']);
$uploadurl=json_decode($response,true)['uploadUrl'];
echo MSAPI('PUT',$uploadurl,$data,$_SERVER['access_token']);*/
$result = MSAPI('PUT', $path1, $data, $_SERVER['access_token'])['body'];
//echo $result;
$resultarry = json_decode($result,true);
if (isset($resultarry['error'])) return message($resultarry['error']['message']. '<hr><a href="javascript:history.back(-1)">上一页</a>','Error',403);
}
if ($_GET['create_name']!='') {
// create 新建
if ($_GET['create_type']=='file') {
$filename = spurlencode($_GET['create_name']);
$filename = path_format($path1 . '/' . $filename);
$result = MSAPI('PUT', $filename, $_GET['create_text'], $_SERVER['access_token']);
}
if ($_GET['create_type']=='folder') {
$data = '{ "name": "' . $_GET['create_name'] . '", "folder": { }, "@microsoft.graph.conflictBehavior": "rename" }';
$result = MSAPI('children', $path1, $data, $_SERVER['access_token']);
}
return output($result['body'], $result['stat']);
}
return $tmparr;
}
function MSAPI($method, $path, $data = '', $access_token)
{
if (substr($path,0,7) == 'http://' or substr($path,0,8) == 'https://') {
$url=$path;
$lenth=strlen($data);
$headers['Content-Length'] = $lenth;
$lenth--;
$headers['Content-Range'] = 'bytes 0-' . $lenth . '/' . $headers['Content-Length'];
} else {
$url = $_SERVER['api_url'];
if ($path=='' or $path=='/') {
$url .= '/';
} else {
$url .= ':' . $path;
if (substr($url,-1)=='/') $url=substr($url,0,-1);
}
if ($method=='PUT') {
if ($path=='' or $path=='/') {
$url .= 'content';
} else {
$url .= ':/content';
}
$headers['Content-Type'] = 'text/plain';
} elseif ($method=='PATCH') {
$headers['Content-Type'] = 'application/json';
} elseif ($method=='POST') {
$headers['Content-Type'] = 'application/json';
} elseif ($method=='DELETE') {
$headers['Content-Type'] = 'application/json';
} else {
if ($path=='' or $path=='/') {
$url .= $method;
} else {
$url .= ':/' . $method;
}
$method='POST';
$headers['Content-Type'] = 'application/json';
}
}
$headers['Authorization'] = 'Bearer ' . $access_token;
if (!isset($headers['Accept'])) $headers['Accept'] = '*/*';
if (!isset($headers['Referer'])) $headers['Referer'] = $url;
$sendHeaders = array();
foreach ($headers as $headerName => $headerVal) {
$sendHeaders[] = $headerName . ': ' . $headerVal;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,$method);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $sendHeaders);
$response['body'] = curl_exec($ch);
$response['stat'] = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
error_log($response['stat'].'
'.$response['body'].'
');
return $response;
}
function fetch_files($path = '/')
{
$path1 = path_format($path);
$path = path_format($_SERVER['list_path'] . path_format($path));
$cache = null;
$cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), '.qdrive');
if (!($files = $cache->fetch('path_' . $path))) {
// https://docs.microsoft.com/en-us/graph/api/driveitem-get?view=graph-rest-1.0
// https://docs.microsoft.com/zh-cn/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http
// https://developer.microsoft.com/zh-cn/graph/graph-explorer
$url = $_SERVER['api_url'];
if ($path !== '/') {
$url .= ':' . $path;
if (substr($url,-1)=='/') $url=substr($url,0,-1);
}
$url .= '?expand=children(select=name,size,file,folder,parentReference,lastModifiedDateTime)';
$files = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']])['body'], true);
// echo $path . '<br><pre>' . json_encode($files, JSON_PRETTY_PRINT) . '</pre>';
if (isset($files['folder'])) {
if ($files['folder']['childCount']>200) {
// files num > 200 , then get nextlink
$page = $_POST['pagenum']==''?1:$_POST['pagenum'];
$files=fetch_files_children($files, $path, $page, $cache);
} else {
// files num < 200 , then cache
$cache->save('path_' . $path, $files, 60);
}
}
}
return $files;
}
function fetch_files_children($files, $path, $page, $cache)
{
$cachefilename = '.SCFcache_'.$_SERVER['function_name'];
$maxpage = ceil($files['folder']['childCount']/200);
if (!($files['children'] = $cache->fetch('files_' . $path . '_page_' . $page))) {
// down cache file get jump info. 下载cache文件获取跳页链接
$cachefile = fetch_files(path_format($path1 . '/' .$cachefilename));
if ($cachefile['size']>0) {
$pageinfo = curl_request($cachefile['@microsoft.graph.downloadUrl'])['body'];
$pageinfo = json_decode($pageinfo,true);
for ($page4=1;$page4<$maxpage;$page4++) {
$cache->save('nextlink_' . $path . '_page_' . $page4, $pageinfo['nextlink_' . $path . '_page_' . $page4], 60);
$pageinfocache['nextlink_' . $path . '_page_' . $page4] = $pageinfo['nextlink_' . $path . '_page_' . $page4];
}
}
$pageinfochange=0;
for ($page1=$page;$page1>=1;$page1--) {
$page3=$page1-1;
$url = $cache->fetch('nextlink_' . $path . '_page_' . $page3);
if ($url == '') {
if ($page1==1) {
$url = $_SERVER['api_url'];
if ($path !== '/') {
$url .= ':' . $path;
if (substr($url,-1)=='/') $url=substr($url,0,-1);
$url .= ':/children?$select=name,size,file,folder,parentReference,lastModifiedDateTime';
} else {
$url .= '/children?$select=name,size,file,folder,parentReference,lastModifiedDateTime';
}
$children = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']])['body'], true);
// echo $url . '<br><pre>' . json_encode($children, JSON_PRETTY_PRINT) . '</pre>';
$cache->save('files_' . $path . '_page_' . $page1, $children['value'], 60);
$nextlink=$cache->fetch('nextlink_' . $path . '_page_' . $page1);
if ($nextlink!=$children['@odata.nextLink']) {
$cache->save('nextlink_' . $path . '_page_' . $page1, $children['@odata.nextLink'], 60);
$pageinfocache['nextlink_' . $path . '_page_' . $page1] = $children['@odata.nextLink'];
$pageinfocache = clearbehindvalue($path,$page1,$maxpage,$pageinfocache);
$pageinfochange = 1;
}
$url = $children['@odata.nextLink'];
for ($page2=$page1+1;$page2<=$page;$page2++) {
sleep(1);
$children = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']])['body'], true);
$cache->save('files_' . $path . '_page_' . $page2, $children['value'], 60);
$nextlink=$cache->fetch('nextlink_' . $path . '_page_' . $page2);
if ($nextlink!=$children['@odata.nextLink']) {
$cache->save('nextlink_' . $path . '_page_' . $page2, $children['@odata.nextLink'], 60);
$pageinfocache['nextlink_' . $path . '_page_' . $page2] = $children['@odata.nextLink'];
$pageinfocache = clearbehindvalue($path,$page2,$maxpage,$pageinfocache);
$pageinfochange = 1;
}
$url = $children['@odata.nextLink'];
}
//echo $url . '<br><pre>' . json_encode($children, JSON_PRETTY_PRINT) . '</pre>';
$files['children'] = $children['value'];
$files['folder']['page']=$page;
$pageinfocache['filenum'] = $files['folder']['childCount'];
$pageinfocache['dirsize'] = $files['size'];
$pageinfocache['cachesize'] = $cachefile['size'];
$pageinfocache['size'] = $files['size']-$cachefile['size'];
if ($pageinfochange == 1) MSAPI('PUT', path_format($path.'/'.$cachefilename), json_encode($pageinfocache, JSON_PRETTY_PRINT), $_SERVER['access_token'])['body'];
return $files;
}
} else {
for ($page2=$page3+1;$page2<=$page;$page2++) {
sleep(1);
$children = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']])['body'], true);
$cache->save('files_' . $path . '_page_' . $page2, $children['value'], 60);
$nextlink=$cache->fetch('nextlink_' . $path . '_page_' . $page2);
if ($nextlink!=$children['@odata.nextLink']) {
$cache->save('nextlink_' . $path . '_page_' . $page2, $children['@odata.nextLink'], 60);
$pageinfocache['nextlink_' . $path . '_page_' . $page2] = $children['@odata.nextLink'];
$pageinfocache = clearbehindvalue($path,$page2,$maxpage,$pageinfocache);
$pageinfochange = 1;
}
$url = $children['@odata.nextLink'];
}
//echo $url . '<br><pre>' . json_encode($children, JSON_PRETTY_PRINT) . '</pre>';
$files['children'] = $children['value'];
$files['folder']['page']=$page;
$pageinfocache['filenum'] = $files['folder']['childCount'];
$pageinfocache['dirsize'] = $files['size'];
$pageinfocache['cachesize'] = $cachefile['size'];
$pageinfocache['size'] = $files['size']-$cachefile['size'];
if ($pageinfochange == 1) MSAPI('PUT', path_format($path.'/'.$cachefilename), json_encode($pageinfocache, JSON_PRETTY_PRINT), $_SERVER['access_token'])['body'];
return $files;
}
}
} else {
$files['folder']['page']=$page;
for ($page4=1;$page4<=$maxpage;$page4++) {
if (!($url = $cache->fetch('nextlink_' . $path . '_page_' . $page4))) {
if ($files['folder'][$path.'_'.$page4]!='') $cache->save('nextlink_' . $path . '_page_' . $page4, $files['folder'][$path.'_'.$page4], 60);
} else {
$files['folder'][$path.'_'.$page4] = $url;
}
}
}
return $files;
}
function render_list($path, $files)
{
global $exts;
global $constStr;
@ob_start();
$path = str_replace('%20','%2520',$path);
$path = str_replace('+','%2B',$path);
$path = str_replace('&','&amp;',path_format(urldecode($path))) ;
$path = str_replace('%20',' ',$path);
$path = str_replace('#','%23',$path);
$p_path='';
if ($path !== '/') {
if (isset($files['file'])) {
$pretitle = str_replace('&','&amp;', $files['name']);
$n_path=$pretitle;
} else {
$pretitle = substr($path,-1)=='/'?substr($path,0,-1):$path;
$n_path=substr($pretitle,strrpos($pretitle,'/')+1);
$pretitle = substr($pretitle,1);
}
if (strrpos($path,'/')!=0) {
$p_path=substr($path,0,strrpos($path,'/'));
$p_path=substr($p_path,strrpos($p_path,'/')+1);
}
} else {
$pretitle = $constStr['Home'][$constStr['language']];
$n_path=$pretitle;
}
$n_path=str_replace('&amp;','&',$n_path);
$p_path=str_replace('&amp;','&',$p_path);
$pretitle = str_replace('%23','#',$pretitle);
$statusCode=200;
date_default_timezone_set(get_timezone($_COOKIE['timezone']));
?>
<!DOCTYPE html>
<html lang="<?php echo $constStr['language']; ?>">
<head>
<title><?php echo $pretitle;?> - <?php echo $_SERVER['sitename'];?></title>
<!--
帖子 https://www.hostloc.com/thread-617698-1-1.html
github https://github.com/qkqpttgf/herokuOnedrive
-->
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width,initial-scale=1">
<meta name="keywords" content="<?php echo $n_path;?>,<?php if ($p_path!='') echo $p_path.','; echo $_SERVER['sitename'];?>,herokuOneDrive,auth_by_逸笙">
<link rel="icon" href="<?php echo $_SERVER['base_path'];?>favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="<?php echo $_SERVER['base_path'];?>favicon.ico" type="image/x-icon" />
<style type="text/css">
body{font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:1em;background-color:#f7f7f9;color:#000}
a{color:#24292e;cursor:pointer;text-decoration:none}
a:hover{color:#24292e}
.changelanguage{position:absolute;right:5px;}
.title{text-align:center;margin-top:1rem;letter-spacing:2px;margin-bottom:2rem}
.title a{color:#333;text-decoration:none}
.list-wrapper{width:80%;margin:0 auto 40px;position:relative;box-shadow:0 0 32px 0 rgb(128,128,128);border-radius:15px;}
.list-container{position:relative;overflow:hidden;border-radius:15px;}
.list-header-container{position:relative}
.list-header-container a.back-link{color:#000;display:inline-block;position:absolute;font-size:16px;margin:20px 10px;padding:10px 10px;vertical-align:middle;text-decoration:none}
.list-container,.list-header-container,.list-wrapper,a.back-link:hover,body{color:#24292e}
.list-header-container .table-header{margin:0;border:0 none;padding:30px 60px;text-align:left;font-weight:400;color:#000;background-color:#f7f7f9}
.list-body-container{position:relative;left:0;overflow-x:hidden;overflow-y:auto;box-sizing:border-box;background:#fff}
.list-table{width:100%;padding:20px;border-spacing:0}
.list-table tr{height:40px}
.list-table tr[data-to]:hover{background:#f1f1f1}
.list-table tr:first-child{background:#fff}
.list-table td,.list-table th{padding:0 10px;text-align:left}
.list-table .size,.list-table .updated_at{text-align:right}
.list-table .file ion-icon{font-size:15px;margin-right:5px;vertical-align:bottom}
.mask{position:absolute;left:0px;top:0px;width:100%;background-color:#000;filter:alpha(opacity=50);opacity:0.5;z-index:2;}
<?php if ($_SERVER['admin']) { ?>
.operate{display:inline-table;margin:0;list-style:none;}
.operate ul{position:absolute;display:none;background:#fffaaa;border:0px #f7f7f7 solid;border-radius:5px;margin:-7px 0 0 0;padding:0 7px;color:#205D67;z-index:1;}
.operate:hover ul{position:absolute;display:inline-table;}
.operate ul li{padding:7px;list-style:none;display:inline-table;}
<?php } ?>
.operatediv{position:absolute;border:1px #CCCCCC;background-color:#FFFFCC;z-index:2;}
.operatediv div{margin:16px}
.operatediv_close{position:absolute;right:3px;top:3px;}
.readme{padding:8px;background-color:#fff;}
#readme{padding:20px;text-align:left}
@media only screen and (max-width:480px){
.title{margin-bottom:24px}
.list-wrapper{width:95%; margin-bottom:24px;}
.list-table {padding:8px}
.list-table td, .list-table th{padding:0 10px;text-align:left;white-space:nowrap;overflow:auto;max-width:80px}
}
</style>
</head>
<body>
<?php
if (getConfig('admin')!='') if (!$_SERVER['admin']) {
if (getConfig('adminloginpage')=='') { ?>
<a onclick="login();"><?php echo $constStr['Login'][$constStr['language']]; ?></a>
<?php }
} else { ?>
<li class="operate"><?php echo $constStr['Operate'][$constStr['language']]; ?><ul>
<?php if (isset($files['folder'])) { ?>
<li><a onclick="showdiv(event,'create','');"><?php echo $constStr['Create'][$constStr['language']]; ?></a></li>
<li><a onclick="showdiv(event,'encrypt','');"><?php echo $constStr['encrypt'][$constStr['language']]; ?></a></li>
<?php } ?>
<li><a href="<?php echo $_GET['preview']?'?preview&':'?';?>setup"><?php echo $constStr['Setup'][$constStr['language']]; ?></a></li>
<li><a onclick="logout()"><?php echo $constStr['Logout'][$constStr['language']]; ?></a></li>
</ul></li>
<?php
} ?>
<select class="changelanguage" name="language" onchange="changelanguage(this.options[this.options.selectedIndex].value)">
<option>Language</option>
<?php
foreach ($constStr['languages'] as $key1 => $value1) { ?>
<option value="<?php echo $key1; ?>"><?php echo $value1; ?></option>
<?php
} ?>
</select>
<?php
if ($_SERVER['needUpdate']) { ?>
<div style='position:absolute;'><font color='red'><?php echo $constStr['NeedUpdate'][$constStr['language']]; ?></font></div>
<?php } ?>
<h1 class="title">
<a href="<?php echo $_SERVER['base_path']; ?>"><?php echo $_SERVER['sitename']; ?></a>
</h1>
<div class="list-wrapper">
<div class="list-container">
<div class="list-header-container">
<?php
if ($path !== '/') {
$current_url = $_SERVER['PHP_SELF'];
while (substr($current_url, -1) === '/') {
$current_url = substr($current_url, 0, -1);
}
if (strpos($current_url, '/') !== FALSE) {
$parent_url = substr($current_url, 0, strrpos($current_url, '/'));
} else {
$parent_url = $current_url;
}
?>
<a href="<?php echo $parent_url.'/'; ?>" class="back-link">
<ion-icon name="arrow-back"></ion-icon>
</a>
<?php } ?>
<h3 class="table-header"><?php echo str_replace('%23', '#', str_replace('&','&amp;', $path)); ?></h3>
</div>
<div class="list-body-container">
<?php
if ($_SERVER['is_imgup_path']&&!$_SERVER['admin']) { ?>
<div id="upload_div" style="margin:10px">
<center>
<input id="upload_file" type="file" name="upload_filename">
<input id="upload_submit" onclick="preup();" value="<?php echo $constStr['Upload'][$constStr['language']]; ?>" type="button">
<center>
</div>
<?php } else {
if ($_SERVER['ishidden']<4) {
if (isset($files['error'])) {
echo '<div style="margin:8px;">' . $files['error']['message'] . '</div>';
$statusCode=404;
} else {
if (isset($files['file'])) {
?>
<div style="margin: 12px 4px 4px; text-align: center">
<div style="margin: 24px">
<textarea id="url" title="url" rows="1" style="width: 100%; margin-top: 2px;" readonly><?php echo str_replace('%2523', '%23', str_replace('%26amp%3B','&amp;',spurlencode(path_format($_SERVER['base_path'] . '/' . $path), '/'))); ?></textarea>
<a href="<?php echo path_format($_SERVER['base_path'] . '/' . $path);//$files['@microsoft.graph.downloadUrl'] ?>"><ion-icon name="download" style="line-height: 16px;vertical-align: middle;"></ion-icon>&nbsp;<?php echo $constStr['Download'][$constStr['language']]; ?></a>
</div>
<div style="margin: 24px">
<?php $ext = strtolower(substr($path, strrpos($path, '.') + 1));
$DPvideo='';
if (in_array($ext, $exts['img'])) {
echo '
<img src="' . $files['@microsoft.graph.downloadUrl'] . '" alt="' . substr($path, strrpos($path, '/')) . '" onload="if(this.offsetWidth>document.getElementById(\'url\').offsetWidth) this.style.width=\'100%\';" />
';
} elseif (in_array($ext, $exts['video'])) {
//echo '<video src="' . $files['@microsoft.graph.downloadUrl'] . '" controls="controls" style="width: 100%"></video>';
$DPvideo=$files['@microsoft.graph.downloadUrl'];
echo '<div id="video-a0"></div>';
} elseif (in_array($ext, $exts['music'])) {
echo '
<audio src="' . $files['@microsoft.graph.downloadUrl'] . '" controls="controls" style="width: 100%"></audio>
';
} elseif (in_array($ext, ['pdf'])) {
echo '
<embed src="' . $files['@microsoft.graph.downloadUrl'] . '" type="application/pdf" width="100%" height=800px">
';
} elseif (in_array($ext, $exts['office'])) {
echo '
<iframe id="office-a" src="https://view.officeapps.live.com/op/view.aspx?src=' . urlencode($files['@microsoft.graph.downloadUrl']) . '" style="width: 100%;height: 800px" frameborder="0"></iframe>
';
} elseif (in_array($ext, $exts['txt'])) {
$txtstr = htmlspecialchars(curl_request($files['@microsoft.graph.downloadUrl'])['body']);
?>
<div id="txt">
<?php if ($_SERVER['admin']) { ?>
<form id="txt-form" action="" method="POST">
<a onclick="enableedit(this);" id="txt-editbutton"><?php echo $constStr['ClicktoEdit'][$constStr['language']]; ?></a>
<a id="txt-save" style="display:none"><?php echo $constStr['Save'][$constStr['language']]; ?></a>
<?php } ?>
<textarea id="txt-a" name="editfile" readonly style="width: 100%; margin-top: 2px;" <?php if ($_SERVER['admin']) echo 'onchange="document.getElementById(\'txt-save\').onclick=function(){document.getElementById(\'txt-form\').submit();}"';?> ><?php echo $txtstr;?></textarea>
<?php if ($_SERVER['admin']) echo '</form>'; ?>
</div>
<?php } elseif (in_array($ext, ['md'])) {
echo '
<div class="markdown-body" id="readme">
<textarea id="readme-md" style="display:none;">' . curl_request($files['@microsoft.graph.downloadUrl'])['body'] . '</textarea>
</div>
';
} else {
echo '<span>'.$constStr['FileNotSupport'][$constStr['language']].'</span>';
} ?>
</div>
</div>
<?php } elseif (isset($files['folder'])) {
$filenum = $_POST['filenum'];
if (!$filenum and $files['folder']['page']) $filenum = ($files['folder']['page']-1)*200;
$readme = false; ?>
<table class="list-table" id="list-table">
<tr id="tr0">
<th class="file" onclick="sortby('a');"><?php echo $constStr['File'][$constStr['language']]; ?>&nbsp;&nbsp;&nbsp;<button onclick="showthumbnails(this);"><?php echo $constStr['ShowThumbnails'][$constStr['language']]; ?></button></th>
<th class="updated_at" width="25%" onclick="sortby('time');"><?php echo $constStr['EditTime'][$constStr['language']]; ?></th>
<th class="size" width="15%" onclick="sortby('size');"><?php echo $constStr['Size'][$constStr['language']]; ?></th>
</tr>
<!-- Dirs -->
<?php //echo json_encode($files['children'], JSON_PRETTY_PRINT);
foreach ($files['children'] as $file) {
// Folders
if (isset($file['folder'])) {
$filenum++; ?>
<tr data-to id="tr<?php echo $filenum;?>">
<td class="file">
<?php if ($_SERVER['admin']) { ?>
<li class="operate"><?php echo $constStr['Operate'][$constStr['language']]; ?>
<ul>
<li><a onclick="showdiv(event,'encrypt',<?php echo $filenum;?>);"><?php echo $constStr['encrypt'][$constStr['language']]; ?></a></li>
<li><a onclick="showdiv(event, 'rename',<?php echo $filenum;?>);"><?php echo $constStr['Rename'][$constStr['language']]; ?></a></li>
<li><a onclick="showdiv(event, 'move',<?php echo $filenum;?>);"><?php echo $constStr['Move'][$constStr['language']]; ?></a></li>
<li><a onclick="showdiv(event, 'delete',<?php echo $filenum;?>);"><?php echo $constStr['Delete'][$constStr['language']]; ?></a></li>
</ul>
</li>&nbsp;&nbsp;&nbsp;
<?php } ?>
<ion-icon name="folder"></ion-icon>
<a id="file_a<?php echo $filenum;?>" href="<?php echo path_format($_SERVER['base_path'] . '/' . $path . '/' . encode_str_replace($file['name']) . '/'); ?>"><?php echo str_replace('&','&amp;', $file['name']);?></a>
</td>
<td class="updated_at" id="folder_time<?php echo $filenum;?>"><?php echo time_format($file['lastModifiedDateTime']); ?></td>
<td class="size" id="folder_size<?php echo $filenum;?>"><?php echo size_format($file['size']); ?></td>
</tr>
<?php }
}
// if ($filenum) echo '<tr data-to></tr>';
foreach ($files['children'] as $file) {
// Files
if (isset($file['file'])) {
if ($_SERVER['admin'] or (substr($file['name'],0,1) !== '.' and $file['name'] !== getConfig('passfile') ) ) {
if (strtolower($file['name']) === 'readme.md') $readme = $file;
if (strtolower($file['name']) === 'index.html') {
$html = curl_request(fetch_files(spurlencode(path_format($path . '/' .$file['name']),'/'))['@microsoft.graph.downloadUrl'])['body'];
return output($html,200);
}
$filenum++; ?>
<tr data-to id="tr<?php echo $filenum;?>">
<td class="file">
<?php if ($_SERVER['admin']) { ?>
<li class="operate"><?php echo $constStr['Operate'][$constStr['language']]; ?>
<ul>
<li><a onclick="showdiv(event, 'rename',<?php echo $filenum;?>);"><?php echo $constStr['Rename'][$constStr['language']]; ?></a></li>
<li><a onclick="showdiv(event, 'move',<?php echo $filenum;?>);"><?php echo $constStr['Move'][$constStr['language']]; ?></a></li>
<li><a onclick="showdiv(event, 'delete',<?php echo $filenum;?>);"><?php echo $constStr['Delete'][$constStr['language']]; ?></a></li>
</ul>
</li>&nbsp;&nbsp;&nbsp;
<?php }
$ext = strtolower(substr($file['name'], strrpos($file['name'], '.') + 1));
if (in_array($ext, $exts['music'])) { ?>
<ion-icon name="musical-notes"></ion-icon>
<?php } elseif (in_array($ext, $exts['video'])) { ?>
<ion-icon name="logo-youtube"></ion-icon>
<?php } elseif (in_array($ext, $exts['img'])) { ?>
<ion-icon name="image"></ion-icon>
<?php } elseif (in_array($ext, $exts['office'])) { ?>
<ion-icon name="paper"></ion-icon>
<?php } elseif (in_array($ext, $exts['txt'])) { ?>
<ion-icon name="clipboard"></ion-icon>
<?php } elseif (in_array($ext, $exts['zip'])) { ?>
<ion-icon name="filing"></ion-icon>
<?php } elseif ($ext=='iso') { ?>
<ion-icon name="disc"></ion-icon>
<?php } elseif ($ext=='apk') { ?>
<ion-icon name="logo-android"></ion-icon>
<?php } elseif ($ext=='exe') { ?>
<ion-icon name="logo-windows"></ion-icon>
<?php } else { ?>
<ion-icon name="document"></ion-icon>
<?php } ?>
<a id="file_a<?php echo $filenum;?>" name="filelist" href="<?php echo path_format($_SERVER['base_path'] . '/' . $path . '/' . encode_str_replace($file['name'])); ?>?preview" target=_blank><?php echo str_replace('&','&amp;', $file['name']); ?></a>
<a href="<?php echo path_format($_SERVER['base_path'] . '/' . $path . '/' . str_replace('&','&amp;', $file['name']));?>"><ion-icon name="download"></ion-icon></a>
</td>
<td class="updated_at" id="file_time<?php echo $filenum;?>"><?php echo time_format($file['lastModifiedDateTime']); ?></td>
<td class="size" id="file_size<?php echo $filenum;?>"><?php echo size_format($file['size']); ?></td>
</tr>
<?php }
}
} ?>
</table>
<?php if ($files['folder']['childCount']>200) {
$pagenum = $files['folder']['page'];
$maxpage = ceil($files['folder']['childCount']/200);
$prepagenext = '
<form action="" method="POST" id="nextpageform">
<input type="hidden" id="pagenum" name="pagenum" value="'. $pagenum .'">
<table width=100% border=0>
<tr>
<td width=60px align=center>';
if ($pagenum!=1) {
$prepagenum = $pagenum-1;
$prepagenext .= '
<a onclick="nextpage('.$prepagenum.');">'.$constStr['PrePage'][$constStr['language']].'</a>';
}
$prepagenext .= '
</td>
<td class="updated_at">';
for ($page=1;$page<=$maxpage;$page++) {
if ($page == $pagenum) {
$prepagenext .= '
<font color=red>' . $page . '</font> ';
} else {
$prepagenext .= '
<a onclick="nextpage('.$page.');">' . $page . '</a> ';
}
}
$prepagenext = substr($prepagenext,0,-1);
$prepagenext .= '
</td>
<td width=60px align=center>';
if ($pagenum!=$maxpage) {
$nextpagenum = $pagenum+1;
$prepagenext .= '
<a onclick="nextpage('.$nextpagenum.');">'.$constStr['NextPage'][$constStr['language']].'</a>';
}
$prepagenext .= '
</td>
</tr>
</table>
</form>';
echo $prepagenext;
}
if ($_SERVER['admin']) { ?>
<div id="upload_div" style="margin:0 0 16px 0">
<center>
<input id="upload_file" type="file" name="upload_filename" multiple="multiple">
<input id="upload_submit" onclick="preup();" value="<?php echo $constStr['Upload'][$constStr['language']]; ?>" type="button">
</center>
</div>
<?php }
} else {
$statusCode=500;
echo 'Unknown path or file.';
echo json_encode($files, JSON_PRETTY_PRINT);
}
if ($readme) {
echo '
</div>
</div>
</div>
<div class="list-wrapper">
<div class="list-container">
<div class="list-header-container">
<div class="readme">
<svg class="octicon octicon-book" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M3 5h4v1H3V5zm0 3h4V7H3v1zm0 2h4V9H3v1zm11-5h-4v1h4V5zm0 2h-4v1h4V7zm0 2h-4v1h4V9zm2-6v9c0 .55-.45 1-1 1H9.5l-1 1-1-1H2c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h5.5l1 1 1-1H15c.55 0 1 .45 1 1zm-8 .5L7.5 3H2v9h6V3.5zm7-.5H9.5l-.5.5V12h6V3z"></path></svg>
<span style="line-height: 16px;vertical-align: top;">'.$readme['name'].'</span>
<div class="markdown-body" id="readme">
<textarea id="readme-md" style="display:none;">' . curl_request(fetch_files(spurlencode(path_format($path . '/' .$readme['name']),'/'))['@microsoft.graph.downloadUrl'])['body'] . '
</textarea>
</div>
</div>
';
}
}
} else {
echo '
<div style="padding:20px">
<center>
<form action="" method="post">
<input name="password1" type="password" placeholder="'.$constStr['InputPassword'][$constStr['language']].'">
<input type="submit" value="'.$constStr['Submit'][$constStr['language']].'">
</form>
</center>
</div>';
$statusCode = 401;
}
} ?>
</div>
</div>
</div>
<div id="mask" class="mask" style="display:none;"></div>
<?php
if ($_SERVER['admin']) {
if (!$_GET['preview']) { ?>
<div>
<div id="rename_div" class="operatediv" style="display:none">
<div>
<label id="rename_label"></label><br><br><a onclick="operatediv_close('rename')" class="operatediv_close"><?php echo $constStr['Close'][$constStr['language']]; ?></a>
<form id="rename_form" onsubmit="return submit_operate('rename');">
<input id="rename_sid" name="rename_sid" type="hidden" value="">
<input id="rename_hidden" name="rename_oldname" type="hidden" value="">
<input id="rename_input" name="rename_newname" type="text" value="">
<input name="operate_action" type="submit" value="<?php echo $constStr['Rename'][$constStr['language']]; ?>">
</form>
</div>
</div>
<div id="delete_div" class="operatediv" style="display:none">
<div>
<br><a onclick="operatediv_close('delete')" class="operatediv_close"><?php echo $constStr['Close'][$constStr['language']]; ?></a>
<label id="delete_label"></label>
<form id="delete_form" onsubmit="return submit_operate('delete');">
<label id="delete_input"><?php echo $constStr['Delete'][$constStr['language']]; ?>?</label>
<input id="delete_sid" name="delete_sid" type="hidden" value="">
<input id="delete_hidden" name="delete_name" type="hidden" value="">
<input name="operate_action" type="submit" value="<?php echo $constStr['Submit'][$constStr['language']]; ?>">
</form>
</div>
</div>
<div id="encrypt_div" class="operatediv" style="display:none">
<div>
<label id="encrypt_label"></label><br><br><a onclick="operatediv_close('encrypt')" class="operatediv_close"><?php echo $constStr['Close'][$constStr['language']]; ?></a>
<form id="encrypt_form" onsubmit="return submit_operate('encrypt');">
<input id="encrypt_sid" name="encrypt_sid" type="hidden" value="">
<input id="encrypt_hidden" name="encrypt_folder" type="hidden" value="">
<input id="encrypt_input" name="encrypt_newpass" type="text" value="" placeholder="<?php echo $constStr['InputPasswordUWant'][$constStr['language']]; ?>">
<?php if (getConfig('passfile')!='') {?><input name="operate_action" type="submit" value="<?php echo $constStr['encrypt'][$constStr['language']]; ?>"><?php } else { ?><br><label><?php echo $constStr['SetpassfileBfEncrypt'][$constStr['language']]; ?></label><?php } ?>
</form>
</div>
</div>
<div id="move_div" class="operatediv" style="display:none">
<div>
<label id="move_label"></label><br><br><a onclick="operatediv_close('move')" class="operatediv_close"><?php echo $constStr['Close'][$constStr['language']]; ?></a>
<form id="move_form" onsubmit="return submit_operate('move');">
<input id="move_sid" name="move_sid" type="hidden" value="">
<input id="move_hidden" name="move_name" type="hidden" value="">
<select id="move_input" name="move_folder">
<?php if ($path != '/') { ?>
<option value="/../"><?php echo $constStr['ParentDir'][$constStr['language']]; ?></option>
<?php }
if (isset($files['children'])) foreach ($files['children'] as $file) {
if (isset($file['folder'])) { ?>
<option value="<?php echo str_replace('&','&amp;', $file['name']);?>"><?php echo str_replace('&','&amp;', $file['name']);?></option>
<?php }
} ?>
</select>
<input name="operate_action" type="submit" value="<?php echo $constStr['Move'][$constStr['language']]; ?>">
</form>
</div>
</div>
<div id="create_div" class="operatediv" style="display:none">
<div>
<a onclick="operatediv_close('create')" class="operatediv_close"><?php echo $constStr['Close'][$constStr['language']]; ?></a>
<form id="create_form" onsubmit="return submit_operate('create');">
<input id="create_sid" name="create_sid" type="hidden" value="">
<input id="create_hidden" type="hidden" value="">
<table>
<tr>
<td></td>
<td><label id="create_label"></label></td>
</tr>
<tr>
<td>   </td>
<td>
<label><input id="create_type_folder" name="create_type" type="radio" value="folder" onclick="document.getElementById('create_text_div').style.display='none';"><?php echo $constStr['Folder'][$constStr['language']]; ?></label>
<label><input id="create_type_file" name="create_type" type="radio" value="file" onclick="document.getElementById('create_text_div').style.display='';" checked><?php echo $constStr['File'][$constStr['language']]; ?></label>
<td>
</tr>
<tr>
<td><?php echo $constStr['Name'][$constStr['language']]; ?></td>
<td><input id="create_input" name="create_name" type="text" value=""></td>
</tr>
<tr id="create_text_div">
<td><?php echo $constStr['Content'][$constStr['language']]; ?></td>
<td><textarea id="create_text" name="create_text" rows="6" cols="40"></textarea></td>
</tr>
<tr>
<td>   </td>
<td><input name="operate_action" type="submit" value="<?php echo $constStr['Create'][$constStr['language']]; ?>"></td>
</tr>
</table>
</form>
</div>
</div>
</div>
<?php }
} else {
if (getConfig('admin')!='') if (getConfig('adminloginpage')=='') { ?>
<div id="login_div" class="operatediv" style="display:none">
<div style="margin:50px">
<a onclick="operatediv_close('login')" class="operatediv_close"><?php echo $constStr['Close'][$constStr['language']]; ?></a>
<center>
<form action="<?php echo $_GET['preview']?'?preview&':'?';?>admin" method="post">
<input id="login_input" name="password1" type="password" placeholder="<?php echo $constStr['InputPassword'][$constStr['language']]; ?>">
<input type="submit" value="<?php echo $constStr['Login'][$constStr['language']]; ?>">
</form>
</center>
</div>
</div>
<?php }
} ?>
<font color="#f7f7f9"><?php echo date("Y-m-d H:i:s")." ".$constStr['Week'][date("w")][$constStr['language']]." ".$_SERVER['REMOTE_ADDR'];?></font>
</body>
<link rel="stylesheet" href="//unpkg.zhimg.com/github-markdown-css@3.0.1/github-markdown.css">
<script type="text/javascript" src="//unpkg.zhimg.com/marked@0.6.2/marked.min.js"></script>
<?php if (isset($files['folder']) && $_SERVER['is_guestup_path'] && !$_SERVER['admin']) { ?><script type="text/javascript" src="//cdn.bootcss.com/spark-md5/3.0.0/spark-md5.min.js"></script><?php } ?>
<script type="text/javascript">
var root = '<?php echo $_SERVER["base_path"]; ?>';
function path_format(path) {
path = '/' + path + '/';
while (path.indexOf('//') !== -1) {
path = path.replace('//', '/')
}
return path
}
document.querySelectorAll('.table-header').forEach(function (e) {
var path = e.innerText;
var paths = path.split('/');
if (paths <= 2) return;
e.innerHTML = '/ ';
for (var i = 1; i < paths.length - 1; i++) {
var to = path_format(root + paths.slice(0, i + 1).join('/'));
e.innerHTML += '<a href="' + to + '">' + paths[i] + '</a> / '
}
e.innerHTML += paths[paths.length - 1];
e.innerHTML = e.innerHTML.replace(/\s\/\s$/, '')
});
function changelanguage(str)
{
document.cookie='language='+str+'; path=/';
location.href = location.href;
}
var $readme = document.getElementById('readme');
if ($readme) {
$readme.innerHTML = marked(document.getElementById('readme-md').innerText)
}
<?php
if ($_GET['preview']) { //is preview mode. 在预览时处理 ?>
var $url = document.getElementById('url');
if ($url) {
$url.innerHTML = location.protocol + '//' + location.host + $url.innerHTML;
$url.style.height = $url.scrollHeight + 'px';
}
var $officearea=document.getElementById('office-a');
if ($officearea) {
$officearea.style.height = window.innerHeight + 'px';
}
var $textarea=document.getElementById('txt-a');
if ($textarea) {
$textarea.style.height = $textarea.scrollHeight + 'px';
}
<?php if (!!$DPvideo) { ?>
function loadResources(type, src, callback) {
let script = document.createElement(type);
let loaded = false;
if (typeof callback === 'function') {
script.onload = script.onreadystatechange = () => {
if (!loaded && (!script.readyState || /loaded|complete/.test(script.readyState))) {
script.onload = script.onreadystatechange = null;
loaded = true;
callback();
}
}
}
if (type === 'link') {
script.href = src;
script.rel = 'stylesheet';
} else {
script.src = src;
}
document.getElementsByTagName('head')[0].appendChild(script);
}
function addVideos(videos) {
let host = 'https://s0.pstatp.com/cdn/expire-1-M';
let unloadedResourceCount = 4;
let callback = (() => {
return () => {
if (!--unloadedResourceCount) {
createDplayers(videos);
}
};
})(unloadedResourceCount, videos);
loadResources(
'link',
host + '/dplayer/1.25.0/DPlayer.min.css',
callback
);
loadResources(
'script',
host + '/dplayer/1.25.0/DPlayer.min.js',
callback
);
loadResources(
'script',
host + '/hls.js/0.12.4/hls.light.min.js',
callback
);
loadResources(
'script',
host + '/flv.js/1.5.0/flv.min.js',
callback
);
}
function createDplayers(videos) {
for (i = 0; i < videos.length; i++) {
console.log(videos[i]);
new DPlayer({
container: document.getElementById('video-a' + i),
screenshot: true,
video: {
url: videos[i]
}
});
}
}
addVideos(['<?php echo $DPvideo;?>']);
<?php }
} else { // view folder. 不预览,即浏览目录时?>
var sort=0;
function showthumbnails(obj) {
var files=document.getElementsByName('filelist');
for ($i=0;$i<files.length;$i++) {
str=files[$i].innerText;
if (str.substr(-1)==' ') str=str.substr(0,str.length-1);
if (!str) return;
strarry=str.split('.');
ext=strarry[strarry.length-1].toLowerCase();
images = [<?php foreach ($exts['img'] as $imgext) echo '\''.$imgext.'\', '; ?>];
if (images.indexOf(ext)>-1) get_thumbnails_url(str, files[$i]);
}
obj.disabled='disabled';
}
function get_thumbnails_url(str, filea) {
if (!str) return;
var nurl=window.location.href;
if (nurl.substr(-1)!="/") nurl+="/";
var xhr = new XMLHttpRequest();
xhr.open("GET", nurl+str+'?thumbnails', true);
//xhr.setRequestHeader('x-requested-with','XMLHttpRequest');
xhr.send('');
xhr.onload = function(e){
if (xhr.status==200) {
if (xhr.responseText!='') filea.innerHTML='<img src="'+xhr.responseText+'" alt="'+str+'">';
} else console.log(xhr.status+'\n'+xhr.responseText);
}
}
function sortby(string) {
if (string=='a') if (sort!=0) {
for (i = 1; i <= <?php echo $filenum?$filenum:0;?>; i++) document.getElementById('tr'+i).parentNode.insertBefore(document.getElementById('tr'+i),document.getElementById('tr'+(i-1)).nextSibling);
sort=0;
return;
} else return;
sort1=sort;
sortby('a');
sort=sort1;
var a=[];
for (i = 1; i <= <?php echo $filenum?$filenum:0;?>; i++) {
a[i]=i;
if (!!document.getElementById('folder_'+string+i)) {
var td1=document.getElementById('folder_'+string+i);
for (j = 1; j < i; j++) {
if (!!document.getElementById('folder_'+string+a[j])) {
var c=false;
if (string=='time') if (sort==-1) {
c=(td1.innerText < document.getElementById('folder_'+string+a[j]).innerText);
} else {
c=(td1.innerText > document.getElementById('folder_'+string+a[j]).innerText);
}
if (string=='size') if (sort==2) {
c=(size_reformat(td1.innerText) < size_reformat(document.getElementById('folder_'+string+a[j]).innerText));
} else {
c=(size_reformat(td1.innerText) > size_reformat(document.getElementById('folder_'+string+a[j]).innerText));
}
if (c) {
document.getElementById('tr'+i).parentNode.insertBefore(document.getElementById('tr'+i),document.getElementById('tr'+a[j]));
for (k = i; k > j; k--) {
a[k]=a[k-1];
}
a[j]=i;
break;
}
}
}
}
if (!!document.getElementById('file_'+string+i)) {
var td1=document.getElementById('file_'+string+i);
for (j = 1; j < i; j++) {
if (!!document.getElementById('file_'+string+a[j])) {
var c=false;
if (string=='time') if (sort==-1) {
c=(td1.innerText < document.getElementById('file_'+string+a[j]).innerText);
} else {
c=(td1.innerText > document.getElementById('file_'+string+a[j]).innerText);
}
if (string=='size') if (sort==2) {
c=(size_reformat(td1.innerText) < size_reformat(document.getElementById('file_'+string+a[j]).innerText));
} else {
c=(size_reformat(td1.innerText) > size_reformat(document.getElementById('file_'+string+a[j]).innerText));
}
if (c) {
document.getElementById('tr'+i).parentNode.insertBefore(document.getElementById('tr'+i),document.getElementById('tr'+a[j]));
for (k = i; k > j; k--) {
a[k]=a[k-1];
}
a[j]=i;
break;
}
}
}
}
}
if (string=='time') if (sort==-1) {
sort=1;
} else {
sort=-1;
}
if (string=='size') if (sort==2) {
sort=-2;
} else {
sort=2;
}
}
function size_reformat(str) {
if (str.substr(-1)==' ') str=str.substr(0,str.length-1);
if (str.substr(-2)=='GB') num=str.substr(0,str.length-3)*1024*1024*1024;
if (str.substr(-2)=='MB') num=str.substr(0,str.length-3)*1024*1024;
if (str.substr(-2)=='KB') num=str.substr(0,str.length-3)*1024;
if (str.substr(-2)==' B') num=str.substr(0,str.length-2);
return num;
}
<?php
}
if ($_COOKIE['timezone']=='') { // cookie timezone. 无时区写时区 ?>
var nowtime= new Date();
var timezone = 0-nowtime.getTimezoneOffset()/60;
var expd = new Date();
expd.setTime(expd.getTime()+(2*60*60*1000));
var expires = "expires="+expd.toGMTString();
document.cookie="timezone="+timezone+"; path=/; "+expires;
if (timezone!='8') {
alert('Your timezone is '+timezone+', reload local timezone.');
location.href=location.protocol + "//" + location.host + "<?php echo path_format($_SERVER['base_path'] . '/' . $path );?>" ;
}
<?php }
if ($files['folder']['childCount']>200) { // more than 200. 有下一页 ?>
function nextpage(num) {
document.getElementById('pagenum').value=num;
document.getElementById('nextpageform').submit();
}
<?php }
if (getConfig('admin')!='') { // close div. 有登录或操作需要关闭DIV时 ?>
function operatediv_close(operate) {
document.getElementById(operate+'_div').style.display='none';
document.getElementById('mask').style.display='none';
}
<?php }
if (isset($files['folder']) && ($_SERVER['is_imgup_path'] || $_SERVER['admin'])) { // is folder and is admin or guest upload path. 当前是admin登录或图床目录时 ?>
function uploadbuttonhide() {
document.getElementById('upload_submit').disabled='disabled';
document.getElementById('upload_file').disabled='disabled';
document.getElementById('upload_submit').style.display='none';
document.getElementById('upload_file').style.display='none';
}
function uploadbuttonshow() {
document.getElementById('upload_file').disabled='';
document.getElementById('upload_submit').disabled='';
document.getElementById('upload_submit').style.display='';
document.getElementById('upload_file').style.display='';
}
function preup() {
uploadbuttonhide();
var files=document.getElementById('upload_file').files;
if (files.length<1) {
uploadbuttonshow();
return;
};
var table1=document.createElement('table');
document.getElementById('upload_div').appendChild(table1);
table1.setAttribute('class','list-table');
var timea=new Date().getTime();
var i=0;
getuplink(i);
function getuplink(i) {
var file=files[i];
var tr1=document.createElement('tr');
table1.appendChild(tr1);
tr1.setAttribute('data-to',1);
var td1=document.createElement('td');
tr1.appendChild(td1);
td1.setAttribute('style','width:30%');
td1.setAttribute('id','upfile_td1_'+timea+'_'+i);
td1.innerHTML=file.name+'<br>'+size_format(file.size);
var td2=document.createElement('td');
tr1.appendChild(td2);
td2.setAttribute('id','upfile_td2_'+timea+'_'+i);
td2.innerHTML='<?php echo $constStr['GetUploadLink'][$constStr['language']]; ?> ...';
if (file.size>100*1024*1024*1024) {
td2.innerHTML='<font color="red"><?php echo $constStr['UpFileTooLarge'][$constStr['language']]; ?></font>';
uploadbuttonshow();
return;
}
var xhr1 = new XMLHttpRequest();
xhr1.open("GET", '?action=upbigfile&upbigfilename='+ encodeURIComponent(file.name) +'&filesize='+ file.size +'&lastModified='+ file.lastModified);
xhr1.setRequestHeader('x-requested-with','XMLHttpRequest');
xhr1.send(null);
xhr1.onload = function(e){
td2.innerHTML='<font color="red">'+xhr1.responseText+'</font>';
if (xhr1.status==200) {
var html=JSON.parse(xhr1.responseText);
if (!html['uploadUrl']) {
td2.innerHTML='<font color="red">'+xhr1.responseText+'</font><br>';
uploadbuttonshow();
} else {
td2.innerHTML='<?php echo $constStr['UploadStart'][$constStr['language']]; ?> ...';
binupfile(file,html['uploadUrl'],timea+'_'+i);
}
}
if (i<files.length-1) {
i++;
getuplink(i);
}
}
}
}
function size_format(num) {
if (num>1024) {
num=num/1024;
} else {
return num.toFixed(2) + ' B';
}
if (num>1024) {
num=num/1024;
} else {
return num.toFixed(2) + ' KB';
}
if (num>1024) {
num=num/1024;
} else {
return num.toFixed(2) + ' MB';
}
return num.toFixed(2) + ' GB';
}
function binupfile(file,url,tdnum){
var label=document.getElementById('upfile_td2_'+tdnum);
var reader = new FileReader();
var StartStr='';
var MiddleStr='';
var StartTime;
var EndTime;
var newstartsize = 0;
if(!!file){
var asize=0;
var totalsize=file.size;
var xhr2 = new XMLHttpRequest();
xhr2.open("GET", url);
//xhr2.setRequestHeader('x-requested-with','XMLHttpRequest');
xhr2.send(null);
xhr2.onload = function(e){
if (xhr2.status==200) {
var html = JSON.parse(xhr2.responseText);
var a = html['nextExpectedRanges'][0];
newstartsize = Number( a.slice(0,a.indexOf("-")) );
StartTime = new Date();
<?php if ($_SERVER['admin']) { ?>
asize = newstartsize;
<?php } ?>
if (newstartsize==0) {
StartStr='<?php echo $constStr['UploadStartAt'][$constStr['language']]; ?>:' +StartTime.toLocaleString()+'<br>' ;
} else {
StartStr='<?php echo $constStr['LastUpload'][$constStr['language']]; ?>'+size_format(newstartsize)+ '<br><?php echo $constStr['ThisTime'][$constStr['language']].$constStr['UploadStartAt'][$constStr['language']]; ?>:' +StartTime.toLocaleString()+'<br>' ;
}
var chunksize=5*1024*1024; // chunk size, max 60M. 每小块上传大小最大60M微软建议10M
if (totalsize>200*1024*1024) chunksize=10*1024*1024;
function readblob(start) {
var end=start+chunksize;
var blob = file.slice(start,end);
reader.readAsArrayBuffer(blob);
}
readblob(asize);
<?php if (!$_SERVER['admin']) { ?>
var spark = new SparkMD5.ArrayBuffer();
<?php } ?>
reader.onload = function(e){
var binary = this.result;
<?php if (!$_SERVER['admin']) { ?>
spark.append(binary);
if (asize < newstartsize) {
asize += chunksize;
readblob(asize);
return;
}
<?php } ?>
var xhr = new XMLHttpRequest();
xhr.open("PUT", url, true);
//xhr.setRequestHeader('x-requested-with','XMLHttpRequest');
bsize=asize+e.loaded-1;
xhr.setRequestHeader('Content-Range', 'bytes ' + asize + '-' + bsize +'/'+ totalsize);
xhr.upload.onprogress = function(e){
if (e.lengthComputable) {
var tmptime = new Date();
var tmpspeed = e.loaded*1000/(tmptime.getTime()-C_starttime.getTime());
var remaintime = (totalsize-asize-e.loaded)/tmpspeed;
label.innerHTML=StartStr+'<?php echo $constStr['Upload'][$constStr['language']]; ?> ' +size_format(asize+e.loaded)+ ' / '+size_format(totalsize) + ' = ' + ((asize+e.loaded)*100/totalsize).toFixed(2) + '% <?php echo $constStr['AverageSpeed'][$constStr['language']]; ?>:'+size_format((asize+e.loaded-newstartsize)*1000/(tmptime.getTime()-StartTime.getTime()))+'/s<br><?php echo $constStr['CurrentSpeed'][$constStr['language']]; ?> '+size_format(tmpspeed)+'/s <?php echo $constStr['Expect'][$constStr['language']]; ?> '+remaintime.toFixed(1)+'s';
}
}
var C_starttime = new Date();
xhr.onload = function(e){
if (xhr.status<500) {
var response=JSON.parse(xhr.responseText);
if (response['size']>0) {
// contain size, upload finish. 有size说明是最终返回上传结束
var xhr3 = new XMLHttpRequest();
xhr3.open("GET", '?action=del_upload_cache&filename=.'+file.lastModified+ '_' +file.size+ '_' +encodeURIComponent(file.name)+'.tmp');
xhr3.setRequestHeader('x-requested-with','XMLHttpRequest');
xhr3.send(null);
xhr3.onload = function(e){
console.log(xhr3.responseText+','+xhr3.status);
}
<?php if (!$_SERVER['admin']) { ?>
var filemd5 = spark.end();
var xhr4 = new XMLHttpRequest();
xhr4.open("GET", '?action=uploaded_rename&filename='+encodeURIComponent(file.name)+'&filemd5='+filemd5);
xhr4.setRequestHeader('x-requested-with','XMLHttpRequest');
xhr4.send(null);
xhr4.onload = function(e){
console.log(xhr4.responseText+','+xhr4.status);
var filename;
if (xhr4.status==200) filename = JSON.parse(xhr4.responseText)['name'];
if (xhr4.status==409) filename = filemd5 + file.name.substr(file.name.indexOf('.'));
if (filename=='') {
alert('<?php echo $constStr['UploadErrorUpAgain'][$constStr['language']]; ?>');
uploadbuttonshow();
return;
}
var lasturl = location.href;
if (lasturl.substr(lasturl.length-1)!='/') lasturl += '/';
lasturl += filename + '?preview';
//alert(lasturl);
window.open(lasturl);
}
<?php } ?>
EndTime=new Date();
MiddleStr = '<?php echo $constStr['EndAt'][$constStr['language']]; ?>:'+EndTime.toLocaleString()+'<br>';
if (newstartsize==0) {
MiddleStr += '<?php echo $constStr['AverageSpeed'][$constStr['language']]; ?>:'+size_format(totalsize*1000/(EndTime.getTime()-StartTime.getTime()))+'/s<br>';
} else {
MiddleStr += '<?php echo $constStr['ThisTime'][$constStr['language']].$constStr['AverageSpeed'][$constStr['language']]; ?>:'+size_format((totalsize-newstartsize)*1000/(EndTime.getTime()-StartTime.getTime()))+'/s<br>';
}
document.getElementById('upfile_td1_'+tdnum).innerHTML='<font color="green"><?php if (!$_SERVER['admin']) { ?>'+filemd5+'<br><?php } ?>'+document.getElementById('upfile_td1_'+tdnum).innerHTML+'<br><?php echo $constStr['UploadComplete'][$constStr['language']]; ?></font>';
label.innerHTML=StartStr+MiddleStr;
uploadbuttonshow();
<?php if ($_SERVER['admin']) { ?>
addelement(response);
<?php } ?>
} else {
if (!response['nextExpectedRanges']) {
label.innerHTML='<font color="red">'+xhr.responseText+'</font><br>';
} else {
var a=response['nextExpectedRanges'][0];
asize=Number( a.slice(0,a.indexOf("-")) );
readblob(asize);
}
} } else readblob(asize);
}
xhr.send(binary);
}
} else {
if (window.location.pathname.indexOf('%23')>0||file.name.indexOf('%23')>0) {
label.innerHTML='<font color="red"><?php echo $constStr['UploadFail23'][$constStr['language']]; ?></font>';
} else {
label.innerHTML='<font color="red">'+xhr2.responseText+'</font>';
}
uploadbuttonshow();
}
}
}
}
<?php }
if ($_SERVER['admin']) { // admin login. 管理登录后 ?>
function logout() {
document.cookie = "<?php echo $_SERVER['function_name'] . 'admin';?>=; path=/";
location.href = location.href;
}
function enableedit(obj) {
document.getElementById('txt-a').readOnly=!document.getElementById('txt-a').readOnly;
//document.getElementById('txt-editbutton').innerHTML=(document.getElementById('txt-editbutton').innerHTML=='取消编辑')?'点击后编辑':'取消编辑';
obj.innerHTML=(obj.innerHTML=='<?php echo $constStr['CancelEdit'][$constStr['language']]; ?>')?'<?php echo $constStr['ClicktoEdit'][$constStr['language']]; ?>':'<?php echo $constStr['CancelEdit'][$constStr['language']]; ?>';
document.getElementById('txt-save').style.display=document.getElementById('txt-save').style.display==''?'none':'';
}
<?php if (!$_GET['preview']) {?>
function showdiv(event,action,num) {
var $operatediv=document.getElementsByName('operatediv');
for ($i=0;$i<$operatediv.length;$i++) {
$operatediv[$i].style.display='none';
}
document.getElementById('mask').style.display='';
//document.getElementById('mask').style.width=document.documentElement.scrollWidth+'px';
document.getElementById('mask').style.height=document.documentElement.scrollHeight<window.innerHeight?window.innerHeight:document.documentElement.scrollHeight+'px';
if (num=='') {
var str='';
} else {
var str=document.getElementById('file_a'+num).innerText;
if (str=='') {
str=document.getElementById('file_a'+num).getElementsByTagName("img")[0].alt;
if (str=='') {
alert('<?php echo $constStr['GetFileNameFail'][$constStr['language']]; ?>');
operatediv_close(action);
return;
}
}
if (str.substr(-1)==' ') str=str.substr(0,str.length-1);
}
document.getElementById(action + '_div').style.display='';
document.getElementById(action + '_label').innerText=str;//.replace(/&/,'&amp;');
document.getElementById(action + '_sid').value=num;
document.getElementById(action + '_hidden').value=str;
if (action=='rename') document.getElementById(action + '_input').value=str;
var $e = event || window.event;
var $scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
var $scrollY = document.documentElement.scrollTop || document.body.scrollTop;
var $x = $e.pageX || $e.clientX + $scrollX;
var $y = $e.pageY || $e.clientY + $scrollY;
if (action=='create') {
document.getElementById(action + '_div').style.left=(document.body.clientWidth-document.getElementById(action + '_div').offsetWidth)/2 +'px';
document.getElementById(action + '_div').style.top=(window.innerHeight-document.getElementById(action + '_div').offsetHeight)/2+$scrollY +'px';
} else {
if ($x + document.getElementById(action + '_div').offsetWidth > document.body.clientWidth) {
document.getElementById(action + '_div').style.left=document.body.clientWidth-document.getElementById(action + '_div').offsetWidth+'px';
} else {
document.getElementById(action + '_div').style.left=$x+'px';
}
document.getElementById(action + '_div').style.top=$y+'px';
}
document.getElementById(action + '_input').focus();
}
function submit_operate(str) {
var num=document.getElementById(str+'_sid').value;
var xhr = new XMLHttpRequest();
xhr.open("GET", '?'+serializeForm(str+'_form'));
xhr.setRequestHeader('x-requested-with','XMLHttpRequest');
xhr.send(null);
xhr.onload = function(e){
var html;
if (xhr.status<300) {
if (str=='rename') {
html=JSON.parse(xhr.responseText);
var file_a = document.getElementById('file_a'+num);
file_a.innerText=html.name;
file_a.href = (file_a.href.substr(-8)=='?preview')?(html.name.replace(/#/,'%23')+'?preview'):(html.name.replace(/#/,'%23')+'/');
}
if (str=='move'||str=='delete') document.getElementById('tr'+num).parentNode.removeChild(document.getElementById('tr'+num));
if (str=='create') {
html=JSON.parse(xhr.responseText);
addelement(html);
}
} else alert(xhr.status+'\n'+xhr.responseText);
document.getElementById(str+'_div').style.display='none';
document.getElementById('mask').style.display='none';
}
return false;
}
function addelement(html) {
var tr1=document.createElement('tr');
tr1.setAttribute('data-to',1);
var td1=document.createElement('td');
td1.setAttribute('class','file');
var a1=document.createElement('a');
a1.href=html.name.replace(/#/,'%23');
a1.innerText=html.name;
a1.target='_blank';
var td2=document.createElement('td');
td2.setAttribute('class','updated_at');
td2.innerText=html.lastModifiedDateTime.replace(/T/,' ').replace(/Z/,'');
var td3=document.createElement('td');
td3.setAttribute('class','size');
td3.innerText=size_format(html.size);
if (!!html.folder) {
a1.href+='/';
document.getElementById('tr0').parentNode.insertBefore(tr1,document.getElementById('tr0').nextSibling);
}
if (!!html.file) {
a1.href+='?preview';
a1.name='filelist';
document.getElementById('tr0').parentNode.appendChild(tr1);
}
tr1.appendChild(td1);
td1.appendChild(a1);
tr1.appendChild(td2);
tr1.appendChild(td3);
}
function getElements(formId) {
var form = document.getElementById(formId);
var elements = new Array();
var tagElements = form.getElementsByTagName('input');
for (var j = 0; j < tagElements.length; j++){
elements.push(tagElements[j]);
}
var tagElements = form.getElementsByTagName('select');
for (var j = 0; j < tagElements.length; j++){
elements.push(tagElements[j]);
}
var tagElements = form.getElementsByTagName('textarea');
for (var j = 0; j < tagElements.length; j++){
elements.push(tagElements[j]);
}
return elements;
}
function serializeElement(element) {
var method = element.tagName.toLowerCase();
var parameter;
if (method == 'select') {
parameter = [element.name, element.value];
}
switch (element.type.toLowerCase()) {
case 'submit':
case 'hidden':
case 'password':
case 'text':
case 'date':
case 'textarea':
parameter = [element.name, element.value];
break;
case 'checkbox':
case 'radio':
if (element.checked){
parameter = [element.name, element.value];
}
break;
}
if (parameter) {
var key = encodeURIComponent(parameter[0]);
if (key.length == 0) return;
if (parameter[1].constructor != Array) parameter[1] = [parameter[1]];
var values = parameter[1];
var results = [];
for (var i = 0; i < values.length; i++) {
results.push(key + '=' + encodeURIComponent(values[i]));
}
return results.join('&');
}
}
function serializeForm(formId) {
var elements = getElements(formId);
var queryComponents = new Array();
for (var i = 0; i < elements.length; i++) {
var queryComponent = serializeElement(elements[i]);
if (queryComponent) {
queryComponents.push(queryComponent);
}
}
return queryComponents.join('&');
}
<?php }
} else if (getConfig('admin')!='') if (getConfig('adminloginpage')=='') { ?>
function login() {
document.getElementById('mask').style.display='';
//document.getElementById('mask').style.width=document.documentElement.scrollWidth+'px';
document.getElementById('mask').style.height=document.documentElement.scrollHeight<window.innerHeight?window.innerHeight:document.documentElement.scrollHeight+'px';
document.getElementById('login_div').style.display='';
document.getElementById('login_div').style.left=(document.body.clientWidth-document.getElementById('login_div').offsetWidth)/2 +'px';
document.getElementById('login_div').style.top=(window.innerHeight-document.getElementById('login_div').offsetHeight)/2+document.body.scrollTop +'px';
document.getElementById('login_input').focus();
}
<?php } ?>
</script>
<script src="//unpkg.zhimg.com/ionicons@4.4.4/dist/ionicons.js"></script>
</html>
<?php
$html=ob_get_clean();
if ($_SERVER['Set-Cookie']!='') return output($html, $statusCode, [ 'Set-Cookie' => $_SERVER['Set-Cookie'], 'Content-Type' => 'text/html' ]);
return output($html,$statusCode);
}