![]() 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/domains/soundstudiopro.com/private_html/utils/ |
<?php
// Social Player Integration Guide
// This file shows how to integrate the new social player with your existing system
// 1. Database Updates Needed
$database_updates = "
-- Add social features to music_tracks table
ALTER TABLE music_tracks ADD COLUMN play_count INT DEFAULT 0;
ALTER TABLE music_tracks ADD COLUMN like_count INT DEFAULT 0;
ALTER TABLE music_tracks ADD COLUMN share_count INT DEFAULT 0;
ALTER TABLE music_tracks ADD COLUMN fire_reactions INT DEFAULT 0;
ALTER TABLE music_tracks ADD COLUMN heart_reactions INT DEFAULT 0;
ALTER TABLE music_tracks ADD COLUMN clap_reactions INT DEFAULT 0;
ALTER TABLE music_tracks ADD COLUMN rocket_reactions INT DEFAULT 0;
-- Create comments table
CREATE TABLE track_comments (
id INT AUTO_INCREMENT PRIMARY KEY,
track_id INT NOT NULL,
user_id INT NOT NULL,
comment TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (track_id) REFERENCES music_tracks(id),
FOREIGN KEY (user_id) REFERENCES users(id)
);
-- Create collaborative playlists table
CREATE TABLE collaborative_playlists (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
created_by INT NOT NULL,
is_public BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (created_by) REFERENCES users(id)
);
-- Create playlist tracks table
CREATE TABLE playlist_tracks (
id INT AUTO_INCREMENT PRIMARY KEY,
playlist_id INT NOT NULL,
track_id INT NOT NULL,
added_by INT NOT NULL,
added_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (playlist_id) REFERENCES collaborative_playlists(id),
FOREIGN KEY (track_id) REFERENCES music_tracks(id),
FOREIGN KEY (added_by) REFERENCES users(id)
);
-- Create listening parties table
CREATE TABLE listening_parties (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
host_id INT NOT NULL,
current_track_id INT,
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (host_id) REFERENCES users(id),
FOREIGN KEY (current_track_id) REFERENCES music_tracks(id)
);
-- Create party participants table
CREATE TABLE party_participants (
id INT AUTO_INCREMENT PRIMARY KEY,
party_id INT NOT NULL,
user_id INT NOT NULL,
joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (party_id) REFERENCES listening_parties(id),
FOREIGN KEY (user_id) REFERENCES users(id)
);
";
// 2. API Endpoints for Real-time Features
$api_endpoints = "
// api/social/reactions.php
<?php
header('Content-Type: application/json');
require_once '../config/database.php';
$pdo = getDBConnection();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$data = json_decode(file_get_contents('php://input'), true);
$track_id = $data['track_id'];
$reaction_type = $data['reaction_type'];
$user_id = $_SESSION['user_id'];
// Update reaction count
$stmt = $pdo->prepare(\"UPDATE music_tracks SET {$reaction_type}_reactions = {$reaction_type}_reactions + 1 WHERE id = ?\");
$stmt->execute([$track_id]);
// Broadcast to WebSocket server
broadcastReaction($track_id, $reaction_type, $user_id);
echo json_encode(['success' => true]);
}
// api/social/comments.php
<?php
header('Content-Type: application/json');
require_once '../config/database.php';
$pdo = getDBConnection();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$data = json_decode(file_get_contents('php://input'), true);
$track_id = $data['track_id'];
$comment = $data['comment'];
$user_id = $_SESSION['user_id'];
// Add comment to database
$stmt = $pdo->prepare(\"INSERT INTO track_comments (track_id, user_id, comment) VALUES (?, ?, ?)\");
$stmt->execute([$track_id, $user_id, $comment]);
// Broadcast to WebSocket server
broadcastComment($track_id, $comment, $user_id);
echo json_encode(['success' => true]);
}
// api/social/playlist.php
<?php
header('Content-Type: application/json');
require_once '../config/database.php';
$pdo = getDBConnection();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$data = json_decode(file_get_contents('php://input'), true);
$name = $data['name'];
$is_public = $data['is_public'] ?? true;
$user_id = $_SESSION['user_id'];
// Create collaborative playlist
$stmt = $pdo->prepare(\"INSERT INTO collaborative_playlists (name, created_by, is_public) VALUES (?, ?, ?)\");
$stmt->execute([$name, $user_id, $is_public]);
echo json_encode(['success' => true, 'playlist_id' => $pdo->lastInsertId()]);
}
// api/social/party.php
<?php
header('Content-Type: application/json');
require_once '../config/database.php';
$pdo = getDBConnection();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$data = json_decode(file_get_contents('php://input'), true);
$name = $data['name'];
$user_id = $_SESSION['user_id'];
// Create listening party
$stmt = $pdo->prepare(\"INSERT INTO listening_parties (name, host_id) VALUES (?, ?)\");
$stmt->execute([$name, $user_id]);
$party_id = $pdo->lastInsertId();
// Add host as participant
$stmt = $pdo->prepare(\"INSERT INTO party_participants (party_id, user_id) VALUES (?, ?)\");
$stmt->execute([$party_id, $user_id]);
echo json_encode(['success' => true, 'party_id' => $party_id]);
}
";
// 3. WebSocket Server for Real-time Communication
$websocket_server = "
// websocket_server.php
<?php
require 'vendor/autoload.php';
use Ratchet\\Server\\IoServer;
use Ratchet\\Http\\HttpServer;
use Ratchet\\WebSocket\\WsServer;
use React\\EventLoop\\Factory;
class SocialMusicServer implements MessageComponentInterface {
protected \$clients;
protected \$rooms;
public function __construct() {
\$this->clients = new \\SplObjectStorage;
\$this->rooms = [];
}
public function onOpen(ConnectionInterface \$conn) {
\$this->clients->attach(\$conn);
echo \"New connection! ({$conn->resourceId})\\n\";
}
public function onMessage(ConnectionInterface \$from, \$msg) {
\$data = json_decode(\$msg, true);
switch (\$data['type']) {
case 'join_room':
\$this->joinRoom(\$from, \$data['room']);
break;
case 'reaction':
\$this->broadcastReaction(\$from, \$data);
break;
case 'comment':
\$this->broadcastComment(\$from, \$data);
break;
case 'track_change':
\$this->broadcastTrackChange(\$from, \$data);
break;
}
}
public function onClose(ConnectionInterface \$conn) {
\$this->clients->detach(\$conn);
echo \"Connection {$conn->resourceId} has disconnected\\n\";
}
public function onError(ConnectionInterface \$conn, \\Exception \$e) {
echo \"An error has occurred: {$e->getMessage()}\\n\";
\$conn->close();
}
protected function joinRoom(\$client, \$room) {
if (!isset(\$this->rooms[\$room])) {
\$this->rooms[\$room] = new \\SplObjectStorage;
}
\$this->rooms[\$room]->attach(\$client);
}
protected function broadcastReaction(\$from, \$data) {
\$room = \$data['room'];
if (isset(\$this->rooms[\$room])) {
foreach (\$this->rooms[\$room] as \$client) {
if (\$client !== \$from) {
\$client->send(json_encode([
'type' => 'reaction',
'reaction_type' => \$data['reaction_type'],
'user' => \$data['user']
]));
}
}
}
}
protected function broadcastComment(\$from, \$data) {
\$room = \$data['room'];
if (isset(\$this->rooms[\$room])) {
foreach (\$this->rooms[\$room] as \$client) {
if (\$client !== \$from) {
\$client->send(json_encode([
'type' => 'comment',
'comment' => \$data['comment'],
'user' => \$data['user']
]));
}
}
}
}
protected function broadcastTrackChange(\$from, \$data) {
\$room = \$data['room'];
if (isset(\$this->rooms[\$room])) {
foreach (\$this->rooms[\$room] as \$client) {
if (\$client !== \$from) {
\$client->send(json_encode([
'type' => 'track_change',
'track' => \$data['track']
]));
}
}
}
}
}
// Start WebSocket server
\$server = IoServer::factory(
new HttpServer(
new WsServer(
new SocialMusicServer()
)
),
8080
);
echo \"WebSocket server started on port 8080\\n\";
\$server->run();
";
// 4. JavaScript for WebSocket Connection
$websocket_client = "
// Add this to social_player.php
const ws = new WebSocket('ws://localhost:8080');
ws.onopen = function() {
console.log('🔌 Connected to WebSocket server');
// Join the current track's room
ws.send(JSON.stringify({
type: 'join_room',
room: 'track_' + currentTrackId
}));
};
ws.onmessage = function(event) {
const data = JSON.parse(event.data);
switch (data.type) {
case 'reaction':
handleIncomingReaction(data.reaction_type, data.user);
break;
case 'comment':
handleIncomingComment(data.comment, data.user);
break;
case 'track_change':
handleIncomingTrackChange(data.track);
break;
}
};
function handleIncomingReaction(type, user) {
reactions[type]++;
document.getElementById(type + 'Count').textContent = reactions[type];
// Show notification
showNotification(user + ' sent a ' + type + ' reaction!');
}
function handleIncomingComment(comment, user) {
const newComment = {
id: Date.now(),
author: user,
text: comment,
time: new Date().toLocaleTimeString(),
avatar: user.charAt(0)
};
comments.unshift(newComment);
updateCommentsDisplay();
// Show notification
showNotification(user + ' commented: ' + comment);
}
function handleIncomingTrackChange(track) {
// Sync track change with other users
if (track.id !== currentTrackId) {
playTrack(track.audioUrl, track.title, track.artist, track.artwork);
}
}
function showNotification(message) {
const notification = document.createElement('div');
notification.className = 'notification';
notification.textContent = message;
document.body.appendChild(notification);
setTimeout(() => {
notification.remove();
}, 3000);
}
";
// 5. Integration with Existing Library
$library_integration = "
// Add this to library.php to integrate with social player
// Add social player button
echo '<div class=\"social-player-btn\">
<a href=\"/social_player.php\" class=\"btn btn-primary\">
<i class=\"fas fa-users\"></i> Open Social Player
</a>
</div>';
// Update play count when track is played
function updatePlayCount(\$track_id) {
global \$pdo;
\$stmt = \$pdo->prepare(\"UPDATE music_tracks SET play_count = play_count + 1 WHERE id = ?\");
\$stmt->execute([\$track_id]);
}
// Add reaction tracking
function addReaction(\$track_id, \$reaction_type) {
global \$pdo;
\$stmt = \$pdo->prepare(\"UPDATE music_tracks SET {$reaction_type}_reactions = {$reaction_type}_reactions + 1 WHERE id = ?\");
\$stmt->execute([\$track_id]);
}
// Display social stats in music cards
function displaySocialStats(\$track) {
echo '<div class=\"social-stats\">
<span><i class=\"fas fa-play\"></i> ' . \$track['play_count'] . '</span>
<span><i class=\"fas fa-heart\"></i> ' . \$track['heart_reactions'] . '</span>
<span><i class=\"fas fa-fire\"></i> ' . \$track['fire_reactions'] . '</span>
</div>';
}
";
// 6. CSS for Social Features
$social_css = "
/* Add to your existing CSS */
.notification {
position: fixed;
top: 20px;
right: 20px;
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
padding: 1rem 2rem;
border-radius: 12px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
z-index: 10000;
animation: slideInRight 0.3s ease;
}
@keyframes slideInRight {
from { transform: translateX(100%); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
.social-stats {
display: flex;
gap: 1rem;
margin-top: 1rem;
font-size: 1.2rem;
color: #a0aec0;
}
.social-stats span {
display: flex;
align-items: center;
gap: 0.5rem;
}
.social-player-btn {
text-align: center;
margin: 2rem 0;
}
.social-player-btn .btn {
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
padding: 1.5rem 3rem;
border-radius: 16px;
text-decoration: none;
font-size: 1.6rem;
font-weight: 600;
transition: all 0.3s ease;
display: inline-flex;
align-items: center;
gap: 1rem;
}
.social-player-btn .btn:hover {
transform: translateY(-3px);
box-shadow: 0 15px 35px rgba(102, 126, 234, 0.4);
}
";
// 7. Usage Instructions
$usage_instructions = "
## Social Player Integration Guide
### 1. Database Setup
Run the database updates to add social features to your existing tables.
### 2. Install WebSocket Dependencies
composer require cboden/ratchet
### 3. Start WebSocket Server
php websocket_server.php
### 4. Update Your Library
Add the social player button to your library.php file.
### 5. Configure WebSocket URL
Update the WebSocket URL in social_player.php to match your server.
### 6. Test Features
- Real-time reactions
- Live comments
- Collaborative playlists
- Listening parties
- Track synchronization
### Key Features:
✅ Real-time reactions (fire, heart, clap, rocket)
✅ Live comments with user avatars
✅ Collaborative playlist creation
✅ Listening parties with friends
✅ Visual audio spectrum analyzer
✅ Social statistics tracking
✅ Fullscreen mode
✅ Shuffle and repeat modes
✅ Track synchronization across users
### Benefits for Social Network:
🎵 Enhanced user engagement
👥 Community building features
🔥 Viral content sharing
📊 Social analytics
🎉 Interactive listening experiences
💬 Real-time communication
🚀 Modern, engaging UI
";
echo "<h1>Social Player Integration Guide</h1>";
echo "<pre>" . htmlspecialchars($usage_instructions) . "</pre>";
echo "<h2>Database Updates</h2>";
echo "<pre>" . htmlspecialchars($database_updates) . "</pre>";
echo "<h2>API Endpoints</h2>";
echo "<pre>" . htmlspecialchars($api_endpoints) . "</pre>";
echo "<h2>WebSocket Server</h2>";
echo "<pre>" . htmlspecialchars($websocket_server) . "</pre>";
echo "<h2>WebSocket Client</h2>";
echo "<pre>" . htmlspecialchars($websocket_client) . "</pre>";
echo "<h2>Library Integration</h2>";
echo "<pre>" . htmlspecialchars($library_integration) . "</pre>";
echo "<h2>CSS Styles</h2>";
echo "<pre>" . htmlspecialchars($social_css) . "</pre>";
?>