forked from DaWe35/SkyLive-webportal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from DaWe35/master
Sync the repos
- Loading branch information
Showing
5 changed files
with
291 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,102 @@ | ||
<?php | ||
|
||
if (isset($_COOKIE['PHPSESSID'])) { | ||
session_start(); | ||
} | ||
|
||
if (isset($_GET['portal']) && !empty($_GET['portal'])) { | ||
$portal = htmlspecialchars($_GET['portal']); | ||
if (isset($_GET['user']) && !empty($_GET['user'])) { | ||
$userid = intval($_GET['user']); | ||
if ($userid < 1) { | ||
$userid = 0; | ||
} | ||
} else { | ||
$portal = ''; | ||
$userid = 0; | ||
} | ||
|
||
//total number of videos | ||
$stmt = $db->prepare("SELECT COUNT(*) FROM stream"); | ||
if (!$stmt->execute()) { | ||
exit('Database error'); | ||
// get total number of videos | ||
if ($userid == 0) { // count all videos | ||
$stmt = $db->prepare("SELECT COUNT(streamid) FROM stream WHERE visibility = 'public'"); | ||
if (!$stmt->execute()) { | ||
exit('Database error'); | ||
} | ||
} else { // count user's videos | ||
$stmt = $db->prepare("SELECT COUNT(streamid) FROM stream WHERE visibility = 'public' AND userid = ?"); | ||
if (!$stmt->execute([$userid])) { | ||
exit('Database error'); | ||
} | ||
} | ||
$num_videos = $stmt->fetch(PDO::FETCH_NUM)[0]; | ||
$stmt = null; | ||
|
||
//number of thumbnails per page | ||
$thumbs = array(5, 10, 20); | ||
$thumbs = array(8, 24, 100); | ||
if (isset($_GET['numperpage']) && !empty($_GET['numperpage'])) { | ||
$thumbs_per_page = htmlspecialchars($_GET['numperpage']); | ||
if (!in_array($thumbs_per_page, $thumbs)) { | ||
$thumbs_per_page = $thumbs[0]; | ||
} | ||
$thumbs_per_page = intval($_GET['numperpage']); | ||
if (!in_array($thumbs_per_page, $thumbs)) { | ||
$thumbs_per_page = $thumbs[0]; | ||
} | ||
} else { | ||
$thumbs_per_page = $thumbs[0]; | ||
$thumbs_per_page = $thumbs[0]; | ||
} | ||
|
||
//current page | ||
if (isset($_GET['current']) && !empty($_GET['current'])) { | ||
$current = htmlspecialchars($_GET['current']); | ||
if (($current < 1) or ($current > ceil($num_videos / $thumbs_per_page))) { | ||
$current = 1; | ||
} | ||
} else { | ||
$current = 1; | ||
} | ||
$offset = $thumbs_per_page * ($current - 1); | ||
|
||
//sort by user | ||
if (isset($_GET['user']) && !empty($_GET['user'])) { | ||
$userid = htmlspecialchars($_GET['user']); | ||
if ($userid < 1) { | ||
$userid = 0; | ||
} | ||
if (isset($_GET['page']) && !empty($_GET['page'])) { | ||
$page = intval($_GET['page']); | ||
if (($page < 1) or ($page > ceil($num_videos / $thumbs_per_page))) { | ||
$page = 1; | ||
} | ||
} else { | ||
$userid = 0; | ||
$page = 1; | ||
} | ||
$offset = $thumbs_per_page * ($page - 1); | ||
|
||
if ($userid == 0) { //select all users | ||
$stmt = $db->prepare("SELECT streamid, userid, title, description, scheule_time, visibility FROM stream LIMIT $thumbs_per_page OFFSET $offset"); | ||
if (!$stmt->execute()) { | ||
exit('Database error'); | ||
} | ||
$stream = $stmt->fetchAll(PDO::FETCH_ASSOC); | ||
$stmt = null; | ||
$names = array(); | ||
$avatars = array(); | ||
$ids = array(); | ||
$stmt = $db->prepare("SELECT name, avatar FROM users WHERE id = ? LIMIT 1"); | ||
for ($i = 0; $i < count($stream); $i++) { | ||
if (!array_key_exists($stream[$i]['userid'], $names)) { | ||
if (!$stmt->execute([$stream[$i]['userid']])) { | ||
exit('Database error'); | ||
} | ||
$user = $stmt->fetch(PDO::FETCH_ASSOC); | ||
} | ||
$names[$i] = $user['name']; | ||
$ids[$i] = $stream[$i]['userid']; | ||
if ($user['avatar'] == '') { | ||
$avatars[$i] = 'assets/logos/skylive round logo dark.png'; | ||
} else { | ||
$avatars[$i] = $user['avatar']; | ||
} | ||
} | ||
$stmt = null; | ||
$stmt = $db->prepare("SELECT streamid, userid, title, description, scheule_time, visibility FROM stream WHERE visibility = 'public' ORDER BY scheule_time DESC, streamid DESC LIMIT $thumbs_per_page OFFSET $offset"); | ||
if (!$stmt->execute()) { | ||
exit('Database error'); | ||
} | ||
$stream = $stmt->fetchAll(PDO::FETCH_ASSOC); | ||
$stmt = null; | ||
$names = array(); | ||
$avatars = array(); | ||
$ids = array(); | ||
$stmt = $db->prepare("SELECT name, avatar FROM users WHERE id = ? LIMIT 1"); | ||
for ($i = 0; $i < count($stream); $i++) { | ||
if (!array_key_exists($stream[$i]['userid'], $names)) { | ||
if (!$stmt->execute([$stream[$i]['userid']])) { | ||
exit('Database error'); | ||
} | ||
$user = $stmt->fetch(PDO::FETCH_ASSOC); | ||
} | ||
$names[$i] = $user['name']; | ||
$ids[$i] = $stream[$i]['userid']; | ||
if ($user['avatar'] == '') { | ||
$avatars[$i] = 'assets/logos/skylive round logo dark.png'; | ||
} else { | ||
$avatars[$i] = $user['avatar']; | ||
} | ||
} | ||
$stmt = null; | ||
} else { | ||
$stmt = $db->prepare("SELECT name, avatar FROM users WHERE id = $userid LIMIT 1"); | ||
if (!$stmt->execute()) { | ||
exit('Database error'); | ||
} | ||
$user = $stmt->fetch(PDO::FETCH_ASSOC); | ||
$stmt = null; | ||
$names = array(); | ||
$avatars = array(); | ||
$ids = array(); | ||
$stmt = $db->prepare("SELECT streamid, userid, title, description, scheule_time, visibility FROM stream WHERE userid = $userid LIMIT $thumbs_per_page OFFSET $offset"); | ||
if (!$stmt->execute()) { | ||
exit('Database error'); | ||
} | ||
$stream = $stmt->fetchAll(PDO::FETCH_ASSOC); | ||
$stmt = null; | ||
for ($i = 0; $i < count($stream); $i++) { | ||
$names[$i] = $user['name']; | ||
$ids[$i] = $userid; | ||
if ($user['avatar'] == '') { | ||
$avatars[$i] = 'assets/logos/skylive round logo dark.png'; | ||
} else { | ||
$avatars[$i] = $user['avatar']; | ||
} | ||
} | ||
$stmt = $db->prepare("SELECT name, avatar FROM users WHERE id = $userid LIMIT 1"); | ||
if (!$stmt->execute()) { | ||
exit('Database error'); | ||
} | ||
$user = $stmt->fetch(PDO::FETCH_ASSOC); | ||
$stmt = null; | ||
$names = array(); | ||
$avatars = array(); | ||
$ids = array(); | ||
$stmt = $db->prepare("SELECT streamid, userid, title, description, scheule_time, visibility FROM stream WHERE userid = ? AND visibility = 'public' ORDER BY scheule_time DESC, streamid DESC LIMIT $thumbs_per_page OFFSET $offset"); | ||
if (!$stmt->execute([$userid])) { | ||
exit('Database error'); | ||
} | ||
$stream = $stmt->fetchAll(PDO::FETCH_ASSOC); | ||
$stmt = null; | ||
for ($i = 0; $i < count($stream); $i++) { | ||
$names[$i] = $user['name']; | ||
$ids[$i] = $userid; | ||
if ($user['avatar'] == '') { | ||
$avatars[$i] = 'assets/logos/skylive round logo dark.png'; | ||
} else { | ||
$avatars[$i] = $user['avatar']; | ||
} | ||
} | ||
} | ||
|
||
include 'model/display.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.