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

View file

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

View file

@ -190,7 +190,7 @@ if (!class_exists('Video')) {
$this->notification_datetime = $notification_datetime; $this->notification_datetime = $notification_datetime;
} }
public function getMade_for_kids() public function getMade_for_kids()
{ {
return _intval($this->made_for_kids); return _intval($this->made_for_kids);
@ -1097,7 +1097,7 @@ if (!class_exists('Video')) {
. "LEFT JOIN users u ON v.users_id = u.id " . "LEFT JOIN users u ON v.users_id = u.id "
. "LEFT JOIN videos nv ON v.next_videos_id = nv.id " . "LEFT JOIN videos nv ON v.next_videos_id = nv.id "
. " WHERE 1=1 "; . " WHERE 1=1 ";
if(isForKidsSet()){ if (isForKidsSet()) {
$sql .= " AND v.made_for_kids = 1 "; $sql .= " AND v.made_for_kids = 1 ";
} }
if ($activeUsersOnly) { if ($activeUsersOnly) {
@ -1472,9 +1472,9 @@ if (!class_exists('Video')) {
$sql .= " UNION "; $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 "; $sql .= " AND made_for_kids = 1 ";
} }
@ -1571,7 +1571,7 @@ if (!class_exists('Video')) {
. " LEFT JOIN users u ON v.users_id = u.id " . " LEFT JOIN users u ON v.users_id = u.id "
. " WHERE 2=2 "; . " WHERE 2=2 ";
if(isForKidsSet()){ if (isForKidsSet()) {
$sql .= " AND made_for_kids = 1 "; $sql .= " AND made_for_kids = 1 ";
} }
$blockedUsers = self::getBlockedUsersIdsArray(); $blockedUsers = self::getBlockedUsersIdsArray();
@ -1901,8 +1901,9 @@ if (!class_exists('Video')) {
return $videos; return $videos;
} }
static function userHasAgeToWatchVideo($row){ static function userHasAgeToWatchVideo($row)
if($row['rrating'] == 'ma'){ {
if ($row['rrating'] == 'ma') {
return User::isOver18(); return User::isOver18();
} }
return true; return true;
@ -2283,7 +2284,7 @@ if (!class_exists('Video')) {
$sql .= " WHERE 1=1 "; $sql .= " WHERE 1=1 ";
if(isForKidsSet()){ if (isForKidsSet()) {
$sql .= " AND made_for_kids = 1 "; $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 categories c ON categories_id = c.id "
. " LEFT JOIN users u ON v.users_id = u.id " . " LEFT JOIN users u ON v.users_id = u.id "
. " WHERE 1=1 "; . " WHERE 1=1 ";
if(isForKidsSet()){ if (isForKidsSet()) {
$sql .= " AND v.made_for_kids = 1 "; $sql .= " AND v.made_for_kids = 1 ";
} }
$blockedUsers = self::getBlockedUsersIdsArray(); $blockedUsers = self::getBlockedUsersIdsArray();
@ -2606,20 +2607,27 @@ if (!class_exists('Video')) {
return $numRows; return $numRows;
} }
static function videoMadeForKidsExists() { static function videoMadeForKidsExists()
{
global $_videoMadeForKidsExists, $advancedCustomUser; global $_videoMadeForKidsExists, $advancedCustomUser;
if(isset($_videoMadeForKidsExists)){ if (isset($_videoMadeForKidsExists)) {
//var_dump(__LINE__);
return $_videoMadeForKidsExists; return $_videoMadeForKidsExists;
} }
if (empty($advancedCustomUser->videosForKids)) { if (empty($advancedCustom)) {
$advancedCustom = AVideoPlugin::getObjectData("CustomizeAdvanced");
}
if (empty($advancedCustom->videosForKids)) {
//var_dump(__LINE__);
return false; return false;
} }
$sql = "SELECT 1 FROM `videos` v WHERE v.`made_for_kids` = 1 "; $sql = "SELECT 1 FROM `videos` v WHERE v.`made_for_kids` = 1 ";
$sql .= " AND v.status IN ('" . implode("','", Video::getViewableStatus(false)) . "')"; $sql .= " AND v.status IN ('" . implode("','", Video::getViewableStatus(false)) . "')";
$sql .= " LIMIT 1 "; $sql .= " LIMIT 1 ";
$res = sqlDAL::readSql($sql); $res = sqlDAL::readSql($sql);
$video = sqlDAL::fetchAssoc($res); $video = sqlDAL::fetchAssoc($res);
//var_dump(__LINE__, $sql, $_videoMadeForKidsExists);
$_videoMadeForKidsExists = $video ? true : false; $_videoMadeForKidsExists = $video ? true : false;
//var_dump($sql, $_videoMadeForKidsExists, $video);exit; //var_dump($sql, $_videoMadeForKidsExists, $video);exit;
return $_videoMadeForKidsExists; return $_videoMadeForKidsExists;
@ -2835,7 +2843,7 @@ if (!class_exists('Video')) {
$videosListCache = new VideosListCacheHandler(); $videosListCache = new VideosListCacheHandler();
$videosListCache->deleteCache(); $videosListCache->deleteCache();
} }
_error_log("Video delete id={$this->id} ".json_encode($resp)); _error_log("Video delete id={$this->id} " . json_encode($resp));
return $resp; return $resp;
} }
@ -6878,3 +6886,4 @@ AVideoPlugin::loadPlugin('Permissions');
if (User::isAdmin() || Permissions::canModerateVideos()) { if (User::isAdmin() || Permissions::canModerateVideos()) {
$statusThatTheUserCanUpdate[] = [Video::$statusUnpublished, '#B00']; $statusThatTheUserCanUpdate[] = [Video::$statusUnpublished, '#B00'];
} }
//Video::videoMadeForKidsExists();exit;

View file

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

View file

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