4 require_once 'HTML/Template/Sigma.php';
5 PEAR::setErrorHandling(PEAR_ERROR_DIE);
13 $extensiones = array('mpg', 'mpeg', 'avi', 'mov');
16 $name = basename($argv[0]);
17 echo "Modo de uso:\n";
18 echo " $name <volumen> [<directorio>] [<filename>]\n\n";
19 echo "Por defecto se usa el directorio actual y se guarda el resultado en MP3_<volumen>.glabels\n";
24 $dir = @$argv[2] ? $argv[2] : '.';
25 $filename = @$argv[3] ? $argv[3] : "videos-dvd-$numero.glabels";
26 $template = 'Template.VIDEOS.glabels';
31 while (($f = $d->read()) !== false) {
32 if (is_dir("$dir/$f") and $f != '.' and $f != '..') {
34 while (($f2 = $d2->read()) !== false) {
35 if (in_array(strtolower(preg_replace('/.*\.(.*)/', '$1', $f2)), $extensiones)) {
37 $datos[ucwords($f)][] = ucwords(preg_replace('/(.*)\..*/', '$1', $f2));
40 } elseif (in_array(strtolower(preg_replace('/.*\.(.*)/', '$1', $f)), $extensiones)) {
42 if (preg_match('/(.*) - (.*)/', $f, $m)) {
43 $datos[ucwords(preg_replace('/(.*)\..*/', '$1', $m[1]))][] = ucwords(preg_replace('/(.*)\..*/', '$1', $m[2]));
45 $datos[ucwords(preg_replace('/(.*)\..*/', '$1', $f))] = array();
52 $tpl =& new HTML_Template_Sigma($template_dir);
53 $tpl->loadTemplateFile($template);
54 $tpl->setGlobalVariable(array(
55 'N' => sprintf("%02d", $numero),
62 foreach ($datos as $artista => $albums) {
63 if ($y > Y_MAX and !@$col2) {
68 $tpl->setVariable(array(
71 'LINEA_Y' => $y + PUNTOS + 2.5,
72 'LINEA_ANCHO' => strlen($artista) * 2.5 + 25 / strlen($artista),
73 'ARTISTA' => translate($artista),
76 for ($i = 0; $i < count($albums); $i++) {
78 $tpl->setVariable('ALBUM', translate($albums[$i]));
80 $tpl->parse('ALBUMS');
82 $y += PUNTOS * ($i + 2);
83 $tpl->parse('ARTISTAS');
86 $results = $tpl->get();
87 $fo = fopen($filename, 'w');
92 function translate($str) {
93 static $tabla = array();
95 $tabla = get_html_translation_table(HTML_ENTITIES);
97 foreach ($tabla as $char => $void) {
98 $tabla[$char] = '&#' . ord($char) . ';';
101 return strtr($str, $tabla);