$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 "