Hi all - I was hoping someone could help.
I've created a php script that successfully uses preg_match_all/regex to scrape a forum. It parses the content into an array that I wish to create a node from.
The node type I have chosen for this is the vote_storylink type as it already has the field types I want.

My problem is twofold I think. This is my first module ever so I may have got some stuff wrong, however I think I've covered the bases by creating an info file that gets read into Drupal and the module itself appears to run until I get an unexpected T variable error from the Drupal site stating the problem is with the globals $user; statement. Ripping out the Drupal stuff and going back to the standalone php script resolves the error so I have made an error there. It's possibly the way variables get dealt with in functions but I'm not sure.

The module should only work when cron is used so I've only used hook_cron. Is that right?

This is the area where is all goes pear shaped - if I comment out the section globals to drupal execute and uncomment what is already done, the script works. :

foreach ($posts as $post) 					{
		$characterlastposts = $post[1];
		$charactericon = $post[2];
		$charactername = $post[3];
		$postdate = $post[4];
		$linktothread = $post[5];
		$postcontent = $post[6];
		global $forumurl;
//		echo "characterlastposts " . $characterlastposts . "<br />";
//		echo "charactericon " . $charactericon . "<br />";
//		echo "charactername " . $charactername . "<br />";
//		echo "postdate " . $postdate . "<br />";
//		echo "linktothread " . $linktothread . "<br />";
//		echo "postcontent " . $postcontent . "<br />";
//		echo "<a href=" . $forumurl . $characterlastposts . "><img src=" . $charactericon . " alt=" . $charactername . "</a>";
		globals $user;
		$user = user_load(array(uid => 1));
		$form_id = 'vote_storylink_node_form';
		$node = array('type' => 'vote_storylink');
		$form_values = array(
		'title' => $linktothread,
		'body' => $postcontent,
		'URL' => $forumurl . $linktothread,
		'name' => $user->name,
		);
		drupal_execute($form_id, $field_values, $form_values);
		}
	}

Also, I have called this module forumscraper with the idea cron will "activate" it so I've used the following hook into it:

function forumscraper_cron() {
lot's of code like the stuff above
}

That's right isn't it?

Comments

Cromicon’s picture

Well, cron time came and went. The module didn't get hit by cron as far as I can tell yet other modules did.
I've searched for ways to get a module linked to cron to work ... not having much luck unless I have hit on the right method and just missed a step somewhere...

Cromicon’s picture

Sussed that one. Cron didn't hit it because I'd spelled the cron hook name wrong.

However I'm still having difficulty in inserting the parsed content into the relevant node type as an error complains the $form_id isn't correct:

globals $user;
$user = user_load(array(uid => 1));
$form_id = 'vote_storylink_node_form';
$node = array('type' => 'vote_storylink');
$form_values = array(
'title' => $linktothread,
'body' => $postcontent,
'URL' => $forumurl . $linktothread,
'name' => $user->name,
);
drupal_execute($form_id, $form_values, $form_values);
Cromicon’s picture

Ok I think I've sorted the $form_id (storylink) but it looks like I'm using the completely wrong method to do this as I get this:
First argument is expected to be a valid callback, 'storylink' was given in /xxxx/public_html/includes/form.inc on line 218.', 2,

Does anyone have any advice?

steve.neill’s picture

I'm also dealing with exactly the same issue. Any resolution yet?

Thanks

Steve