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 09-03-2007, 04:35 PM
ralle89 ralle89 is offline
 
Join Date: Oct 2005
Location: Denmark
Posts: 63
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default vB_DataManager_Thread, How do I do?

Hey!
I am trying to generate threads with the class: vB_DataManager_Thread.
I tried searching Google and the forums.
I couldn't really find what I need.

I need a simple piece of code on how to make a thread in forum, by userid, with contents and dateline.

I have seached a lot,

Thanks in advance,
Ralle
Reply With Quote
  #2  
Old 09-03-2007, 06:08 PM
Delphiprogrammi Delphiprogrammi is offline
 
Join Date: Feb 2004
Location: Landen(Belgium)
Posts: 1,335
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hi,

You must create a datamanager instance set the things you want to set check for errors and finally when things are ok save them

PHP Code:
$threaddm =& datamanager_init('Thread_FirstPost',$vbulletin,ERRTYPE_ARRAY,'threadpost');
  
$threaddm->setr('forumid',$destforum);
  
$threaddm->setr('title','');
  
$threaddm->setr('pagetext','');
  
$threaddm->set('userid','');
  
$threaddm->set('open',1);
  
$threaddm->set('visible',1);
  
$threaddm->set('allowsmilie',1);
  
$threaddm->set_info('forum',$newforuminfo);
  
$threaddm->set_info('thread',array());
  
$threaddm->pre_save();
  if(!empty(
$threaddm->errors))
  {
   
print_r($threaddm->errors);
   exit;
  }
  else
  {
   
$newthreadid $threaddm->save();
  } 
now you have at least an idea howto do it $newforuminfo is coming from a fetch_foruminfo(); call
Reply With Quote
  #3  
Old 09-03-2007, 06:43 PM
ralle89 ralle89 is offline
 
Join Date: Oct 2005
Location: Denmark
Posts: 63
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Never mind, I fixed it.
I replaced all setr with set
Once again, thank you!
Quote:
Thank you for your response and the big help. But I cannot get this to work.
This is my code:
PHP Code:
<?php
// don't look at the $scriptpath variable. It's assigned from an upper file.
require_once("$scriptpath/vbulletin.php");
require_once(
'./includes/class_dm.php');
require_once(
'./includes/class_dm_threadpost.php');

$threaddm =& datamanager_init('Thread_FirstPost',$vbulletin,ERRTYPE_ARRAY,'threadpost');
$threaddm->setr('forumid',$destforum);
$threaddm->setr('title','Peter Jackson');
$threaddm->setr('pagetext','This thread [b]rocks!');
$threaddm->set('userid','1');
$threaddm->set('open',1);
$threaddm->set('visible',1);
$threaddm->set('allowsmilie',1);
$threaddm->set_info('forum',$newforuminfo);
$threaddm->set_info('thread',array());
$threaddm->pre_save();
if(!empty(
$threaddm->errors)) {
    
print_r($threaddm->errors);
    exit;
} else {
    
$newthreadid $threaddm->save();
}

?>
And I am getting this error:
Code:
Fatal error:  Cannot pass parameter 2 by reference in /[...]/tools_thread.php on line 9
I tried to uncomment this line:
PHP Code:
$threaddm->setr('title','Peter Jackson'); 
But then it just started complaining about the next line
Reply With Quote
  #4  
Old 09-03-2007, 07:38 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In setr the value is passed as a reference. (So it must be a variable I assume.)

PHP Code:
$title 'Peter Jackson';
$threaddm->setr('title'$title); 
Would work, I think.
Reply With Quote
  #5  
Old 09-03-2007, 07:47 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Correct - setr() means set by reference, so cannot be a constant.
Reply With Quote
  #6  
Old 09-21-2007, 06:34 PM
toucan42 toucan42 is offline
 
Join Date: Sep 2006
Posts: 112
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am getting the following error:

That username is already in use or does not meet the administrator's standards.

any ideas?
Reply With Quote
  #7  
Old 09-21-2007, 06:52 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Didn't you read the error?
Quote:
That username is already in use or does not meet the administrator's standards.
It seems pretty self explanatory to me.

