From 77cc0b3d131d50ab432254f81edbe52ce561c829 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Sun, 16 Aug 2026 23:09:13 +0200 Subject: [PATCH] Add password-protected album sharing module --- include/album_shares.inc.php | 241 +++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 include/album_shares.inc.php diff --git a/include/album_shares.inc.php b/include/album_shares.inc.php new file mode 100644 index 0000000..62c6f24 --- /dev/null +++ b/include/album_shares.inc.php @@ -0,0 +1,241 @@ + 'Geschützte Albumfreigabe erstellt: '.get_absolute_root_url().'?brshare='.$token, + ); +} + +function bratonien_tools_revoke_album_share() +{ + $share_id = isset($_POST['share_id']) ? (int)$_POST['share_id'] : 0; + if ($share_id < 1) + { + throw new Exception('Ungültige Freigabe.'); + } + + $query = 'SELECT user_id FROM '.bratonien_tools_shares_table().' WHERE id = '.$share_id.' LIMIT 1'; + $result = pwg_query($query); + if (!pwg_db_num_rows($result)) + { + throw new Exception('Freigabe nicht gefunden.'); + } + $row = pwg_db_fetch_assoc($result); + $user_id = (int)$row['user_id']; + + pwg_query('DELETE FROM '.USER_ACCESS_TABLE.' WHERE user_id = '.$user_id); + if (defined('USER_GROUP_TABLE')) + { + pwg_query('DELETE FROM '.USER_GROUP_TABLE.' WHERE user_id = '.$user_id); + } + pwg_query('DELETE FROM '.USER_INFOS_TABLE.' WHERE user_id = '.$user_id); + pwg_query('DELETE FROM '.USERS_TABLE.' WHERE id = '.$user_id); + if (function_exists('delete_user_sessions')) + { + delete_user_sessions($user_id); + } + + pwg_query('DELETE FROM '.bratonien_tools_shares_table().' WHERE id = '.$share_id.' LIMIT 1'); + + return array('message' => 'Albumfreigabe wurde widerrufen.'); +} + +function bratonien_tools_grant_album_access($user_id, $category_id) +{ + $user_id = (int)$user_id; + $category_id = (int)$category_id; + + $query = 'SELECT 1 FROM '.USER_ACCESS_TABLE.' WHERE user_id = '.$user_id.' AND cat_id = '.$category_id.' LIMIT 1'; + if (pwg_db_num_rows(pwg_query($query)) === 0) + { + pwg_query('INSERT INTO '.USER_ACCESS_TABLE.' (user_id, cat_id) VALUES ('.$user_id.', '.$category_id.')'); + } +} + +function bratonien_tools_ensure_private_album_access($category_id, $user_id = null) +{ + global $user; + $uid = $user_id === null ? (int)$user['id'] : (int)$user_id; + if ($uid < 1 || (int)$category_id < 1) + { + return; + } + bratonien_tools_grant_album_access($uid, (int)$category_id); +} + +function bratonien_tools_share_access_page($error = '', $token = '', $show_form = false) +{ + header('Content-Type: text/html; charset=UTF-8'); + $action = htmlspecialchars(get_absolute_root_url().'?brshare='.$token, ENT_QUOTES, 'UTF-8'); + $message = $error !== '' ? '

'.htmlspecialchars($error, ENT_QUOTES, 'UTF-8').'

' : ''; + $form = ''; + if ($show_form) + { + $form = '
'; + } + + echo 'Geschützte Albumfreigabe

Geschütztes Album

Für diese Freigabe ist ein Passwort erforderlich.

'.$message.$form.'
'; + exit; +}