Skip to content

Commit

Permalink
Remove debug_logger() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
s22-tech committed Jul 1, 2024
1 parent 6fa8ccd commit 7add993
Show file tree
Hide file tree
Showing 28 changed files with 25 additions and 270 deletions.
3 changes: 1 addition & 2 deletions bookmarks/bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ function list_bookmarks($bookmarks, $show_checkbox, $show_folder, $show_icon, $s

echo '<form name="bookmarks" action="" class="nav">' . PHP_EOL;

debug_logger(name:'BOOKMARKS', variable: $bookmarks, file: __FILE__, function: __FUNCTION__);

foreach ($bookmarks as $value) {
echo '<div class="bookmark">' . PHP_EOL;
Expand Down Expand Up @@ -190,7 +189,6 @@ function list_bookmarks($bookmarks, $show_checkbox, $show_folder, $show_icon, $s
// The favicon.
echo $tab . '<div class="link">' . PHP_EOL;
echo $tab . $tab;
// echo '<pre>'; print_r($value); echo '</pre>'; //:debug
if ($show_icon) {
if ($value['favicon']) { /* && is_file($value['favicon']) */
echo '<img src="'. $cfg['sub_dir'] .'/icons/'. $value['favicon'] .'" width="'. $cfg['icon_w'] .'" height="'. $cfg['icon_h'] .'" alt="">'. PHP_EOL;
Expand Down Expand Up @@ -248,3 +246,4 @@ function set_last_visit($id) {
xmlhttp.send();
}
</script>

3 changes: 1 addition & 2 deletions bookmarks/delete_bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,10 @@ function delete_bookmarks($bm_to_delete) {
unlink(DOC_ROOT .'/icons/'. $favicon);
}
else {
debug_logger(name: 'ERROR -- Favicon was not found: ', variable: $favicon, file: __FILE__, function: __FUNCTION__);
}
}
}
// Close the window.
echo "<script> reloadclose(); </script>";
}
?>
?>
3 changes: 1 addition & 2 deletions bookmarks/edit_bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
require_once(realpath(DOC_ROOT . '/includes/favicon.inc.php'));
$favicon = new Favicon($used_url);
$new_fav = $favicon->favicon;
debug_logger(name:'favicon->favicon >>', variable:$new_fav, file:__FILE__, function:__FUNCTION__);
if ($new_fav) {
$update_query = sprintf("
UPDATE `obm_bookmarks`
Expand All @@ -152,7 +151,6 @@
$mysql->escape($username),
$mysql->escape($bm_array[0])
);
debug_logger(name:'bm-query', variable:$update_query, file:__FILE__, function:__FUNCTION__);
if (!$mysql->query($update_query)) {
message($mysql->error);
}
Expand Down Expand Up @@ -245,3 +243,4 @@

require_once(realpath(DOC_ROOT . '/includes/footer.inc.php'));
?>

10 changes: 1 addition & 9 deletions bookmarks/move_bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@
$folderid = set_get_folderid(); // This allows the root folder to be selected in the list.

$bm_array = set_post_num_array('bmlist'); // Returns an array.
debug_logger( name:'bm_array-1', variable: print_r($bm_array, true), file: __FILE__, function: __FUNCTION__ );

if (count($bm_array) == 0) {
$bm_array = set_get_num_array('bmlist'); // Returns an array from the URL.
debug_logger( name:'bm_array-2', variable: print_r($bm_array, true), file: __FILE__, function: __FUNCTION__ );
?>

<h2 class="title">Move bookmarks to:</h2>
<form action="<?php echo $_SERVER['SCRIPT_NAME'] . "?folderid=" . $folderid; ?>" method="post">
<div style="width:100%; height:330px; overflow:auto;">

<?php
debug_logger( name:'form-bm_array', variable: $bm_array, file: __FILE__, function: __FUNCTION__ );
debug_logger( name:'form-folderid', variable: $folderid, file: __FILE__, function: __FUNCTION__ );
require_once(realpath(DOC_ROOT . '/folders/folder.php'));
$tree = new Folder();
$tree->make_tree(0);
Expand All @@ -41,11 +37,9 @@
<?php
}
elseif ($folderid == '') {
debug_logger( name:'folderid-empty', variable: $folderid, file: __FILE__, function: __FUNCTION__ );
message('No destination Folder selected.');
}
else {
debug_logger( name:'3rd-bm_array', variable: $bm_array, file: __FILE__, function: __FUNCTION__ );
$query = sprintf("
UPDATE `obm_bookmarks`
SET `childof` = %d
Expand All @@ -56,17 +50,15 @@
);

if ($mysql->query($query)) {
debug_logger( name:'success', variable: $query, file: __FILE__, function: __FUNCTION__ );
echo 'Bookmarks moved.<br>'. PHP_EOL;
echo '<script> reloadclose(); </script>';
}
else {
debug_logger( name:'error', variable: $query, file: __FILE__, function: __FUNCTION__ );
message($mysql->error);
}
}

debug_logger( name:'------------', variable: 'separator', file: __FILE__, function: __FUNCTION__ );

require_once(realpath(DOC_ROOT . '/includes/footer.inc.php'));
?>

12 changes: 1 addition & 11 deletions bookmarks/new_bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,18 @@
$bm_id = mysqli_insert_id($mysql->conn); // Returns the value generated for an AUTO_INCREMENT column by the last query.
// https://www.php.net/manual/en/mysqli.insert-id.php
// Using $mysql->insert_id produces "Undefined property: mysql::$insert_id".
// $bm_id = $pdo->lastInsertId(); // PDO equivalent -- https://www.php.net/pdo.lastinsertid
}
else {
message($mysql->error);
}
unset($_SESSION['title'], $_SESSION['url']);

debug_logger(variable:$post_url, name:'post_url', file:__FILE__, function:__FUNCTION__);

///////////////////////////
// SAVE Favicon
// Saving the favicon in a separate second step is done because
// we want to make sure the bookmark is saved in any case,
// since the favicon is not as important.
///////////////////////////
if ($settings['show_bookmark_icon']) {
require_once(realpath(DOC_ROOT . '/includes/favicon.inc.php'));
$favicon = new Favicon($post_url);
debug_logger(variable:print_r($favicon, true), name:'favicon-object', file:__FILE__, function:__FUNCTION__);

if (!empty($favicon->favicon)) {
$update_query = sprintf("
Expand All @@ -143,16 +136,13 @@
$mysql->escape($username),
$mysql->escape($bm_id)
);
debug_logger(variable:$update_query, name:'update-query', file:__FILE__, function:__FUNCTION__);
if (!$mysql->query($update_query)) {
message($mysql->error);
}
$icon = '<img src="/icons/'.$favicon->favicon.'">';
}
else {
$icon = $bookmark_image;
debug_logger(variable:$icon, name:'favicon->favicon was NOT set', file:__FILE__, function:__FUNCTION__);
debug_logger(variable:debug_backtrace(), name:'debug_backtrace()', file:__FILE__, function:__FUNCTION__);
}
}

Expand All @@ -170,4 +160,4 @@
}
}
require_once(realpath(DOC_ROOT . '/includes/footer.inc.php'));
?>
?>
74 changes: 0 additions & 74 deletions favicon.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,24 @@ function __construct($url) {
$this->notes = '';

if ($settings['show_bookmark_icon']) {
debug_logger(name:'--------', variable: '-------------------------', file: '--------', function: '--------');
debug_logger(name:'URL', variable: $url, newline: false, file: __FILE__, function: __FUNCTION__, time: true);

if ($this->parsed_url = $this->return_parse_url($url)) {
if ($this->favicon_url = $this->get_favicon_url()) {
$this->download_favicon_image();
$this->icon_name = $this->rename_favicon($url . '/'. $this->temp_icon_name);
$favicon_url_path = DOC_ROOT .'/icons/'. $this->icon_name;

debug_logger(name:'this->temp_icon_name', variable: $this->temp_icon_name, newline: false, file: __FILE__, function:__FUNCTION__);
debug_logger(name:'this->favicon_url', variable: $this->favicon_url, newline: false, file: __FILE__, function:__FUNCTION__);
debug_logger(name:'this->icon_name', variable: $this->icon_name, newline: false, file: __FILE__, function:__FUNCTION__);
debug_logger(name:'favicon_url_path', variable: $favicon_url_path, file: __FILE__, function:__FUNCTION__);

$tmp_file = DOC_ROOT . '/tmp/'. $this->temp_icon_name;
[$fav_ext, $ident, $icons] = $this->identify_fav($tmp_file);
debug_logger(name:'tmp_file', variable: $tmp_file, newline: false, file: __FILE__, function:__FUNCTION__);
debug_logger(name:'fav_ext', variable: $fav_ext, file: __FILE__, function:__FUNCTION__);

if ($cfg['convert_favicons']) {
$this->favicon = $this->convert_favicon($tmp_file, $fav_ext, $ident, $icons);
debug_logger(name:'converted favicon', variable: $this->favicon, file: __FILE__, function:__FUNCTION__);
}
else {
// Move the file from the tmp dir.
rename($tmp_file, $favicon_url_path);
$this->favicon = $favicon_url_path;
debug_logger(name:'no conversion favicon', variable: $this->favicon, file: __FILE__, function:__FUNCTION__);
}
}
else {
Expand All @@ -87,29 +77,19 @@ function convert_favicon($tmp_file, $fav_ext, $ident, $icons) : string {
$tmp_ext = pathinfo($tmp_file, PATHINFO_EXTENSION);
$new_ext = 'png';

debug_logger(name:'ident-stat', variable: $ident, newline: false, file: __FILE__, function:__FUNCTION__);
debug_logger(name:'tmp_file', variable: $tmp_file, newline: false, file: __FILE__, function:__FUNCTION__);
debug_logger(name:'tmp_ext', variable: $tmp_ext, newline: false, file: __FILE__, function:__FUNCTION__);
debug_logger(name:'fav_ext', variable: $fav_ext, newline: false, file: __FILE__, function:__FUNCTION__);
debug_logger(name:'icons', variable: $icons, newline: false, file: __FILE__, function:__FUNCTION__);

$new_name = $this->icon_name;
debug_logger(name:'new_name1', variable: $new_name, newline: false, file: __FILE__, function:__FUNCTION__);
$converted_file_path = DOC_ROOT . '/tmp/'. $new_name;
$save_path_name = DOC_ROOT . '/icons/'. $new_name;

if ($ident && $fav_ext !== 'svg') {
$new_name = str_replace($tmp_ext, $new_ext, $new_name);
debug_logger(name:'new_name2', variable: $new_name, newline: false, file: __FILE__, function:__FUNCTION__);
$converted_file_path = DOC_ROOT . '/tmp/'. $new_name;
debug_logger(name:'converted_file_path', variable: $converted_file_path, newline: false, file: __FILE__, function:__FUNCTION__);
$convert = "{$cfg['convert']} $tmp_file -resize {$cfg['icon_size']}\> -unsharp 0x1 $converted_file_path";
debug_logger(name:'convert-cmd', variable: $convert, newline: false, file: __FILE__, function:__FUNCTION__);

// Convert image to .png, and resize to $cfg['icon_size'] if original is different.
## https://legacy.imagemagick.org/Usage/resize/
system($convert, $status);
debug_logger(name:'SUCCESS--conversion status', variable: $status, file: __FILE__, function:__FUNCTION__);

if (count($icons) > 1) {
$multi_ico_name = str_replace('.'.$new_ext, '-0.'.$new_ext, $converted_file_path);
Expand All @@ -124,14 +104,9 @@ function convert_favicon($tmp_file, $fav_ext, $ident, $icons) : string {
$tmp_file .= '.'. $tmp_ext;
}
$rename = rename($tmp_file.'.png', $save_path_name); // Move & rename the file.
debug_logger(name:'MOVED--no conversion', variable: $this->icon_name, newline: false, file: __FILE__, function:__FUNCTION__);
debug_logger(name:'tmp_file2', variable: $tmp_file, newline: false, file: __FILE__, function:__FUNCTION__);
debug_logger(name:'save_path_name2', variable: $save_path_name, newline: false, file: __FILE__, function:__FUNCTION__);
debug_logger(name:'rename-move2', variable: $rename, file: __FILE__, function:__FUNCTION__);
}

if (file_exists($tmp_file)) {
debug_logger(name:'tmp_file_exists - YES', variable:'', file: __FILE__, function:__FUNCTION__);
unlink($tmp_file);
}
if (count($icons) > 1) {
Expand All @@ -154,14 +129,11 @@ function convert_favicon($tmp_file, $fav_ext, $ident, $icons) : string {
function download_favicon_image() {
global $cfg;
$save_path_name = DOC_ROOT . '/tmp/'. $this->temp_icon_name;
debug_logger(name:'this->favicon_url', variable: $this->favicon_url, newline: false, file: __FILE__, function: __FUNCTION__);
debug_logger(name:'temp_icon_name', variable: $save_path_name, newline: false, file: __FILE__, function: __FUNCTION__);

if (str_contains($this->favicon_url, 'base64')) {
$this->notes = 'This favicon was in base64.';
$data = preg_replace("#$this->url#", '', $this->favicon_url);
file_put_contents($save_path_name.'.png', file_get_contents($data));
debug_logger(name:'data', variable: $data, newline: false, file: __FILE__, function: __FUNCTION__);
}
else {
$open_file_in_binary = fopen($save_path_name, 'wb');
Expand All @@ -185,12 +157,9 @@ function download_favicon_image() {

// Close the file pointer.
fclose($open_file_in_binary);
debug_logger(name:'response', variable: $response, file: __FILE__, function: __FUNCTION__);
}

if (admin_only()) {
// $bytes = file_put_contents($save_path_name, $response);
// debug_logger(name:'bytes saved', variable: $bytes, file: __FILE__, function: __FUNCTION__);
}

return true;
Expand All @@ -201,43 +170,32 @@ function download_favicon_image() {
function get_favicon_url() {
$host_url = $this->parsed_url['scheme'] . '://' . $this->parsed_url['host'];
$host_url = rtrim($host_url, '/');
debug_logger(name:'host_url', variable: $host_url, newline: false, file: __FILE__, function:__FUNCTION__);

## https://github.com/simplehtmldom/simplehtmldom
## https://sourceforge.net/p/simplehtmldom/bugs/
## https://simplehtmldom.sourceforge.io/docs/1.9/
$dom = new HtmlWeb();
$html = $dom->load($host_url);

// DOES THIS SECTION DO ANYTHING BENEFICIAL?
if (empty($html)) {
// sleep(3);
// $html_string = $this->scrape_html($host_url);
// $html = str_get_html($html_string);
// if (empty($html)) {
echo '<span style="color:red">&bull; favicon.php &mdash; $html is blank.<br></span>';
return;
// }
}

debug_logger(name:'html', variable: $html, file: __FILE__, function:__FUNCTION__);

$favicon_url = '';
foreach ($html->find('link') as $e) {
if (!empty($e->rel)) {
if (strtolower(trim($e->rel)) === 'shortcut icon' || strtolower(trim($e->rel)) === 'icon') {
debug_logger(name:'••• e->rel', variable: $e->rel, newline: false, file: __FILE__, function:__FUNCTION__);
$favicon_url = $e->href;
break;
}
elseif (strtolower(trim($e->rel)) === 'apple-touch-icon') {
debug_logger(name:'••• e->rel', variable: $e->rel, newline: false, file: __FILE__, function:__FUNCTION__);
$favicon_url = $e->href;
break;
}
}
}
debug_logger(name:'get-favicon--ORIG', variable: $favicon_url, newline: false, file: __FILE__, function:__FUNCTION__);

if (empty($favicon_url)) return; // So as not to populate the /tmp/ directory.

Expand All @@ -249,21 +207,17 @@ function get_favicon_url() {
// If link doesn't start with http...
if (str_starts_with($favicon_url, '//')) {
$favicon_url = 'https:'. $favicon_url;
debug_logger(name:'get-favicon--2', variable: $favicon_url, newline: false, file: __FILE__, function: __FUNCTION__);
}
elseif (str_starts_with($favicon_url, '/')) {
$favicon_url = $host_url . $favicon_url;
debug_logger(name:'get-favicon--3', variable: $favicon_url, newline: false, file: __FILE__, function: __FUNCTION__);
}
elseif (!str_starts_with($favicon_url, 'http')) {
$favicon_url = $host_url .'/'. $favicon_url;
debug_logger(name:'get-favicon--4', variable: $favicon_url, newline: false, file: __FILE__, function: __FUNCTION__);
}

$html->clear();
unset($html);

debug_logger(name:'get-favicon--FINAL', variable: $favicon_url, file: __FILE__, function: __FUNCTION__);

$this->temp_icon_name = basename(parse_url($favicon_url, PHP_URL_PATH));

Expand Down Expand Up @@ -304,7 +258,6 @@ function return_parse_url($url) {
$parsed['scheme'] = 'https';
}
if (empty($parsed['host']) || $parsed['host'] == '') {
debug_logger(name:'parsed[host]', variable: $parsed['host'], file: __FILE__, function: __FUNCTION__);
return false;
}
if (empty($parsed['port']) || $parsed['port'] == '') {
Expand All @@ -325,15 +278,9 @@ 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];
// debug_logger(name:'•••host_name', variable: $host_name, newline: false, file: __FILE__, function:__FUNCTION__);
$host_name = str_replace('www-', '', $host_name);
$ext = pathinfo($this->favicon_url, PATHINFO_EXTENSION);
$ext = strlen($ext) < 3 ? 'png' : $ext;
debug_logger(name:'•••favicon_name', variable: $host_name . '.' . $ext, file: __FILE__, function:__FUNCTION__);
return $host_name . '.' . $ext;
}

Expand All @@ -342,8 +289,6 @@ function identify_fav($tmp_file) {
global $cfg;
$tmp_ext = pathinfo($tmp_file, PATHINFO_EXTENSION);
exec($cfg['identify'] .' '. $tmp_file, $output);
debug_logger(name:'identify output', variable: $output, newline: false, file: __FILE__, function:__FUNCTION__);
debug_logger(name:'identify tmp_file', variable: $tmp_file, newline: false, file: __FILE__, function:__FUNCTION__);

$icons = [];
if ($output) {
Expand All @@ -353,15 +298,11 @@ function identify_fav($tmp_file) {
}
$idents = explode(' ', $output[0]);
$file_ext = strtolower($idents[1]);
debug_logger(name:'identify idents[0]', variable: $idents[0], newline: false, file: __FILE__, function:__FUNCTION__);
debug_logger(name:'identify idents[1]', variable: $file_ext, newline: false, file: __FILE__, function:__FUNCTION__);
$file_ext = ($file_ext === 'jpeg') ? 'jpg' : $file_ext;
debug_logger(name:'identify file_ext', variable: $file_ext, newline: false, file: __FILE__, function:__FUNCTION__);

return [$file_ext, true, $icons];
}
else {
debug_logger(name:'identify return', variable:'', newline: false, file: __FILE__, function:__FUNCTION__);
return ['png', false, $icons];
}
}
Expand Down Expand Up @@ -392,18 +333,3 @@ function get_current_url($url) {

}

__halt_compiler();

Test Icons
• hostinger.com has an ICI file with multiple images
• some site ??? had a base64 image -- Which one was it?

debug_logger(name:$name, variable: $variable, $type, $file, $function)
prints out:
error_log(''. basename($file) .':'.$function.'()->$'. $name .': '. $variable . PHP_EOL, 3, $cfg['error_log']);
e.g.:
• favicon.php:__construct()->$__construct1: https://www.invizbox.com/products/invizbox-2-pro/#select-plan
NOTES:
• If the site's favicon is an svg image, DO NOT convert it. It looks terrible as a png.
• Don't convert icons to jpg. JPEG doesn't offer transparency, so there may be black banding if the image isn't square.
Loading

0 comments on commit 7add993

Please sign in to comment.