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

Reply
 
Thread Tools Display Modes
  #1  
Old 06-06-2008, 12:18 PM
el_rob el_rob is offline
 
Join Date: Jan 2008
Location: Switzerland
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Create thread from script

Hello all,

I have written a script which allows me to create a new thread by submitting an HTML form in the Admin CP. Here the code:

PHP Code:
// create new thread
$poststarttime TIMENOW;
$posthash md5($poststarttime $vbulletin->userinfo['userid'] . $vbulletin->userinfo['salt']);
$postinfo = array('posthash' => $posthash);
$forumid $vbulletin->GPC['forumid'];
$foruminfo fetch_foruminfo($forumid);

$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');
$threaddm->set_info('forum'$foruminfo);
$threaddm->set('forumid'$foruminfo['forumid']);
$threaddm->set('userid'$vbulletin->userinfo['userid']);
$threaddm->set('title'$vbulletin->GPC['subject']);
$threaddm->set('pagetext'$vbulletin->GPC['message']);
$threaddm->set('allowsmilie'1);
$threaddm->set('visible'1);
$threaddm->set('showsignature'0);
$threaddm->set('dateline'$poststarttime);

$vbulletin->input->clean_gpc('f''attachment'TYPE_FILE);

// if file to attach
if ($vbulletin->GPC['attachment']) {

    require_once(
DIR '/includes/class_upload.php');
    require_once(
DIR '/includes/class_image.php');
    
    
$threaddm->set('attach'1);
    
$threadid $threaddm->save();
    
$threadinfo fetch_threadinfo($threadid);

    
$uploadsum count(array_filter($vbulletin->GPC['attachment']['name']));
    for (
$x 0$x $uploadsum$x++)
    {
        
$attachdata =& datamanager_init('Attachment'$vbulletinERRTYPE_ARRAY);
        
$upload =& new vB_Upload_Attachment($vbulletin);                        
        
$image =& vB_Image::fetch_library($vbulletin);
        
        
$upload->data =& $attachdata;
        
$upload->image =& $image;
        
        if (
$uploadsum 1)
        {
            
$upload->emptyfile false;
        }
        
        
$upload->foruminfo =& $foruminfo;
        
$upload->postinfo =& $postinfo;
        
$attachment = array(
            
'name'     =>& $vbulletin->GPC['attachment']['name']["$x"],
            
'tmp_name' =>& $vbulletin->GPC['attachment']['tmp_name']["$x"],
            
'error'    =>&    $vbulletin->GPC['attachment']['error']["$x"],
            
'size'     =>& $vbulletin->GPC['attachment']['size']["$x"],
        );
        
        if (
$attachmentid $upload->process_upload($attachment)) {

            
// update db
            
$postid $threadinfo['firstpostid'];
            
$db->query_write("
                UPDATE " 
TABLE_PREFIX "attachment SET
                    postid = 
$postid
                WHERE attachmentid = 
$attachmentid
            "
);
        }
        else {
            print 
$upload->fetch_error();
        }
    }
}
// no file to attach
else
{
    
$threaddm->save();


All works fine, except for this little thing:

I'm trying to set the postid in the attachment table like this
PHP Code:
$upload->postinfo = array('postid' => $threadinfo['firstpostid']); 
however this only works if I change the file "includes/class_upload.php" (Line 908) from
PHP Code:
$this->data->setr_info('postid'$this->postinfo['postid']); 
to
PHP Code:
$this->data->setr('postid'$this->postinfo['postid']); 
But I hate to change vBulletin core files, therefore for now I've solved it by using a regular database update query.

However I would appreciate any help, if someone knows why the datamanager isn't updating the postid!!!

Cheers,
Rob

--------------- Added [DATE]1212826595[/DATE] at [TIME]1212826595[/TIME] ---------------

Ok, got it to work now, thanks to some help from Andreas of vbulletin-germany.org. The trick is to first create the attachment and then the thread...

PHP Code:
// define required variables
$vbulletin->input->clean_gpc('f''attachment'TYPE_FILE);
$poststarttime TIMENOW;
$posthash md5($poststarttime $vbulletin->userinfo['userid'] . $vbulletin->userinfo['salt']);
$postinfo = array('posthash' => $posthash);
$forumid $vbulletin->GPC['forumid'];
$foruminfo fetch_foruminfo($forumid);

// if file to attach
if ($vbulletin->GPC['attachment']) {

    require_once(
DIR '/includes/class_upload.php');
    require_once(
DIR '/includes/class_image.php');
            
    
$uploadsum count(array_filter($vbulletin->GPC['attachment']['name']));
    for (
$x 0$x $uploadsum$x++)
    {
        
$attachdata =& datamanager_init('Attachment'$vbulletinERRTYPE_ARRAY);
        
$upload =& new vB_Upload_Attachment($vbulletin);                        
        
$image =& vB_Image::fetch_library($vbulletin);
        
        
$upload->data =& $attachdata;
        
$upload->image =& $image;
        
        if (
$uploadsum 1)
        {
            
$upload->emptyfile false;
        }
        
        
$upload->foruminfo =& $foruminfo;
        
$upload->postinfo =& $postinfo;
        
$attachment = array(
            
'name'     =>& $vbulletin->GPC['attachment']['name']["$x"],
            
'tmp_name' =>& $vbulletin->GPC['attachment']['tmp_name']["$x"],
            
'error'    =>&    $vbulletin->GPC['attachment']['error']["$x"],
            
'size'     =>& $vbulletin->GPC['attachment']['size']["$x"],
        );
        
        if (
$attachmentid $upload->process_upload($attachment)) {
            
$postinfo['attachmentid'] =& $attachmentid;
        }
        else {
            print 
'Fehler: '$upload->fetch_error();
            exit;
        }
    }
}
// create new thread
$postinfo['forumid'] =& $foruminfo['forumid'];
$newpost['message'] =& $vbulletin->GPC['message'];
$newpost['title'] =& $vbulletin->GPC['subject'];

$newpost['username']        =& $vbulletin->userinfo['username'];
$newpost['poststarttime']   = $poststarttime;
$newpost['posthash']        = $posthash;

/*$newpost['iconid'] =& $vbulletin->GPC['iconid'];
$newpost['prefixid'] =& $vbulletin->GPC['prefixid'];
$newpost['taglist'] =& $vbulletin->GPC['taglist'];
// 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'];
$newpost['emailupdate'] =& $vbulletin->GPC['emailupdate'];*/

require_once(DIR '/includes/functions_newpost.php');
build_new_post('thread'$foruminfo, array(), $postinfo$newpost$errors); 
Reply With Quote
  #2  
Old 06-15-2008, 07:22 AM
Hereward Hereward is offline
 
Join Date: Jun 2008
Posts: 9
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi there,

Is there a page I can visit which has documentation on how to use these API functions?

I want to create a PHP script which can be called from non-vbulletin CMS so that I can populate a dedicated vbulletin forum with a duplicate of blog posts.

I want to be able to read the number of responses to the main post also and have that number displayed eg: "Comments (88) | New comment"

I have been searching for a resource without much luck, but your post is a good start - thanks.

(: Hereward
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 04:24 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05239 seconds
  • Memory Usage 2,246KB
  • Queries Executed 13 (?)
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
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit_info
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)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_postinfo_query
  • fetch_postinfo
  • 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