| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
* Implementation of hook_help().
|
| 5 |
*/
|
| 6 |
function phpbbPostNode_help($section) {
|
| 7 |
switch ($section) {
|
| 8 |
case 'admin/help#phpbbPostNode':
|
| 9 |
$output = '<p>'. t('The phpbbPostNode module allows users to automatically add a post to an existing installation of phpbb') .'</p>';
|
| 10 |
$output .= '<p>'. t('Users with the "phpbbPostNode" permission can utilize this functionality. Three new form elements appear on node edit/create pages. One will be a checkbox to create the new topic, another is a teaser field, the other will be either the resultant topic ID nubmer, or if there is an existing topic you can enter that value there.') .'</p>';
|
| 11 |
return $output;
|
| 12 |
}
|
| 13 |
}
|
| 14 |
|
| 15 |
/**
|
| 16 |
* Implementation of hook_perm().
|
| 17 |
*/
|
| 18 |
function phpbbPostNode_perm() {
|
| 19 |
return array('access phpbb autopost functions');
|
| 20 |
}
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Implementation of hook_menu().
|
| 24 |
*/
|
| 25 |
function phpbbPostNode_menu($may_cache) {
|
| 26 |
$items = array();
|
| 27 |
|
| 28 |
if ($may_cache) {
|
| 29 |
$items[] = array(
|
| 30 |
'path' => 'admin/settings/phpbbPostNode',
|
| 31 |
'title' => t('phpbbPostPost module'),
|
| 32 |
'description' => t('Configuration options needed for allowing users to post to a phpbb installation.'),
|
| 33 |
'callback' => 'drupal_get_form',
|
| 34 |
'callback arguments' => 'phpbbPostNode_settings',
|
| 35 |
'access' => user_access('administer site configuration'),
|
| 36 |
);
|
| 37 |
}
|
| 38 |
return $items;
|
| 39 |
}
|
| 40 |
|
| 41 |
/**
|
| 42 |
* menu callback to configure module settings.
|
| 43 |
*/
|
| 44 |
function phpbbPostNode_settings() {
|
| 45 |
|
| 46 |
$form['heading'] = array(
|
| 47 |
'#value' => '<b>'.t('Configuration options for the phpbbPostNode module:').'</b>',
|
| 48 |
);
|
| 49 |
$form['phpbbPostNode_url'] = array(
|
| 50 |
'#type' => 'textfield',
|
| 51 |
'#title' => t('URL of phpbb index page'),
|
| 52 |
'#default_value' => variable_get('phpbbPostNode_url',''),
|
| 53 |
'#description' => t('The url of your existing phpbb installation'),
|
| 54 |
'#required' => TRUE,
|
| 55 |
'#weight' => -5
|
| 56 |
);
|
| 57 |
$form['phpbbPostNode_forumID'] = array(
|
| 58 |
'#type' => 'textfield',
|
| 59 |
'#title' => t('ID number of the forum'),
|
| 60 |
'#default_value' => variable_get('phpbbPostNode_forumID',''),
|
| 61 |
'#description' => t('The ID nubmer of the forum, the number given to the forum by phpbb'),
|
| 62 |
'#required' => TRUE,
|
| 63 |
'#weight' => -4
|
| 64 |
);
|
| 65 |
$form['phpbbPostNode_textPosted'] = array(
|
| 66 |
'#type' => 'textfield',
|
| 67 |
'#title' => t('Text posted to new topic'),
|
| 68 |
'#default_value' => variable_get('phpbbPostNode_textPosted',''),
|
| 69 |
'#description' => t('Text that is posted to the new forum topic before the "here" link'),
|
| 70 |
'#required' => TRUE,
|
| 71 |
'#weight' => -3
|
| 72 |
);
|
| 73 |
$form['phpbbPostNode_user'] = array(
|
| 74 |
'#type' => 'textfield',
|
| 75 |
'#title' => t('Login/Username'),
|
| 76 |
'#default_value' => variable_get('phpbbPostNode_user',''),
|
| 77 |
'#description' => t('The login of a uset that is allowed to post to your phpbb forum'),
|
| 78 |
'#required' => TRUE,
|
| 79 |
'#weight' => -2
|
| 80 |
);
|
| 81 |
$form['phpbbPostNode_pwd'] = array(
|
| 82 |
'#type' => 'password',
|
| 83 |
'#title' => t('Password'),
|
| 84 |
'#default_value' => variable_get('phpbbPostNode_pwd',''),
|
| 85 |
'#description' => t('The password of the above user'),
|
| 86 |
'#required' => TRUE,
|
| 87 |
'#weight' => 0
|
| 88 |
);
|
| 89 |
$form['phpbbPostNode_nodeType'] = array(
|
| 90 |
'#type' => 'textfield',
|
| 91 |
'#title' => t('Node Type'),
|
| 92 |
'#default_value' => variable_get('phpbbPostNode_nodeType',''),
|
| 93 |
'#description' => t('The type of node that you want to add this functionality to'),
|
| 94 |
'#required' => TRUE,
|
| 95 |
'#weight' => 0
|
| 96 |
);
|
| 97 |
|
| 98 |
return system_settings_form($form);
|
| 99 |
}
|
| 100 |
|
| 101 |
/**
|
| 102 |
* Implementation of hook_form_alter().
|
| 103 |
* Generate form elements for the phpbbPostNode Module
|
| 104 |
*/
|
| 105 |
function phpbbPostNode_form_alter($form_id, &$form) {
|
| 106 |
if (user_access('access phpbb autopost functions') && isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
|
| 107 |
$node = $form['#node'];
|
| 108 |
if ($node->type == variable_get('phpbbPostNode_nodeType','')) {
|
| 109 |
$form['phpbbPostNode_settings'] = array(
|
| 110 |
'#type' => 'fieldset',
|
| 111 |
'#title' => t('phpbbPostNode Forum Settings'),
|
| 112 |
'#collapsible' => TRUE,
|
| 113 |
'#collapsed' => TRUE,
|
| 114 |
'#weight' => 0,
|
| 115 |
);
|
| 116 |
$form['phpbbPostNode_settings']['phpbbPostNode_postToForum'] = array(
|
| 117 |
'#type' => 'checkbox',
|
| 118 |
'#title' => t('Add this node to my forum'),
|
| 119 |
'#default_value' => $node->phpbbPostNode_postToForum,
|
| 120 |
'#description' => t('Check this box to create a new forum topic, this topic will have a link that refers back to this page.'),
|
| 121 |
'#required' => FALSE,
|
| 122 |
'#weight' => -4,
|
| 123 |
);
|
| 124 |
$form['phpbbPostNode_settings']['phpbbPostNode_teaser'] = array(
|
| 125 |
'#type' => 'textfield',
|
| 126 |
'#title' => t('Teaser'),
|
| 127 |
'#default_value' => $node->phpbbPostNode_teaser,
|
| 128 |
'#size' => 128,
|
| 129 |
'#maxlength' => 128,
|
| 130 |
'#description' => t('Optionally specify a teaser that will be used when posting to the forum'),
|
| 131 |
'#weight' => -3,
|
| 132 |
);
|
| 133 |
$form['phpbbPostNode_settings']['phpbbPostNode_topic'] = array(
|
| 134 |
'#type' => 'textfield',
|
| 135 |
'#title' => t('Forum Topic Number'),
|
| 136 |
'#default_value' => $node->phpbbPostNode_topic,
|
| 137 |
'#size' => 10,
|
| 138 |
'#maxlength' => 9,
|
| 139 |
'#description' => t('Optionally specify the post number, if you check the above box this will be automatically filled in'),
|
| 140 |
'#weight' => -3,
|
| 141 |
);
|
| 142 |
}
|
| 143 |
}
|
| 144 |
}
|
| 145 |
|
| 146 |
/**
|
| 147 |
* Implementation of nodeapi().
|
| 148 |
*/
|
| 149 |
function phpbbPostNode_nodeapi(&$node, $op) {
|
| 150 |
global $base_url;
|
| 151 |
switch ($op) {
|
| 152 |
case 'submit':
|
| 153 |
if (($node->type == variable_get('phpbbPostNode_nodeType','')) && ($node->phpbbPostNode_postToForum)) {
|
| 154 |
$phpbb = new curl_phpbb(variable_get('phpbbPostNode_url',''));
|
| 155 |
|
| 156 |
// Log in
|
| 157 |
$phpbb->phpbbPostNodelogin(variable_get('phpbbPostNode_user',''), variable_get('phpbbPostNode_pwd',''));
|
| 158 |
|
| 159 |
// Post a topic
|
| 160 |
if ($node->phpbbPostNode_teaser) {
|
| 161 |
$body = $node->phpbbPostNode_teaser;
|
| 162 |
$body .= "\n\n";
|
| 163 |
}
|
| 164 |
$body .= variable_get('phpbbPostNode_textPosted','');
|
| 165 |
$body .= ' [url=';
|
| 166 |
$body .= $base_url;
|
| 167 |
if ($newAlias = drupal_lookup_path(alias, '/node/'.$node->nid)) {
|
| 168 |
$body .= $newAlias;
|
| 169 |
}
|
| 170 |
else $body .= '/node/'.$node->nid;
|
| 171 |
$body .= ']here[/url]';
|
| 172 |
$subject = $node->title;
|
| 173 |
$topic = $phpbb->phpbbPostNodeNewtopic(variable_get('phpbbPostNode_forumID',''), $body, $subject);
|
| 174 |
$node->phpbbPostNode_topic = $topic;
|
| 175 |
|
| 176 |
// Log out
|
| 177 |
$phpbb->phpbbPostNodelogout();
|
| 178 |
$node->phpbbPostNode_postToForum = 0;
|
| 179 |
}
|
| 180 |
$result = db_query("SELECT * FROM {phpbbPostNode} LEFT JOIN {node} USING(nid) WHERE {phpbbPostNode}.nid=%d", $node->nid);
|
| 181 |
if (!($oldnode = db_fetch_object($result))) {
|
| 182 |
if ($node->phpbbPostNode_teaser) {
|
| 183 |
db_query("INSERT INTO {phpbbPostNode} (nid, phpbbPostNode_topic, phpbbPostNode_teaser) VALUES(%d, %f, '%s')", $node->nid, $node->phpbbPostNode_topic, $node->phpbbPostNode_teaser);
|
| 184 |
}
|
| 185 |
else db_query("INSERT INTO {phpbbPostNode} (nid, phpbbPostNode_topic) VALUES(%d, %f)", $node->nid, $node->phpbbPostNode_topic);
|
| 186 |
}
|
| 187 |
else {
|
| 188 |
if (user_access('access phpbb autopost functions')) {
|
| 189 |
db_query("UPDATE {phpbbPostNode} SET phpbbPostNode_topic=%f, phpbbPostNode_teaser='%s' WHERE nid=%d", $node->phpbbPostNode_topic, $node->phpbbPostNode_teaser, $node->nid);
|
| 190 |
}
|
| 191 |
}
|
| 192 |
break;
|
| 193 |
case 'load':
|
| 194 |
if ($node->nid) {
|
| 195 |
$result = db_query("SELECT phpbbPostNode_topic, phpbbPostNode_teaser FROM {phpbbPostNode} WHERE nid=%d", $node->nid);
|
| 196 |
if ($nd = db_fetch_object($result)) {
|
| 197 |
$node->phpbbPostNode_topic = $nd->phpbbPostNode_topic;
|
| 198 |
$node->phpbbPostNode_teaser = $nd->phpbbPostNode_teaser;
|
| 199 |
}
|
| 200 |
}
|
| 201 |
break;
|
| 202 |
case 'delete':
|
| 203 |
db_query("DELETE FROM {phpbbPostNode} WHERE nid=%d", $node->nid);
|
| 204 |
break;
|
| 205 |
}
|
| 206 |
}
|
| 207 |
|
| 208 |
|
| 209 |
/*
|
| 210 |
* @ Program : phpBB CURL Library
|
| 211 |
* @ Author : Dean Newman, Afterlife(69)
|
| 212 |
* @ Purpose : Remote login and posting in phpBB
|
| 213 |
* @ Filename : curl_phpbb.class.php
|
| 214 |
* @ Class : curl_phpbb
|
| 215 |
* @ About : Function lib for login, posting and logout on remote phpbb's
|
| 216 |
* @ Licence : GNU/General Public Licence v2
|
| 217 |
* @ Created : 6/22/2006, 7:41pm
|
| 218 |
* @ Updated : 3/01/2007, 5:19pm
|
| 219 |
*/
|
| 220 |
|
| 221 |
/*
|
| 222 |
* @ Changelog
|
| 223 |
* @ 9/01/2006: Added ->read() functionality.
|
| 224 |
* @ 3/01/2007: Added ->Session ID functionality to work with new phpbb security--Matt Rice.
|
| 225 |
*/
|
| 226 |
|
| 227 |
class curl_phpbb
|
| 228 |
{
|
| 229 |
/*
|
| 230 |
* @ Variable : $curl (Resource)
|
| 231 |
* @ About : The cURL object used for the request
|
| 232 |
* @ Type : Private
|
| 233 |
*/
|
| 234 |
var $curl = null;
|
| 235 |
|
| 236 |
/*
|
| 237 |
* @ Variable : $cookie_name (String)
|
| 238 |
* @ About : The filename of the temp file used for storing cookies
|
| 239 |
* @ Type : Private
|
| 240 |
*/
|
| 241 |
var $cookie_name = array();
|
| 242 |
|
| 243 |
/*
|
| 244 |
* @ Variable : $phpbb_url (String)
|
| 245 |
* @ About : The address of the remote phpbb that is being connected to
|
| 246 |
* @ Type : Private
|
| 247 |
*/
|
| 248 |
var $phpbb_url = null;
|
| 249 |
|
| 250 |
/*
|
| 251 |
* @ Variable : $sid (string)
|
| 252 |
* @ About : The session ID used to authenticate with PHPBB
|
| 253 |
* @ Type : Public
|
| 254 |
*/
|
| 255 |
var $sid = null;
|
| 256 |
|
| 257 |
/*
|
| 258 |
* @ Variable : $error (Array)
|
| 259 |
* @ About : The array including error code and message on errors
|
| 260 |
* @ Type : Public
|
| 261 |
*/
|
| 262 |
var $error = array();
|
| 263 |
|
| 264 |
/*
|
| 265 |
* @ Function : curl_phpbb() - Constructor
|
| 266 |
* @ About : Check if CURL is available and the url exists.
|
| 267 |
* @ Type : Public
|
| 268 |
*/
|
| 269 |
function curl_phpbb($phpbb_url, $cookie_name = 'tmpfile.tmp') {
|
| 270 |
// Check CURL is present
|
| 271 |
if ( ! function_exists ( 'curl_init') ) {
|
| 272 |
// Output an error message
|
| 273 |
trigger_error('curl_phpbb::error, Sorry but it appears that CURL is not loaded, Please install it to continue.');
|
| 274 |
return false;
|
| 275 |
}
|
| 276 |
if ( empty($phpbb_url) ) {
|
| 277 |
// Output an error message
|
| 278 |
trigger_error('curl_phpbb::error, The phpBB location is required to continue, Please edit your script.');
|
| 279 |
return false;
|
| 280 |
}
|
| 281 |
// Set base location
|
| 282 |
$this->phpbb_url = $phpbb_url;
|
| 283 |
// Create temp file
|
| 284 |
$this->cookie_name = $cookie_name;
|
| 285 |
}
|
| 286 |
|
| 287 |
/*
|
| 288 |
* @ Function : login() - Log In
|
| 289 |
* @ About : Does a remote login to the target phpBB and stores in cookie
|
| 290 |
* @ Type : Public
|
| 291 |
*/
|
| 292 |
function phpbbPostNodelogin($username, $password) {
|
| 293 |
global $_SERVER;
|
| 294 |
|
| 295 |
// Generate post string
|
| 296 |
$post_fields = $this->array_to_http(array(
|
| 297 |
'username' => $username,
|
| 298 |
'password' => $password,
|
| 299 |
'autologin' => 1,
|
| 300 |
'redirect' => 'index.php',
|
| 301 |
'login' => 'Log In',
|
| 302 |
));
|
| 303 |
// Init curl
|
| 304 |
$this->curl = curl_init();
|
| 305 |
// Set options
|
| 306 |
curl_setopt ( $this->curl, CURLOPT_URL, $this->phpbb_url . 'login.php' );
|
| 307 |
curl_setopt ( $this->curl, CURLOPT_POST, true );
|
| 308 |
curl_setopt ( $this->curl, CURLOPT_POSTFIELDS, $post_fields );
|
| 309 |
curl_setopt ( $this->curl, CURLOPT_RETURNTRANSFER, true );
|
| 310 |
curl_setopt ( $this->curl, CURLOPT_HEADER, false );
|
| 311 |
curl_setopt ( $this->curl, CURLOPT_COOKIE, $this->cookie_name );
|
| 312 |
curl_setopt ( $this->curl, CURLOPT_COOKIEJAR, $this->cookie_name );
|
| 313 |
curl_setopt ( $this->curl, CURLOPT_COOKIEFILE, $this->cookie_name );
|
| 314 |
curl_setopt ( $this->curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
|
| 315 |
// Execute request
|
| 316 |
$result = curl_exec ( $this->curl );
|
| 317 |
// Error handling
|
| 318 |
if ( curl_errno ( $this->curl ) ) {
|
| 319 |
$this->error = array(
|
| 320 |
curl_errno($this->curl),
|
| 321 |
curl_error($this->curl),
|
| 322 |
);
|
| 323 |
curl_close ( $this->curl );
|
| 324 |
return false;
|
| 325 |
}
|
| 326 |
// Set Session ID
|
| 327 |
$content=file_get_contents($this->cookie_name);
|
| 328 |
preg_match('/phpbb2mysql_sid/', $content, $matches, PREG_OFFSET_CAPTURE);
|
| 329 |
$offset = $matches[0][1] + strlen($matches[0][0]) + 1;
|
| 330 |
$this->sid = substr($content,$offset,32);
|
| 331 |
// Close connection
|
| 332 |
curl_close ( $this->curl );
|
| 333 |
// Return result
|
| 334 |
return true;
|
| 335 |
}
|
| 336 |
/*
|
| 337 |
* @ Function : new_topic() - New Topic
|
| 338 |
* @ About : Remotely posts a topic to the target phpBB forum.
|
| 339 |
* @ Type : Public
|
| 340 |
*/
|
| 341 |
function phpbbPostNodeNewtopic($forum_id, $message, $topic_title) {
|
| 342 |
global $_SERVER;
|
| 343 |
|
| 344 |
// Generate post string
|
| 345 |
$post_fields = $this->array_to_http(array(
|
| 346 |
'post' => 'Submit',
|
| 347 |
'mode' => 'newtopic',
|
| 348 |
'message' => $message,
|
| 349 |
'f' => $forum_id,
|
| 350 |
'subject' => $topic_title,
|
| 351 |
'disable_bbcode' => 0,
|
| 352 |
'disable_smilies' => 0,
|
| 353 |
'attach_sig' => 1,
|
| 354 |
'topictype' => 0,
|
| 355 |
'sid' => $this->sid,
|
| 356 |
));
|
| 357 |
// Location
|
| 358 |
$url_vars = $this->array_to_http(array(
|
| 359 |
'mode' => 'newtopic',
|
| 360 |
'f' => $forum_id,
|
| 361 |
));
|
| 362 |
// Init curl
|
| 363 |
$this->curl = curl_init();
|
| 364 |
// Set options
|
| 365 |
curl_setopt ( $this->curl, CURLOPT_URL, $this->phpbb_url . 'posting.php?' . $url_vars );
|
| 366 |
curl_setopt ( $this->curl, CURLOPT_POST, true );
|
| 367 |
curl_setopt ( $this->curl, CURLOPT_POSTFIELDS, $post_fields );
|
| 368 |
curl_setopt ( $this->curl, CURLOPT_RETURNTRANSFER, true );
|
| 369 |
curl_setopt ( $this->curl, CURLOPT_HEADER, false );
|
| 370 |
curl_setopt ( $this->curl, CURLOPT_COOKIE, $this->cookie_name );
|
| 371 |
curl_setopt ( $this->curl, CURLOPT_COOKIEJAR, $this->cookie_name );
|
| 372 |
curl_setopt ( $this->curl, CURLOPT_COOKIEFILE, $this->cookie_name );
|
| 373 |
curl_setopt ( $this->curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
|
| 374 |
// Execute request
|
| 375 |
$result = curl_exec ( $this->curl );
|
| 376 |
// Get the Topic ID to Return to the requestee
|
| 377 |
preg_match('/viewtopic.php\?p=/', $result, $match, PREG_OFFSET_CAPTURE);
|
| 378 |
$offset = $match[0][1] + strlen($match[0][0]);
|
| 379 |
$maxTopics = substr($result,$offset,7);
|
| 380 |
preg_match('/#/', $maxTopics, $match, PREG_OFFSET_CAPTURE);
|
| 381 |
$postID = substr($maxTopics,0,$match[0][1]);
|
| 382 |
db_set_active('phpbb');
|
| 383 |
$getTopic = db_query('SELECT `topic_id` FROM `phpbb_posts` WHERE post_id =%d', $postID);
|
| 384 |
if ($nd = db_fetch_object($getTopic)) {
|
| 385 |
$tid = $nd->topic_id;
|
| 386 |
}
|
| 387 |
//Switch back to the default connection when finished.
|
| 388 |
db_set_active('default');
|
| 389 |
// Get the result
|
| 390 |
if ( preg_match ( '#<td align="center"><span class="gen">Your message has been entered successfully.<br \/><br \/>#is', $result, $match ) ) {
|
| 391 |
$post_status = 1;
|
| 392 |
}
|
| 393 |
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 ) ) {
|
| 394 |
$post_status = 0;
|
| 395 |
}
|
| 396 |
else {
|
| 397 |
$post_status = 0;
|
| 398 |
}
|
| 399 |
// Error handling
|
| 400 |
if ( curl_errno ( $this->curl ) ) {
|
| 401 |
$this->error = array(
|
| 402 |
curl_errno($this->curl),
|
| 403 |
curl_error($this->curl),
|
| 404 |
);
|
| 405 |
curl_close ( $this->curl );
|
| 406 |
return false;
|
| 407 |
}
|
| 408 |
// Close connection
|
| 409 |
curl_close ( $this->curl );
|
| 410 |
// Return result
|
| 411 |
|
| 412 |
return $tid;
|
| 413 |
}
|
| 414 |
/*
|
| 415 |
* @ Function : topic_reply() - Topic Reply
|
| 416 |
* @ About : Remotely replys a post to a topic to the target phpBB forum.
|
| 417 |
* @ Type : Public
|
| 418 |
*/
|
| 419 |
function phpbbPostNodetopic_reply($topic_id, $message, $topic_title) {
|
| 420 |
global $_SERVER;
|
| 421 |
|
| 422 |
// Generate post string
|
| 423 |
$post_fields = $this->array_to_http(array(
|
| 424 |
'post' => 'Submit',
|
| 425 |
'mode' => 'reply',
|
| 426 |
'message' => $message,
|
| 427 |
't' => $topic_id,
|
| 428 |
'subject' => $topic_title,
|
| 429 |
'disable_bbcode' => 0,
|
| 430 |
'disable_smilies' => 0,
|
| 431 |
'attach_sig' => 1,
|
| 432 |
'topictype' => 0,
|
| 433 |
'sid' => $this->sid,
|
| 434 |
));
|
| 435 |
// Location
|
| 436 |
$url_vars = $this->array_to_http(array(
|
| 437 |
'mode' => 'reply',
|
| 438 |
't' => $topic_id,
|
| 439 |
));
|
| 440 |
// Init curl
|
| 441 |
$this->curl = curl_init();
|
| 442 |
// Set options
|
| 443 |
curl_setopt ( $this->curl, CURLOPT_URL, $this->phpbb_url . 'posting.php?' . $url_vars );
|
| 444 |
curl_setopt ( $this->curl, CURLOPT_POST, true );
|
| 445 |
curl_setopt ( $this->curl, CURLOPT_POSTFIELDS, $post_fields );
|
| 446 |
curl_setopt ( $this->curl, CURLOPT_RETURNTRANSFER, true );
|
| 447 |
curl_setopt ( $this->curl, CURLOPT_HEADER, false );
|
| 448 |
curl_setopt ( $this->curl, CURLOPT_COOKIE, $this->cookie_name );
|
| 449 |
curl_setopt ( $this->curl, CURLOPT_COOKIEJAR, $this->cookie_name );
|
| 450 |
curl_setopt ( $this->curl, CURLOPT_COOKIEFILE, $this->cookie_name );
|
| 451 |
curl_setopt ( $this->curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
|
| 452 |
// Execute request
|
| 453 |
$result = curl_exec ( $this->curl );
|
| 454 |
// Get the result
|
| 455 |
if ( preg_match ( '#<td align="center"><span class="gen">Your message has been entered successfully.<br \/><br \/>#is', $result, $match ) ) {
|
| 456 |
$post_status = 1;
|
| 457 |
}
|
| 458 |
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 ) ) {
|
| 459 |
$post_status = 0;
|
| 460 |
}
|
| 461 |
else {
|
| 462 |
$post_status = 0;
|
| 463 |
}
|
| 464 |
// Error handling
|
| 465 |
if ( curl_errno ( $this->curl ) ) {
|
| 466 |
$this->error = array(
|
| 467 |
curl_errno($this->curl),
|
| 468 |
curl_error($this->curl),
|
| 469 |
);
|
| 470 |
curl_close ( $this->curl );
|
| 471 |
return false;
|
| 472 |
}
|
| 473 |
// Close connection
|
| 474 |
curl_close ( $this->curl );
|
| 475 |
// Return result
|
| 476 |
return $post_status;
|
| 477 |
}
|
| 478 |
|
| 479 |
/*
|
| 480 |
* @ Function : logout() - Log Out
|
| 481 |
* @ About : Logs out of the target phpBB properly.
|
| 482 |
* @ Type : Public
|
| 483 |
*/
|
| 484 |
function phpbbPostNodelogout() {
|
| 485 |
global $_SERVER;
|
| 486 |
$ipAddress = '66.104.45.38';
|
| 487 |
// Generate post string
|
| 488 |
$urlopt = $this->array_to_http(array(
|
| 489 |
'logout' => 'true',
|
| 490 |
'mode' => 'logout',
|
| 491 |
));
|
| 492 |
// Init curl
|
| 493 |
$this->curl = curl_init();
|
| 494 |
// Set options
|
| 495 |
curl_setopt ( $this->curl, CURLOPT_URL, $this->phpbb_url . 'login.php?' . $urlopt );
|
| 496 |
curl_setopt ( $this->curl, CURLOPT_POST, false );
|
| 497 |
curl_setopt ( $this->curl, CURLOPT_RETURNTRANSFER, true );
|
| 498 |
curl_setopt ( $this->curl, CURLOPT_HEADER, false );
|
| 499 |
curl_setopt ( $this->curl, CURLOPT_COOKIE, $this->cookie_name );
|
| 500 |
curl_setopt ( $this->curl, CURLOPT_COOKIEJAR, $this->cookie_name );
|
| 501 |
curl_setopt ( $this->curl, CURLOPT_COOKIEFILE, $this->cookie_name );
|
| 502 |
curl_setopt ( $this->curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
|
| 503 |
// Execute request
|
| 504 |
$result = curl_exec ( $this->curl );
|
| 505 |
// Error handling
|
| 506 |
if ( curl_errno ( $this->curl ) ) {
|
| 507 |
$this->error = array(
|
| 508 |
curl_errno($this->curl),
|
| 509 |
curl_error($this->curl),
|
| 510 |
);
|
| 511 |
curl_close ( $this->curl );
|
| 512 |
return false;
|
| 513 |
}
|
| 514 |
// Close connection
|
| 515 |
curl_close ( $this->curl );
|
| 516 |
// Delete cookie file
|
| 517 |
//@unlink($this->cookie_name);
|
| 518 |
// Return result
|
| 519 |
return true;
|
| 520 |
}
|
| 521 |
|
| 522 |
/*
|
| 523 |
* @ Function : array_to_http() - Converter
|
| 524 |
* @ About : Converts data from array to http string
|
| 525 |
* @ Type : Private
|
| 526 |
*/
|
| 527 |
function array_to_http($array) {
|
| 528 |
$retvar = '';
|
| 529 |
while ( list ( $field, $data ) = @each ( $array ) ) {
|
| 530 |
$retvar .= ( empty($retvar) ) ? '' : '&';
|
| 531 |
$retvar .= urlencode($field) . '=' . urlencode($data);
|
| 532 |
}
|
| 533 |
return $retvar;
|
| 534 |
}
|
| 535 |
}
|