דלגו לתוכן

XOOPS מערכת מודול

מערכת המודולים XOOPS מספקת מסגרת מלאה לפיתוח, התקנה, ניהול והרחבת פונקציונליות המודול. מודולים הם חבילות עצמאיות המרחיבות XOOPS עם תכונות ויכולות נוספות.

graph TD
A[Module Package] -->|contains| B[xoops_version.php]
A -->|contains| C[Admin Interface]
A -->|contains| D[User Interface]
A -->|contains| E[Class Files]
A -->|contains| F[SQL Schema]
B -->|defines| G[Module Metadata]
B -->|defines| H[Admin Pages]
B -->|defines| I[User Pages]
B -->|defines| J[Blocks]
B -->|defines| K[Hooks]
L[Module Manager] -->|reads| B
L -->|controls| M[Installation]
L -->|controls| N[Activation]
L -->|controls| O[Update]
L -->|controls| P[Uninstallation]

מבנה ספריות מודול XOOPS סטנדרטי:

mymodule/
├── xoops_version.php # Module manifest and configuration
├── admin.php # Admin main page
├── index.php # User main page
├── admin/ # Admin pages directory
│ ├── main.php
│ ├── manage.php
│ └── settings.php
├── class/ # Module classes
│ ├── Handler/
│ │ ├── ItemHandler.php
│ │ └── CategoryHandler.php
│ └── Objects/
│ ├── Item.php
│ └── Category.php
├── sql/ # Database schemas
│ ├── mysql.sql
│ └── postgres.sql
├── include/ # Include files
│ ├── common.inc.php
│ └── functions.php
├── templates/ # Module templates
│ ├── admin/
│ │ └── main.tpl
│ └── user/
│ ├── index.tpl
│ └── item.tpl
├── blocks/ # Module blocks
│ └── blocks.php
├── tests/ # Unit tests
├── language/ # Language files
│ ├── english/
│ │ └── main.php
│ └── spanish/
│ └── main.php
└── docs/ # Documentation

המחלקה XoopsModule מייצגת מודול XOOPS מותקן.

namespace Xoops\Core\Module;
class XoopsModule extends XoopsObject
{
protected int $moduleid = 0;
protected string $name = '';
protected string $dirname = '';
protected string $version = '';
protected string $description = '';
protected array $config = [];
protected array $blocks = [];
protected array $adminPages = [];
protected array $userPages = [];
}
נכסהקלדתיאור
$moduleidintמזהה מודול ייחודי
$nameמחרוזתשם תצוגה של מודול
$dirnameמחרוזתשם ספריית מודול
$versionמחרוזתגרסת המודול הנוכחית
$descriptionמחרוזתתיאור מודול
$configמערךתצורת מודול
$blocksמערךבלוקים מודולים
$adminPagesמערךדפי פאנל ניהול
$userPagesמערךדפים הפונים למשתמש
public function __construct()

יוצר מופע מודול חדש ומאתחל משתנים.

מקבל את שם התצוגה של המודול.

public function getName(): string

החזרות: string - שם תצוגת מודול

דוגמה:

$module = new XoopsModule();
$module->setVar('name', 'Publisher');
echo $module->getName(); // "Publisher"

מקבל את שם הספרייה של המודול.

public function getDirname(): string

החזרות: string - שם ספריית המודול

דוגמה:

echo $module->getDirname(); // "publisher"

מקבל את גרסת המודול הנוכחית.

public function getVersion(): string

החזרות: string - מחרוזת גרסה

דוגמה:

echo $module->getVersion(); // "2.1.0"

מקבל את תיאור המודול.

public function getDescription(): string

החזרות: string - תיאור המודול

דוגמה:

$desc = $module->getDescription();

מאחזר את תצורת המודול.

public function getConfig(string $key = null): mixed

פרמטרים:

פרמטרהקלדתיאור
$keyמחרוזתמפתח תצורה (null עבור כולם)

החזרות: mixed - ערך תצורה או מערך

דוגמה:

$config = $module->getConfig();
$itemsPerPage = $module->getConfig('items_per_page');

מגדיר את תצורת המודול.

public function setConfig(string $key, mixed $value): void

פרמטרים:

פרמטרהקלדתיאור
$keyמחרוזתמפתח תצורה
$valueמעורבערך תצורה

דוּגמָה:

$module->setConfig('items_per_page', 20);
$module->setConfig('enable_cache', true);

מקבל את הנתיב המלא של מערכת הקבצים למודול.

public function getPath(): string

החזרות: string - נתיב ספריית מודול מוחלט

דוגמה:

$path = $module->getPath(); // "/var/www/xoops/modules/publisher"
$classPath = $module->getPath() . '/class';

מקבל את URL למודול.

public function getUrl(): string

החזרות: string - מודול URL

דוגמה:

