1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 17:59:55 +02:00
Daniel Neto 2024-01-22 11:19:31 -03:00
parent 39c8c0ea06
commit 5bcf87ea81
5 changed files with 44 additions and 19 deletions

View file

@ -1084,7 +1084,16 @@ abstract class CacheHandler {
}
public function getCache($suffix, $lifetime = 60) {
global $_getCache;
if(!isset($_getCache)){
$_getCache = array();
}
$this->setSuffix($suffix);
$name = $this->getCacheName( $this->suffix);
if(isset($_getCache[$name])){
return $_getCache[$name];
}
if(!empty($lifetime) && !$this->canRefreshCache()){
//_error_log("{$suffix} lifetime={$lifetime} cache will not be refreshed now");
$lifetime = 0;
@ -1094,6 +1103,7 @@ abstract class CacheHandler {
if(!empty($cache)){
self::$cachedResults++;
}
$_getCache[$name] = $cache;
return $cache;
}
@ -1129,6 +1139,10 @@ abstract class CacheHandler {
abstract protected function canRefreshCache();
public function hasCache($suffix, $lifetime = 60) {
$cache = $this->getCache($suffix, $lifetime);
return $cache!==null;
}
}
class VideosListCacheHandler extends CacheHandler {

View file

@ -661,9 +661,8 @@ class Category
$timeLogName = TimeLogStart($cacheSuffix);
$cacheHandler = new CategoryCacheHandler(0);
$result = $cacheHandler->getCache($cacheSuffix, 0);
TimeLogEnd($timeLogName, __LINE__);
if (empty($result)) {
if (!$cacheHandler->hasCache($cacheSuffix, 0)) {
$videos = self::getTotalVideosFromCategory($categories_id, $showUnlisted, $getAllVideos, $renew);
TimeLogEnd($timeLogName, __LINE__);
$lives = self::getTotalLivesFromCategory($categories_id, $showUnlisted, $renew);
@ -675,6 +674,7 @@ class Category
$cacheHandler->setCache($result);
TimeLogEnd($timeLogName, __LINE__);
} else {
$result = $cacheHandler->getCache($cacheSuffix, 0);
$result = object_to_array($result);
}
TimeLogEnd($timeLogName, __LINE__);
@ -771,7 +771,7 @@ class Category
$total = $cacheHandler->getCache($suffix);
TimeLogEnd($timeLogName, __LINE__);
if ($renew || empty($total)) {
if ($renew || (empty($total) && $total !== 0 && $total !== '0')) {
$sql = "SELECT count(id) as total FROM videos v WHERE 1=1 AND categories_id = ? ";
if (User::isLogged()) {

View file

@ -1901,7 +1901,8 @@ if (!class_exists('Video')) {
return $videos;
}
static function userHasAgeToWatchVideo($row){
static function userHasAgeToWatchVideo($row)
{
if ($row['rrating'] == 'ma') {
return User::isOver18();
}
@ -2606,12 +2607,18 @@ if (!class_exists('Video')) {
return $numRows;
}
static function videoMadeForKidsExists() {
static function videoMadeForKidsExists()
{
global $_videoMadeForKidsExists, $advancedCustomUser;
if (isset($_videoMadeForKidsExists)) {
//var_dump(__LINE__);
return $_videoMadeForKidsExists;
}
if (empty($advancedCustomUser->videosForKids)) {
if (empty($advancedCustom)) {
$advancedCustom = AVideoPlugin::getObjectData("CustomizeAdvanced");
}
if (empty($advancedCustom->videosForKids)) {
//var_dump(__LINE__);
return false;
}
$sql = "SELECT 1 FROM `videos` v WHERE v.`made_for_kids` = 1 ";
@ -2620,6 +2627,7 @@ if (!class_exists('Video')) {
$res = sqlDAL::readSql($sql);
$video = sqlDAL::fetchAssoc($res);
//var_dump(__LINE__, $sql, $_videoMadeForKidsExists);
$_videoMadeForKidsExists = $video ? true : false;
//var_dump($sql, $_videoMadeForKidsExists, $video);exit;
return $_videoMadeForKidsExists;
@ -6878,3 +6886,4 @@ AVideoPlugin::loadPlugin('Permissions');
if (User::isAdmin() || Permissions::canModerateVideos()) {
$statusThatTheUserCanUpdate[] = [Video::$statusUnpublished, '#B00'];
}
//Video::videoMadeForKidsExists();exit;

View file

@ -1,4 +1,5 @@
<?php
//return false;
global $global, $config;
if (!isset($global['systemRootPath'])) {
require_once '../../../videos/configuration.php';

View file

@ -77,6 +77,7 @@ global $avideoLayout;
</li>
<?php
}
//var_dump(Video::videoMadeForKidsExists());exit;
if (empty($advancedCustomUser->doNotShowLeftProfile)) {
if (User::isLogged()) {
?>