You probably need to add something like:

PHP Code:
$threaddm->set('username''Username for Userid #1 or something here'); 
To the list.
Reply With Quote
  #8  
Old 09-21-2007, 07:23 PM
toucan42 toucan42 is offline
 
Join Date: Sep 2006
Posts: 112
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Opserty View Post
Didn't you read the error?
It seems pretty self explanatory to me.

You probably need to add something like:

PHP Code:
$threaddm->set('username''Username for Userid #1 or something here'); 
To the list.
Of course I read the error - how else would I know to post the durn thing!?

It just doesn't make sense to me.

I already have:

PHP Code:
$threaddm->setr('username'$uname); 
you are using set i am using setr but both flavors give the same result.
Reply With Quote
  #9  
Old 09-21-2007, 08:53 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What is the value of $uname? Also make sure it is set to the username of the member with the same userid which is defined earlier.
Reply With Quote
  #10  
Old 09-21-2007, 10:58 PM
toucan42 toucan42 is offline
 
Join Date: Sep 2006
Posts: 112
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here is my entire script - the variables in $_GET are all form variables being sent via AJAX to a page processing the form and creating a new thread:

PHP Code:
<?php
    
    
// Get Required Includes
    
require_once('global.php');
    require_once(
'includes/class_dm.php');
    require_once(
'includes/class_dm_threadpost.php'); 
    require_once(
'includes/functions_databuild.php'); 
        
        
// Retrieve data from Query String
    
$name $_GET['name'];
    
$lat $_GET['lat'];
    
$lon $_GET['lon'];
    
$uid $_GET['uid'];
    
$uname $_GET['uname'];
    
$gid $_GET['gid'];
    
$desc $_GET['desc'];
    
$phone $_GET['phone'];
    
$addr $_GET['addr'];
    
$addr2 $_GET['addr2'];
    
$city $_GET['city'];
    
$state $_GET['state'];
    
$zip $_GET['zip'];
    
$cat $_GET['cat'];

    
// Escape User Input to help prevent SQL Injection
    
$name mysql_real_escape_string($name);
    
$lat mysql_real_escape_string($lat);
    
$lon mysql_real_escape_string($lon);
    
$uid mysql_real_escape_string($uid);
    
$uname mysql_real_escape_string($uname);
    
$gid mysql_real_escape_string($gid);
    
$desc mysql_real_escape_string($desc);
    
$phone mysql_real_escape_string($phone);
    
$addr mysql_real_escape_string($addr);
    
$addr2 mysql_real_escape_string($addr2);
    
$city mysql_real_escape_string($city);
    
$state mysql_real_escape_string($state);
    
$zip mysql_real_escape_string($zip);
    
$cat mysql_real_escape_string($cat);


    
// Thread_FirstPost DataManager to add thread
        
$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');
        
$threadinfo = array();

    
// unsure about these two
        
$threaddm->set_info('forum'$foruminfo);
        
$threaddm->set_info('thread'$threadinfo);
        
        
// set to correct forum to use
        
$forumtouse 57;
        
$threaddm->setr('forumid'$forumtouse);
        
        
// user information - uid and username come from submitted form
        
$threaddm->setr('userid'$uid);

        
$threaddm->setr('username'$uname);
       
       
$threadtitle "Some title text";
        
$threaddm->setr('title'$threadtitle);
        
       
        
// Set thread contents
        
$pagetext $desc;
        
$threaddm->setr('pagetext'$pagetext);
        
       
        
        
// allow replies
        
$threaddm->set('open'$open);
        
        
// allow smilies
        
$threaddm->set('allowsmilie'$allowsmilie);
        
        
// make visible
        
$threaddm->set('visible'$visible);

    
// pre-save
        
$threaddm->pre_save();


            
$threadid $threaddm->save();
            unset(
$threaddm);
            
build_thread_counters($threaddm);

        
build_forum_counters($foruminfo['forumid']);
There exists more code below this but none of it deals with inserting a new thread.
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 12:37 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04657 seconds
  • Memory Usage 2,324KB
  • 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
  • (1)bbcode_code
  • (8)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete