1
0
mirror of https://github.com/misterunknown/ifm.git synced 2025-08-12 11:04:01 +02:00

Merge branch 'sane-coding-style' into v4.0

This commit is contained in:
Marco Dickert
2021-01-21 16:54:41 +01:00
10 changed files with 1114 additions and 1085 deletions

View File

@@ -16,14 +16,14 @@ define( "IFM_STANDALONE_GZ", "ifm.min.php" );
define( "IFM_LIB", "libifm.php" ); define( "IFM_LIB", "libifm.php" );
// php source files // php source files
$IFM_SRC_PHP = array( $IFM_SRC_PHP = [
0 => "src/main.php", 0 => "src/main.php",
1 => "src/ifmarchive.php", 1 => "src/ifmarchive.php",
2 => "src/htpasswd.php" 2 => "src/htpasswd.php"
); ];
// get options // get options
$options = getopt(null, array("language::", "languages::", "lang::", "cdn")); $options = getopt(null, ["language::", "languages::", "lang::", "cdn"]);
// build CDN version? // build CDN version?
if (isset($options['cdn'])) if (isset($options['cdn']))
@@ -36,6 +36,7 @@ $langs = [];
foreach ($options as $key => $value) foreach ($options as $key => $value)
if (substr($key, 0, 4) == "lang") if (substr($key, 0, 4) == "lang")
$langs = array_merge($langs, explode(",", $value)); $langs = array_merge($langs, explode(",", $value));
$langs = array_unique($langs); $langs = array_unique($langs);
if (!empty($langs)) { if (!empty($langs)) {
$vars['default_lang'] = ($langs[0] == "all") ? "en" : $langs[0]; $vars['default_lang'] = ($langs[0] == "all") ? "en" : $langs[0];
@@ -65,7 +66,7 @@ foreach ($langs as $l)
print "WARNING: Language file src/i18n/".$l.".json not found.\n"; print "WARNING: Language file src/i18n/".$l.".json not found.\n";
// Concat PHP Files // Concat PHP Files
$compiled = array( "<?php" ); $compiled = ["<?php"];
foreach ($IFM_SRC_PHP as $phpfile) { foreach ($IFM_SRC_PHP as $phpfile) {
$lines = file($phpfile); $lines = file($phpfile);
unset($lines[0]); // remove <?php line unset($lines[0]); // remove <?php line
@@ -73,11 +74,9 @@ foreach( $IFM_SRC_PHP as $phpfile ) {
} }
$compiled = join($compiled); $compiled = join($compiled);
if( IFM_CDN ) // Include assets
$IFM_ASSETS = "src/assets.cdn.part"; $compiled = str_replace("@@@ASSETS_CSS@@@", file_get_contents("src/assets".(IFM_CDN?".cdn":"").".css"), $compiled);
else $compiled = str_replace("@@@ASSETS_JS@@@", file_get_contents("src/assets".(IFM_CDN?".cdn":"").".js"), $compiled);
$IFM_ASSETS = "src/assets.part";
$compiled = str_replace( "IFM_ASSETS", file_get_contents("src/assets".(IFM_CDN?".cdn":"").".part"), $compiled );
// Process file includes // Process file includes
$includes = NULL; $includes = NULL;
@@ -108,9 +107,8 @@ foreach( $includes as $var )
$compiled = str_replace('IFM_VERSION', IFM_VERSION, $compiled); $compiled = str_replace('IFM_VERSION', IFM_VERSION, $compiled);
if (!is_dir(IFM_RELEASE_DIR)){ if (!is_dir(IFM_RELEASE_DIR))
mkdir(IFM_RELEASE_DIR); mkdir(IFM_RELEASE_DIR);
}
// build standalone ifm // build standalone ifm
file_put_contents(IFM_RELEASE_DIR . (IFM_CDN ? 'cdn.' : '') . IFM_STANDALONE, $compiled); file_put_contents(IFM_RELEASE_DIR . (IFM_CDN ? 'cdn.' : '') . IFM_STANDALONE, $compiled);

8
src/assets.cdn.css Normal file
View File

@@ -0,0 +1,8 @@
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/dt-1.10.20/datatables.min.css"/>
<style type="text/css">
@@@file:src/includes/bootstrap-treeview.min.css@@@
@@@file:src/includes/fontello-embedded.css@@@
@@@file:src/includes/animation.css@@@
@@@file:src/style.css@@@
</style>

15
src/assets.cdn.js Normal file
View File

@@ -0,0 +1,15 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.10.20/datatables.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.8/ace.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.3.2/mustache.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mouse0270-bootstrap-notify/3.1.7/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/classnames/2.2.6/index.min.js"></script>
<script>
@@@file:src/includes/bootstrap-treeview.min.js@@@
@@@file:src/includes/BootstrapMenu.min.js@@@
@@@file:src/ifm.js@@@
</script>

View File

@@ -1,31 +0,0 @@
public function getCSS() {
print '
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css" integrity="sha512-oc9+XSs1H243/FRN9Rw62Fn8EtxjEYWHXRvjS43YtueEewbS6ObfXcJNyohjHqVKFPoXXUxwc+q1K7Dee6vv9g==" crossorigin="anonymous"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/dt-1.10.22/r-2.2.6/datatables.min.css"/>
<style type="text/css">';?> @@@file:src/includes/bootstrap-treeview.min.css@@@ <?php print '</style>
<style type="text/css">';?> @@@file:src/includes/fontello-embedded.css@@@ <?php print '</style>
<style type="text/css">';?> @@@file:src/includes/animation.css@@@ <?php print '</style>
<style type="text/css">';?> @@@file:src/style.css@@@ <?php print '</style>
';
}
public function getJS() {
print '
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" integrity="sha512-uto9mlQzrs59VwILcLiRYeLKPPbS/bT71da/OEBYEwcdNUk8jYIy+D176RYoop1Da+f9mvkYrmj5MCLZWEtQuA==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.3/js/bootstrap.bundle.min.js" integrity="sha512-iceXjjbmB2rwoX93Ka6HAHP+B76IY1z0o3h+N1PeDtRSsyeetU3/0QKJqGyPJcX63zysNehggFwMC/bi7dvMig==" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.10.22/r-2.2.6/datatables.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.min.js" integrity="sha512-GoORoNnxst42zE3rYPj4bNBm0Q6ZRXKNH2D9nEmNvVF/z24ywVnijAWVi/09iBiVDQVf3UlZHpzhAJIdd9BXqw==" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.3.2/mustache.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mouse0270-bootstrap-notify/3.1.7/bootstrap-notify.min.js" integrity="sha512-BUaP7iu0aHqAISI8LphJT07Rv/MOiPI+mmq0h1rckNbzuKAW+UqmwEANqLPqanKNU331yApBM+40pZIkwkWAEQ==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js" integrity="sha512-90vH1Z83AJY9DmlWa8WkjkV79yfS2n2Oxhsi2dZbIv0nC4E6m5AbH8Nh156kkM7JePmqD6tcZsfad1ueoaovww==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/classnames/2.2.6/index.min.js" integrity="sha512-PMVw2HzV4gXtPe+BpvOQRQe9HtKcU4jA4N9ilRq+paTcz/ERKCt4d9hqXlslfsKOydknA4Y4JsiQexm/1W8zIA==" crossorigin="anonymous"></script>
';
echo <<<'f00bar'
<script>
@@@file:src/includes/bootstrap-treeview.min.js@@@
@@@file:src/includes/BootstrapMenu.min.js@@@
@@@file:src/ifm.js@@@
</script>
f00bar;
}

8
src/assets.css Normal file
View File

@@ -0,0 +1,8 @@
<style type="text/css">
@@@file:src/includes/bootstrap.min.css@@@
@@@file:src/includes/bootstrap-treeview.min.css@@@
@@@file:src/includes/datatables.min.css@@@
@@@file:src/includes/fontello-embedded.css@@@
@@@file:src/includes/animation.css@@@
@@@file:src/style.css@@@
</style>

16
src/assets.js Normal file
View File

@@ -0,0 +1,16 @@
<script>
@@@file:src/includes/jquery.min.js@@@
@@@file:src/includes/jquery-ui.min.js@@@
@@@file:src/includes/popper.min.js@@@
@@@file:src/includes/bootstrap.min.js@@@
@@@file:src/includes/bootstrap-notify.min.js@@@
@@@file:src/includes/bootstrap-treeview.min.js@@@
@@@file:src/includes/datatables.min.js@@@
@@@file:src/includes/lodash.min.js@@@
@@@file:src/includes/classnames.js@@@
@@@file:src/includes/BootstrapMenu.min.js@@@
@@@file:src/includes/mustache.min.js@@@
@@@file:src/includes/ace.js@@@
@@@acedir:src/includes/ace@@@
@@@file:src/ifm.js@@@
</script>

View File

@@ -1,30 +0,0 @@
public function getCSS() {
print '
<style type="text/css">';?> @@@file:src/includes/bootstrap.min.css@@@ <?php print '</style>
<style type="text/css">';?> @@@file:src/includes/bootstrap-treeview.min.css@@@ <?php print '</style>
<style type="text/css">';?> @@@file:src/includes/datatables.min.css@@@ <?php print '</style>
<style type="text/css">';?> @@@file:src/includes/fontello-embedded.css@@@ <?php print '</style>
<style type="text/css">';?> @@@file:src/includes/animation.css@@@ <?php print '</style>
<style type="text/css">';?> @@@file:src/style.css@@@ <?php print '</style>
';
}
public function getJS() {
echo <<<'f00bar'
<script>
@@@file:src/includes/jquery.min.js@@@
@@@file:src/includes/jquery-ui.min.js@@@
@@@file:src/includes/bootstrap.min.js@@@
@@@file:src/includes/bootstrap-notify.min.js@@@
@@@file:src/includes/bootstrap-treeview.min.js@@@
@@@file:src/includes/datatables.min.js@@@
@@@file:src/includes/lodash.min.js@@@
@@@file:src/includes/classnames.min.js@@@
@@@file:src/includes/BootstrapMenu.min.js@@@
@@@file:src/includes/mustache.min.js@@@
@@@file:src/includes/ace.min.js@@@
@@@acedir:src/includes/ace@@@
@@@file:src/ifm.js@@@
</script>
f00bar;
}

View File

@@ -105,10 +105,10 @@ function IFM(params) {
*/ */
this.rebuildFileTable = function( data ) { this.rebuildFileTable = function( data ) {
if( data.status == "ERROR" ) { if( data.status == "ERROR" ) {
this.showMessage( data.message, "e" ); self.showMessage( data.message, "e" );
return; return;
} else if ( ! Array.isArray( data ) ) { } else if ( ! Array.isArray( data ) ) {
this.showMessage( self.i18n.invalid_data, "e" ); self.showMessage( self.i18n.invalid_data, "e" );
return; return;
} }
data.forEach( function( item ) { data.forEach( function( item ) {
@@ -217,8 +217,8 @@ function IFM(params) {
if( self.datatable ) self.datatable.destroy(); if( self.datatable ) self.datatable.destroy();
self.datatable = $('#filetable').DataTable({ self.datatable = $('#filetable').DataTable({
paging: self.config.pagination, paging: !!self.config.paging,
pageLength: 50, pageLength: self.config.pageLength||50,
info: false, info: false,
autoWidth: false, autoWidth: false,
columnDefs: [ columnDefs: [
@@ -351,6 +351,38 @@ function IFM(params) {
self.copyToClipboard( link ); self.copyToClipboard( link );
} }
}, },
extract: {
name: self.i18n.extract,
onClick: function( data ) {
self.showExtractFileDialog( data.clicked.name );
},
iconClass: "icon icon-archive",
isShown: function( data ) {
return !!( self.config.extract && data.clicked.eaction == "extract" && !data.selected.length );
}
},
rename: {
name: self.i18n.rename,
onClick: function( data ) {
self.showRenameFileDialog( data.clicked.name );
},
iconClass: "icon icon-terminal",
isShown: function( data ) { return !!( self.config.rename && !data.selected.length && data.clicked.name != ".." ); }
},
copylink: {
name: self.i18n.copylink,
onClick: function( data ) {
if( data.clicked.link.toLowerCase().substr(0,4) == "http" )
self.copyToClipboard( data.clicked.link );
else {
var pathname = window.location.pathname.replace( /^\/*/g, '' ).split( '/' );
pathname.pop();
var link = self.pathCombine( window.location.origin, data.clicked.link )
if( pathname.length > 0 )
link = self.pathCombine( window.location.origin, pathname.join( '/' ), data.clicked.link )
self.copyToClipboard( link );
}
},
iconClass: "icon icon-link-ext", iconClass: "icon icon-link-ext",
isShown: function( data ) { return !!( !data.selected.length && data.clicked.name != ".." ); } isShown: function( data ) { return !!( !data.selected.length && data.clicked.name != ".." ); }
}, },
@@ -1842,7 +1874,7 @@ function IFM(params) {
success: function(d) { success: function(d) {
self.i18n = d; self.i18n = d;
self.log("I18N loaded"); self.log("I18N loaded");
self.initApplication(); self.initCheckAuth();
}, },
error: function() { error: function() {
throw new Error( self.i18n.load_text_error ); throw new Error( self.i18n.load_text_error );
@@ -1850,6 +1882,50 @@ function IFM(params) {
}); });
}; };
this.initCheckAuth = function() {
$.ajax({
url: self.api,
type: "POST",
data: {
api: "checkAuth"
},
dataType: "json",
success: function(d) {
if (d.status == "ERROR") {
self.showModal(Mustache.render(self.templates.login, {i18n: self.i18n}), {large: true});
var form = document.forms.loginForm;
form.addEventListener('click', function(e) {
if (e.target.id == "buttonLogin") {
$.ajax({
url: self.api,
type: "POST",
data: {
api: "checkAuth",
inputLogin: form.elements[0].value,
inputPassword: form.elements[1].value
},
dataType: "json",
success: function(e) {
self.hideModal();
self.initApplication();
},
error: function(e) {
self.showMessage("Authentication failed", "e");
}
});
}
});
} else {
self.initApplication();
}
},
error: function(resp) {
throw new Error("Not authenticated");
}
});
};
this.initApplication = function() { this.initApplication = function() {
self.rootElement.innerHTML = Mustache.render( self.rootElement.innerHTML = Mustache.render(
self.templates.app, self.templates.app,

File diff suppressed because it is too large Load Diff

View File

@@ -103,7 +103,7 @@ body {
} }
</style> </style>
<form class="form-signin" method="POST" action> <form id="loginForm" class="form-signin" method="post">
<div class="text-center mb-4"> <div class="text-center mb-4">
<h1 class="h3 mb-3 font-weight-normal">IFM {{i18n.login}}</h1> <h1 class="h3 mb-3 font-weight-normal">IFM {{i18n.login}}</h1>
</div> </div>
@@ -118,6 +118,6 @@ body {
</div> </div>
<div class="alert alert-danger d-none" role="alert"></div> <div class="alert alert-danger d-none" role="alert"></div>
<button class="btn btn-lg btn-primary btn-block" type="submit">{{i18n.login}}</button> <button id="buttonLogin" class="btn btn-lg btn-primary btn-block" type="submit">{{i18n.login}}</button>
</form> </form>