vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   Auto-creation of threads? (https://vborg.vbsupport.ru/showthread.php?t=61030)

SnitchSeeker 01-22-2005 09:39 AM

Is there a way to pass the last thread's id from build_new_post? I currently have this: (just a snippet)
PHP Code:

    build_new_post('thread'$foruminfo, array(), 0$post$errors); 

    
$DB_site->query("
            INSERT INTO fp_news_info
                (threadid, avatar, summary)
            VALUES
                (
$threadinfo[threadid], '$news[avatar]', '$news[summary]')
    "
); 

It's not passing the $threadinfo[threadid] variable. I used to insert it directly into the database, but I want a cleaner version. So I modified build_new_post function and added a new variable. So now it would say:
PHP Code:

function build_new_post($type 'thread'$foruminfo$threadinfo$parentid, &$post, &$errors$news

Then an if news exist check, and my previous sql code. However I'm not very sure if this won't bug current posting? Because previously with build_new_post code it'd post, now it just gives a blank page. I need to add the $news variable or it won't work. Regular posting and topic creating is working as far as I can see, but I want to be sure if this is in fact going to work... (did that make sense? :))

SnitchSeeker 01-23-2005 11:32 AM

Bump. Anyone?

Wired1 02-16-2005 06:09 AM

Just checking into my baby ;)

Been busy for forever, but IF I get a chance, I'll try to delve into the code again.

Only way I'll release it as a hack is if I can somehow figure out how to put a module in the admin / mod CP for it, gotta be user friendly and all.

fly 02-16-2005 06:30 PM

Thanks guys. I set mine up to combine the Contact Us page with this 'hack' so that users could submit news stories to our News admin forum without giving them access to it. Thanks!

Any function and/or example for sending PMs?

Wired1 02-17-2005 04:29 AM

Quote:

Originally Posted by flypaper
Thanks guys. I set mine up to combine the Contact Us page with this 'hack' so that users could submit news stories to our News admin forum without giving them access to it. Thanks!

Any function and/or example for sending PMs?

Do the submissions go into a moderation queue or just straight in? Got a link?

Automating sending PMS to one person or a certain amount? Can't see reasoning behind this ATM though, but I'll put it on the list of things to check into.

trafix 02-17-2005 04:44 AM

WTF .... 85 posts just to try to explain how to auto generate a new thread.

I have used this often .... it only requires like about 6 lines

PS .. i havnt read the thread, there is tooooooooooo much and i dont have that much time

Wired1 02-17-2005 06:42 AM

Then by all means, post your way of doing it. FYI, this thread is a year old. The first 2 pages are mainly myself and some others working it out, the rest are about others using the code.

Also, counted the lines, it's about 8 after trimming non-essential stuff, so your code would probably look similar.

Hoffi 02-17-2005 01:19 PM

I just found this Thread. That helps me figuring out how to build a Thread. ;)

Did someone know how to add a Poll to the created Thread?

fly 02-18-2005 11:14 AM

Quote:

Originally Posted by flypaper
The threads go straight into the forum. Link to the hackjob is http://uselessforums.com/submitnews.php

And I was talking in the Ucash/Ushop forum yesterday and someone mentioned PMing a member after they were 'theifed'. I liked the idea and tried to poke around and see if there was a function to send PMs like creating threads, but couldn't find one.

Hmmm. Looks like there isn't a function to do it, but these DB queries do:

PHP Code:

$DB_site->query("INSERT INTO " TABLE_PREFIX "pmtext\n\t(fromuserid, fromusername, title, message, touserarray, iconid, dateline, showsignature, allowsmilie)\nVALUES\n\t($bbuserinfo[userid], '" addslashes($bbuserinfo['username']) . "', '$title', '$message', '" addslashes(serialize($tostring)) . "', $iconid, " TIMENOW ", $signature$disablesmilies)"); 

PHP Code:

$DB_site->query("INSERT INTO " TABLE_PREFIX "pm (pmtextid, userid, folderid, messageread) VALUES ($pmtextid$bbuserinfo[userid], -1, 1)"); 

PHP Code:

$DB_site->shutdown_query("UPDATE " TABLE_PREFIX "user SET pmtotal=pmtotal+1 WHERE userid=$bbuserinfo[userid]"); 

Can anyone explain how I pass whatever is needed in these queries and/or what the queries are exactly doing?

edit: I should probably start a new thread.

zeropaid 02-23-2005 06:46 AM

Ok I had this working, but am now trying to implement on a new machine running a version of 3.0.7 and php5. I am getting an odd error,

Fatal error: Call to undefined method stdClass::query_first() in /usr/local/www/htdocs/bbs/includes/functions.php on line 938

Here is my code. As far as I can tell everything is being included fine, no errors there.

PHP Code:

# Do forum stuff


 chdir('/usr/local/www/htdocs/bbs');

// Load vB-Backend
require('./global.php');
require('./includes/functions_newpost.php');

if ($_POST[news_user_id] == 0 || !$_POST[news_user_id]) {
        $userid = 1;
} else {
        $userid = 1;
}

//$userid = $_POST[news_user_id]; // The user creating the thread
$forumid = 120; // The forum where the thread should be posted

// Get forum & user info
$foruminfo = fetch_foruminfo($forumid);
$bbuserinfo = fetch_userinfo($userid);

print_r($bbuserinfo);


// Setup the thread
$post[title] = $title;
$post[message] = $article;
$post[poststarttime] = TIMENOW;
$post[posthash] = md5($post[poststarttime] . $bbuserinfo['userid'] . $bbuserinfo['salt']);
$post[emailupdate] = 9999;

// build the thread
build_new_post('thread', $foruminfo, array(), 0, $post, $errors);

// Errors?
if (sizeof($errors) > 0) {
  ?>There have been errors. <?=$errors?><?
  print_r($errors);
  die('errors');
}

$ThreadID = $post['threadid'];
$PostID = $post['postid'];

print ("the threadid is $ThreadID and the postid is $PostID");


fly 02-23-2005 11:16 AM

What's on line 938 of functions.php?

zeropaid 02-23-2005 05:02 PM

PHP Code:

    938         $user $DB_site->query_first("
    939                 SELECT " 
.
    
940                 iif(($option 16), ' administrator.*, ') . "
    941                 userfield.*, usertextfield.*, user.*, UNIX_TIMESTAMP(passworddate) AS passworddate,
    942                 IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid" 
.
    
943                 iif(($option 1) AND $vboptions['reputationenable'] == 1', level') .
    
944                 iif(($option 2) AND $vboptions['avatarenabled'], ', avatar.avatarpath, NOT ISNULL(customavatar.avatardata) AS hascustomavatar, customavatar.dateline AS avatardateline').
    
945                 iif(($option 8), ', customprofilepic.userid AS profilepic, customprofilepic.dateline AS profilepicdateline') .
    
946                 iif(!isset($vbphrase), fetch_language_fields_sql(), '') . "
    947                 FROM " 
TABLE_PREFIX "user AS user
    948                 LEFT JOIN " 
TABLE_PREFIX "userfield AS userfield ON (user.userid = userfield.userid)
    949                 LEFT JOIN " 
TABLE_PREFIX "usertextfield AS usertextfield ON (usertextfield.userid = user.userid) " .
    
950                 iif(($option 1) AND $vboptions['reputationenable'] == 1"LEFT JOIN  " TABLE_PREFIX "reputationlevel AS reputationlevel ON (user.reputationlevelid = reputationlevel.re        putationlevelid) ").
    
951                 iif(($option 2) AND $vboptions['avatarenabled'], "LEFT JOIN " TABLE_PREFIX "avatar AS avatar ON (avatar.avatarid = user.avatarid) LEFT JOIN " TABLE_PREFIX "customa        vatar AS customavatar ON (customavatar.userid = user.userid) ") .
    
952                 iif(($option 8), "LEFT JOIN " TABLE_PREFIX "customprofilepic AS customprofilepic ON (user.userid = customprofilepic.userid) ") .
    
953                 iif(($option 16), "LEFT JOIN " TABLE_PREFIX "administrator AS administrator ON (administrator.userid = user.userid) ") .
    
954                 iif(!isset($vbphrase), "INNER JOIN " TABLE_PREFIX "language AS language ON (language.languageid = IF(user.languageid = 0, " intval($vboptions['languageid']) . ", user.        languageid)) ")."
    955                 WHERE user.userid = 
$userid
    956         "
); 


mtrac 03-02-2005 01:10 AM

Excellent thread. I hooked the auto-creation up to the CaRP RSS parser and a couple of cron jobs and now have this.

Today's question is how do I create calendar events? I'd be interested in a year at a time; i.e. monthly board meeting schedules. I'm thinking of inserting a text file into vb3_event with PHPMyAdmin but would like something more sophisticated.

Thanks.

fly 03-02-2005 10:59 AM

Quote:

Originally Posted by mtrac
Excellent thread. I hooked the auto-creation up to the CaRP RSS parser and a couple of cron jobs and now have this.

Today's question is how do I create calendar events? I'd be interested in a year at a time; i.e. monthly board meeting schedules. I'm thinking of inserting a text file into vb3_event with PHPMyAdmin but would like something more sophisticated.

Thanks.

Search here for news2vb also...

zeropaid 03-07-2005 11:03 PM

Ok, I figured out my problem. Has anyone got this code to work inside a function? When I run it normally, it works fine. When I put it inside a function, I get all kinds of errors.

fly 03-08-2005 11:21 AM

Quote:

Originally Posted by zeropaid
Ok, I figured out my problem. Has anyone got this code to work inside a function? When I run it normally, it works fine. When I put it inside a function, I get all kinds of errors.

Can you post what you're doing?

zeropaid 03-11-2005 09:09 PM

PHP Code:

<?
require_once("../classes/nested.php");
require_once("../classes/form.php");
require_once("../classes/mysql.php");

$nested = new Nested;
$forms = new Forms;

function doforum () {
global $forumcache;


# Do forum stuff

 chdir('/usr/local/www/htdocs/bbs');

// Load vB-Backend

$globaltemplates = array();
$specialtemplates = array();
$actiontemplates = array();

#require_once('./includes/db_mysql.php');
require_once('./global.php');
require_once('./includes/functions_newpost.php');

#if ($_POST[news_user_id] == 0 || !$_POST[news_user_id]) {
#        $userid = 1;
#} else {
#        $userid = 1;
#}

//$userid = $_POST[news_user_id]; // The user creating the thread
$userid = 1;
$forumid = 34; // The forum where the thread should be posted

// Get forum & user info
$foruminfo = fetch_foruminfo($forumid);
$bbuserinfo = fetch_userinfo($userid);

#print_r($bbuserinfo);

$title = "this is the title";
$article = "this is the body of the article where the text would go.... need to parse html out, maybe just link to the story";

// Setup the thread
$post[title] = $title;
$post[message] = $article;
$post[poststarttime] = TIMENOW;
$post[posthash] = md5($post[poststarttime] . $bbuserinfo['userid'] . $bbuserinfo['salt']);
$post[emailupdate] = 9999;

// build the thread
build_new_post('thread', $foruminfo, array(), 0, $post, $errors);

// Errors?
if (sizeof($errors) > 0) {
  ?>There have been errors. <?=$errors?><?
  print_r($errors);
  die('errors');
}

$ThreadID = $post['threadid'];
$PostID = $post['postid'];

print ("the threadid is $ThreadID and the postid is $PostID");
}

doforum();
?>


Which returns:

Warning: array_keys() [function.array-keys]: The first argument should be an array in /includes/functions.php on line 3089

Warning: Invalid argument supplied for foreach() in /includes/functions.php on line 3089

Fatal error: Call to a member function query() on a non-object in /usr/local/www/htdocs/bbs/includes/functions.php on line 2298

Fatal error: Call to undefined method stdClass::query() in /usr/local/www/htdocs/bbs/includes/functions.php on line 524

I also have the same code outside a function, which works fine:

PHP Code:

<?
require_once("../classes/nested.php");
require_once("../classes/form.php");
require_once("../classes/mysql.php");

$nested = new Nested;
$forms = new Forms;

global $forumcache;


# Do forum stuff

 chdir('/usr/local/www/htdocs/bbs');

// Load vB-Backend

$globaltemplates = array();
$specialtemplates = array();
$actiontemplates = array();

#require_once('./includes/db_mysql.php');
require_once('./global.php');
require_once('./includes/functions_newpost.php');

#if ($_POST[news_user_id] == 0 || !$_POST[news_user_id]) {
#        $userid = 1;
#} else {
#        $userid = 1;
#}

//$userid = $_POST[news_user_id]; // The user creating the thread
$userid = 1;
$forumid = 34; // The forum where the thread should be posted

// Get forum & user info
$foruminfo = fetch_foruminfo($forumid);
$bbuserinfo = fetch_userinfo($userid);

#print_r($bbuserinfo);

$title = "this is the title";
$article = "this is the body of the article where the text would go.... need to parse html out, maybe just link to the story";

// Setup the thread
$post[title] = $title;
$post[message] = $article;
$post[poststarttime] = TIMENOW;
$post[posthash] = md5($post[poststarttime] . $bbuserinfo['userid'] . $bbuserinfo['salt']);
$post[emailupdate] = 9999;

// build the thread
build_new_post('thread', $foruminfo, array(), 0, $post, $errors);

// Errors?
if (sizeof($errors) > 0) {
  ?>There have been errors. <?=$errors?><?
  print_r($errors);
  die('errors');
}

$ThreadID = $post['threadid'];
$PostID = $post['postid'];

print ("the threadid is $ThreadID and the postid is $PostID");
?>

It seems like it is missing some data inside that function or something.

Marco van Herwaarden 03-12-2005 04:45 AM

I didn't really go through your code, but try getting the userinfo before the foruminfo.

zeropaid 03-14-2005 04:23 AM

yeah the code is pretty long and convoluted, the bottom line is when i run it just in a normal test script it works perfectly, when I put it in any sort of function construct it fails as soon as it tries to execute any vb code.

Lee Wilde 03-17-2005 01:22 AM

You may be interested in this hack just released by deathemperor:

Calendar Search and Comments for Events
https://vborg.vbsupport.ru/showthread.php?p=626269

zeropaid 03-18-2005 06:02 PM

So i just wrote a custom workaround so I don't have to have this code in a function.. it is ugly but it works.

I know there is a lot of people using this hack since this thread is so big, but has anyone gotten posts to display on another page? Is there an easy way to get vbulletin to display posts in their format or is the easier way to just grab the postdata from the db and display them myself?

fly 06-01-2005 11:18 PM

Quote:

Originally Posted by SnitchSeeker
Is there a way to pass the last thread's id from build_new_post? I currently have this: (just a snippet)
PHP Code:

    build_new_post('thread'$foruminfo, array(), 0$post$errors); 

    
$DB_site->query("
            INSERT INTO fp_news_info
                (threadid, avatar, summary)
            VALUES
                (
$threadinfo[threadid], '$news[avatar]', '$news[summary]')
    "
); 

It's not passing the $threadinfo[threadid] variable. I used to insert it directly into the database, but I want a cleaner version. So I modified build_new_post function and added a new variable. So now it would say:
PHP Code:

function build_new_post($type 'thread'$foruminfo$threadinfo$parentid, &$post, &$errors$news

Then an if news exist check, and my previous sql code. However I'm not very sure if this won't bug current posting? Because previously with build_new_post code it'd post, now it just gives a blank page. I need to add the $news variable or it won't work. Regular posting and topic creating is working as far as I can see, but I want to be sure if this is in fact going to work... (did that make sense? :))


Did that end up working? If so, can you post your build_new_post function, as I need a way to get the threadid back out of this...

Andreas 06-01-2005 11:36 PM

You don't have to modify build_new_post().

If you take a close look at its implementation, you will see that $post['threadid'] contains the threadid :)
$threadinfo can't contain the threadid, as this paramater is call by value instead of call by reference (like $post or $errors)

fly 06-02-2005 12:45 PM

Quote:

Originally Posted by KirbyDE
You don't have to modify build_new_post().

If you take a close look at its implementation, you will see that $post['threadid'] contains the threadid :)
$threadinfo can't contain the threadid, as this paramater is call by value instead of call by reference (like $post or $errors)

Sweet! Thanks man. That was it!

Wired1 06-02-2005 09:35 PM

Hrm, don't think my subscription is working to this thread, ack!

Anyway, just as an FYI, I'd release this as an official hack if I could find an article or something that would tell me the easiest way to make a menu within the admin panel.

Andreas 06-02-2005 09:36 PM

What do you mwan with " make a menu within the admin panel."?

Wired1 06-02-2005 10:55 PM

sry, i'm a bit sleep deprived atm :)

Basically when you look at some hacks, you see that they have added menus to the adminCP / modCP areas. GUIs to make the hack as easy as possible to use. IMHO, someone should make a tutorial on how to do it for newbie vB hackers anyway.

Now that I think of it though, I can't recall WHY I wanted that. IIRC, I had a good reason (someone posted a reason why in this thread), but I'm spacing ATM.

