#!/usr/bin/php4 -qC
[] []\n\n";
echo "Por defecto se usa el directorio actual y se guarda el resultado en mp3-dvd-.glabels\n";
exit;
}
$numero = $argv[1];
$dir = @$argv[2] ? $argv[2] : '.';
$filename = @$argv[3] ? $argv[3] : "mp3-dvd-$numero.glabels";
$template = 'Template.MP3.glabels';
$template_dir = '.';
$datos = array();
$d = dir($dir);
while (($f = $d->read()) !== false) {
if (is_dir("$dir/$f") and $f != '.' and $f != '..') {
$d2 = dir("$dir/$f");
while (($f2 = $d2->read()) !== false) {
if (is_dir("$dir/$f/$f2") and $f2 != '.' and $f2 != '..') {
$is_album = false;
$d3 = dir("$dir/$f/$f2");
while (($f3 = $d3->read()) !== false) {
if (preg_match('/\.mp3$/i', $f3)) {
$is_album = true;
}
}
if ($is_album) {
if (preg_match('/(\d{4}) - (.*)/', $f2, $m)) {
$datos[ucwords($f)][] = ucwords("$m[2] [$m[1]]");
} else {
$datos[ucwords($f)][] = ucwords($f2);
}
}
}
}
}
}
if ($datos) {
$tpl =& new HTML_Template_Sigma($template_dir);
$tpl->loadTemplateFile($template);
$tpl->setGlobalVariable(array(
'N' => sprintf("%02d", $numero),
'PUNTOS' => PUNTOS,
));
$x = X_BASE;
$y = Y_BASE;
ksort($datos);
foreach ($datos as $artista => $albums) {
if ($y > Y_MAX and !@$col2) {
$x = X_COL2;
$y = Y_BASE;
$col2 = true;
}
$tpl->setVariable(array(
'X' => $x,
'TEXTO_Y' => $y,
'LINEA_Y' => $y + PUNTOS + 2.5,
'LINEA_ANCHO' => strlen($artista) * 2.5 + 25 / strlen($artista),
'ARTISTA' => translate($artista),
));
sort($albums);
for ($i = 0; $i < count($albums); $i++) {
// assign data
$tpl->setVariable('ALBUM', translate($albums[$i]));
// process the block
$tpl->parse('ALBUMS');
}
$y += PUNTOS * ($i + 2);
$tpl->parse('ARTISTAS');
}
$results = $tpl->get();
$fo = fopen($filename, 'w');
fputs($fo, $results);
fclose($fo);
}
function translate($str) {
static $tabla = array();
if (!@$tabla) {
$tabla = get_html_translation_table(HTML_ENTITIES);
array_shift($tabla);
foreach ($tabla as $char => $void) {
$tabla[$char] = '' . ord($char) . ';';
}
}
return strtr($str, $tabla);
}
?>