From 0ccd4223e8cd8b94afba9c7c9a44930bb470ce5e Mon Sep 17 00:00:00 2001 From: Marco Dickert Date: Fri, 23 Feb 2018 15:33:47 +0100 Subject: [PATCH] Enable edit function only for text files, not binary etc. Related to #90 --- build/libifm.php | 3 ++- ifm.php | 3 ++- src/ifm.js | 2 +- src/main.php | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/build/libifm.php b/build/libifm.php index 1db68b7..d1307ff 100644 --- a/build/libifm.php +++ b/build/libifm.php @@ -1565,7 +1565,7 @@ function IFM( params ) { icon: "icon icon-archive", title: "extract" }); - } else if( self.config.edit && item.icon.indexOf( 'file-image' ) == -1 && ! self.inArray( item.ext, ["zip","tar","tgz","tar.gz","tar.xz","tar.bz2"] ) ) { + } else if( self.config.edit && item.mime_type.substr( 0, 4 ) == "text" ) { item.eaction = "edit"; item.button.push({ action: "edit", @@ -3367,6 +3367,7 @@ function IFM( params ) { $type = substr( strrchr( $name, "." ), 1 ); $item["icon"] = $this->getTypeIcon( $type ); $item["ext"] = strtolower($type); + $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['showfilesize'] == 1 ) { diff --git a/ifm.php b/ifm.php index 151aa3b..cabe41a 100644 --- a/ifm.php +++ b/ifm.php @@ -1565,7 +1565,7 @@ function IFM( params ) { icon: "icon icon-archive", title: "extract" }); - } else if( self.config.edit && item.icon.indexOf( 'file-image' ) == -1 && ! self.inArray( item.ext, ["zip","tar","tgz","tar.gz","tar.xz","tar.bz2"] ) ) { + } else if( self.config.edit && item.mime_type.substr( 0, 4 ) == "text" ) { item.eaction = "edit"; item.button.push({ action: "edit", @@ -3367,6 +3367,7 @@ function IFM( params ) { $type = substr( strrchr( $name, "." ), 1 ); $item["icon"] = $this->getTypeIcon( $type ); $item["ext"] = strtolower($type); + $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['showfilesize'] == 1 ) { diff --git a/src/ifm.js b/src/ifm.js index 59e3a19..778123a 100644 --- a/src/ifm.js +++ b/src/ifm.js @@ -145,7 +145,7 @@ function IFM( params ) { icon: "icon icon-archive", title: "extract" }); - } else if( self.config.edit && item.icon.indexOf( 'file-image' ) == -1 && ! self.inArray( item.ext, ["zip","tar","tgz","tar.gz","tar.xz","tar.bz2"] ) ) { + } else if( self.config.edit && item.mime_type.substr( 0, 4 ) == "text" ) { item.eaction = "edit"; item.button.push({ action: "edit", diff --git a/src/main.php b/src/main.php index 11a418a..772741c 100644 --- a/src/main.php +++ b/src/main.php @@ -356,6 +356,7 @@ f00bar; $type = substr( strrchr( $name, "." ), 1 ); $item["icon"] = $this->getTypeIcon( $type ); $item["ext"] = strtolower($type); + $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['showfilesize'] == 1 ) {