1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00
This commit is contained in:
Daniel Neto 2023-12-18 11:49:44 -03:00
parent 46928394ca
commit 51ceea9e6d
6 changed files with 153 additions and 151 deletions

View file

@ -717,6 +717,9 @@ function array_iunique(array $array): array
function partition(array $list, $totalItens)
{
$listlen = count($list);
if(empty($listlen)){
return $list;
}
_error_log("partition: listlen={$listlen} totalItens={$totalItens}");
$p = ceil($listlen / $totalItens);
$partlen = floor($listlen / $p);

View file

@ -21,11 +21,11 @@ if (!(!empty($_REQUEST['user']) && !empty($_REQUEST['recoverpass']))) {
$obj->request = $_REQUEST;
*/
header('Content-Type: application/json');
if(empty($user->getStatus())){
if (empty($user->getStatus())) {
$obj->error = __("User not found");
die(json_encode($obj));
}
if($user->getStatus() !== 'a'){
if ($user->getStatus() !== 'a') {
$obj->error = __("The user is not active");
die(json_encode($obj));
}
@ -44,7 +44,7 @@ if (!(!empty($_REQUEST['user']) && !empty($_REQUEST['recoverpass']))) {
$url = addQueryStringParameter($url, 'recoverpass', $recoverPass);
$to = $user->getEmail();
$subject = __('Recover Pass from') .' '. $config->getWebSiteTitle();
$subject = __('Recover Pass from') . ' ' . $config->getWebSiteTitle();
$message = __("You asked for a recover link, click on the provided link") . "<br><a href='{$url}' class='button blue-button'>" . __("Reset password") . "</a>";
$fromEmail = $config->getContactEmail();
$resp = sendSiteEmail($to, $subject, $message, $fromEmail);
@ -68,109 +68,90 @@ if (!(!empty($_REQUEST['user']) && !empty($_REQUEST['recoverpass']))) {
}
die(json_encode($obj));
} else {
?>
<!DOCTYPE html>
<html lang="<?php echo getLanguage(); ?>">
<head>
<?php echo getHTMLTitle(__("Recover Password")); ?>
<?php include $global['systemRootPath'] . 'view/include/head.php'; ?>
</head>
if ($user->getRecoverPass() !== $_REQUEST['recoverpass']) {
//forbiddenPage('The recover pass does not match!');
}
$_page = new Page(array('Recover Password'));
?>
<div class="container">
<form class="well form-horizontal" action=" " method="post" id="recoverPassForm">
<fieldset>
<body class="<?php echo $global['bodyClass']; ?>">
<?php include $global['systemRootPath'] . 'view/include/navbar.php'; ?>
<!-- Form Name -->
<legend><?php echo __("Recover password!"); ?></legend>
<div class="container">
<?php
if ($user->getRecoverPass() !== $_REQUEST['recoverpass']) {
?>
<div class="alert alert-danger"><?php echo __("The recover pass does not match!"); ?></div>
<?php
} else {
?>
<form class="well form-horizontal" action=" " method="post" id="recoverPassForm">
<fieldset>
<div class="form-group">
<label class="col-md-4 control-label"><?php echo __("User"); ?></label>
<div class="col-md-8 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input name="user" class="form-control" type="text" value="<?php echo $user->getUser(); ?>" readonly>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label"><?php echo __("Recover Password"); ?></label>
<div class="col-md-8 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input name="recoverPassword" class="form-control" type="text" value="<?php echo $user->getRecoverPass(); ?>" readonly>
</div>
</div>
</div>
<!-- Form Name -->
<legend><?php echo __("Recover password!"); ?></legend>
<div class="form-group">
<label class="col-md-4 control-label"><?php echo __("New Password"); ?></label>
<div class="col-md-8 inputGroupContainer">
<?php getInputPassword("newPassword", 'class="form-control" required="required" autocomplete="off"', __("New Password")); ?>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label"><?php echo __("User"); ?></label>
<div class="col-md-8 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input name="user" class="form-control" type="text" value="<?php echo $user->getUser(); ?>" readonly >
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label"><?php echo __("Recover Password"); ?></label>
<div class="col-md-8 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input name="recoverPassword" class="form-control" type="text" value="<?php echo $user->getRecoverPass(); ?>" readonly >
</div>
</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("newPassword", 'class="form-control" required="required" 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("newPasswordConfirm", 'class="form-control" required="required" autocomplete="off"', __("Confirm 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("newPasswordConfirm", 'class="form-control" required="required" autocomplete="off"', __("Confirm New Password")); ?>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-8">
<button type="submit" class="btn btn-primary" ><?php echo __("Save"); ?> <span class="glyphicon glyphicon-save"></span></button>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-8">
<button type="submit" class="btn btn-primary btn-block">
<i class="fa-regular fa-floppy-disk"></i>
<?php echo __("Save Password"); ?>
</button>
</div>
</div>
</fieldset>
</form>
<?php }
?>
</div>
</div><!--/.container-->
<?php include $global['systemRootPath'] . 'view/include/footer.php'; ?>
<script>
$(document).ready(function () {
$('#recoverPassForm').submit(function (evt) {
evt.preventDefault();
modal.showPleaseWait();
$.ajax({
url: '<?php echo $global['webSiteRootURL']; ?>objects/userRecoverPassSave.json.php',
data: $('#recoverPassForm').serializeArray(),
type: 'post',
success: function (response) {
modal.hidePleaseWait();
if (!response.error) {
avideoAlert("<?php echo __("Congratulations!"); ?>", "<?php echo __("Your new password has been set!"); ?>", "success");
} else {
avideoAlert("<?php echo __("Your new password could not be set!"); ?>", response.error, "error");
}
</fieldset>
</form>
</div>
<script>
$(document).ready(function() {
$('#recoverPassForm').submit(function(evt) {
evt.preventDefault();
modal.showPleaseWait();
$.ajax({
url: '<?php echo $global['webSiteRootURL']; ?>objects/userRecoverPassSave.json.php',
data: $('#recoverPassForm').serializeArray(),
type: 'post',
success: function(response) {
modal.hidePleaseWait();
if (!response.error) {
avideoAlert("<?php echo __("Congratulations!"); ?>", "<?php echo __("Your new password has been set!"); ?>", "success");
} else {
avideoAlert("<?php echo __("Your new password could not be set!"); ?>", response.error, "error");
}
});
return false;
}
});
return false;
});
</script>
</body>
</html>
});
</script>
<?php
<?php
$_page->print();exit;
}

View file

@ -206,70 +206,84 @@ class CachesInDB extends ObjectYPT
$c->setExpires(date('Y-m-d H:i:s', strtotime('+ 1 month')));
return $c->save();
}
public static function setBulkCache($cacheArray, $metadata, $try=0) {
private static function prepareCacheItem($name, $cache, $metadata, $tz, $time) {
$formattedCacheItem = [];
$name = self::hashName($name);
$content = !is_string($cache) ? json_encode($cache) : $cache;
if (empty($content)) {
return null;
}
$expires = date('Y-m-d H:i:s', strtotime('+1 month'));
// Format for the prepared statement
$formattedCacheItem['format'] = "ssssssssi";
$formattedCacheItem['values'] = [
$name,
$content,
$metadata['domain'],
$metadata['ishttps'],
$metadata['user_location'],
$metadata['loggedType'],
$expires,
$tz,
$time
];
return $formattedCacheItem;
}
public static function setBulkCache($cacheArray, $metadata, $try = 0, $maxRetries = 5) {
if (empty($cacheArray)) {
return false;
}
global $global;
$placeholders = [];
$formats = [];
$values = [];
$batchSize = 50; // Adjust batch size as appropriate
$cacheBatches = array_chunk($cacheArray, $batchSize, true);
$tz = date_default_timezone_get();
$time = time();
$start = microtime(true);
foreach ($cacheArray as $name => $cache) {
$name = self::hashName($name);
$content = !is_string($cache) ? _json_encode($cache) : $cache;
if (empty($content)) continue;
$formats[] = "ssssssssi";
$placeholders[] = "(?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())";
$expires = date('Y-m-d H:i:s', strtotime('+ 1 month'));
/*
echo PHP_EOL.'--name=';
var_dump($name);
echo PHP_EOL.'--content=';
var_dump($content);
*/
// Add values to the values array
//_error_log("setBulkCache [{$name}]");
array_push($values, $name, $content, $metadata['domain'], $metadata['ishttps'], $metadata['user_location'], $metadata['loggedType'], $expires, $tz, $time);
}
$sql = "INSERT INTO " . static::getTableName() . " (name, content, domain, ishttps, user_location, loggedType, expires, timezone, created_php_time, created, modified)
VALUES " . implode(", ", $placeholders) . "
ON DUPLICATE KEY UPDATE
content = VALUES(content),
expires = VALUES(expires),
created_php_time = VALUES(created_php_time),
modified = NOW()";
// Assuming you have a PDO connection $pdo
try {
$result = sqlDAL::writeSql($sql, implode('', $formats), $values);
} catch (\Throwable $th) {
if(preg_match('/Deadlock found when trying to get lock/i', $th->getMessage())){
if(empty($try)){
_error_log($th->getMessage(), AVideoLog::$WARNING);
$sql = 'DROP TABLE IF EXISTS `CachesInDB`';
sqlDAL::writeSql($sql, implode('', $formats), $values);
$file = $global['systemRootPath'] . 'plugin/Cache/install/install.sql';
sqlDal::executeFile($file);
return self::setBulkCache($cacheArray, $metadata, $try+1);
}else{
_error_log($th->getMessage(), AVideoLog::$ERROR);
$result = true;
foreach ($cacheBatches as $batch) {$placeholders = [];
$formats = [];
$values = [];
foreach ($batch as $name => $cache) {
$cacheItem = self::prepareCacheItem($name, $cache, $metadata, $tz, $time);
if ($cacheItem === null) continue;
$placeholders[] = "(?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())";
$formats[] = $cacheItem['format'];
$values = array_merge($values, $cacheItem['values']);
}
$sql = "INSERT INTO " . static::getTableName() . " (...) VALUES " . implode(", ", $placeholders) . " ON DUPLICATE KEY UPDATE ...";
// Start transaction
mysqlBeginTransaction();
try {
$result &= sqlDAL::writeSql($sql, implode('', $formats), $values);
mysqlCommit();
} catch (\Throwable $th) {
mysqlRollback();
_error_log($th->getMessage(), AVideoLog::$ERROR);
if ($try < $maxRetries && preg_match('/Deadlock found/i', $th->getMessage())) {
usleep(100000 * pow(2, $try)); // Exponential backoff
return self::setBulkCache($cacheArray, $metadata, $try + 1, $maxRetries);
} else {
// Handle the error or throw an exception
return false;
}
}
}
//_error_log("setBulkCache writeSql total= ".count($placeholders));
//var_dump($result, $sql, implode('', $formats), $values);exit;
$end = number_format(microtime(true) - $start, 5);
//_error_log("Disk setBulkCache took {$end} seconds");
return $result;
}
public static function _deleteCache($name)
{

View file

@ -53,7 +53,10 @@ class CookieAlert extends PluginAbstract {
}
$obj = $this->getDataObject();
global $global;
if(!empty($global['cookieAlertAlreadyIncluded'])){
return '';
}
$global['cookieAlertAlreadyIncluded'] = 1;
include $global['systemRootPath'] . 'plugin/CookieAlert/footer.php';
}

View file

@ -10,6 +10,7 @@ function startCookieAlert(){
return false;
}
if (!getCookie("acceptCookies") && !inIframe()) {
$(".cookiealert").show();
$(".cookiealert").addClass("show");
}
$(".acceptcookies").on('click', function(){

View file

@ -1,5 +1,5 @@
<!-- COOKIES -->
<div class="alert alert-dismissible text-center cookiealert" role="alert">
<div class="alert alert-dismissible text-center cookiealert" role="alert" style="display: none;">
<div class="cookiealert-container">
<?php echo $obj->text; ?>
<button type="button" class="btn btn-primary btn-sm acceptcookies" aria-label="Close">