1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00
Oinktube/objects/Channel.php
Caleb Mazalevskis 8ce4b01fda
Stricter checking.
'!==' is slightly more secure than '!=' due to type strictness/looseness.
2022-02-03 09:25:00 +08:00

55 lines
1.8 KiB
PHP

<?php
global $global, $config;
if (!isset($global['systemRootPath'])) {
require_once '../videos/configuration.php';
}
require_once $global['systemRootPath'] . 'objects/bootGrid.php';
require_once $global['systemRootPath'] . 'objects/user.php';
class Channel
{
public static function getChannels($activeOnly = true, $FIND_IN_SET = "")
{
global $global;
$sql = "SELECT u.*, "
. " (SELECT count(v.id) FROM videos v where v.users_id = u.id) as total_videos "
. " FROM users u "
. " HAVING total_videos > 0 ";
if ($activeOnly) {
$sql .= " AND u.status = 'a' ";
}
$sql .= BootGrid::getSqlFromPost(['user', 'about', 'channelName', 'u.name', 'u.email'], "", "", false, $FIND_IN_SET);
$res = sqlDAL::readSql($sql);
$fullResult = sqlDAL::fetchAllAssoc($res);
sqlDAL::close($res);
$subscribe = [];
if ($res !== false) {
foreach ($fullResult as $row) {
$row = cleanUpRowFromDatabase($row);
$subscribe[] = $row;
}
} else {
$subscribe = false;
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
return $subscribe;
}
public static function getTotalChannels($activeOnly=true)
{
global $global;
$sql = "SELECT count(*) as total "
. " FROM users u "
. " WHERE (SELECT count(v.id) FROM videos v where v.users_id = u.id) > 0 ";
if ($activeOnly) {
$sql .= " AND u.status = 'a' ";
}
$sql .= BootGrid::getSqlFromPost(['user', 'about']);
$res = sqlDAL::readSql($sql);
$data = sqlDAL::fetchAssoc($res);
sqlDAL::close($res);
return $res ? intval($data['total']) : 0;
}
}