mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Comments/Replies
* also show replies on latest-comments utility page * sort replies by score DESC
This commit is contained in:
@@ -51,7 +51,7 @@ class CommunityContent
|
||||
GROUP BY
|
||||
c.id
|
||||
ORDER BY
|
||||
rating ASC
|
||||
`date` ASC
|
||||
';
|
||||
|
||||
private static string $ssQuery = '
|
||||
@@ -92,11 +92,7 @@ class CommunityContent
|
||||
LEFT JOIN
|
||||
?_comments c2 ON c.replyTo = c2.id
|
||||
WHERE
|
||||
{c.userId = ?d AND}
|
||||
{c.replyTo <> ?d AND}
|
||||
{c.replyTo = ?d AND}
|
||||
{ur.entry IS ?n AND}
|
||||
{(c.flags & ?d) AND}
|
||||
%s
|
||||
((c.flags & ?d) = 0 OR c.userId = ?d OR ?d)
|
||||
GROUP BY
|
||||
c.id
|
||||
@@ -129,22 +125,32 @@ class CommunityContent
|
||||
}
|
||||
}
|
||||
|
||||
public static function getCommentPreviews(array $params = [], ?int &$nFound = 0, bool $dateFmt = true) : array
|
||||
public static function getCommentPreviews(array $opt = [], ?int &$nFound = 0, bool $dateFmt = true) : array
|
||||
{
|
||||
/*
|
||||
purged:0, <- doesnt seem to be used anymore
|
||||
domain:'live' <- irrelevant for our case
|
||||
*/
|
||||
|
||||
// add default values
|
||||
$opt += ['user' => 0, 'unrated' => 0, 'comments' => 0, 'replies' => 0];
|
||||
|
||||
$w = [];
|
||||
if ($opt['user'])
|
||||
$w[] = sprintf('c.userId = %d AND', $opt['user']);
|
||||
if ($opt['unrated'])
|
||||
$w[] = 'ur.entry IS NULL AND';
|
||||
if ($opt['comments'] && !$opt['replies'])
|
||||
$w[] = 'c.replyTo = 0 AND';
|
||||
else if (!$opt['comments'] && $opt['replies'])
|
||||
$w[] = 'c.replyTo <> 0 AND';
|
||||
// else
|
||||
// pick both and no extra constraint needed for that
|
||||
|
||||
$comments = DB::Aowow()->selectPage(
|
||||
$nFound,
|
||||
self::$previewQuery,
|
||||
sprintf(self::$previewQuery, implode(' ', $w)),
|
||||
CC_FLAG_DELETED,
|
||||
empty($params['user']) ? DBSIMPLE_SKIP : $params['user'],
|
||||
empty($params['replies']) ? DBSIMPLE_SKIP : 0, // i dont know, how to switch the sign around
|
||||
!empty($params['replies']) ? DBSIMPLE_SKIP : 0,
|
||||
empty($params['unrated']) ? DBSIMPLE_SKIP : null,
|
||||
empty($params['flags']) ? DBSIMPLE_SKIP : $params['flags'],
|
||||
CC_FLAG_DELETED,
|
||||
User::$id,
|
||||
User::isInGroup(U_GROUP_COMMENTS_MODERATOR),
|
||||
|
||||
@@ -251,7 +251,7 @@ class AccountPage extends GenericPage
|
||||
}
|
||||
|
||||
// comments
|
||||
if ($_ = CommunityContent::getCommentPreviews(['user' => User::$id, 'replies' => false]))
|
||||
if ($_ = CommunityContent::getCommentPreviews(['user' => User::$id, 'comments' => true]))
|
||||
{
|
||||
// needs foundCount for params
|
||||
// _totalCount: 377,
|
||||
|
||||
@@ -151,7 +151,7 @@ class UserPage extends GenericPage
|
||||
}
|
||||
|
||||
// Comments
|
||||
if ($_ = CommunityContent::getCommentPreviews(['user' => $this->user['id'], 'replies' => false], $nFound))
|
||||
if ($_ = CommunityContent::getCommentPreviews(['user' => $this->user['id'], 'comments' => true], $nFound))
|
||||
{
|
||||
$tabData = array(
|
||||
'data' => $_,
|
||||
|
||||
@@ -75,11 +75,25 @@ class UtilityPage extends GenericPage
|
||||
header('Location: ?'.Type::getFileString($type).'='.$typeId, true, 302);
|
||||
die();
|
||||
case 'latest-comments': // rss
|
||||
$data = CommunityContent::getCommentPreviews(dateFmt: false);
|
||||
$comments = CommunityContent::getCommentPreviews(['comments' => true, 'replies' => false], $i, false);
|
||||
$replies = CommunityContent::getCommentPreviews(['comments' => false, 'replies' => true], $i, false);
|
||||
|
||||
if ($this->rss)
|
||||
{
|
||||
foreach ($data as $d)
|
||||
foreach ($comments as $d)
|
||||
{
|
||||
// todo (low): preview should be html-formated
|
||||
$this->feedData[] = array(
|
||||
'title' => [true, [], Lang::typeName($d['type']).Lang::main('colon').htmlentities($d['subject'])],
|
||||
'link' => [false, [], HOST_URL.'/?go-to-comment&id='.$d['id']],
|
||||
'description' => [true, [], htmlentities($d['preview'])."<br /><br />".Lang::main('byUser', [$d['user'], '']) . Util::formatTimeDiff($d['date'], true)],
|
||||
'pubDate' => [false, [], date(DATE_RSS, $d['date'])],
|
||||
'guid' => [false, [], HOST_URL.'/?go-to-comment&id='.$d['id']]
|
||||
// 'domain' => [false, [], null]
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($replies as $d)
|
||||
{
|
||||
// todo (low): preview should be html-formated
|
||||
$this->feedData[] = array(
|
||||
@@ -94,8 +108,11 @@ class UtilityPage extends GenericPage
|
||||
}
|
||||
else
|
||||
{
|
||||
array_walk($data, fn(&$d) => $d['date'] = date(Util::$dateFormatInternal, $d['date']));
|
||||
$this->lvTabs[] = ['commentpreview', ['data' => $data]];
|
||||
array_walk($comments, fn(&$d) => $d['date'] = date(Util::$dateFormatInternal, $d['date']));
|
||||
$this->lvTabs[] = ['commentpreview', ['data' => $comments]];
|
||||
|
||||
array_walk($replies, fn(&$d) => $d['date'] = date(Util::$dateFormatInternal, $d['date']));
|
||||
$this->lvTabs[] = ['commentpreview', ['data' => $replies]];
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -162,10 +179,10 @@ class UtilityPage extends GenericPage
|
||||
|
||||
break;
|
||||
case 'unrated-comments':
|
||||
if ($_ = CommunityContent::getCommentPreviews(['unrated' => true]))
|
||||
$this->lvTabs[] = ['commentpreview', ['data' => $_]];
|
||||
$this->lvTabs[] = ['commentpreview', [
|
||||
'data' => CommunityContent::getCommentPreviews(['unrated' => true, 'comments' => true])
|
||||
]];
|
||||
|
||||
$this->lvTabs[] = ['commentpreview', ['data' => []]];
|
||||
break;
|
||||
case 'missing-screenshots':
|
||||
// limit to 200 entries each (it generates faster, consumes less memory and should be enough options)
|
||||
|
||||
Reference in New Issue
Block a user