One main reason for the function was for server-side bots/programs to auto-post info (e.g. RSS feeds, whatever). My personal reason for it was similar.

Would you even classify this as a hack? It's more of a collection of vB functions IMHO.

mtrac 08-23-2005 04:00 AM

Stupid question, but how do I put carriage returns in? \n doesn't work.

mtrac 08-24-2005 12:03 PM

Never mind. I just discovered the distinction between single and double quotes in PHP.

Wired1 09-02-2005 01:33 AM

kewlness

Yes, I plan to update this when vB 3.5 comes out if it doesn't work

Rendog 09-16-2005 06:47 PM

Hey guys, I'm having a very fundamental issue getting this to work.

As soon as I do the require global.php line, my varibles don't work... by that i mean the php page below prints only Test:

$FORUM_ID is blank even though its decalred...

if i remove the require global.php line its fine.... what gives?

PHP Code:

<?php

    $FORUM_ID 
60;

     
chdir('/www/data/website/forums');

    
// Load vB-Backend
    
require_once ('./global.php');
    
// require_once ('./includes/functions_newpost.php')


?>

Test: <?php echo $FORUM_ID?>

forum_id ends up blank... if i comment out the global.php, it prints properly... any ideas?

Wired1 09-17-2005 05:00 AM

1. what version of PHP are you running, 4 or 5?

2. is global.php called from the function?

Andreas 09-17-2005 05:03 AM

I guess you got register_globals=on
For the sake of security, vBulletin unsets all global variables created by register_globals=on, and there is no way (well ... except changing some basic internal functions would be necessary) to stop it from doing that :)

Best suggestion: Code without relying on register_globals :)

artonex 09-21-2005 10:05 AM

I need to take this rss feed and use it for auto new threads.

http://news.google.com/news?q=mariju...F-8&output=rss

I use vb3.5 rc3.

how would i do this?

mtrac 10-02-2005 03:43 PM

Quote:

Originally Posted by Wired1
Yes, I plan to update this when vB 3.5 comes out if it doesn't work

It's not working off a cron job any more but does work when called locally. Compared to the other problems I'm having it's not exactly a catastrophe. Any ideas?

Wired1 10-02-2005 06:41 PM

artonex:
Not a clue if this will work in vB 3.5.0. Gotta get into the code more first.

mtrac:
what vB version?

mtrac 10-03-2005 09:22 AM

3.5.0 (Gold)

mickmel 07-31-2007 06:42 PM

Quote:

Originally Posted by Wired1 (Post 766713)
Yes, I plan to update this when vB 3.5 comes out if it doesn't work

I was hoping for an update to this. It still creates threads, but:

- They're created under the username of the person that pushes the "create" button, rather than the user specified by the script.
- The threads automatically go into the moderation queue, rather than appearing on the site for other users to respond to.

Thanks.

Wired1 07-31-2007 07:32 PM

blast from the past :)

Could've sworn there's a couple of plugins now that auto-create threads now, could be wrong. If you can't find them, I'll dig into the code (maybe this weekend) and see what I can come up with. As you can see from this thread, I pretty much grabbed some vBulletin functions and slapped them together. I'm guessing these functions have changed, and so this broke. Probably have to re-smush the vBulletin code together :)

Yeah, that last thought didn't make much sense to me either.

norma-aguilera 12-30-2009 02:23 AM

OK. In case anyone else needs this code....

This worked for me with vBullentin version 3.5.4

The new thread was created successfully -even when I was not loggin in.

<?php
require_once('./global.php');
require_once('./includes/functions_newpost.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_threadpost.php');
require_once('./includes/functions_databuild.php');

$forumid = 19;
$userid = 1;
$title = 'The first autopost!';
$pagetext = 'More details here.';

$threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');

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

$threaddm->set('forumid', $forumid);
$threaddm->set('userid', $userid);
//$threaddm->set('user', 'SGD DESIGNS');
$threaddm->set('title', $title);
$threaddm->set('pagetext', $pagetext);
$threaddm->set('allowsmilie', 1);
$threaddm->set('visible', 1);
$threaddm->set('dateline', TIMENOW);
$threaddm->save();
?>


All times are GMT. The time now is 04:17 AM.

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.01413 seconds
  • Memory Usage 1,904KB
  • 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
  • (12)bbcode_php_printable
  • (8)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)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