View Single Post
  #2  

Building Modules

Modules
  Next Chapter »

Credit to Cent for this information:

modulename_init.php


- loads the modulename_settings.php file which has all of the definitions.
- include_in_pages is an array with all of the pagename(s) the module should work in.
- do_not_include_in_pages is an array of pagename(s) the module should not work in. include_in_pages can be ('all') and do_not_include_in_pages can be ('submit') which makes life pretty easy.
- module_add_action('external_name', 'internal_function_name', 'variables')... whereas external_name is the name placed in .tpl files such as check_actions('external_name'). internal_function_name is the name of the php function that should be triggered in the modulename_main.php file.
- include_once(mnmodules . "moduledirectory/modulename_main.php) just loads all of the PHP functions for the module.

modulename_install.php

- module_info['name'] is the name of the module for the module manager
- module_info['desc'] is the description
- module_info['version'] is the version number
- [i]module_info['requires'][] is an array of any dependent modules required (pass/fail)

modulename_main.php

There are PHP functions which are called, when needed, from various templates. You will need to declare globals for certain variables that you will need access to outside of the function like $db (for the database), $smarty and $main_smarty (for smarty variables -- to set or retrieve values) and any other variables as well like $linkres (if needed).

modulename_readme.htm

The module's readme file. I've been trying to make them easier to understand and with step by step instructions for installation and configuration.

modulename_settings.php

Here is where you define all of your module's variables.

- define('modulename_path', '') - path to your module
- define('modulename_plugins_path', '') - path to plugins your module uses (if necessary)

There is also a section called if(is_object($main_smarty)) which allows you to send variable definitions back to smarty. I used them in the imageupload module, but I dont actually use them. However, I can see how they could be pretty powerful as it allows you to send back variables called set from within the module itself.

That's pretty much all I know. I believe module_add_action_tpl would in some way allow you to include say an HTML form within a template. Like, I believe I could have used it to automatically include the "Select JPG file" file attachment using the module instead of having to use enable_extra_fields. This would allow people to turn off the module, and essentially turn off the ability to upload image file with an entry. As it stands now, if you turn off the module, the form fields are still present even though they don't actually do anything.

Modules
  Next Chapter »

Contributors: Yankidank
Created by Yankidank, 09-22-2007 at 04:55 PM
Last edited by Yankidank, 09-22-2007 at 04:55 PM
1 Comments , 1298 Views