diff --git a/endpoints/latest-comments/latest-comments.php b/endpoints/latest-comments/latest-comments.php new file mode 100644 index 00000000..da742f32 --- /dev/null +++ b/endpoints/latest-comments/latest-comments.php @@ -0,0 +1,46 @@ + Util > Latest Comments + + protected function generate() : void + { + $this->h1 = Lang::main('utilities', 2); + $this->h1Link = '?'.$this->pageName.'&rss' . (Lang::getLocale()->value ? '&locale='.Lang::getLocale()->value : ''); + $this->rss = Cfg::get('HOST_URL').'/?' . $this->pageName . '&rss' . (Lang::getLocale()->value ? '&locale='.Lang::getLocale()->value : ''); + + + /*********/ + /* Title */ + /*********/ + + array_unshift($this->title, $this->h1); + + + /****************/ + /* Main Content */ + /****************/ + + $this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"]); + + $comments = CommunityContent::getCommentPreviews(['comments' => true, 'replies' => false]); + $this->lvTabs->addListviewTab(new Listview(['data' => $comments], 'commentpreview')); + + $replies = CommunityContent::getCommentPreviews(['comments' => false, 'replies' => true]); + $this->lvTabs->addListviewTab(new Listview(['data' => $replies], 'replypreview')); + + parent::generate(); + } +} + +?> diff --git a/endpoints/latest-comments/latest-comments_rss.php b/endpoints/latest-comments/latest-comments_rss.php new file mode 100644 index 00000000..d3611151 --- /dev/null +++ b/endpoints/latest-comments/latest-comments_rss.php @@ -0,0 +1,34 @@ +feedData[] = array( + 'title' => [true, [], Lang::typeName($comment['type']).Lang::main('colon').htmlentities($comment['subject'])], + 'link' => [false, [], Cfg::get('HOST_URL').'/?go-to-comment&id='.$comment['id']], + 'description' => [true, [], htmlentities($comment['preview'])."

".Lang::main('byUser', [$comment['user'], '']) . Util::formatTimeDiff($comment['date'])], + 'pubDate' => [false, [], date(DATE_RSS, $comment['date'])], + 'guid' => [false, [], Cfg::get('HOST_URL').'/?go-to-comment&id='.$comment['id']] + // 'domain' => [false, [], null] + ); + } + + $this->result = $this->generateRSS(Lang::main('utilities', 2), 'latest-comments'); + } +} + +?> diff --git a/endpoints/latest-screenshots/latest-screenshots.php b/endpoints/latest-screenshots/latest-screenshots.php new file mode 100644 index 00000000..cc08465f --- /dev/null +++ b/endpoints/latest-screenshots/latest-screenshots.php @@ -0,0 +1,43 @@ + Util > Latest Screenshots + + protected function generate() : void + { + $this->h1 = Lang::main('utilities', 3); + $this->h1Link = '?'.$this->pageName.'&rss' . (Lang::getLocale()->value ? '&locale='.Lang::getLocale()->value : ''); + $this->rss = Cfg::get('HOST_URL').'/?' . $this->pageName . '&rss' . (Lang::getLocale()->value ? '&locale='.Lang::getLocale()->value : ''); + + + /*********/ + /* Title */ + /*********/ + + array_unshift($this->title, $this->h1); + + + /****************/ + /* Main Content */ + /****************/ + + $this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"]); + + $data = CommunityContent::getScreenshots(); + $this->lvTabs->addListviewTab(new Listview(['data' => $data], 'screenshot')); + + parent::generate(); + } +} + +?> diff --git a/endpoints/latest-screenshots/latest-screenshots_rss.php b/endpoints/latest-screenshots/latest-screenshots_rss.php new file mode 100644 index 00000000..a91c0127 --- /dev/null +++ b/endpoints/latest-screenshots/latest-screenshots_rss.php @@ -0,0 +1,40 @@ +'; + if ($screenshot['caption']) + $desc .= '
'.$screenshot['caption']; + $desc .= "

".Lang::main('byUser', [$screenshot['user'], '']) . Util::formatTimeDiff($screenshot['date'], true); + + // enclosure/length => filesize('static/uploads/screenshots/thumb/'.$screenshot['id'].'.jpg') .. always set to this placeholder value though + $this->feedData[] = array( + 'title' => [true, [], Lang::typeName($screenshot['type']).Lang::main('colon').htmlentities($screenshot['subject'])], + 'link' => [false, [], Cfg::get('HOST_URL').'/?'.Type::getFileString($screenshot['type']).'='.$screenshot['typeId'].'#screenshots:id='.$screenshot['id']], + 'description' => [true, [], $desc], + 'pubDate' => [false, [], date(DATE_RSS, $screenshot['date'])], + 'enclosure' => [false, ['url' => Cfg::get('STATIC_URL').'/uploads/screenshots/thumb/'.$screenshot['id'].'.jpg', 'length' => 12345, 'type' => 'image/jpeg'], null], + 'guid' => [false, [], Cfg::get('HOST_URL').'/?'.Type::getFileString($screenshot['type']).'='.$screenshot['typeId'].'#screenshots:id='.$screenshot['id']], + // 'domain' => [false, [], live|ptr] + ); + } + + $this->result = $this->generateRSS(Lang::main('utilities', 3), 'latest-screenshots'); + } +} + +?> diff --git a/endpoints/latest-videos/latest-videos.php b/endpoints/latest-videos/latest-videos.php new file mode 100644 index 00000000..24406460 --- /dev/null +++ b/endpoints/latest-videos/latest-videos.php @@ -0,0 +1,43 @@ + Util > Latest Videos + + protected function generate() : void + { + $this->h1 = Lang::main('utilities', 11); + $this->h1Link = '?'.$this->pageName.'&rss' . (Lang::getLocale()->value ? '&locale='.Lang::getLocale()->value : ''); + $this->rss = Cfg::get('HOST_URL').'/?' . $this->pageName . '&rss' . (Lang::getLocale()->value ? '&locale='.Lang::getLocale()->value : ''); + + + /*********/ + /* Title */ + /*********/ + + array_unshift($this->title, $this->h1); + + + /****************/ + /* Main Content */ + /****************/ + + $this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"]); + + $data = CommunityContent::getVideos(); + $this->lvTabs->addListviewTab(new Listview(['data' => $data], 'video')); + + parent::generate(); + } +} + +?> diff --git a/endpoints/latest-videos/latest-videos_rss.php b/endpoints/latest-videos/latest-videos_rss.php new file mode 100644 index 00000000..4fd63165 --- /dev/null +++ b/endpoints/latest-videos/latest-videos_rss.php @@ -0,0 +1,40 @@ +'; + if ($video['caption']) + $desc .= '
'.$video['caption']; + $desc .= "