$url = $module->getUrl(); // "http://example.com/modules/publisher"

פונקציית התקנת המודול שהוגדרה ב-xoops_version.php:

function xoops_module_install_modulename($module)
{
// $module is an XoopsModule instance
// Create database tables
// Initialize default configuration
// Create default folders
// Set up file permissions
return true; // Success
}

פרמטרים:

פרמטרהקלדתיאור
$moduleXoopsModuleהמודול המותקן

החזרות: bool - נכון על הצלחה, לא נכון על כישלון

דוגמה:

function xoops_module_install_publisher($module)
{
// Get module path
$modulePath = $module->getPath();
// Create uploads directory
$uploadsPath = XOOPS_ROOT_PATH . '/uploads/publisher';
if (!is_dir($uploadsPath)) {
mkdir($uploadsPath, 0755, true);
}
// Get database connection
global $xoopsDB;
// Execute SQL installation script
$sqlFile = $modulePath . '/sql/mysql.sql';
if (file_exists($sqlFile)) {
$sqlQueries = file_get_contents($sqlFile);
// Execute queries (simplified)
$xoopsDB->queryFromFile($sqlFile);
}
// Set default configuration
$module->setConfig('items_per_page', 10);
$module->setConfig('enable_comments', true);
return true;
}

פונקציית הסרת ההתקנה של המודול:

function xoops_module_uninstall_modulename($module)
{
// Drop database tables
// Remove uploaded files
// Clean up configuration
return true;
}

דוּגמָה:

function xoops_module_uninstall_publisher($module)
{
global $xoopsDB;
// Drop tables
$tables = ['publisher_items', 'publisher_categories', 'publisher_comments'];
foreach ($tables as $table) {
$xoopsDB->query('DROP TABLE IF EXISTS ' . $xoopsDB->prefix($table));
}
// Remove upload folder
$uploadsPath = XOOPS_ROOT_PATH . '/uploads/publisher';
if (is_dir($uploadsPath)) {
// Recursive directory deletion
$this->recursiveRemoveDir($uploadsPath);
}
return true;
}

ווי מודולים מאפשרים למודולים להשתלב עם מודולים אחרים והמערכת.

ב-xoops_version.php:

$modversion['hooks'] = [
'system.page.footer' => [
'function' => 'publisher_page_footer'
],
'user.profile.view' => [
'function' => 'publisher_user_articles'
],
];
// In a module file (e.g., include/hooks.php)
function publisher_page_footer()
{
// Return HTML for footer
return '<div class="publisher-footer">Publisher Footer Content</div>';
}
function publisher_user_articles($user_id)
{
global $xoopsDB;
// Get user's articles
$result = $xoopsDB->query(
'SELECT * FROM ' . $xoopsDB->prefix('publisher_articles') .
' WHERE author_id = ? ORDER BY published DESC LIMIT 5',
[$user_id]
);
$articles = [];
while ($row = $xoopsDB->fetchAssoc($result)) {
$articles[] = $row;
}
return $articles;
}
הוקפרמטריםתיאור
system.page.headerאיןפלט כותרת עמוד
system.page.footerאיןפלט כותרת תחתונה של עמוד
user.login.success$user חפץלאחר התחברות משתמש
user.logout$user חפץלאחר התנתק משתמש
user.profile.view$user_idצופה בפרופיל משתמש
module.install$module חפץהתקנת מודול
module.uninstall$module חפץהסרת מודול

שירות ModuleManager מטפל בפעולות מודול.

מאחזר מודול לפי שם.

public function getModule(string $dirname): ?XoopsModule

פרמטרים:

פרמטרהקלדתיאור
$dirnameמחרוזתשם ספריית מודול

החזרות: ?XoopsModule - מופע מודול או null

דוגמה:

$moduleManager = $kernel->getService('module');
$publisher = $moduleManager->getModule('publisher');
if ($publisher) {
echo $publisher->getName();
}

מקבל את כל המודולים המותקנים.

public function getAllModules(bool $activeOnly = true): array

פרמטרים:

פרמטרהקלדתיאור
$activeOnlyboolהחזר רק מודולים פעילים

החזרות: array - מערך של XoopsModule אובייקטים

דוגמה:

$activeModules = $moduleManager->getAllModules(true);
foreach ($activeModules as $module) {
echo $module->getName() . " - " . $module->getVersion() . "\n";
}

בודק אם מודול פעיל.

public function isModuleActive(string $dirname): bool

דוּגמָה:

if ($moduleManager->isModuleActive('publisher')) {
// Publisher module is active
}

מפעיל מודול.

public function activateModule(string $dirname): bool

דוּגמָה:

if ($moduleManager->activateModule('publisher')) {
echo "Publisher activated";
}

מבטל מודול.

public function deactivateModule(string $dirname): bool

דוּגמָה:

if ($moduleManager->deactivateModule('publisher')) {
echo "Publisher deactivated";
}

