libdir.'/adminlib.php'); // Configuration $autokeywords = array( "id)) { if (isset($SESSION->users_result[$id])) { $user = $SESSION->users_result[$id]; if (delete_user($user)) { unset($SESSION->users_result[$id]); echo json_encode(true); } else { echo json_encode(false); } } else { echo json_encode(false); } exit; } // Delete lots of users if (!empty($delall) && confirm_sesskey()) { if (!empty($SESSION->users_result)) { foreach ($SESSION->users_result as $userid => $user) { if ($userid != $USER->id) { if (delete_user($user)) { unset($SESSION->users_result[$userid]); } } } } echo json_encode(true); exit; } if (!empty($ignore)) { unset($SESSION->users_result[$id]); echo json_encode(true); exit; } $PAGE->requires->js_init_call('M.tool_spamcleaner.init', array(me()), true); $strings = Array('spaminvalidresult','spamdeleteallconfirm','spamcannotdelete','spamdeleteconfirm'); $PAGE->requires->strings_for_js($strings, 'tool_spamcleaner'); echo $OUTPUT->header(); // Print headers and things echo $OUTPUT->box(get_string('spamcleanerintro', 'tool_spamcleaner')); echo $OUTPUT->box_start(); // The forms section at the top ?>


box_end(); echo '
'; // Print list of resulting profiles if (!empty($keyword)) { // Use the keyword(s) supplied by the user $keywords = explode(',', $keyword); foreach ($keywords as $key => $keyword) { $keywords[$key] = trim($keyword); } search_spammers($keywords); } else if (!empty($autodetect)) { // Use the inbuilt keyword list to detect users search_spammers($autokeywords); } echo '
'; ///////////////////////////////////////////////////////////////////////////////// /// Functions function search_spammers($keywords) { global $CFG, $USER, $DB, $OUTPUT; if (!is_array($keywords)) { $keywords = array($keywords); // Make it into an array } $params = array('userid'=>$USER->id); $keywordfull = array(); $i = 0; foreach ($keywords as $keyword) { $keywordfull[] = $DB->sql_like('description', ':descpat'.$i, false); $params['descpat'.$i] = "%$keyword%"; $keywordfull2[] = $DB->sql_like('p.summary', ':sumpat'.$i, false); $params['sumpat'.$i] = "%$keyword%"; $keywordfull3[] = $DB->sql_like('p.subject', ':subpat'.$i, false); $params['subpat'.$i] = "%$keyword%"; $keywordfull4[] = $DB->sql_like('c.content', ':contpat'.$i, false); $params['contpat'.$i] = "%$keyword%"; $keywordfull5[] = $DB->sql_like('m.fullmessage', ':msgpat'.$i, false); $params['msgpat'.$i] = "%$keyword%"; $keywordfull6[] = $DB->sql_like('fp.message', ':forumpostpat'.$i, false); $params['forumpostpat'.$i] = "%$keyword%"; $keywordfull7[] = $DB->sql_like('fp.subject', ':forumpostsubpat'.$i, false); $params['forumpostsubpat'.$i] = "%$keyword%"; $i++; } $conditions = '( '.implode(' OR ', $keywordfull).' )'; $conditions2 = '( '.implode(' OR ', $keywordfull2).' )'; $conditions3 = '( '.implode(' OR ', $keywordfull3).' )'; $conditions4 = '( '.implode(' OR ', $keywordfull4).' )'; $conditions5 = '( '.implode(' OR ', $keywordfull5).' )'; $conditions6 = '( '.implode(' OR ', $keywordfull6).' )'; $conditions7 = '( '.implode(' OR ', $keywordfull7).' )'; $sql = "SELECT * FROM {user} WHERE deleted = 0 AND id <> :userid AND $conditions"; // Exclude oneself $sql2 = "SELECT u.*, p.summary FROM {user} AS u, {post} AS p WHERE $conditions2 AND u.deleted = 0 AND u.id=p.userid AND u.id <> :userid"; $sql3 = "SELECT u.*, p.subject as postsubject FROM {user} AS u, {post} AS p WHERE $conditions3 AND u.deleted = 0 AND u.id=p.userid AND u.id <> :userid"; $sql4 = "SELECT u.*, c.content FROM {user} AS u, {comments} AS c WHERE $conditions4 AND u.deleted = 0 AND u.id=c.userid AND u.id <> :userid"; $sql5 = "SELECT u.*, m.fullmessage FROM {user} AS u, {message} AS m WHERE $conditions5 AND u.deleted = 0 AND u.id=m.useridfrom AND u.id <> :userid"; $sql6 = "SELECT u.*, fp.message FROM {user} AS u, {forum_posts} AS fp WHERE $conditions6 AND u.deleted = 0 AND u.id=fp.userid AND u.id <> :userid"; $sql7 = "SELECT u.*, fp.subject FROM {user} AS u, {forum_posts} AS fp WHERE $conditions7 AND u.deleted = 0 AND u.id=fp.userid AND u.id <> :userid"; $spamusers_desc = $DB->get_recordset_sql($sql, $params); $spamusers_blog = $DB->get_recordset_sql($sql2, $params); $spamusers_blogsub = $DB->get_recordset_sql($sql3, $params); $spamusers_comment = $DB->get_recordset_sql($sql4, $params); $spamusers_message = $DB->get_recordset_sql($sql5, $params); $spamusers_forumpost = $DB->get_recordset_sql($sql6, $params); $spamusers_forumpostsub = $DB->get_recordset_sql($sql7, $params); $keywordlist = implode(', ', $keywords); echo $OUTPUT->box(get_string('spamresult', 'tool_spamcleaner').s($keywordlist)).' ...'; print_user_list(array($spamusers_desc, $spamusers_blog, $spamusers_blogsub, $spamusers_comment, $spamusers_message, $spamusers_forumpost, $spamusers_forumpostsub ), $keywords); } function print_user_list($users_rs, $keywords) { global $CFG, $SESSION; // reset session everytime this function is called $SESSION->users_result = array(); $count = 0; foreach ($users_rs as $rs){ foreach ($rs as $user) { if (!$count) { echo ''; } $count++; filter_user($user, $keywords, $count); } } if (!$count) { echo get_string('spamcannotfinduser', 'tool_spamcleaner'); } else { echo '
 '.get_string('user','admin').''.get_string('spamdesc', 'tool_spamcleaner').''.get_string('spamoperation', 'tool_spamcleaner').'
'; echo '
'; } } function filter_user($user, $keywords, $count) { global $CFG; $image_search = false; if (in_array('summary)) { $user->description = '

'.get_string('spamfromblog', 'tool_spamcleaner').'

'.$user->summary; unset($user->summary); } else if (isset($user->postsubject)) { $user->description = '

'.get_string('spamfromblog', 'tool_spamcleaner').'

'.$user->postsubject; unset($user->postsubject); } else if (isset($user->content)) { $user->description = '

'.get_string('spamfromcomments', 'tool_spamcleaner').'

'.$user->content; unset($user->content); } else if (isset($user->fullmessage)) { $user->description = '

'.get_string('spamfrommessages', 'tool_spamcleaner').'

'.$user->fullmessage; unset($user->fullmessage); } else if (isset($user->message)) { $user->description = '

'.get_string('spamfromforumpost', 'tool_spamcleaner').'

'.$user->message; unset($user->message); } else if (isset($user->subject)) { $user->description = '

'.get_string('spamfromforumpost', 'tool_spamcleaner').'

'.$user->subject; unset($user->subject); } if (preg_match('#wwwroot.')#', $user->description, $matches) && $image_search) { $result = false; foreach ($keywords as $keyword) { if (preg_match('#'.$keyword.'#', $user->description) && ($keyword != 'id = $user->id; $smalluserobject->email = $user->email; $smalluserobject->auth = $user->auth; $smalluserobject->firstname = $user->firstname; $smalluserobject->lastname = $user->lastname; $smalluserobject->username = $user->username; if (empty($SESSION->users_result[$user->id])) { $SESSION->users_result[$user->id] = $smalluserobject; $html = ''; $html .= ''.$count.''; $html .= 'id.'" title="'.s($user->username).'">'.fullname($user).''; $html .= "
    "; $profile_set = array('city'=>true, 'country'=>true, 'email'=>true); foreach ($profile_set as $key=>$value) { if (isset($user->$key)){ $html .= '
  • '.$user->$key.'
  • '; } } $html .= "
"; $html .= ''; foreach ($keywords as $keyword) { $user->description = highlight($keyword, $user->description); } if (!isset($user->descriptionformat)) { $user->descriptionformat = FORMAT_MOODLE; } $html .= ''.format_text($user->description, $user->descriptionformat, array('overflowdiv'=>true)).''; $html .= ''; $html .= '
'; $html .= ''; $html .= ''; $html .= ''; return $html; } else { return null; } } echo $OUTPUT->footer();