Jump to content

Automating new post at forum, using SQL


wookie

Recommended Posts

I'm trying to run this automated script that posts a new topic to a forum, using info gained via an sql query. The part of this script that actually posts at the forum is "test" from this line "$msgBody =  'test';" How do I add the following query so that the results are posted instead of "test"? Here's the query..

 

$result = mysql_query("SELECT * FROM smf_messages

WHERE ID_BOARD='1'");

while($row = mysql_fetch_array($result))

  {

 

<?php

include_once('/absolute path/SSI.php');
require_once($sourcedir . '/Post.php');
require_once($sourcedir . '/Subs-Post.php');


// comment out below line to run in shell
if (!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 = 1; // set to valid board id

$ID_MEMBER = 1;

$_POST['subject'] = 'you\'re okay';  // the notify function uses this

$msgSubject = addslashes($_POST['subject']);

$msgBody =  'test';

$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);
}

?>

 

Many thanks in advance!

 

Wookie

Link to comment
https://forums.phpfreaks.com/topic/92223-automating-new-post-at-forum-using-sql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.