XOOPS module Sistemi
XOOPS module Sistemi, module işlevselliğini geliştirmek, kurmak, yönetmek ve genişletmek için eksiksiz bir çerçeve sağlar. modules, XOOPS’yi ek özellikler ve yeteneklerle genişleten bağımsız paketlerdir.
module Mimarisi
Section titled “module Mimarisi”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]module Yapısı
Section titled “module Yapısı”Standart XOOPS module dizin yapısı:
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/ # DocumentationXoopsModule Sınıfı
Section titled “XoopsModule Sınıfı”XoopsModule sınıfı, kurulu bir XOOPS modülünü temsil eder.
Sınıfa Genel Bakış
Section titled “Sınıfa Genel Bakış”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 = [];}Özellikler
Section titled “Özellikler”| Emlak | Tür | Açıklama |
|---|---|---|
$moduleid | int | Benzersiz module kimliği |
$name | dize | module görünen adı |
$dirname | dize | module dizini adı |
$version | dize | Mevcut module sürümü |
$description | dize | module açıklaması |
$config | dizi | module konfigürasyonu |
$blocks | dizi | module blokları |
$adminPages | dizi | Yönetici paneli sayfaları |
$userPages | dizi | Kullanıcıya yönelik sayfalar |
Yapıcı
Section titled “Yapıcı”public function __construct()Yeni bir module örneği oluşturur ve değişkenleri başlatır.
Temel Yöntemler
Section titled “Temel Yöntemler”getName
Section titled “getName”Modülün görünen adını alır.
public function getName(): stringDöndürür: string - module görünen adı
Örnek:
$module = new XoopsModule();$module->setVar('name', 'Publisher');echo $module->getName(); // "Publisher"getDirname
Section titled “getDirname”Modülün dizin adını alır.
public function getDirname(): stringDöndürür: string - module dizini adı
Örnek:
echo $module->getDirname(); // "publisher"Sürümü Al
Section titled “Sürümü Al”Geçerli module sürümünü alır.
public function getVersion(): stringDöndürür: string - Sürüm dizesi
Örnek:
echo $module->getVersion(); // "2.1.0"getDescription
Section titled “getDescription”module açıklamasını alır.
public function getDescription(): stringDöndürür: string - module açıklaması
Örnek:
$desc = $module->getDescription();getConfig
Section titled “getConfig”module yapılandırmasını alır.
public function getConfig(string $key = null): mixedParametreler:
| Parametre | Tür | Açıklama |
|---|---|---|
$key | dize | Yapılandırma anahtarı (hepsi için boş) |
Döndürür: mixed - Yapılandırma değeri veya dizisi
Örnek:
$config = $module->getConfig();$itemsPerPage = $module->getConfig('items_per_page');setConfig
Section titled “setConfig”module yapılandırmasını ayarlar.
public function setConfig(string $key, mixed $value): voidParametreler:
| Parametre | Tür | Açıklama |
|---|---|---|
$key | dize | Yapılandırma anahtarı |
$value | karışık | Yapılandırma değeri |
Örnek:
$module->setConfig('items_per_page', 20);$module->setConfig('enable_cache', true);GetPath
Section titled “GetPath”Modülün tam dosya sistemi yolunu alır.
public function getPath(): stringDöndürür: string - Mutlak module dizin yolu
Örnek:
$path = $module->getPath(); // "/var/www/xoops/modules/publisher"$classPath = $module->getPath() . '/class';getUrl
Section titled “getUrl”URL’yi modüle alır.
public function getUrl(): stringGeri döndürür: string - module URL
Örnek:
$url = $module->getUrl(); // "http://example.com/modules/publisher"module Kurulum Süreci
Section titled “module Kurulum Süreci”xoops_module_install İşlev
Section titled “xoops_module_install İşlev”xoops_version.php’de tanımlanan module kurulum işlevi:
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}Parametreler:
| Parametre | Tür | Açıklama |
|---|---|---|
$module | XoopsModule | Kurulan module |
Döndürür: bool - Başarı durumunda doğru, başarısızlık durumunda yanlış
Örnek:
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;}xoops_module_uninstall İşlev
Section titled “xoops_module_uninstall İşlev”module kaldırma işlevi:
function xoops_module_uninstall_modulename($module){ // Drop database tables // Remove uploaded files // Clean up configuration
return true;}Örnek:
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;}module Kancaları
Section titled “module Kancaları”module kancaları, modüllerin diğer modüllerle ve sistemle entegre olmasını sağlar.
Kanca Bildirgesi
Section titled “Kanca Bildirgesi”xoops_version.php’de:
$modversion['hooks'] = [ 'system.page.footer' => [ 'function' => 'publisher_page_footer' ], 'user.profile.view' => [ 'function' => 'publisher_user_articles' ],];Kanca Uygulaması
Section titled “Kanca Uygulaması”// 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;}Mevcut Sistem Kancaları
Section titled “Mevcut Sistem Kancaları”| Kanca | Parametreler | Açıklama |
|---|---|---|
system.page.header | Yok | Sayfa başlığı çıktısı |
system.page.footer | Yok | Sayfa altbilgisi çıktısı |
user.login.success | $user nesnesi | user oturum açtıktan sonra |
user.logout | $user nesnesi | user oturumu kapattıktan sonra |
user.profile.view | $user_id | user profili görüntüleniyor |
module.install | $module nesnesi | module kurulumu |
module.uninstall | $module nesnesi | module kaldırma |
module Yöneticisi Hizmeti
Section titled “module Yöneticisi Hizmeti”ModuleManager hizmeti module işlemlerini yönetir.
Yöntemler
Section titled “Yöntemler”getModule
Section titled “getModule”Bir modülü ada göre alır.
public function getModule(string $dirname): ?XoopsModuleParametreler:
| Parametre | Tür | Açıklama |
|---|---|---|
$dirname | dize | module dizini adı |
Döndürür: ?XoopsModule - module örneği veya boş
Örnek:
$moduleManager = $kernel->getService('module');$publisher = $moduleManager->getModule('publisher');if ($publisher) { echo $publisher->getName();}getAllModules
Section titled “getAllModules”Kurulu tüm modülleri alır.
public function getAllModules(bool $activeOnly = true): arrayParametreler:
| Parametre | Tür | Açıklama |
|---|---|---|
$activeOnly | bool | Yalnızca etkin modülleri döndür |
Döndürür: array - XoopsModule nesnelerinin dizisi
Örnek:
$activeModules = $moduleManager->getAllModules(true);foreach ($activeModules as $module) { echo $module->getName() . " - " . $module->getVersion() . "\n";}isModuleActive
Section titled “isModuleActive”Bir modülün aktif olup olmadığını kontrol eder.
public function isModuleActive(string $dirname): boolÖrnek:
if ($moduleManager->isModuleActive('publisher')) { // Publisher module is active}activeModule
Section titled “activeModule”Bir modülü etkinleştirir.
public function activateModule(string $dirname): boolÖrnek:
if ($moduleManager->activateModule('publisher')) { echo "Publisher activated";}deactivateModule
Section titled “deactivateModule”Bir modülü devre dışı bırakır.
public function deactivateModule(string $dirname): boolÖrnek:
if ($moduleManager->deactivateModule('publisher')) { echo "Publisher deactivated";}module Yapılandırması (xoops_version.php)
Section titled “module Yapılandırması (xoops_version.php)”Tam module manifest örneği:
<?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;}En İyi Uygulamalar
Section titled “En İyi Uygulamalar”-
Sınıflarınızın Ad Alanı - Çakışmaları önlemek için modüle özgü ad alanlarını kullanın
-
İşleyicileri Kullan - database işlemleri için her zaman işleyici sınıflarını kullanın
-
İçeriği Uluslararasılaştırın - Kullanıcıya yönelik tüm dizeler için dil sabitlerini kullanın
-
Kurulum Komut Dosyaları Oluşturun - database tabloları için SQL şemaları sağlayın
-
Belge Kancaları - Modülünüzün hangi kancaları sağladığını açıkça belgeleyin
-
Modülünüzün Sürümünü Oluşturun - Sürüm numaralarını sürümlerle birlikte artırın
-
Test Kurulumu - install/uninstall işlemlerini kapsamlı bir şekilde test edin
-
İzinleri Yönetme - Eylemlere izin vermeden önce user izinlerini kontrol edin
Tam module Örneği
Section titled “Tam module Örneği”<?php/** * Custom Article Module Main Page */
include __DIR__ . '/include/common.inc.php';
// Get module instance$module = xoops_getModuleByDirname('mymodule');
// Check if module is activeif (!$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');İlgili Belgeler
Section titled “İlgili Belgeler”- ../Kernel/Kernel-Classes - Core başlatma ve temel hizmetler
- ../Template/Template-System - module şablonları ve theme entegrasyonu
- ../Database/QueryBuilder - database sorgusu oluşturma
- ../Core/XoopsObject - Temel nesne sınıfı
Ayrıca bakınız: XOOPS module Geliştirme Kılavuzu