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-15-2008, 08:37 AM
Hereward Hereward is offline
 
Join Date: Jun 2008
Posts: 9
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Create a thread remotely

My goal is simple. I need a PHP class which can interface with my external CMS in the following way:

1) create an article in CMS.

2) on completion of CMS submission, call a PHP function from my custom class (probably via HTTP request) which will insert a new thread into a dedicated vb forum, using the title and body of the new article - and returning to the calling app the id of the newly created forum thread.

3) provide a function which can be called from the CMS each time the page loads to get the number of replies.

I have so far found one discussion of this, here:
https://vborg.vbsupport.ru/showthread.php?t=181689

But the code sample is tantalisingly incomplete... I would love to see a full working example rather than just a snippet.

I would have thought this problem would have been solved a hundred times over by now?

Any pointers?

thanks.
Reply With Quote
  #2  
Old 06-15-2008, 08:44 AM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

<a href="https://vborg.vbsupport.ru/showthread.php?t=102418&page=3#39" target="_blank">https://vborg.vbsupport.ru/showt...2418&page=3#39</a>
Reply With Quote
  #3  
Old 06-15-2008, 08:45 AM
Hereward Hereward is offline
 
Join Date: Jun 2008
Posts: 9
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

my guess is that the essence is in the following:
PHP Code:
require_once(DIR '/includes/functions_newpost.php');
build_new_post('thread', , array(), $postinfo$newpost$errors); 
I assume that $foruminfo, $postinfo, and newpost are simple arrays. Is there a data type definition for this stuff anywhere?

Is there any documentation for the code?

