Skip to content

Commit

Permalink
Merge pull request #2 from DaWe35/master
Browse files Browse the repository at this point in the history
Sync the repos
  • Loading branch information
mike76-dev authored Oct 15, 2020
2 parents 1b4f3b4 + 79e3c80 commit 90dfa9f
Show file tree
Hide file tree
Showing 5 changed files with 291 additions and 304 deletions.
165 changes: 80 additions & 85 deletions get/channel.php
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';
2 changes: 1 addition & 1 deletion get/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$streams_stmt = $db->prepare("SELECT `streamid`, `title`, `description`, `scheule_time`, `started`, `finished` FROM `stream` WHERE visibility = 'public' ORDER BY scheule_time DESC, streamid DESC LIMIT 100");
$streams_stmt = $db->prepare("SELECT `streamid`, `title`, `description`, `scheule_time`, `started`, `finished` FROM `stream` WHERE visibility = 'public' ORDER BY scheule_time DESC, streamid DESC LIMIT 100");
if (!$streams_stmt->execute()) {
exit('Database error');
}
Expand Down
2 changes: 1 addition & 1 deletion get/player.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
exit('Access denied, please log in if this is your content');
}

$stmt = $db->prepare("SELECT name, avatar FROM users WHERE id = ? LIMIT 1");
$stmt = $db->prepare("SELECT name, avatar, id FROM users WHERE id = ? LIMIT 1");
if (!$stmt->execute([$stream['userid']])) {
exit('Database error');
}
Expand Down
Loading

0 comments on commit 90dfa9f

Please sign in to comment.