Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
s22-tech committed May 25, 2024
1 parent cc25485 commit 73928a9
Show file tree
Hide file tree
Showing 20 changed files with 198 additions and 160 deletions.
2 changes: 1 addition & 1 deletion admin.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require_once(realpath(dirname(__FILE__, 1)) . '/header.php');
require_once(__DIR__ . '/header.php');
logged_in_only();

$delete = set_post_string_var('delete');
Expand Down
20 changes: 10 additions & 10 deletions async_header.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<?php
define ('ABSOLUTE_PATH', dirname (__FILE__) . '/');
require_once(__DIR__ . '/header.php');

if (extension_loaded('zlib')) {
ob_end_clean();
ob_start('ob_gzhandler');
}

require_once (ABSOLUTE_PATH . 'lib/webstart.php');
if (! is_file (ABSOLUTE_PATH . 'config/config.php')) {
require_once(DOC_ROOT . '/lib/webstart.php');
if (! is_file(DOC_ROOT . '/config/config.php')) {
die ('You have to <a href="./install.php">install</a> OpenBookmark.');
}
else {
require_once (ABSOLUTE_PATH . 'config/config.php');
require_once(DOC_ROOT . '/config/config.php');
}
require_once (ABSOLUTE_PATH . 'lib/mysql.php');
require_once(DOC_ROOT . '/lib/mysql.php');
$mysql = new mysql;

require_once (ABSOLUTE_PATH . 'lib/auth.php');
require_once(DOC_ROOT . '/lib/auth.php');
$auth = new Auth;

require_once (ABSOLUTE_PATH . 'lib/lib.php');
require_once (ABSOLUTE_PATH . 'lib/login.php');
require_once(DOC_ROOT . '/lib/lib.php');
require_once(DOC_ROOT . '/lib/login.php');

//if (is_file (ABSOLUTE_PATH . 'install.php')) {
//if (is_file (DOC_ROOT . '/install.php')) {
// message ('Remove "install.php" before using OpenBookmark.');
//}

if ($display_login_form) {
$auth->display_login_form();
require_once (ABSOLUTE_PATH . 'footer.php');
require_once(DOC_ROOT . '/footer.php');
}

3 changes: 2 additions & 1 deletion bookmarks/add_bookmark.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<?php
include(DOC_ROOT . '/bookmarks/new_bookmark.php');

include(dirname(__DIR__, 1) . '/bookmarks/new_bookmark.php');
41 changes: 21 additions & 20 deletions bookmarks/async_bookmarks.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require_once(DOC_ROOT .'/async_header.php');
require_once(dirname(__DIR__, 1) . '/async_header.php');
logged_in_only();

$order = set_get_order();
Expand All @@ -10,33 +10,34 @@
$query = sprintf("
SELECT `title`, `url`, `description`, UNIX_TIMESTAMP(`date`) AS timestamp, `id`, `favicon`, `public`
FROM `obm_bookmarks`
WHERE `user`='%s'
AND `childof`='%d'
AND `deleted`!='1'
WHERE `user` = '%s'
AND `childof` = '%d'
AND `deleted` != '1'
ORDER BY $order[1]",
$mysql->escape($username),
$mysql->escape($folderid)
$mysql->escape($username),
$mysql->escape($folderid)
);

if ($mysql->query($query)) {
$bookmarks = [];
while ($row = mysqli_fetch_assoc($mysql->result)) {
array_push($bookmarks, $row);
}
list_bookmarks($bookmarks,
true,
false,
$settings['show_bookmark_icon'],
true,
$settings['show_bookmark_description'],
$settings['show_column_date'],
$settings['show_column_edit'],
$settings['show_column_move'],
$settings['show_column_delete'],
$settings['show_public'],
true,
false,
'index.php'
list_bookmarks(
bookmarks: $bookmarks,
show_checkbox: true,
show_folder: false,
show_icon: $settings['show_bookmark_icon'],
show_link: true,
show_desc: $settings['show_bookmark_description'],
show_date: $settings['show_column_date'],
show_edit: $settings['show_column_edit'],
show_move: $settings['show_column_move'],
show_delete: $settings['show_column_delete'],
show_share: $settings['show_public'],
show_header: true,
user: false,
scriptname: 'index.php'
);
}
else {
Expand Down
36 changes: 24 additions & 12 deletions bookmarks/delete_bookmark.inc.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?php

require_once(realpath(dirname(__FILE__, 2)) . '/header.min.php');
require_once(dirname(__DIR__, 1) . '/header.min.php');
logged_in_only();

if (!empty($username) && $username !== 'demo') {
debug_logger(name:'SERVER[QUERY_STRING]', variable:$_SERVER['QUERY_STRING'], file:__FILE__, function:__FUNCTION__);
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__);
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("
Expand All @@ -36,21 +35,34 @@

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(*)
FROM `obm_bookmarks`
WHERE `favicon` = '%d'
AND `user` = '%s'",
$mysql->escape($favicon),
$mysql->escape($username)
);
if ($mysql->query($count_query)) {
if (mysql_result($mysql->result, 0) >= 1) {
// Skip deletion if more than one bookmark uses the same favicon.
continue;
}
}

if (is_file(DOC_ROOT .'/icons/'. $favicon)) {
unlink(DOC_ROOT .'/icons/'. $favicon);
}
else {
debug_logger(name:'ERROR -- No favicon was found for deletion.', variable:$favicon, file:__FILE__, function:__FUNCTION__);
debug_logger(name: 'ERROR -- No favicon was found for deletion.', variable: $favicon, file: __FILE__, function: __FUNCTION__);
}
}
}
// 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()">';
}

