Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-28-2009, 10:13 PM
zeroality zeroality is offline
 
Join Date: Jul 2006
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default how can i make this display the latest 5 threads or whatever?

I had an hack on my old site which displayed username, PM status (or guest message for unregistered members), total posts, threads, members and the last 5 posts of the forum. The first part is very simple, however the last 5 posts required quite a bit of code, utilizing templates from the old topXstats hack that I had. So I've gotten the first part working:

http://www.pkmndex.com/testvb - it's the right box.

Now I'd like to have it display last 5 posts as well (thread titles only) and I have Cyb's Advanced Forum Stats installed so maybe we can use the code from that? I have no idea where to start though.

Here is the old code:

Code:
global $vbulletin;

$displayrecords = $vbulletin->input->clean_gpc('r', 'displayrecords', TYPE_UINT);

if ($displayrecords <= 0) {
	$displayrecords = $vbulletin->options['topXstats_displayrecords'];
} else if ($displayrecords >= $vbulletin->options['topXstats_maxdisplayrecords']) {
	$displayrecords = $vbulletin->options['topXstats_maxdisplayrecords'];
} else {
	$displayrecords = $displayrecords;
}

if ($vbulletin->options['topXstats_excludedforums'] !== '') {
	$excludedforums = ',' . $vbulletin->options['topXstats_excludedforums'];
}

$forumpermissions = array();
foreach($vbulletin->forumcache AS $forum) {

	$forumpermissions[$forum["forumid"]] = fetch_permissions($forum['forumid']);

	// ## HIDE FORUMS WITHOUT THE CANVIEW, CANVIEWOTHERS OR CANSEEDELNOTICE PERMISSION ##
	if (!($forumpermissions[$forum["forumid"]] & $vbulletin->bf_ugp_forumpermissions['canview']) AND !$vbulletin->options['showprivateforums'])  {
		$excludedforums = $excludedforums . ',' . $forum['forumid'];
	}
	// filter out deletion notices if can't be seen
	if ($forumpermissions[$forum["forumid"]] & $vbulletin->bf_ugp_forumpermissions['canseedelnotice'] OR can_moderate($forum['forumid'])){
		$deljoin = "LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog ON(thread.threadid = deletionlog.primaryid AND type = 'thread')";
	} else {
		$deljoin = '';
	}
}


unset($forum);

// get rid of initial comma
$excludedforums = substr($excludedforums, 1);

if ($excludedforums != "") {
	$excludedforums = "AND thread.forumid NOT IN ($excludedforums)";
}

$threadchars = $vbulletin->options['topXstats_threadchars'];
if ($threadchars <= 0) {
	$threadchars = $vbulletin->options['lastthreadchars'];
}

$userchars = $vbulletin->options['topXstats_userchars'];
$newpostprefix = $vbulletin->options['topXstats_newpostprefix'];
$oldpostprefix = $vbulletin->options['topXstats_oldpostprefix'];

if ($threadchars <= 0) {
	$threadchars = $vbulletin->options['lastthreadchars'];
}

$getstats_posters = $db->query_read("SELECT userid, usergroupid, IF(displaygroupid=0, usergroupid, displaygroupid) AS displaygroupid, username, posts FROM " . TABLE_PREFIX . "user ORDER BY posts DESC LIMIT 0, $displayrecords");
while ($getstats_poster = $db->fetch_array($getstats_posters))
{
	if ($userchars > 0) {

		if (strlen($getstats_poster[username]) > $userchars)
		{		
			$getstats_poster[username] = substr($getstats_poster[username], 0, $userchars) . '...';
		}
		else
		{
			$getstats_poster[username] = $getstats_poster[username];
		}
	}
	$getstats_poster[musername] = fetch_musername($getstats_poster);
	eval('$topXstats_posters_bits .= "' . fetch_template('topXstats_poster_bit') . '";');
}

$getstats_members = $db->query_read("SELECT userid, usergroupid, IF(displaygroupid=0, usergroupid, displaygroupid) AS displaygroupid, username, posts, joindate FROM " . TABLE_PREFIX . "user ORDER BY joindate DESC LIMIT 0, $displayrecords");
while ($getstats_member = $db->fetch_array($getstats_members))
{
	if ($userchars > 0) {
		if (strlen($getstats_member[username]) > $userchars)
		{		
			$getstats_member[username] = substr($getstats_member[username], 0, $userchars) . '...';
		}
		else
		{
			$getstats_member[username] = $getstats_member[username];
		}
	}
	$getstats_member[musername] = fetch_musername($getstats_member);
	eval('$topXstats_members_bits .= "' . fetch_template('topXstats_member_bit') . '";');
}

