<?php
/**
 *  (c) 2025 BeCast
 * -------------------------------------
 * Filename: plugin.class.php
 * Purpose: Plugin Handling
 * CVS Header: $Header$
 * 
 * This program is free software; you can redistribute it and/or modify  
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; version 2 of the License.              
 * 
 * This program is distributed in the hope that it will be useful,      
 * but WITHOUT ANY WARRANTY; without even the implied warranty of       
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        
 * GNU General Public License for more details.                         
 * 
 * You should have received a copy of the GNU General Public License    
 * along with this program; if not, write to the Free Software          
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,                
 * MA  02111-1307  USA
 */
 
$module["module"]["name"]="Plugin Class";
$module["module"]["ver"]="0.1.1";
class plugins{
	
	var $hooks;
	var $current_hook;
	var $plugin_=array();
		
	function load_plugins($region='G'){
		global $config, $db;
		$result = $db->query("SELECT * FROM " . $config["prefix"] . "module");
		while ($row = $db->fetch_array($result)){
		    	$this->plugin_[$row["file"]] = $row;
			if($row["module"]=""){
				//$plugin="$
			}else{
			
			}
			//include_once();
		}

   	}
	
	function use_hook($name,$function,$order=20,$file="") {
		if(is_array($function)){
			$fname=serialize($function);
		}else{
			$fname=$function;
		}
			if(!empty($this->hooks[$name][$order][$fname]) && is_array($this->hooks[$name][$order][$fname])){
				return true;
			}
			
		$this->hooks[$name][$order][$fname] = array(
			"function" => $function,
			"file" => $file
		);
		return true;
	}
	
	
	function run_hook($name,$variables=array()) {
		if(array_key_exists($name,$this->hooks)){
			if(!is_array($this->hooks[$name]))
			{
				return false;
			}
			$this->current_hook = $name;
			ksort($this->hooks[$name]);
			foreach($this->hooks[$name] as $priority => $hooks)
			{
				if(is_array($hooks))
				{
					foreach($hooks as $hook)
					{
						if($hook['file'])
						{
							require_once $hook['file'];
						}
						if(!is_array($variables))
							$variables=array();

						$return = call_user_func_array($hook['function'], $variables);


					}
				}
			}
			$this->current_hook = '';
			return $return;
		}
	}


}
?>
