Oh?
Well in that case do you mind if you fix the sql code?
Thanks
<?php
if ( ! defined( 'IN_IPB' ) )
{
print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
exit();
}
class task_item
{
/**
* Parent task manager class
*
* @access protected
* @var object
*/
protected $class;
/**
* This task data
*
* @access protected
* @var array
*/
protected $task = array();
/**
* Registry Object Shortcuts
*/
protected $registry;
protected $settings;
/**
* Constructor
*
* @access public
* @param object ipsRegistry reference
* @param object Parent task class
* @param array This task data
* @return void
*/
public function __construct( ipsRegistry $registry, $class, $task )
{
/* Make registry objects */
$this->registry = $registry;
$this->settings =& $this->registry->fetchSettings();
$this->class = $class;
$this->task = $task;
}
/**
* Run this task
*
* @access public
* @return void
*/
public function runTask()
{
//-----------------------------------------
// ATTEMPT TO CONNECT TO DB
//-----------------------------------------
$con = mysql_connect($this->settings['sql_host'], $this->settings['sql_user'], $this->settings['sql_pass']) or die('Could not connect: ' . mysql_error());
mysql_select_db($this->settings['sql_database'], $con);
if(!mysql_query("SELECT bot_msg FROM " . $this->settings['sql_tbl_prefix'] . "posts LIMIT 0"))
mysql_query("ALTER TABLE " . $this->settings['sql_tbl_prefix'] . "posts ADD COLUMN bot_msg varchar (20)");
//-----------------------------------------
// CHECK AND GET BOT SETTINGS
//-----------------------------------------
if($this->settings['linkbot_member_id']=="" OR $this->settings['linkbot_scanfirstpost']=="" OR $this->settings['linkbot_forumids']=="" OR $this->settings['linkbot_trashcan_id']=="" OR $this->settings['linkbot_threshold']=="" OR $this->settings['linkbot_reply_msg']=="" OR !is_numeric($this->settings['linkbot_member_id']) OR !is_numeric($this->settings['linkbot_threshold']))
{
echo "Please configure the bot's settings completely and correctly. Hit your browser's back button to go back to the ACP.";
mysql_query("UPDATE " . $this->settings['sql_tbl_prefix'] . "task_manager SET task_locked=0 WHERE task_id = " . $this->task['task_id']);
mysql_close($con);
exit;
}
$get_bot_name = mysql_query("SELECT members_l_display_name FROM " . $this->settings['sql_tbl_prefix'] . "members WHERE member_id=".$this->settings['linkbot_member_id']);
$bot_name = mysql_result($get_bot_name,0);
if($this->settings['linkbot_scanfirstpost'] == 1)
$scan_first_option = " AND p.new_topic=1";
$hosts = explode("\
", $this->settings['linkbot_filehosts']);
$total_urls = 0;
$total_dead_urls = 0;
$total_errors = 0;
$i = 0;
//-----------------------------------------
// BOT START
//-----------------------------------------
mysql_query("INSERT INTO " . $this->settings['sql_tbl_prefix'] . "task_logs (log_title,log_date,log_ip,log_desc) VALUES ('" . $this->task['task_title'] . "','" . time() . "','127.0.0.1','Started Scanning Forums')");
//-----------------------------------------
// GET POSTS
//-----------------------------------------
$get_post_query = mysql_query("SELECT t.forum_id,t.title,t.title_seo,p.post,p.pid,p.topic_id,p.new_topic FROM " . $this->settings['sql_tbl_prefix'] . "topics AS t INNER JOIN " . $this->settings['sql_tbl_prefix'] . "posts AS p WHERE t.forum_id IN (".$this->settings['linkbot_forumids'].") AND t.forum_id<>".$this->settings['linkbot_trashcan_id']." AND t.tid=p.topic_id".$scan_first_option);
if ( mysql_num_rows( $get_post_query ) )
{
while( $post = mysql_fetch_assoc( $get_post_query ) )
{
$i++;
//-----------------------------------------
// FOR DEBUGGING
//-----------------------------------------
if($i%$this->settings['linkbot_postinterval'] == 0)
mysql_query("INSERT INTO " . $this->settings['sql_tbl_prefix'] . "task_logs (log_title,log_date,log_ip,log_desc) VALUES ('" . $this->task['task_title'] . "','" . time() . "','127.0.0.1','Scanned " . $i . " Posts')");
$rs = ""; $mu = "";
$total_links = 0;
$total_dead = 0;
//-----------------------------------------
// GET POST CONTENT AND SCAN FOR LINKS
//-----------------------------------------
$subject = $post['post'];
$pattern = '|http[^ "<\\s[]{1,}|';
preg_match_all($pattern, $subject, $matches);
foreach($matches[0] as $link)
{
//-----------------------------------------
// ADD RS AND MU LINKS TO BATCH ARRAY
//-----------------------------------------
if(strpos($link,"rapidshare.com/files"))
{
$total_links++;
$rs .= $link . "\
";
}
if(strpos($link,"megaupload.com"))
{
$total_links++;
$mu .= $link . "\
";
}
//-----------------------------------------
// CHECK HOSTS OTHER THAN RS AND MU
//-----------------------------------------
foreach($hosts as $h)
{
$filehosts = explode("|",$h);
if(strpos($link,$filehosts[0])) { $keyword = $filehosts[1]; break; }
}
if($keyword != "")
{
$total_links++;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$link);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 8);
curl_setopt($ch, CURLOPT_COOKIEFILE, IPSLib::getAppDir( 'forums' ) . '/tasks/mscookie');
$result = curl_exec($ch);
$header = curl_getinfo( $ch );
curl_close($ch);
if($header['http_code'] == "200")
{
if(!strpos($result,$keyword))
$total_dead++;
}
else
$total_errors++;
}
unset($keyword,$h,$filehosts);
}
//-----------------------------------------
// BATCH CHECK RS LINKS
//-----------------------------------------
if($rs != "")
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://rapidshare.com/cgi-bin/checkfiles.cgi");
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "toolmode=1&urls=$rs");
$result = curl_exec($ch);
$header = curl_getinfo( $ch );
curl_close($ch);
if($header['http_code'] == "200")
{
$total_dead += substr_count($result,",-1");
}
else
$total_errors++;
}
//-----------------------------------------
// BATCH CHECK MU LINKS
//-----------------------------------------
if($mu != "")
{
$pattern = '|\\?d=\\w{8}|';
preg_match_all($pattern, $mu, $matches);
$mu = "";
for($j=0;$j<count($matches[0]);$j++)
{
$mu .= "id" . $j . "=" . substr($matches[0][$j],3) . "&";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://megaupload.com/mgr_linkcheck.php");
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$mu");
$result = curl_exec($ch);
$header = curl_getinfo( $ch );
curl_close($ch);
if($header['http_code'] == "200")
{
$pattern = '|id\\d{1}=1|';
preg_match_all($pattern, $result, $matches);
$total_dead += count($matches[0]);
}
else
$total_errors++;
}
if($total_links > 0)
{
//-------------------------------------------------
// IF DEAD LINKS % > THRESHOLD, TAKE SOME ACTION
//-------------------------------------------------
if(($total_dead/$total_links)*100 >= $this->settings['linkbot_threshold'])
{
if($this->settings['linkbot_action'] == "1")
{
//-----------------------------------------
// POST NOT FIRST POST OF TOPIC, UNAPPROVE
//-----------------------------------------
if($post['new_topic'] != "1")
{
mysql_query("UPDATE " . $this->settings['sql_tbl_prefix'] . "posts SET queued=1 WHERE pid = " . $post['pid']);
$posts = mysql_query("SELECT COUNT(pid) as posts FROM " . $this->settings['sql_tbl_prefix'] . "posts WHERE queued!=1 AND topic_id=".$post['topic_id']);
$pcount = mysql_result($posts,0) - 1;
$qposts = mysql_query("SELECT COUNT(pid) as posts FROM " . $this->settings['sql_tbl_prefix'] . "posts WHERE queued=1 AND topic_id=".$post['topic_id']);
$qpcount = mysql_result($qposts,0);
mysql_query("UPDATE " . $this->settings['sql_tbl_prefix'] . "topics SET posts=" . $pcount . ",topic_queuedposts=" . $qpcount . " WHERE tid = " . $post['topic_id']);
unset($qposts,$qpcount,$posts,$pcount);
}
//----------------------------------------------------------
// POST IS FIRST POST OF TOPIC, MOVE TOPIC AND ADD BOT REPLY
//----------------------------------------------------------
else
{
mysql_query("UPDATE " . $this->settings['sql_tbl_prefix'] . "topics SET forum_id='" . $this->settings['linkbot_trashcan_id'] . "' WHERE tid = " . $post['topic_id']);
mysql_query("UPDATE " . $this->settings['sql_tbl_prefix'] . "polls SET forum_id='" . $this->settings['linkbot_trashcan_id'] . "' WHERE tid = " . $post['topic_id']);
mysql_query("INSERT INTO " . $this->settings['sql_tbl_prefix'] . "posts (author_id,author_name,ip_address,post_date,post,topic_id) VALUES ('" . $this->settings['linkbot_member_id'] . "','" . $bot_name . "','127.0.0.1','" . time() . "','" . htmlentities($this->settings['linkbot_reply_msg'],ENT_QUOTES) . "','" . $post['topic_id'] . "')");
mysql_query("UPDATE " . $this->settings['sql_tbl_prefix'] . "topics SET posts=posts+1,last_poster_id='" . $this->settings['linkbot_member_id'] . "',last_post='" . time() . "',last_poster_name='" . $bot_name . "' WHERE tid = " . $post['topic_id']);
mysql_query("UPDATE " . $this->settings['sql_tbl_prefix'] . "members SET posts=posts+1 WHERE member_id = " . $this->settings['linkbot_member_id']);
}
}
//-----------------------------------------
// REPORT POST
//-----------------------------------------
if($this->settings['linkbot_action'] == "2")
{
$cacheupdate['last_updated'] = time();
$report_content = "I found " . $total_dead . " dead link(s) in a post from the topic: ". $post['title'] ."<br/>[ ."/index.php?showtopic=". $post['topic_id'] ."&view=findpost&p=". $post['pid'] ."\\"]Click here to view the post](\\"" . $this->settings['board_url')";
mysql_query("INSERT INTO " . $this->settings['sql_tbl_prefix'] . "rc_reports_index (title,status,url,rc_class,updated_by,date_updated,date_created,exdat1,exdat2,exdat3,num_reports,num_comments,seoname,seotemplate) VALUES ('". htmlentities($post['title'],ENT_QUOTES) ."','1','/index.php?showtopic=". $post['topic_id'] ."&view=findpost&p=". $post['pid'] ."','2','". $this->settings['linkbot_member_id'] ."',". time() .",". time() .",'". $post['forum_id'] ."','". $post['topic_id'] ."','". $post['pid'] ."','1','0','". $post['title_seo'] ."','showtopic')");
$rid = mysql_insert_id();
mysql_query("INSERT INTO " . $this->settings['sql_tbl_prefix'] . "rc_reports (rid,report,report_by,date_reported) VALUES ('". $rid ."','". $report_content ."','". $this->settings['linkbot_member_id'] ."',". time() .")");
mysql_query("INSERT INTO " . $this->settings['sql_tbl_prefix'] . "cache_store (cs_key,cs_value,cs_array,cs_updated) VALUES ('report_cache','". serialize($cacheupdate) ."','1',". time() . ") ON DUPLICATE KEY UPDATE cs_value='". serialize($cacheupdate) ."',cs_updated=". time());
unset($cacheupdate,$rid,$report_content);
}
}
//-----------------------------------------
// ADD BOT CHECK TIME TO POST
//-----------------------------------------
if($total_links>0)
mysql_query("UPDATE " . $this->settings['sql_tbl_prefix'] . "posts SET bot_msg='" . time() . "," . $total_dead . "' WHERE pid = " . $post['pid']);
}
//-----------------------------------------
// UPDATE GLOBAL VARIABLES AND CLEAR MEMORY
//-----------------------------------------
$total_urls += $total_links;
$total_dead_urls += $total_dead;
unset($total_links,$total_dead,$subject,$pattern,$matches,$link,$keyword,$ch,$result,$header,$post,$rs,$mu,$j);
}
}
//-----------------------------------------
// BOT FINISHED CHECKING
//-----------------------------------------
mysql_query("INSERT INTO " . $this->settings['sql_tbl_prefix'] . "task_logs (log_title,log_date,log_ip,log_desc) VALUES ('" . $this->task['task_title'] . "','" . time() . "','127.0.0.1','Finished! Total Posts Scanned: " . $i . " Total Links Checked: " . $total_urls . " Total Dead: " . $total_dead_urls . " Errors: " . $total_errors . "')");
//-----------------------------------------
// UPDATE FORUM STATISTICS
//-----------------------------------------
if($this->settings['linkbot_action'] == "1")
{
$allforums = explode(",",$this->settings['linkbot_forumids'].",".$this->settings['linkbot_trashcan_id']);
foreach($allforums as $fid)
{
$topics = mysql_fetch_assoc(mysql_query("SELECT COUNT(tid) as count FROM " . $this->settings['sql_tbl_prefix'] . "topics WHERE approved=1 AND forum_id=" . $fid));
$queued_topics = mysql_fetch_assoc(mysql_query("SELECT COUNT(tid) as count FROM " . $this->settings['sql_tbl_prefix'] . "topics WHERE approved=0 AND forum_id=" . $fid));
$posts = mysql_fetch_assoc(mysql_query("SELECT SUM(posts) as replies FROM " . $this->settings['sql_tbl_prefix'] . "topics WHERE approved=1 AND forum_id=" . $fid));
$queued_posts = mysql_fetch_assoc(mysql_query("SELECT SUM(topic_queuedposts) as replies FROM " . $this->settings['sql_tbl_prefix'] . "topics WHERE forum_id=" . $fid));
$last_post = mysql_fetch_assoc(mysql_query("SELECT tid, title, last_poster_id, last_poster_name, last_post FROM " . $this->settings['sql_tbl_prefix'] . "topics WHERE approved=1 AND forum_id=" . $fid . " ORDER BY last_post DESC LIMIT 1"));
if(!$last_post) { $last_post['last_poster_id'] = 0; $last_post['last_poster_name'] = ''; $last_post['last_post'] = 0; $last_post['title'] = ''; $last_post['tid'] = 0; }
if($queued_posts['replies']=="") $queued_posts['replies']=0; if($posts['replies']=="") $posts['replies']=0;
mysql_query("UPDATE " . $this->settings['sql_tbl_prefix'] . "forums SET last_poster_id=" . $last_post['last_poster_id'] . ",last_poster_name='" . $last_post['last_poster_name'] . "',last_post=" . $last_post['last_post'] . ",last_title='" . $last_post['title'] . "',last_id=" . $last_post['tid'] . ",topics=" . $topics['count'] . ",posts=" . $posts['replies'] . ",queued_posts=" . $queued_posts['replies'] . ",queued_topics=" . $queued_topics['count'] . " WHERE id=" . $fid);
unset($topics,$queued_topics,$posts,$queued_posts,$last_post);
}
}
//--------------------------------------------------
// UNLOCK TASK, CLOSE DB CONNECTION AND CLEAR MEMORY
//--------------------------------------------------
mysql_query("UPDATE " . $this->settings['sql_tbl_prefix'] . "task_manager SET task_locked=0 WHERE task_id = " . $this->task['task_id']);
mysql_close($con);
unset($total_urls,$total_dead_urls,$total_errors,$i,$get_bot_name,$bot_name,$scan_first_option,$get_post_query,$post,$con,$this->settings,$this->registry,$this->task,$allforums,$fid,$hosts);
}
}