Create Pligg Modules

November 5, 2007 by hejian

Pligg’s Module system is a pluggable architecture to extend Pligg functionality. Every module has these files (xxx is module name):

templates/ : custom html files.
xxx.css
xxx_init.php : the main controller for your module.
xxx_install.php
xxx_main.php : functions you can use elsewhere in your module.
xxx_readme.htm : a readme file that gets linked from the list of modules page.
xxx_settings.php : defined variables.

xxx_init.php

<?php
if(defined('mnminclude')){
include_once('xxx_settings.php');
$include_in_pages = array('index', 'user', 'upcoming', 'topstories', 'story', 'search', 'live', 'cloud', 'topusers');
$do_not_include_in_pages = array();
if( do_we_load_module() ) {
module_add_action('action1', 'xxx_func1', '');
module_add_action('action2', 'xxx_func2', '');
module_add_action_tpl('tpl_action1', xxx_tpl_path . 'xxx_file1.tpl');
module_add_action_tpl('tpl_action2', xxx_tpl_path . 'xxx_file2.tpl');
module_add_css(my_pligg_base . '/modules/xxx/xxx.css');
include_once(mnmmodules . 'xxx/xxx_main.php');
}
}
?>

xxx_func1 and xxx_func2 are callback functions implemented in xxx_main.php.
xxx_file1.tpl and xxx_file2.tpl are custom html file.

Actions
The module_add_actions are essentially setting callbacks for various actions already in the Pligg code, these actions are:

upcoming.php: upcoming_top
upcoming.php: index_top
user.php: user_post_views
libs/html1.php: do_sidebar
libs/link.php: lib_link_summary_fill_smarty
libs/login.php: logout_success
libs/smartyvariables.php: all_pages_top
admin_users.php: admin_users_view
admin_users.php: admin_users_edit
admin_users.php: admin_users_save
index.php: index_top
login.php: login_success_pre_redirect
module.php: module_page
profile.php: profile_show
profile.php: profile_save
register.php: register_success_pre_redirect
search.php: search_top

TPL Actions
The module_add_action_tpl is a great way to insert custom html code into an already existing template. These place are:

admin_templates/admin_main_center.tpl: tpl_header_admin_main_links
admin_templates/user_edit_center.tpl: tpl_admin_user_edit_center_fields
admin_templates/user_show_center.tpl: tpl_admin_user_show_center_fields
footer.tpl: tpl_footer
header.tpl: tpl_sidebar_logged_in_just_below_profile  
header.tpl: tpl_banner_location_main
link_summary.tpl: tpl_link_summary_pre_story_content
link_summary.tpl: tpl_link_summary_end
login_center.tpl: tpl_login_top
login_center.tpl: tpl_login_bottom
pligg.tpl: tpl_pligg_pre_title_thickbox
pligg.tpl: tpl_pligg_pre_title_lightbox
pligg.tpl: tpl_pligg_above_center
pligg.tpl: tpl_pligg_below_center
profile_center.tpl: tpl_profile_center_fields
sidebar.tpl: tpl_sidebar_top
submit_step_2.tpl: submit_step_2_pre_extrafields
user_center.tpl: tpl_user_center_just_below_header
user_center.tpl: tpl_user_center

xxx_install.php

<?php
$module_info['name'] = ‘The Module Name’;
$module_info['desc'] = ‘This is module descriptions.’;
$module_info['version'] = 0.1;
$module_info['requires'][] = array(’lightbox’, 0.1);
?>

Leave a Reply

You must be logged in to post a comment.

Wordpress template made by HeJian