From 6a521d4b989c2c683c3c6301fd1a97221be92da6 Mon Sep 17 00:00:00 2001 From: Marco Dickert Date: Mon, 10 Dec 2018 13:24:22 +0100 Subject: [PATCH] misterunknown/ifm: Fixed sorting by last modified date. Closes #105 --- build/libifm.php | 20 ++++++++++++++++---- ifm.php | 20 ++++++++++++++++---- src/ifm.js | 12 ++++++++++++ src/main.php | 2 +- src/templates/filetable.html | 2 +- 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/build/libifm.php b/build/libifm.php index da63afd..b289987 100644 --- a/build/libifm.php +++ b/build/libifm.php @@ -290,7 +290,7 @@ f00bar; {{/config.download}} {{#config.showlastmodified}} - {{lastmodified}} + {{lastmodified_hr}} {{/config.showlastmodified}} {{#config.showfilesize}} {{size}} @@ -1560,6 +1560,7 @@ function IFM( params ) { item.download = {}; item.download.name = ( item.name == ".." ) ? "." : item.name; item.download.currentDir = self.currentDir; + item.lastmodified_hr = self.formatDate( item.lastmodified ); if( self.config.isDocroot ) item.link = self.hrefEncode( self.pathCombine( self.currentDir, item.name ) ); if( ! self.config.chmod ) @@ -2710,6 +2711,17 @@ function IFM( params ) { return false; }; + /** + * Formats a date from an unix timestamp + * + * @param {integer} timestamp - UNIX timestamp + */ + this.formatDate = function( timestamp ) { + var d = new Date( timestamp * 1000 ); + + return d.toLocaleString(); + }; + this.getNodeFromString = function( s ) { var template = document.createElement( 'template'); template.innerHTML = s; @@ -2727,10 +2739,10 @@ function IFM( params ) { const el = document.createElement('textarea'); el.value = str; el.setAttribute('readonly', ''); - el.style.position = 'absolute'; + el.style.position = 'absolute'; el.style.left = '-9999px'; document.body.appendChild(el); - const selected = + const selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false; @@ -3480,7 +3492,7 @@ f00bar; if( !$this->config['disable_mime_detection'] ) $item["mime_type"] = mime_content_type( $name ); } - if( $this->config['showlastmodified'] == 1 ) { $item["lastmodified"] = date( "d.m.Y, G:i e", filemtime( $name ) ); } + if( $this->config['showlastmodified'] == 1 ) { $item["lastmodified"] = filemtime( $name ); } if( $this->config['showfilesize'] == 1 ) { if( $item['type'] == "dir" ) { $item['size_raw'] = 0; diff --git a/ifm.php b/ifm.php index c732016..2878a00 100644 --- a/ifm.php +++ b/ifm.php @@ -290,7 +290,7 @@ f00bar; {{/config.download}} {{#config.showlastmodified}} - {{lastmodified}} + {{lastmodified_hr}} {{/config.showlastmodified}} {{#config.showfilesize}} {{size}} @@ -1560,6 +1560,7 @@ function IFM( params ) { item.download = {}; item.download.name = ( item.name == ".." ) ? "." : item.name; item.download.currentDir = self.currentDir; + item.lastmodified_hr = self.formatDate( item.lastmodified ); if( self.config.isDocroot ) item.link = self.hrefEncode( self.pathCombine( self.currentDir, item.name ) ); if( ! self.config.chmod ) @@ -2710,6 +2711,17 @@ function IFM( params ) { return false; }; + /** + * Formats a date from an unix timestamp + * + * @param {integer} timestamp - UNIX timestamp + */ + this.formatDate = function( timestamp ) { + var d = new Date( timestamp * 1000 ); + + return d.toLocaleString(); + }; + this.getNodeFromString = function( s ) { var template = document.createElement( 'template'); template.innerHTML = s; @@ -2727,10 +2739,10 @@ function IFM( params ) { const el = document.createElement('textarea'); el.value = str; el.setAttribute('readonly', ''); - el.style.position = 'absolute'; + el.style.position = 'absolute'; el.style.left = '-9999px'; document.body.appendChild(el); - const selected = + const selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false; @@ -3480,7 +3492,7 @@ f00bar; if( !$this->config['disable_mime_detection'] ) $item["mime_type"] = mime_content_type( $name ); } - if( $this->config['showlastmodified'] == 1 ) { $item["lastmodified"] = date( "d.m.Y, G:i e", filemtime( $name ) ); } + if( $this->config['showlastmodified'] == 1 ) { $item["lastmodified"] = filemtime( $name ); } if( $this->config['showfilesize'] == 1 ) { if( $item['type'] == "dir" ) { $item['size_raw'] = 0; diff --git a/src/ifm.js b/src/ifm.js index f9b49a9..46ca2ca 100644 --- a/src/ifm.js +++ b/src/ifm.js @@ -116,6 +116,7 @@ function IFM( params ) { item.download = {}; item.download.name = ( item.name == ".." ) ? "." : item.name; item.download.currentDir = self.currentDir; + item.lastmodified_hr = self.formatDate( item.lastmodified ); if( self.config.isDocroot ) item.link = self.hrefEncode( self.pathCombine( self.currentDir, item.name ) ); if( ! self.config.chmod ) @@ -1266,6 +1267,17 @@ function IFM( params ) { return false; }; + /** + * Formats a date from an unix timestamp + * + * @param {integer} timestamp - UNIX timestamp + */ + this.formatDate = function( timestamp ) { + var d = new Date( timestamp * 1000 ); + + return d.toLocaleString(); + }; + this.getNodeFromString = function( s ) { var template = document.createElement( 'template'); template.innerHTML = s; diff --git a/src/main.php b/src/main.php index 59f7eb0..48b6863 100644 --- a/src/main.php +++ b/src/main.php @@ -372,7 +372,7 @@ f00bar; if( !$this->config['disable_mime_detection'] ) $item["mime_type"] = mime_content_type( $name ); } - if( $this->config['showlastmodified'] == 1 ) { $item["lastmodified"] = date( "d.m.Y, G:i e", filemtime( $name ) ); } + if( $this->config['showlastmodified'] == 1 ) { $item["lastmodified"] = filemtime( $name ); } if( $this->config['showfilesize'] == 1 ) { if( $item['type'] == "dir" ) { $item['size_raw'] = 0; diff --git a/src/templates/filetable.html b/src/templates/filetable.html index ddc5b7f..3e453f0 100644 --- a/src/templates/filetable.html +++ b/src/templates/filetable.html @@ -25,7 +25,7 @@ {{/config.download}} {{#config.showlastmodified}} - {{lastmodified}} + {{lastmodified_hr}} {{/config.showlastmodified}} {{#config.showfilesize}} {{size}}