diff --git a/CHANGES b/CHANGES
new file mode 100644
index 0000000..59e5fd5
--- /dev/null
+++ b/CHANGES
@@ -0,0 +1,7 @@
+16.04.2008, Version 0.8.8 beta
+- New design.
+- Added the possibility to change the public/private status on multiple
+ bookmarks.
+- Added the possibility to mark bookmarks and folders public/private
+ when importing them.
+
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..47963f8
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1 @@
+See http://www.frech.ch/online-bookmarks/installation.php for installation instructions.
diff --git a/README b/README
new file mode 100644
index 0000000..41c6f80
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+See http://www.frech.ch/online-bookmarks/ for documentation.
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..8340c15
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.8.8 beta
\ No newline at end of file
diff --git a/admin.php b/admin.php
new file mode 100644
index 0000000..1e8ac20
--- /dev/null
+++ b/admin.php
@@ -0,0 +1,282 @@
+
+
+
+
+ Admin Page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+escape ($new_username),
+ $mysql->escape ($new_password),
+ $mysql->escape ($new_admin));
+
+ if ($mysql->query ($query)) {
+ $message1 = "User $new_username created.";
+ }
+ else {
+ message ($mysql->error);
+ }
+ unset ($new_password, $_POST['new_password']);
+ }
+}
+?>
+
+
+ Create User
+
+
+
+
+
+
+
+ Delete User
+
+ escape ($existing_user));
+ if ($mysql->query ($query)) {
+ $message2 = "User $existing_user deleted. ";
+ }
+ else {
+ message ($mysql->error);
+ }
+
+ $query = sprintf ("DELETE FROM bookmark WHERE md5(user)=md5('%s')",
+ $mysql->escape ($existing_user));
+ if (!$mysql->query ($query)) {
+ message ($mysql->error);
+ }
+
+ $query = sprintf ("DELETE FROM folder WHERE md5(user)=md5('%s')",
+ $mysql->escape ($existing_user));
+ if (!$mysql->query ($query)) {
+ message ($mysql->error);
+ }
+ list_users ();
+ }
+ else {
+ ?>
+
+ Are you sure you want to delete the user and all it's Bookmarks and Folders?
+
+
+
+
+
+
+
+
+
+
+
+ Version
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/bookmark_add.php b/bookmark_add.php
new file mode 100644
index 0000000..e1e99c0
--- /dev/null
+++ b/bookmark_add.php
@@ -0,0 +1,3 @@
+
\ No newline at end of file
diff --git a/bookmark_delete.php b/bookmark_delete.php
new file mode 100644
index 0000000..48e8db4
--- /dev/null
+++ b/bookmark_delete.php
@@ -0,0 +1,70 @@
+escape ($bmlist),
+ $mysql->escape ($username));
+ if ($mysql->query ($query)) {
+ echo "Bookmarks successfully deleted \n";
+ echo '';
+ }
+ else {
+ message ($mysql->error);
+ }
+}
+else {
+ $bmlistq = implode (",", $bmlist);
+ $query = sprintf ("SELECT title, id, favicon FROM bookmark WHERE id IN (%s) AND user='%s' ORDER BY title",
+ $mysql->escape ($bmlistq),
+ $mysql->escape ($username));
+ if ($mysql->query ($query)) {
+ require_once (ABSOLUTE_PATH . "bookmarks.php");
+ $query_string = "?bmlist=" . implode ("_", $bmlist) . "&noconfirm=1";
+ ?>
+
+ Delete these Bookmarks?
+
+
+ result)) {
+ array_push ($bookmarks, $row);
+ }
+ list_bookmarks ($bookmarks,
+ false,
+ false,
+ $settings['show_bookmark_icon'],
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false);
+ ?>
+
+
+
+
+
+
+ error);
+ }
+}
+
+require_once (ABSOLUTE_PATH . "footer.php");
+?>
\ No newline at end of file
diff --git a/bookmark_edit.php b/bookmark_edit.php
new file mode 100644
index 0000000..44a60bf
--- /dev/null
+++ b/bookmark_edit.php
@@ -0,0 +1,188 @@
+ 1) {
+ # if there is more than one bookmark to edit, we just care about the
+ # public/private field.
+ if ( ! isset ($_POST['public'])) {
+ $qbmlist = implode (",", $bmlist);
+ $query = sprintf ("SELECT title, id, public, favicon FROM bookmark WHERE id IN (%s) AND user='%s' ORDER BY title",
+ $mysql->escape ($qbmlist),
+ $mysql->escape ($username));
+ if ($mysql->query ($query)) {
+ require_once (ABSOLUTE_PATH . "bookmarks.php");
+ $query_string = "?bmlist=" . implode ("_", $bmlist);
+ ?>
+
+ Change public state:
+
+
+ result)) {
+ array_push ($bookmarks, $row);
+ }
+ list_bookmarks ($bookmarks,
+ false,
+ false,
+ $settings['show_bookmark_icon'],
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true);
+ ?>
+
+
+
+
+
+
+ error);
+ }
+ }
+ else {
+ $bmlist = implode (",", $bmlist);
+ $query = sprintf ("UPDATE bookmark SET public='%d'
+ WHERE id IN (%s)
+ AND user='%s'",
+ $mysql->escape ($post_public),
+ $mysql->escape ($bmlist),
+ $mysql->escape ($username));
+ if ($mysql->query ($query)) {
+ echo "Bookmark successfully updated \n";
+ echo '';
+ }
+ else {
+ message ($mysql->error);
+ }
+ }
+
+}
+else if (count ($bmlist) < 1) {
+ message ("No Bookmark to edit.");
+}
+else if ($post_title == "" || $post_url == "" || $post_icon) {
+ $query = sprintf ("SELECT title, url, description, childof, id, favicon, public
+ FROM bookmark
+ WHERE id='%d'
+ AND user='%s'
+ AND deleted != '1'",
+ $mysql->escape ($bmlist[0]),
+ $mysql->escape ($username));
+ if ($mysql->query ($query)) {
+ if (mysql_num_rows ($mysql->result) != 1) {
+ message ("No Bookmark to edit");
+ }
+ else {
+ $row = mysql_fetch_object ($mysql->result);
+ require_once (ABSOLUTE_PATH . "folders.php");
+ $tree = & new folder;
+ $query_string = "?expand=" . implode(",", $tree->get_path_to_root ($row->childof)) . "&folderid=" . $row->childof;
+ $path = $tree->print_path ($row->childof);
+ if ($post_icon && $settings['show_bookmark_icon']) {
+ if (isset ($row->favicon)) {
+ @unlink ($row->favicon);
+ }
+ require_once (ABSOLUTE_PATH . "favicon.php");
+ $favicon = & new favicon ($post_url);
+ if (isset ($favicon->favicon)) {
+ $icon = ' ';
+ $query = sprintf ("UPDATE bookmark SET favicon='%s' WHERE user='%s' AND id='%d'",
+ $mysql->escape ($favicon->favicon),
+ $mysql->escape ($username),
+ $mysql->escape ($bmlist[0]));
+ if (!$mysql->query ($query)) {
+ message ($mysql->error);
+ }
+ }
+ else {
+ $icon = $bookmark_image;
+ }
+ }
+ else if ($row->favicon && is_file ($row->favicon)) {
+ $icon = ' ';
+ }
+ else {
+ $icon = $bookmark_image;
+ }
+ }
+ }
+ else {
+ message ($mysql->error);
+ }
+
+?>
+
+ Edit Bookmark
+
+
+
+escape ($post_title),
+ $mysql->escape ($post_url),
+ $mysql->escape ($post_description),
+ $mysql->escape ($post_childof),
+ $mysql->escape ($post_public),
+ $mysql->escape ($bmlist[0]),
+ $mysql->escape ($username));
+ if ($mysql->query ($query)) {
+ echo "Bookmark successfully updated \n";
+ echo '';
+ }
+ else {
+ message ($mysql->error);
+ }
+}
+
+require_once (ABSOLUTE_PATH . "footer.php");
+?>
diff --git a/bookmark_move.php b/bookmark_move.php
new file mode 100644
index 0000000..0c84c79
--- /dev/null
+++ b/bookmark_move.php
@@ -0,0 +1,56 @@
+
+
+ Move bookmarks to:
+ " method="POST" name="bookmarksmove">
+
+
+
+ make_tree (0);
+ $tree->print_tree ();
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+ escape ($folderid),
+ $mysql->escape (implode (",", $bmlist)),
+ $mysql->escape ($username));
+
+ if ($mysql->query ($query)) {
+ echo "Bookmarks moved \n";
+ echo '';
+ }
+ else {
+ message ($mysql->error);
+ }
+}
+
+require_once (ABSOLUTE_PATH . "footer.php");
+?>
\ No newline at end of file
diff --git a/bookmark_new.php b/bookmark_new.php
new file mode 100644
index 0000000..fc008f2
--- /dev/null
+++ b/bookmark_new.php
@@ -0,0 +1,122 @@
+get_path_to_root ($post_childof)) . "&folderid=" . $post_childof;
+
+if ($post_title == '' || $post_url == '') {
+ $path = $tree->print_path ($folderid);
+ if ($post_title != '') {
+ $title = $post_title;
+ }
+ else {
+ $title = $get_title;
+ }
+ if ($post_url != '') {
+ $url = $post_url;
+ }
+ else if ($get_url != '') {
+ $url = $get_url;
+ }
+ else {
+ $url = 'http://';
+ }
+ if (strtolower (basename ($_SERVER['SCRIPT_NAME'])) == 'bookmark_add.php') {
+ $js_onclick = 'history.back()';
+ }
+ else {
+ $js_onclick = 'self.close()';
+ }
+
+?>
+
+ New Bookmark
+ " id="bmnew" method="POST">
+ Title
+
+ Homepage
+
+ Description
+
+ Select/Change folder
+
+
+ Tags
+
+
+
+ Public >
+
+
+
+escape ($username),
+ $mysql->escape ($post_title),
+ $mysql->escape ($post_url),
+ $mysql->escape ($post_description),
+ $mysql->escape ($post_childof),
+ $mysql->escape ($post_public));
+
+ if ($mysql->query ($query)) {
+ echo "Bookmark successfully created \n";
+ $bm_id = mysql_insert_id ();
+ }
+ else {
+ message ($mysql->error);
+ }
+ unset ($_SESSION['title'], $_SESSION['url']);
+
+ # safing the favicon in a separate second step is done because
+ # we want to make sure the bookmark is safed in any case. the
+ # favicon is not that important.
+ if ($settings['show_bookmark_icon']) {
+ require_once (ABSOLUTE_PATH . "favicon.php");
+ $favicon = & new favicon ($post_url);
+ if (isset ($favicon->favicon)) {
+ $query = sprintf ("UPDATE bookmark set favicon='%s' WHERE user='%s' AND id='%d'",
+ $mysql->escape ($favicon->favicon),
+ $mysql->escape ($username),
+ $mysql->escape ($bm_id));
+ $mysql->query ($query);
+ $icon = ' ';
+ }
+ else {
+ $icon = $bookmark_image;
+ }
+ }
+
+ if (strtolower (basename ($_SERVER['SCRIPT_NAME'])) == "bookmark_add.php") {
+ echo 'Back to '.$icon.' '.$post_title.' ' . "\n";
+ echo 'Open '.$folder_opened.' folder containing new Bookmark ' . "\n";
+ }
+ else {
+ echo '';
+ # I know, the following is ugly, but I found no other way to do.
+ # When creating a bookmark out of the personal toolbar, there is no
+ # window.opener that can be closed. Thus javascript exits with an error
+ # without finishing itself (self.close()).
+ echo '';
+ }
+}
+require_once (ABSOLUTE_PATH . "footer.php");
+?>
\ No newline at end of file
diff --git a/bookmarks.php b/bookmarks.php
new file mode 100644
index 0000000..5bd900b
--- /dev/null
+++ b/bookmarks.php
@@ -0,0 +1,138 @@
+' . "\n";
+ echo '' . "\n";
+
+ foreach ($bookmarks as $value) {
+ echo '' . "\n";
+
+ # the folders, only needed when searching for bookmarks
+ if ($show_folder) {
+ if ($value['fid'] == null) {
+ $value['name'] = $settings['root_folder_name'];
+ $value['fid'] = 0;
+ }
+ if ($value['fpublic']) {
+ $folder_image = $folder_opened_public;
+ }
+ else {
+ $folder_image = $folder_opened;
+ }
+ $expand = $tree->get_path_to_root ($value['fid']);
+ echo '';
+ echo '';
+ echo $folder_image . " " . $value['name'] . " ";
+ echo " \n";
+ }
+
+ if ($show_checkbox){
+ # the checkbox, needed in any case
+ echo '';
+ echo ' ';
+ echo " \n";
+ }
+
+ # the bookmark image if configured to be displayed
+ if ($show_icon){
+ echo '';
+ if ($value['favicon'] && is_file ($value['favicon'])) {
+ echo ' ';
+ }
+ else {
+ echo $bookmark_image;
+ }
+ echo " \n";
+ }
+
+ # the link if configured to be displayed
+ echo '';
+
+ if ($settings['open_new_window']) {
+ $target = ' target="_blank"';
+ }
+ else {
+ $target = null;
+ }
+
+ if ($show_link){
+ $link = '' . $value['title'] . " ";
+ }
+ else {
+ $link = $value['title'];
+ }
+ echo '' . $link . "
\n";
+
+ # the description if configured to be displayed and if not empty
+ # thanks to Tim Hogan
+ # also display the public status here
+ if ($show_desc && $value['description'] != "") {
+ echo '' . $value['description'] . "
\n";
+ }
+ echo " \n";
+
+ if ($show_date) {
+ echo '';
+ echo ''. date ($date_formats[$settings['date_format']], $value['timestamp']) .'
';
+ echo " \n";
+ }
+
+
+ if ($show_share) {
+ echo '';
+ $share = $value['public'] ? 'public' : 'private';
+ echo ''.$share.'
';
+ echo " \n";
+ }
+
+
+ # the edit column if configured to be displayed
+ if ($show_edit) {
+ echo '';
+ echo '';
+ echo sprintf ($edit_image, "Edit");
+ echo " \n";
+ }
+
+ # the move column if configured to be displayed
+ if ($show_move) {
+ echo '';
+ echo '';
+ echo sprintf ($move_image, "Move");
+ echo " \n";
+ }
+
+ # the delete column if configured to be displayed
+ if ($show_delete) {
+ echo '';
+ echo '';
+ echo sprintf ($delete_image, "Delete");
+ echo " \n";
+ }
+
+ echo " \n";
+ }
+ echo "
\n";
+}
+
+?>
diff --git a/export.php b/export.php
new file mode 100644
index 0000000..dbbf4ba
--- /dev/null
+++ b/export.php
@@ -0,0 +1,326 @@
+
+
+
+
+ Export Bookmarks
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+\n";
+ echo "Bookmarks \n";
+ echo "Bookmarks \n";
+ echo "\n";
+ $export = & new export;
+ $export->make_tree ($folderid);
+ echo "
\n";
+ }
+ else if ($browser == "opera") {
+ echo "Opera Hotlist version 2.0\n";
+ echo "Options: encoding = utf8, version=3\n\n";
+ $export = & new export;
+ $export->make_tree ($folderid);
+ }
+}
+
+class export {
+ function export () {
+ # collect the folder data
+ require_once (ABSOLUTE_PATH . "folders.php");
+ $this->tree = & new folder;
+ $this->tree->folders[0] = array ('id' => 0, 'childof' => null, 'name' => $GLOBALS['settings']['root_folder_name']);
+
+ global $username, $mysql;
+ $this->browser = $GLOBALS['browser'];
+
+ $this->counter = 0;
+
+ # work around PHP < 5 problem
+ # http://bugs.php.net/bug.php?id=25670
+ if (intval(str_replace('.', '', phpversion())) < 500) {
+ $this->charset = 'iso-8859-1';
+ }
+ else {
+ $this->charset = set_post_charset ();
+ }
+
+ # collect the bookmark data
+ $query = sprintf ("SELECT title, url, description, childof, id
+ FROM bookmark
+ WHERE user='%s'
+ AND deleted!='1'",
+ $mysql->escape ($username));
+
+ if ($mysql->query ($query)) {
+ while ($row = mysql_fetch_assoc ($mysql->result)) {
+ if (!isset ($this->bookmarks[$row['childof']])) {
+ $this->bookmarks[$row['childof']] = array ();
+ }
+ array_push ($this->bookmarks[$row['childof']], $row);
+ }
+ }
+ else {
+ message ($mysql->error);
+ }
+ }
+
+ function make_tree ($id) {
+ if (isset ($this->tree->children[$id])) {
+ $this->counter++;
+ foreach ($this->tree->children[$id] as $value) {
+ $this->print_folder ($value);
+ $this->make_tree ($value);
+ $this->print_folder_close ();
+ }
+ $this->counter--;
+ }
+ $this->print_bookmarks ($id);
+ }
+
+
+ function print_folder ($folderid) {
+ $spacer = str_repeat (" ", $this->counter);
+ $foldername = html_entity_decode ($this->tree->folders[$folderid]['name'], ENT_QUOTES, $this->charset);
+ if ($this->browser == "netscape") {
+ echo $spacer . "
" . $foldername . " \n";
+ echo $spacer . "\n";
+ }
+ else if ($this->browser == "IE") {
+ echo $spacer . '
' . $foldername . " \n";
+ echo $spacer . "\n";
+ }
+ else if ($this->browser == "opera") {
+ echo "\n#FOLDER\n";
+ echo "\tNAME=" . $foldername . "\n";
+ }
+ }
+
+ function print_folder_close () {
+ $spacer = str_repeat (" ", $this->counter);
+ if ($this->browser == "netscape" || $this->browser == "IE"){
+ echo $spacer . "
\n";
+ }
+ else if ($this->browser == "opera"){
+ echo "\n-\n";
+ }
+ }
+
+ function print_bookmarks ($folderid) {
+ $spacer = str_repeat (" ", $this->counter);
+ if (isset ($this->bookmarks[$folderid])) {
+ foreach ($this->bookmarks[$folderid] as $value) {
+ $url = html_entity_decode ($value['url'], ENT_QUOTES, $this->charset);
+ $title = html_entity_decode ($value['title'], ENT_QUOTES, $this->charset);
+ if ($value['description'] != '') {
+ $description = html_entity_decode ($value['description'], ENT_QUOTES, $this->charset);
+ }
+ else {
+ $description = '';
+ }
+
+ if ($this->browser == 'netscape') {
+ echo $spacer . '
' . $title . " \n";
+ if ($description != '') {
+ echo $spacer . ' ' . $description . "\n";
+ }
+ }
+ else if ($this->browser == 'IE') {
+ echo $spacer . ' ' . $title . " \n";
+ # unfortunately description for bookmarks in MS Internet Explorer is not supported.
+ # thats why we just ignore the output of the description here.
+ }
+ else if ($this->browser == 'opera') {
+ echo "\n#URL\n";
+ echo "\tNAME=" . $title . "\n";
+ echo "\tURL=" . $url . "\n";
+ if ($description != "") {
+ # opera cannot handle the \r\n character, so we fix this.
+ $description = str_replace ("\r\n", " ", $description);
+ echo "\tDESCRIPTION=" . $description . "\n";
+ }
+ }
+ }
+ }
+ }
+}
+
+?>
diff --git a/favicon.ico b/favicon.ico
new file mode 100644
index 0000000..8b9106c
Binary files /dev/null and b/favicon.ico differ
diff --git a/favicon.php b/favicon.php
new file mode 100644
index 0000000..d9da61a
--- /dev/null
+++ b/favicon.php
@@ -0,0 +1,200 @@
+parsed_url = $this->return_parse_url ($url)) {
+ if ($this->favicon_url = $this->get_favicon_url ()) {
+ $this->icon_name = rand () . basename ($this->favicon_url);
+ if ($this->get_favicon_image ()) {
+ $this->convert_favicon ();
+ }
+ }
+ }
+ }
+ }
+ ###
+ ### check the image type and convert & resize it if required
+ ### returns the absolute path of the (converted) .png file
+ ###
+ function convert_favicon () {
+
+ global $convert, $identify;
+
+ $tmp_file = "./favicons/" . $this->icon_name;
+ # find out file type
+ if (@exec ("$identify $tmp_file", $output)) {
+ $ident = explode (" ", $output[0]);
+ if (count ($output) > 1) {
+ $file_to_convert = $ident[0];
+ }
+ else {
+ $file_to_convert = $tmp_file;
+ }
+
+ # convert image in any case to 16x16 and .png
+ system ("$convert $file_to_convert -resize 16x16 $tmp_file.png");
+ $this->favicon = $tmp_file . ".png";
+ @unlink ($tmp_file);
+ return true;
+ }
+ else {
+ @unlink ($tmp_file);
+ return false;
+ }
+ }
+
+ ###
+ ### download and save favicon
+ ###
+ function get_favicon_image () {
+ //Selbstgebastelte, IIS-kompatible Version von Arne Haak (www.arnehaak.de)
+ # HTTP-Url auswerten
+ $httpparsed = $this->return_parse_url ($this->favicon_url);
+
+ //HTTP-Request-Header erzeugen
+ $httprequest = "GET ".$httpparsed['path']." HTTP/1.0\r\n".
+ "Accept: */*\r\n".
+ "Accept-Language: en\r\n".
+ "Accept-Encoding: identity\r\n".
+ "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n".
+ "Host: ".$httpparsed['host']."\r\n".
+ "Connection: close\r\n\r\n";
+
+ //Verbindung aufbauen und Request abschicken
+ if ($httphandle = fsockopen($httpparsed['host'],$httpparsed['port'])) {
+ fputs($httphandle, $httprequest);
+
+ //Daten runterladen solange vorhanden
+ $answerdata = null;
+ do {
+ $answerdata .= fread($httphandle, 1024);
+ } while (feof($httphandle) != true);
+
+ // Verbindung schliessen
+ fclose ($httphandle);
+
+ //Header finden und abtrennen
+ $finalposi = strpos($answerdata, "\r\n\r\n") + 4; //Position des ersten Bytes nach dem Header bestimmen
+ $finalfile = substr($answerdata, $finalposi, strlen($answerdata) - $finalposi); //Header abschneiden
+
+ //Datei abspeichern
+ if ($fp = @fopen("./favicons/" . $this->icon_name, "w")) {
+ fwrite($fp, $finalfile);
+ fclose($fp);
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ else {
+ return false;
+ }
+ }
+
+ ###
+ ### checks for the existence of a favicon on a remote server
+ ### and returns the url if one exist
+ ###
+ function get_favicon_url () {
+ global $timeout;
+ # search for favicon in document root first
+ if ($socket = @fsockopen ($this->parsed_url['host'], $this->parsed_url['port'], $errno, $errstr, $timeout)) {
+ fwrite ($socket, "HEAD /favicon.ico HTTP/1.0\r\nHost: " . $this->parsed_url['host'] . "\r\n\r\n");
+ $http_response = fgets ($socket, 22);
+ fclose ($socket);
+ if (ereg ("200 OK", $http_response)) {
+ #echo "favicon found in document root\n";
+ return $this->parsed_url['scheme'] . "://" . $this->parsed_url['host'] . ":" . $this->parsed_url['port'] . "/favicon.ico";
+ }
+ else {
+ # if favicon was not found in document root, search in html header for it
+ if ($socket = @fsockopen ($this->parsed_url['host'], $this->parsed_url['port'], $errno, $errstr, $timeout)) {
+ fwrite ($socket, "GET " . $this->parsed_url['path'] . " HTTP/1.0\r\nHost: " . $this->parsed_url['host'] . "\r\n\r\n");
+ while (!feof ($socket)) {
+ $html = fgets ($socket, 1024);
+ if ($html == null) {
+ return false;
+ }
+
+ # we only want to search in HTML documents
+ if (preg_match ('/.*Content-Type:.*/si', $html, $contenttype)) {
+ if ( ! preg_match ('/text\/html/si', $contenttype[0])) {
+ return false;
+ }
+ }
+
+ if (preg_match ('/ ]+rel="(?:shortcut )?icon".*>/si', $html, $tag)) {
+ #echo "found favicon in html header\n";
+ if (preg_match ('/ ]+href="([^"]+)".*>/si', $tag[0], $location)) {
+ # the favicon location is an url
+ if (substr($location[1], 0, 7) == 'http://') {
+ $favicon = $location[1];
+ }
+ # the favicon location is an absolute path
+ else if (substr ($location[1], 0, 1) == '/') {
+ $favicon = $this->parsed_url['scheme'] . '://' . $this->parsed_url['host'] . ":" . $this->parsed_url['port'] . $location[1];
+ }
+ # else the path can only be something useless
+ # or a relative path, looking like this.
+ # ./path/to/favicon.ico
+ # path/to/favicon.ico
+ else {
+ # The location we called is either a file or a directory.
+ # We have to guess. We assume it is a directory if there is a trailing slash
+ if (substr ($this->parsed_url['path'], strlen($this->parsed_url['path'])-1) == "/") {
+ $favicon = $this->parsed_url['scheme'] . '://' . $this->parsed_url['host'] . ":" . $this->parsed_url['port'] . $this->parsed_url['path'] . $location[1];
+ }
+ else {
+ $favicon = $this->parsed_url['scheme'] . '://' . $this->parsed_url['host'] . ":" . $this->parsed_url['port'] . dirname ($this->parsed_url['path']) . '/' . $location[1];
+ }
+ }
+ return $favicon;
+ }
+ }
+ else if (preg_match ('/.*<\/head.*>/si', $html)) {
+ #echo "html header end found, giving up\n";
+ return false;
+ }
+ }
+ fclose ($socket);
+ }
+ }
+ }
+ return false;
+ }
+
+ ###
+ ### returns an array with parts of the given url
+ ###
+ function return_parse_url ($url) {
+ if ($parsed = @parse_url ($url)) {
+ if (!isset ($parsed['scheme']) || $parsed['scheme'] == "") {
+ $parsed['scheme'] = "http";
+ }
+ else if ($parsed['scheme'] != "http") {
+ return false;
+ }
+ if (!isset ($parsed['host']) || $parsed['host'] == "") {
+ return false;
+ }
+ if (!isset ($parsed['port']) || $parsed['port'] == "") {
+ $parsed['port'] = 80;
+ }
+ if (!isset ($parsed['path']) || $parsed['path'] == "") {
+ $parsed['path'] = "/";
+ }
+ return ($parsed);
+ }
+ else {
+ return false;
+ }
+ }
+}
+
+?>
diff --git a/folder_delete.php b/folder_delete.php
new file mode 100644
index 0000000..d43fb09
--- /dev/null
+++ b/folder_delete.php
@@ -0,0 +1,112 @@
+get_children ($folderid);
+
+ # we need $parent_folders for javascript code below.
+ $parent_folders = $tree->get_path_to_root ($folderid);
+ if (count ($parent_folders) > 1) {
+ $parent_folder = $parent_folders[1];
+ }
+ else {
+ $parent_folder = 0;
+ }
+
+ array_push ($tree->get_children, $folderid);
+ $folders = implode (",", $tree->get_children);
+ # first delete all subfolders
+ $query = sprintf ("DELETE FROM folder WHERE childof IN (%s) AND user='%s'",
+ $mysql->escape ($folders),
+ $mysql->escape ($username));
+ if (!$mysql->query ($query)) {
+ message ($mysql->error);
+ }
+
+ # of course, we want to delete all bookmarks as well
+ $query = sprintf ("DELETE FROM bookmark WHERE childof IN (%s) AND user='%s'",
+ $mysql->escape ($folders),
+ $mysql->escape ($username));
+ if (!$mysql->query ($query)) {
+ message ($mysql->error);
+ }
+
+ # now delete the folder itself
+ $query = sprintf ("DELETE FROM folder WHERE id=%d AND user='%s'",
+ $mysql->escape ($folderid),
+ $mysql->escape ($username));
+ if (!$mysql->query ($query)) {
+ message ($mysql->error);
+ }
+
+ ?>
+
+
+
+ escape ($folderid),
+ $mysql->escape ($username));
+
+ if ($mysql->query ($query)) {
+ if (mysql_num_rows ($mysql->result) == 0){
+ message ("Folder does not exist");
+ }
+ $row = mysql_fetch_object ($mysql->result);
+ ?>
+
+ Delete this Folder?
+ public ? $folder_opened_public : $folder_opened; echo " " . $row->name; ?>
+
+ " method="POST" name="fdelete">
+
+
+
+
+ error);
+ }
+}
+
+require_once (ABSOLUTE_PATH . "footer.php");
+?>
\ No newline at end of file
diff --git a/folder_edit.php b/folder_edit.php
new file mode 100644
index 0000000..ba1f8c0
--- /dev/null
+++ b/folder_edit.php
@@ -0,0 +1,104 @@
+escape ($folderid),
+ $mysql->escape ($username));
+
+ if ($mysql->query ($query)) {
+ if (mysql_num_rows ($mysql->result) == 1) {
+ $row = mysql_fetch_object ($mysql->result);
+ }
+ else {
+ message ("No Folder to edit.");
+ }
+ }
+ else {
+ message ($mysql->error);
+ }
+ ?>
+
+ Edit Folder
+ " id="fedit" method="POST">
+ public ? $folder_opened_public : $folder_opened; ?>
+ public) {echo "checked";} ?>> Public
+ Inherit Public Status to all Subfolders and Bookmarks
+
+
+
+
+
+ escape ($foldername),
+ $mysql->escape ($public),
+ $mysql->escape ($folderid),
+ $mysql->escape ($username));
+
+ if ($mysql->query ($query)) {
+ if ($inherit) {
+ require_once (ABSOLUTE_PATH . "folders.php");
+ $tree = & new folder;
+ $tree->get_children ($folderid);
+ if (count ($tree->get_children) > 0) {
+ $sub_folders = implode (",", $tree->get_children);
+
+ # set subfolders to public
+ $query = sprintf ("UPDATE folder SET public='%d' WHERE id IN (%s) AND user='%s'",
+ $mysql->escape ($public),
+ $mysql->escape ($sub_folders),
+ $mysql->escape ($username));
+ if (! $mysql->query ($query)) {
+ message ($mysql->error);
+ }
+
+ $sub_folders .= "," . $folderid;
+ # set bookmarks to public as well
+ $query = sprintf ("UPDATE bookmark SET public='%d' WHERE childof IN (%s) AND user='%s'",
+ $mysql->escape ($public),
+ $mysql->escape ($sub_folders),
+ $mysql->escape ($username));
+ if ($mysql->query ($query)) {
+ echo '';
+ }
+ else {
+ message ($mysql->error);
+ }
+ }
+ else {
+ $query = sprintf ("UPDATE bookmark SET public='%d' WHERE childof='%d' AND user='%s'",
+ $mysql->escape ($public),
+ $mysql->escape ($folderid),
+ $mysql->escape ($username));
+ if ($mysql->query ($query)) {
+ echo '';
+ }
+ else {
+ message ($mysql->error);
+ }
+ }
+ }
+ echo '';
+ }
+ else {
+ message ($mysql->error);
+ }
+}
+
+require_once (ABSOLUTE_PATH . "footer.php");
+?>
diff --git a/folder_move.php b/folder_move.php
new file mode 100644
index 0000000..789db3f
--- /dev/null
+++ b/folder_move.php
@@ -0,0 +1,60 @@
+get_path_to_root ($folderid);
+
+if ($sourcefolder == "") {
+ ?>
+
+ Move Folder
+ " method="POST" id="fmove">
+
+
+
+ make_tree (0);
+ $tree->print_tree ();
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+ self.close();';
+}
+else if (in_array ($sourcefolder, $parents)){
+ message ("A folder cannot be moved to one of its own subfolders");
+}
+else if ($sourcefolder != "" && $sourcefolder != $folderid){
+ $query = sprintf ("UPDATE folder SET childof='%d' WHERE id='%d' AND user='%s'",
+ $mysql->escape ($folderid),
+ $mysql->escape ($sourcefolder),
+ $mysql->escape ($username));
+
+ if ($mysql->query ($query)) {
+ echo "Folder moved \n";
+ echo '';
+ }
+ else {
+ message ($mysql->error);
+ }
+}
+require_once (ABSOLUTE_PATH . "footer.php");
+?>
diff --git a/folder_new.php b/folder_new.php
new file mode 100644
index 0000000..97f4341
--- /dev/null
+++ b/folder_new.php
@@ -0,0 +1,41 @@
+
+
+ New Folder
+ " id="fnew" method="POST">
+
+ Public
+
+
+
+
+
+ escape ($folderid),
+ $mysql->escape ($foldername),
+ $mysql->escape ($public),
+ $mysql->escape ($username));
+ if ($mysql->query ($query)) {
+ echo "Folder successfully created \n";
+ echo '';
+ }
+ else {
+ message ($mysql->error);
+ }
+}
+
+require_once (ABSOLUTE_PATH . "footer.php");
+?>
\ No newline at end of file
diff --git a/folders.php b/folders.php
new file mode 100644
index 0000000..6e87cc2
--- /dev/null
+++ b/folders.php
@@ -0,0 +1,312 @@
+username = $GLOBALS['username'];
+ $this->folderid = $GLOBALS['folderid'];
+ $this->folders = array ();
+ $this->tree = array ();
+ $this->get_children = array ();
+ $this->level = 0;
+ $this->foreign_username = false;
+ $this->expand = $GLOBALS['expand'];
+
+ if ($user) {
+ $this->get_shared_data ($user);
+ }
+ else {
+ $this->get_user_data ();
+ }
+
+ if ($settings['simple_tree_mode']) {
+ $this->expand = $this->get_path_to_root ($this->folderid);
+ }
+
+ # searching for invalid folderid in GET variable
+ if ( ! array_key_exists ($this->folderid, $this->folders)) {
+ $this->folderid = 0;
+ }
+
+ # searching for invalid expand entries
+ foreach ($this->expand as $key => $value) {
+ if (! array_key_exists ($value, $this->folders)) {
+ unset ($this->expand[$key]);
+ }
+ }
+ }
+
+ function get_user_data () {
+ global $mysql;
+ $query = sprintf ("SELECT id, childof, name, public FROM folder WHERE user='%s' AND deleted!='1' ORDER BY name",
+ $mysql->escape ($_SESSION['username']));
+ if ($mysql->query ($query)) {
+ while ($row = mysql_fetch_assoc ($mysql->result)) {
+ $this->folders[$row['id']] = $row;
+ if (!isset ($this->children[$row['childof']])) {
+ $this->children[$row['childof']] = array ();
+ }
+ array_push ($this->children[$row['childof']], $row['id']);
+ }
+ }
+ else {
+ message ($mysql->error);
+ }
+ }
+
+ function get_shared_data ($username) {
+ global $mysql;
+
+ # does the user exist in the database?
+ if (check_username ($username)) {
+ $this->foreign_username = $username;
+ }
+ else {
+ $this->foreign_username = $GLOBALS['username'];
+ }
+
+ # get all shared folders for the given user
+ $query = "SELECT id, childof, name, public FROM folder WHERE public='1' AND deleted!='1'AND user='$this->foreign_username' ORDER BY 'name'";
+ if ($mysql->query ($query)) {
+ # make two arrays:
+ # 1) $children containing arrays with children. the keys of these arrays are the id's of the parents
+ # 2) $folders containing arrays with folder settings (id, childof, name, public)
+ $shared_children = array ();
+ while ($row = mysql_fetch_assoc ($mysql->result)) {
+ $this->folders[$row['id']] = $row;
+ if (!isset ($this->children[$row['childof']])) {
+ $this->children[$row['childof']] = array ();
+ }
+ array_push ($this->children[$row['childof']], $row['id']);
+ array_push ($shared_children, $row['id']);
+ }
+
+ $this->children[0] = array ();
+ # the childof fields of each folder with no parent is being set to 0, so it becomes a child of the root folder
+ foreach ($this->folders as $value) {
+ if (in_array ($value['childof'], $shared_children)) {
+ continue;
+ }
+ else {
+ array_push ($this->children[0], $value['id']);
+ $this->folders[$value['id']]['childof'] = 0;
+ }
+ }
+ }
+ else {
+ message ($mysql->error);
+ }
+ }
+
+
+ # assembles the tree
+ function make_tree ($id) {
+ if (isset ($this->children)){
+ $this->level++;
+ if (isset ($this->children[$id])) {
+ foreach ($this->children[$id] as $value) {
+ array_push ($this->tree, array (
+ 'level' => $this->level,
+ 'id' => $value,
+ 'name' => $this->folders[$value]['name'],
+ 'public' => $this->folders[$value]['public'],
+ ));
+ # check for children
+ $symbol = &$this->tree[count ($this->tree) - 1]['symbol'];
+ if (isset ($this->children[$value])) {
+ if (in_array ($value, $this->expand)) {
+ $symbol = 'minus';
+ $this->make_tree ($value);
+ }
+ else {
+ $symbol = 'plus';
+ }
+ }
+ else {
+ $symbol = '';
+ }
+ }
+ }
+ $this->level--;
+ }
+ }
+
+ # draws the tree
+ function print_tree () {
+ global $settings, $folder_opened, $folder_closed, $folder_opened_public, $folder_closed_public, $plus, $minus, $neutral;
+
+ # depending on whom's bookmarks are being displayed, we set some variables differently
+ if ($this->foreign_username) {
+ $root_folder_name = $this->foreign_username . "'s Bookmarks";
+ $user_var = "&user=$this->foreign_username";
+ }
+ else {
+ $root_folder_name = $settings['root_folder_name'];
+ $user_var = "";
+ }
+
+ $root_folder = array (
+ 'level' => 0,
+ 'id' => 0,
+ 'name' => $root_folder_name,
+ 'symbol' => null,
+ 'public' => 0,
+ );
+ array_unshift ($this->tree, $root_folder);
+
+ foreach ($this->tree as $key => $value) {
+ # this is the begining of the line that shows a folder
+ # with the symbol (plus, minus or neutral)
+ $spacer = '';
+ echo $spacer;
+
+ if ($value['id'] == $this->folderid) {
+ $folder_name = '
' . $value['name'] . ' ';
+ if (!$this->foreign_username && $value['public']) {
+ $folder_image = $folder_opened_public;
+ }
+ else {
+ $folder_image = $folder_opened;
+ }
+ }
+ else {
+ $folder_name = $value['name'];
+ if (!$this->foreign_username && $value['public']) {
+ $folder_image = $folder_closed_public;
+ }
+ else {
+ $folder_image = $folder_closed;
+ }
+ }
+
+ if ($key > 5) {
+ $ankor = "#" . $this->tree[$key - 5]['id'];
+ }
+ else {
+ $ankor = "";
+ }
+
+ if ($value['symbol'] == "plus" || $value['symbol'] == "minus") {
+ if ($value['symbol'] == "plus") {
+ $symbol = $plus;
+ $expand_s = $this->add_to_expand_list ($value['id']);
+ if ($settings['fast_folder_plus']) {
+ $expand_f = $expand_s;
+ }
+ else {
+ $expand_f = $this->expand;
+ }
+ }
+ else if ($value['symbol'] == "minus") {
+ $symbol = $minus;
+ $expand_s = $this->remove_from_expand_list ($value['id']);
+ if ($settings['fast_folder_minus'] && $value['id'] == $this->folderid) {
+ $expand_f = $expand_s;
+ }
+ else {
+ $expand_f = $this->expand;
+ }
+ }
+ if ($settings['fast_symbol']) {
+ $folderid = $value['id'];
+ }
+ else {
+ $folderid = $this->folderid;
+ }
+ # this prints the symbol (plus or minus) with its appropriate link
+ echo '
' . $symbol . ' ';
+ }
+ else {
+ $symbol = $neutral;
+ $expand_f = $this->expand;
+ echo $symbol;
+ }
+
+ # this prints the folder name with its appropriate link
+ echo '
' . $folder_image . " " . $folder_name . ' ';
+ # and this is the end of the line
+ echo "
\n";
+ }
+ }
+
+ ###
+ ### removes a value from the expand list
+ ###
+ function remove_from_expand_list ($id){
+ $expand = $this->expand;
+ foreach ($expand as $key => $value) {
+ if ($value == $id) {
+ unset ($expand[$key]);
+ }
+ }
+ return $expand;
+ }
+
+ ###
+ ### adds a value to the expand list
+ ###
+ function add_to_expand_list ($id){
+ $expand = $this->expand;
+ array_push ($expand, $id);
+ return $expand;
+ }
+
+ ###
+ ### returns an array containing all folder id's from
+ ### a given folder up to the root folder
+ ###
+ function get_path_to_root ($id) {
+ $path = array ();
+ while ($id > 0) {
+ array_push ($path, $id);
+ if (!isset ($this->folders[$id])) {
+ #echo "Folder Nr. $id does not have a parent";
+ return array ();
+ }
+ else {
+ $id = $this->folders[$id]['childof'];
+ }
+ }
+ return $path;
+ }
+
+ ###
+ ### prints a path
+ ###
+ function print_path ($id) {
+ global $settings;
+ $parents = $this->get_path_to_root ($id);
+ $parents = array_reverse ($parents);
+ # the following if condition has been disabled. could be enabled to
+ # allow the "show_root_folder" function.
+ #if ($GLOBALS['show_root_folder']){
+ $path = $GLOBALS['delimiter'] . $settings['root_folder_name'];
+ #}
+ foreach ($parents as $value) {
+ $path .= $GLOBALS['delimiter'] . $this->folders[$value]['name'];
+ }
+ return $path;
+ }
+
+ ###
+ ### returns an array containing all folder id's that
+ ### are children from a given folder
+ ###
+ function get_children ($id) {
+ if (isset ($this->children[$id])) {
+ foreach ($this->children[$id] as $value) {
+ array_push ($this->get_children, $value);
+ $this->get_children ($value);
+ }
+ }
+ }
+}
+
+?>
diff --git a/footer.php b/footer.php
new file mode 100644
index 0000000..27af208
--- /dev/null
+++ b/footer.php
@@ -0,0 +1,7 @@
+
+