/** * Handle the importation of Firefox HTML bookmarks * * Use external library firefox/bookmarks.class.php to parse html files * * @see firefox/bookmarks.class.php * * @return a list of WpHerissonBookmarks */ public function import() { $this->preImport(); include HERISSON_VENDOR_DIR . "firefox/bookmarks.class.php"; $filename = $this->getFilename(); // Parsing bookmarks file $bookmarks = new \Bookmarks(); $bookmarks->parse($filename); $bookmarks->bookmarksFileMd5 = md5_file($filename); $list = array(); //$page_title = __("Importation results from Firefox bookmarks", HERISSON_TD); $i = 0; $spacer = " "; while ($bookmarks->hasMoreItems()) { $item = $bookmarks->getNextElement(); $bookmark = array(); $bookmark['title'] = $item->name; if ($item->_isFolder) { $space = str_repeat($spacer, $item->depth - 1); $bookmark['prefix'] = $space; $bookmark['url'] = ""; $bookmark['description'] = ""; $bookmark['is_public'] = 1; $bookmark['favicon_image'] = ""; $bookmark['favicon_url'] = ""; $bookmark['tags'] = ""; } else { $bookmark['url'] = $item->HREF; $bookmark['description'] = ""; $bookmark['is_public'] = 1; $bookmark['favicon_image'] = $item->ICON_DATA; $bookmark['favicon_url'] = $item->ICON_URI; $bookmark['tags'] = ""; } $list[] = $bookmark; } unset($bookmarks); return $list; }
if ($binaryBookmarksExist) { # If the binary file exists $fp = fopen('bookmarks.bin', 'r'); $contents = fread($fp, filesize('bookmarks.bin')); fclose($fp); # Unserializing contents $bookmarks = unserialize(gzinflate($contents)); # Checking if the bookmarks file is the same if ($bookmarks->bookmarksFileMd5 != md5_file('bookmarks.html')) { $shouldReparseBookmarks = true; } } if (!$binaryBookmarksExist || $shouldReparseBookmarks) { # Creating new bookmarks $bookmarks = new Bookmarks(); $bookmarks->parse('bookmarks.html'); $bookmarks->bookmarksFileMd5 = md5_file('bookmarks.html'); # Writting icons $bookmarks->iconset->writeIcons(); # Writing bookmarks to a binary file $contents = gzdeflate(serialize($bookmarks), 9); $fp = fopen('bookmarks.bin', 'w+'); fwrite($fp, $contents); fclose($fp); } $currentDepth = 0; $tt = 0; $counter = 1; while ($bookmarks->hasMoreItems()) { $item = $bookmarks->getNextElement(); if ($item->depth > $currentDepth) {