$v) {
if (is_array($v)) {
foreach ($v as $k2 => $v2) {
if ($k2 == $key) {
$tempArray[$k] = $v2;
}
}
} else {
$tempArray[$k] = $v;
}
}
// Sort temporary array based on order
switch ($order) {
case SORT_ASC:
asort($tempArray);
break;
case SORT_DESC:
arsort($tempArray);
break;
default:
}
// Copy original array into new array based on the order in the temporary array
foreach ($tempArray as $k => $v) {
$sortedArray[$k] = $array[$k];
}
return $sortedArray;
}
session_start();
$_SESSION[‘lastPageVisited’] = ‘../library’;
$currentUser = getCurrentUser();
if ($currentUser[1] === true) {
echo ““;
// Number of videos to show on each page
$numVideos = 15;
// Valid session token
// Get all the files belonging to this user
// Get page number if in url
if (isset($_GET[‘v’])) {
$pageNumber = $_GET[‘v’];
$skip = ($pageNumber – 1) * $numVideos;
} else {
$pageNumber = 1;
$skip = 0;
}
// Build the url
$query = ‘where=’ . rawurlencode(‘{“user”:{“__type”:”Pointer”,”className”:”_User”, “objectId”:”‘ . $currentUser[0] . ‘”},”shareMode”:{“$nin”:[“shareChat”,”shareChatCoach”]}}’);
$query .= ‘&order=’ . rawurlencode(‘-createdAt’);
$query .= ‘&limit=’ . rawurlencode($numVideos);
$query .= ‘&count=’ . rawurlencode(‘1’);
$query .= ‘&skip=’ . rawurlencode($skip);
$retrieveUrl = ‘https://parseapi.back4app.com/classes/Video2?’ . $query;
// Headers
$retrieveHeaders = array(
“X-Parse-Application-Id: 9s7Zfx1VQafAc1raQ9iHvWpNIfYk7nGV8YX8h5jq”,
“X-Parse-REST-API-Key: TiWvQ83bIfqAKIjl292jPN3zx3RIjDb15X5pYtKZ”
);
// Set up and execute curl
$retrieveRest = curl_init();
curl_setopt($retrieveRest, CURLOPT_URL, $retrieveUrl);
curl_setopt($retrieveRest, CURLOPT_HTTPGET, 1);
curl_setopt($retrieveRest, CURLOPT_HTTPHEADER, $retrieveHeaders);
curl_setopt($retrieveRest, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($retrieveRest, CURLOPT_RETURNTRANSFER, true);
$retrieveResponse = curl_exec($retrieveRest);
$retrieveResponse = json_decode($retrieveResponse, true);
curl_close($retrieveRest);
//print_r($retrieveResponse);
echo ““;
if (isset($retrieveResponse[‘results’][‘0’])) {
// Uploads found
// Sort by date
$retrieveResponse[‘results’] = sortArray($retrieveResponse[‘results’], ‘createdAt’, SORT_DESC);
// Show video gallery
echo ‘
-
‘;
-
Preview
Player: ‘ . $videoInfo[‘playerInfo’][‘firstName’] . ‘ ‘ . $videoInfo[‘playerInfo’][‘lastName’] . ‘
Date: ‘ . $date[0] . ‘
// Generate html for each set of uploads as a list
foreach ($retrieveResponse[‘results’] as $upload) {
// Decode video info
$jsonUrl = $upload[‘videoInfo’][‘url’];
$videoInfo = json_decode(file_get_contents($jsonUrl), true);
// Trim date
$date = explode(“T”, $upload[‘createdAt’]);
echo ‘
‘;
}
echo ‘
‘;
// Show page numbers
$totalVideos = $retrieveResponse[‘count’];
$totalPages = ceil($totalVideos/$numVideos);
$startVidNumber = ($pageNumber – 1) * $numVideos + 1;
if ($pageNumber == $totalPages) {
$endVidNumber = $totalVideos;
} else {
$endVidNumber = $pageNumber * $numVideos;
}
echo ‘Showing videos ‘ . $startVidNumber . ‘ to ‘ . $endVidNumber . ‘ of ‘ . $totalVideos . ‘ videos.
‘;
$nextPage = $pageNumber + 1;
$prevPage = $pageNumber – 1;
if ($pageNumber < $totalPages && $pageNumber > 1) {
// Current page isn’t last page or first page
echo ‘First‘;
echo ‘ Previous‘;
echo ‘ Next‘;
echo ‘ Last‘;
} elseif ($pageNumber == 1) {
echo ‘Next‘;
echo ‘ Last‘;
} elseif ($pageNumber == $totalPages) {
echo ‘First Page‘;
echo ‘ Previous‘;
}
} else {
// No uploads found
echo ‘
No videos found.
‘;
}
} else {
// Invalid session token
// Redirect to login page
echo “Redirecting to log in page.”;
echo ‘
‘;
}
?>