I've just got a news script to post automatically on my phpBB forum..there seems to be something wrong with the script..dunno..
The problem that I get is something like missing files even thought I have them..
Can anyone help ?
<?
define('IN_PHPBB', true);
$phpbb_root_path = '/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
$user->session_begin();
$sql = 'SELECT *
FROM ' . USERS_TABLE . '
WHERE user_id = 2';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$auth->acl($row);
$user->data['user_id'] = 2;
$user->data['user_type'] = 0;
$user->data['group_id'] = 5;
$user->data['user_regdate'] = 1157021201;
$user->data['username'] = 'FootballNews';
$user->data['username_clean'] = 'newsbot';
$user->data['user_email'] = 'example@example.com';
$user->data['user_email_hash'] = '187292980428';
$user->data['user_rank'] = 2;
$user->data['user_occ'] = 'Fetching news';
$user->data['is_registered'] = true;
$user->data['is_bot'] = false;
$user->setup();
$dbhost = 'xxxx';
$dbname = 'xxxx';
$dbuser = 'xxxx';
$dbpasswd = 'xxxx';
$root = "http://www.example.com";
$sURLnews = "/en/news/news/index.php";
ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
$fd=@fopen($root . $sURLnews,"r");
if ($fd) {
while ($line=fgets($fd,1000)) {
$data .= $line;
}
fclose ($fd);
}
preg_match_all('/<a\s.*?href="(\/en\/news\/[a-z]+\/2[^\?]+)\?fcb_sid=/', $data, $matches);
$news = array_unique($matches[1]);
sort($news);
// Connecting, selecting database
$link = mysql_connect($dbhost, $dbuser, $dbpasswd)
or die('Could not connect: ' . mysql_error());
mysql_select_db($dbname) or die('Could not select database');
foreach($news as $key => $val) {
preg_match('/\/news\/[a-z]+\/[0-9]+\/(.*)\.php/', $val, $matches);
$news_id = $matches[1];
// Performing SQL query
$query = "SELECT Count(*) FROM news WHERE newsid = '" . $news_id . "';";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$row = mysql_fetch_row($result);
if ($row[0] == 0) {
echo $news_id . " is NOT available in the db.<br>";
$page = '';
ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
$fd=@fopen($root . $val ,"r");
if ($fd) {
while ($line=fgets($fd,1000)) {
$page .= $line;
}
fclose ($fd);
}
//preg_match('/<span class="fcc003318px">(.*)<\/span>/', $page, $matches);
preg_match('/<h1 class="MainTitle">(.*)<\/h1>/', $page, $matches);
$title = str_replace("'", "''", $matches[1]);
$title = str_replace("\r\n", "", $title);
$title = str_replace("\n", "", $title);
$title = str_replace("’", "'", $title);
$title = str_replace("‘", "'", $title);
$title = str_replace("“", "\"", $title);
$title = str_replace("”", "\"", $title);
$title = str_replace("…","...", $title);
$title = str_replace("–","-", $title);
$title = str_replace("€","€", $title);
preg_match('/<!-- Article Template Area -->(.*)<!-- \/Article Module Area -->/si', $page, $matches);
$body = str_replace("'", "''", $matches[1]);
$body = str_replace("\r\n", "", $body);
$body = str_replace("\n", "", $body);
$body = str_replace("’", "'", $body);
$body = str_replace("‘", "'", $body);
$body = str_replace("“", "\"", $body);
$body = str_replace("”", "\"", $body);
$body = str_replace("…","...", $body);
$body = str_replace("–","-", $body);
$body = str_replace("€","€", $body);
preg_match_all('|<p>(.+)</p>|Ui', $body, $matches);
$body = implode("\n\n", $matches[1]);
$body = str_replace("<br />", "\n", $body);
$body = str_replace("\n\n\n", "\n\n", $body);
$body = str_replace("<b>", "[b]", $body);
$body = str_replace("</b>", "[/b]", $body);
$body = str_replace("<i>", "[i]", $body);
$body = str_replace("</i>", "[/i]", $body);
$time = time();
$my_subject = utf8_normalize_nfc($title);
$my_text = utf8_normalize_nfc($body);
$poll = $uid = $bitfield = $options = '';
generate_text_for_storage($my_subject, $uid, $bitfield, $options, false, false, false);
generate_text_for_storage($my_text, $uid, $bitfield, $options, true, true, true);
$data = array(
'post_approved' => true,
'topic_approved' => true,
'forum_id' => 22,
'icon_id' => false,
'enable_bbcode' => true,
'enable_smilies' => true,
'enable_urls' => true,
'enable_sig' => true,
'message' => $my_text,
'message_md5' => md5($my_text),
'bbcode_bitfield' => $bitfield,
'bbcode_uid' => $uid,
'post_edit_locked' => 0,
'topic_title' => $my_subject,
'notify_set' => false,
'notify' => false,
'post_time' => 0,
'forum_name' => '',
'enable_indexing' => true,
);
submit_post('post', $my_subject, '', POST_NORMAL, $poll, $data);
$query = "INSERT INTO news (newsid) VALUES ('$news_id');";
$result = mysql_query($query) or die('Query failed: ' . $query . " - " . mysql_error());
}
else {
echo $matches[1] . " is available in the db.<br>";
}
}
// Closing connection
mysql_close($link);
die;
?>