vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Create Posts (https://vborg.vbsupport.ru/showthread.php?t=102418)

fly 12-06-2005 10:00 PM

Create Posts
 
PHP Code:

require_once('./global.php');
require_once(
'./includes/class_dm.php');
require_once(
'./includes/class_dm_threadpost.php');

$postdm = new vB_DataManager_Post($vbulletinERRTYPE_STANDARD);

$postthreadid '4473';
$postusername 'admin';
// Use $postusername if posting as a guest, use $postuserid if posting as a user
//$postuserid = '1';
$postpagetext 'Hi mom!';

$threadinfo fetch_threadinfo($postthreadid);
$foruminfo fetch_foruminfo($threadinfo['forumid']);

$postdm->set_info('forum'$foruminfo);
$postdm->set_info('thread'$threadinfo);  
$postdm->set('threadid'$postthreadid);
$postdm->set('username'$postusername);
// Use $postusername if posting as a guest, use $postuserid if posting as a user
//$postdm->set('userid', $postuserid);
$postdm->set('pagetext'$postpagetext);
$postdm->set('allowsmilie'1);
$postdm->set('visible'1);
$postdm->set('dateline'TIMENOW);
$postdm->save();
unset(
$postdm); 


Rich 12-20-2005 10:24 PM

Hello,

I am a pretty crafty fellow and can figure out most things but I am a tad confused here. As a tutorial, I would expect this to tell me what it does and how to implement it.

(I am guessing it creates a thread that reads"Hi mom!")

All I see is some code but what I would do with this code and what it would do for me I am at a loss for. Is there any chance you could expand on this for us not so knowledgeable individuals. lol

Paul M 12-20-2005 10:49 PM

I thought the title pretty much gave it away > [How To] Create Posts

That is the code to create a post in an existing thread.

Daniel 12-21-2005 02:39 AM

Wouldn't it be easier to just use the "Create Thread" button and call it Hi Mom?

Code Monkey 12-21-2005 03:51 AM

Quote:

Originally Posted by Daniel
Wouldn't it be easier to just use the "Create Thread" button and call it Hi Mom?

Yes, but that's not as fun as doing it with the Data Manager. ;)

fly 12-21-2005 11:12 AM

Quote:

Originally Posted by iguanairs
Hello,

I am a pretty crafty fellow and can figure out most things but I am a tad confused here. As a tutorial, I would expect this to tell me what it does and how to implement it.

(I am guessing it creates a thread that reads"Hi mom!")

All I see is some code but what I would do with this code and what it would do for me I am at a loss for. Is there any chance you could expand on this for us not so knowledgeable individuals. lol

As stated, this is code you would use in a hack to reply to a certain thread. What else do you want to know?

Razz 01-07-2006 10:52 PM

I tried this out but it doesn't seem to update the view and reply counters when it creates the new post or did I miss something?

laddil 01-11-2006 07:36 PM

I have a quick question about using this method to put in a post...

Does it take into account user preferances (i.e., emoticons, smilies, etc.) and forum security settings (vBcode, raw HTML, etc.)?

The modification I'm writing needs to add posts to a specific forum, but I have consern about the potential of this bypassing security and causing mischief.

grana 04-10-2006 10:15 AM

I have a question: if I create a post in this way, does vb send the "update notification emails" to the subscribed users?
If not, how can I trigger this?

Thanks!

Cloud Strife 04-17-2006 10:27 PM

edit

Wild-Wing 04-24-2006 02:47 PM

how can this be used to edit a post already posted?

fly 04-25-2006 11:43 AM

afaik, it can't. :D

Evercraft 04-26-2006 09:53 AM

You need to add the following code, after the post has been created, to update forum counters and last post index etc.

PHP Code:

require_once(DIR '/includes/functions_databuild.php');
build_forum_counters($threadinfo['forumid']); 

Quote:

Originally Posted by laddil
I have a quick question about using this method to put in a post...

Does it take into account user preferances (i.e., emoticons, smilies, etc.) and forum security settings (vBcode, raw HTML, etc.)?

The modification I'm writing needs to add posts to a specific forum, but I have consern about the potential of this bypassing security and causing mischief.

It doesn't check permissions.

nj_vb 07-22-2006 07:28 PM

This doesn't work with 3.5.x for me...

It's saying "the user is already logged in, if you have lost your pw click here" or something to that effect. Any ideas?

Atakan KOC 07-24-2006 04:52 AM

3.5.x

PHP Code:

$rforuminfo fetch_foruminfo($Feed['forumid']);
$newpost = array(
    
'emailupdate' => 9999,
    
'userid' => 'Userid',
    
'username' => 'Username',
    
'title' => 'Title',
  
'message' =>  'Message',
  
'thread' => 'threadid'
);
$threadinfo['threadid'] = 'threadid';
build_new_post('Post'$rforuminfo$threadinfo, array(), $newpost$errors); 


fly 07-24-2006 11:32 AM

Quote:

Originally Posted by nj_vb
This doesn't work with 3.5.x for me...

It's saying "the user is already logged in, if you have lost your pw click here" or something to that effect. Any ideas?

I remember that happening to me as well. iirc, you populated BOTH the username and userid. Only fill in one.

ragtek 08-25-2006 05:24 PM

i've created a hook :
PHP Code:

if ($forumid==7)
{
$newpost = array(
    
'emailupdate' => 9999,
    
'userid' => '120',
    
'username' => 'Informationsminister',
    
'title' => 'Info',
  
'message' =>  '[SHOWTOGROUPS="10"]folge dem wei?n wolf
:P oder w?hle folgende nummer[/SHOWTOGROUPS]'
,
  
'thread' => '$threadid'
);
$threadinfo['threadid'] = 'threadid';
build_new_post('Post''7'$threadinfo, array(), $newpost$errors);} 

the start is newpost_complete
i want to make a automatic answer on every thread that someone creates in forum=7 but it doesn do that

FreekBoy 08-29-2006 01:35 AM

Is there a way like this to create forums?

Derschizo 10-04-2006 01:53 PM

What if you put it in the function_new reply and you want it to be a auto second post, what would you put for the threadid?
b/c
$threadinfo['threadid'] = 'threadid'; doesn't seem to work.

I want it in the same thread.

ruinernix 10-07-2006 03:03 AM

Quote:

Originally Posted by Atakan KOC
3.5.x

PHP Code:

$rforuminfo fetch_foruminfo($Feed['forumid']);
$newpost = array(
    
'emailupdate' => 9999,
    
'userid' => 'Userid',
    
'username' => 'Username',
    
'title' => 'Title',
  
'message' =>  'Message',
  
'thread' => 'threadid'
);
$threadinfo['threadid'] = 'threadid';
build_new_post('Post'$rforuminfo$threadinfo, array(), $newpost$errors); 


This works, but all messages created end up in a moderation queue even though the forum is not set to moderate posts/threads. I tried adding 'visible'=>'1' but it doesn't make a difference. Any clues? I suppose it's because I'm running this from an outside script, that isn't really logged into VB. I made a modification to functions_newpost.php
PHP Code:

Replaced:
    
// see if post has to be moderated or if poster in a mod
    
if ( 
        ((
With:
    
// see if post has to be moderated or if poster in a mod
    
if ( ($post['visible'] == 0) AND
        (( 

It does the job, but I'd like to understand why it's not working properly..

I also added build_forum_counters($forumid); after posting, otherwise the lastthread info doesn't get updated in the forum list.

Quote:

Originally Posted by Derschizo
What if you put it in the function_new reply and you want it to be a auto second post, what would you put for the threadid?
b/c
$threadinfo['threadid'] = 'threadid'; doesn't seem to work.

I want it in the same thread.

You should be using

$threadinfo['threadid'] = 3310; (ie: 3310 is the thread id)

ks_work 11-22-2006 02:24 PM

i'm with 3.6.3 now.
How do I update existing post ?

thanks

amcd 11-23-2006 03:52 AM

Quote:

Originally Posted by ks_work (Post 1122972)
i'm with 3.6.3 now.
How do I update existing post ?

thanks

this is how we do it on 3.6.1 . i think the same is valid for 3.6.3 as well
Code:

$vbulletin->db->query_write("UPDATE post SET pagetext = '$message' WHERE postid=$postid");
$vbulletin->db->query_write("DELETE FROM postparsed WHERE postid=$postid");


ks_work 11-23-2006 12:37 PM

thanks a lot !
I'll try it.
Meanwhile this code did the job for me (i apologize for it's messiness):
PHP Code:

<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
//define('GET_EDIT_TEMPLATES', true);

    
define('SKIP_SESSIONCREATE'1);
    
define('DIE_QUIETLY'1);    
define('THIS_SCRIPT''editpost');

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(
DIR '/includes/functions_newpost.php');
require_once(
DIR '/includes/functions_bigthree.php');
require_once(
DIR '/includes/functions_editor.php');
require_once(
DIR '/includes/functions_log_error.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

// ### STANDARD INITIALIZATIONS ###
$checked = array();
$edit = array();
$postattach = array();



############################ start  input from tt_news

$k_postid=$_REQUEST["k_postid"];
$k_threadid=$_REQUEST['k_threadid'];
$k_title=$_REQUEST['k_title'];
$k_pagetext=$_REQUEST['k_pagetext'];
$k_hidden_visible=$_REQUEST['k_hidden_visible'];

############################  end input from tt_news



$threadinfo['forumid']=55;
$threadinfo['threadid']=$k_threadid;
$threadinfo['firstpostid']= $k_postid;

$foruminfo fetch_foruminfo($threadinfo['forumid'], false);
//print"<P>forum: <pre>".print_r($foruminfo,1);print"<P>thread :<pre>".print_r($threadinfo,1);
    
$postinfo['postid'] = $k_postid;
    
$postinfo['threadid'] =$threadinfo['threadid'];
    
$postinfo['parentid'] = $k_postid;
    
$postinfo['username'] = 'administrator';
    
$postinfo['userid'] = 1;
    
$postinfo['title'] = $k_title;
    
$postinfo['dateline'] = '';
    
$postinfo['pagetext'] =$k_pagetext;
    
$postinfo['allowsmilie'] = 1;
    
$postinfo['showsignature'] = 0;
    
$postinfo['ipaddress'] = '206.223.168.166';
    
$postinfo['iconid'] = 0;

        if( isset(
$_REQUEST["k_hidden_visible"]))//
        
{
                if(
$_REQUEST["k_hidden_visible"]==0)// hidden
                
{
                
$visible_val=0;
                }
                else 
//
                
{
                
$visible_val=1;
                }        
        }
        else 
//
        
{
            
$visible_val=0;
        
        }

    
$postinfo['visible'] = $visible_val;
    
$postinfo['attach'] = 0;
    
$postinfo['infraction'] = 0;
    
$postinfo['reportthreadid'] = 0;
    
$postinfo['isdeleted'] = 0;
    
$postinfo['edit_userid'] = '';
    
$postinfo['edit_dateline'] = '';
    
$postinfo['edit_reason'] ='' ;


    
$threadinfo['visible']=$visible_val;
///print"<P>post <pre>".print_r($postinfo,1);
$aaa=1;

// need to get last post-type information
cache_ordered_forums(1);

// ############################### start update post ###############################
if ($aaa ==1)
{
    
// Variables reused in templates
    
$posthash $vbulletin->input->clean_gpc('p''posthash'TYPE_NOHTML);
    
$poststarttime $vbulletin->input->clean_gpc('p''poststarttime'TYPE_UINT);

    
$vbulletin->input->clean_array_gpc('p', array(
        
'stickunstick'   => TYPE_BOOL,
        
'openclose'      => TYPE_BOOL,
        
'wysiwyg'        => TYPE_BOOL,
        
'message'        => TYPE_STR,
        
'title'          => TYPE_STR,
        
'iconid'         => TYPE_UINT,
        
'parseurl'       => TYPE_BOOL,
        
'signature'         => TYPE_BOOL,
        
'disablesmilies' => TYPE_BOOL,
        
'reason'         => TYPE_NOHTML,
        
'preview'        => TYPE_STR,
        
'folderid'       => TYPE_UINT,
        
'emailupdate'    => TYPE_UINT,
        
'ajax'           => TYPE_BOOL,
        
'advanced'       => TYPE_BOOL,
        
'postcount'      => TYPE_UINT,
        
'podcasturl'     => TYPE_STR,
        
'podcastsize'    => TYPE_UINT,
        
'podcastexplicit' => TYPE_BOOL,
        
'podcastkeywords' => TYPE_STR,
        
'podcastsubtitle' => TYPE_STR,
        
'podcastauthor'   => TYPE_STR,
    ));
    
    
// ### PREP INPUT ###
    
        
$edit['message'] =$k_pagetext;
        
$edit['iconid'] =& $vbulletin->GPC['iconid'];
        
$edit['title'] =$k_title;
        
$edit['podcasturl'] =& $vbulletin->GPC['podcasturl'];
        
$edit['podcastsize'] =& $vbulletin->GPC['podcastsize'];
        
$edit['podcastexplicit'] =& $vbulletin->GPC['podcastexplicit'];
        
$edit['podcastkeywords'] =& $vbulletin->GPC['podcastkeywords'];
        
$edit['podcastsubtitle'] =& $vbulletin->GPC['podcastsubtitle'];
        
$edit['podcastauthor'] =& $vbulletin->GPC['podcastauthor'];        
        
$edit['signature'] =& $vbulletin->GPC['signature'];
        
$edit['disablesmilies'] =& $vbulletin->GPC['disablesmilies'];
        
$edit['enablesmilies'] = $edit['allowsmilie'] = ($edit['disablesmilies']) ? 1;
        
$edit['stickunstick'] =& $vbulletin->GPC['stickunstick'];
        
$edit['openclose'] =& $vbulletin->GPC['openclose'];
        
$edit['visible'] = $visible_val;

        
$edit['reason'] = fetch_censored_text($vbulletin->GPC['reason']);
        
$edit['preview'] =& $vbulletin->GPC['preview'];
        
$edit['folderid'] =& $vbulletin->GPC['folderid'];    

    
$dataman =& datamanager_init('Post'$vbulletinERRTYPE_ARRAY'threadpost');
    
$dataman->set_existing($postinfo);
//print"<P>edit:<pre>".print_r($edit,1);
    // set info
    
$dataman->set_info('parseurl', ($foruminfo['allowbbcode'] AND $edit['parseurl']));
    
$dataman->set_info('posthash'$posthash);
    
$dataman->set_info('forum'$foruminfo);
    
$dataman->set_info('visible'$visible_val);
    
$dataman->set_info('thread'$threadinfo);
    
$dataman->set_info('show_title_error'true);
    
$dataman->set_info('podcasturl'$edit['podcasturl']);
    
$dataman->set_info('podcastsize'$edit['podcastsize']);
    
$dataman->set_info('podcastexplicit'$edit['podcastexplicit']);
    
$dataman->set_info('podcastkeywords'$edit['podcastkeywords']);
    
$dataman->set_info('podcastsubtitle'$edit['podcastsubtitle']);
    
$dataman->set_info('podcastauthor'$edit['podcastauthor']);
    if (
$postinfo['userid'] == $vbulletin->userinfo['userid'])
    {
        
$dataman->set_info('user'$vbulletin->userinfo);
    }
//print"<P>userinfo:<pre>".print_r($vbulletin->userinfo,1);


    // set options
    
$dataman->setr('showsignature'$edit['signature']);
    
$dataman->setr('allowsmilie'$edit['enablesmilies']);

    
// set data
    /*$dataman->setr('userid', $vbulletin->userinfo['userid']);
    if ($vbulletin->userinfo['userid'] == 0)
    {
        $dataman->setr('username', $post['username']);
    }*/
    
$dataman->setr('title'$edit['title']);
    
$dataman->setr('visible'$edit['visible']);
    
$dataman->setr('pagetext'$edit['message']);
    if (
$postinfo['userid'] != $vbulletin->userinfo['userid'])
    {
        
$dataman->setr('iconid'$edit['iconid'], truefalse);
    }
    else
    {
        
$dataman->setr('iconid'$edit['iconid']);
    }
    
    
$dataman->pre_save();
    if (
$dataman->errors)
    {
        
$errors $dataman->errors;
    }
    
    if (
sizeof($errors) > 0)
    {
        
// ### POST HAS ERRORS ###
        
print"<P>ERRORS:<pre>".print_r($errors,1);
            
    }    
    else
    {
        
// ### POST HAS NO ERRORS ###

        
print"<P>No errors so far !";
        print
"<P>edit:<pre>".print_r($edit,1);

        print 
"<P>result is :".$dataman->save();    

        
$date vbdate($vbulletin->options['dateformat'], TIMENOW);
        
$time vbdate($vbulletin->options['timeformat'], TIMENOW);

        
// initialize thread / forum update clauses
        
$forumupdate false;

        
$threadman =& datamanager_init('Thread'$vbulletinERRTYPE_SILENT'threadpost');
        
$threadman->set_existing($threadinfo);

    if (
$edit['title'] != '' )
        {
            
// need to update thread title and iconid            
            
$threadman->set_info('skip_first_post_update'false);
            
$threadman->set('title'unhtmlspecialchars($edit['title']));
            
$threadman->set('visible'$edit['visible']);
            
$threadman->set('iconid'$edit['iconid']);

            
// do we need to update the forum counters?
            
$forumupdate = ($foruminfo['lastthreadid'] == $threadinfo['threadid']) ? true false;
        }
        else{
        print 
"<P> line 237 not update thread";
        }
                
        
$threadman->save();
        
        require_once(
DIR '/includes/functions_databuild.php');

        
// do forum update if necessary
        
if ($forumupdate)
        {
            
build_forum_counters($threadinfo['forumid']);
        }

        
$cansubscribe true;
        
        
//    $vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "p=$postinfo[postid]#post$postinfo[postid]";                
    
}
}
?>


Derschizo 12-03-2006 11:23 PM

That looks interesting can you show me how to implement and make it fully work completely. I'm not sure exactly where you put the code and what each section completely means. I'm assuming it goes to the function_newpost .

amcd 12-04-2006 03:18 AM

That depends on what you want to achieve. In vbulletin 3.5 or higher, editing the original php files is discouraged and its better to add plugins.

jj 12-09-2006 03:10 PM

Hi guys, I'm creating/posting/modifying posts/thread out of some custom software I wrote. Now is there a way of bypassing the post-time limit with the datamanager-method when doing it?

BOLT 12-21-2006 03:38 PM

I dont understand. Where do you enter this code? And how do you make the post, time, thread, etc. be what exactly you want?

liquidx 05-27-2007 03:36 AM

Can someone help here?

I'm trying to create new posts, I've tried both the dataman and build_new_post methods, here's my problems:

Dataman method:
How do I handle errors? When I get an error (like posting anonymously with a user name that is already in use) it directly echos out a full error page! I don't want this, I want just the error message..

build_new_post method:
When posting anonymous, the new posts are moderated, even though the forum allows anonymous posting and is not moderated.. I can't figure out how to stop this from happening.

I've searched all over the forums for both these issues but came up empty, anyone?

quitsmoking 07-04-2007 10:26 PM

And what if I want to add a new thread (not a post in an existing thread)?

fly 07-05-2007 11:49 AM

Then you'd find the thread about HowTo Create Threads. ;)

quitsmoking 07-07-2007 09:44 PM

Thank you. Your advice worked :) I found one and it worked like charm.

Ranma2k 08-30-2007 11:47 AM

I have a Q

can we use the vb post class / data manager to store the posts in different table other the the default table Posts ?
If yes can you please explain ?

ragtek 08-31-2007 04:52 PM

what do you realy want?:D
you could "inherit" the class i think

Ranma2k 09-01-2007 06:36 AM

well basically i want to use the post class to process the Comments and store it in the comment table

toucan42 09-21-2007 01:48 PM

Quote:

Originally Posted by Paul M (Post 853471)
I thought the title pretty much gave it away > [How To] Create Posts

That is the code to create a post in an existing thread.

I am struggling to get my mind wrapped around the datamanager - if i want code to create a new thread is it the vB_DataManager_Thread_FirstPost I am looking for?

Any decent examples of using the DM?

rootnik 09-29-2007 05:54 PM

Quote:

Originally Posted by flypaper (Post 1283415)
Then you'd find the thread about HowTo Create Threads. ;)

There is no such thread anymore. I am needing to do this as well.

fly 09-29-2007 07:12 PM

Quote:

Originally Posted by rootnik (Post 1349746)
There is no such thread anymore. I am needing to do this as well.

I'll try to write one up this weekend then, if no one else does. Dunno why it got removed...

Thibaut 10-21-2007 08:23 PM

Quote:

Originally Posted by rootnik (Post 1349746)
There is no such thread anymore. I am needing to do this as well.

I would need that too, thanks.

ragtek 10-21-2007 08:42 PM

with this code:
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(); 

if you need the threadid save it with
PHP Code:

$id $threaddm->save(); 


Thibaut 10-22-2007 08:06 AM

Thanks ;)


All times are GMT. The time now is 07:31 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.01543 seconds
  • Memory Usage 1,984KB
  • 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
  • (1)bbcode_code_printable
  • (9)bbcode_php_printable
  • (11)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)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