".Lang::main('byUser', [$video['user'], '']) . Util::formatTimeDiff($video['date'], true); + + // is enclosure/length .. is this even relevant..? + $this->feedData[] = array( + 'title' => [true, [], Lang::typeName($video['type']).Lang::main('colon').htmlentities($video['subject'])], + 'link' => [false, [], Cfg::get('HOST_URL').'/?'.Type::getFileString($video['type']).'='.$video['typeId'].'#videos:id='.$video['id']], + 'description' => [true, [], $desc], + 'pubDate' => [false, [], date(DATE_RSS, $video['date'])], + 'enclosure' => [false, ['url' => '//i3.ytimg.com/vi/'.$video['videoId'].'/default.jpg', 'length' => 12345, 'type' => 'image/jpeg'], null], + 'guid' => [false, [], Cfg::get('HOST_URL').'/?'.Type::getFileString($video['type']).'='.$video['typeId'].'#videos:id='.$video['id']], + // 'domain' => [false, [], live|ptr] + ); + } + + $this->result = $this->generateRSS(Lang::main('utilities', 11), 'latest-videos'); + } +} + +?> diff --git a/endpoints/missing-screenshots/missing-screenshots.php b/endpoints/missing-screenshots/missing-screenshots.php new file mode 100644 index 00000000..8341008c --- /dev/null +++ b/endpoints/missing-screenshots/missing-screenshots.php @@ -0,0 +1,58 @@ + Util > Missing Screenshots + + protected function generate() : void + { + $this->h1 = Lang::main('utilities', 13); + + + /*********/ + /* Title */ + /*********/ + + array_unshift($this->title, $this->h1); + + + /****************/ + /* Main Content */ + /****************/ + + $this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"]); + + // limit to 200 entries each (it generates faster, consumes less memory and should be enough options) + $cnd = [[['cuFlags', CUSTOM_HAS_SCREENSHOT, '&'], 0], 200]; + if (!User::isInGroup(U_GROUP_EMPLOYEE)) + $cnd[] = [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0]; + + $hasTabs = false; + foreach (Type::getClassesFor(Type::FLAG_RANDOM_SEARCHABLE, 'contribute', CONTRIBUTE_SS) as $classStr) + { + $typeObj = new $classStr($cnd); + if ($typeObj->error) + continue; + + $this->extendGlobalData($typeObj->getJSGlobals(GLOBALINFO_ANY)); + $this->lvTabs->addListviewTab(new Listview(['data' => $typeObj->getListviewData()], $typeObj::$brickFile)); + $hasTabs = true; + } + + if (!$hasTabs) + $this->lvTabs->addListviewTab(new Listview(['data' => []], 'item')); + + parent::generate(); + } +} + +?> diff --git a/endpoints/most-comments/most-comments.php b/endpoints/most-comments/most-comments.php new file mode 100644 index 00000000..7d4f178e --- /dev/null +++ b/endpoints/most-comments/most-comments.php @@ -0,0 +1,110 @@ + Util > Most Comments + + protected array $validCats = [1, 7, 30]; + + public function __construct($pageParam) + { + $this->getCategoryFromUrl($pageParam); + + parent::__construct($pageParam); + } + + protected function onInvalidCategory() : never + { + $this->forward('?most-comments=1'); + } + + protected function generate() : void + { + $this->h1 = Lang::main('utilities', 12); + if ($this->category && $this->category[0] > 1) + $this->h1 .= Lang::main('colon') . Lang::main('mostComments', 1, $this->category); + else + $this->h1 .= Lang::main('colon') . Lang::main('mostComments', 0); + + $this->h1Link = '?' . $this->pageName.($this->category ? '='.$this->category[0] : '').'&rss' . (Lang::getLocale()->value ? '&locale='.Lang::getLocale()->value : ''); + $this->rss = Cfg::get('HOST_URL').'/?' . $this->pageName.($this->category ? '='.$this->category[0] : '') . '&rss' . (Lang::getLocale()->value ? '&locale='.Lang::getLocale()->value : ''); + + + /*********/ + /* Title */ + /*********/ + + array_unshift($this->title, $this->h1); + + + /**************/ + /* Breadcrumb */ + /**************/ + + $this->breadcrumb[] = $this->category[0] ?? 1; + + + /****************/ + /* Main Content */ + /****************/ + + $this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"], __forceTabs: true); + + $tabBase = array( + 'extraCols' => ["\$Listview.funcBox.createSimpleCol('ncomments', 'tab_comments', '10%', 'ncomments')"], + 'sort' => ['-ncomments'] + ); + + $hasTabs = false; + foreach (Type::getClassesFor() as $type => $classStr) + { + $comments = DB::Aowow()->selectCol( + 'SELECT `typeId` AS ARRAY_KEY, COUNT(1) 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, + ($this->category[0] ?? 1) * DAY + ); + if (!$comments) + continue; + + $typeClass = new $classStr(array(['id', array_keys($comments)])); + if ($typeClass->error) + continue; + + $data = $typeClass->getListviewData(); + + foreach ($data as $typeId => &$d) + $d['ncomments'] = $comments[$typeId]; + + $addIn = ''; + if (in_array($type, [Type::AREATRIGGER, Type::ENCHANTMENT, Type::ENCHANTMENT, Type::EMOTE])) + { + $addIn = Type::getFileString($type); + $tabBase['name'] = '$LANG.types['.$type.'][2]'; + } + + $this->extendGlobalData($typeClass->getJSGlobals(GLOBALINFO_ANY)); + $this->lvTabs->addListviewTab(new Listview($tabBase + ['data' => $data], $typeClass::$brickFile, $addIn)); + $hasTabs = true; + } + + if (!$hasTabs) + $this->lvTabs->addListviewTab(new Listview(['data' => []], 'commentpreview')); + + parent::generate(); + } +} + +?> diff --git a/endpoints/most-comments/most-comments_rss.php b/endpoints/most-comments/most-comments_rss.php new file mode 100644 index 00000000..da5a1baf --- /dev/null +++ b/endpoints/most-comments/most-comments_rss.php @@ -0,0 +1,63 @@ +params && !in_array($this->params[0], $this->validCats)) + $this->forward('?most-comments=1&rss'); + } + + protected function generate() : void + { + foreach (Type::getClassesFor() as $type => $classStr) + { + $comments = DB::Aowow()->selectCol( + 'SELECT `typeId` AS ARRAY_KEY, COUNT(1) 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, + ($this->category[0] ?? 1) * DAY + ); + if (!$comments) + continue; + + $typeClass = new $classStr(array(['id', array_keys($comments)])); + if ($typeClass->error) + continue; + + $data = $typeClass->getListviewData(); + + foreach ($data as $typeId => &$d) + { + $this->feedData[] = array( + 'title' => [true, [], htmlentities(Type::getFileString($type) == 'item' ? mb_substr($d['name'], 1) : $d['name'])], + 'type' => [false, [], Type::getFileString($type)], + 'link' => [false, [], Cfg::get('HOST_URL').'/?'.Type::getFileString($type).'='.$d['id']], + 'ncomments' => [false, [], $comments[$typeId]] + ); + } + + } + + $this->result = $this->generateRSS(Lang::main('utilities', 12), 'most-comments' . ($this->params ? '='.$this->params[0] : '')); + } +} + +?> diff --git a/endpoints/random/random.php b/endpoints/random/random.php new file mode 100644 index 00000000..21250899 --- /dev/null +++ b/endpoints/random/random.php @@ -0,0 +1,48 @@ +h1 = 'Random Page'; + // array_unshift($this->title, $this->h1); + + $type = array_rand(Type::getClassesFor(Type::FLAG_RANDOM_SEARCHABLE)); + $typeId = (Type::newList($type))?->getRandomId(); + + $this->redirectTo = '?'.Type::getFileString($type).'='.$typeId; + + // $this->extraHTML = <<// + // JS; + } +} + +?> diff --git a/endpoints/unrated-comments/unrated-comments.php b/endpoints/unrated-comments/unrated-comments.php new file mode 100644 index 00000000..bd0027e8 --- /dev/null +++ b/endpoints/unrated-comments/unrated-comments.php @@ -0,0 +1,41 @@ + Util > Unrated Comments + + protected function generate() : void + { + $this->h1 = Lang::main('utilities', 5); + + + /*********/ + /* Title */ + /*********/ + + array_unshift($this->title, $this->h1); + + + /****************/ + /* Main Content */ + /****************/ + + $this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"]); + + $data = CommunityContent::getCommentPreviews(['unrated' => true, 'comments' => true]); + $this->lvTabs->addListviewTab(new Listview(['data' => $data], 'commentpreview')); + + parent::generate(); + } +} + +?> diff --git a/includes/components/communitycontent.class.php b/includes/components/communitycontent.class.php index 14d039b0..12e37385 100644 --- a/includes/components/communitycontent.class.php +++ b/includes/components/communitycontent.class.php @@ -113,7 +113,7 @@ class CommunityContent continue; foreach ($obj->iterate() as $id => $__) - self::$subjCache[$type][$id] = $obj->getField('name', true); + self::$subjCache[$type][$id] = $obj->getField('name', true, true); } } diff --git a/includes/components/response/textresponse.class.php b/includes/components/response/textresponse.class.php index e8000987..caa5acb7 100644 --- a/includes/components/response/textresponse.class.php +++ b/includes/components/response/textresponse.class.php @@ -62,6 +62,15 @@ trait TrRss } } + // pretty print for debug + if (Cfg::get('DEBUG') >= LOG_LEVEL_INFO) + { + $dom = new \DOMDocument('1.0'); + $dom->formatOutput = true; + $dom->loadXML($root->asXML()); + return $dom->saveXML(); + } + return $root->asXML(); } } diff --git a/pages/utility.php b/pages/utility.php deleted file mode 100644 index 8042d0d6..00000000 --- a/pages/utility.php +++ /dev/null @@ -1,330 +0,0 @@ - 'latest-videos', 12 => 'most-comments', 13 => 'missing-screenshots' - ); - - protected $_get = ['rss' => ['filter' => FILTER_CALLBACK, 'options' => 'Aowow\GenericPage::checkEmptySet']]; - - private $page = ''; - private $rss = false; - private $feedData = []; - - public function __construct($pageCall, $pageParam) - { - $this->getCategoryFromUrl($pageParam); - - parent::__construct($pageCall, $pageParam); - - $this->page = $pageCall; - $this->rss = $this->_get['rss']; - - if ($this->page != 'random') - $this->name = Lang::main('utilities', array_search($pageCall, $this->validPages)); - - if ($this->page == 'most-comments') - { - if ($this->category && in_array($this->category[0], [7, 30])) - $this->name .= Lang::main('colon') . sprintf(Lang::main('mostComments', 1), $this->category[0]); - else - $this->name .= Lang::main('colon') . Lang::main('mostComments', 0); - } - } - - public function display(string $override = '') : never - { - if ($this->rss) // this should not be cached - { - header(MIME_TYPE_RSS); - die($this->generateRSS()); - } - else - parent::display($override); - } - - protected function generateContent() - { - /****************/ - /* Main Content */ - /****************/ - - if (in_array(array_search($this->page, $this->validPages), [2, 3, 11, 12])) - $this->h1Links = ''.Lang::main('subscribe').''; - - switch ($this->page) - { - case 'random': - $type = array_rand(Type::getClassesFor(Type::FLAG_RANDOM_SEARCHABLE)); - $typeId = (Type::newList($type))?->getRandomId(); - - header('Location: ?'.Type::getFileString($type).'='.$typeId, true, 302); - die(); - case 'latest-comments': // rss - $comments = CommunityContent::getCommentPreviews(['comments' => true, 'replies' => false], $i, false); - $replies = CommunityContent::getCommentPreviews(['comments' => false, 'replies' => true], $i, false); - - if ($this->rss) - { - 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, [], Cfg::get('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, [], Cfg::get('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( - 'title' => [true, [], Lang::typeName($d['type']).Lang::main('colon').htmlentities($d['subject'])], - 'link' => [false, [], Cfg::get('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, [], Cfg::get('HOST_URL').'/?go-to-comment&id='.$d['id']] - // 'domain' => [false, [], null] - ); - } - } - else - { - 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[] = ['replypreview', ['data' => $replies]]; - } - - break; - case 'latest-screenshots': // rss - $data = CommunityContent::getScreenshots(dateFmt: false); - - if ($this->rss) - { - foreach ($data as $d) - { - $desc = ''; - if ($d['caption']) - $desc .= '
'.$d['caption']; - $desc .= "