דוגמה של מניפסט מודול מלא:

<?php
/**
* Module manifest for Publisher
*/
$modversion = [
'name' => 'Publisher',
'version' => '2.1.0',
'description' => 'Professional content publishing module',
'author' => 'XOOPS Community',
'credits' => 'Based on original work by...',
'license' => 'GPL v2',
'official' => 1,
'image' => 'images/logo.png',
'dirname' => 'publisher',
'onInstall' => 'xoops_module_install_publisher',
'onUpdate' => 'xoops_module_update_publisher',
'onUninstall' => 'xoops_module_uninstall_publisher',
// Admin pages
'hasAdmin' => 1,
'adminindex' => 'admin/main.php',
'adminmenu' => [
[
'title' => 'Dashboard',
'link' => 'admin/main.php',
'icon' => 'dashboard.png'
],
[
'title' => 'Manage Items',
'link' => 'admin/items.php',
'icon' => 'items.png'
],
[
'title' => 'Settings',
'link' => 'admin/settings.php',
'icon' => 'settings.png'
]
],
// User pages
'hasMain' => 1,
'main_file' => 'index.php',
// Blocks
'blocks' => [
[
'file' => 'blocks/recent.php',
'name' => 'Recent Articles',
'description' => 'Display recent published articles',
'show_func' => 'publisher_recent_show',
'edit_func' => 'publisher_recent_edit',
'options' => '5|0|0',
'template' => 'publisher_block_recent.tpl'
],
[
'file' => 'blocks/featured.php',
'name' => 'Featured Articles',
'description' => 'Display featured articles',
'show_func' => 'publisher_featured_show',
'edit_func' => 'publisher_featured_edit'
]
],
// Module hooks
'hooks' => [
'system.page.footer' => [
'function' => 'publisher_page_footer'
],
'user.profile.view' => [
'function' => 'publisher_user_articles'
]
],
// Configuration items
'config' => [
[
'name' => 'items_per_page',
'title' => '_MI_PUBLISHER_ITEMS_PER_PAGE',
'description' => '_MI_PUBLISHER_ITEMS_PER_PAGE_DESC',
'formtype' => 'text',
'valuetype' => 'int',
'default' => '10'
],
[
'name' => 'enable_comments',
'title' => '_MI_PUBLISHER_ENABLE_COMMENTS',
'description' => '_MI_PUBLISHER_ENABLE_COMMENTS_DESC',
'formtype' => 'yesno',
'valuetype' => 'int',
'default' => '1'
]
]
];
function xoops_module_install_publisher($module)
{
// Installation logic
return true;
}
function xoops_module_update_publisher($module)
{
// Update logic
return true;
}
function xoops_module_uninstall_publisher($module)
{
// Uninstallation logic
return true;
}
  1. מרחב שמות הכיתות שלך - השתמש במרחבי שמות ספציפיים למודול כדי למנוע התנגשויות

  2. השתמש במטפלים - השתמש תמיד במחלקות מטפל לפעולות מסד נתונים

  3. אינטרנציונל תוכן - השתמש בקבועי שפה עבור כל המחרוזות הפונות למשתמש

  4. צור סקריפטים להתקנה - ספק SQL סכימות עבור טבלאות מסד נתונים

  5. הוקסים למסמכים - תיעד בבירור אילו ווים המודול שלך מספק

  6. גרסת המודול שלך - הגדל מספרי גרסאות עם מהדורות

  7. התקנה בדיקה - בדוק היטב תהליכים install/uninstall

  8. הרשאות טיפול - בדוק את הרשאות המשתמש לפני שמתירים פעולות

<?php
/**
* Custom Article Module Main Page
*/
include __DIR__ . '/include/common.inc.php';
// Get module instance
$module = xoops_getModuleByDirname('mymodule');
// Check if module is active
if (!$module) {
die('Module not found');
}
// Get module configuration
$itemsPerPage = $module->getConfig('items_per_page');
// Get item handler
$itemHandler = xoops_getModuleHandler('item', 'mymodule');
// Fetch items with pagination
$criteria = new CriteriaCompo();
$criteria->add(new Criteria('status', 1));
$items = $itemHandler->getObjects($criteria, $itemsPerPage);
// Prepare template
$xoopsTpl->assign('items', $items);
$xoopsTpl->assign('module_name', $module->getName());
$xoopsTpl->display($module->getPath() . '/templates/user/index.tpl');
  • ../Kernel/Kernel-Classes - אתחול ליבה ושירותי ליבה
  • ../Template/Template-System - תבניות מודול ושילוב ערכות נושא
  • ../Database/QueryBuilder - בניית שאילתות מסד נתונים
  • ../Core/XoopsObject - מחלקת אובייקט בסיס

ראה גם: XOOPS מדריך לפיתוח מודול