Skip to content

Commit

Permalink
Improved favicon deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
s22-tech committed May 30, 2024
1 parent 61b7987 commit 8a9f1ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
35 changes: 18 additions & 17 deletions bookmarks/delete_bookmark.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -36,21 +30,28 @@

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);
}
}
}
// Close the window.
echo "<script> reloadclose(); </script>";
}
else {
echo 'Demo users cannot delete folders.<br><br>' . PHP_EOL;
echo 'Demo users cannot delete bookmarks.<br><br>' . PHP_EOL;
echo '<input type="button" value=" Cancel " onclick="self.close()">';
}

11 changes: 4 additions & 7 deletions favicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8a9f1ff

Please sign in to comment.