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

@ -68,25 +68,12 @@ if (!(!empty($_REQUEST['user']) && !empty($_REQUEST['recoverpass']))) {
} }
die(json_encode($obj)); die(json_encode($obj));
} else { } else {
?>
<!DOCTYPE html>
<html lang="<?php echo getLanguage(); ?>">
<head>
<?php echo getHTMLTitle(__("Recover Password")); ?>
<?php include $global['systemRootPath'] . 'view/include/head.php'; ?>
</head>
<body class="<?php echo $global['bodyClass']; ?>">
<?php include $global['systemRootPath'] . 'view/include/navbar.php'; ?>
<div class="container">
<?php
if ($user->getRecoverPass() !== $_REQUEST['recoverpass']) { if ($user->getRecoverPass() !== $_REQUEST['recoverpass']) {
//forbiddenPage('The recover pass does not match!');
}
$_page = new Page(array('Recover Password'));
?> ?>
<div class="alert alert-danger"><?php echo __("The recover pass does not match!"); ?></div> <div class="container">
<?php
} else {
?>
<form class="well form-horizontal" action=" " method="post" id="recoverPassForm"> <form class="well form-horizontal" action=" " method="post" id="recoverPassForm">
<fieldset> <fieldset>
@ -131,20 +118,16 @@ if (!(!empty($_REQUEST['user']) && !empty($_REQUEST['recoverpass']))) {
<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">
<i class="fa-regular fa-floppy-disk"></i>
<?php echo __("Save Password"); ?>
</button>
</div> </div>
</div> </div>
</fieldset> </fieldset>
</form> </form>
<?php }
?>
</div> </div>
</div><!--/.container-->
<?php include $global['systemRootPath'] . 'view/include/footer.php'; ?>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
$('#recoverPassForm').submit(function(evt) { $('#recoverPassForm').submit(function(evt) {
@ -167,10 +150,8 @@ if (!(!empty($_REQUEST['user']) && !empty($_REQUEST['recoverpass']))) {
}); });
}); });
</script> </script>
</body>
</html>
<?php <?php
$_page->print();exit;
} }

View file

@ -206,71 +206,85 @@ 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) {
$formattedCacheItem = [];
public static function setBulkCache($cacheArray, $metadata, $try=0) { $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;
$placeholders = []; global $global;
$formats = []; $batchSize = 50; // Adjust batch size as appropriate
$values = []; $cacheBatches = array_chunk($cacheArray, $batchSize, true);
$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 = [];
foreach ($batch as $name => $cache) {
$cacheItem = self::prepareCacheItem($name, $cache, $metadata, $tz, $time);
if ($cacheItem === null) continue;
$formats[] = "ssssssssi";
$placeholders[] = "(?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())"; $placeholders[] = "(?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())";
$formats[] = $cacheItem['format'];
$expires = date('Y-m-d H:i:s', strtotime('+ 1 month')); $values = array_merge($values, $cacheItem['values']);
/*
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) $sql = "INSERT INTO " . static::getTableName() . " (...) VALUES " . implode(", ", $placeholders) . " ON DUPLICATE KEY UPDATE ...";
VALUES " . implode(", ", $placeholders) . "
ON DUPLICATE KEY UPDATE // Start transaction
content = VALUES(content), mysqlBeginTransaction();
expires = VALUES(expires),
created_php_time = VALUES(created_php_time),
modified = NOW()";
// Assuming you have a PDO connection $pdo
try { try {
$result = sqlDAL::writeSql($sql, implode('', $formats), $values); $result &= sqlDAL::writeSql($sql, implode('', $formats), $values);
mysqlCommit();
} catch (\Throwable $th) { } catch (\Throwable $th) {
if(preg_match('/Deadlock found when trying to get lock/i', $th->getMessage())){ mysqlRollback();
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($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; return $result;
} }
public static function _deleteCache($name) public static function _deleteCache($name)
{ {
global $global; global $global;

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">