Creating Modules
SLAED CMS is built on a modular architecture where each module represents separate functionality. This guide will walk you through creating custom modules for your SLAED CMS installation.
Table of Contents
Module System Overview
SLAED CMS modules can be activated, deactivated, and configured independently:
Module Principles
- Independence - Each module works autonomously
- Standardization - Unified API for all modules
- Security - Own access rights for each module
- Scalability - Ability to add new modules
Module Structure
modules/module_name/
├── index.php # Main module file
├── admin/ # Administrative interface
│ └── index.php
└── language/ # Language files
├── lang-english.php
├── lang-russian.php
└── lang-german.php
Standard Modules
SLAED CMS comes with essential modules:
Module | Description | Features |
---|---|---|
News | News publishing system | Categories, comments, RSS |
Pages | Static content | Hierarchical structure, editor |
Forum | Discussion system | Threading, moderation, PM |
Shop | E-commerce | Products, orders, payments |
Media | Gallery | Images, videos, slideshows |
Developing Custom Modules
To create a custom module:
- Create module directory:
/modules/my_module/
- Create main file:
index.php
- Add language files in
language/
directory - Create admin interface in
admin/index.php
- Register module in database
Main Module File
<?php
if (!defined('MODULE_FILE')) die('Illegal file access');
// Include language file
get_lang('my_module');
// Include configuration
include('config/config_my_module.php');
// Check if module is active
if (!is_active('my_module')) {
head();
echo setTemplateBasic('title', array('{%title%}' => _MODULE_DISABLED));
foot();
exit;
}
// Main module logic
$op = getVar('req', 'op', 'var');
switch($op) {
case 'view':
view_item();
break;
default:
show_main();
break;
}
function show_main() {
head();
echo '<h1>My Module</h1>';
echo '<p>Module content...</p>';
foot();
}
function view_item() {
$id = getVar('req', 'id', 'num');
head();
echo '<h1>View Item '.$id.'</h1>';
foot();
}
?>
Language File
<?php
if (!defined('FUNC_FILE')) die('Illegal file access');
define('_MY_MODULE_TITLE', 'My Module');
define('_MY_MODULE_DESCRIPTION', 'Module description');
define('_MY_MODULE_ADD', 'Add');
define('_MY_MODULE_EDIT', 'Edit');
define('_MY_MODULE_DELETE', 'Delete');
?>
Admin Interface
<?php
if (!defined('ADMIN_FILE')) die('Illegal file access');
// Check admin rights
if (!is_moder('my_module')) {
admin_access_denied();
exit;
}
$op = getVar('req', 'op', 'var');
switch($op) {
case 'add':
admin_add_item();
break;
case 'edit':
admin_edit_item();
break;
default:
admin_main();
break;
}
?>
Module API
Key module functions:
// Check module activity
function is_active($module, $view = '1') {
global $db, $prefix;
list($active) = $db->sql_fetchrow(
$db->sql_query("SELECT active FROM {$prefix}_modules WHERE title='{$module}'")
);
return ($active == $view);
}
// Get module configuration
function get_module_config($module) {
include("config/config_{$module}.php");
return $conf;
}
// Check module admin rights
function is_module_admin($module) {
return is_moder($module);
}
Module Registration
After creating a module, register it in the database:
INSERT INTO {prefix}_modules (
title, description, active, view, blocks, blocks_c, mod_group
) VALUES (
'my_module', 'Module description', 1, 0, 1, 1, 0
);
Module Configuration
Each module has its configuration file /config/config_module.php
:
<?php
if (!defined('FUNC_FILE')) die('Illegal file access');
$conf_module = array(
'items_per_page' => '10', // Items per page
'allow_comments' => '1', // Allow comments
'moderation' => '0', // Pre-moderation
'rss_enable' => '1', // RSS feed
'seo_urls' => '1', // SEO URLs
'upload_enable' => '1', // File uploads
'rating_enable' => '1', // Rating system
);
?>
Integration with Core
Using system functions:
// Database operations
global $db, $prefix;
$result = $db->sql_query("SELECT * FROM {$prefix}_my_table");
// User authentication
if (is_user()) {
// Code for authenticated users
}
// Template usage
echo setTemplateBasic('title', array('{%title%}' => $title));
// Getting variables
$id = getVar('req', 'id', 'num');
$text = getVar('post', 'text', 'html');
// File uploads
upload_file('image', 'uploads/my_module/', array('jpg', 'png'));