hey chco,
here is a pointer for what an Enumerator is used for with XOOPS, in the 'action' field in this log.php from xortify for the log runs plugins in the /plugins folder of Xortify..
if (!defined('XOOPS_ROOT_PATH')) {
exit();
}
/**
* Class for Blue Room Xortify Log
* @author Simon Roberts
* @copyright copyright (c) 2009-2003 XOOPS.org
* @package kernel
*/
class XortifyLog extends XoopsObject
{
function XortifyLog($id = null)
{
$this->initVar('lid', XOBJ_DTYPE_INT, null, false);
$this->initVar('uid', XOBJ_DTYPE_INT, null, false);
$this->initVar('uname', XOBJ_DTYPE_TXTBOX, false, false, 64);
$this->initVar('email', XOBJ_DTYPE_TXTBOX, false, false, 255);
$this->initVar('ip4', XOBJ_DTYPE_TXTBOX, false, false, 15);
$this->initVar('ip6', XOBJ_DTYPE_TXTBOX, false, false, 128);
$this->initVar('proxy-ip4', XOBJ_DTYPE_TXTBOX, false, false, 15);
$this->initVar('proxy-ip6', XOBJ_DTYPE_TXTBOX, false, false, 128);
$this->initVar('network-addy', XOBJ_DTYPE_TXTBOX, false, false, 255);
$this->initVar('provider', XOBJ_DTYPE_TXTBOX, false, false, 128);
$this->initVar('agent', XOBJ_DTYPE_TXTBOX, false, false, 255);
$this->initVar('extra', XOBJ_DTYPE_OTHER, false, false);
$this->initVar('date', XOBJ_DTYPE_INT, null, false);
$this->initVar('action', XOBJ_DTYPE_ENUM, 'monitored', false, false, false, array('banned', 'blocked', 'monitored'));
}
function toArray() {
$ret = parent::toArray();
$ret['date_datetime'] = date(_DATESTRING, $this->getVar('date'));
$ret['action'] = ucfirst($this->getVar('action'));
foreach($ret as $key => $value)
$ret[str_replace('-', '_', $key)] = $value;
return $ret;
}
function runPrePlugin($default = true) {
include_once($GLOBALS['xoops']->path('/modules/xortify/plugin/'.$this->getVar('provider').'.php'));
switch ($this->getVar('action')) {
case 'banned':
case 'blocked':
case 'monitored':
$func = ucfirst($this->getVar('action')).'PreHook';
break;
default:
return $default;
break;
}
if (function_exists($func)) {
return @$func($default, $this);
}
return $default;
}
function runPostPlugin($lid) {
include_once($GLOBALS['xoops']->path('/modules/xortify/plugin/'.$this->getVar('provider').'.php'));
switch ($this->getVar('action')) {
case 'banned':
case 'blocked':
case 'monitored':
$func = ucfirst($this->getVar('action')).'PostHook';
break;
default:
return $lid;
break;
}
if (function_exists($func)) {
return @$func($this);
}
return $lid;
}
}
/**
* XOOPS Xortify Log handler class.
* This class is responsible for providing data access mechanisms to the data source
* of XOOPS user class objects.
*
* @author Simon Roberts
* @package kernel
*/
class XortifyLogHandler extends XoopsPersistableObjectHandler
{
function __construct(&$db)
{
$this->db = $db;
parent::__construct($db, 'xortify_log', 'XortifyLog', "lid", "network-addy");
}
function insert($object, $force = true) {
$module_handler = xoops_gethandler('module');
$config_handler = xoops_gethandler('config');
$xoModule = $module_handler->getByDirname('xortify');
$xoConfig = $config_handler->getConfigList($xoModule->getVar('mid'));
$criteria = new Criteria('`date`', time()-$xoConfig['logdrops'], '<=');
$this->deleteAll($criteria, true);
if ($object->isNew()) {
$object->setVar('date', time());
}
$run_plugin_action=false;
if ($obj->vars['action']['changed']==true) {
$run_plugin_action=true;
}
if ($run_plugin_action){
if ($object->runPrePlugin($xoConfig['save_'.$object->getVar('action')])==true)
$lid = parent::insert($object, $force);
else
return false;
} else
$lid = parent::insert($object, $force);
if ($run_plugin_action)
return $object->runPostPlugin($lid);
else
return $lid;
}
}
?>
In the function
XortifyLogHandler::insert($object, $force) the following detection using the $this->vars[] of the XoopsObject allows for it to be checked if it changes then calls the plugin in the following code.
if ($obj->vars['action']['changed']==true) {
$run_plugin_action=true;
}
// then further down when the insert has been done so the object is complete.
if ($run_plugin_action){
if ($object->runPrePlugin($xoConfig['save_'.$object->getVar('action')])==true)
$lid = parent::insert($object, $force);
else
return false;
} else
$lid = parent::insert($object, $force);
if ($run_plugin_action)
return $object->runPostPlugin($lid);
else
return $lid;