Go Back   Pligg Forum > Pligg Development > Pligg Mods
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-21-2007, 02:23 PM
revolver revolver is offline
Constant Pligger
 
Join Date: Oct 2006
Posts: 232
Downloads: 5
Uploads: 0
Thanks: 56
Thanked 22 Times in 18 Posts
Building modules 101

I've been digging around in existing modules trying to figure out how to build my own. Can someone give a quick explanation on how module_add_action_tpl and module_add_actionwork?

As far as i can tell init.php declares which pages should load the module (easy to understand) and if(do_we_load_module){} contains everything that should be done if the module is loaded (also easy to understand).

module_add_action_tpl() and module_add_action seems to insert custom templates and actions respectively. But how does pligg know where to insert the new code?
Reply With Quote
Sponsored Links
Check out the New Modules at the Pligg Pro Shop.
  #2 (permalink)  
Old 05-23-2007, 10:40 PM
cent's Avatar
cent cent is offline
Constant Pligger
 
Join Date: Jan 2007
Location: New York, NY
Posts: 183
Downloads: 20
Uploads: 5
Thanks: 24
Thanked 65 Times in 26 Posts
Hi Revolver,

Here's what I do know from playing around with it...

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.

Best,
Cent


Quote:
Originally Posted by revolver View Post
I've been digging around in existing modules trying to figure out how to build my own. Can someone give a quick explanation on how module_add_action_tpl and module_add_actionwork?

As far as i can tell init.php declares which pages should load the module (easy to understand) and if(do_we_load_module){} contains everything that should be done if the module is loaded (also easy to understand).

module_add_action_tpl() and module_add_action seems to insert custom templates and actions respectively. But how does pligg know where to insert the new code?
__________________
All of my modules are developed for free to help support the Pligg community. If you use or feel my modules were helpful to your site and want to thank me, please support the Pligg development team by donating.

Modules: Welcome Private Message (v0.1), Welcome Email (v0.1), Thickbox Module (v0.3), Image Upload (v1.0) & MP3 Upload Module (v0.9)
Reply With Quote
The Following 3 Users Say Thank You to cent For This Useful Post:
Reply



Thread Tools
Display Modes
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Similar Threads
Thread Thread Starter Forum Replies Last Post
Keeping sidebar modules hidden/expanded elquiosco General Help 1 10-13-2007 03:38 AM
New Sidebar Modules spartacus "Mollio-Beat" 1 04-22-2007 12:42 AM
Documents about developing modules shawntsai Pligg Mods 5 03-06-2007 05:10 AM
Installing all the modules in Pligg 9.0 Beta...and then where is the categories menu? leoperez Bug Report 2 01-16-2007 06:47 AM
A question about modules... aixelsyd Pligg Mods 7 12-06-2006 10:48 AM


LinkBacks Enabled by vBSEO 3.0.0