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); # The top folder shows up too much on the top. Draw # a little space there. echo '
' . "\n"; 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 = '