Geschütztes Album
Für diese Freigabe ist ein Passwort erforderlich.
'.$message.$form.'($password === '' ? 'Albumfreigabe' : 'Passwortgeschützte Albumfreigabe').' erstellt: '.bratonien_tools_share_url($token), ); } /** * Legacy shares created before reproducible tokens cannot expose their old raw * token because only its hash was stored. Regeneration intentionally replaces * that old token so the link becomes copyable from the admin UI afterwards. */ function bratonien_tools_regenerate_album_share_link() { $share_id = isset($_POST['share_id']) ? (int)$_POST['share_id'] : 0; if ($share_id < 1) { throw new Exception('Ungültige Freigabe.'); } $query = 'SELECT id, category_id, user_id FROM '.bratonien_tools_shares_table().' WHERE id = '.$share_id.' AND active = 1 LIMIT 1'; $result = pwg_query($query); if (!pwg_db_num_rows($result)) { throw new Exception('Freigabe nicht gefunden.'); } $share = pwg_db_fetch_assoc($result); $token = bratonien_tools_share_token((int)$share['user_id'], (int)$share['category_id']); $token_hash = hash('sha256', $token); pwg_query( 'UPDATE '.bratonien_tools_shares_table()." SET token_hash = '".pwg_db_real_escape_string($token_hash)."' WHERE id = ".$share_id.' LIMIT 1' ); return array( 'message' => 'Neuer Freigabelink erzeugt: '.bratonien_tools_share_url($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); bratonien_tools_delete_share_user((int)$row['user_id']); pwg_query('DELETE FROM '.bratonien_tools_shares_table().' WHERE id = '.$share_id.' LIMIT 1'); invalidate_user_cache(); return array('message' => 'Albumfreigabe wurde widerrufen.'); } function bratonien_tools_delete_share_user($user_id) { $user_id = (int)$user_id; if ($user_id < 1) { return; } 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); } } 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_preserve_private_album_access() { global $user; if ($_SERVER['REQUEST_METHOD'] !== 'POST' || empty($user['id'])) { return; } $category_ids = array(); $private_intent = false; if ( defined('IN_ADMIN') && (string)($_GET['page'] ?? '') === 'cat_options' && (string)($_GET['section'] ?? '') === 'status' && isset($_POST['falsify']) && !empty($_POST['cat_true']) && is_array($_POST['cat_true']) ) { $category_ids = $_POST['cat_true']; $private_intent = true; } foreach (array('status', 'privacy', 'visibility') as $field) { if (isset($_POST[$field]) && strtolower((string)$_POST[$field]) === 'private') { $private_intent = true; } } if (isset($_POST['category_id'])) { $category_ids[] = $_POST['category_id']; } if (isset($_POST['cat_id'])) { $category_ids[] = $_POST['cat_id']; } if (isset($_POST['category_ids']) && is_array($_POST['category_ids'])) { $category_ids = array_merge($category_ids, $_POST['category_ids']); } if (!$private_intent || empty($category_ids)) { return; } $ids = array_values(array_unique(array_filter(array_map('intval', $category_ids), function ($id) { return $id > 0; }))); if (empty($ids)) { return; } $user_id = (int)$user['id']; register_shutdown_function(function () use ($ids, $user_id) { foreach ($ids as $category_id) { $query = 'SELECT status FROM '.CATEGORIES_TABLE.' WHERE id = '.(int)$category_id.' LIMIT 1'; $result = pwg_query($query); if (!pwg_db_num_rows($result)) { continue; } $row = pwg_db_fetch_assoc($result); if ($row['status'] === 'private') { bratonien_tools_grant_album_access($user_id, (int)$category_id); } } if (function_exists('invalidate_user_cache')) { invalidate_user_cache(); } }); } function bratonien_tools_album_shares_on_delete_categories($category_ids) { foreach ((array)$category_ids as $category_id) { $result = pwg_query('SELECT id, user_id FROM '.bratonien_tools_shares_table().' WHERE category_id = '.(int)$category_id); while ($row = pwg_db_fetch_assoc($result)) { bratonien_tools_delete_share_user((int)$row['user_id']); pwg_query('DELETE FROM '.bratonien_tools_shares_table().' WHERE id = '.(int)$row['id'].' LIMIT 1'); } } } function bratonien_tools_share_access_page($error = '', $token = '', $show_form = false) { header('Content-Type: text/html; charset=UTF-8'); $action = htmlspecialchars(bratonien_tools_share_url($token), ENT_QUOTES, 'UTF-8'); $message = $error !== '' ? '
' : ''; $form = ''; if ($show_form) { $form = ''; } echo 'Für diese Freigabe ist ein Passwort erforderlich.
'.$message.$form.'