Skip to content

Commit 3125c29

Browse files
committed
fix(HtmlExporter): Make sure to produce correct NETSCAPE-Bookmark-file-1 markup
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent e717219 commit 3125c29

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

lib/Service/HtmlExporter.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public function exportFolder(string $userId, int $folderId): string {
7070
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
7171
<TITLE>Bookmarks</TITLE>';
7272

73+
$file .= "<DL><p>\n";
7374
$file .= $this->serializeFolder($userId, $folderId, true);
75+
$file .= "</DL><p>\n";
7476

7577
return $file;
7678
}
@@ -84,14 +86,15 @@ public function exportFolder(string $userId, int $folderId): string {
8486
* @throws MultipleObjectsReturnedException
8587
* @throws UnauthorizedAccessError
8688
*/
87-
protected function serializeFolder(string $userId, int $id, bool $onlyContent = false): string {
88-
if ($onlyContent) {
89-
$output = '';
90-
} else {
89+
protected function serializeFolder(string $userId, int $id, string $indent = ''): string {
90+
$nextIndent = $indent . ' ';
91+
$childFolders = $this->treeMapper->findChildren(TreeMapper::TYPE_FOLDER, $id);
92+
foreach ($childFolders as $childFolder) {
9193
$folder = $this->folderMapper->find($id);
92-
$output = '<DT><h3>' . htmlspecialchars($folder->getTitle()) . '</h3>' . "\n"
93-
. '<DL><p>';
94+
$output = $indent . '<DT><H3>' . htmlspecialchars($folder->getTitle()) . '</H3>' . "\n";
95+
$output .= $indent . '<DL><p>' . "\n" . $this->serializeFolder($userId, $childFolder->getId(), $nextIndent) . '</DL><p>' . "\n";
9496
}
97+
9598
$childBookmarks = $this->treeMapper->findChildren(TreeMapper::TYPE_BOOKMARK, $id);
9699
foreach ($childBookmarks as $bookmark) {
97100
// discards records with no URL. This should not happen but
@@ -111,19 +114,12 @@ protected function serializeFolder(string $userId, int $id, bool $onlyContent =
111114
$title = Util::sanitizeHTML($title);
112115
$description = Util::sanitizeHTML($bookmark->getDescription());
113116

114-
$output .= '<DT><A HREF="' . $url . '" TAGS="' . $tags . '" ADD_DATE="' . $bookmark->getAdded() . '">' . $title . '</A>' . "\n";
117+
$output .= $indent . '<DT><A HREF="' . $url . '" TAGS="' . $tags . '" ADD_DATE="' . $bookmark->getAdded() . '">' . $title . '</A>' . "\n";
115118
if ($description !== '') {
116119
$output .= '<DD>' . $description . '</DD>';
117120
}
118121
$output .= "\n";
119122
}
120-
121-
$childFolders = $this->treeMapper->findChildren(TreeMapper::TYPE_FOLDER, $id);
122-
foreach ($childFolders as $childFolder) {
123-
$output .= $this->serializeFolder($userId, $childFolder->getId());
124-
}
125-
126-
$output .= '</p></DL>';
127123
return $output;
128124
}
129125
}

0 commit comments

Comments
 (0)