<?
if (isset($_GET['l']) && $_GET['l']=='')exit;

include_once "../SYSTEM/include/pclzip.lib.php";
include_once "../SYSTEM/include/mp3.php";
include_once "../SYSTEM/include/functions.php";
include_once "../SYSTEM/include/mysql.php";
include_once "../SYSTEM/include/param.php";
include_once "../SYSTEM/include/sess.php";
if (ereg("\.\.\/",$_GET['l']))
{
ban_ip($ip,3600,'Попытка взлома З-Ц');
header("Location: ".BASEDIR."banip.php?".SID."");
exit;
}

$lll=$_GET['l'];
$lll=ereg_replace("(/){1,}$","",$lll);
$lll=ereg_replace("(/){1,}","/",$lll);
$lll=ereg_replace("^(/){1,}","",$lll);

$l=$folder_level.$set['loaddir']."/$lll";

if (!eregi("\.jar$",$l))exit;
if (!is_file($l))exit;


$zip=new PclZip($l);
$content = $zip->extract(PCLZIP_OPT_BY_NAME, "META-INF/MANIFEST.MF" ,PCLZIP_OPT_EXTRACT_AS_STRING);


if (ereg("MIDlet-Icon: ",$content[0]['content']))
{
$jad=explode("MIDlet-Icon: ",$content[0]['content']);
$icon=str_replace("\n"," ", $jad[1]);
$icon=str_replace("\r"," ", $icon);
$icon=strtok($icon,' ');
$icon=ereg_replace("^/","", $icon);
}
else $icon='icon.png';




$content = $zip->extract(PCLZIP_OPT_BY_NAME, "$icon",PCLZIP_OPT_EXTRACT_AS_STRING);
if (!isset($content[0]['content']) || $content[0]['content']=='')exit;
$j=fopen("../SYSTEM/temp/$sess.png", 'w');
fwrite($j, $content[0]['content']);
fclose($j);
@chmod("../SYSTEM/temp/$sess.png", 0777);


$size = GetImageSize("../SYSTEM/temp/$sess.png"); 
$width = $size[0]; 
$height = $size[1]; 




$x_ratio = 16 / $width; 
$y_ratio = 16 / $height; 

if ( ($width <= 16) && ($height <= 16) ){$tn_width = $width; $tn_height = $height; } 
else if (($x_ratio * $height) < 16) { $tn_height = ceil($x_ratio * $height); $tn_width = 16; } 
else {$tn_width = ceil($y_ratio * $width); $tn_height = 16;} 

$src = ImageCreateFromPng("../SYSTEM/temp/$sess.png"); 
$dst = ImageCreate($tn_width,$tn_height); 


ImageCopyResized($dst, $src, 0, 0, 0, 0, $tn_width,$tn_height,$width,$height); 


imagecolortransparent($dst, '0');
header("Content-type: image/png"); 

if ($width>16 || $height>16)
ImagePng ($dst); 
else
ImagePng ($src);
unlink("../SYSTEM/temp/$sess.png");
?>
