Replacement for the Events handler to included a function/method handler as well for the events hooking stratums as well as by design to include preloads in theme as well the following class preloads.php need to be changed to so:~
class/preloads.php class XoopsPreload
{
/**
* @var array $_preloads array containing information about the event observers
*/
var $_preloads = array();
/**
* @var array $_routines array containing the events that are being observed
*/
var $_routines = array();
/**
* Constructor
*
* @return void
*/
function XoopsPreload()
{
$this->setPreloads();
$this->setEvents();
}
/**
* Allow one instance only!
*
* @return object
*/
static function &getInstance()
{
static $instance = false;
if (!$instance) {
$instance = new XoopsPreload();
}
return $instance;
}
/**
* Get available preloads information and set them to go!
*
* @return void
*/
function setPreloads()
{
//$modules_list = XoopsLists::getDirListAsArray(XOOPS_ROOT_PATH . "/modules/");
if ($modules_list = XoopsCache::read('system_modules_active')) {
$i = 0;
foreach ($modules_list as $module) {
if (is_dir($dir = XOOPS_ROOT_PATH . "/modules/{$module}/preloads/")) {
$file_list = XoopsLists::getFileListAsArray($dir);
foreach ($file_list as $file) {
if (preg_match('/(.php)$/i', $file)) {
$file = substr($file, 0, -4);
$this->_preloads[$i]['module'] = $module;
$this->_preloads[$i]['file'] = $file;
$i++;
}
}
}
}
if (isset($GLOBALS["xoopsConfig"]['theme_set']))
{
$theme = $GLOBALS["xoopsConfig"]['theme_set'];
if (is_dir($dir = XOOPS_ROOT_PATH . "/themes/{$theme}/preloads/")) {
$file_list = XoopsLists::getFileListAsArray($dir);
foreach ($file_list as $file) {
if (preg_match('/(.php)$/i', $file)) {
$file = substr($file, 0, -4);
$this->_preloads[$i]['theme'] = $theme;
$this->_preloads[$i]['file'] = $file;
$i++;
}
}
}
}
}
}
/**
* Get available events and set them to go!
*
* @return void
*/
function setEvents()
{
foreach ($this->_preloads as $preload) {
if (isset($preload['module']))
{
include_once XOOPS_ROOT_PATH . '/modules/' . $preload['module'] . '/preloads/' . $preload['file']. '.php';
$class_name = ucfirst($preload['module']) . ucfirst($preload['file']) . 'Preload' ;
if (!class_exists($class_name)) {
continue;
}
} elseif (isset($preload['theme'])) {
include_once XOOPS_ROOT_PATH . '/themes/' . $preload['theme'] . '/preloads/' . $preload['file']. '.php';
$class_name = ucfirst($preload['theme']) . ucfirst($preload['file']) . 'Preload' ;
if (!class_exists($class_name)) {
continue;
}
}
$class_methods = get_class_methods($class_name);
foreach ($class_methods as $method) {
if (strpos($method, 'event') === 0) {
$event_name = strtolower(str_replace('event', '', $method));
$event= array('class_name' => $class_name, 'method' => $method);
$this->_routines[$event_name][] = $event;
}
}
}
}
/**
* Triggers a specific event
*
* @param $event_name string Name of the event to trigger
* @param $args array Method arguments
*
* @return void
*/
function triggerEvent($event_name, $args = array())
{
$event_name = strtolower(str_replace('.', '', $event_name));
if (isset($this->_routines[$event_name])) {
foreach ($this->_routines[$event_name] as $event) {
try {
call_user_func(array($event['class_name'], $event['method']), $args);
}
catch(Exception $err)
{
trigger_error("Preload Event Hooking Error: ".$event['class_name']."::".$event['method'] . " ~ $err", E_RECOVERABLE_ERROR);
}
}
}
}
/**
* Triggers a specific function or method with variable of return
*
* @param $event_name string Name of the event to trigger
* @param $args array Method arguments
*
* @return void
*/
function triggerMethod($method_name = '', $dbtable = 'default', $arga = NULL, $argb = NULL, $argc = NULL, $argd = NULL, $arge = NULL, $argf = NULL, $argg = NULL, $argh = NULL, $argj = NULL)
{
if (!is_null($argj))
$args = "j";
elseif (!is_null($argh) && is_null($argj))
$args = "h";
elseif (!is_null($argg) && is_null($argh))
$args = "g";
elseif (!is_null($argf) && is_null($argg))
$args = "f";
elseif (!is_null($arge) && is_null($argf))
$args = "e";
elseif (!is_null($argd) && is_null($arge))
$args = "d";
elseif (!is_null($argc) && is_null($argd))
$args = "c";
elseif (!is_null($argb) && is_null($argc))
$args = "b";
elseif (!is_null($arga) && is_null($argb))
$args = "a";
else
$args = "-";
$method_name = strtolower(str_replace('.', '', $method_name));
if (isset($this->_routines[$method_name])) {
foreach ($this->_routines[$method_name] as $event) {
try {
switch ($args)
{
case "j":
return call_user_func(array($event['class_name'], $event['method']), $dbtable, $arga, $argb, $argc, $argd, $arge, $argf, $argg, $arge, $argj);
break;
case "h":
return call_user_func(array($event['class_name'], $event['method']), $dbtable, $arga, $argb, $argc, $argd, $arge, $argf, $argg, $argh);
break;
case "g":
return call_user_func(array($event['class_name'], $event['method']), $dbtable, $arga, $argb, $argc, $argd, $arge, $argf, $argg);
break;
case "f":
return call_user_func(array($event['class_name'], $event['method']), $dbtable, $arga, $argb, $argc, $argd, $arge, $argf);
break;
case "e":
return call_user_func(array($event['class_name'], $event['method']), $dbtable, $arga, $argb, $argc, $argd, $arge);
break;
case "d":
return call_user_func(array($event['class_name'], $event['method']), $dbtable, $arga, $argb, $argc, $argd);
break;
case "c":
return call_user_func(array($event['class_name'], $event['method']), $dbtable, $arga, $argb, $argc);
break;
case "b":
return call_user_func(array($event['class_name'], $event['method']), $dbtable, $arga, $argb);
break;
case "a":
return call_user_func(array($event['class_name'], $event['method']), $dbtable, $arga);
break;
default:
return call_user_func(array($event['class_name'], $event['method']), $dbtable);
break;
}
}
catch(Exception $err)
{
trigger_error("Preload Function Hooking Error: ".$event['class_name']."::".$event['method'] . " ~ $err", E_RECOVERABLE_ERROR);
}
}
}
}
}
This lists' the changes to the
XoopsPreload that need to be made!!