Biblioteca on-line

<php>

$INDEX = '/var/www/html/www.rigacci.org/docs/biblio/bibliolist.txt'; $URL_PREFIX = 'https://www.rigacci.org/docs/biblio/';

setlocale(LC_ALL, 'it_IT.UTF-8'); $last_change = strftime('%A %d %B %Y', filemtime($INDEX));

echo “Ultime modifiche: $last_change.\n</p>\n”; echo “<p>\n”;

if ($fp = fopen($INDEX, 'r')) {

  $list_open = false;
  unset($record);
  while (!feof($fp)) {
      $line = trim(fgets($fp, 4096));
      // Skip comments.
      if (preg_match('/^\s*#/', $line)) next;
      // A blank line: output the record.
      if (preg_match('/^\s*$/', $line) and is_array($record)) {
          print_record($record, $URL_PREFIX);
          unset($record);
      }
      if (preg_match('/=/', $line)) {
          list($tag, $val) = explode('=', $line, 2);
          switch ($tag) {
              case 'section':
                  if (isset($record)) {
                      print_record($record, $URL_PREFIX);
                      unset($record);
                  }
                  if ($list_open) echo "</ul>\n</div>\n";
                  echo "<h2>" . htmlentities($val, ENT_COMPAT, 'UTF-8') . "</h2>\n";
                  echo "<div class=\"level2\">\n";
                  echo "<ul>\n";
                  $list_open = true;
                  break;
              default:
                  $record[$tag] = $val;
          }
      }
  }
  fclose($fp);
  if ($list_open) echo "</ul>\n</div>\n";

}

———————————————————————— Print a list entry with the contents of $record[] array. ———————————————————————— function print_record($record, $URL_PREFIX) { if (isset($record['title']) and isset($record['online'])) { echo ' <li>'; echo '<a href=“' . $URL_PREFIX . $record['online'] . '”>'; echo htmlentities($record['title']); echo '</a>'; if (isset($record['lang'])) { $image = $record['lang'] . '.png'; $alt = $record['lang']; $width = 21; $height = 14; echo ' '; echo_image ($image, $URL_PREFIX, $alt, $width, $height); } if (isset($record['src'])) { echo ' <a href=“' . $URL_PREFIX . $record['src'] . '”>'; echo 'doc'; echo '</a>'; } if (isset($record['offline'])) { echo ' <a href=“' . $URL_PREFIX . $record['offline'] . '”>'; echo 'zip'; echo '</a>'; } if (isset($record['pdf'])) { echo ' <a href=“' . $URL_PREFIX . $record['pdf'] . '”>'; echo 'pdf'; echo '</a>'; } if (isset($record['web'])) { echo ' <a href=“' . $record['web'] . '”>'; echo 'web'; echo '</a>'; } echo “</li>\n”; } } ———————————————————————— Echo an <img> tag. ———————————————————————— function echo_image($file_name, $URL_PREFIX, $alt_text = , $width = , $height = '') {

  echo '<img align="middle" src=';
  echo '"' . $URL_PREFIX . 'img/' . $file_name . '"';
  if ($width and $height) echo " width=\"$width\" height=\"$height\"";
  echo ' border="0" alt="' . htmlentities($alt_text, ENT_COMPAT, 'UTF-8') . '"/>';

}

</php>