diff --git a/pages/utility.php b/pages/utility.php
index 4677ae61..1666edc4 100644
--- a/pages/utility.php
+++ b/pages/utility.php
@@ -36,6 +36,8 @@ class UtilityPage extends GenericPage
else
$this->name .= Lang::main('colon') . Lang::main('mostComments', 0);
}
+
+ $this->lvTabs = [];
}
public function display($override = '')
@@ -61,7 +63,7 @@ class UtilityPage extends GenericPage
switch ($this->page)
{
case 'random':
- $type = array_rand(array_filter(Util::$typeStrings));
+ $type = array_rand(array_keys(array_filter(Util::$typeClasses)));
$typeId = (new Util::$typeClasses[$type](null))->getRandomId();
header('Location: ?'.Util::$typeStrings[$type].'='.$typeId, true, 302);
@@ -114,7 +116,7 @@ class UtilityPage extends GenericPage
$typeObj = new $classStr($cnd);
if (!$typeObj->error)
{
- $this->extendGlobalData($typeObj->getJSGlobals(GLOBALINFO_SELF | GLOBALINFO_RELATED | GLOBALINFO_REWARDS));
+ $this->extendGlobalData($typeObj->getJSGlobals(GLOBALINFO_ANY));
$this->lvTabs[] = array(
'file' => $typeObj::$brickFile,
'data' => $typeObj->getListviewData(),
@@ -127,13 +129,56 @@ class UtilityPage extends GenericPage
if ($this->category && !in_array($this->category[0], [1, 7, 30]))
header('Location: ?most-comments=1'.($this->rss ? '&rss' : null), true, 302);
- $this->lvTabs[] = array(
- 'file' => 'commentpreview',
- 'data' => [],
- 'params' => []
+ $params = array(
+ 'extraCols' => '$[Listview.funcBox.createSimpleCol(\'ncomments\', \'tab_comments\', \'10%\', \'ncomments\')]',
+ 'sort' => '$[\'-ncomments\']'
);
+
+ foreach (Util::$typeClasses as $type => $classStr)
+ {
+ if (!$classStr)
+ continue;
+
+ $comments = DB::Aowow()->selectCol('
+ SELECT `typeId` AS ARRAY_KEY, count(1) AS nComments FROM ?_comments
+ WHERE `replyTo` = 0 AND (`flags` & ?d) = 0 AND `type`= ?d AND `date` > (UNIX_TIMESTAMP() - ?d)
+ GROUP BY `type`, `typeId`
+ LIMIT 100',
+ CC_FLAG_DELETED,
+ $type,
+ (isset($this->category[0]) ? $this->category[0] : 1) * DAY
+ );
+ if (!$comments)
+ continue;
+
+ $typeClass = new $classStr(array(['id', array_keys($comments)]));
+ if (!$typeClass->error)
+ {
+ $data = $typeClass->getListviewData();
+ foreach ($data as $typeId => &$d)
+ $d['ncomments'] = $comments[$typeId];
+
+ $this->extendGlobalData($typeClass->getJSGlobals(GLOBALINFO_ANY));
+ $this->lvTabs[] = array(
+ 'file' => $typeClass::$brickFile,
+ 'data' => $data,
+ 'params' => $params,
+ '_type' => Util::$typeStrings[$type]
+ );
+ }
+ }
break;
}
+
+ // found nothing => set empty content
+ if (!$this->lvTabs)
+ {
+ $this->lvTabs[] = array(
+ 'file' => 'commentpreview', // anything, doesn't matter what
+ 'data' => [],
+ 'params' => []
+ );
+ }
}
protected function generateRSS()
@@ -149,16 +194,35 @@ class UtilityPage extends GenericPage
"".CFG_TTL_RSS."\n".
"".date(DATE_RSS)."\n";
- foreach ($this->lvTabs[0]['data'] as $row)
+
+ if ($this->page == 'most-comments')
{
- $xml .= "- \n".
- "\n".
- "".HOST_URL.'?go-to-comment&id='.$row['id']."\n".
- "\n". // todo (low): preview should be html-formated
- "".date(DATE_RSS, time() - $row['elapsed'])."\n".
- "".HOST_URL.'?go-to-comment&id='.$row['id']."\n".
- "\n".
- "
\n";
+ foreach ($this->lvTabs as $tab)
+ {
+ foreach ($tab['data'] as $row)
+ {
+ $xml .= "- \n".
+ "\n".
+ "".$tab['_type']."\n".
+ "".HOST_URL.'/?'.$tab['_type'].'='.$row['id']."\n".
+ "".$row['ncomments']."\n".
+ "
\n";
+ }
+ }
+ }
+ else
+ {
+ foreach ($this->lvTabs[0]['data'] as $row)
+ {
+ $xml .= "- \n".
+ "\n".
+ "".HOST_URL.'?go-to-comment&id='.$row['id']."\n".
+ "\n". // todo (low): preview should be html-formated
+ "".date(DATE_RSS, time() - $row['elapsed'])."\n".
+ "".HOST_URL.'?go-to-comment&id='.$row['id']."\n".
+ "\n".
+ "
\n";
+ }
}
$xml .= "\n";