PDA

View Full Version : first post


testbot
08-30-2009, 01:24 AM
is there away to pull the first post from using a plugin hook?

Brandon Sheley
08-30-2009, 03:07 AM
the first post on the whole forum? or from one particular user? or from one section

Lynne
08-30-2009, 03:18 AM
And to use where? Which hook location? Just the post id or the actual text or ?? Your question is waaaaay too general unless you just want an answer like "yes, probably".

testbot
08-30-2009, 04:10 AM
oh sorry... i want to get the text from the first post in a thread and store it to a value.

$first_post =

not sure if i can use showthread_start

or if there's already something like $threadinfo[title] i could use that.

thanks for your replies!

--------------- Added 1251639047 at 1251639047 ---------------

the first post on the whole forum? or from one particular user? or from one section


just the first post of every thread regardless of user or forum.

Lynne
08-30-2009, 03:49 PM
So, you want to grab the text of the first post in every thread and put it where? We need to know where you are going to display it in order to figure out the variable name. (You know the first text (a set amount of it) is already displayed if you hover over the thread title in the forumdisplay.php page, right?)

testbot
08-30-2009, 04:29 PM
i know if i tell you where i'm going to put it you're just going to tell me to buy vbseo. i don't want that junk. lol

i'm putting it in the head description.

Lynne
08-30-2009, 04:59 PM
Since I am barely familiar with vbseo (I know what it is, but that's all), I would never suggest to someone to buy it.

The $header is evaled before the SHOWTHREAD template is. You will have to write a query in the global_start location (perhaps) to grab the text from the first post of the thread and then do something with it.

testbot
08-31-2009, 11:38 AM
thanks as always Lynne. that makes sense. time to brush up on proper vbulletin queries. :)

--------------- Added 1251722183 at 1251722183 ---------------

of course i'm back. :(

not only does my code suck but i also don't know the db structure. i don't have phpmyadmin installed or anything so digging through tables and stuff via command line seems like a lot of work.

what jumps out at you when you look at the following.

i know this is wrong but this is what i have so far:


$thread_id_inj = $_GET['t'];
if ($thread_id_inj != '' && $_GET['styleid']==9){
//global $db $vbulletin;
//$get_first_post_inj = $db->query_read();

$get_first_post_inj = $vbulletin->db->query_read("SELECT pagetext FROM " . TABLE_PREFIX . "post WHERE threadid = $thread_id_inj LIMIT 1");
}
echo $get_first_post_inj;


i get the following:



Database error in vBulletin 3.8.4:

Invalid SQL:
;

MySQL Error :
Error Number : 0

James Birkett
08-31-2009, 01:36 PM
i know if i tell you where i'm going to put it you're just going to tell me to buy vbseo. i don't want that junk. lol

i'm putting it in the head description.

You mean similar to what RaGEZONE has (or had)? where it shows the beginning of a thread in the description of that forum?

Lynne
08-31-2009, 03:09 PM
So you are passing both the threadid and styleid in the url? If so, you need to clean them prior to using them. example:
$vbulletin->input->clean_array_gpc('r', array(
'threadid' => TYPE_UINT,
'styleid' => TYPE_UINT,
));Then you can use $vbulletin->GPC['threadid'] or assign another variable to that value. example:

$thread_id_inj = $vbulletin->GPC['threadid'];Then, use query_first instead of query_readsince you are only expecting one result. Then you don't have to do a fetch_array (which you didn't do which is why it isn't working).

And don't echo. Assign the result to a variable and then insert the variable into the template where you want it.

You may have issues just using the pagetext as is (I can't remember). Perhaps use stripslashes or similar after you get it from the database.

Gio~Logist
08-31-2009, 04:34 PM
Why not just add a plugin in postbit_display_start to save $post[message] from the first instance, and then use it in the showthread template?

Lynne
08-31-2009, 05:10 PM
That won't allow him to use it in the $header. The header is evaled long before you get to eval the postbit_display_start hook.

testbot
09-01-2009, 02:02 AM
You mean similar to what RaGEZONE has (or had)? where it shows the beginning of a thread in the description of that forum?

So you are passing both the threadid and styleid in the url? If so, you need to clean them prior to using them. example:
$vbulletin->input->clean_array_gpc('r', array(
'threadid' => TYPE_UINT,
'styleid' => TYPE_UINT,
));Then you can use $vbulletin->GPC['threadid'] or assign another variable to that value. example:

$thread_id_inj = $vbulletin->GPC['threadid'];Then, use query_first instead of query_readsince you are only expecting one result. Then you don't have to do a fetch_array (which you didn't do which is why it isn't working).

And don't echo. Assign the result to a variable and then insert the variable into the template where you want it.

You may have issues just using the pagetext as is (I can't remember). Perhaps use stripslashes or similar after you get it from the database.

i was only doing the styleid while testing it in our dev template so our users wouldn't receive any errors while i screwed around. :)

the echo thing was just to see some quick output before putting it in a variable for real testing. i think i was staring at the screen too when i posted that too so that didn't help. lol

anyway, thanks to your help, i finally got it done. it went from a quick query to adding a bunch of little things to make it work good. like limiting it to 30 words, removing line breaks, quotes and all that other stuff.

i'll test this for a bit to make sure it's working well and then i'll post it so if someone else wants to do the same they can.

thanks again!