diff --git a/objects/Object.php b/objects/Object.php index b73dda1d58..a42362c712 100644 --- a/objects/Object.php +++ b/objects/Object.php @@ -1084,7 +1084,16 @@ abstract class CacheHandler { } 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()){ //_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 { diff --git a/objects/category.php b/objects/category.php index 6c9f82c2b7..29e98cd404 100644 --- a/objects/category.php +++ b/objects/category.php @@ -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()) { diff --git a/objects/video.php b/objects/video.php index 11453eef0e..8dbd188cf1 100644 --- a/objects/video.php +++ b/objects/video.php @@ -190,7 +190,7 @@ if (!class_exists('Video')) { $this->notification_datetime = $notification_datetime; } - + public function getMade_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 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,20 +2607,27 @@ 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 "; - $sql .= " AND v.status IN ('" . implode("','", Video::getViewableStatus(false)) . "')"; + $sql = "SELECT 1 FROM `videos` v WHERE v.`made_for_kids` = 1 "; + $sql .= " AND v.status IN ('" . implode("','", Video::getViewableStatus(false)) . "')"; $sql .= " LIMIT 1 "; $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; \ No newline at end of file diff --git a/plugin/Gallery/view/modeGalleryCategory.php b/plugin/Gallery/view/modeGalleryCategory.php index e40a283aa4..26be1f9c08 100644 --- a/plugin/Gallery/view/modeGalleryCategory.php +++ b/plugin/Gallery/view/modeGalleryCategory.php @@ -1,4 +1,5 @@ doNotShowLeftProfile)) { if (User::isLogged()) { ?>