From 1c7acf6a08ad0130109f63c5443239bdcfd102e7 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Thu, 10 Mar 2022 14:02:15 +0100 Subject: [PATCH] CommunityContent/Misc * granularly define inclusion of comments, screenshots or videos * i hope everyone is on a 2y old php version by now --- README.md | 2 +- includes/community.class.php | 67 ++++++++++++++++------------ includes/shared.php | 4 +- pages/areatrigger.php | 1 - pages/genericPage.class.php | 43 +++++++++++------- pages/sound.php | 12 ++--- template/bricks/infobox.tpl.php | 30 +++++++------ template/bricks/pageTemplate.tpl.php | 7 ++- 8 files changed, 97 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index ef3a101d..67094695 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Also, this project is not meant to be used for commercial puposes of any kind! ## Requirements -+ Webserver running PHP ≥ 7.1 — 8.0 including extensions: ++ Webserver running PHP ≥ 7.4 — 8.0 including extensions: + [SimpleXML](https://www.php.net/manual/en/book.simplexml.php) + [GD](https://www.php.net/manual/en/book.image) + [MySQL Improved](https://www.php.net/manual/en/book.mysqli.php) diff --git a/includes/community.class.php b/includes/community.class.php index 72955995..61334031 100644 --- a/includes/community.class.php +++ b/includes/community.class.php @@ -18,10 +18,10 @@ if (!defined('AOWOW_REVISION')) class CommunityContent { - private static $jsGlobals = []; - private static $subjCache = []; + private static array $jsGlobals = []; + private static array $subjCache = []; - private static $commentQuery = ' + private static string $coQuery = ' SELECT c.*, a1.displayName AS user, @@ -54,7 +54,25 @@ class CommunityContent rating ASC '; - private static $previewQuery = ' + private static string $ssQuery = ' + SELECT s.id, a.displayName AS user, s.date, s.width, s.height, s.caption, IF(s.status & ?d, 1, 0) AS "sticky", s.type, s.typeId + FROM ?_screenshots s + LEFT JOIN ?_account a ON s.userIdOwner = a.id + WHERE {s.userIdOwner = ?d AND }{s.type = ? AND }{s.typeId = ? AND }s.status & ?d AND (s.status & ?d) = 0 + {ORDER BY ?# DESC} + {LIMIT ?d} + '; + + private static string $viQuery = ' + SELECT v.id, a.displayName AS user, v.date, v.videoId, v.caption, IF(v.status & ?d, 1, 0) AS "sticky", v.type, v.typeId + FROM ?_videos v + LEFT JOIN ?_account a ON v.userIdOwner = a.id + WHERE {v.userIdOwner = ?d AND }{v.type = ? AND }{v.typeId = ? AND }v.status & ?d AND (v.status & ?d) = 0 + {ORDER BY ?# DESC} + {LIMIT ?d} + '; + + private static string $previewQuery = ' SELECT c.id, c.body AS preview, @@ -87,13 +105,13 @@ class CommunityContent ?d '; - private static function addSubject($type, $typeId) + private static function addSubject(int $type, int $typeId) : void { if (!isset(self::$subjCache[$type][$typeId])) self::$subjCache[$type][$typeId] = 0; } - private static function getSubjects() + private static function getSubjects() : void { foreach (self::$subjCache as $type => $ids) { @@ -133,7 +151,7 @@ class CommunityContent } } - public static function getCommentPreviews($params = [], &$nFound = 0) + public static function getCommentPreviews(array $params = [], int &$nFound = 0) : array { /* purged:0, <- doesnt seem to be used anymore @@ -185,10 +203,10 @@ class CommunityContent return $comments; } - public static function getCommentReplies($commentId, $limit = 0, &$nFound = 0) + public static function getCommentReplies(int $commentId, int $limit = 0, int &$nFound = 0) : array { $replies = []; - $query = $limit > 0 ? self::$commentQuery.' LIMIT '.$limit : self::$commentQuery; + $query = $limit > 0 ? self::$coQuery.' LIMIT '.$limit : self::$coQuery; // get replies $results = DB::Aowow()->selectPage($nFound, $query, User::$id, User::$id, $commentId, 0, 0, CC_FLAG_DELETED, User::$id, User::isInGroup(U_GROUP_COMMENTS_MODERATOR)); @@ -342,10 +360,10 @@ class CommunityContent return $pages; } - private static function getComments($type, $typeId) + public static function getComments(int $type, int $typeId) : array { - $results = DB::Aowow()->query(self::$commentQuery, User::$id, User::$id, 0, $type, $typeId, CC_FLAG_DELETED, User::$id, (int)User::isInGroup(U_GROUP_COMMENTS_MODERATOR)); + $results = DB::Aowow()->query(self::$coQuery, User::$id, User::$id, 0, $type, $typeId, CC_FLAG_DELETED, User::$id, (int)User::isInGroup(U_GROUP_COMMENTS_MODERATOR)); $comments = []; // additional informations @@ -400,15 +418,9 @@ class CommunityContent return $comments; } - public static function getVideos($typeOrUser = 0, $typeId = 0, &$nFound = 0) + public static function getVideos(int $typeOrUser = 0, int $typeId = 0, int &$nFound = 0) : array { - $videos = DB::Aowow()->selectPage($nFound, " - SELECT v.id, a.displayName AS user, v.date, v.videoId, v.caption, IF(v.status & ?d, 1, 0) AS 'sticky', v.type, v.typeId - FROM ?_videos v - LEFT JOIN ?_account a ON v.userIdOwner = a.id - WHERE {v.userIdOwner = ?d AND }{v.type = ? AND }{v.typeId = ? AND }v.status & ?d AND (v.status & ?d) = 0 - {ORDER BY ?# DESC} - {LIMIT ?d}", + $videos = DB::Aowow()->selectPage($nFound, self::$viQuery, CC_FLAG_STICKY, $typeOrUser < 0 ? -$typeOrUser : DBSIMPLE_SKIP, $typeOrUser > 0 ? $typeOrUser : DBSIMPLE_SKIP, @@ -451,15 +463,9 @@ class CommunityContent return $videos; } - public static function getScreenshots($typeOrUser = 0, $typeId = 0, &$nFound = 0) + public static function getScreenshots(int $typeOrUser = 0, int $typeId = 0, int &$nFound = 0) : array { - $screenshots = DB::Aowow()->selectPage($nFound, " - SELECT s.id, a.displayName AS user, s.date, s.width, s.height, s.caption, IF(s.status & ?d, 1, 0) AS 'sticky', s.type, s.typeId - FROM ?_screenshots s - LEFT JOIN ?_account a ON s.userIdOwner = a.id - WHERE {s.userIdOwner = ?d AND }{s.type = ? AND }{s.typeId = ? AND }s.status & ?d AND (s.status & ?d) = 0 - {ORDER BY ?# DESC} - {LIMIT ?d}", + $screenshots = DB::Aowow()->selectPage($nFound, self::$ssQuery, CC_FLAG_STICKY, $typeOrUser < 0 ? -$typeOrUser : DBSIMPLE_SKIP, $typeOrUser > 0 ? $typeOrUser : DBSIMPLE_SKIP, @@ -501,7 +507,7 @@ class CommunityContent return $screenshots; } - public static function getAll($type, $typeId, &$jsg) + public static function getAll(int $type, int $typeId, array &$jsg) : array { $result = array( 'vi' => self::getVideos($type, $typeId), @@ -513,5 +519,10 @@ class CommunityContent return $result; } + + public static function getJSGlobals() : array + { + return self::$jsGlobals; + } } ?> diff --git a/includes/shared.php b/includes/shared.php index 63aea5e2..5e29a95a 100644 --- a/includes/shared.php +++ b/includes/shared.php @@ -10,8 +10,8 @@ foreach ($reqExt as $r) if (!extension_loaded($r)) $error .= 'Required Extension '.$r." was not found. Please check if it should exist, using \"php -m\"\n\n"; -if (version_compare(PHP_VERSION, '7.1.0') < 0) - $error .= 'PHP Version 7.1 or higher required! Your version is '.PHP_VERSION.".\nCore functions are unavailable!\n"; +if (version_compare(PHP_VERSION, '7.4.0') < 0) + $error .= 'PHP Version 7.4 or higher required! Your version is '.PHP_VERSION.".\nCore functions are unavailable!\n"; if ($error) { diff --git a/pages/areatrigger.php b/pages/areatrigger.php index ec9721a0..b6aff173 100644 --- a/pages/areatrigger.php +++ b/pages/areatrigger.php @@ -20,7 +20,6 @@ class AreaTriggerPage extends GenericPage public function __construct($pageCall, $id) { - $this->hasComContent = false; $this->contribute = CONTRIBUTE_NONE; parent::__construct($pageCall, $id); diff --git a/pages/genericPage.class.php b/pages/genericPage.class.php index 91fe4458..a35b81e6 100644 --- a/pages/genericPage.class.php +++ b/pages/genericPage.class.php @@ -6,17 +6,16 @@ if (!defined('AOWOW_REVISION')) trait TrDetailPage { - protected $hasComContent = true; - protected $category = null; // not used on detail pages - protected $lvTabs = []; // most pages have this + protected $category = null; // not used on detail pages + protected $lvTabs = []; // most pages have this - protected $ssError = null; - protected $coError = null; - protected $viError = null; + protected $ssError = null; + protected $coError = null; + protected $viError = null; - protected $subject = null; // so it will not get cached + protected $subject = null; // so it will not get cached - protected $contribute = CONTRIBUTE_ANY; + protected $contribute = CONTRIBUTE_ANY; protected function generateCacheKey(bool $withStaff = true) : string { @@ -136,8 +135,8 @@ trait TrProfiler { $this->prepareContent(); - $this->hasComContent = false; - $this->notFound = array( + $this->contribute = CONTRIBUTE_NONE; + $this->notFound = array( 'title' => sprintf(Lang::profiler('firstUseTitle'), $this->subjectName, $this->realm), 'msg' => '' ); @@ -172,6 +171,7 @@ class GenericPage protected $reqUGroup = U_GROUP_NONE; protected $reqAuth = false; protected $mode = CACHE_TYPE_NONE; + // protected $contribute; // defined in __construct() protected $jsGlobals = []; protected $lvData = []; @@ -238,6 +238,9 @@ class GenericPage { $this->time = microtime(true); + if (!isset($this->contribute)) + $this->contribute = CONTRIBUTE_NONE; + $this->fullParams = $pageCall; if ($pageParam) $this->fullParams .= '='.$pageParam; @@ -399,11 +402,19 @@ class GenericPage $this->contribute = $x::$contribute; } - if (!empty($this->hasComContent)) // get comments, screenshots, videos + if ($this->contribute & CONTRIBUTE_CO) + $this->community['co'] = CommunityContent::getComments($this->type, $this->typeId); + + if ($this->contribute & CONTRIBUTE_SS) + $this->community['ss'] = CommunityContent::getScreenshots($this->type, $this->typeId); + + if ($this->contribute & CONTRIBUTE_VI) + $this->community['vi'] = CommunityContent::getVideos($this->type, $this->typeId); + + // as comments are not cached, those globals cant be either + if ($this->contribute) { - $jsGlobals = []; - $this->community = CommunityContent::getAll($this->type, $this->typeId, $jsGlobals); - $this->extendGlobalData($jsGlobals); // as comments are not cached, those globals cant be either + $this->extendGlobalData(CommunityContent::getJSGlobals()); $this->applyGlobals(); } @@ -595,8 +606,8 @@ class GenericPage { array_unshift($this->title, Lang::main('nfPageTitle')); - $this->hasComContent = false; - $this->notFound = array( + $this->contribute = CONTRIBUTE_NONE; + $this->notFound = array( 'title' => isset($this->typeId) ? Util::ucFirst($title).' #'.$this->typeId : $title, 'msg' => !$msg && isset($this->typeId) ? sprintf(Lang::main('pageNotFound'), $title) : $msg ); diff --git a/pages/sound.php b/pages/sound.php index 7abd7f2f..91516296 100644 --- a/pages/sound.php +++ b/pages/sound.php @@ -26,12 +26,12 @@ class SoundPage extends GenericPage // special case if (!$id && isset($_GET['playlist'])) { - $this->special = true; - $this->name = Lang::sound('cat', 1000); - $this->cat = 1000; - $this->articleUrl = 'sound&playlist'; - $this->hasComContent = false; - $this->mode = CACHE_TYPE_NONE; + $this->special = true; + $this->name = Lang::sound('cat', 1000); + $this->cat = 1000; + $this->articleUrl = 'sound&playlist'; + $this->contribute = CONTRIBUTE_NONE; + $this->mode = CACHE_TYPE_NONE; } // regular case else diff --git a/template/bricks/infobox.tpl.php b/template/bricks/infobox.tpl.php index 0a83025d..6726ba2e 100644 --- a/template/bricks/infobox.tpl.php +++ b/template/bricks/infobox.tpl.php @@ -1,8 +1,7 @@ infobox) || !empty($this->contributions) || !empty($this->series) || $this->hasComContent): -?> - -infobox) || !empty($this->contributions) || !empty($this->series) || $this->contribute & (CONTRIBUTE_SS | CONTRIBUTE_VI)): +echo "
\n"; + if (!empty($this->infobox)): ?> @@ -35,29 +34,32 @@ if (!empty($this->infobox) || !empty($this->contributions) || !empty($this->seri endforeach; endif; - if ($this->hasComContent): + if ($this->contribute & CONTRIBUTE_SS): ?> community['vi'])): + endif; + + if ($this->contribute & CONTRIBUTE_VI && (User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_VIDEO) || !empty($this->community['vi']))): ?> contribute & CONTRIBUTE_SS): ?> -
community['vi'])): + endif; + + if ($this->contribute & CONTRIBUTE_VI && (User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_VIDEO) || !empty($this->community['vi']))): ?> \n"; endif; -endif; -?> \ No newline at end of file + echo " \n"; +endif; +?> diff --git a/template/bricks/pageTemplate.tpl.php b/template/bricks/pageTemplate.tpl.php index 3a48fc73..ab722116 100644 --- a/template/bricks/pageTemplate.tpl.php +++ b/template/bricks/pageTemplate.tpl.php @@ -1,8 +1,13 @@