PDA

View Full Version : Extra Post Fields ?


wolfe
10-17-2007, 11:48 AM
i have tried to add 3 extra fields to my new post for chosen forum but its not inserting anything. here what i have done so far.

in the database table post i have added 4 fields img, info, trailer and url.

and a normal newthread form but with extra fields and there names are

for table img fieldname is txtImage
for table trailer fieldname is txtTrailer
for table url fieldname is url
for table info fieldname is infotext

in class_dm_threadpost.php: i changed

var $validfields = array(
'postid' => array(TYPE_UINT, REQ_INCR, 'return ($data > 0);'),
'threadid' => array(TYPE_UINT, REQ_YES),
'parentid' => array(TYPE_UINT, REQ_AUTO),
'username' => array(TYPE_STR, REQ_NO, VF_METHOD),
'userid' => array(TYPE_UINT, REQ_NO, VF_METHOD),
'title' => array(TYPE_STR, REQ_NO, VF_METHOD),
'dateline' => array(TYPE_UINT, REQ_AUTO),
'pagetext' => array(TYPE_STR, REQ_YES, VF_METHOD),
'allowsmilie' => array(TYPE_UINT, REQ_YES), // this is required as we must know whether smilies count as images
'showsignature' => array(TYPE_BOOL, REQ_NO),
'ipaddress' => array(TYPE_STR, REQ_AUTO),
'iconid' => array(TYPE_UINT, REQ_NO, VF_METHOD),
'visible' => array(TYPE_UINT, REQ_NO),
'attach' => array(TYPE_UINT, REQ_NO),
'infraction' => array(TYPE_UINT, REQ_NO),
'reportthreadid' => array(TYPE_UINT, REQ_NO),
);into

var $validfields = array(
'postid' => array(TYPE_UINT, REQ_INCR, 'return ($data > 0);'),
'threadid' => array(TYPE_UINT, REQ_YES),
'parentid' => array(TYPE_UINT, REQ_AUTO),
'username' => array(TYPE_STR, REQ_NO, VF_METHOD),
'userid' => array(TYPE_UINT, REQ_NO, VF_METHOD),
'title' => array(TYPE_STR, REQ_NO, VF_METHOD),
'dateline' => array(TYPE_UINT, REQ_AUTO),
'pagetext' => array(TYPE_STR, REQ_YES, VF_METHOD),
'allowsmilie' => array(TYPE_UINT, REQ_YES), // this is required as we must know whether smilies count as images
'showsignature' => array(TYPE_BOOL, REQ_NO),
'ipaddress' => array(TYPE_STR, REQ_AUTO),
'iconid' => array(TYPE_UINT, REQ_NO, VF_METHOD),
'visible' => array(TYPE_UINT, REQ_NO),
'attach' => array(TYPE_UINT, REQ_NO),
'infraction' => array(TYPE_UINT, REQ_NO),
'reportthreadid' => array(TYPE_UINT, REQ_NO),
'info' => array(TYPE_STR, REQ_NO),
'url' => array(TYPE_STR, REQ_NO),
'img' => array(TYPE_STR, REQ_NO),
'trailer' => array(TYPE_STR, REQ_NO),
);and then in same file i changed

var $validfields = array(
'firstpostid' => array(TYPE_UINT, REQ_AUTO),
'lastpost' => array(TYPE_UINT, REQ_AUTO),
'forumid' => array(TYPE_UINT, REQ_YES),
'pollid' => array(TYPE_UINT, REQ_NO),
'open' => array(TYPE_UINT, REQ_AUTO, VF_METHOD),
'replycount' => array(TYPE_UINT, REQ_AUTO),
'hiddencount' => array(TYPE_UINT, REQ_AUTO),
'deletedcount' => array(TYPE_UINT, REQ_AUTO),
'lastposter' => array(TYPE_STR, REQ_AUTO),
'lastpostid' => array(TYPE_UINT, REQ_AUTO),
'views' => array(TYPE_UINT, REQ_NO),
'notes' => array(TYPE_STR, REQ_NO),
'sticky' => array(TYPE_UINT, REQ_NO, VF_METHOD),
'votenum' => array(TYPE_UINT, REQ_NO),
'votetotal' => array(TYPE_UINT, REQ_NO),
'similar' => array(TYPE_STR, REQ_AUTO),

// shared fields
'threadid' => array(TYPE_UINT, REQ_INCR),
'title' => array(TYPE_STR, REQ_YES, VF_METHOD),
'username' => array(TYPE_STR, REQ_NO, VF_METHOD), // maps to thread.postusername
'userid' => array(TYPE_UINT, REQ_NO, VF_METHOD), // maps to thread.postuserid
'dateline' => array(TYPE_UINT, REQ_AUTO),
'iconid' => array(TYPE_UINT, REQ_NO, VF_METHOD),
'visible' => array(TYPE_BOOL, REQ_NO), // note: post.visible will always be 1 with this object!
'attach' => array(TYPE_UINT, REQ_NO),

'pagetext' => array(TYPE_STR, REQ_YES, VF_METHOD),
'allowsmilie' => array(TYPE_UINT, REQ_YES), // this is required as we must know whether smilies count as images
'showsignature' => array(TYPE_BOOL, REQ_NO),
'ipaddress' => array(TYPE_STR, REQ_AUTO),
);info

var $validfields = array(
'firstpostid' => array(TYPE_UINT, REQ_AUTO),
'lastpost' => array(TYPE_UINT, REQ_AUTO),
'forumid' => array(TYPE_UINT, REQ_YES),
'pollid' => array(TYPE_UINT, REQ_NO),
'open' => array(TYPE_UINT, REQ_AUTO, VF_METHOD),
'replycount' => array(TYPE_UINT, REQ_AUTO),
'hiddencount' => array(TYPE_UINT, REQ_AUTO),
'deletedcount' => array(TYPE_UINT, REQ_AUTO),
'lastposter' => array(TYPE_STR, REQ_AUTO),
'lastpostid' => array(TYPE_UINT, REQ_AUTO),
'views' => array(TYPE_UINT, REQ_NO),
'notes' => array(TYPE_STR, REQ_NO),
'sticky' => array(TYPE_UINT, REQ_NO, VF_METHOD),
'votenum' => array(TYPE_UINT, REQ_NO),
'votetotal' => array(TYPE_UINT, REQ_NO),
'similar' => array(TYPE_STR, REQ_AUTO),

// shared fields
'threadid' => array(TYPE_UINT, REQ_INCR),
'title' => array(TYPE_STR, REQ_YES, VF_METHOD),
'username' => array(TYPE_STR, REQ_NO, VF_METHOD), // maps to thread.postusername
'userid' => array(TYPE_UINT, REQ_NO, VF_METHOD), // maps to thread.postuserid
'dateline' => array(TYPE_UINT, REQ_AUTO),
'iconid' => array(TYPE_UINT, REQ_NO, VF_METHOD),
'visible' => array(TYPE_BOOL, REQ_NO), // note: post.visible will always be 1 with this object!
'attach' => array(TYPE_UINT, REQ_NO),

'info' => array(TYPE_STR, REQ_NO),
'url' => array(TYPE_STR, REQ_NO),
'img' => array(TYPE_STR, REQ_NO),
'trailer' => array(TYPE_STR, REQ_NO),

'pagetext' => array(TYPE_STR, REQ_YES, VF_METHOD),
'allowsmilie' => array(TYPE_UINT, REQ_YES), // this is required as we must know whether smilies count as images
'showsignature' => array(TYPE_BOOL, REQ_NO),
'ipaddress' => array(TYPE_STR, REQ_AUTO),
);and then in same file i changed


case 'pagetext':
case 'allowsmilie':
case 'showsignature':
case 'ipaddress':
{
$tables = array('post');
}
into


case 'pagetext':
case 'allowsmilie':
case 'showsignature':
case 'ipaddress':
case 'info':
case 'url':
case 'img':
case 'trailer':
{
$tables = array('post');
}
then in functions_newpost.php i changed


// set data
$dataman->setr('userid', $vbulletin->userinfo['userid']);
if ($vbulletin->userinfo['userid'] == 0)
{
$dataman->setr('username', $post['username']);
}

$dataman->setr('title', $post['title']);
$dataman->setr('pagetext', $post['message']);
$dataman->setr('iconid', $post['iconid']);
into


// set data
$dataman->setr('userid', $vbulletin->userinfo['userid']);
if ($vbulletin->userinfo['userid'] == 0)
{
$dataman->setr('username', $post['username']);
}

if (in_array($foruminfo['forumid'], array($vbulletin->options['info_forumids'])))
{
$dataman->setr('title', $post['txtTitle']);
$dataman->setr('pagetext', $post['txtDesc']);
} else {
$dataman->setr('title', $post['title']);
$dataman->setr('pagetext', $post['message']);
}
$dataman->setr('iconid', $post['iconid']);
$dataman->set('img', $post['txtImage']);
$dataman->set('url', $post['url']);
$dataman->set('trailer', $post['txtTrailer']);
$dataman->set('info', $post['infotext']);
and then in newthread.php i changed


