Merge pull request #76 from qkqpttgf/master

pull
pull/98/head
Mr.Lin 2020-05-25 22:45:13 +08:00 committed by GitHub
commit 3442526cc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 155 additions and 60 deletions

View File

@ -9,6 +9,7 @@ $Base64Env = [
//'adminloginpage',
'background',
'diskname',
//'disableShowThumb',
//'disktag',
//'downloadencrypt',
//'function_name', // used in heroku.
@ -18,6 +19,7 @@ $Base64Env = [
'sitename',
'customScript',
'customCss',
'customTheme',
//'theme',
//'Drive_ver',
//'Drive_custom',
@ -45,6 +47,7 @@ $CommonEnv = [
'adminloginpage',
'background',
'disktag',
'disableShowThumb',
'function_name', // used in heroku.
'hideFunctionalityFile',
'timezone',
@ -52,6 +55,7 @@ $CommonEnv = [
'sitename',
'customScript',
'customCss',
'customTheme',
'theme',
];
@ -64,6 +68,7 @@ $ShowedCommonEnv = [
'adminloginpage',
'background',
//'disktag',
'disableShowThumb',
//'function_name', // used in heroku.
'hideFunctionalityFile',
'timezone',
@ -71,6 +76,7 @@ $ShowedCommonEnv = [
'sitename',
'customScript',
'customCss',
'customTheme',
'theme',
];
@ -175,8 +181,6 @@ function main($path)
$_SERVER['timezone'] = getConfig('timezone');
if (isset($_COOKIE['timezone'])&&$_COOKIE['timezone']!='') $_SERVER['timezone'] = $_COOKIE['timezone'];
if ($_SERVER['timezone']=='') $_SERVER['timezone'] = 0;
if (isset($_COOKIE['theme'])&&$_COOKIE['theme']!='') $_SERVER['theme'] = $_COOKIE['theme'];
else $_SERVER['theme'] = getConfig('theme');
$_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
if (getConfig('admin')=='') return install();
@ -305,7 +309,7 @@ function main($path)
if (isset($_GET['thumbnails'])) {
if ($_SERVER['ishidden']<4) {
if (in_array(strtolower(substr($path, strrpos($path, '.') + 1)), $exts['img'])) {
return get_thumbnails_url($path);
return get_thumbnails_url($path, $_GET['location']);
} else return output(json_encode($exts['img']),400);
} else return output('',401);
}
@ -364,7 +368,7 @@ function get_access_token($refresh_token)
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));
error_log('['.$_SERVER['disktag'].'] Get access token:'.json_encode($ret, JSON_PRETTY_PRINT));
savecache('access_token', $_SERVER['access_token']);
$tmp = [];
$tmp['shareapiurl'] = $_SERVER['api_url'];
@ -374,10 +378,10 @@ function get_access_token($refresh_token)
if ($response['stat']==200) $ret = json_decode($response['body'], true);
if (!isset($ret['access_token'])) {
error_log($_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);
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 ['.$_SERVER['disktag'].'] access_token. response' . json_encode($ret));
throw new Exception($response['stat'].', failed to get ['.$_SERVER['disktag'].'] access_token.'.$response['body']);
}
error_log('Get access token:'.json_encode($ret, JSON_PRETTY_PRINT));
error_log('['.$_SERVER['disktag'].'] Get access token:'.json_encode($ret, JSON_PRETTY_PRINT));
$_SERVER['access_token'] = $ret['access_token'];
savecache('access_token', $_SERVER['access_token'], $ret['expires_in'] - 300);
if (time()>getConfig('token_expires')) setConfig([ 'refresh_token' => $ret['refresh_token'], 'token_expires' => time()+7*24*60*60 ]);
@ -777,23 +781,28 @@ function time_format($ISO)
return date('Y-m-d H:i:s',strtotime($ISO . " UTC"));
}
function get_thumbnails_url($path = '/')
function get_thumbnails_url($path = '/', $location = 0)
{
$path1 = path_format($path);
$path = path_format($_SERVER['list_path'] . path_format($path));
if ($path!='/'&&substr($path,-1)=='/') $path=substr($path,0,-1);
$thumb_url = getcache('thumb_'.$path);
if ($thumb_url!='') return output($thumb_url);
$url = $_SERVER['api_url'];
if ($path !== '/') {
$url .= ':' . $path;
if (substr($url,-1)=='/') $url=substr($url,0,-1);
if ($thumb_url=='') {
$url = $_SERVER['api_url'];
if ($path !== '/') {
$url .= ':' . $path;
if (substr($url,-1)=='/') $url=substr($url,0,-1);
}
$url .= ':/thumbnails/0/medium';
$files = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']])['body'], true);
if (isset($files['url'])) {
savecache('thumb_'.$path, $files['url']);
$thumb_url = $files['url'];
}
}
$url .= ':/thumbnails/0/medium';
$files = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']])['body'], true);
if (isset($files['url'])) {
savecache('thumb_'.$path, $files['url']);
return output($files['url']);
if ($thumb_url!='') {
if ($location) return output('', 302, [ 'Location' => $thumb_url ]);
else return output($thumb_url);
}
return output('', 404);
}
@ -989,6 +998,7 @@ function adminoperate($path)
$path1 = path_format($_SERVER['list_path'] . path_format($path));
if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1);
savecache('path_' . $path1 . '/?password', '', 1);
savecache('customTheme', '', 1);
return message('<meta http-equiv="refresh" content="2;URL=./">', getconstStr('RefreshCache'), 302);
}
return $tmparr;
@ -1569,6 +1579,7 @@ function EnvOpt($needUpdate = 0)
}
$html .= '
</select>
'.getconstStr('EnvironmentsDescription')[$key].'
</td>
</tr>';
} elseif ($key=='theme') {
@ -1585,6 +1596,7 @@ function EnvOpt($needUpdate = 0)
}
$html .= '
</select>
'.getconstStr('EnvironmentsDescription')[$key].'
</td>
</tr>';
} /*elseif ($key=='domain_path') {
@ -1750,18 +1762,40 @@ function render_list($path = '', $files = '')
Github: https://github.com/qkqpttgf/OneManager-php
-->';
//$theme = getConfig('theme');
$theme = $_SERVER['theme'];
if ( $theme=='' || !file_exists('theme/'.$theme) ) $theme = 'classic.html';
if (isset($_COOKIE['theme'])&&$_COOKIE['theme']!='') $theme = $_COOKIE['theme'];
if ( $theme=='' ) {
$tmp = getConfig('customTheme');
if ( $tmp!='' ) $theme = $tmp;
}
if ( $theme=='' ) {
$theme = getConfig('theme');
if ( $theme=='' || !file_exists('theme/'.$theme) ) $theme = 'classic.html';
}
if (substr($theme,-4)=='.php') {
@ob_start();
include 'theme/'.$theme;
$html = ob_get_clean();
} else {
$file_path = 'theme/'.$theme;
$fp = fopen($file_path,"r");
$html = fread($fp,filesize($file_path));
fclose($fp);
if (file_exists('theme/'.$theme)) {
$file_path = 'theme/'.$theme;
$html = file_get_contents($file_path);
} else {
if (!($html = getcache('customTheme'))) {
$file_path = $theme;
$tmp = curl_request($file_path, false, [], 1);
if ($tmp['stat']==302) {
error_log(json_encode($tmp));
$tmp = curl_request($tmp["returnhead"]["Location"]);
}
if (!!$tmp['body']) $html = $tmp['body'];
savecache('customTheme', $html, 9999);
}
}
//$fp = fopen($file_path,"r");
//$html = fread($fp,filesize($file_path));
//fclose($fp);
$tmp = splitfirst($html, '<!--IconValuesStart-->');
$html = $tmp[0];
@ -2009,17 +2043,19 @@ function render_list($path = '', $files = '')
//$FolderListStr = str_replace('<!--FileEncodeReplaceUrl-->', path_format($_SERVER['base_disk_path'] . '/' . $path . '/' . str_replace('&','&amp;', $file['name'])), $FolderListStr);
$FolderListStr = str_replace('<!--lastModifiedDateTime-->', time_format($file['lastModifiedDateTime']), $FolderListStr);
$FolderListStr = str_replace('<!--size-->', size_format($file['size']), $FolderListStr);
foreach ($IconValues as $key1 => $value1) {
if (isset($exts[$key1])&&in_array($ext, $exts[$key1])) {
$FolderListStr = str_replace('<!--IconValue-->', $value1, $FolderListStr);
if (!!$IconValues) {
foreach ($IconValues as $key1 => $value1) {
if (isset($exts[$key1])&&in_array($ext, $exts[$key1])) {
$FolderListStr = str_replace('<!--IconValue-->', $value1, $FolderListStr);
}
if ($ext==$key1) {
$FolderListStr = str_replace('<!--IconValue-->', $value1, $FolderListStr);
}
//error_log('file:'.$file['name'].':'.$key1);
if (!strpos($FolderListStr, '<!--IconValue-->')) break;
}
if ($ext==$key1) {
$FolderListStr = str_replace('<!--IconValue-->', $value1, $FolderListStr);
}
//error_log('file:'.$file['name'].':'.$key1);
if (!strpos($FolderListStr, '<!--IconValue-->')) break;
if (strpos($FolderListStr, '<!--IconValue-->')) $FolderListStr = str_replace('<!--IconValue-->', $IconValues['default'], $FolderListStr);
}
if (strpos($FolderListStr, '<!--IconValue-->')) $FolderListStr = str_replace('<!--IconValue-->', $IconValues['default'], $FolderListStr);
while (strpos($FolderListStr, '<!--filenum-->')) $FolderListStr = str_replace('<!--filenum-->', $filenum, $FolderListStr);
$html .= $FolderListStr;
}
@ -2080,6 +2116,8 @@ function render_list($path = '', $files = '')
}
$html .= $tmp[1];
while (strpos($html, '<!--MaxPageNum-->')) $html = str_replace('<!--MaxPageNum-->', $maxpage, $html);
} else {
while (strpos($html, '<!--MorePageStart-->')) {
$tmp = splitfirst($html, '<!--MorePageStart-->');
@ -2236,7 +2274,7 @@ function render_list($path = '', $files = '')
$folder1 = $tmp1[0];
if ($folder1!='') {
$tmp_url .= $folder1 . '/';
$PathArrayStr1 = str_replace('<!--PathArrayLink-->', $tmp_url, $PathArrayStr);
$PathArrayStr1 = str_replace('<!--PathArrayLink-->', ($folder1==$files['name']?'':$tmp_url), $PathArrayStr);
$PathArrayStr1 = str_replace('<!--PathArrayName-->', $folder1, $PathArrayStr1);
$html .= $PathArrayStr1;
}
@ -2286,7 +2324,8 @@ function render_list($path = '', $files = '')
$tmp = splitfirst($html, '<!--ShowThumbnailsStart-->');
$html = $tmp[0];
$tmp = splitfirst($tmp[1], '<!--ShowThumbnailsEnd-->');
if (!(isset($_SERVER['USER'])&&$_SERVER['USER']=='qcloud')) {
//if (!(isset($_SERVER['USER'])&&$_SERVER['USER']=='qcloud')) {
if (!getConfig('disableShowThumb')) {
$html .= str_replace('<!--constStr@OriginalPic-->', getconstStr('OriginalPic'), $tmp[0]) . $tmp[1];
} else $html .= $tmp[1];
}
@ -2321,7 +2360,7 @@ function render_list($path = '', $files = '')
$html .= $MultiDiskArea . $tmp[1];
$diskname = getConfig('diskname');
if ($diskname=='') $diskname = $_SERVER['disktag'];
if (strlen($diskname)>10) $diskname = substr($diskname, 0, 7).'...';
if (strlen($diskname)>15) $diskname = substr($diskname, 0, 12).'...';
while (strpos($html, '<!--DiskNameNow-->')) $html = str_replace('<!--DiskNameNow-->', $diskname, $html);
$tmp = splitfirst($html, '<!--HeadomfStart-->');
@ -2467,15 +2506,21 @@ function render_list($path = '', $files = '')
<option value="">'.getconstStr('Theme').'</option>';
foreach ($theme_arr as $v1) {
if ($v1!='.' && $v1!='..') $html .= '
<option value="'.$v1.'" '.($v1==$_SERVER['theme']?'selected="selected"':'').'>'.$v1.'</option>';
<option value="'.$v1.'" '.($v1==$theme?'selected="selected"':'').'>'.$v1.'</option>';
}
//$tmp = getConfig('customTheme');
//if ($tmp!='') $html .= '
// <option value="" '.($tmp==$theme?'selected="selected"':'').'>customTheme</option>';
$html .= '
</select>
</div>
<script type="text/javascript">
function changetheme(str)
{
document.cookie=\'theme=\'+str+\'; path=/\';
var expd = new Date();
expd.setTime(expd.getTime()+(2*60*60*1000));
var expires = "expires="+expd.toGMTString();
document.cookie=\'theme=\'+str+\'; path=/; \'+expires;
location.href = location.href;
}
</script>';

View File

@ -68,11 +68,15 @@ $constStr = [
'adminloginpage' => 'if set, the Login button will not display, and the login page no longer \'?admin\', it is \'?{this value}\'.',
'customScript' => '<script> in all pages, e.g. http turn to https',
'customCss' => '<style> in <head>',
'customTheme' => 'an url of html',
'domain_path' => 'more custom domain, format is a1.com:/dirto/path1|b2.com:/path2',
'diskname' => 'The disk name you want show.',
'disktag' => 'A tag used in store config and url.',
'disableShowThumb' => 'if 1, the ShowThumbnail button will not display',
'downloadencrypt' => '0 or 1. if 1, the files in encrypt folder can be downloaded without password',
'background' => 'Set an url as background photo.',
'theme' => 'Select theme.',
'timezone' => 'Set default timezone.',
'guestup_path' => 'Set guest upload dir, before set this, the files in this dir will show as normal.',
'hideFunctionalityFile' => '0 or 1. if 1, some file will not show in list to guest, like readme.md',
'passfile' => 'The password of dir will save in this file.',
@ -85,11 +89,15 @@ $constStr = [
'adminloginpage' => '如果设置,登录按钮及页面隐藏。管理登录的页面不再是\'?admin\',而是\'?此设置的值\'。',
'customScript' => '<script>,在所有页都会存在,例如放一个http跳转https',
'customCss' => '<style>,在<head>最后面',
'customTheme' => 'html格式的主题的url',
'domain_path' => '使用多个自定义域名时指定每个域名看到的目录。格式为a1.com:/dirto/path1|b1.com:/path2比private_path优先。',
'diskname' => '这个盘你想显示什么名称。',
'disktag' => '一个标签用于保存配置多盘时会显示在url中。',
'disableShowThumb' => '如果填 1, ‘显示缩略’按钮将被隐藏。',
'downloadencrypt' => '0 或 1。如果 1, 那加密目录内的文件可以不需要密码就能下载。',
'background' => '设置一个url作为背景。',
'theme' => '选择一个主题。',
'timezone' => '设置默认时区。',
'guestup_path' => '设置游客上传路径(图床路径),不设置这个值时该目录内容会正常列文件出来,设置后只有上传界面,不显示其中文件(登录后显示)。',
'hideFunctionalityFile' => '0 或 1。如果 1, 某些文件不列表给游客看但它的功能正常比如readme.md',
'passfile' => '自定义密码文件的名字,可以是\'pppppp\',也可以是\'aaaa.txt\'等等;列目录时不会显示,只有知道密码才能查看或下载此文件。密码是这个文件的内容,可以空格、可以中文;',

View File

@ -151,7 +151,7 @@
<ion-icon name="arrow-back"></ion-icon>
</a>
<!--BackArrowEnd-->
<h3 class="table-header"><!--Path--></h3>
<h3 class="table-header"><!--PathArrayStart--> / <a href="<!--PathArrayLink-->"><!--PathArrayName--></a><!--PathArrayEnd--></h3>
</div>
<div class="list-body-container">
<!--EncryptedStart-->
@ -480,7 +480,7 @@
location.href = location.href;
}
<!--ListStart-->
var root = '<!--base_disk_path-->';
/*var root = '<!--base_disk_path-->';
function path_format(path) {
path = '/' + path + '/';
while (path.indexOf('//') !== -1) {
@ -500,7 +500,7 @@
}
e.innerHTML += paths[paths.length - 1];
e.innerHTML = e.innerHTML.replace(/\s\/\s$/, '')
});
});*/
<!--IsFileStart-->
var $url = document.getElementById('url');
if ($url) {

View File

@ -252,6 +252,25 @@
</li>
<!--FileListEnd-->
<!--MorePageStart-->
<form action="" method="POST" id="nextpageform">
<input type="hidden" id="pagenum" name="pagenum" value="">
<li class="mdui-list-item th">
<div class="mdui-col-sm-6 mdui-left mdui-text-left">
<!--PrePageStart-->
<a onclick="nextpage(<!--PrePageNum-->);" class="mdui-btn mdui-btn-raised"><!--constStr@PrePage--></a>
<!--PrePageEnd-->
<!--NextPageStart-->
<a onclick="nextpage(<!--NextPageNum-->);" class="mdui-btn mdui-btn-raised"><!--constStr@NextPage--></a>
<!--NextPageEnd-->
</div>
<div class="mdui-col-sm-6 mdui-right mdui-text-right">
<div class="mdui-right mdui-text-right"><span class="mdui-chip-title">Page: <!--MorePageListStart--><!--MorePageListEnd--><!--MorePageListNowStart--><!--PageNum--><!--MorePageListNowEnd-->/<!--MaxPageNum--></span></div>
</div>
</li>
</form>
<!--MorePageEnd-->
</ul>
</div>
</div>
@ -270,10 +289,18 @@
</div>
<!--FootomfEnd-->
</div>
<!--ShowThumbnailsStart-->
<a href="javascript:thumb();" class="mdui-fab mdui-fab-fixed mdui-ripple mdui-color-theme-accent"><i class="mdui-icon material-icons">format_list_bulleted</i></a>
<!--ShowThumbnailsEnd-->
<!--IsFolderEnd-->
<!--ListEnd-->
<script>
<!--MorePageStart-->
function nextpage(num) {
document.getElementById('pagenum').value=num;
document.getElementById('nextpageform').submit();
}
<!--MorePageEnd-->
$ = mdui.JQ;
$.fn.extend({
@ -314,7 +341,7 @@
a.click() // 模拟点击
a.remove();
}
<!--ShowThumbnailsStart-->
function thumb(){
if($('.mdui-fab i').text() == "apps"){
$('.mdui-fab i').text("format_list_bulleted");
@ -325,17 +352,17 @@
$('.mdui-fab i').text("apps");
$('.nexmoe-item').addClass('thumb');
$('.mdui-col-xs-12 i.mdui-icon').each(function(){
if($(this).text() == "image" || $(this).text() == "ondemand_video"){
var href = $(this).parent().parent().attr('href');
var thumb =(href.indexOf('?') == -1)?'?t=220':'&t=220';
if($(this).text() == "image"){
var thumbnails = $(this).parent().parent().attr('href');
thumbnails = thumbnails.substr(0, thumbnails.length-8)+'?thumbnails&location';
$(this).hide();
$(this).parent().parent().parent().css("background","url("+href+thumb+") no-repeat center top");
$(this).parent().parent().parent().css("background","url("+thumbnails+") no-repeat center top");
}
});
}
}
<!--ShowThumbnailsEnd-->
$(function(){
$('.file a').each(function(){
$(this).on('click', function () {

View File

@ -110,7 +110,9 @@
<a href="<!--PathArrayLink-->"><!--PathArrayName--></a>
<!--PathArrayEnd-->
<div class="mdui-toolbar-spacer"></div>
<!--ShowThumbnailsStart-->
<a href="javascript:thumb();" id="thumb" class="mdui-btn mdui-btn-icon" mdui-tooltip="{content: '切换显示'}"><i class="mdui-icon material-icons">format_list_bulleted</i></a>
<!--ShowThumbnailsEnd-->
</div>
</header>
@ -339,20 +341,24 @@
<!--FileListEnd-->
<!--MorePageStart-->
<form action="" method="POST" id="nextpageform">
<input type="hidden" id="pagenum" name="pagenum" value="">
<li class="mdui-list-item th">
<div class="mdui-col-sm-6 mdui-left mdui-text-left">
<!--PrePageStart-->
<a href="<?php echo preg_replace('/\/$/', '', "$root"); ?><?php e($path) ?>.page-<?php e($page-1) ?>/" class="mdui-btn mdui-btn-raised">上一页</a>
<a onclick="nextpage(<!--PrePageNum-->);" class="mdui-btn mdui-btn-raised"><!--constStr@PrePage--></a>
<!--PrePageEnd-->
<!--NextPageStart-->
<a href="<?php echo preg_replace('/\/$/', '', "$root"); ?><?php e($path) ?>.page-<?php e($page+1) ?>/" class="mdui-btn mdui-btn-raised">下一页</a>
<a onclick="nextpage(<!--NextPageNum-->);" class="mdui-btn mdui-btn-raised"><!--constStr@NextPage--></a>
<!--NextPageEnd-->
</div>
<div class="mdui-col-sm-6 mdui-right mdui-text-right">
<div class="mdui-right mdui-text-right"><span class="mdui-chip-title">Page: <?php e($page);?>/<?php e($totalpage);?></span></div>
</div>
</li>
<div class="mdui-right mdui-text-right"><span class="mdui-chip-title">Page: <!--MorePageListStart--><!--MorePageListEnd--><!--MorePageListNowStart--><!--PageNum--><!--MorePageListNowEnd-->/<!--MaxPageNum--></span></div>
</div>
</li>
</form>
<!--MorePageEnd-->
</ul>
</div>
</div>
@ -377,6 +383,12 @@
<script src="//cdn.jsdelivr.net/gh/mcstudios/glightbox/dist/js/glightbox.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script>
<script>
<!--MorePageStart-->
function nextpage(num) {
document.getElementById('pagenum').value=num;
document.getElementById('nextpageform').submit();
}
<!--MorePageEnd-->
var $$ = mdui.JQ;
$$(function() {
$$('.file .iframe').each(function() {
@ -493,7 +505,7 @@ function downall() {
a.click() // 模拟点击
a.remove();
}
<!--ShowThumbnailsStart-->
function thumb(){
if($('#thumb i').text() == "apps"){
$('#thumb i').text("format_list_bulleted");
@ -504,17 +516,20 @@ function thumb(){
$('#thumb i').text("apps");
$('.nexmoe-item').addClass('thumb');
$('.mdui-col-xs-12 i.mdui-icon').each(function(){
if($(this).text() == "image" || $(this).text() == "ondemand_video"){
var href = $(this).parent().parent().attr('href');
var thumb =(href.indexOf('?') == -1)?'?t=220':'&t=220';
//if($(this).text() == "image" || $(this).text() == "ondemand_video"){
if($(this).text() == "image"){
var thumbnails = $(this).parent().parent().attr('href');
//var thumb =(href.indexOf('?') == -1)?'?t=220':'&t=220';
thumbnails = thumbnails.substr(0, thumbnails.length-8)+'?thumbnails&location';
$(this).hide();
$(this).parent().parent().parent().css("background","url("+href+thumb+") no-repeat center top");
//$(this).parent().parent().parent().css("background","url("+href+thumb+") no-repeat center top");
$(this).parent().parent().parent().css("background","url("+thumbnails+") no-repeat center top");
}
});
}
}
}
<!--ShowThumbnailsEnd-->
$(function(){