1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +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) function partition(array $list, $totalItens)
{ {
$listlen = count($list); $listlen = count($list);
if(empty($listlen)){
return $list;
}
_error_log("partition: listlen={$listlen} totalItens={$totalItens}"); _error_log("partition: listlen={$listlen} totalItens={$totalItens}");
$p = ceil($listlen / $totalItens); $p = ceil($listlen / $totalItens);
$partlen = floor($listlen / $p); $partlen = floor($listlen / $p);

View file

@ -21,11 +21,11 @@ if (!(!empty($_REQUEST['user']) && !empty($_REQUEST['recoverpass']))) {
$obj->request = $_REQUEST; $obj->request = $_REQUEST;
*/ */
header('Content-Type: application/json'); header('Content-Type: application/json');
if(empty($user->getStatus())){ if (empty($user->getStatus())) {
$obj->error = __("User not found"); $obj->error = __("User not found");
die(json_encode($obj)); die(json_encode($obj));
} }
if($user->getStatus() !== 'a'){ if ($user->getStatus() !== 'a') {
$obj->error = __("The user is not active"); $obj->error = __("The user is not active");
die(json_encode($obj)); die(json_encode($obj));
} }
@ -44,7 +44,7 @@ if (!(!empty($_REQUEST['user']) && !empty($_REQUEST['recoverpass']))) {
$url = addQueryStringParameter($url, 'recoverpass', $recoverPass); $url = addQueryStringParameter($url, 'recoverpass', $recoverPass);
$to = $user->getEmail(); $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>"; $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(); $fromEmail = $config->getContactEmail();
$resp = sendSiteEmail($to, $subject, $message, $fromEmail); $resp = sendSiteEmail($to, $subject, $message, $fromEmail);
@ -68,109 +68,90 @@ if (!(!empty($_REQUEST['user']) && !empty($_REQUEST['recoverpass']))) {
} }
die(json_encode($obj)); die(json_encode($obj));
} else { } else {
?> if ($user->getRecoverPass() !== $_REQUEST['recoverpass']) {
<!DOCTYPE html> //forbiddenPage('The recover pass does not match!');
<html lang="<?php echo getLanguage(); ?>"> }
<head> $_page = new Page(array('Recover Password'));
<?php echo getHTMLTitle(__("Recover Password")); ?> ?>
<?php include $global['systemRootPath'] . 'view/include/head.php'; ?> <div class="container">
</head> <form class="well form-horizontal" action=" " method="post" id="recoverPassForm">
<fieldset>
<body class="<?php echo $global['bodyClass']; ?>"> <!-- Form Name -->
<?php include $global['systemRootPath'] . 'view/include/navbar.php'; ?> <legend><?php echo __("Recover password!"); ?></legend>
<div class="container"> <div class="form-group">
<?php <label class="col-md-4 control-label"><?php echo __("User"); ?></label>
if ($user->getRecoverPass() !== $_REQUEST['recoverpass']) { <div class="col-md-8 inputGroupContainer">
?> <div class="input-group">
<div class="alert alert-danger"><?php echo __("The recover pass does not match!"); ?></div> <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<?php <input name="user" class="form-control" type="text" value="<?php echo $user->getUser(); ?>" readonly>
} else { </div>
?> </div>
<form class="well form-horizontal" action=" " method="post" id="recoverPassForm"> </div>
<fieldset> <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 --> <div class="form-group">
<legend><?php echo __("Recover password!"); ?></legend> <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"> <div class="form-group">
<label class="col-md-4 control-label"><?php echo __("User"); ?></label> <label class="col-md-4 control-label"><?php echo __("Confirm New Password"); ?></label>
<div class="col-md-8 inputGroupContainer"> <div class="col-md-8 inputGroupContainer">
<div class="input-group"> <?php getInputPassword("newPasswordConfirm", 'class="form-control" required="required" autocomplete="off"', __("Confirm New Password")); ?>
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span> </div>
<input name="user" class="form-control" type="text" value="<?php echo $user->getUser(); ?>" readonly > </div>
</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>
<!-- Button --> <!-- Button -->
<div class="form-group"> <div class="form-group">
<label class="col-md-4 control-label"></label> <label class="col-md-4 control-label"></label>
<div class="col-md-8"> <div class="col-md-8">
<button type="submit" class="btn btn-primary" ><?php echo __("Save"); ?> <span class="glyphicon glyphicon-save"></span></button> <button type="submit" class="btn btn-primary btn-block">
</div> <i class="fa-regular fa-floppy-disk"></i>
</div> <?php echo __("Save Password"); ?>
</button>
</div>
</div>
</fieldset> </fieldset>
</form> </form>
<?php } </div>
?> <script>
</div> $(document).ready(function() {
$('#recoverPassForm').submit(function(evt) {
</div><!--/.container--> evt.preventDefault();
modal.showPleaseWait();
<?php include $global['systemRootPath'] . 'view/include/footer.php'; ?> $.ajax({
url: '<?php echo $global['webSiteRootURL']; ?>objects/userRecoverPassSave.json.php',
<script> data: $('#recoverPassForm').serializeArray(),
$(document).ready(function () { type: 'post',
$('#recoverPassForm').submit(function (evt) { success: function(response) {
evt.preventDefault(); modal.hidePleaseWait();
modal.showPleaseWait(); if (!response.error) {
$.ajax({ avideoAlert("<?php echo __("Congratulations!"); ?>", "<?php echo __("Your new password has been set!"); ?>", "success");
url: '<?php echo $global['webSiteRootURL']; ?>objects/userRecoverPassSave.json.php', } else {
data: $('#recoverPassForm').serializeArray(), avideoAlert("<?php echo __("Your new password could not be set!"); ?>", response.error, "error");
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> </script>
</html>
<?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'))); $c->setExpires(date('Y-m-d H:i:s', strtotime('+ 1 month')));
return $c->save(); return $c->save();
} }
private static function prepareCacheItem($name, $cache, $metadata, $tz, $time) {
public static function setBulkCache($cacheArray, $metadata, $try=0) { $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)) { if (empty($cacheArray)) {
return false; return false;
} }
global $global; global $global;
$batchSize = 50; // Adjust batch size as appropriate
$placeholders = []; $cacheBatches = array_chunk($cacheArray, $batchSize, true);
$formats = [];
$values = [];
$tz = date_default_timezone_get(); $tz = date_default_timezone_get();
$time = time(); $time = time();
$start = microtime(true); $result = true;
foreach ($cacheArray as $name => $cache) {
$name = self::hashName($name); foreach ($cacheBatches as $batch) {$placeholders = [];
$content = !is_string($cache) ? _json_encode($cache) : $cache; $formats = [];
if (empty($content)) continue; $values = [];
$formats[] = "ssssssssi"; foreach ($batch as $name => $cache) {
$placeholders[] = "(?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())"; $cacheItem = self::prepareCacheItem($name, $cache, $metadata, $tz, $time);
if ($cacheItem === null) continue;
$expires = date('Y-m-d H:i:s', strtotime('+ 1 month'));
/* $placeholders[] = "(?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())";
echo PHP_EOL.'--name='; $formats[] = $cacheItem['format'];
var_dump($name); $values = array_merge($values, $cacheItem['values']);
echo PHP_EOL.'--content='; }
var_dump($content);
*/ $sql = "INSERT INTO " . static::getTableName() . " (...) VALUES " . implode(", ", $placeholders) . " ON DUPLICATE KEY UPDATE ...";
// Add values to the values array
//_error_log("setBulkCache [{$name}]"); // Start transaction
array_push($values, $name, $content, $metadata['domain'], $metadata['ishttps'], $metadata['user_location'], $metadata['loggedType'], $expires, $tz, $time); mysqlBeginTransaction();
}
try {
$sql = "INSERT INTO " . static::getTableName() . " (name, content, domain, ishttps, user_location, loggedType, expires, timezone, created_php_time, created, modified) $result &= sqlDAL::writeSql($sql, implode('', $formats), $values);
VALUES " . implode(", ", $placeholders) . " mysqlCommit();
ON DUPLICATE KEY UPDATE } catch (\Throwable $th) {
content = VALUES(content), mysqlRollback();
expires = VALUES(expires), _error_log($th->getMessage(), AVideoLog::$ERROR);
created_php_time = VALUES(created_php_time),
modified = NOW()"; if ($try < $maxRetries && preg_match('/Deadlock found/i', $th->getMessage())) {
usleep(100000 * pow(2, $try)); // Exponential backoff
// Assuming you have a PDO connection $pdo return self::setBulkCache($cacheArray, $metadata, $try + 1, $maxRetries);
try { } else {
$result = sqlDAL::writeSql($sql, implode('', $formats), $values); // Handle the error or throw an exception
} catch (\Throwable $th) { return false;
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);
} }
} }
} }
//_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; return $result;
} }
public static function _deleteCache($name) public static function _deleteCache($name)
{ {

View file

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

View file

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

View file

@ -1,5 +1,5 @@
<!-- COOKIES --> <!-- 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"> <div class="cookiealert-container">
<?php echo $obj->text; ?> <?php echo $obj->text; ?>
<button type="button" class="btn btn-primary btn-sm acceptcookies" aria-label="Close"> <button type="button" class="btn btn-primary btn-sm acceptcookies" aria-label="Close">