XOOPS 2.0.x Series¶
Legacy documentation for XOOPS 2.0.x (2003-2005).
⚠️ Legacy Notice¶
This documentation is for historical reference only. XOOPS 2.0.x is no longer supported. For current development, see Core Concepts.
Overview¶
XOOPS 2.0 was a complete rewrite that introduced many foundational concepts still used today:
- Smarty Template Engine: First integration of Smarty for theming
- Module System: Self-contained modules with blocks
- Object-Oriented Design: PHP 4 OOP patterns
- Database Abstraction: XoopsDatabase layer
Architecture¶
graph TB
subgraph "XOOPS 2.0 Architecture"
A[mainfile.php] --> B[include/common.php]
B --> C[class/xoopsload.php]
C --> D[XoopsDatabase]
C --> E[XoopsSecurity]
C --> F[XoopsModule]
D --> G[MySQL Connection]
F --> H[Module Classes]
H --> I[Smarty Templates]
end Key Classes¶
XoopsObject (2.0 Style)¶
<?php
// XOOPS 2.0.x style class definition
// Note: This is legacy code pattern
class MyObject extends XoopsObject
{
function MyObject() // PHP 4 constructor
{
$this->XoopsObject();
$this->initVar('id', XOBJ_DTYPE_INT, null, false);
$this->initVar('title', XOBJ_DTYPE_TXTBOX, '', true, 255);
$this->initVar('content', XOBJ_DTYPE_TXTAREA, '', false);
}
}
class MyObjectHandler extends XoopsObjectHandler
{
function &create($isNew = true)
{
$obj = new MyObject();
if ($isNew) {
$obj->setNew();
}
return $obj;
}
function &get($id)
{
$id = intval($id);
if ($id > 0) {
$sql = "SELECT * FROM " . $this->db->prefix('mytable') . " WHERE id=" . $id;
if ($result = $this->db->query($sql)) {
if ($this->db->getRowsNum($result) == 1) {
$obj = new MyObject();
$obj->assignVars($this->db->fetchArray($result));
return $obj;
}
}
}
return false;
}
}
Module Structure (2.0)¶
modules/mymodule/
├── admin/
│ ├── index.php
│ └── menu.php
├── class/
│ └── myclass.php
├── include/
│ ├── functions.php
│ └── search.inc.php
├── language/
│ └── english/
│ ├── main.php
│ └── modinfo.php
├── sql/
│ └── mysql.sql
├── templates/
│ └── mymodule_index.html
├── blocks/
│ └── myblock.php
├── index.php
├── header.php
└── xoops_version.php
Database Queries (2.0 Style)¶
<?php
// Direct database queries - legacy pattern
global $xoopsDB;
$sql = sprintf(
"SELECT * FROM %s WHERE status = %d ORDER BY created DESC",
$xoopsDB->prefix('mytable'),
1
);
$result = $xoopsDB->query($sql);
while ($row = $xoopsDB->fetchArray($result)) {
echo $row['title'] . "<br>";
}
// Count
$sql = sprintf(
"SELECT COUNT(*) FROM %s WHERE active = 1",
$xoopsDB->prefix('mytable')
);
list($count) = $xoopsDB->fetchRow($xoopsDB->query($sql));
Template Syntax (Smarty 2.x)¶
{* XOOPS 2.0 template syntax *}
<{if $items|@count > 0}>
<ul>
<{section name=i loop=$items}>
<li><{$items[i].title}></li>
<{/section}>
</ul>
<{else}>
<p>No items found.</p>
<{/if}>
Breaking Changes from 2.0 to 2.5¶
| Feature | 2.0.x | 2.5.x |
|---|---|---|
| PHP Constructor | function ClassName() | function __construct() |
| Reference Returns | function &get() | function get() |
| Global Variables | Required | Discouraged |
| Namespaces | None | XoopsModules\ |
| Autoloading | Manual includes | PSR-4 |
Migration Notes¶
If maintaining a 2.0.x module, consider these upgrades:
- Constructor: Change to
__construct() - References: Remove
&from return types - Globals: Use dependency injection or handlers
- SQL: Use prepared statements
- Templates: Update to Smarty 3 syntax
See: Migration Guide