PDA

View Full Version : which PHP file contains posting sql function?


radiofranky
07-28-2011, 03:31 PM
Hi,
I have created additional fields in my editor and I would like to able to store those variables into database. However, I'm not quit familiar with VB yet and don't know which file contains the code for submitting the post bits to db.

I have manually create three "columns" named "price", "orig_price" and "pct".
Could someone show me where sql command is called during posting and when it pulls out to render in the template.

thanks

HMBeaty
07-28-2011, 03:39 PM
I believe it would be: includes/functions_newpost.php

radiofranky
07-28-2011, 03:47 PM
I believe it would be: includes/functions_newpost.php

thanks. I have the following code as a plugin which adds two extra input fields during new post. Stored in "price" and "saleprice", it also calculate the third value "pct".
I would like to store them into db with the thread of the postbits. Could you help me figure it out? Thanks


$vbulletin->input->clean_array_gpc('p', array(
'saleprice' => TYPE_uinit,
'price' => TYPE_uinit));
$price = $vbulletin->GPC['price'];
$saleprice = $vbulletin->GPC['saleprice'];
vB_Template::preRegister('newthread', array('price' => $price, 'saleprice' => $saleprice));
$pct = intval((1-($vbulletin->GPC['saleprice'] / $vbulletin->GPC['price']))*100 );
$vbulletin->GPC['subject'] .= " for $".$vbulletin->GPC['saleprice'] .", {$pct}% off (orig.$" . $vbulletin->GPC['price'] . ")";



i see this function build_new_post($type = 'thread', $foruminfo, $threadinfo, $postinfo, &$post, &$errors)
and should i add my variable to it?

kh99
07-28-2011, 04:07 PM
In includes/class_dm_threadpost.php, around line 1515 is class vB_DataManager_ThreadFirstPost, if you scroll down you see a $validfields array which I believe are the columns from the thread table. If you scroll down further you see this:

function vB_DataManager_Thread_FirstPost(&$registry, $errtype = ERRTYPE_STANDARD)
{
parent::vB_DataManager($registry, $errtype);

($hook = vBulletinHook::fetch_hook('threadfpdata_start')) ? eval($hook) : false;
}



which is executed when one of those objects is created, so if you create a plugin using hook threadfpdata_start, you should be able to add your fields to the $validfields array. Then in build_new_post() in includes/functions_newpost.php, you can see the fields being set. So you should be able to create a plugin using hook newpost_process and something like:

if ($type == 'thread')
{
$dataman->setr('price', $post['price']);
// etc.
}


(BTW, I haven't actually tried this).

radiofranky
07-28-2011, 04:19 PM
Thanks very much..

How do I set the third variable "pct" which is the result of calculation from "price" and "saleprice"?

since the three additional fields were done by another plugin, will this work?

if ($type == 'thread')
{
$dataman->setr('price', $post['price']);
$dataman->setr('saleprice', $post['saleprice']);
$dataman->setr('pct', $post['pct']);
// etc.
}

kh99
07-28-2011, 04:24 PM
As long as the other plugin runs first. I guess it'll be easy enough to tell. If they were done in newthread.php before build_new_post() is called, you'll be OK.

--------------- Added 1311888277 at 1311888277 ---------------

Where do you want to read them? Your other thread said postbit, but this is a thread thing and not a post thing. Anyway, it might be available already. In a template you could try {vb:raw thread.price}.

radiofranky
07-28-2011, 09:38 PM
actually I want to display in vbadvanced template. Thanks

As long as the other plugin runs first. I guess it'll be easy enough to tell. If they were done in newthread.php before build_new_post() is called, you'll be OK.

--------------- Added 1311888277 at 1311888277 ---------------

Where do you want to read them? Your other thread said postbit, but this is a thread thing and not a post thing. Anyway, it might be available already. In a template you could try {vb:raw thread.price}.