<?php
if ( $_GET['no'] == NULL ) {

$i = $_SERVER["REQUEST_URI"];
if ( $_SERVER[QUERY_STRING] ) {
$i =  $_SERVER[QUERY_STRING];
} else {
}
	echo "<title>NDS NFO</title><body bgcolor=black><center><img src=image.php?no=".$i."></center></body>";
} else {


	

  $nfotext = "";
  $footer = "";  
  $fg = "FFFFFF";



   function InStr($String,$Find,$CaseSensitive = false) {
    $i=0;
    while (strlen($String)>=$i) {
     unset($substring);
     if ($CaseSensitive) {
      $Find=strtolower($Find);
      $String=strtolower($String);
     }
     $substring=substr($String,$i,strlen($Find));
     if ($substring==$Find) return true;
     $i++;
    }
    return false;
   } 


$i = $_GET['no'];
$i = str_replace(".php", "",$i);
$i = str_replace(".png", "",$i);
$i = str_replace("/nfo/", "",$i);
$i = str_replace("/", "",$i);
$i = str_replace("\\", "",$i);
$i = str_replace("etc", "",$i);
$i = str_replace("pass", "",$i);


$ii=$i;
if ( InStr($i,"gt",0) ) {
$logo = imagecreatefromgif("./gbatemp.gif");
$i = str_replace("gt", "",$i);
}

if ( InStr($i,"go",0) ) {
$logo = imagecreatefromgif("./gonline.gif");
$i = str_replace("go", "",$i);
}


	$ffile = "../nds/$i.nfo";

    $f = file("$ffile");

	//die("hello");

    $nfotext = implode("",$f);


  header("Content-Type: image/png");
  header("Content-Disposition: inline; filename=\"gbatemp.net.nfo.png\"");
  if(!strlen($nfotext)) $nfotext = "              NFO not found!.          ";
  $nfo = explode("\n", $nfotext);
  $fnt = imageloadfont("font");
  $fillers = strlen($nfo[1])+strlen($nfo[3])+strlen($nfo[5])+strlen($nfo[7])<9?1:0;
  $nxo = array();
  $xmax = 0;
  if($vc) {
    array_push($nxo,"");
    array_push($nxo,"");
 }
  foreach($nfo as $key=>$line){
    $line = chop($line);
    if($xmax < strlen($line)) $xmax = strlen($line);
    if($fillers and ($key & 1)) continue;
    array_push($nxo,$line);
  }
  if($vc) {
    $fill = str_repeat(" ",($xmax - strlen($vc)>>1));
     $nxo[0] = $fill.$vc;
  }
  if(strlen($footer)) {
    array_push($nxo,"");
    $fill = str_repeat(" ",($xmax - strlen($footer)>>1));
    array_push($nxo,$fill.$footer);
  }
  $ymax = count($nxo);
  $color = array(0, 0, 0);
  if(strlen($fg) == 6) {
    $color[0] = intval(substr($fg,0,2), 16);
    $color[1] = intval(substr($fg,2,2), 16);
    $color[2] = intval(substr($fg,4,2), 16);
  }
                      
  // Render NFO
  $im = ImageCreate($xmax*8,$ymax*16);
  $background_color = ImageColorTransparent($im, ImageColorAllocate ($im, 254, 254, 126));
  $text_color = ImageColorAllocate ($im, $color[0], $color[1], $color[2]);
  foreach($nxo as $y=>$line)
    ImageString($im, $fnt, 0, $y*16, $line, $text_color);


$width = ImageSX($im);
$height = ImageSY($im);

//$percent = $width / 400;
$percent = 1;
$newwidth = $width / $percent;
$newheight = $height / $percent;
$thumb = imagecreatetruecolor($newwidth, $newheight);
$background_color = ImageColorTransparent($thumb, ImageColorAllocate ($thumb, 0, 0, 0));
imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

imagecopymerge($thumb,$logo,$width - ImageSX($logo), 0,0,0,ImageSX($logo),ImageSY($logo),100);


//if ( InStr($ii,"gt",0) ) {
//$logo2 = imagecreatefromgif("./gbatemp2.gif");
//imagecopymerge($thumb,$logo2,$newwidth - ImageSX($logo2), $newheight - ImageSY($logo2),0,0,ImageSX($logo2),ImageSY($logo2),60);
//}

  ImagePNG($thumb);
}


?>