Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: pctwo on September 15, 2006, 01:00:47 PM

Title: Tip: script to automate posting in 1.1
Post by: pctwo on September 15, 2006, 01:00:47 PM
I searched for a way to automate posting to 1.1 and found some old answers and some hints for how to do it.  Here's a bare minimum working script that demonstrates how to automate posting.  Notes

1) it's  meant to be run from the web.  Running it from the shell gives some errors, but it seems to work nevertheless.  It uses very simple security checking (must be admin to run).

2) it doesn't handle polls or attachments.

3) it does do notification.and appears to keep unread/read stats correctly.

4) it comes with a simple routine to turn htmlized msg to smf compatible one.

Hopefully, this will give you a place a start.  Adjust to suit your needs.  If you figure out how to get it to run under shell w/o error, pls let me know :)


<?phpinclude_once('/aboslute-local-path-to-ssi-php/SSI.php');require_once($sourcedir . '/Post.php');require_once($sourcedir . '/Subs-Post.php'); // comment out below line to run in shellif (!isset($context['user']) || !$context['user']['is_admin']) die ('Unknown error 744 has occurred');$topic = 0;  // set to 0 for new topic, set to a topic id to reply$board = 2; // set to valid board id$ID_MEMBER = 5;$_POST['subject'] = 'you\'re okay';  // the notify function uses this$msgSubject = addslashes($_POST['subject']);$msgBody =  '[quote author=anon]<br>You can use bbc code here<p>This script assumes you have html-ized body which it will convert to smf compatible format[/quote]<p>it\'s all good';$msgBody = prepBody( $msgBody);$msgOptions = array( 'id' => 0, // set id to modify 'subject' => $msgSubject, 'body' => $msgBody, 'icon' => 'xx', // look at smf_message_icons table to see all possible values 'smileys_enabled' => 1, 'attachments' => empty($attachIDs) ? array() : $attachIDs, );$topicOptions = array( 'id' => empty($topic) ? 0 : $topic, 'board' => $board, 'poll' => null, 'lock_mode' => 0, 'sticky_mode' => null, 'mark_as_read' => true, ); $posterOptions = array( 'id' => $ID_MEMBER, 'name' => 'some name', 'email' => '[email protected]', 'update_post_count' => 1 ); $newTopic = empty($topic) || $topic == 0; createPost($msgOptions, $topicOptions, $posterOptions); if (isset($topicOptions['id'])) $topic = $topicOptions['id']; if ($newTopic) notifyMembersBoard(); else sendNotifications($topic, 'reply'); redirectexit('topic=' . $topic); // take an htmlized $txt and turn it into a smf compatible msg// no cr lf, no html tags, <br> turned into <br /> and <p>  made into <br /><br />function prepBody( $txt){ // cr lf to spaces $txt = str_replace( "\r", ' ', $txt); $txt = str_replace( "\n", ' ', $txt); // reduce blank spaces $txt = preg_replace( '/[ ][ ]+/', ' ', $txt); // turn <br> or <br /> into \n $txt = preg_replace( '!\s*<br(\s*/)?>\s*!i', "\n", $txt);

// turn <p ...> and <p> into \n\n
$txt = preg_replace( '/\s*<p([^>]+|)>\s*/i', "\n\n", $txt);

// mercilessly strip all other html
$txt = preg_replace( '/<[^>]+>/', '', $txt);
$txt = preg_replace( '!</[a-z]+>!i', '', $txt);

// turn \n back to <br />
$txt = str_replace( "\n", '<br />', trim( $txt));

return addslashes($txt);
}

?>



Title: Re: Tip: script to automate posting in 1.1
Post by: kangkenyot on September 26, 2006, 04:12:18 AM
would you like to let me know the complete script if on my form include file attachment (foto)  ???
Title: Re: Tip: script to automate posting in 1.1
Post by: pctwo on September 26, 2006, 06:34:04 AM
sorry I did not work out how to do attachment or poll.

