Writing Plugins

amFM is open source, so you may edit and redistribute the code as you please, but if you are planning to add features yourself, I recommend using plugins. I recommend this for several reasons: Firstly, if you change the source code of amFM and later want to install a newer version from my website, you will have to re-edit the new version each time. That gets tedious. Secondly, by writing plugins, a single code base can be maintained for the file manager itself while still allowing it to function in different environments. Thirdly, if you write plugins, I can publish them here and others can benefit from your contributions.

Plugins can be written in PHP and Javascript. PHP plugins are included at the start of the page generation so that your functions are available during the entire process. Javascript plugins are included at the end of the page generation so that your functions can overwrite existing functions.

PHP Override Functions

Include these methods in your plugin to override the standard (empty) authentication methods. These methods are override only, so you cannot have multiple authentication plugins.

has_access_override()
	returns true if the user has permission to use the file manager
	present version simply returns true
authentication_succeeded_override()
	called if the user has permission to use the file manager
	present version simply returns true and loads the file manager
authentication_failed_override()
	called if the user does not have permission to use the file manager
	present version sends an "HTTP/1.1 403 Forbidden" page

PHP Hooks:

There are currently 5 hooks written into amFM. To use a hook, simply write a PHP method with the same name as the hook and preface it with the name of the file it is located in. For example, to utilize the 'document_end' hook in a plugin named 'myplugin.php', the method name should be 'myplugin_document_end'. Unlike override methods, hooks can be used by multiple plugins.

presetup()
	called at the beginning of the setup() function
postsetup()
	called at the end of the setup() function
document_start()
	called just before the first HTML tags are printed
buttons()
	called after all buttons have been added to the left toolbar
document_end()
	called just before the end of the page

Javascript Plugins

You can overwrite any method with a Javascript plugin. For example, the 'select()' method does nothing by alert the user which file is currently highlighted... which is pretty useless. This method is designed to be overwritten so that amFM can mesh with your website. For example, the 'fck.js' plugin overwrites the 'select()' method and passes the current file's url to FCK Editor's image chooser.