![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/.cursor-server/data/User/History/-73b029f5/ |
<?php
/**
* Share Track
* POST /api/radio/v1/tracks/{id}/share
*
* Record a track share
*/
$pdo = getDBConnection();
// Get station_id from authenticated station (optional - can be public)
$station_id = $station['id'] ?? null;
// Get request data
$input = json_decode(file_get_contents('php://input'), true);
$track_id = $input['track_id'] ?? $_GET['track_id'] ?? null;
$share_platform = $input['share_platform'] ?? 'link';
if (!$track_id) {
http_response_code(400);
echo json_encode(['error' => 'track_id is required']);
exit;
}
// Validate platform
$valid_platforms = ['facebook', 'twitter', 'instagram', 'whatsapp', 'email', 'link', 'other'];
if (!in_array($share_platform, $valid_platforms)) {
http_response_code(400);
echo json_encode(['error' => 'Invalid share_platform']);
exit;
}
// Get user info
$user_id = $_SESSION['user_id'] ?? null;
$ip_address = $_SERVER['REMOTE_ADDR'] ?? null;
$user_agent = $_SERVER['HTTP_USER_AGENT'] ?? null;
// Insert share
$stmt = $pdo->prepare("
INSERT INTO radio_track_shares (
station_id, track_id, user_id, share_platform, ip_address, user_agent
) VALUES (?, ?, ?, ?, ?, ?)
");
$stmt->execute([
$station_id,
$track_id,
$user_id,
$share_platform,
$ip_address,
$user_agent
]);
// Update cache
$pdo->prepare("
UPDATE music_tracks
SET radio_share_count = radio_share_count + 1
WHERE id = ?
")->execute([$track_id]);
echo json_encode([
'success' => true,
'message' => 'Share recorded successfully'
]);