addendum: I did not say so in my original post, but obviously you need to set $ID_MEMBER to a valid member's ID.  You can use 0 for a guest if guests are allowed to post.
Title: Re: Tip: script to automate posting in 1.1
Post by: a2h_ on September 26, 2006, 07:31:51 AM
The end of the script turns black... there is a problem in your scripting. It appears to be the ?>, which is the last bit of blue.
Title: Re: Tip: script to automate posting in 1.1
Post by: pctwo on September 26, 2006, 02:36:16 PM
sorry I don't understand what you mean.
Title: Re: Tip: script to automate posting in 1.1
Post by: a2h_ on September 28, 2006, 05:14:47 PM
Quote // turn <br> or <br /> into \n
$txt = preg_replace( '!\s*<br(\s*/)?>\s*!i', "\n", $txt);

// turn <p ...> and <p> into \n\n
$txt = preg_replace( '/\s*<p([^>]+|)>\s*/i', "\n\n", $txt);

// mercilessly strip all other html
$txt = preg_replace( '/<[^>]+>/', '', $txt);
$txt = preg_replace( '!</[a-z]+>!i', '', $txt);

// turn \n back to <br />
$txt = str_replace( "\n", '<br />', trim( $txt));

return addslashes($txt);
}

?>
Title: Re: Tip: script to automate posting in 1.1
Post by: pctwo on September 29, 2006, 01:47:00 AM
my regex threw the syntax highlighter off.  However, I ran it through php and it found no error.  I tested the script.  It works.
Title: Re: Tip: script to automate posting in 1.1
Post by: motumbo on October 08, 2006, 04:59:15 AM
I wanted the ability to do automated posts (I have informational posts stickied at the tops of forum categories and I didn't want to do it by hand) but couldn't find a way to do it.

So what I did is wrote an external PHP script to take the data I already had in a MySQL database and format it into INSERT queries that I imported into my SMF forum using phpMyAdmin.  That allowed me to "automate" my posts.

Title: Re: Tip: script to automate posting in 1.1
Post by: tattooedpierre on October 17, 2006, 12:35:36 PM
Can anyone help me extend this script? I'm looking to either; use a similair method to create a posting from a form (completed by an already logged in user), or to create a posting for a user but not submit .. ie: pre-filled fields but not actually posted. I know there is a mod kicking around to do this, but I hoped it could be done via SSI, similair to what happens here.
Title: Re: Tip: script to automate posting in 1.1
Post by: floppy01 on March 04, 2007, 12:59:41 PM
Hi!

Many thanks for you input regarding how to create a posting functionality. But there is still one question left for me. Ive tried to implement it almost the same way you did, but when I try to submit the form, i get 1 error saying:

Notice: notifyMembersBoard(): Can't send a notification without a board id! in ../smf/Sources/Post.php on line 1896

But the board id is stated :/ as shown by you.

Could anyone help me to solve this? As I really need the notification feature.

Many thanks in advance!

floppy
Title: Re: Tip: script to automate posting in 1.1
Post by: twistedsymphony on March 09, 2007, 02:12:34 PM
WOW!!!

Thank you, I've been looking for exactly this functionality for some time now.

I have 1 question and 1 comment.

The comment I have is about your HMTLized clean up... if the user is admin you can use [ html ][ /html ] tags on either end of the content and it will render your HTML for you...  but this only works for admins (anytime) or if you allow HTML in your forums. AFAIK it's a newer feature of SMF.

I would think you'd rather use this because it allows me to use things like blockquotes iframes and object tags. since this script is posting from an HTML source one would assume you'd trust that same source to not to inject malicious code in it :) Not to mention it's all inclusive instead of trying to script the conversion of all kinds of HTML tags....

I can't wait to try this out and see if it works with the rest of my integration... this is the  last piece I needed in my puzzle.

The question I have is I was wondering if you could use the SMF API instead of SSI.php... the only reason I ask this is because the application I'm integrating with has some function names that are the same as SMF (the first one it crashes on is is_admin()) and it spews error messages whenever I try to include it... while I haven't tried the SMF API yet I've seen others use it with the same system as me to some success.

