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
+ 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)

View File

@@ -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;
}
}
?>

View File

@@ -10,8 +10,8 @@ foreach ($reqExt as $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";
if (version_compare(PHP_VERSION, '7.1.0') < 0)
$error .= 'PHP Version <b>7.1</b> or higher required! Your version is <b>'.PHP_VERSION."</b>.\nCore functions are unavailable!\n";
if (version_compare(PHP_VERSION, '7.4.0') < 0)
$error .= 'PHP Version <b>7.4</b> or higher required! Your version is <b>'.PHP_VERSION."</b>.\nCore functions are unavailable!\n";
if ($error)
{

View File

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

View File

@@ -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
);

View File

@@ -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

View File

@@ -1,8 +1,7 @@
<?php
if (!empty($this->infobox) || !empty($this->contributions) || !empty($this->series) || $this->hasComContent):
?>
<table class="infobox">
<?php
if (!empty($this->infobox) || !empty($this->contributions) || !empty($this->series) || $this->contribute & (CONTRIBUTE_SS | CONTRIBUTE_VI)):
echo " <table class=\"infobox\">\n";
if (!empty($this->infobox)):
?>
<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;
endif;
if ($this->hasComContent):
if ($this->contribute & CONTRIBUTE_SS):
?>
<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>
<?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><td><div class="infobox-spacer"></div><div id="infobox-sticky-vi"></div></td></tr>
<?php
endif;
endif;
if ($this->contribute & CONTRIBUTE_SS):
?>
</table>
<script type="text/javascript">ss_appendSticky()</script>
<?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>
<?php
endif;
else:
echo " </table>\n";
endif;
endif;
?>
echo " </table>\n";
endif;
?>

View File

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