<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.installer.php
 * Type:     Check Updates
 * Name:     Installer
 * Owner:	 Michael Ruhl
 * -------------------------------------------------------------
 */
 
function smarty_function_installer($params, &$smarty)
{

	include_once(BASE_DIR ."/functions/Func.Installer.php");
	
	if(!isset($_SESSION['addons']))
	{
		$addons = array();
		
		$ordner = BASE_DIR . "/addons/";
		{ 
		$handle = opendir($ordner); 
		while ($file = readdir ($handle)) { 
				if($file{0} != '.') {
						if(is_dir($ordner.'/'.$file)) { 
								$folderArray[] = $file; 
						} 
				} 
		} 
		closedir($handle); 
	
		if(isset($folderArray)) { 
				asort($folderArray); 
				foreach($folderArray as $row) { 
					unset($folderArray2);
					if(is_file(BASE_DIR . "/addons/" . $row . "/addon.". $row .".php")) array_push($addons, $row);
				} 
			} 
		}
		
		$_SESSION['addons'] = implode(",", $addons);

	}
	else $addons = explode(",", $_SESSION['addons']);

	foreach($addons as $add)
	{

		include(BASE_DIR . "/addons/" . $add . "/addon.". $add .".php");
		
		if(isset($modul['pcode']) and !isset($_SESSION[$modul['pcode']]))
		{
			@$xml = file_get_contents("http://www.koobi-erweiterungen.de/updates/".$modul['pcode'] ."/");
			@$build = str_replace(" ", "", strip_content(preg_replace("/(.*?)<build>(.*?)<\/build>(.*?)/is", "\\2", $xml)));
					
			if($build > $modul['Build']) $num = $num + 1;
	
		}	
		
		$_SESSION[$modul['pcode']] = 1;
		
	} 
		
	$num != "" ? $return = "(".$num.")" : $return = "";
    return $return;
}

?>