Thanks again!
Title: Re: Tip: script to automate posting in 1.1
Post by: yort124 on March 15, 2007, 02:07:32 PM
This might be a stupid question...but where do I put this at?
Title: Re: Tip: script to automate posting in 1.1
Post by: twistedsymphony on March 16, 2007, 02:54:39 PM
@floppy01... I found a solution to your problem... I tested this script as-is and had some great success... then I added a bunch of code of my own and tried running it again only to hit the same errors you were... I was scratching my head but then looking at the source code for post.php I realized $board is a global variable.

you can't change the name of the variable $board... it's a bit screwy but you must leave that variable name as is... just to be on the save side I'd leave the other variables like $ID_MEMBER the same as well... set them to whatever you want just don't change them.

@yort124
you put this where ever you want to put the intent of this code is to auto-magically create a new topic in SMF from some other application running on the same server.

So for instance my use is I'm linking this up to my WordPress front end. I've created a WordPress plugin using this code so when I create a new topic in WordPress it will set the variables at the top for my message, subject, user, and board and then run the rest of the code to create a matching topic in SMF.

There are alot of other complex things going on in my code but that's the gist of it.

if you copy paste this code into a .php file on the same server... make sure the path to ssi.php is correct and then call the page in a browser it will create a new topic in board #2 called "you're ok"

it's really quite nifty.
Title: Re: Tip: script to automate posting in 1.1
Post by: floppy01 on April 11, 2007, 06:33:00 PM
@twistedsymphony

Hi! Thank you for you comment. But I am not sure wether i got you right. What do you mean by  leaving the name of the variable $board the same. I didn't change it. I used almost the same code as stated but when it comes to the notifymembersboard() function an error occurs. Could you please explain to me how I could correctly call this function or what you have done differently then me.
You can read what i've done in this thread: http://www.simplemachines.org/community/index.php?topic=148074.0
Thank you very much in advance!
floppy
Title: Re: Tip: script to automate posting in 1.1
Post by: rockinaway on April 17, 2007, 03:35:06 PM
Not working for me..
Title: Re: Tip: script to automate posting in 1.1
Post by: Zeshin on July 29, 2007, 12:14:08 AM
Hey guys, I know this topic hasn't been posted in for a while, but it kind of pertains to what I need help with. I've followed all the advice given in this topic and several other topics and I'm still getting the same error.

This is sort of what I'm trying to put together: I have a Medieval Fantasy based RP Forum. It's somewhat like DnD. I'm trying to make a character sheet page and when the user is completely finished filling out their character sheet, it can be posted as a new topic into a board and is then reviewed. Anyway, I'm stuck on that part - the posting. I'm trying to do this all from Profile.php

Here's my code:

require_once($sourcedir . '/Subs-Post.php');
require_once($sourcedir . '/Post.php');

$topic = 0;
$subject = $_POST['fullname'];
$username = $context['user']['name'];
$board = 34;

$msgSubject = addslashes($subject); //the title is our topic

//here we prepare the message itself by adding the download link
$msgBody = $body;

$msgBody = prepBody($msgBody); //get rid of html tags in favor of smf tags

$msgOptions = array(
'id' => 0, // set id to modify
'subject' => $msgSubject,
'body' => $msgBody,
'icon' => 'xx', // look at smf_message_icons table to see all possible values
'smileys_enabled' => 1,
'attachments' => empty($attachIDs) ? array() : $attachIDs,
);

$topicOptions = array(
'id' => empty($topic) ? 0 : $topic,
'board' => $board,
'poll' => null,
'lock_mode' => 0,
'sticky_mode' => null,
'mark_as_read' => true,
);

$posterOptions = array(
'id' => $ID_MEMBER,
'name' => 'some name',
'email' => '[email protected]',
'update_post_count' => 1
);

