CommunityContent/Misc

* granularly define inclusion of comments, screenshots or videos
 * i hope everyone is on a 2y old php version by now
This commit is contained in:
Sarjuuk
2022-03-10 14:02:15 +01:00
parent 012ebe578b
commit 1c7acf6a08
8 changed files with 97 additions and 69 deletions

View File

@@ -18,7 +18,7 @@ Also, this project is not meant to be used for commercial puposes of any kind!
## Requirements ## 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) + [SimpleXML](https://www.php.net/manual/en/book.simplexml.php)
+ [GD](https://www.php.net/manual/en/book.image) + [GD](https://www.php.net/manual/en/book.image)
+ [MySQL Improved](https://www.php.net/manual/en/book.mysqli.php) + [MySQL Improved](https://www.php.net/manual/en/book.mysqli.php)

View File

@@ -18,10 +18,10 @@ if (!defined('AOWOW_REVISION'))
class CommunityContent class CommunityContent
{ {
private static $jsGlobals = []; private static array $jsGlobals = [];
private static $subjCache = []; private static array $subjCache = [];
private static $commentQuery = ' private static string $coQuery = '
SELECT SELECT
c.*, c.*,
a1.displayName AS user, a1.displayName AS user,
@@ -54,7 +54,25 @@ class CommunityContent
rating ASC 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 SELECT
c.id, c.id,
c.body AS preview, c.body AS preview,
@@ -87,13 +105,13 @@ class CommunityContent
?d ?d
'; ';
private static function addSubject($type, $typeId) private static function addSubject(int $type, int $typeId) : void
{ {
if (!isset(self::$subjCache[$type][$typeId])) if (!isset(self::$subjCache[$type][$typeId]))
self::$subjCache[$type][$typeId] = 0; self::$subjCache[$type][$typeId] = 0;
} }
private static function getSubjects() private static function getSubjects() : void
{ {
foreach (self::$subjCache as $type => $ids) 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 purged:0, <- doesnt seem to be used anymore
@@ -185,10 +203,10 @@ class CommunityContent
return $comments; 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 = []; $replies = [];
$query = $limit > 0 ? self::$commentQuery.' LIMIT '.$limit : self::$commentQuery; $query = $limit > 0 ? self::$coQuery.' LIMIT '.$limit : self::$coQuery;
// get replies // 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)); $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; 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 = []; $comments = [];
// additional informations // additional informations
@@ -400,15 +418,9 @@ class CommunityContent
return $comments; 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, " $videos = DB::Aowow()->selectPage($nFound, self::$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}",
CC_FLAG_STICKY, CC_FLAG_STICKY,
$typeOrUser < 0 ? -$typeOrUser : DBSIMPLE_SKIP, $typeOrUser < 0 ? -$typeOrUser : DBSIMPLE_SKIP,
$typeOrUser > 0 ? $typeOrUser : DBSIMPLE_SKIP, $typeOrUser > 0 ? $typeOrUser : DBSIMPLE_SKIP,
@@ -451,15 +463,9 @@ class CommunityContent
return $videos; 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, " $screenshots = DB::Aowow()->selectPage($nFound, self::$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}",
CC_FLAG_STICKY, CC_FLAG_STICKY,
$typeOrUser < 0 ? -$typeOrUser : DBSIMPLE_SKIP, $typeOrUser < 0 ? -$typeOrUser : DBSIMPLE_SKIP,
$typeOrUser > 0 ? $typeOrUser : DBSIMPLE_SKIP, $typeOrUser > 0 ? $typeOrUser : DBSIMPLE_SKIP,
@@ -501,7 +507,7 @@ class CommunityContent
return $screenshots; return $screenshots;
} }
public static function getAll($type, $typeId, &$jsg) public static function getAll(int $type, int $typeId, array &$jsg) : array
{ {
$result = array( $result = array(
'vi' => self::getVideos($type, $typeId), 'vi' => self::getVideos($type, $typeId),
@@ -513,5 +519,10 @@ class CommunityContent
return $result; return $result;
} }
public static function getJSGlobals() : array
{
return self::$jsGlobals;
}
} }
?> ?>

View File

@@ -10,8 +10,8 @@ foreach ($reqExt as $r)
if (!extension_loaded($r)) if (!extension_loaded($r))
$error .= 'Required Extension <b>'.$r."</b> was not found. Please check if it should exist, using \"<i>php -m</i>\"\n\n"; $error .= 'Required Extension <b>'.$r."</b> was not found. Please check if it should exist, using \"<i>php -m</i>\"\n\n";
if (version_compare(PHP_VERSION, '7.1.0') < 0) if (version_compare(PHP_VERSION, '7.4.0') < 0)
$error .= 'PHP Version <b>7.1</b> or higher required! Your version is <b>'.PHP_VERSION."</b>.\nCore functions are unavailable!\n"; $error .= 'PHP Version <b>7.4</b> or higher required! Your version is <b>'.PHP_VERSION."</b>.\nCore functions are unavailable!\n";
if ($error) if ($error)
{ {

View File

@@ -20,7 +20,6 @@ class AreaTriggerPage extends GenericPage
public function __construct($pageCall, $id) public function __construct($pageCall, $id)
{ {
$this->hasComContent = false;
$this->contribute = CONTRIBUTE_NONE; $this->contribute = CONTRIBUTE_NONE;
parent::__construct($pageCall, $id); parent::__construct($pageCall, $id);

View File

@@ -6,17 +6,16 @@ if (!defined('AOWOW_REVISION'))
trait TrDetailPage trait TrDetailPage
{ {
protected $hasComContent = true; protected $category = null; // not used on detail pages
protected $category = null; // not used on detail pages protected $lvTabs = []; // most pages have this
protected $lvTabs = []; // most pages have this
protected $ssError = null; protected $ssError = null;
protected $coError = null; protected $coError = null;
protected $viError = 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 protected function generateCacheKey(bool $withStaff = true) : string
{ {
@@ -136,8 +135,8 @@ trait TrProfiler
{ {
$this->prepareContent(); $this->prepareContent();
$this->hasComContent = false; $this->contribute = CONTRIBUTE_NONE;
$this->notFound = array( $this->notFound = array(
'title' => sprintf(Lang::profiler('firstUseTitle'), $this->subjectName, $this->realm), 'title' => sprintf(Lang::profiler('firstUseTitle'), $this->subjectName, $this->realm),
'msg' => '' 'msg' => ''
); );
@@ -172,6 +171,7 @@ class GenericPage
protected $reqUGroup = U_GROUP_NONE; protected $reqUGroup = U_GROUP_NONE;
protected $reqAuth = false; protected $reqAuth = false;
protected $mode = CACHE_TYPE_NONE; protected $mode = CACHE_TYPE_NONE;
// protected $contribute; // defined in __construct()
protected $jsGlobals = []; protected $jsGlobals = [];
protected $lvData = []; protected $lvData = [];
@@ -238,6 +238,9 @@ class GenericPage
{ {
$this->time = microtime(true); $this->time = microtime(true);
if (!isset($this->contribute))
$this->contribute = CONTRIBUTE_NONE;
$this->fullParams = $pageCall; $this->fullParams = $pageCall;
if ($pageParam) if ($pageParam)
$this->fullParams .= '='.$pageParam; $this->fullParams .= '='.$pageParam;
@@ -399,11 +402,19 @@ class GenericPage
$this->contribute = $x::$contribute; $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->extendGlobalData(CommunityContent::getJSGlobals());
$this->community = CommunityContent::getAll($this->type, $this->typeId, $jsGlobals);
$this->extendGlobalData($jsGlobals); // as comments are not cached, those globals cant be either
$this->applyGlobals(); $this->applyGlobals();
} }
@@ -595,8 +606,8 @@ class GenericPage
{ {
array_unshift($this->title, Lang::main('nfPageTitle')); array_unshift($this->title, Lang::main('nfPageTitle'));
$this->hasComContent = false; $this->contribute = CONTRIBUTE_NONE;
$this->notFound = array( $this->notFound = array(
'title' => isset($this->typeId) ? Util::ucFirst($title).' #'.$this->typeId : $title, 'title' => isset($this->typeId) ? Util::ucFirst($title).' #'.$this->typeId : $title,
'msg' => !$msg && isset($this->typeId) ? sprintf(Lang::main('pageNotFound'), $title) : $msg 'msg' => !$msg && isset($this->typeId) ? sprintf(Lang::main('pageNotFound'), $title) : $msg
); );

View File

@@ -26,12 +26,12 @@ class SoundPage extends GenericPage
// special case // special case
if (!$id && isset($_GET['playlist'])) if (!$id && isset($_GET['playlist']))
{ {
$this->special = true; $this->special = true;
$this->name = Lang::sound('cat', 1000); $this->name = Lang::sound('cat', 1000);
$this->cat = 1000; $this->cat = 1000;
$this->articleUrl = 'sound&playlist'; $this->articleUrl = 'sound&playlist';
$this->hasComContent = false; $this->contribute = CONTRIBUTE_NONE;
$this->mode = CACHE_TYPE_NONE; $this->mode = CACHE_TYPE_NONE;
} }
// regular case // regular case
else else

View File

@@ -1,8 +1,7 @@
<?php <?php
if (!empty($this->infobox) || !empty($this->contributions) || !empty($this->series) || $this->hasComContent): if (!empty($this->infobox) || !empty($this->contributions) || !empty($this->series) || $this->contribute & (CONTRIBUTE_SS | CONTRIBUTE_VI)):
?> echo " <table class=\"infobox\">\n";
<table class="infobox">
<?php
if (!empty($this->infobox)): if (!empty($this->infobox)):
?> ?>
<tr><th id="infobox-quick-facts"><?php echo Lang::main('quickFacts'); ?></th></tr> <tr><th id="infobox-quick-facts"><?php echo Lang::main('quickFacts'); ?></th></tr>
@@ -35,29 +34,32 @@ if (!empty($this->infobox) || !empty($this->contributions) || !empty($this->seri
endforeach; endforeach;
endif; endif;
if ($this->hasComContent): if ($this->contribute & CONTRIBUTE_SS):
?> ?>
<tr><th id="infobox-screenshots"><?php echo Lang::main('screenshots'); ?></th></tr> <tr><th id="infobox-screenshots"><?php echo Lang::main('screenshots'); ?></th></tr>
<tr><td><div class="infobox-spacer"></div><div id="infobox-sticky-ss"></div></td></tr> <tr><td><div class="infobox-spacer"></div><div id="infobox-sticky-ss"></div></td></tr>
<?php <?php
if (User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_VIDEO) || !empty($this->community['vi'])): endif;
if ($this->contribute & CONTRIBUTE_VI && (User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_VIDEO) || !empty($this->community['vi']))):
?> ?>
<tr><th id="infobox-videos"><?php echo Lang::main('videos'); ?></th></tr> <tr><th id="infobox-videos"><?php echo Lang::main('videos'); ?></th></tr>
<tr><td><div class="infobox-spacer"></div><div id="infobox-sticky-vi"></div></td></tr> <tr><td><div class="infobox-spacer"></div><div id="infobox-sticky-vi"></div></td></tr>
<?php <?php
endif; endif;
if ($this->contribute & CONTRIBUTE_SS):
?> ?>
</table>
<script type="text/javascript">ss_appendSticky()</script> <script type="text/javascript">ss_appendSticky()</script>
<?php <?php
if (User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_VIDEO) || !empty($this->community['vi'])): endif;
if ($this->contribute & CONTRIBUTE_VI && (User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_VIDEO) || !empty($this->community['vi']))):
?> ?>
<script type="text/javascript">vi_appendSticky()</script> <script type="text/javascript">vi_appendSticky()</script>
<?php <?php
endif;
else:
echo " </table>\n";
endif; endif;
endif;
?> echo " </table>\n";
endif;
?>

View File

@@ -1,8 +1,13 @@
<script type="text/javascript">//<![CDATA[ <script type="text/javascript">//<![CDATA[
<?php <?php
if (!empty($this->hasComContent)): if ($this->contribute & CONTRIBUTE_CO):
echo " var lv_comments = ".Util::toJSON($this->community['co']).";\n"; echo " var lv_comments = ".Util::toJSON($this->community['co']).";\n";
endif;
if ($this->contribute & CONTRIBUTE_SS):
echo " var lv_screenshots = ".Util::toJSON($this->community['sc']).";\n"; echo " var lv_screenshots = ".Util::toJSON($this->community['sc']).";\n";
endif;
if ($this->contribute & CONTRIBUTE_VI):
echo " var lv_videos = ".Util::toJSON($this->community['vi']).";\n"; echo " var lv_videos = ".Util::toJSON($this->community['vi']).";\n";
endif; endif;