thanks (:
Reply With Quote
  #4  
Old 06-15-2008, 08:46 AM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Check the thread datamanager files in the include directory. class_dm_thread*.php

TYPE_xxx defines their type and requirements.

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

Maybe of interest: Data Managers
Reply With Quote
  #5  
Old 06-15-2008, 08:50 AM
Hereward Hereward is offline
 
Join Date: Jun 2008
Posts: 9
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Opserty View Post
hi - thanks for that!

in the example you referenced there is a variable $vbulletin which is passed as a parameter to the datamanager_init function. How is that variable created?

Also wondering which php files I need to require for datamanager_init to work.

PHP Code:
$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');

$forumid $vbulletin->GPC['fid']; // can also be a number ;) $forumdid= 12;

$foruminfo fetch_foruminfo($forumid);
$threaddm->set_info('forum'$foruminfo);

$threaddm->set('forumid'$foruminfo['forumid']);
$threaddm->set('userid'1234);
$threaddm->set('title''Testtitle');
$threaddm->set('pagetext''a little test');
$threaddm->set('allowsmilie'1);
$threaddm->set('visible'1);
$threaddm->set('dateline'TIMENOW);
$threaddm->save(); 
--------------- Added [DATE]1213523643[/DATE] at [TIME]1213523643[/TIME] ---------------

Quote:
Originally Posted by Opserty View Post
Check the thread datamanager files in the include directory. class_dm_thread*.php

TYPE_xxx defines their type and requirements.

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

Maybe of interest: Data Managers
OK - i will start reading the manual.

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

PHP Code:
$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost'); 
In the manual it says (in regard to the 2nd param):
Quote:
$registry - the main registry object used by vBulletin to hold application-level data. In most cases, this will be the variable $vbulletin.
Do I need to use this? If so, how do I construct the object ($vbulletin)?

I am guessing that maybe I don't need it because in the sample code it is only used to fetch an id - but in my case I will be passing that as a separate param:
PHP Code:
$forumid $vbulletin->GPC['fid']; 
So can I get away with passing an empty string as "the main registry object" or will this cause the function to fail?

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

OK, small question:

where does the function datamanager_init live?

This seems to be the key to it all. it would be nice if there was a working sample that showed what needs to be in the required path etc..

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

OK I found it in functions.php

so i guess I need to start with something like:

PHP Code:
require $root_path/functions.php
--------------- Added [DATE]1213526419[/DATE] at [TIME]1213526419[/TIME] ---------------

In the comments for datamanager_init we see:
PHP Code:
/*
* Class factory. This is used for instantiating the extended classes.
*
* @param    string            The type of the class to be called (user, forum etc.)
* @param    vB_Registry        An instance of the vB_Registry object.
* @param    integer            One of the ERRTYPE_x constants
* @param    string            Option to force loading a class from a specific file; no extension
*
* @return    vB_DataManager    An instance of the desired class
*/ 
question: How do I construct the vB_Registry object?

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

OK, looks like I need something like the following:

PHP Code:
<?php
require $root_path/includes/class_core.php;
require 
$root_path/functions.php

$vbulletin = new vB_Registry();

$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');

$forumid $vbulletin->GPC['fid']; // can also be a number ;) $forumdid= 12;

$foruminfo fetch_foruminfo($forumid);
$threaddm->set_info('forum'$foruminfo);

$threaddm->set('forumid'$foruminfo['forumid']);
$threaddm->set('userid'1234);
$threaddm->set('title''Testtitle');
$threaddm->set('pagetext''a little test');
$threaddm->set('allowsmilie'1);
$threaddm->set('visible'1);
$threaddm->set('dateline'TIMENOW);
$threaddm->save(); 

?>
--------------- Added [DATE]1213529047[/DATE] at [TIME]1213529047[/TIME] ---------------

OK, I have no confirmed that the above DOES NOT WORK.

Can anyone tell me what is wrong with the code or should I just give up?

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

The following is tested and WORKS:

PHP Code:
<?php

define
('VB_AREA''Forum');
define('CWD', (($getcwd getcwd()) ? $getcwd '.'));
require_once(
"./includes/init.php");

define('DIR'CWD);

require_once 
"./includes/functions.php"

$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');
$forumid 30//$vbulletin->GPC['fid']; // can also be a number ;) $forumdid= 12;
$foruminfo fetch_foruminfo($forumid);
$threaddm->set_info('forum'$foruminfo);
$threaddm->set('forumid'$foruminfo['forumid']);
$threaddm->set('userid'1);
$threaddm->set('title''Testtitle');
$threaddm->set('pagetext''a little test');
$threaddm->set('allowsmilie'1);
$threaddm->set('visible'1);
$threaddm->set('dateline'TIMENOW);
$threaddm->save(); 

print 
"The action was performed.";
?>
--------------- Added [DATE]1213531734[/DATE] at [TIME]1213531734[/TIME] ---------------

NOTE: The file needs to be placed at the root level of your vbulletin installation.
Reply With Quote
  #6  
Old 06-15-2008, 02:16 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you just include global.php it includes init.php and functions.php. If you want to move out of the forum root use chdir()

E.g.:
PHP Code:
$cwd getcwd();
chdir('path/to/forumroot/');
require_once(
'global.php');

$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');

chdir($cwd);

// Continue script here...

// For error checking I think they are contained in a $threaddm->errors array. 
Reply With Quote
  #7  
Old 06-21-2008, 05:29 PM
Cryo Cryo is offline
 
Join Date: Dec 2003
Location: Buffalo, NY
Posts: 197
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm pretty much lost at this point. Here is the code I have...

PHP Code:
// vBulletin Add Post Function (Start)
                                        
$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');
                    
$forumid 17;
$foruminfo fetch_foruminfo($forumid);
                                                    
$threaddm->set_info('forum'$foruminfo);
$threaddm->set('forumid'$foruminfo['forumid']);
$threaddm->set('userid'$postuserid);
$threaddm->set('title'$title);
$threaddm->set('pagetext'$output);
$threaddm->set('allowsmilie'0);
$threaddm->set('visible'1);
$threaddm->set('dateline'TIMENOW);
$threaddm->save(); 
The code worked prior to my 3.7 upgrade, now it gives this error...

Fatal error: Database object is not an object in [path]/includes/class_dm.php on line 172

I have the global.php included and directories are correct... like I said, this all worked pre-3.7. Any ideas? The output and title variables are set, by the way.

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

OK, so I took the code and put it into its own page and it works fine. Putting it into the page's IF statement seems to break it and gives me the error indicated above.
Reply With Quote
  #8  
Old 06-22-2008, 06:42 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Please post the whole page.
Reply With Quote
  #9  
Old 06-29-2008, 12:50 AM
Cryo Cryo is offline
 
Join Date: Dec 2003
Location: Buffalo, NY
Posts: 197
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I did read the whole page. The code I have works if it is OUTSIDE the post statement, once it is inside it stops functioning (which renders it worthless). I may be missing it, but I don't see that problem addressed here. If it was, please point me to the post / segment which gives resolution.
Reply With Quote
  #10  
Old 06-29-2008, 12:57 PM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Please post the whole page. The whole code you are using.
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 09:20 AM.


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.04645 seconds
  • Memory Usage 2,317KB
  • Queries Executed 11 (?)
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
  • (10)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
  • (1)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_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