![]() 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/config/ |
<?php
// API.box Configuration
// Replace these with your actual API.box credentials
// API.box API Configuration
define('API_BOX_CLIENT_ID', 'your_client_id_here');
define('API_BOX_CLIENT_SECRET', 'your_client_secret_here');
define('API_BOX_REDIRECT_URI', 'https://soundstudiopro.com/auth/box_callback.php');
define('API_BOX_AUTH_URL', 'https://account.box.com/api/oauth2/authorize');
define('API_BOX_TOKEN_URL', 'https://api.box.com/oauth2/token');
define('API_BOX_API_URL', 'https://api.box.com/2.0');
// Function to get Box access token (you'll need to implement OAuth flow)
function getBoxAccessToken() {
// This should be stored securely in your database
// For now, return a placeholder
return 'your_access_token_here';
}
// Function to refresh Box access token
function refreshBoxAccessToken($refreshToken) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, API_BOX_TOKEN_URL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'grant_type' => 'refresh_token',
'refresh_token' => $refreshToken,
'client_id' => API_BOX_CLIENT_ID,
'client_secret' => API_BOX_CLIENT_SECRET
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Function to get user's music files from Box
function getBoxMusicFiles($userId, $accessToken = null) {
if (!$accessToken) {
$accessToken = getBoxAccessToken();
}
$tracks = [];
try {
// Get user's root folder
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, API_BOX_API_URL . '/folders/0/items');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $accessToken,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
$data = json_decode($response, true);
if (isset($data['entries'])) {
foreach ($data['entries'] as $item) {
// Check if it's an audio file
if ($item['type'] === 'file' && isAudioFile($item['name'])) {
$tracks[] = [
'id' => $item['id'],
'title' => $item['name'],
'audio_url' => getBoxDownloadUrl($item['id'], $accessToken),
'created_at' => $item['created_at'],
'modified_at' => $item['modified_at'],
'size' => $item['size'],
'status' => 'complete'
];
}
}
}
}
} catch (Exception $e) {
error_log("Box API error: " . $e->getMessage());
}
return $tracks;
}
// Function to get download URL for a Box file
function getBoxDownloadUrl($fileId, $accessToken = null) {
if (!$accessToken) {
$accessToken = getBoxAccessToken();
}
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, API_BOX_API_URL . '/files/' . $fileId . '/content');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $accessToken
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
// For direct download, you might want to proxy the file
// or use a temporary download URL
return API_BOX_API_URL . '/files/' . $fileId . '/content';
}
} catch (Exception $e) {
error_log("Box download URL error: " . $e->getMessage());
}
return null;
}
// Function to check if file is audio
function isAudioFile($filename) {
$audioExtensions = ['mp3', 'wav', 'flac', 'aac', 'ogg', 'm4a'];
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
return in_array($extension, $audioExtensions);
}
// Function to upload file to Box
function uploadToBox($filePath, $fileName, $folderId = '0', $accessToken = null) {
if (!$accessToken) {
$accessToken = getBoxAccessToken();
}
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, API_BOX_API_URL . '/files/content');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'attributes' => json_encode([
'name' => $fileName,
'parent' => ['id' => $folderId]
]),
'file' => new CURLFile($filePath)
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $accessToken
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 201) {
$data = json_decode($response, true);
return $data['entries'][0] ?? null;
}
} catch (Exception $e) {
error_log("Box upload error: " . $e->getMessage());
}
return null;
}
// Function to create Box OAuth URL
function getBoxOAuthUrl() {
$params = [
'response_type' => 'code',
'client_id' => API_BOX_CLIENT_ID,
'redirect_uri' => API_BOX_REDIRECT_URI,
'state' => bin2hex(random_bytes(16))
];
return API_BOX_AUTH_URL . '?' . http_build_query($params);
}
// Function to exchange authorization code for access token
function exchangeCodeForToken($code) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, API_BOX_TOKEN_URL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'grant_type' => 'authorization_code',
'code' => $code,
'client_id' => API_BOX_CLIENT_ID,
'client_secret' => API_BOX_CLIENT_SECRET,
'redirect_uri' => API_BOX_REDIRECT_URI
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
?>