$vbulletin->input->clean_array_gpc('p', array(
'wysiwyg' => TYPE_BOOL,
'message' => TYPE_STR,
'postpoll' => TYPE_BOOL,
'subject' => TYPE_STR,
'iconid' => TYPE_UINT,
'signature' => TYPE_BOOL,
'preview' => TYPE_STR,
'disablesmilies' => TYPE_BOOL,
'rating' => TYPE_UINT,
'polloptions' => TYPE_UINT,
'folderid' => TYPE_UINT,
'emailupdate' => TYPE_UINT,
'stickunstick' => TYPE_BOOL,
'openclose' => TYPE_BOOL,
'parseurl' => TYPE_BOOL,
'username' => TYPE_STR,
'loggedinuser' => TYPE_INT,
'imagehash' => TYPE_STR,
'imagestamp' => TYPE_STR,
'podcasturl' => TYPE_STR,
'podcastsize' => TYPE_UINT,
'podcastexplicit' => TYPE_BOOL,
'podcastkeywords' => TYPE_STR,
'podcastsubtitle' => TYPE_STR,
'podcastauthor' => TYPE_STR,
));
into


$vbulletin->input->clean_array_gpc('p', array(
'wysiwyg' => TYPE_BOOL,
'message' => TYPE_STR,

'infotext' => TYPE_STR,
'url' => TYPE_STR,
'txtImage' => TYPE_STR,
'txtTrailer' => TYPE_STR,
'txtDesc' => TYPE_STR,
'txtTitle' => TYPE_STR,

'postpoll' => TYPE_BOOL,
'subject' => TYPE_STR,
'iconid' => TYPE_UINT,
'signature' => TYPE_BOOL,
'preview' => TYPE_STR,
'disablesmilies' => TYPE_BOOL,
'rating' => TYPE_UINT,
'polloptions' => TYPE_UINT,
'folderid' => TYPE_UINT,
'emailupdate' => TYPE_UINT,
'stickunstick' => TYPE_BOOL,
'openclose' => TYPE_BOOL,
'parseurl' => TYPE_BOOL,
'username' => TYPE_STR,
'loggedinuser' => TYPE_INT,
'imagehash' => TYPE_STR,
'imagestamp' => TYPE_STR,
'podcasturl' => TYPE_STR,
'podcastsize' => TYPE_UINT,
'podcastexplicit' => TYPE_BOOL,
'podcastkeywords' => TYPE_STR,
'podcastsubtitle' => TYPE_STR,
'podcastauthor' => TYPE_STR,
));
and then in same file i changed



$newpost['title'] =& $vbulletin->GPC['subject'];
$newpost['iconid'] =& $vbulletin->GPC['iconid'];
$newpost['parseurl'] = ($foruminfo['allowbbcode'] AND $vbulletin->GPC['parseurl']);
$newpost['signature'] =& $vbulletin->GPC['signature'];
$newpost['preview'] =& $vbulletin->GPC['preview'];
$newpost['disablesmilies'] =& $vbulletin->GPC['disablesmilies'];
$newpost['rating'] =& $vbulletin->GPC['rating'];
$newpost['username'] =& $vbulletin->GPC['username'];
$newpost['postpoll'] =& $vbulletin->GPC['postpoll'];
$newpost['polloptions'] =& $vbulletin->GPC['polloptions'];
$newpost['folderid'] =& $vbulletin->GPC['folderid'];
$newpost['imagehash'] =& $vbulletin->GPC['imagehash'];
$newpost['imagestamp'] =& $vbulletin->GPC['imagestamp'];
$newpost['poststarttime'] = $poststarttime;
$newpost['posthash'] = $posthash;
// moderation options
$newpost['stickunstick'] =& $vbulletin->GPC['stickunstick'];
$newpost['openclose'] =& $vbulletin->GPC['openclose'];
$newpost['podcasturl'] =& $vbulletin->GPC['podcasturl'];
$newpost['podcastsize'] =& $vbulletin->GPC['podcastsize'];
$newpost['podcastexplicit'] =& $vbulletin->GPC['podcastexplicit'];
$newpost['podcastkeywords'] =& $vbulletin->GPC['podcastkeywords'];
$newpost['podcastsubtitle'] =& $vbulletin->GPC['podcastsubtitle'];
$newpost['podcastauthor'] =& $vbulletin->GPC['podcastauthor'];

into


if (in_array($foruminfo['forumid'], array($vbulletin->options['info_forumids'])))
{
$newpost['message'] =& $vbulletin->GPC['txtDesc'];
$newpost['title'] =& $vbulletin->GPC['txtTitle'];
} else {
$newpost['message'] =& $vbulletin->GPC['message'];
$newpost['title'] =& $vbulletin->GPC['subject'];
}

$newpost['info'] =& $vbulletin->GPC['infotext'];
$newpost['url'] =& $vbulletin->GPC['url'];
$newpost['img'] =& $vbulletin->GPC['txtImage'];
$newpost['trailer'] =& $vbulletin->GPC['txtTrailer'];

