diff --git a/includes/community.class.php b/includes/community.class.php index a11a75ed..26f9f6c5 100644 --- a/includes/community.class.php +++ b/includes/community.class.php @@ -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), diff --git a/pages/account.php b/pages/account.php index cf9697de..6e0f3d53 100644 --- a/pages/account.php +++ b/pages/account.php @@ -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, diff --git a/pages/user.php b/pages/user.php index 10006f37..104145d2 100644 --- a/pages/user.php +++ b/pages/user.php @@ -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' => $_, diff --git a/pages/utility.php b/pages/utility.php index acc1772a..c14ada2f 100644 --- a/pages/utility.php +++ b/pages/utility.php @@ -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'])."

".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)