Skip to content

Commit

Permalink
Install files
Browse files Browse the repository at this point in the history
  • Loading branch information
s22-tech committed May 26, 2024
1 parent d3facb5 commit 9ee496c
Show file tree
Hide file tree
Showing 5 changed files with 707 additions and 12 deletions.
22 changes: 10 additions & 12 deletions bookmarks/new_bookmark.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

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

$get_title = set_title();
Expand All @@ -17,7 +14,7 @@
$post_childof = set_post_childof();
$post_public = set_post_bool_var('public', false);

require_once(DOC_ROOT . '/folders/folder.php');
require_once(realpath(DOC_ROOT . '/folders/folder.php'));
$tree = new Folder();
$query_string = '?expand=' . implode(',', $tree->get_path_to_root($post_childof)) . '&amp;folderid=' . $post_childof;

Expand All @@ -32,7 +29,7 @@
if ($post_url != '') {
$url = $post_url;
}
else if ($get_url != '') {
elseif ($get_url != '') {
$url = $get_url;
}
else {
Expand Down Expand Up @@ -77,15 +74,16 @@
<?php
}
else {
$query = sprintf ("
INSERT INTO `obm_bookmarks` (`user`, `title`, `url`, `description`, `childof`, `public`)
VALUES ('%s', '%s', '%s', '%s', '%d', '%d')",
$query = sprintf("
INSERT INTO `obm_bookmarks` (`user`, `title`, `url`, `description`, `childof`, `public`, `date_created`)
VALUES ('%s', '%s', '%s', '%s', '%d', '%d', '%s')",
$mysql->escape($username),
$mysql->escape($post_title),
$mysql->escape($post_url),
$mysql->escape($post_description),
$mysql->escape($post_childof),
$mysql->escape($post_public)
$mysql->escape($post_public),
date('Y-m-d H:i:s')
);
if ($mysql->query($query)) {
echo 'Bookmark successfully created.<br>' . PHP_EOL;
Expand All @@ -108,7 +106,7 @@
// since the favicon is not as important.
///////////////////////////
if ($settings['show_bookmark_icon']) {
require_once(DOC_ROOT . '/favicon.php');
require_once(realpath(DOC_ROOT . '/favicon.php'));
$favicon = new Favicon($post_url);
debug_logger(variable:print_r($favicon, true), name:'favicon-object', file:__FILE__, function:__FUNCTION__);

Expand Down Expand Up @@ -148,5 +146,5 @@
echo '<script> self.close(); </script>';
}
}
require_once(DOC_ROOT . '/footer.php');
require_once(realpath(DOC_ROOT . '/footer.php'));
?>
53 changes: 53 additions & 0 deletions cron/remove_stray_favicons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/local/bin/php
<?php

ini_set('display_errors', 1);
require_once(realpath(dirname(__DIR__, 1) . '/config/config.php'));
require_once(realpath(dirname(__DIR__, 1) . '/lib/mysql.php'));
$mysql = new mysql;

$param = $argv[1] ?? PHP_SAPI ?? '';

//////////////////////////////////
// Retrieve favicon names from db.
//////////////////////////////////
$query = "
SELECT * FROM `obm_bookmarks`
GROUP BY `favicon` HAVING COUNT(`favicon`) >= 1;
";

if ($mysql->query($query)) {
$favicons_sql = [];
while ($row = mysqli_fetch_assoc($mysql->result)) {
if (!empty($row['favicon'])) {
$favicons_sql[$row['id']] = $row['favicon'];
}
}
// print_r($favicons_sql); //:debug
}


//////////////////////////////////
// Delete favicons from the server.
//////////////////////////////////
$favicons = [];
$icons_path = realpath(DOC_ROOT . '/icons/');
foreach (glob($icons_path . '/*') as $filename) {
if (!in_array(basename($filename), $favicons_sql)) {
$favicons[] = $filename;
unlink($filename);
}
}


//////////////////////////////////
// Print results.
//////////////////////////////////
if ($param !== 'cron') {
$deleted_icons = implode(PHP_EOL, $favicons);
echo 'Deleted favicons:' . PHP_EOL;
echo $deleted_icons . PHP_EOL;
}

__halt_compiler();
This script will delete all unsused favicons on the server as often as it's run either manually or scheduled via cron. Helps to keep the icon footprint as small as possible.
58 changes: 58 additions & 0 deletions docs/SQL.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
CREATE TABLE `obm_bookmarks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`childof` int(11) NOT NULL DEFAULT 0,
`user` char(20) NOT NULL DEFAULT '',
`title` varchar(200) NOT NULL DEFAULT '',
`url` varchar(512) NOT NULL DEFAULT '',
`description` longtext DEFAULT NULL,
`deleted` enum('0','1') NOT NULL DEFAULT '0',
`favicon` varchar(1048) DEFAULT NULL,
`private` enum('0','1') DEFAULT NULL,
`public` enum('0','1') NOT NULL DEFAULT '0',
`last_visit` datetime DEFAULT NULL,
`date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`date_created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
FULLTEXT KEY `title` (`title`,`url`,`description`)
) ENGINE=Aria AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci PAGE_CHECKSUM=1;


CREATE TABLE `obm_folders` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`childof` int(11) NOT NULL DEFAULT 0,
`name` char(70) NOT NULL DEFAULT '',
`user` char(20) NOT NULL DEFAULT '',
`deleted` enum('0','1') NOT NULL DEFAULT '0',
`public` enum('0','1') NOT NULL DEFAULT '0',
UNIQUE KEY `id` (`id`)
) ENGINE=Aria AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci PAGE_CHECKSUM=1;


CREATE TABLE `obm_users` (
`username` char(50) NOT NULL DEFAULT '',
`password` char(50) NOT NULL DEFAULT '',
`theme` varchar(50) NOT NULL DEFAULT '',
`admin` enum('0','1') NOT NULL DEFAULT '0',
`language` char(20) NOT NULL DEFAULT '',
`root_folder_name` char(50) NOT NULL DEFAULT 'My Bookmarks',
`column_width_folder` smallint(3) NOT NULL DEFAULT 0,
`column_width_bookmark` smallint(3) NOT NULL DEFAULT 0,
`table_height` smallint(3) NOT NULL DEFAULT 0,
`confirm_delete` enum('0','1') NOT NULL DEFAULT '1',
`open_new_window` enum('0','1') NOT NULL DEFAULT '1',
`show_bookmark_description` enum('0','1') NOT NULL DEFAULT '1',
`show_bookmark_icon` enum('0','1') NOT NULL DEFAULT '1',
`show_column_date` enum('0','1') NOT NULL DEFAULT '1',
`date_format` smallint(6) NOT NULL DEFAULT 0,
`show_column_edit` enum('0','1') NOT NULL DEFAULT '1',
`show_column_move` enum('0','1') NOT NULL DEFAULT '1',
`show_column_delete` enum('0','1') NOT NULL DEFAULT '1',
`fast_folder_minus` enum('0','1') NOT NULL DEFAULT '1',
`fast_folder_plus` enum('0','1') NOT NULL DEFAULT '1',
`fast_symbol` enum('0','1') NOT NULL DEFAULT '1',
`simple_tree_mode` enum('0','1') NOT NULL DEFAULT '0',
`show_public` enum('0','1') NOT NULL DEFAULT '1',
`private_mode` enum('0','1') NOT NULL DEFAULT '1',
`notes` varchar(512) DEFAULT NULL,
UNIQUE KEY `id` (`username`)
) ENGINE=Aria DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci PAGE_CHECKSUM=1;
58 changes: 58 additions & 0 deletions install/SQL.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
CREATE TABLE `obm_bookmarks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`childof` int(11) NOT NULL DEFAULT 0,
`user` char(20) NOT NULL DEFAULT '',
`title` varchar(200) NOT NULL DEFAULT '',
`url` varchar(512) NOT NULL DEFAULT '',
`description` longtext DEFAULT NULL,
`deleted` enum('0','1') NOT NULL DEFAULT '0',
`favicon` varchar(1048) DEFAULT NULL,
`private` enum('0','1') DEFAULT NULL,
`public` enum('0','1') NOT NULL DEFAULT '0',
`last_visit` datetime DEFAULT NULL,
`date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`date_created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
FULLTEXT KEY `title` (`title`,`url`,`description`)
) ENGINE=Aria AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci PAGE_CHECKSUM=1;


CREATE TABLE `obm_folders` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`childof` int(11) NOT NULL DEFAULT 0,
`name` char(70) NOT NULL DEFAULT '',
`user` char(20) NOT NULL DEFAULT '',
`deleted` enum('0','1') NOT NULL DEFAULT '0',
`public` enum('0','1') NOT NULL DEFAULT '0',
UNIQUE KEY `id` (`id`)
) ENGINE=Aria AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci PAGE_CHECKSUM=1;


CREATE TABLE `obm_users` (
`username` char(50) NOT NULL DEFAULT '',
`password` char(50) NOT NULL DEFAULT '',
`theme` varchar(50) NOT NULL DEFAULT '',
`admin` enum('0','1') NOT NULL DEFAULT '0',
`language` char(20) NOT NULL DEFAULT '',
`root_folder_name` char(50) NOT NULL DEFAULT 'My Bookmarks',
`column_width_folder` smallint(3) NOT NULL DEFAULT 0,
`column_width_bookmark` smallint(3) NOT NULL DEFAULT 0,
`table_height` smallint(3) NOT NULL DEFAULT 0,
`confirm_delete` enum('0','1') NOT NULL DEFAULT '1',
`open_new_window` enum('0','1') NOT NULL DEFAULT '1',
`show_bookmark_description` enum('0','1') NOT NULL DEFAULT '1',
`show_bookmark_icon` enum('0','1') NOT NULL DEFAULT '1',
`show_column_date` enum('0','1') NOT NULL DEFAULT '1',
`date_format` smallint(6) NOT NULL DEFAULT 0,
`show_column_edit` enum('0','1') NOT NULL DEFAULT '1',
`show_column_move` enum('0','1') NOT NULL DEFAULT '1',
`show_column_delete` enum('0','1') NOT NULL DEFAULT '1',
`fast_folder_minus` enum('0','1') NOT NULL DEFAULT '1',
`fast_folder_plus` enum('0','1') NOT NULL DEFAULT '1',
`fast_symbol` enum('0','1') NOT NULL DEFAULT '1',
`simple_tree_mode` enum('0','1') NOT NULL DEFAULT '0',
`show_public` enum('0','1') NOT NULL DEFAULT '1',
`private_mode` enum('0','1') NOT NULL DEFAULT '1',
`notes` varchar(512) DEFAULT NULL,
UNIQUE KEY `id` (`username`)
) ENGINE=Aria DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci PAGE_CHECKSUM=1;
Loading

0 comments on commit 9ee496c

Please sign in to comment.