<?php
// $Id: functions.php,v 1.1 2006/07/15 13:18:59 ohwada Exp $

// 2006-07-10 K.OHWADA
// this is new file
// porting from rssc_get_handler.php

//=========================================================
// Happy Linux Framework Module
// 2006-07-10 K.OHWADA
//=========================================================

function &happy_linux_get_handler($name=null, $module_dir=null, $prefix='happy_linux')
{
	static $handlers;

// if $module_dir is not specified
	if (!isset($module_dir)) 
	{
//if a module is loaded
		if ( isset($GLOBALS['xoopsModule']) && is_object($GLOBALS['xoopsModule']) )
		{
			$module_dir = $GLOBALS['xoopsModule']->getVar('dirname');
		}
		else 
		{
			trigger_error('No Module is loaded', E_USER_ERROR);
		}
	}
	else 
	{
		$module_dir = trim($module_dir);
	}

	$name = (!isset($name)) ? $module_dir : trim($name);

	if (!isset($handlers[$module_dir][$name])) 
	{
		$class = $prefix.'_'.$name.'_handler';
		$file  = XOOPS_ROOT_PATH.'/modules/'.$module_dir.'/class/'.$class.'.php';

		if ( file_exists($file) )
		{
			include_once $file;
		}

		if ( class_exists($class) ) 
		{
			$handlers[$module_dir][$name] = new $class( $module_dir );
		}
	}

	if ( isset($handlers[$module_dir][$name]) ) 
	{
		$han =& $handlers[$module_dir][$name];
		return $han;
	}
	else
	{
		$msg = 'Handler does not exist<br />Module: '.$module_dir.'<br />Name: '.$name.'<br />Prefix: '.$prefix.'<br />';
		trigger_error($msg, E_USER_ERROR);
//		echo $msg;
	}

	return false;
}

?>