Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Recent discussions code
I have some code that shows recent discussions on my main site from the Vanilla forum.
I want it to only show the latest posts but currently it also shows the original thread mixed into the list too. Can someone help there?
Also, it shows the data next to each item, is there a way to show that in "Hours ago"/"Days ago" format?
Hope you can help, cheers guys.
/** * Get latest vanilla discussions * @param integer $limit * @return array */ public function getLatestDiscussions($limit) { $discussions = []; $displayMaxSub = 1; // No trailing slash $vanillaUrl = url('forum'); $jsonStr = file_get_contents($vanillaUrl . '/discussions.json'); if (!$jsonStr) { return []; } $json = json_decode($jsonStr, true); $i = 0; $discussions_count = count($json['Discussions']); foreach ($json['Discussions'] as $discussion) { if ($i >= $limit) break; $discussions[] = [ 'id' => $discussion['DiscussionID'], 'subject' => $discussion['Name'], 'body' => $discussion['Body'], 'username' => $discussion['FirstName'], 'date' => $discussion['DateInserted'], 'link' => url('forum/discussion/' . $discussion['DiscussionID']), ]; if ($discussion['CountComments'] > 1) { $jsonStr_single = file_get_contents($vanillaUrl . '/discussion.json?DiscussionID=' . $discussion['DiscussionID']); if ($jsonStr_single) { $json_single = json_decode($jsonStr_single, true); if (isset($json_single['Comments'])) { $addedComments = 1; $comments = array_reverse($json_single['Comments']); foreach ($comments as $comment) { if ($addedComments === $displayMaxSub || $i === $limit) break; $discussions[] = [ 'id' => $discussion['DiscussionID'], 'subject' => 'RE: ' . $discussion['Name'], 'body' => $comment['Body'], 'username' => $comment['InsertName'], 'date' => $comment['DateInserted'], 'link' => $this->generateCommentLink($comment['CommentID']), ]; $addedComments++; $i++; } } } } $i++; } return $discussions; }
0
Comments
I am a little confused as to what you are trying to accomplish?
Are you looking to show the actual posts or just a list with links?
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Just a list of links to the latest posts
You can install Latest Post List in your vanilla forum (http://vanillaforums.org/addon/latestpostlist-plugin). Then request its module view (//forums.example.com/module/latestpostlistmodule).
Feel free to disable the module from appearing on your Vanilla install.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.