diff --git a/bookmarks/delete_bookmark.inc.php b/bookmarks/delete_bookmark.inc.php index 84c8635..fdba65c 100644 --- a/bookmarks/delete_bookmark.inc.php +++ b/bookmarks/delete_bookmark.inc.php @@ -4,26 +4,20 @@ logged_in_only(); if (!empty($username) && $username !== 'demo') { -debug_logger(name:'SERVER[QUERY_STRING]', variable:$_SERVER['QUERY_STRING'], file:__FILE__, function:__FUNCTION__); $qs = ltrim($_SERVER['QUERY_STRING'], '?'); parse_str($qs, $qs_arr); - $icons_to_delete = $qs_arr['bookmarks']; + $bmlist = $qs_arr['bmlist']; // Comma separated string of bookmark ID's, e.g. 4186,4193,5825 + $icons_to_delete = $qs_arr['bookmarks']; // Array of favicon name's. - $bmlist = $qs_arr['bmlist']; - -debug_logger(name:'bmlist', variable:$bmlist, file:__FILE__, function:__FUNCTION__); -debug_logger(name:'icons_to_delete', variable:$icons_to_delete, file:__FILE__, function:__FUNCTION__); - - - $query = sprintf(" + $query_delete = sprintf(" DELETE FROM `obm_bookmarks` WHERE `id` IN (%s) AND `user`='%s'", $mysql->escape($bmlist), $mysql->escape($username) ); - if ($mysql->query($query)) { + if ($mysql->query($query_delete)) { $mysql->query(" ALTER TABLE `obm_bookmarks` AUTO_INCREMENT = 1" @@ -36,13 +30,21 @@ foreach ($icons_to_delete as $favicon) { if (! str_contains($favicon, 'bookmark.gif')) { - if (is_file(DOC_ROOT .'/icons/'. $favicon)) { - if (!str_contains($favicon, 'bookmark')) { - unlink(DOC_ROOT .'/icons/'. $favicon); + $count_query = sprintf(" + SELECT COUNT(`id`) AS icon_cnt + FROM `obm_bookmarks` + WHERE `favicon` = '%s'", + $mysql->escape($favicon) + ); + if ($mysql->query($count_query)) { + if (mysql_result($mysql->result, 0) > 1) { + // Skip deletion if more than one bookmark uses the same favicon. + continue; } } - else { - debug_logger(name:'ERROR -- No favicon was found for deletion.', variable:$favicon, file:__FILE__, function:__FUNCTION__); + + if (is_file(DOC_ROOT .'/icons/'. $favicon)) { + unlink(DOC_ROOT .'/icons/'. $favicon); } } } @@ -50,7 +52,6 @@ echo ""; } else { - echo 'Demo users cannot delete folders.

' . PHP_EOL; + echo 'Demo users cannot delete bookmarks.

' . PHP_EOL; echo ''; } - diff --git a/favicon.php b/favicon.php index 8ff172e..fab7f1f 100644 --- a/favicon.php +++ b/favicon.php @@ -215,13 +215,14 @@ function get_favicon_url() { } - function get_html_dom($url) { + function scrape_html($url) { global $cfg; // If a saved URL changes and gets redirected to a new one... $options = [ + CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36', CURLOPT_URL => $url, - CURLOPT_USERAGENT => 'Mozilla/5.0 (compatible; MSIE 7.01; Windows NT 5.0)', - CURLOPT_RETURNTRANSFER => 1, + CURLOPT_FAILONERROR => true, + CURLOPT_RETURNTRANSFER => true, CURLOPT_CONNECTTIMEOUT => 2, CURLOPT_TIMEOUT => 10, /* Lets you use this script when there is redirect on the server. */ @@ -267,10 +268,6 @@ function rename_favicon($domain) { $parsed = parse_url($domain); $host_name = $parsed['host']; $host_name = str_replace('.', '-', $host_name); - $parts = explode('-', $host_name); - $last = array_pop($parts); - $parts = [implode('-', $parts), $last]; // Get domain w/o the domain extension. - $host_name = $parts[0]; $host_name = str_replace('www-', '', $host_name); $ext = pathinfo($this->favicon_url, PATHINFO_EXTENSION); $ext = strlen($ext) < 3 ? 'png' : $ext;