Log in

View Full Version : I need help making this plugin,..


just.b.jealous
12-14-2010, 10:43 AM
I'd like to be able to display the (postdate/time, username, thread title, and post content) for the latest 5/10 threads from a specific forum/s?

Is there anyway to make a plug-in so I could put a variable where it's needed.

Similiar to this here (which only displays 10 latest post - showing only the thread title and username):

$numposts='10';


$thrdqry = $vbulletin->db->query_read("
SELECT forumid,threadid, title, dateline, lastpost, visible, open, lastposter
FROM " . TABLE_PREFIX . "thread
WHERE forumid IN (1, 2, 3) AND visible = '1'
ORDER BY lastpost DESC
LIMIT 0, $numposts ");

while ($thrds = mysql_fetch_array($thrdqry))
{

$ttid = $thrds[threadid];
$pstqry = $vbulletin->db->query_read("
SELECT postid
FROM " . TABLE_PREFIX . "post
WHERE threadid= $ttid
ORDER BY postid DESC");

$psts = mysql_fetch_array($pstqry);
$pstid = $psts[postid];


$homepage_recentpost .=<<<EOD
$thrds[title]
$thrds[lastposter]
EOD;

}
$db->free_result($thrds);
$db->free_result($psts);


the I just post $homepage_recentpost into a template and vB does the rest, some help would be greatly appreciated,..

kh99
12-15-2010, 05:42 PM
You could do this:

$numposts='10';


$thrdqry = $vbulletin->db->query_read("
SELECT thread.title, username, post.dateline, post.pagetext FROM " . TABLE_PREFIX . "thread AS thread
LEFT JOIN " . TABLE_PREFIX . "post AS post ON thread.lastpostid = post.postid
WHERE thread.forumid IN (1, 2, 3) AND thread.visible = '1'
ORDER BY lastpost DESC
LIMIT 0, $numposts ");

while ($thrds = $vbulletin->db->fetch_array($thrdqry))
{
$postdate = vbdate($vbulletin->options['dateformat'], $thrds['dateline'], true);
$posttime = vbdate($vbulletin->options['timeformat'], $thrds['dateline']);

$homepage_recentpost .=<<<EOD
$thrds[title] $thrds[username] $postdate $posttime
<BR>
$thrds[pagetext]
<BR><BR>
EOD;

}


This doesn't check permissions of course, but maybe you're not worried about that.
A bigger problem is that this doesn't handle bbcode in the text. :(

just.b.jealous
12-15-2010, 11:40 PM
You could do this:

$numposts='10';


$thrdqry = $vbulletin->db->query_read("
SELECT thread.title, username, post.dateline, post.pagetext FROM " . TABLE_PREFIX . "thread AS thread
LEFT JOIN " . TABLE_PREFIX . "post AS post ON thread.lastpostid = post.postid
WHERE thread.forumid IN (1, 2, 3) AND thread.visible = '1'
ORDER BY lastpost DESC
LIMIT 0, $numposts ");

while ($thrds = $vbulletin->db->fetch_array($thrdqry))
{
$postdate = vbdate($vbulletin->options['dateformat'], $thrds['dateline'], true);
$posttime = vbdate($vbulletin->options['timeformat'], $thrds['dateline']);

$homepage_recentpost .=<<<EOD
$thrds[title] $thrds[username] $postdate $posttime
<BR>
$thrds[pagetext]
<BR><BR>
EOD;

}

This doesn't check permissions of course, but maybe you're not worried about that.
A bigger problem is that this doesn't handle bbcode in the text. :(

Thanks for helping me out, I'm not too good with plugins yet, template stuff is easy. 1 more question for ya, or anyone else who knows, I'm sure it would be pretty easy- any chance of making this just pick up the last thread posted/user/date/contents, instead of the last poster in a thread?

Thanks in advance,.

kh99
12-16-2010, 12:00 AM
I'm sure it would be pretty easy- any chance of making this just pick up the last thread posted/user/date/contents, instead of the last poster in a thread?

It does sound like it should be easy, but I'm afraid I don't understand what you want.

just.b.jealous
12-16-2010, 02:04 AM
It does sound like it should be easy, but I'm afraid I don't understand what you want.

Oh sorry,. Right now the plugin displays:

When someone has posted in forums 1,2, or 3.
Displays the Username for who posted.
Displays the Title of the thread that they posted in.
Displays the Date & Time when they posted.

I would like it to display:
When someone has started a new thread (not a post) in forums 1,2, or 3.
Displays the Username for who started the thread (not the last poster).
Displays the Title of the new thread.
Displays the Date & Time when the new thread was posted.

Once again, thanks for helping me out.

kh99
12-16-2010, 02:42 AM
OK, I think I see now. I think if you change lastpostid to firstpostid, and order by thread.dateline instead of lastpost that might do it. (There's a dateline in post as well, I don't know if the dateline of the first post is the same as the thread dateline or not. If not you might have to change post.dateline to thread.dateline on the SELECT line).

ETA: the answer seems to be that thread.dateline and dateline of the first post are sometimes different but I don't know why - maybe someone else does?

just.b.jealous
12-16-2010, 04:50 AM
Awesome man, I can't appreciate it enough. I almost have it working- you might as well say it is. Last question, swear. Any way to pull the threads id into it as well? I'm trying to wrap the threads title with an href leading to the thread it's pulling, you'll see what I mean:

$numposts='10';

$thrdqry = $vbulletin->db->query_read("
SELECT thread.title, username, post.dateline, post.pagetext FROM " . TABLE_PREFIX . "thread AS thread
LEFT JOIN " . TABLE_PREFIX . "post AS post ON thread.firstpostid = post.postid
WHERE thread.forumid IN (61, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 130, 131, 132, 133, 134, 136, 137, 138, 139) AND thread.visible = '1'
ORDER BY thread.dateline DESC
LIMIT 0, $numposts ");

while ($thrds = $vbulletin->db->fetch_array($thrdqry))
{
$postdate = vbdate($vbulletin->options['dateformat'], $thrds['dateline'], true);
$posttime = vbdate($vbulletin->options['timeformat'], $thrds['dateline']);
$homepage_recentpost .=<<<EOD
<div class="post-1 post type-post hentry category-uncategorized" id="post-1">
<h2 class="title"><a href="showthread.php?t=THREADID" target="_blank" alt="$thrds[title]" title="$thrds[title]">
$thrds[title]
</a>
</h2>
<div class="postdate">
<img src="images/date.png" /> $postdate <img src="images/user.png" /> $thrds[username]
</div>
<div class="entry">
<p>$thrds[pagetext]</p><br/><a href="showthread.php?t=THREADID" target="_blank" alt="$thrds[title]" title="$thrds[title]">
Read more..
</a><br/>
</div>
</div>
EOD;

}

kh99
12-16-2010, 07:14 AM
You can add any field from the thread or post db tables just by adding it after SELECT. So if you add thread.threadid to the list of columns after SELECT you can use $thrds[threadid] to get your id.

just.b.jealous
12-17-2010, 02:36 AM
Hell yeah, thanks a million bro, you made my life soo much easier..