Code: Select all
<?php
/***************************************************************************
* iai_cron.php
* -------------------
* copyright : (C) 2003 James Gay
* email : zemaj@palgn.com
*
***************************************************************************/
/***************************************************************************
* Zemaj wrote:
* This *should* check & update IAI posts where needed when called.
* To use set this page as a cron jobs to run every minute.
*
* Mr.Luc wrote:
* Actually i don't know if this version will run as a cronjob.
* I included it with:
* include($phpbb_root_path.'iai_cron.php');
* at the very beginning of page_tail.php
*
***************************************************************************/
define('IN_PHPBB', true);
if(!isset($phpbb_root_path)) {
$phpbb_root_path='./';
}
include_once($phpbb_root_path.'extension.inc');
include_once($phpbb_root_path.'common.'.$phpEx);
include_once($phpbb_root_path . 'includes/bbcode.'.$phpEx);
include_once($phpbb_root_path . 'includes/functions_post.'.$phpEx);
// Grab all our data
$sql = "SELECT c.*, pt.post_text AS past_message, pt.bbcode_uid AS past_bbcode_uid, p.post_username, p.poster_id, t.topic_last_post_id
FROM " . IAI_CRON_TABLE . " c, " . POSTS_TEXT_TABLE . " pt, " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
WHERE c.update_time < " . time() . "
AND pt.post_id = c.past_post_id
AND p.post_id = c.past_post_id
AND t.topic_id = p.topic_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
$posts = $db->sql_fetchrowset($result);
if($total_posts = count($posts)) // if there is a message...
{
for( $i = 0; $i < $total_posts; $i++ ) // get each message
{
// Int vars
$iai_post_id = $posts[$i]['post_id'];
$topic_id = $posts[$i]['topic_id'];
$forum_id = $posts[$i]['forum_id'];
$iai_subject = $posts[$i]['post_subject'];
$bbcode_uid = $posts[$i]['bbcode_uid'];
$iai_message = $posts[$i]['post_text'];
$current_time = time();
$quote_poster = $posts[$i]['poster_id'];
if($posts[$i]['topic_last_post_id'] != $posts[$i]['past_post_id'])
{
// New posts in thread since this reply was set...
// Now we have to add old text in a quote. Fun.
// clean_up
$posts[$i]['past_message'] = trim($posts[$i]['past_message']);
$iai_message = trim($iai_message);
// we get rid of old bbcode_uid
$past_message = preg_replace('/\:(([a-z0-9]:)?)' . $posts[$i]['past_bbcode_uid'] . '/s', '', $posts[$i]['past_message']);
$iai_message = preg_replace('/\:(([a-z0-9]:)?)' . $bbcode_uid . '/s', '', $iai_message);
// we get the username
if($posts[$i]['poster_id'] > 1)
{
/* getting the registered username. the post_username gets only the name of anonymous users. tried to include this query in the one above.. but i failed. so i put it here */
$sql2 = "SELECT username FROM ". USERS_TABLE ."
WHERE user_id = $quote_poster";
if ( !($result2 = $db->sql_query($sql2)) )
{
message_die(GENERAL_ERROR, 'Error in posting1', '', __LINE__, __FILE__, $sql2);
}
$posterinfo = $db->sql_fetchrow($result2);
// now we put the username into the quotes [quote="Username"]
$iai_message = "[quote=\"" . $posterinfo['username'] . "\"]" . $past_message . "[/quote]" . $iai_message;
}
else
{
if($posts[$i]['post_username'] != "" )
{
/* an anonymous user posted... but he entered a username */
$iai_message = "[quote=\"" . $posts[$i]['post_username'] . "\"]" . $past_message . "[/quote]" . $iai_message;
}
else
{
/* an anonymous user posted... but he did not enter a username */
$iai_message = "[quote=\"Anonymous\"]" . $past_message . "[/quote]" . $iai_message;
}
}
// now we parse with new bbcode
$bbcode_uid = make_bbcode_uid();
$iai_message = addslashes($iai_message);
$iai_message = bbencode_first_pass($iai_message, $bbcode_uid);
$iai_message = stripslashes($iai_message);
/* somehow this needs an add AND strip slashes!!! i don't know why :-0 but it won't work without... at least on my system !!! */
}
$sql = "UPDATE " . POSTS_TABLE . "
SET topic_id = $topic_id, forum_id = $forum_id, post_time = $current_time
WHERE post_id = $iai_post_id";
if ( !($result = $db->sql_query($sql, BEGIN_TRANSACTION)) )
{
message_die(GENERAL_ERROR, 'Error in posting1', '', __LINE__, __FILE__, $sql);
}
$iai_message = str_replace("'", "''", $iai_message);
$iai_subject = str_replace("'", "''", $iai_subject);
$sql = "INSERT INTO " . POSTS_TEXT_TABLE . " (post_id, bbcode_uid, post_subject, post_text) VALUES ($iai_post_id, '$bbcode_uid', '" . str_replace("\'", "''", $iai_subject) . "', '" . str_replace("\'", "''", $iai_message) . "')";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error in posting2', '', __LINE__, __FILE__, $sql);
}
/* we don't include the add_search_words function... because we don't want to upset users if they do a serious search and they would get 100 stupid posts of the bot. If you want to include it you would have to uncomment the 2 following lines! - But i don't know how much load it adds to system and how big dbase gets... if the bot posts alot */
// include_once($phpbb_root_path . 'includes/functions_search.'.$phpEx);
// add_search_words($iai_post_id, stripslashes($iai_message), stripslashes($iai_subject));
/* you can comment out following line if you dont want the bot count to rise with each post */
// iai_update_post_stats($forum_id, $topic_id, $iai_post_id, $board_config['iai_userid']);
// Updating complete! Remove this post from cron table!
$sql = "DELETE FROM " . IAI_CRON_TABLE . "
WHERE post_id = $iai_post_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
}
}
?>
.beardeddone wrote: This
src="./../mods/iai/jsrs/talk.gif"
should be
src="mods/iai/jsrs/talk.gif"
if from the root dir
works great at
http://www.skyport.dynip.com/skyport/aichat.php
you just need to be logged in to play
Error on registering
Error on registering