$newTopic = empty($topic) || $topic == 0;

createPost($msgOptions, $topicOptions, $posterOptions);


And here is the syntax error that I'm getting:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' SUBSTRING('This is the subject!', 1, 255), SUBSTRING('Human', 1, 65534), SUBSTR' at line 4
File: /home/hiddenre/public_html/development/Sources/Subs-Post.php
Line: 1535


Any help would be much appreciated. I'm not too great at PHP myself, just really getting tired of being stuck on this for a couple days now. >.<
Title: Re: Tip: script to automate posting in 1.1
Post by: elfishtroll on August 05, 2007, 07:58:55 PM
QuoteYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' SUBSTRING('This is the subject!', 1, 255), SUBSTRING('Human', 1, 65534), SUBSTR' at line 4
File: /home/hiddenre/public_html/development/Sources/Subs-Post.php
Line: 1535



You seem to have a post SUBJECT
Quote$topic = 0;
$subject = $_POST['fullname'];
$username = $context['user']['name'];

...but I'm not sure where you get the $msgbody from. If you havent initialized it somewhere then it will be null and may be the source of an error when you try to execute a query with it.

If your msgbody is being initialized properly (within code you did not include in your post) then perhaps you did not escape the data properly?
Title: Re: Tip: script to automate posting in 1.1
Post by: rockinaway on August 14, 2007, 01:11:51 AM
I took this script and enhanced it to work very well at http://www.wickettowicket.com/

Take a look, it works for both topics and posts...
Title: Re: Tip: script to automate posting in 1.1
Post by: elfishtroll on August 14, 2007, 01:20:44 AM
Quote from: rockinaway on August 14, 2007, 01:11:51 AM
I took this script and enhanced it to work very well at http://www.whogivesaratsass.com/

Take a look, it works for both topics and posts...

^ did you really?

wow.
Title: Re: Tip: script to automate posting in 1.1
Post by: husmen73 (Gulhin) on September 03, 2007, 10:22:25 AM
its working but I want to work as like form. Such us someone write yourselft on any form mail section. while creating new post, must be write his name on automatic creating post. (like form mail)

I have did a form, its posting to this code page but member name showing as Guest
Title: Re: Tip: script to automate posting in 1.1
Post by: dakotaroar on November 14, 2007, 10:17:36 AM
I've just started playing with this, but it seems like the member id is coming from the SMF cookie (if it gets included with SSI.php).  I tested this script while logged out, and it posted with the 'some.name
in the array; after I logged in I tested it again and it posted as 'root' (my name for my test install).

Curious, but a very very useful thing!

EDIT:  I was mistaken, it seems that the 'root' actually was user ID 5.  This makes sense now.
Title: Re: Tip: script to automate posting in 1.1
Post by: Wookie on February 20, 2008, 12:48:03 PM
Would anyone be able to help me with running a query to insert the results into the msgBody?

I've tried echoing and includes and am getting nowhere fast, I want to post the results of a query as a new topic, and also insert the Date into the msgSubject.

Many thanks in advance!

Wookie
Title: Re: Tip: script to automate posting in 1.1
Post by: Wookie on February 22, 2008, 09:42:44 AM
Can anyone help please?

Wookie
Title: Re: Tip: script to automate posting in 1.1
Post by: dakotaroar on February 22, 2008, 09:55:03 AM
This example might get you started:

$query = mysql_query("SELECT * FROM smf.smf_messages WHERE ID_TOPIC = '$SMFTopic' ORDER BY ID_MSG") or die("Error: ".mysql_error());
while($smffetch=mysql_fetch_array($query))
{ //Loop through each message.
          $smfmessageID=$smffetch["ID_MSG"];
          $smftopicID=$smffetch["ID_TOPIC"];
$smftime=$smffetch['posterTime'];
$time = date("l, jS F Y ¥a¥¥t g:i a", $smftime);
          $smfsubject=$smffetch["subject"];
          $smfbody=parse_bbc($smffetch["body"]);
          $smfauthorID=$smffetch["ID_MEMBER"];
$smfpostername = $smffetch["posterName"];
}


Then take the variable you need and put it in msgSubject.  The query above is looking for individual messages, so it looks up the messages table (your database name will vary) and assigns variables values according to the column names in the messages table (ID_MSG, ID_TOPIC, etc.).  You can use this for doing any query you want, and coupled with the posting script above, will make a new topic in the board you designate.
Title: Re: Tip: script to automate posting in 1.1
Post by: Wookie on February 22, 2008, 10:13:50 AM
Thanks mburtonk, will have a play with this code later tonight...looks good and gives me another avenue to expore. Will post back with results.

Wookie

PS> I wonder if anyone ever fixed the last part of this script? The part that is the topic starter area is all black and and has "?>" in it.

Wookie
Title: Re: Tip: script to automate posting in 1.1
Post by: dakotaroar on February 22, 2008, 10:40:07 PM
I'm posting this script here so people can understand what is going on--Some lines will need to be changed to get it to work on your system, but hopefully the comments are decent.  I threw it together quickly, so things might not be in exactly the right place for easiest reading.

<?php//These three files are needed for this script to work--adjust the path to suit your installation, a URL will not work.require_once('/Users/Matt/Sites/SMF1.1.4/SSI.php');require_once('/Users/Matt/Sites/SMF1.1.4/Sources/Post.php');require_once('/Users/Matt/Sites/SMF1.1.4/Sources/Subs-Post.php');//Example query--getting info about a member from the database.  You can replace this with your own query and variables.$name = 'Wookie';  //The value we are looking for in the query.$query = mysql_query("SELECT * FROM smf114.smf_members WHERE memberName = '$name'") or die("Error: ".mysql_error()); //Replace 'smf114' with your database name and 'smf_' with your table prefix.while($smffetch=mysql_fetch_array($query)) { //Loop through each record, even though there is only one. $memberid = $smffetch["ID_MEMBER"];  //Put the value in the ID_MEMBER column into a variable. $registerdate= $smffetch["dateRegistered"];  //Put the value in the dateRegistered column into a variable. }$query_results = $memberid . '<br>' . $registerdate; //This just builds your message body with the variables you created and a line break to separate them.$date = $context['current_time']; //Getting the current date and time.$board = '6';  //The board to which you want to post.$msgSubject = $date;  //The subject of the topic.  This is where the date will go. $msgBody = $query_results;  //Puts the query results into the message body.//Not much of this is changed from the original script. $msgOptions = array( 'id' => 0, // set id to modify 'subject' => $msgSubject, 'body' => $msgBody, 'icon' => 'xx', // look at smf_message_icons table to see all possible values 'smileys_enabled' => 1, 'attachments' => empty($attachIDs) ? array() : $attachIDs, ); $topicOptions = array( 'id' => empty($topic) ? 0 : $topic, 'board' => $board, 'poll' => null, 'lock_mode' => 0, 'sticky_mode' => null, 'mark_as_read' => true, ); $posterOptions = array( 'id' => $ID_MEMBER,  //User ID of the member whose name you want on the posts. 'name' => 'Mr. Roboto',  //The name you want associated if the user ID does not exist. 'email' => '[email protected]',  //Email associated with the above name. 'update_post_count' => 1 //This adds to the user's post count. ); $newTopic = empty($topic) || $topic == 0;  //Creates a new topic. createPost($msgOptions, $topicOptions, $posterOptions);  //Actually creates the post and topic.//The following is from the original script.  Makes sure the board stays up and knows what just happened to it. if (isset($topicOptions['id'])) $topic = $topicOptions['id']; if ($newTopic) notifyMembersBoard(); else sendNotifications($topic, 'reply'); ?>
Title: Re: Tip: script to automate posting in 1.1
Post by: Wookie on February 26, 2008, 06:21:38 AM
I'm getting the following error on two different domains: a test board and a live one

