function move($var1, $var2) { if ($var1 != "" && $var2 != "") { include '../includes/bookmarks.php'; $action = substr($var1, 0, 1); $var1 = substr($var1, 1); $var2 = substr($var2, 1); switch ($action) { case 'b': $result = move_bookmark($var1, $var2); break; case 'f': $result = move_folder($var1, $var2); break; } return $result; } else { return false; } }
function add_bookmark($url, $folder, $type, $bookmark_json, $name = null, $redirect = 0) { global $site_url; if ($bookmark = parse_bookmark_json($bookmark_json)) { $id = ++$bookmark[1]; } else { $id = 1; } if ($type == 'url' && !isset($name)) { $name = substr($url, 0, 140); //$str = @file_get_contents($url); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $str = curl_exec($ch); curl_close($ch); if (strlen($str)) { preg_match('/\\<title\\>(.*)\\<\\/title\\>/i', $str, $title); $name = isset($title[1]) ? toutf8($title[1]) : ''; } } $hash = sha1($url); if ($type == 'url' && $redirect) { $url = $site_url . 'index.php?action=redirect&u=' . urlencode($url) . '&id=_' . $id; } $new = array('_' . $id => array('id' => $id, 'type' => $type, 'name' => $type == 'url' ? $name : $url, 'date_added' => isset($time) ? $time : time(), 'hash' => $hash)); if ($type == 'url') { $new['_' . $id]['url'] = $url; } $data = $new['_' . $id]; if ($folder) { $levels = array_reverse(explode('_', substr($folder, 1))); foreach ($levels as $level) { if ($level) { $new = array('_' . $level => array('entries' => $new)); } } } if (isset($bookmark[0]['entries']) && is_array($bookmark[0]['entries'])) { $bookmark[0]['entries'] = array_merge_recursive($bookmark[0]['entries'], $new); } else { $bookmark[0]['entries'] = $new; } file_put_contents($bookmark_json, json_encode($bookmark), LOCK_EX); if ($type == 'folder') { move_bookmark($data, ($folder !== '_0' ? $folder : '') . '_-1', $bookmark_json); } return $data; }
$update = array('name' => $_POST['n']); if (isset($_POST['u'])) { $update['url'] = $_POST['u']; } $entry = update_bookmark($_GET['id'], $update, $bookmark_json); if (isset($_POST['l']) && $_POST['l'] !== substr($_GET['id'], 0, strrpos($_GET['id'], '_'))) { $entry = delete_bookmark($_GET['id'], 1, $bookmark_json); move_bookmark($entry, $_POST['l'] . '_0', $bookmark_json); } $anchor = $_POST['l'] . '_' . $entry['id']; } break; case 'move': if (isset($_GET['id']) && $_GET['id']) { $entry = delete_bookmark($_GET['id'], 1, $bookmark_json); move_bookmark($entry, $_GET['position'], $bookmark_json); $anchor = substr($_GET['position'], 0, strrpos($_GET['position'], '_')) . '_' . $entry['id']; } break; case 'sort': if (isset($_GET['id']) && $_GET['id']) { $entry = sort_bookmark($_GET['id'], $_GET['sort'], isset($_GET['recursive']) ? $_GET['recursive'] : 0, $bookmark_json); $anchor = $_GET['id'] == '_0' ? '' : $_GET['id']; } break; case 'export': header('Content-Type: text/plain'); readfile($bookmark_json); exit; } header('Location: index.php' . (isset($anchor) && $anchor ? '#entry-' . $anchor : ''));