$newpost['iconid'] =& $vbulletin->GPC['iconid'];
$newpost['parseurl'] = ($foruminfo['allowbbcode'] AND $vbulletin->GPC['parseurl']);
$newpost['signature'] =& $vbulletin->GPC['signature'];
$newpost['preview'] =& $vbulletin->GPC['preview'];
$newpost['disablesmilies'] =& $vbulletin->GPC['disablesmilies'];
$newpost['rating'] =& $vbulletin->GPC['rating'];
$newpost['username'] =& $vbulletin->GPC['username'];
$newpost['postpoll'] =& $vbulletin->GPC['postpoll'];
$newpost['polloptions'] =& $vbulletin->GPC['polloptions'];
$newpost['folderid'] =& $vbulletin->GPC['folderid'];
$newpost['imagehash'] =& $vbulletin->GPC['imagehash'];
$newpost['imagestamp'] =& $vbulletin->GPC['imagestamp'];
$newpost['poststarttime'] = $poststarttime;
$newpost['posthash'] = $posthash;
// moderation options
$newpost['stickunstick'] =& $vbulletin->GPC['stickunstick'];
$newpost['openclose'] =& $vbulletin->GPC['openclose'];
$newpost['podcasturl'] =& $vbulletin->GPC['podcasturl'];
$newpost['podcastsize'] =& $vbulletin->GPC['podcastsize'];
$newpost['podcastexplicit'] =& $vbulletin->GPC['podcastexplicit'];
$newpost['podcastkeywords'] =& $vbulletin->GPC['podcastkeywords'];
$newpost['podcastsubtitle'] =& $vbulletin->GPC['podcastsubtitle'];
$newpost['podcastauthor'] =& $vbulletin->GPC['podcastauthor'];
and then in same file i changed


eval('print_output("' . fetch_template('newthread') . '");');
into


if (in_array($foruminfo['forumid'], array($vbulletin->options['info_forumids'])))
{
eval('print_output("' . fetch_template('newinfo') . '");');
} else {
eval('print_output("' . fetch_template('newthread') . '");');
}
what am i missing because its just returning


The following errors occurred when this message was submitted:
Please complete both the subject and message fields.
The message you have entered is too short. Please lengthen your message to at least 10 characters.

Opserty
10-17-2007, 12:58 PM
Use the same name for the inputs as you do in the table, i.e. in the post table you should have the columns url, image, trailer and info. Regarding the error message its probably because you have mucked up a piece of code somewhere and its throwing up problems. Also you shouldn't edit files directly, what you are trying to do can be achieved by using plugins I'm pretty sure.

I'll look through the files and try and give you some pointers in a bit.

wolfe
10-17-2007, 01:01 PM
thx m8 would be alot better if i could use a plugin. also i need it so the txtDesc field submits as the message.

Opserty
10-17-2007, 01:14 PM
Hook Location: newthread_post_start

// Clean input
$vbulletin->input->clean_array_gpc('p', array(
'url' => TYPE_STR,
'img' => TYPE_STR,
'info' => TYPE_NOHTML,
'trailer' => TYPE_NOHTML
));

// Assign the input to go to the builder
$newpost['url'] = $vbulletin->GPC['url'];
// Repeat for others


Hook Location: postdata_start

// Set our custom valid fields
$this->validfields['url'] = array(TYPE_STR, REQ_NO);
// Repeat for others

Hook Location: newpost_process

// Set the input data to the custom fields
$dataman->setr('url', $post['url']);
// Repeat for others


Now you need to edit the newthread template with the correct input boxes which have the names 'url', 'img', 'info' and 'trailer'.

I hope I haven't missed anything out but I think that it is pretty much it.

EDIT: I don't know if you can overwrite the message text with the txtDesc using plugins. Why not just ask the user to input the description as the content of the post? It would be far easier to do it that way :p

wolfe
10-17-2007, 02:14 PM
get this error m8

Fatal error: Field img is not defined in $validfields in class vB_DataManager_Thread_FirstPost in /includes/class_dm.php on line 485

Opserty
10-17-2007, 03:04 PM
Did you repeat this code appropriately?

// Set our custom valid fields
$this->validfields['url'] = array(TYPE_STR, REQ_NO);
// Repeat for others


For img, trailer e.t.c. same goes for the wherever else I commented "Repeat for others".

If you have repeated it and its still not working post the code you wrote.

wolfe
10-17-2007, 10:47 PM
yes m8 i repeated all required ones and i get that error. any ideas

Paul M
10-17-2007, 11:12 PM
You need to define the fields in threadfpdata_start as well as postdata_start - add the same code to that hook.

You also need to define them as being for the post table - via hook threadfpdata_doset

Add a line like this for each one ;

if ($fieldname == 'url') $tables = array('post');

wolfe
10-17-2007, 11:50 PM
i have sorted the problem now but i cant get it to update the contents of the post on edit it just insert nothing into the database.