vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Create a thread remotely (https://vborg.vbsupport.ru/showthread.php?t=182545)

Hereward 06-15-2008 08:37 AM

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.

Opserty 06-15-2008 08:44 AM

<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>

Hereward 06-15-2008 08:45 AM

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 (:

Opserty 06-15-2008 08:46 AM

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

Hereward 06-15-2008 08:50 AM

Quote:

Originally Posted by Opserty (Post 1549770)

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 (Post 1549775)
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.

Opserty 06-15-2008 02:16 PM

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. 


Cryo 06-21-2008 05:29 PM

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.

Dismounted 06-22-2008 06:42 AM

Please post the whole page.

Cryo 06-29-2008 12:50 AM

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.

Dismounted 06-29-2008 12:57 PM

Please post the whole page. The whole code you are using.


All times are GMT. The time now is 08:43 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.01368 seconds
  • Memory Usage 1,821KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (10)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete