PDA

View Full Version : latest posts from private forums on external page?


khininger
03-14-2016, 03:07 AM
hi.

i have an external page thats not a vbulletin page (same domain, parent directory). it includes global.php, greets the user by name and displays dynamic content based on their usergroup. on this page i have the external js with latest posts. the problem is that most of our forums are private, and this js only lists posts from the one public forum we got. i want to show latest posts from whatever forums the user has access to read, since the page knows which usergroup they belong to. can it be done with this external js somehow, or i need to do it differently? any pointers if so?

thank you very much!

MarkFL
03-14-2016, 03:15 AM
I use the following condition to determine whether a user has permission to view a post or not:

($vbulletin->userinfo['forumpermissions'][$post['forumid']] & $vbulletin->bf_ugp_forumpermissions['canview']) AND (($tpost['visible'] == 1) OR can_moderate($post['forumid']))

khininger
03-14-2016, 03:37 AM
thank you :)

how do i get the posts to the page though, before checking which of them to display and which to hide?

MarkFL
03-14-2016, 03:56 AM
If you want to get the latest posts, along with the titles of the threads to which they belong (and the thread icons/prefixes), then I suggest this query:

$recent_posts = $vbulletin->db->query_read("
SELECT post.*, thread.title, thread.forumid, thread.prefixid, thread.iconid, icon.iconpath, icon.title AS icon_title, phrase.text
FROM " . TABLE_PREFIX . "post AS post
INNER JOIN " . TABLE_PREFIX . "thread AS thread
ON thread.threadid = post.threadid
LEFT JOIN " . TABLE_PREFIX . "icon AS icon
ON icon.iconid = thread.iconid
LEFT JOIN " . TABLE_PREFIX . "phrase AS phrase
ON phrase.varname = CONCAT('prefix_', thread.prefixid, '_title_rich')
ORDER BY post.dateline DESC
");


Then, you could use a while loop to get each post:

$pcount = 0;
$number_of_posts = 15; //this will grab 15 posts

while ($tpost = $db->fetch_array($recent_posts) AND $pcount < $number_of_posts)
{
if (($vbulletin->userinfo['forumpermissions'][$tpost['forumid']] & $vbulletin->bf_ugp_forumpermissions['canview']) AND (($tpost['visible'] == 1) OR can_moderate($tpost['forumid'])))
{
$pcount++;
//build links to posts here
}
}

khininger
03-14-2016, 01:41 PM
thank you very much mark, this is perfect, much more than i expected!

only one question - i didnt mention it, my bad, but i also need forumtitle, in addition to forumid. i tried googling, but i never used queries before, and it looks like forumtitle is in a different table, so im not sure how to get it...

MarkFL
03-14-2016, 01:54 PM
Okay, try changing the query to:

$recent_posts = $vbulletin->db->query_read("
SELECT post.*, thread.title, thread.forumid, thread.prefixid, thread.iconid, icon.iconpath, icon.title AS icon_title, phrase.text, forum.title AS forum_title
FROM " . TABLE_PREFIX . "post AS post
INNER JOIN " . TABLE_PREFIX . "thread AS thread
ON thread.threadid = post.threadid
LEFT JOIN " . TABLE_PREFIX . "icon AS icon
ON icon.iconid = thread.iconid
LEFT JOIN " . TABLE_PREFIX . "phrase AS phrase
ON phrase.varname = CONCAT('prefix_', thread.prefixid, '_title_rich')
LEFT JOIN " . TABLE_PREFIX . "forum AS forum
ON forum.forumid = thread.forumid
ORDER BY post.dateline DESC
");

khininger
03-14-2016, 02:03 PM
works perfectly, thank you so very much!