<?php
##
## [PHP/mp3stream]
## for default template parsing
##

if(file_exists(__TMPLPATH__.'/config.php'))
{ require_once 
__TMPLPATH__.'/config.php'; }

## get userconfig override
##
$TMPL array_merge($TMPL,str2array($_userconf['info'])); // it's override
$TMPL['copyright'] = tag_a($TMPL['copyright'],'http://linuxchannel.net/','_blank');
$TMPL['pointer'] = ($browser['br']=='MSIE')&&($browser['vr']<=5.5)?'hand':'pointer';
$TMPL['rpath'] = $_GET['path'];
$TMPL['player_link'] = '<A HREF="'.$player['link'].'" TARGET="_blank">['.$player['str'].']</A>';

## start of templates parsing
##
$tmpl = new tmpl(__DEBUG__);

## get blocks
##
$block['dirs'] = $tmpl->get_file(__TMPLPATH__.'/block/dirs.html.tmpl');
$block['list'] = $tmpl->get_file(__TMPLPATH__.'/block/list.html.tmpl');
$block['curr'] = $tmpl->get_file(__TMPLPATH__.'/block/curr.html.tmpl');

$block['blist'] = str_replace('$STR','add',$block['list']);
$block['mlist'] = str_replace('$STR','del',$block['list']);

## get list link
##
$from_list = array('$TYPE','$VALUE','$LINK','$TITLE','$LAME','$DOWNLOAD',
    
'$ACTLIST','$MODE','$BITRATE','$FREQUENCY','$LENGTH','$SIZE');

## get currlink
##
if($currlink)
{
  
$from = array('$NBSP','$STR','$LINK');
  
$size sizeof($currlink['link']);
  for(
$i=0$i<$size$i++)
  {
    
$nbsp str_repeat('&nbsp;&nbsp;&nbsp;',$i);
    
$to = array($nbsp,$currlink['str'][$i],$currlink['link'][$i]);
    
$curr .= str_replace($from,$to,$block['curr']);
  }
  
$curr '<BR>'.$tmpl->parse($curr,$TMPL);
}
$TMPL['currlink'] = "<A HREF='$_SERVER[PHP_SELF]'>HOME</A> $curr<P>\n";

## get dirs link
##
$from = array('$STR','$LINK');
for(
$i=0$i<sizeof($dirs['link']); $i++)
{
  
$to = array($dirs['str'][$i],$dirs['link'][$i]);
  
$TMPL['dirs'] .= str_replace($from,$to,$block['dirs']);
}
$TMPL['dirs'] = $tmpl->parse($TMPL['dirs'],$TMPL); 

//$downloadimg = "<IMG SRC=$_SERVER[_PATH]/images/download.gif BORDER=0>";
$downloadimg '[download]';

for(
$i=0$i<$_size[files]; $i++)
{
  
$to = array(
    
$files['tail'][$i],
    
$files['enc'][$i],
    
$files['link'][$i],
    
$files['str'][$i],
    
$files['nolame'][$i] ? '-' '<A HREF="'.$files['lame'][$i].'">'.$_playmode.'</A>',
    
$files['download'][$i] ? '<A HREF='.$files['download'][$i].">$downloadimg</A>" '',
    
$files['addlist'][$i],
    
$files['mode'][$i],
    
$files['bitrate'][$i],
    
$files['frequency'][$i],
    
$files['length'][$i],
    
$files['filesize'][$i],
    );
  
$blist .= str_replace($from_list,$to,$block['blist']);
}
$TMPL['list'] = $tmpl->parse($blist,$TMPL);

## get images
##
for($i=0$i<$_size['imgs']; $i++)
{
  
$br = ($i%2) ? '<BR>' '';
  
$TMPL['imgs'] .= '<A HREF="Javascript:openwin(\''.$imgs['src'][$i].
    
'\',\''.$imgs['w'][$i].'\',\''.$imgs['h'][$i].'\',\''.$imgs['sbars_off'][$i].'\')"><IMG SRC="'.
    
$imgs['src'][$i].'&r=1" '.$imgs['wh'][$i].' BORDER=0></A>&nbsp;'.$br."\n";
}
$TMPL['imgs'] = $tmpl->parse($TMPL['imgs'],$TMPL); 

## get txts
##
for($i=0$i<$_size[txts]; $i++)
{
  
$TMPL['txts'] .= '<A HREF="Javascript:openwin(\''.$txts['link'][$i].'\',\'500\',\'600\')"><B>'.
    
$txts['str'][$i].'</B><BR>'.
    
'<PRE>'.$txts['contents'][$i].'<BR>more....</PRE></A><P>'."\n";
}
$TMPL['txts'] = $tmpl->parse($TMPL['txts'],$TMPL);

## get menu link
##
$menu_link $tmpl->get_file(__TMPLPATH__.'/menu/link.html.tmpl');
$TMPL['menu_link'] = $tmpl->parse($menu_link,$TMPL);

## cookie my playlist
##
$size sizeof($playlist['link']);
for(
$i=0$i<$size$i++)
{
  
$to = array(
    
$playlist['tail'][$i],
    
$playlist['idx'][$i],
    
$playlist['link'][$i],
    
$playlist['str'][$i],
    
$playlist['nolame'][$i] ? '-' '<A HREF="'.$playlist['lame'][$i].'">'.$_playmode.'</A>',
    
$playlist['download'][$i] ? '<A HREF='.$playlist['download'][$i].">$downloadimg</A>" '',
    
$playlist['dellist'][$i],
    
$playlist['mode'][$i],
    
$playlist['bitrate'][$i],
    
$playlist['frequency'][$i],
    
$playlist['length'][$i],
    
$playlist['filesize'][$i],
    );
  
$mlist .= str_replace($from_list,$to,$block['mlist']);
}

if(
$TMPL['playlist'] = $tmpl->parse($mlist,$TMPL))
{
  
$menu_playlist $tmpl->get_file(__TMPLPATH__.'/menu/playlist.html.tmpl');
  
$TMPL['menu_playlist'] = $tmpl->parse($menu_playlist,$TMPL);
}
else 
$TMPL['menu_playlist'] = '&nbsp;<BR>Ãß°¡µÈ °îÀÌ ¾ø½À´Ï´Ù.';

## TMPL parsing
##
$header $tmpl->get_file(__TMPLPATH__.'/header.html.tmpl');
$contents $tmpl->get_file(__TMPLPATH__.'/index.html.tmpl');
$footer $tmpl->get_file(__TMPLPATH__.'/footer.html.tmpl');

## printing
##
echo $tmpl->parse($header,$TMPL);
echo 
$tmpl->parse($contents,$TMPL);
echo 
$tmpl->parse($footer,$TMPL);

## debugging
##
//if($_GET['debug']) _debug(1);

?>