".Lang::main('byUser', [$d['user'], '']) . Util::formatTimeDiff($d['date'], true); - - // enclosure/length => filesize('static/uploads/screenshots/thumb/'.$d['id'].'.jpg') .. always set to this placeholder value though - $this->feedData[] = array( - 'title' => [true, [], Lang::typeName($d['type']).Lang::main('colon').htmlentities($d['subject'])], - 'link' => [false, [], Cfg::get('HOST_URL').'/?'.Type::getFileString($d['type']).'='.$d['typeId'].'#screenshots:id='.$d['id']], - 'description' => [true, [], $desc], - 'pubDate' => [false, [], date(DATE_RSS, $d['date'])], - 'enclosure' => [false, ['url' => Cfg::get('STATIC_URL').'/uploads/screenshots/thumb/'.$d['id'].'.jpg', 'length' => 12345, 'type' => 'image/jpeg'], null], - 'guid' => [false, [], Cfg::get('HOST_URL').'/?'.Type::getFileString($d['type']).'='.$d['typeId'].'#screenshots:id='.$d['id']], - // 'domain' => [false, [], live|ptr] - ); - } - } - else - { - array_walk($data, fn(&$d) => $d['date'] = date(Util::$dateFormatInternal, $d['date'])); - $this->lvTabs[] = ['screenshot', ['data' => $data]]; - } - - break; - case 'latest-videos': // rss - $data = CommunityContent::getVideos(dateFmt: false); - - if ($this->rss) - { - foreach ($data as $d) - { - $desc = ''; - if ($d['caption']) - $desc .= '
'.$d['caption']; - $desc .= "

