Posted by nbchip on October 19, 2008 at 2:25pm
Jump to:
| Project: | phpbbPostNode |
| Version: | 5.x-1.2 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
I had problems with tmpfile.tmp file... the path had to be changed for curl to 'htdocs/tmpfile.tmp' and for php to $content=file_get_contents('../tmpfile.tmp');
Also modules doesnt use allias path when posting link at original node to forum... and even the normal path node/xxx is only written after u submit, edit and submit again... cause $nid is unknown at first submit, i guess...
Comments
#1
What lines in the .module file did you have to change?
I've seen the need to post twice, but that is normally because the cookie is holding an older sessionID and needs a fresh one to submit the topic. The alias works correctly on my test invironment, and on my production sites. Can you tell what isn't working?
#2
Curl writes the cookie after u call curl_close.... So in Function phpbbPostNodelogin before
$content=file_get_contents('../tmpfile.tmp');line 327 u should callcurl_close($this->curl);and then ull get new $sidI also had to change paths to cookie... line 327 and line 51
Still i dont get link to node , all i get is
www.site-name.com/node/, i will look at this problem after i rewrite curl class so it works with phpbb3....Using 5.7 with xampp
#3
This are the Login and Post Functions that work for my PHPBB3 , but still there are no $nid on Submit and no link back to original node...
function phpbbPostNodelogin($username, $password) {
//global $_SERVER;
// Generate post string
$post_fields = $this->array_to_http(array(
'username' => $username,
'password' => $password,
//'autologin' => 1,
'redirect' => 'index.php',
'login' => 'Login',
));
// Init curl
$this->curl = curl_init();
// Set options
curl_setopt($this->curl, CURLOPT_URL, $this->phpbb_url .'ucp.php?mode=login');
curl_setopt($this->curl, CURLOPT_POST, true);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curl, CURLOPT_HEADER, false);
curl_setopt($this->curl, CURLOPT_COOKIE, $this->cookie_name);
curl_setopt($this->curl, CURLOPT_COOKIEJAR, $this->cookie_name);
curl_setopt($this->curl, CURLOPT_COOKIEFILE, $this->cookie_name);
curl_setopt($this->curl, CURLOPT_USERAGENT, 'HTTP_USER_AGENT');
//curl_setopt($this->curl, CURLOPT_PROXY, '127.0.0.1:8888');
// Execute request
$result = curl_exec($this->curl);
// Error handling
if (curl_errno($this->curl)) {
$this->error = array(
curl_errno($this->curl),
curl_error($this->curl),
);
curl_close($this->curl);
return false;
}
// Close connection
curl_close($this->curl);
// Set Session ID
$content=file_get_contents('../tmpfile.tmp');
preg_match('/phpbb3_m8j8i_sid/', $content, $matches, PREG_OFFSET_CAPTURE);
$offset = $matches[0][1] + strlen($matches[0][0]) + 1;
$this->sid = substr($content, $offset, 32);
// Close connection
//curl_close($this->curl);
// Return result
return true;
}
/*
* @ Function : new_topic() - New Topic
* @ About : Remotely posts a topic to the target phpBB forum.
* @ Type : Public
*/
function phpbbPostNodeNewtopic($forum_id, $message, $topic_title) {
//global $_SERVER;
//tomislav: get form stuff
$this->curl = curl_init();
curl_setopt($this->curl, CURLOPT_URL, $this->phpbb_url . 'posting.php?mode=post&f='.$forum_id);
curl_setopt($this->curl, CURLOPT_USERAGENT, 'HTTP_USER_AGENT');
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curl, CURLOPT_COOKIEJAR, $this->cookie_name);
curl_setopt($this->curl, CURLOPT_COOKIEFILE, $this->cookie_name);
curl_setopt($this->curl, CURLOPT_HEADER, false);
//curl_setopt($this->curl, CURLOPT_PROXY, '127.0.0.1:8888');
$curlresult=curl_exec($this->curl);
sleep(1);
preg_match ('|<input type="hidden" name="lastclick" value="(.*)" />|U', $curlresult, $click);
$lastclick=$click['1'];
//preg_match ('|<input type="hidden" name="creation_time" value="(.*)" />|U', $curlresult, $creation);
$creation_time=$click['1'];
preg_match ('|<input type="hidden" name="form_token" value="(.*)" />|U', $curlresult, $token);
$form_token=$token['1'];
// Generate post string
$post_fields = array(
'icon' => 0,
'subject' => $topic_title,
'addbbcode20' => 100,
'message' => $message,
'lastclick' => $lastclick,
'post' => 'Submit',
'attach_sig' => 'on',
'topic_type' => 0,
'topic_time_limit' => 0,
'creation_time' => $creation_time,
'form_token' => $form_token,
'fileupload' => '',
'filecomment' => '',
'poll_title' => '',
'poll_option_text' => '',
'poll_max_options' => '1',
'poll_length' => '0',
);
// Location
$url_vars = $this->array_to_http(array(
'mode' => 'post',
'f' => $forum_id,
'sid' => $this->sid,
));
// Init curl
//$this->curl = curl_init();
// Set options
curl_setopt($this->curl, CURLOPT_URL, $this->phpbb_url .'posting.php?'. $url_vars);
//curl_setopt($this->curl, CURLOPT_POST, true);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curl, CURLOPT_HEADER, false);
curl_setopt($this->curl, CURLOPT_COOKIE, $this->cookie_name);
curl_setopt($this->curl, CURLOPT_COOKIEJAR, $this->cookie_name);
curl_setopt($this->curl, CURLOPT_COOKIEFILE, $this->cookie_name);
curl_setopt($this->curl, CURLOPT_USERAGENT, 'HTTP_USER_AGENT' );
//curl_setopt($this->curl, CURLOPT_PROXY, '127.0.0.1:8888');
// Execute request
$result = curl_exec($this->curl);
// Get the Topic ID to Return to the requestee
preg_match ('/viewtopic\.php\?f='.$forum_id.'&t=(?<tID>.*)"/', $result, $postid);
//preg_match('/viewtopic.php\?f=/', $result, $match, PREG_OFFSET_CAPTURE);
//$offset = $match[0][1] + strlen($match[0][0]);
//$maxTopics = substr($result, $offset, 12);
//preg_match('/=/', $maxTopics, $match, PREG_OFFSET_CAPTURE);
$tid = $postid['tID'];
//db_set_active('phpbb');
//$getTopic = db_query('SELECT `topic_id` FROM `phpbb_posts` WHERE post_id =%d', $postID);
//if ($nd = db_fetch_object($getTopic)) {
// $tid = $nd->topic_id;
//}
//Switch back to the default connection when finished.
//db_set_active('default');
// Get the result
//if (preg_match('#<td align="center"><span class="gen">Your message has been entered successfully.<br \/><br \/>#is', $result, $match)) {
$post_status = 1;
//}
//else if (preg_match('#<td align="center"><span class="gen">You cannot make another post so soon after your last; please try again in a short while.<\/span><\/td>>#is', $result, $match)) {
// $post_status = 0;
//}
//else {
// $post_status = 0;
//}
// Error handling
if (curl_errno($this->curl)) {
$this->error = array(
curl_errno($this->curl),
curl_error($this->curl),
);
curl_close($this->curl);
return false;
}
// Close connection
curl_close($this->curl);
// Return result
return $tid;
}
#4
Changing
switch ($op) { case 'submit':tocase 'insert':and using Global Redirect module , now everything looks fine with PHPBB3