$getstats_threads = $db->query_read("
	SELECT
		thread.threadid, thread.title, thread.lastpost, thread.forumid, thread.replycount, thread.lastposter, thread.dateline, IF(views<=replycount, replycount+1, views) AS views, thread.visible, user.username, user.userid, user.usergroupid, IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid
		" . iif($deljoin, ", NOT ISNULL(deletionlog.primaryid) AS isdeleted, deletionlog.userid AS del_userid, deletionlog.username AS del_username, deletionlog.reason AS del_reason") . "
	FROM " . TABLE_PREFIX . "thread AS thread
		LEFT JOIN  " . TABLE_PREFIX . "user AS user ON (user.username = thread.lastposter)
		$deljoin
		WHERE NOT ISNULL(thread.threadid)
		$excludedforums
		" . iif(!$deljoin, "AND thread.visible <> 2") . "
	ORDER BY lastpost DESC LIMIT 0, 5");

while ($getstats_thread = $db->fetch_array($getstats_threads))
{
	$getstats_thread[title] = unhtmlspecialchars($getstats_thread[title]);
	if ($threadchars > 0) {
		if (strlen($getstats_thread[title]) > $threadchars)
		{		
			$getstats_thread[titletrimmed] = substr($getstats_thread[title], 0, strrpos(substr($getstats_thread[title], 0, $threadchars), ' ')) . '...';
		}
		else
		{
			$getstats_thread[titletrimmed] = $getstats_thread[title];
		}
	}
	$getstats_thread[titletrimmed]=htmlspecialchars($getstats_thread[titletrimmed]);
	$getstats_thread[titlelong]=htmlspecialchars($getstats_thread[title]);

	if ($getstats_thread[lastpost] > $vbulletin->userinfo['lastvisit'])
	{
		$getstats_thread[newpost] = true;
	}
	if ($getstats_thread[isdeleted])
	{
		$getstats_thread[isdeleted] = true;
	}
	if ($userchars > 0) {
		if (strlen($getstats_thread[username]) > $userchars)
		{		
			$getstats_thread[username] = substr($getstats_thread[username], 0, $userchars) . '...';
		}
		else
		{
			$getstats_thread[username] = $getstats_thread[username];
		}
	}
	$getstats_member[musername] = fetch_musername($getstats_thread);
	eval('$foruminteg .= "' . fetch_template('foruminteg') . '";');
}
eval('$memberstats .= "' . fetch_template('memberstats') . '";');

echo "<p><strong>Latest Posts</strong><br>$foruminteg</p>";
Reply With Quote
  #2  
Old 06-30-2009, 10:50 AM
zeroality zeroality is offline
 
Join Date: Jul 2006
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Bump.

OK, I've been messing with it. Here's what I have so far... I don't see why this isn't working.

http://www.pkmndex.com/zero/login_inc.txt

Code was too big to post here.

The posts, threads, members work fine but it isn't displaying the $cyb_topstats_poster stuff. I put in the code and have it call that template so I don't really understand why it isn't working.

The test page is at: http://www.pkmndex.com/testvb

Edit2:

I made another page without all the code and it calls a template called foruminteg and it works fine:

http://www.pkmndex.com/vbs

So all I need now is a way to make the latest posts show up via the template. I tried adding the code from Cyb's Advanced Forum latest posts template but that returns a "N/A" value.
Reply With Quote
  #3  
Old 07-01-2009, 01:25 PM
zeroality zeroality is offline
 
Join Date: Jul 2006
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Anybody?
Reply With Quote
  #4  
Old 07-03-2009, 12:38 PM
Cryo Cryo is offline
 
Join Date: Dec 2003
Location: Buffalo, NY
Posts: 197
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Zero,

If you're just looking for the 5 most recent posts you can do a simple query such as this...

PHP Code:
SELECT
    b
.title,
    
a.threadid,
    
a.username,
    
a.userid,
    
a.dateline
FROM
    
". TABLE_PREFIX ."post a,
    
". TABLE_PREFIX ."thread b
WHERE
    a
.threadid b.threadid
    
AND b.forumid NOT IN ()
ORDER BY
    a
.dateline DESC
LIMIT
    0

For "AND b.forumid NOT IN ()" just include forum ids (such as staff / warnings / private / etc) you don't want shown.
Reply With Quote
  #5  
Old 07-04-2009, 12:11 AM
zeroality zeroality is offline
 
Join Date: Jul 2006
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

http://www.pkmndex.com/posts

Code:

Code:
$lpost = $db->query_first('SELECT b.title,a.threadid,a.username,a.userid,a.dateline FROM ' . TABLE_PREFIX . 'post a,thread b WHERE a.threadid = b.threadid AND b.forumid NOT IN (31) ORDER BY a.dateline DESC LIMIT 0 , 5');
What is wrong? It returns 'array' where the latest posts should be.
Reply With Quote
  #6  
Old 07-05-2009, 09:02 PM
zeroality zeroality is offline
 
Join Date: Jul 2006
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Bump, see above post.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:02 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04127 seconds
  • Memory Usage 2,222KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete