Import Bookmarks

from Browser:
select File:
Character encoding:
Make them:
Destination Folder:
make_tree (0); $tree->print_tree (); ?>

import_opera (); } else if ($_POST['browser'] == "netscape") { $import->import_netscape (); } echo "$import->count_folders folders and $import->count_bookmarks bookmarks imported.
\n"; echo 'My Bookmarks'; } ?>
fp = fopen ($_FILES['importfile']['tmp_name'], "r"); if ($this->fp == null){ message ("Failed to open file"); } $this->charset = set_post_charset (); $this->public = set_post_bool_var ("public", false); $this->count_folders = 0; $this->count_bookmarks = 0; $this->username = $username; $this->parent_folder = $parentfolder; $this->current_folder = $this->parent_folder; $this->folder_depth = array (); $this->mysql = $mysql; } function import_opera () { while (!feof ($this->fp)) { $line = trim (fgets ($this->fp, 4096)); # a folder has been found if ($line == "#FOLDER") { $item = "Folder"; } # a bookmark has been found else if ($line == "#URL") { $item = "Bookmark"; } # if a line starts with NAME= ... else if (substr ($line, 0, strlen("NAME=")) == "NAME=") { $line = substr ($line, strlen ("NAME=")); # ... depending on the value of "$item" we assign the name to # either folder or bookmark. if ($item == "Folder") { $this->name_folder = input_validation ($line, $this->charset); } else if ($item == "Bookmark") { $this->name_bookmark = input_validation ($line, $this->charset); } } # only bookmarks can have a description or/and an url. else if (substr ($line, 0, strlen ("DESCRIPTION=")) == "DESCRIPTION=") { $this->description = substr (input_validation ($line, $this->charset), strlen ("DESCRIPTION=")); } else if (substr ($line, 0, strlen ("URL=")) == "URL="){ $this->url = substr (input_validation ($line, $this->charset), strlen ("URL=")); } # process the corresponding item, if there is an empty line found else if ($line == "") { if (isset ($item) && $item == "Folder") { $this->folder_new (); unset ($item); } else if (isset ($item) && $item == "Bookmark") { $this->bookmark_new (); unset ($item); } } # this indicates, that the folder is being closed else if ($line == "-") { $this->folder_close (); } } } function import_netscape () { while (!feof ($this->fp)){ $line = trim (fgets ($this->fp)); # netscape seems to store html encoded values $line = html_entity_decode ($line, ENT_QUOTES, $this->charset); # a folder has been found if (ereg ("
name_folder = input_validation (ereg_replace ("^( *
<[^>]*>)([^<]*)(.*)", "\\2", $line), $this->charset); $this->folder_new (); } # a bookmark has been found else if (ereg("
name_bookmark = input_validation (ereg_replace ("^( *
<[^>]*>)([^<]*)(.*)", "\\2", $line), $this->charset); $this->url = input_validation (ereg_replace ("([^H]*HREF=\")([^\"]*)(\".*)", "\\2", $line), $this->charset); $this->bookmark_new (); $insert_id = mysql_insert_id (); } # this is a description. it is only being saved # if a bookmark has been saved previously else if (ereg("
*", $line)) { if (isset ($insert_id)) { $this->description = input_validation (ereg_replace ("^( *
)(.*)", "\\2", $line), $this->charset); $query = sprintf ("UPDATE bookmark SET description='%s' WHERE id='%d' and user='%s'", $this->mysql->escape ($this->description), $this->mysql->escape ($insert_id), $this->mysql->escape ($this->username)); @$this->mysql->query ($query); unset ($this->description); unset ($insert_id); } } # this indicates, that the folder is being closed else if ($line == "

") { $this->folder_close (); } } } function folder_new () { if (!isset ($this->name_folder)) { $this->name_folder == ""; } $query = sprintf ("INSERT INTO folder (childof, name, user, public) values ('%d', '%s', '%s', '%d')", $this->mysql->escape ($this->current_folder), $this->mysql->escape ($this->name_folder), $this->mysql->escape ($this->username), $this->mysql->escape ($this->public)); if ($this->mysql->query ($query)) { $this->current_folder = mysql_insert_id (); array_push ($this->folder_depth, $this->current_folder); unset ($this->name_folder); $this->count_folders++; } else { message ($this->mysql->error); } } function bookmark_new () { if (!isset ($this->name_bookmark)) { $this->name_bookmark = ""; } if (!isset ($this->url)) { $this->url = ""; } if (!isset ($this->description)) { $this->description = ""; } $query = sprintf ("INSERT INTO bookmark (user, title, url, description, childof, public) values ('%s', '%s', '%s', '%s', '%d', '%d')", $this->mysql->escape ($this->username), $this->mysql->escape ($this->name_bookmark), $this->mysql->escape ($this->url), $this->mysql->escape ($this->description), $this->mysql->escape ($this->current_folder), $this->mysql->escape ($this->public)); if ($this->mysql->query ($query)) { unset ($this->name_bookmark, $this->url, $this->description); $this->count_bookmarks++; } else { message ($this->mysql->error); } } function folder_close () { if (count ($this->folder_depth) <= 1) { $this->folder_depth = array (); $this->current_folder = $this->parent_folder; } else{ # remove the last folder from the folder history unset ($this->folder_depth[count ($this->folder_depth) - 1]); $this->folder_depth = array_values ($this->folder_depth); # set the last folder to the current folder $this->current_folder = $this->folder_depth[count ($this->folder_depth) - 1]; } } } print_footer (); require_once (ABSOLUTE_PATH . "footer.php"); ?>