39 changes: 23 additions & 16 deletions bookmarks/delete_bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ini_set('error_prepend_string', '<pre style="white-space: pre-wrap;">');
ini_set('error_append_string', '</pre>');

require_once(realpath(dirname(__FILE__, 2)) . '/header.php');
require_once(dirname(__DIR__, 1) . '/header.php');
logged_in_only();

echo <<<CSS
Expand Down Expand Up @@ -64,18 +64,19 @@
while ($row = mysqli_fetch_assoc($mysql->result)) {
array_push($bookmarks, $row);
}
list_bookmarks($bookmarks,
false,
false,
$settings['show_bookmark_icon'],
false,
false,
false,
false,
false,
false,
false,
false
list_bookmarks(
bookmarks: $bookmarks,
show_checkbox: false,
show_folder: false,
show_icon: $settings['show_bookmark_icon'],
show_link: false,
show_desc: false,
show_date: false,
show_edit: false,
show_move: false,
show_delete: false,
show_share: false,
show_header: false
);

$bm_string = '';
Expand All @@ -85,9 +86,15 @@
?>

</div>

<div style="float:right">
<a href="<?= $cfg['sub_dir'] ?>/bookmarks/delete_bookmark.inc.php?<?= $query_string . $bm_string; ?>" class="button"> Delete Me </a>

<div>
<div style="float:left">
<input type="button" value="Cancel" onclick="window.close()">
</div>

<div style="float:right">
<a href="<?= $cfg['sub_dir'] ?>/bookmarks/delete_bookmark.inc.php?<?= $query_string . $bm_string; ?>" class="button"> Delete Me </a>
</div>
</div>
<br>
<br>
Expand Down
40 changes: 22 additions & 18 deletions bookmarks/edit_bookmark.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
require_once(realpath(dirname(__FILE__, 2)) . '/header.php');
require_once(dirname(__DIR__, 1) . '/header.php');
logged_in_only();

$bmlist = set_get_num_list('bmlist');
Expand All @@ -17,7 +17,7 @@
$qbmlist = implode(',', $bmlist);
$query = sprintf("
SELECT `title`, `id`, `public`, `favicon`
FROM `bookmark`
FROM `obm_bookmarks`
WHERE `id` IN (%s) AND `user`='%s'
ORDER BY `title`",
$mysql->escape($qbmlist),
Expand All @@ -36,18 +36,19 @@
while ($row = mysqli_fetch_assoc($mysql->result)) {
array_push($bookmarks, $row);
}
list_bookmarks($bookmarks,
false,
false,
$settings['show_bookmark_icon'],
false,
false,
false,
false,
false,
false,
true,
false
list_bookmarks(
bookmarks: $bookmarks,
show_checkbox: false,
show_folder: false,
show_icon: $settings['show_bookmark_icon'],
show_link: false,
show_desc: false,
show_date: false,
show_edit: false,
show_move: false,
show_delete: false,
show_share: true,
show_header: false
);
?>

Expand Down Expand Up @@ -96,7 +97,8 @@
message('No Bookmark to edit.');
}
elseif ($post_title == '' || $post_url == '' || $refresh_icon) {
$query = sprintf("
// Edit a single bookmark.
$select_query = sprintf("
SELECT `title`, `url`, `description`, `childof`, `id`, `favicon`, `public`
FROM `obm_bookmarks`
WHERE `id` = '%d'
Expand All @@ -106,12 +108,13 @@
$mysql->escape($username)
);
$icon = $new_fav = '';
if ($mysql->query($query)) {
if ($mysql->query($select_query)) {
if (mysqli_num_rows($mysql->result) != 1) {
message('No Bookmark to edit');
}
else {
$row = mysqli_fetch_object($mysql->result);
$saved_favicon = $row->favicon ?? '';

require_once(DOC_ROOT . '/folders/folder.php');
$tree = new Folder();
Expand Down Expand Up @@ -150,8 +153,9 @@
if (!$mysql->query($update_query)) {
message($mysql->error);
}
if (!empty($row->favicon)) { /* && is_file($row->favicon) */
@unlink(DOC_ROOT .'/icons/'. $row->favicon);
if (!empty($saved_favicon) && $saved_favicon !== $new_fav) { /* && is_file($row->favicon) */
// Only delete the existing icon if a new one's been saved.
@unlink(DOC_ROOT .'/icons/'. $saved_favicon);
}
$icon = '<img src="/icons/'. $new_fav .'" width="'.$cfg['icon_w'].'" height="'.$cfg['icon_h'].'" alt="">';
}
Expand Down
2 changes: 1 addition & 1 deletion bookmarks/move_bookmark.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
require_once(realpath(dirname(__FILE__, 2)) . '/header.php');
require_once(dirname(__DIR__, 1) . '/header.php');
logged_in_only();

$bmlist = set_post_num_list('bmlist');
Expand Down
2 changes: 1 addition & 1 deletion bookmarks/new_bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
error_reporting(E_ALL);
ini_set('display_errors', 1);

require_once(realpath(dirname(__FILE__, 2)) . '/header.php');
require_once(dirname(__DIR__, 1) . '/header.php');
global $conn;

$get_title = set_title();
Expand Down
14 changes: 6 additions & 8 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@
die ('No direct access allowed.');
}

define('DOC_ROOT', dirname(__FILE__, 2)); // Includes the sub-directory.
define('DOC_ROOT', dirname(__DIR__, 1)); // Includes any sub-directory.

////////////////////////
// Load Config File ////
////////////////////////
$cfg['user'] = get_current_user();
$cfg['home_path'] = exec('echo ~');
$cfg['projects_path'] = $cfg['home_path'].'/projects';
include_once($cfg['projects_path'].'/scripts/php/library/lib_functions_dtp.inc.php');
$cfg['db_user'] = functions_dtp::global__get_variable('sql_username_html');
$cfg['db_pass'] = functions_dtp::global__get_variable('sql_password_html');
$cfg['database'] = $cfg['user'].'_s22_obm';
$cfg['db_user'] = '';
$cfg['db_pass'] = '';
$cfg['database'] = '';
$cfg['hostspec'] = 'localhost';
$cfg['timezone'] = 'America/Los_Angeles';
$cfg['timezone'] = '';
date_default_timezone_set($cfg['timezone']);
////////////////////////

$cfg['domain'] = 's22.us';
$cfg['domain'] = '';
$cfg['debug'] = true; // Turns debug logging on or off.

$cfg['sub_dir'] = '';
Expand Down
2 changes: 1 addition & 1 deletion export.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// plain text when exporting bookmarks, so that browsers
// can handle results better. header.php is needed only to
// display HTML.
require_once(realpath(dirname(__FILE__, 1)) . '/header.php');
require_once(__DIR__ . '/header.php');
logged_in_only();

$folderid = set_get_folderid();
Expand Down
Loading

0 comments on commit 73928a9

Please sign in to comment.