4 require_once 'HTML/Template/Sigma.php';
5 PEAR::setErrorHandling(PEAR_ERROR_DIE);
14 $name = basename($argv[0]);
15 echo "Modo de uso:\n";
16 echo " $name <volumen> [<directorio>] [<filename>]\n\n";
17 echo "Por defecto se usa el directorio actual y se guarda el resultado en MP3_<volumen>.glabels\n";
22 $dir = @$argv[2] ? $argv[2] : '.';
23 $filename = @$argv[3] ? $argv[3] : "MP3_$numero.glabels";
24 $template = 'Template.MP3.glabels';
29 while (($f = $d->read()) !== false) {
30 if (is_dir("$dir/$f") and $f != '.' and $f != '..') {
32 while (($f2 = $d2->read()) !== false) {
33 if (is_dir("$dir/$f/$f2") and $f2 != '.' and $f2 != '..') {
35 $d3 = dir("$dir/$f/$f2");
36 while (($f3 = $d3->read()) !== false) {
37 if (preg_match('/\.mp3$/i', $f3)) {
42 if (preg_match('/(\d{4}) - (.*)/', $f2, $m)) {
43 $datos[ucwords($f)][] = ucwords("$m[2] [$m[1]]");
45 $datos[ucwords($f)][] = ucwords($f2);
55 $tpl =& new HTML_Template_Sigma($template_dir);
56 $tpl->loadTemplateFile($template);
57 $tpl->setGlobalVariable(array(
65 foreach ($datos as $artista => $albums) {
66 if ($y > Y_MAX and !@$col2) {
71 $tpl->setVariable(array(
74 'LINEA_Y' => $y + PUNTOS - 1,
75 'LINEA_ANCHO' => strlen($artista) * 6,
76 'ARTISTA' => translate($artista),
79 for ($i = 0; $i < count($albums); $i++) {
81 $tpl->setVariable('ALBUM', translate($albums[$i]));
83 $tpl->parse('ALBUMS');
85 $y += PUNTOS * ($i + 2);
86 $tpl->parse('ARTISTAS');
89 $results = $tpl->get();
90 $fo = fopen($filename, 'w');
95 function translate($str) {
96 static $tabla = array();
98 $tabla = get_html_translation_table(HTML_ENTITIES);
100 foreach ($tabla as $char => $void) {
101 $tabla[$char] = '&#' . ord($char) . ';';
104 return strtr($str, $tabla);