1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00

Le add a birth date on user profile

This commit is contained in:
Daniel Neto 2024-01-08 14:34:32 -03:00
parent 010579d72b
commit f0ec84e7a0
12 changed files with 251 additions and 124 deletions

View file

@ -5,7 +5,7 @@ if (file_exists("../videos/configuration.php")) {
}
$installationVersion = "14.1";
$installationVersion = "14.2";
require_once '../objects/functionSecurity.php';

View file

@ -41,6 +41,7 @@ CREATE TABLE IF NOT EXISTS `users` (
`extra_info` TEXT NULL DEFAULT NULL,
`phone` VARCHAR(255) NULL DEFAULT NULL,
`is_company` TINYINT(4) NULL DEFAULT NULL,
`birth_date` DATE NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `user_UNIQUE` (`user` ASC))
ENGINE = InnoDB;

View file

@ -250,6 +250,7 @@ $object->canStream = User::canStream();
$object->redirectUri = @$_POST['redirectUri'];
$object->embedChatUrl = '';
$object->embedChatUrlMobile = '';
$object->age = User::getAge();
//_error_log("login.json.php check chat2");
if (AVideoPlugin::isEnabledByName('Chat2') && method_exists('Chat2', 'getChatRoomLink')) {

View file

@ -58,6 +58,7 @@ class User
private $extra_info;
private $phone;
private $is_company;
private $birth_date;
public static $DOCUMENT_IMAGE_TYPE = "Document Image";
public static $channel_artTV = 'tv';
public static $channel_artDesktopMax = 'desktop_max';
@ -123,6 +124,17 @@ class User
$this->phone = $phone;
}
function getBirth_date()
{
return $this->birth_date;
}
function setBirth_date($birth_date): void
{
$time = strtotime($birth_date);
$this->birth_date = date('Y/m/d', $time);
}
public function getEmail()
{
return $this->email;
@ -629,7 +641,7 @@ if (typeof gtag !== \"function\") {
global $global;
$photo = self::_getPhoto($users_id);
if ($photo == ImagesPlaceHolders::getUserIcon()) {
return $global['systemRootPath'].($photo);
return $global['systemRootPath'] . ($photo);
}
if (empty($photo)) {
return false;
@ -727,7 +739,7 @@ if (typeof gtag !== \"function\") {
//echo "u:" . $this->user . "|p:" . strlen($this->password);
if (empty($this->user)) {
//echo "u:" . $this->user . "|p:" . strlen($this->password);
_error_log('Error : 1 You need a user to register '.json_encode(debug_backtrace()));
_error_log('Error : 1 You need a user to register ' . json_encode(debug_backtrace()));
return false;
}
if (empty($this->password)) {
@ -799,6 +811,11 @@ if (typeof gtag !== \"function\") {
$values[] = $this->canViewChart;
$sql .= "canViewChart = ?, ";
}
if (!empty($this->birth_date)) {
$formats .= "s";
$values[] = $this->birth_date;
$sql .= "birth_date = ?, ";
}
$formats .= "ssssssisssssssssssi";
$values[] = $this->status;
$values[] = $this->photoURL;
@ -1050,7 +1067,7 @@ if (typeof gtag !== \"function\") {
WHERE users_id = ?
)";
sqlDAL::writeSql($sql, "i", [$this->id]);
$arrayTables = [
//'live_transmition_history_log',
'live_transmitions',
@ -1075,7 +1092,7 @@ if (typeof gtag !== \"function\") {
_error_log("Delete usertable not found {$value}");
$tableExists = false;
}
if ($tableExists) {
$sql = "DELETE FROM {$value} WHERE users_id = ?";
try {
@ -1109,7 +1126,7 @@ if (typeof gtag !== \"function\") {
return self::USER_LOGGED;
}
global $global, $advancedCustom, $advancedCustomUser, $config;
if(class_exists('AVideoPlugin')){
if (class_exists('AVideoPlugin')) {
if (empty($advancedCustomUser)) {
$advancedCustomUser = AVideoPlugin::getObjectData("CustomizeUser");
}
@ -1340,6 +1357,39 @@ if (typeof gtag !== \"function\") {
return !empty($_SESSION['user']['isAdmin']);
}
public static function getBirthIfIsSet($users_id = 0)
{
$birth_date = '';
if (!empty($users_id)) {
$user = new User($users_id);
$birth_date = $user->getBirth_date();
} else {
self::recreateLoginFromCookie();
$birth_date = $_SESSION['user']['birth_date'];
}
return $birth_date;
}
public static function getAge($users_id = 0)
{
$birth_date = self::getBirthIfIsSet($users_id);
if (empty($birth_date)) {
return 0;
}
$birth_date = new DateTime($birth_date);
$current_date = new DateTime('now');
$age = $current_date->diff($birth_date)->y;
if($age<0){
return 0;
}
return $age;
}
public static function isOver18($users_id = 0): bool
{
return self::getAge($users_id) > 18;
}
public static function isACompany($users_id = 0)
{
global $_is_a_company;
@ -1977,12 +2027,12 @@ if (typeof gtag !== \"function\") {
//current=1&rowCount=10&sort[sender]=asc&searchPhrase=
global $global;
$sql = "SELECT * ";
if(!empty($_REQUEST['getUsage'])){
$sql .=", (SELECT sum(filesize) as total FROM videos WHERE filesize > 0 AND (users_id = u.id)) as usageInBytes";
if (!empty($_REQUEST['getUsage'])) {
$sql .= ", (SELECT sum(filesize) as total FROM videos WHERE filesize > 0 AND (users_id = u.id)) as usageInBytes";
}
$sql .=" FROM users u WHERE 1=1 ";
$sql .= " FROM users u WHERE 1=1 ";
if (!empty($status)) {
if (strtolower($status) === 'i') {
$sql .= " AND status = 'i' ";
@ -2303,17 +2353,17 @@ if (typeof gtag !== \"function\") {
global $global, $config, $advancedCustomUser;
$reason = [];
if (empty($doNotCheckPlugins) && !AVideoPlugin::userCanUpload(User::getId())) {
$reason[] = 'A plugin said users_id=['.User::getId().'] cannot upload';
$reason[] = 'A plugin said users_id=[' . User::getId() . '] cannot upload';
}
if ((isset($advancedCustomUser->onlyVerifiedEmailCanUpload) && $advancedCustomUser->onlyVerifiedEmailCanUpload && !User::isVerified())) {
$reason[] = 'The email is not verified';
}
if ($config->getAuthCanUploadVideos() && !self::isLogged()) {
if ($config->getAuthCanUploadVideos() && !self::isLogged()) {
$reason[] = 'The user is not logged';
}
if (self::isLogged() && !empty($_SESSION['user']['canUpload'])) {
if (self::isLogged() && !empty($_SESSION['user']['canUpload'])) {
$reason[] = 'You do not have upload rights';
}
return $reason;
@ -2677,7 +2727,7 @@ if (typeof gtag !== \"function\") {
$msg .= "<br><br>" . __($advancedCustomUser->verificationMailTextLine4);
$msg .= "<br><br>" . " <a href='{$global['webSiteRootURL']}objects/userVerifyEmail.php?code={$code}'>" . __("Verify") . "</a>";
$resp = sendSiteEmail($user->getEmail(), __('Please Verify Your E-mail '). ' ' . $webSiteTitle, $msg);
$resp = sendSiteEmail($user->getEmail(), __('Please Verify Your E-mail ') . ' ' . $webSiteTitle, $msg);
if (!$resp) {
_error_log("sendVerificationLink Error Info: {$mail->ErrorInfo}");

View file

@ -51,6 +51,7 @@ $user->setStatus($_POST['status']);
$user->setEmailVerified($_POST['isEmailVerified']);
$user->setAnalyticsCode($_POST['analyticsCode']);
$user->setPhone($_POST['phone']);
$user->setBirth_date($_POST['birth']);
_error_log("userAddNew.json.php: set channel name = ({$_POST['channelName']})");

View file

@ -29,6 +29,7 @@ $user->setAbout($_POST['about']);
$user->setAnalyticsCode($_POST['analyticsCode']);
$user->setDonationLink($_POST['donationLink']);
$user->setPhone($_POST['phone']);
$user->setBirth_date($_POST['birth_date']);
$unique = $user->setChannelName($_POST['channelName']);
if (!$unique) {
$obj->msg = __("Channel name already exists");

View file

@ -1841,7 +1841,6 @@ if (!class_exists('Video')) {
_error_log("Video::updateLikesDislikes: id={$row['id']}");
$row['dislikes'] = self::updateLikesDislikes($row['id'], 'dislikes');
}
if (empty($row['duration_in_seconds']) && in_array($row['type'], $allowedDurationTypes)) {
_error_log("Video::duration_in_seconds: id={$row['id']} {$row['duration']} {$row['type']}");
$row['duration_in_seconds'] = self::updateDurationInSeconds($row['id'], $row['duration']);
@ -1996,6 +1995,7 @@ if (!class_exists('Video')) {
$row['views_count_short'] = number_format_short($row['views_count']);
TimeLogEnd($timeLogName, __LINE__, $TimeLogLimit);
$row['identification'] = User::getNameIdentificationById(!empty($row['users_id_company']) ? $row['users_id_company'] : $row['users_id']);
$row['age'] = User::getAge($row['users_id']);
if (empty($row['externalOptions'])) {
$row['externalOptions'] = json_encode(['videoStartSeconds' => '00:00:00']);

View file

@ -1,6 +1,6 @@
<?php
require_once dirname(__FILE__) . '/../../videos/configuration.php';
$global['doNotLoadPlayer'] = 1;
setIsConfirmationPage();
$images = Video::getImageFromFilename($video['filename']);
$img = $images->poster;
@ -11,82 +11,108 @@ $imgw = 1280;
$imgh = 720;
$metaDescription = $title = getSEOTitle($video['title']);
$ogURL = Video::getLinkToVideo($video['id'], $video['clean_title'], false, false);
$_page = new Page(array('Confirm Rating'));
?>
<!DOCTYPE html>
<html lang="<?php echo getLanguage(); ?>">
<head>
<title><?php echo __("Confirm Rating") . $config->getPageTitleSeparator() . $title; ?></title>
<?php
include $global['systemRootPath'] . 'view/include/head.php';
?>
<style>
body {
padding-top: 0;
}
footer{
display: none;
}
#bg{
position: fixed;
width: 100%;
height: 100%;
background-image: url('<?php echo $images->poster; ?>');
background-size: cover;
opacity: 0.3;
filter: alpha(opacity=30); /* For IE8 and earlier */
}
</style>
</head>
<body class="<?php echo $global['bodyClass']; ?>">
<?php
//include $global['systemRootPath'] . 'view/include/navbar.php';
?>
<div id="bg"></div>
<!-- Modal -->
<div id="myModal" class="modal fade in" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title">
<?php echo $video['title']; ?>
</h2>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-2">
<?php
echo Video::getRratingIMG($video['rrating']);
?>
</div>
<div class="col-sm-4">
<img src="<?php echo $img; ?>" class="img img-responsive"/>
</div>
<div class="col-sm-6 text-center">
<?php
echo Video::getRratingText($video['rrating']);
?>
</div>
</div>
</div>
<div class="modal-footer" >
<a href="<?php echo $_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], "?") === false ? "?" : "&"; ?>rrating=1" class="btn btn-success pull-right"><i class="fas fa-check-circle"></i> <?php echo __("Confirm"); ?></a>
<a href="<?php echo getHomePageURL(); ?>" class="btn btn-danger pull-right"><i class="fas fa-times-circle"></i> <?php echo __("Cancel"); ?></a>
</div>
<style>
#bg {
position: fixed;
width: 100%;
height: 100%;
background-image: url('<?php echo $images->poster; ?>');
background-size: cover;
opacity: 0.3;
filter: alpha(opacity=30);
z-index: -1;
/* For IE8 and earlier */
}
</style>
<div id="bg"></div>
<div class="container">
<div class="panel panel-danger">
<div class="panel-heading">
<h1>
<?php echo $video['title']; ?>
</h1>
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-2">
<?php
echo Video::getRratingIMG($video['rrating']);
?>
</div>
<div class="col-sm-4">
<img src="<?php echo $img; ?>" class="img img-responsive" />
</div>
<div class="col-sm-6 text-center">
<?php
echo Video::getRratingText($video['rrating']);
?>
</div>
</div>
</div>
<?php
include $global['systemRootPath'] . 'view/include/footer.php';
?>
<script type="text/javascript">
$(window).on('load', function () {
$('#myModal').modal('show');
});
</script>
</body>
</html>
<div class="panel-footer">
<?php
$canAccept = true;
if ($video['rrating'] == 'ma') { // if is mature
if (!User::isLogged()) {
$canAccept = false;
?>
<div class="alert alert-warning">
<strong><?php echo __('Sign In Required'); ?></strong>
<p><?php echo __('This content is for viewers 18+'); ?></p>
<a href="<?php echo $global['webSiteRootURL']; ?>user" class="btn btn-primary btn-block">
<i class="fa-solid fa-right-to-bracket"></i>
<?php echo __('Sign In'); ?>
</a>
</div>
<?php
} else {
$birth_date = User::getBirthIfIsSet();
if (empty($birth_date)) {
$canAccept = false;
?>
<div class="alert alert-danger">
<strong><?php echo __('Age Confirmation Needed'); ?></strong>
<p><?php echo __('Please update your birth date in your profile to access this content'); ?></p>
<a href="<?php echo $global['webSiteRootURL']; ?>user" class="btn btn-primary btn-block">
<i class="fa-solid fa-clipboard-check"></i>
<?php echo __('Update Profile'); ?>
</a>
</div>
<?php
} else if (!User::isOver18()) {
$canAccept = false;
?>
<div class="alert alert-info">
<strong><?php echo __('Content Not Available'); ?></strong>
<p><?php echo __('This content is restricted to viewers 18 and over'); ?></p>
<a href="<?php echo $global['webSiteRootURL']; ?>user" class="btn btn-primary btn-block">
<i class="fa-solid fa-house"></i>
<?php echo __('Home'); ?>
</a>
</div>
<?php
}
}
}
if ($canAccept) {
?>
<div class="btn-group btn-group-justified">
<a href="<?php echo getHomePageURL(); ?>" class="btn btn-danger">
<i class="fas fa-times-circle"></i> <?php echo __("Cancel"); ?>
</a>
<a href="<?php echo $_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], "?") === false ? "?" : "&"; ?>rrating=1" class="btn btn-success">
<i class="fas fa-check-circle"></i> <?php echo __("Confirm"); ?>
</a>
</div>
<?php
}
?>
</div>
</div>
</div>
<?php
$_page->print();
?>

View file

@ -0,0 +1,3 @@
ALTER TABLE `users` ADD COLUMN `birth_date` DATE NULL DEFAULT NULL;
UPDATE configurations SET version = '14.2', modified = now() WHERE id = 1;

View file

@ -2704,7 +2704,7 @@ function isUserOnline(users_id) {
}
function isReadyToCheckIfIsOnline() {
return !empty(users_id_online);
return typeof users_id_online !== 'undefined' && !empty(users_id_online);
}
var addAtMentionActive = false;

View file

@ -105,27 +105,58 @@ foreach ($userGroups as $value) {
<div class="modal-body">
<form class="form-compact" id="updateUserForm" onsubmit="">
<input type="hidden" id="inputUserId">
<label for="inputUser" class="sr-only"><?php echo __("User"); ?></label>
<input type="text" id="inputUser" class="form-control first" placeholder="<?php echo __("User"); ?>" autofocus required="required" data-toggle="tooltip" title="<?php echo __('User'); ?>">
<?php
getInputPassword("inputPassword", 'class="form-control" required="required" autocomplete="off"', __("Password"));
?>
<label for="inputEmail" class="sr-only"><?php echo __("E-mail"); ?></label>
<input type="email" id="inputEmail" class="form-control" placeholder="<?php echo __("E-mail"); ?>" data-toggle="tooltip" title="<?php echo __('E-mail'); ?>">
<label for="inputName" class="sr-only"><?php echo __("Name"); ?></label>
<input type="text" id="inputName" class="form-control " placeholder="<?php echo __("Name"); ?>" data-toggle="tooltip" title="<?php echo __('Name'); ?>">
<label for="inputChannelName" class="sr-only"><?php echo __("Channel Name"); ?></label>
<input type="text" id="inputChannelName" class="form-control" placeholder="<?php echo __("Channel Name"); ?>" data-toggle="tooltip" title="<?php echo __('Channel Name'); ?>">
<label for="inputPhone" class="sr-only"><?php echo __("Phone"); ?></label>
<input type="text" id="inputPhone" class="form-control" placeholder="<?php echo __("Phone"); ?>" data-toggle="tooltip" title="<?php echo __('Phone'); ?>">
<label for="inputAnalyticsCode" class="sr-only"><?php echo __("Analytics Code"); ?></label>
<input type="text" id="inputAnalyticsCode" class="form-control last" placeholder="Google Analytics Code: UA-123456789-1" data-toggle="tooltip" title="<?php echo __('Analytics Code'); ?>">
<small>Do not paste the full javascript code, paste only the gtag id</small>
<br>
<div class="row">
<div class="col-sm-6">
<label for="inputUser"><?php echo __("User"); ?></label>
<input type="text" id="inputUser" class="form-control first" placeholder="<?php echo __("User"); ?>" autofocus required="required" data-toggle="tooltip" title="<?php echo __('User'); ?>">
</div>
<div class="col-sm-6">
<label for="inputPassword"><?php echo __("Password"); ?></label><?php
getInputPassword("inputPassword", 'class="form-control" required="required" autocomplete="off"', __("Password"));
?>
</div>
<div class="col-sm-6">
<label for="inputName">
<?php echo __("Name"); ?>
</label>
<input type="text" id="inputName" class="form-control " placeholder="<?php echo __("Name"); ?>" data-toggle="tooltip" title="<?php echo __('Name'); ?>">
</div>
<div class="col-sm-6">
<label for="inputEmail">
<?php echo __("E-mail"); ?>
</label>
<input type="email" id="inputEmail" class="form-control" placeholder="<?php echo __("E-mail"); ?>" data-toggle="tooltip" title="<?php echo __('E-mail'); ?>">
</div>
<div class="col-sm-6">
<label for="inputChannelName">
<?php echo __("Channel Name"); ?>
</label>
<input type="text" id="inputChannelName" class="form-control" placeholder="<?php echo __("Channel Name"); ?>" data-toggle="tooltip" title="<?php echo __('Channel Name'); ?>">
</div>
<div class="col-sm-6">
<label for="inputBirth">
<?php echo __("Birth"); ?>
</label>
<input type="date" id="inputBirth" class="form-control" placeholder="<?php echo __("Birth"); ?>" data-toggle="tooltip" title="<?php echo __('Birth'); ?>">
</div>
<div class="col-sm-6">
<label for="inputPhone">
<?php echo __("Phone"); ?>
</label>
<input type="text" id="inputPhone" class="form-control" placeholder="<?php echo __("Phone"); ?>" data-toggle="tooltip" title="<?php echo __('Phone'); ?>">
</div>
<div class="col-sm-6">
<label for="inputAnalyticsCode">
<?php echo __("Analytics Code"); ?>
</label>
<input type="text" id="inputAnalyticsCode" class="form-control last" placeholder="Google Analytics Code: UA-123456789-1" data-toggle="tooltip" title="<?php echo __('Analytics Code'); ?>">
<small>Do not paste the full javascript code, paste only the gtag id</small>
</div>
</div>
<?php
if (empty($advancedCustomUser->disableCompanySignUp) || !empty($advancedCustomUser->enableAffiliation)) {
?>
<label for="is_company" class="sr-only"><?php echo __("is a Company"); ?></label>
<label for="is_company"><?php echo __("is a Company"); ?></label>
<select name="is_company" id="is_company" class="form-control last">
<?php
foreach (User::$is_company_status as $key => $value) {
@ -337,6 +368,7 @@ foreach ($userGroups as $value) {
$('#inputName').val('');
$('#inputChannelName').val('');
$('#inputPhone').val('');
$('#inputBirth').val('');
$('#inputAnalyticsCode').val('');
$('#is_company').val(0);
$('#isAdmin').prop('checked', false);
@ -379,6 +411,7 @@ foreach ($userGroups as $value) {
"email": $('#inputEmail').val(),
"name": $('#inputName').val(),
"phone": $('#inputPhone').val(),
"birth": $('#inputBirth').val(),
"channelName": $('#inputChannelName').val(),
"analyticsCode": $('#inputAnalyticsCode').val(),
"isAdmin": $('#isAdmin').is(':checked'),
@ -489,6 +522,7 @@ foreach ($userGroups as $value) {
$('#inputName').val(row.name);
$('#inputChannelName').val(row.channelName);
$('#inputPhone').val(row.phone);
$('#inputBirth').val(row.birth_date);
$('#inputAnalyticsCode').val(row.analyticsCode);
$('.userGroups').prop('checked', false);
$('.usergroupsLi').removeClass('dynamic');

View file

@ -33,6 +33,24 @@
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label"><?php echo __("New Password"); ?></label>
<div class="col-md-8 inputGroupContainer">
<?php
getInputPassword("inputPassword", 'class="form-control" autocomplete="off"', __("New Password"));
?>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label"><?php echo __("Confirm New Password"); ?></label>
<div class="col-md-8 inputGroupContainer">
<?php
getInputPassword("inputPasswordConfirm", 'class="form-control" autocomplete="off"', __("Confirm New Password"));
?>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label"><?php echo __("E-mail"); ?></label>
<div class="col-md-6 inputGroupContainer">
@ -95,22 +113,13 @@
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label"><?php echo __("New Password"); ?></label>
<label class="col-md-4 control-label"><?php echo __("Birth"); ?></label>
<div class="col-md-8 inputGroupContainer">
<?php
getInputPassword("inputPassword", 'class="form-control" autocomplete="off"', __("New Password"));
?>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label"><?php echo __("Confirm New Password"); ?></label>
<div class="col-md-8 inputGroupContainer">
<?php
getInputPassword("inputPasswordConfirm", 'class="form-control" autocomplete="off"', __("Confirm New Password"));
?>
<div class="input-group">
<span class="input-group-addon"><i class="fa-solid fa-cake-candles"></i></span>
<input id="inputBirth" placeholder="<?php echo __("Birth"); ?>" class="form-control" type="date" value="<?php echo $user->getBirth_date(); ?>">
</div>
</div>
</div>
@ -234,6 +243,7 @@
"pass": $('#inputPassword').val(),
"email": $('#inputEmail').val(),
"phone": $('#phone').val(),
"birth_date": $('#inputBirth').val(),
"name": $('#inputName').val(),
"about": content,
"channelName": $('#channelName').val(),