$name\n"; } function print_links($arr, $indent_level) { global $indent_str; foreach ($arr as $str) { $tmp = $indent_level; while ($tmp) { echo $indent_str; $tmp--; } echo "$str
"; } return; } /* Process the contents of a folder. * $fh is the file handle of the open bookmark file. * $indent_level is how many levels down into the folder hierarchy we are. */ function process_folder($fh, $indent_level) { global $indent_str; $links = array(); $is_trash = 0; while (!feof($fh)) { $line = fgets($fh, 4096); if (strncmp($line, "#FOLDER", 7) == 0) { // Start of a folder process_folder($fh, $indent_level+1); } else if (strncmp($line, "#URL", 4) == 0) { // Start of a bookmark $this_link = process_url_entry($fh, $indent_level); if ($this_link) { // Add the link we've just parsed to the array $links[] = $this_link; } } else if (strncmp($line, "-", 1) == 0) { // End of folder // Print the array of links (but not for the Trash folder) if (!$is_trash) { print_links($links, $indent_level); echo "
\n"; } return; } else if (strpos($line, "NAME=")) { // Name of the folder $heading = rtrim(substr($line, 6)); // Are we in the Trash folder? if (strcmp($heading, "Trash") == 0) { $is_trash = 1; } $headerlevel = $indent_level + 1; if ($headerlevel > 6) { $headerlevel = 6; } if (!$is_trash) { // Don't print the Trash folder echo "$heading\n"; } } } print_links($links, $indent_level); return; } /* Start of main program */ if (file_exists($filename)) { $fh = fopen($filename, "r"); // And so begins the fun. process_folder($fh, 0); fclose($fh); echo "
\n"; echo "Opera bookmark converter by Rayner Lucas, 2003\n"; } ?>