1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +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

@ -1097,7 +1097,7 @@ if (!class_exists('Video')) {
. "LEFT JOIN users u ON v.users_id = u.id "
. "LEFT JOIN videos nv ON v.next_videos_id = nv.id "
. " WHERE 1=1 ";
if(isForKidsSet()){
if (isForKidsSet()) {
$sql .= " AND v.made_for_kids = 1 ";
}
if ($activeUsersOnly) {
@ -1472,9 +1472,9 @@ if (!class_exists('Video')) {
$sql .= " UNION ";
$sql .= "SELECT * FROM videos v WHERE v.id != {$videos_id} AND v.status='".Video::$statusActive."' ";
$sql .= "SELECT * FROM videos v WHERE v.id != {$videos_id} AND v.status='" . Video::$statusActive . "' ";
if(isForKidsSet()){
if (isForKidsSet()) {
$sql .= " AND made_for_kids = 1 ";
}
@ -1571,7 +1571,7 @@ if (!class_exists('Video')) {
. " LEFT JOIN users u ON v.users_id = u.id "
. " WHERE 2=2 ";
if(isForKidsSet()){
if (isForKidsSet()) {
$sql .= " AND made_for_kids = 1 ";
}
$blockedUsers = self::getBlockedUsersIdsArray();
@ -1901,8 +1901,9 @@ if (!class_exists('Video')) {
return $videos;
}
static function userHasAgeToWatchVideo($row){
if($row['rrating'] == 'ma'){
static function userHasAgeToWatchVideo($row)
{
if ($row['rrating'] == 'ma') {
return User::isOver18();
}
return true;
@ -2283,7 +2284,7 @@ if (!class_exists('Video')) {
$sql .= " WHERE 1=1 ";
if(isForKidsSet()){
if (isForKidsSet()) {
$sql .= " AND made_for_kids = 1 ";
}
@ -2431,7 +2432,7 @@ if (!class_exists('Video')) {
. "LEFT JOIN categories c ON categories_id = c.id "
. " LEFT JOIN users u ON v.users_id = u.id "
. " WHERE 1=1 ";
if(isForKidsSet()){
if (isForKidsSet()) {
$sql .= " AND v.made_for_kids = 1 ";
}
$blockedUsers = self::getBlockedUsersIdsArray();
@ -2606,12 +2607,18 @@ if (!class_exists('Video')) {
return $numRows;
}
static function videoMadeForKidsExists() {
static function videoMadeForKidsExists()
{
global $_videoMadeForKidsExists, $advancedCustomUser;
if(isset($_videoMadeForKidsExists)){
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;
@ -2835,7 +2843,7 @@ if (!class_exists('Video')) {
$videosListCache = new VideosListCacheHandler();
$videosListCache->deleteCache();
}
_error_log("Video delete id={$this->id} ".json_encode($resp));
_error_log("Video delete id={$this->id} " . json_encode($resp));
return $resp;
}
@ -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()) {
?>