Skip to content

Commit

Permalink
Fix converting foldernames to tags during import.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Jul 5, 2014
1 parent 2dc019c commit 301dc1f
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions trean/lib/Data/Json.php
Expand Up @@ -24,16 +24,35 @@ public function importData($contents, $header = false)
return $this->_parseJson($json->children, null);
}

protected function _parseFolders($data)
{
// Need a first pass to grab all the folders
foreach ($data as $child) {
if ($child->type == 'text/x-moz-place-container') {
if (empty($child->root)) {
$this->_tagMap[$child->id] = $child->title;
$this->_parentMap[$child->id] = $child->parent;
}
if (!empty($child->children)) {
$this->_parseFolders($child->children);
}
}
}
}

protected function _parseJson($data, $container)
{
$rows = array();
// Need a first pass to grab all the folders
$this->_parseFolders($data);
return $this->_parseBookmarks($data);
}

protected function _parseBookmarks($data, $container = null)
{
$rows = array();
foreach ($data as $child) {

if ($child->type == 'text/x-moz-place-container') {
$this->_tagMap[$child->id] = $child->title;
$this->_parentMap[$child->id] = $child->parent;
$rows = array_merge($this->_parseJson($child->children, $child->title), $rows);
$rows = array_merge($this->_parseBookmarks($child->children, $child), $rows);
}
if ($child->type == 'text/x-moz-place') {
$desc = '';
Expand All @@ -49,9 +68,8 @@ protected function _parseJson($data, $container)
}
}
}

$tags = array();
$current_parent = $child->parent;
$current_parent = $container->parent;
while (!empty($current_parent)) {
if (!empty($this->_tagMap[$current_parent])) {
$tags[] = $this->_tagMap[$current_parent];
Expand All @@ -60,6 +78,9 @@ protected function _parseJson($data, $container)
? $this->_parentMap[$current_parent]
: false;
}
if (!empty($container) && empty($container->root)) {
$tags[] = $container->title;
}

$rows[] = array(
'bookmark_url' => $child->uri,
Expand Down

0 comments on commit 301dc1f

Please sign in to comment.