Error: SELECT command denied to user 'user'@'localhost' for table 'smf_members'

Full privelidges exist for user via control panel at host on both domains, and script is being run from forum root. Minimal changes made to the above script, eg paths are changed, boardid etc.

Anyone anyideas why I would get this error as its normally associated with incorrect user permission to the database, and these have been checked numerous times at two different domains I've tried to run the script on.

Wookie
Title: Re: Tip: script to automate posting in 1.1
Post by: dakotaroar on February 26, 2008, 08:54:24 AM
I have gotten that error before when I have had the name of the database wrong, e.g.,

SELECT * FROM smf114.smf_members WHERE memberName = '$name'

The bolded bit is the name of your SMF database.
Title: Re: Tip: script to automate posting in 1.1
Post by: Wookie on February 26, 2008, 10:08:26 AM
I've now made a fresh install of smf and I'm now getting a new error.

Warning: Invalid argument supplied for foreach() in /home/~/public_html/f/Sources/Subs-Post.php on line 2005

Which refers to this in subs-post php...

// Ignore any parents on the top child level.
foreach ($parents as $id => $parent)     // <-- Line 2005
{
if ($parent['level'] == 0)
unset($parent[$id]);
else


Tis strange to get so many errors on 3 installs now on two domains.

Wookie
Title: Re: Tip: script to automate posting in 1.1
Post by: dakotaroar on February 26, 2008, 10:34:37 AM
I *cough* ignored that warning, as the script seemed to work for me and posted the topic.  I should have warned you (ha. ha.) about that.

I'm wondering whether this might be the offending clause:

{
foreach ($setboards as $ID_BOARD)
$lastMsg[$ID_BOARD] = $ID_MSG;
}


I don't know how to fix it though.
Title: Re: Tip: script to automate posting in 1.1
Post by: Wookie on February 26, 2008, 10:55:13 AM
Yup, indeed it does work. Just took a minute to go and see the post instead of just sitting here looking at an error page.

Would be good to fix the error, so if anyone else can shed any light on this subject I would be very gratful.

Thank you mburtonk, for sticking with me on this and offering the help above and beyond (and via email too!)

Wookie
Title: Re: Tip: script to automate posting in 1.1
Post by: Wookie on March 06, 2008, 12:29:21 PM
So this code now produces one result from a database table, how would one extend this script to include 40 or so results?

Would I need to use foreach to achieve that? Can anyone start me off?

Manyy thanks

Wookie
Title: Re: Tip: script to automate posting in 1.1
Post by: Wookie on March 07, 2008, 05:56:29 AM
Can anyone point me in the right direction?

Many thanks.

Wookie
Title: Re: Tip: script to automate posting in 1.1
Post by: dakotaroar on March 07, 2008, 10:49:00 AM
I'm not sure what you are asking.  Do you mean

-40 results from the same query in the same post,
-40 results from different queries in the same post, or
-40 posts with the same query?

This script will do the first, if the query returns multiple rows.
For the second, you have to code in each query manually.
For the third, you need to set up a for loop and pass the right variable each time (unless you want 40 of the same post).
Title: Re: Tip: script to automate posting in 1.1
Post by: Wookie on March 07, 2008, 01:01:33 PM
The first option "-40 results from the same query in the same post"

I just have no idea how to implement itm although I have a feeling its to do with $rows or $rowsets ...and I also thought using foreach...but more than likely wrong in that.

Many thanks!

Wookie
Title: Re: Tip: script to automate posting in 1.1
Post by: dakotaroar on March 07, 2008, 02:04:01 PM
It's already in there:

while($smffetch=mysql_fetch_array($query))
{ //Loop through each record, even though there is only one.
$memberid = $smffetch["ID_MEMBER"];  //Put the value in the ID_MEMBER column into a variable.
$registerdate= $smffetch["dateRegistered"];  //Put the value in the dateRegistered column into a variable.
}


The example query searches by membername, so you only get one result.  If you run a query that gets multiple results (say, messages that match a topic ID), you would get it looping through each.  I think the code below will work (if you change your query and your variables).  It should take $query_results and keep tacking more on to the end of the variable (with a ':  ' between the two in the example and a '<br>' between different sets).


while($smffetch=mysql_fetch_array($query))
{ //Loop through each record, even though there is only one.
$memberid = $smffetch["ID_MEMBER"];  //Put the value in the ID_MEMBER column into a variable.
$registerdate= $smffetch["dateRegistered"];  //Put the value in the dateRegistered column into a variable.
                $query_results=$query_results . '<br>' . $memberid . ':  ' . $registerdate
}

$date = $context['current_time']; //Getting the current date and time.
$board = '6';  //The board to which you want to post.
$msgSubject = $date;  //The subject of the topic.  This is where the date will go.
$msgBody = $query_results;  //Puts the query results into the message body.

Title: Re: Tip: script to automate posting in 1.1
Post by: Wookie on March 08, 2008, 12:32:07 PM
Still struggling to get this working, here is the complete script complete with dakotaroar's addition..(many thanks for trying to help me!)


<?php//These three files are needed for this script to work--adjust the path to suit your installation, a URL will not work.require_once('/home/stev1965/public_html/foru/SSI.php');require_once('/home/stev1965/public_html/foru/Sources/Post.php');require_once('/home/stev1965/public_html/foru/Sources/Subs-Post.php');//Example query--getting info about a member from the database.  You can replace this with your own query and variables.//$name = '0';  //The value we are looking for in the query.$query = mysql_query("SELECT cpmsubtitle FROM stev1965_smf14.cpg14x_potdp WHERE position = 0") or die("Error: ".mysql_error());while($smffetch=mysql_fetch_array($query)) { //Loop through each record, even though there is only one. $memberid = $smffetch["cpmsubtitle"];  //Put the value in the ID_MEMBER column into a variable. $registerdate= $smffetch["title"];  //Put the value in the dateRegistered column into a variable.                $query_results=$query_results . '<br>' . $memberid . ':  ' . $registerdate; }$query_results = $memberid . '<br>' . $registerdate; //This just builds your message body with the variables you created and a line break to separate them.$date = date("F j, Y"); //Getting the current date and time.$board = '5';  //The board to which you want to post.$msgSubject = $date;  //The subject of the topic.  This is where the date will go. $msgBody =  $query_results;  //Puts the query results into the message body.//Not much of this is changed from the original script. $msgOptions = array( 'id' => 0, // set id to modify 'subject' => $msgSubject, 'body' => $msgBody, 'icon' => 'xx', // look at smf_message_icons table to see all possible values 'smileys_enabled' => 1, 'attachments' => empty($attachIDs) ? array() : $attachIDs, ); $topicOptions = array( 'id' => empty($topic) ? 0 : $topic, 'board' => $board, 'poll' => null, 'lock_mode' => 0, 'sticky_mode' => null, 'mark_as_read' => true, ); $posterOptions = array( 'id' => $ID_MEMBER,  //User ID of the member whose name you want on the posts. 'name' => 'Mr. Roboto',  //The name you want associated if the user ID does not exist. 'email' => '[email protected]',  //Email associated with the above name. 'update_post_count' => 1 //This adds to the user's post count. ); $newTopic = empty($topic) || $topic == 0;  //Creates a new topic. createPost($msgOptions, $topicOptions, $posterOptions);  //Actually creates the post and topic.//The following is from the original script.  Makes sure the board stays up and knows what just happened to it. if (isset($topicOptions['id'])) $topic = $topicOptions['id']; if ($newTopic) notifyMembersBoard(); else sendNotifications($topic, 'reply'); ?>


Its still just giving me one result, in the table there are around 40 results and nearly all are positon = 0, these are what I would like to show in the post. Can anyone help?

Many thanks!

Wookie
Title: Re: Tip: script to automate posting in 1.1
Post by: rockinaway on March 21, 2008, 06:55:47 AM
<?php//These three files are needed for this script to work--adjust the path to suit your installation, a URL will not work.require_once('/home/stev1965/public_html/foru/SSI.php');require_once('/home/stev1965/public_html/foru/Sources/Post.php');require_once('/home/stev1965/public_html/foru/Sources/Subs-Post.php');//Example query--getting info about a member from the database.  You can replace this with your own query and variables.//$name = '0';  //The value we are looking for in the query.$query = mysql_query("SELECT cpmsubtitle FROM stev1965_smf14.cpg14x_potdp WHERE position = 0") or die("Error: ".mysql_error());$query_results = '';while($smffetch=mysql_fetch_assoc($query)){//Loop through each record, even though there is only one.$memberid = $smffetch["cpmsubtitle"];  //Put the value in the ID_MEMBER column into a variable.$registerdate= $smffetch["title"];  //Put the value in the dateRegistered column into a variable.                $query_results .= '<br>' . $memberid . ':  ' . $registerdate; }$date = date("F j, Y"); //Getting the current date and time.$board = '5';  //The board to which you want to post.$msgSubject = $date;  //The subject of the topic.  This is where the date will go.$msgBody =  $query_results;  //Puts the query results into the message body.//Not much of this is changed from the original script.$msgOptions = array('id' => 0, // set id to modify'subject' => $msgSubject,'body' => $msgBody,'icon' => 'xx', // look at smf_message_icons table to see all possible values'smileys_enabled' => 1, 'attachments' => empty($attachIDs) ? array() : $attachIDs,);$topicOptions = array('id' => empty($topic) ? 0 : $topic,'board' => $board,'poll' => null,'lock_mode' => 0,'sticky_mode' => null,'mark_as_read' => true,);$posterOptions = array('id' => $ID_MEMBER,  //User ID of the member whose name you want on the posts.'name' => 'Mr. Roboto',  //The name you want associated if the user ID does not exist.'email' => '[email protected]',  //Email associated with the above name.'update_post_count' => 1 //This adds to the user's post count.);$newTopic = empty($topic) || $topic == 0;  //Creates a new topic.createPost($msgOptions, $topicOptions, $posterOptions);  //Actually creates the post and topic.//The following is from the original script.  Makes sure the board stays up and knows what just happened to it.if (isset($topicOptions['id']))$topic = $topicOptions['id'];if ($newTopic)notifyMembersBoard();elsesendNotifications($topic, 'reply');?>


Replace the old code with this, see if it helps :)
Title: Re: Tip: script to automate posting in 1.1
Post by: gimmoroy on September 24, 2009, 03:21:12 PM
What should be done to script to use it with SMF 2.0 RC1.2 ?
Is it possible at all?
Title: Re: Tip: script to automate posting in 1.1
Post by: liamgibbins on April 23, 2013, 03:38:00 AM
I hope this is still active....

If ran by itself it posts the sample to the forum... great but I want to post:

$msgBody =  "Staging System: " .$_POST['system'] . "<br />"."<br />"."<br />"." FC: ".$_POST['fcname']. "<br />"."<br />" ."Op Type: ". $_POST['selecttype']."<br /> " . "Date: ".$_POST['date']. "<br />"."<br />" ." SRP: ".$_POST['srp']. "<br />"."<br />" ."  Cycle: ".$_POST['cycle']. "<br />"."<br />" ." Planet:: ".$_POST['planet']. "<br />"."<br />" ." Moon: ".$_POST['moon']. "<br />"."<br />" ." Description: ".$_POST['description'];

These values are taken straight from a form but when ran it gives me a white page.
all i altered as I require this to be passed to the board..

any ideas how to fix this?
Title: Re: Tip: script to automate posting in 1.1
Post by: liamgibbins on April 23, 2013, 05:32:32 AM
Think I figured it out..

I had the form and the parsing script in one file..

you need to parse the form and use the original post from external site script in a separate file for it to work for some reason.. well its working now so it must be that.. lol no idea..