".Lang::main('byUser', [$d['user'], '']) . Util::formatTimeDiff($d['date'], true); - - // is enclosure/length .. is this even relevant..? - $this->feedData[] = array( - 'title' => [true, [], Lang::typeName($d['type']).Lang::main('colon').htmlentities($d['subject'])], - 'link' => [false, [], Cfg::get('HOST_URL').'/?'.Type::getFileString($d['type']).'='.$d['typeId'].'#videos:id='.$d['id']], - 'description' => [true, [], $desc], - 'pubDate' => [false, [], date(DATE_RSS, $d['date'])], - 'enclosure' => [false, ['url' => '//i3.ytimg.com/vi/'.$d['videoId'].'/default.jpg', 'length' => 12345, 'type' => 'image/jpeg'], null], - 'guid' => [false, [], Cfg::get('HOST_URL').'/?'.Type::getFileString($d['type']).'='.$d['typeId'].'#videos:id='.$d['id']], - // 'domain' => [false, [], live|ptr] - ); - } - } - else - { - array_walk($data, fn(&$d) => $d['date'] = date(Util::$dateFormatInternal, $d['date'])); - $this->lvTabs[] = ['video', ['data' => $data]]; - } - - break; - case 'unrated-comments': - $this->lvTabs[] = ['commentpreview', [ - 'data' => CommunityContent::getCommentPreviews(['unrated' => true, 'comments' => true]) - ]]; - - break; - case 'missing-screenshots': - // limit to 200 entries each (it generates faster, consumes less memory and should be enough options) - $cnd = [[['cuFlags', CUSTOM_HAS_SCREENSHOT, '&'], 0], 200]; - if (!User::isInGroup(U_GROUP_EMPLOYEE)) - $cnd[] = [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0]; - - - foreach (Type::getClassesFor(Type::FLAG_RANDOM_SEARCHABLE, 'contribute', CONTRIBUTE_SS) as $type => $classStr) - { - $typeObj = new $classStr($cnd); - if (!$typeObj->error) - { - $this->extendGlobalData($typeObj->getJSGlobals(GLOBALINFO_ANY)); - $this->lvTabs[] = [$typeObj::$brickFile, ['data' => array_values($typeObj->getListviewData())]]; - } - } - break; - case 'most-comments': // rss - if ($this->category && !in_array($this->category[0], [1, 7, 30])) - header('Location: ?most-comments=1'.($this->rss ? '&rss' : null), true, 302); - - $tabBase = array( - 'extraCols' => ["\$Listview.funcBox.createSimpleCol('ncomments', 'tab_comments', '10%', 'ncomments')"], - 'sort' => ['-ncomments'] - ); - - foreach (Type::getClassesFor() as $type => $classStr) - { - $comments = DB::Aowow()->selectCol(' - SELECT `typeId` AS ARRAY_KEY, count(1) 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(); - - if ($this->rss) - { - foreach ($data as $typeId => &$d) - { - $this->feedData[] = array( - 'title' => [true, [], htmlentities(Type::getFileString($type) == 'item' ? mb_substr($d['name'], 1) : $d['name'])], - 'type' => [false, [], Type::getFileString($type)], - 'link' => [false, [], Cfg::get('HOST_URL').'/?'.Type::getFileString($type).'='.$d['id']], - 'ncomments' => [false, [], $comments[$typeId]] - ); - } - } - else - { - foreach ($data as $typeId => &$d) - $d['ncomments'] = $comments[$typeId]; - - $this->extendGlobalData($typeClass->getJSGlobals(GLOBALINFO_ANY)); - $this->lvTabs[] = [$typeClass::$brickFile, array_merge($tabBase, ['data' => array_values($data)])]; - } - } - } - - break; - } - - // found nothing => set empty content - // tpl: commentpreview - anything, doesn't matter what - if (!$this->lvTabs && !$this->rss) - $this->lvTabs[] = ['commentpreview', ['data' => []]]; - } - - protected function generateRSS() - { - $this->generateContent(); - - $root = new SimpleXML(''); - $root->addAttribute('version', '2.0'); - - $channel = $root->addChild('channel'); - - $channel->addChild('title', Cfg::get('NAME_SHORT').' - '.$this->name); - $channel->addChild('link', Cfg::get('HOST_URL').'/?'.$this->page . ($this->category ? '='.$this->category[0] : null)); - $channel->addChild('description', Cfg::get('NAME')); - $channel->addChild('language', implode('-', str_split(Lang::getLocale()->json(), 2))); - $channel->addChild('ttl', Cfg::get('TTL_RSS')); - $channel->addChild('lastBuildDate', date(DATE_RSS)); - - foreach ($this->feedData as $row) - { - $item = $channel->addChild('item'); - - foreach ($row as $key => [$isCData, $attrib, $text]) - { - if ($isCData && $text) - $child = $item->addChild($key)->addCData($text); - else - $child = $item->addChild($key, $text); - - foreach ($attrib as $k => $v) - $child->addAttribute($k, $v); - } - } - - return $root->asXML(); - } - - protected function generateTitle() - { - if ($this->page == 'most-comments') - { - if ($this->category && in_array($this->category[0], [7, 30])) - array_unshift($this->title, sprintf(Lang::main('mostComments', 1), $this->category[0])); - else - array_unshift($this->title, Lang::main('mostComments', 0)); - } - - array_unshift($this->title, $this->name); - } - - protected function generatePath() - { - $this->path[] = array_search($this->page, $this->validPages); - - if ($this->page == 'most-comments') - { - if ($this->category && in_array($this->category[0], [7, 30])) - $this->path[] = $this->category[0]; - else - $this->path[] = 1; - } - } -} - -?>