Skip to content
Stenio Elson edited this page Oct 4, 2019 · 5 revisions

introduction

The source code of the IFM is a bit different from other projects you might know. Historically I developed it literally in one single file. As this became very confusing, I splitted the parts up into the src directory and searched for a nice way to compile it into a single file in the end. Other single-file script solutions, like Adminer, use custom compilers for their scripts, so I decided to do it in a similar way.

compiler

The compiler script is written in PHP and assembles all the source files into one single script. The following tasks are part of the process:

  • concat PHP files while removing the first line (<?php)
  • insert all file includes
  • insert all variable includes (languages)
  • add snippet to start the IFM

Includes can be made by putting the filename enclosed by three at signs (@@@) anywhere in the code.

The compiler updates the following files:

  • ifm.php (standalone IFM)
  • build/libifm.php (IFM library for the use in other projects)

files

Here is a short explanation of what does what:

  • src/htpasswd.php: htpasswd class for authentication
  • src/i18n/*: language files
  • src/ifmarchive.php: archive class used by the IFM
  • src/ifm.js: IFM client application, written in JS
  • src/includes/*: external sources like bootstrap, jquery, ace etc.
  • src/main.php: IFM class, core of the IFM
  • src/style.css: some custom css
  • src/templates/*: mustache templates

example

After you checked out the IFM, you can compile the script like this:

./compiler.php --language=en,de

advanced topics

compressed build

I experimented with compressing the IFM code to minimize the filesize. This worked, but was not quite fancy. If you have a very small webspace where every megabyte counts, you can build a compressed version. This is slightly less performant, as the server has to unzip the script with every request you do. To build the compressed version, just uncomment the following lines in the compiler:

/* // build compressed ifm
file_put_contents(
        IFM_STANDALONE_GZ,
        '<?php eval( gzdecode( file_get_contents( __FILE__, false, null, 85 ) ) ); exit(0); ?>'
        . gzencode( file_get_contents( "ifm.php", false, null, 5 ) )
);
*/

Why isn't this enabled by default? Simply because there are very few use cases and no one wants to execute code which he cannot inspect.