diff --git a/admin/report/spamcleaner/index.php b/admin/report/spamcleaner/index.php new file mode 100755 index 00000000000..3b0be1a084e --- /dev/null +++ b/admin/report/spamcleaner/index.php @@ -0,0 +1,397 @@ +libdir.'/adminlib.php'); +function delete_user($user) { + $updateuser = new object(); + $updateuser->id = $user->id; + $updateuser->deleted = 1; + $updateuser->username = addslashes("$user->email.".time()); + $updateuser->email = ''; + $updateuser->idnumber = ''; + $updateuser->timemodified = time(); + if (update_record('user', $updateuser)) { + role_unassign(0, $user->id); + return true; + } else { + return false; + } +} + +$keyword = optional_param('keyword', '', PARAM_RAW); +$autodetect = optional_param('autodetect', '', PARAM_RAW); +$del = optional_param('del', '', PARAM_RAW); +$delall = optional_param('delall', '', PARAM_RAW); +$ignore = optional_param('ignore', '', PARAM_RAW); +$reset = optional_param('reset', '', PARAM_RAW); +$id = optional_param('id', '', PARAM_INT); + +require_login(); + +// Implement some AJAX calls + +// Delete one user +if (!empty($del) && confirm_sesskey() && ($id != $USER->id)) { + if (isset($SESSION->users_result[$id])) { + $user = $SESSION->users_result[$id]; + if (delete_user($user)) { + unset($SESSION->users_result[$id]); + echo 1; + } else { + echo 0; + } + } else { + echo 0; + } + 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 1; + exit; +} + +if (!empty($ignore)) { + unset($SESSION->users_result[$id]); + echo 1; + exit; +} + +$strspamcleaner = get_string('spamcleaner', 'admin'); +$strnav = ''.get_string('administration').' -> '. get_string('reports') .' -> '.$strspamcleaner; +// Print headers and things +print_header($strspamcleaner, $strspamcleaner, $strnav); + +print_spamcleaner_javascript(); + +print_simple_box(get_string('spamcleanerintro', 'report_spamcleaner')); + +?> + +
+ +
+
+ + + +
+
+

+ +
+ +
+
+ +
+
+ + +
+ +'; + +// 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; + + if (!is_array($keywords)) { + $keywords = array($keywords); // Make it into an array + } + + $like = sql_ilike(); + + $keywordfull = array(); + foreach ($keywords as $keyword) { + $keyword = addslashes($keyword); // Just to be safe + $keywordfull[] = " description $like '%$keyword%' "; + $keywordfull2[] = " p.summary $like '%$keyword%' "; + } + $conditions = '( '.implode(' OR ', $keywordfull).' )'; + $conditions2 = '( '.implode(' OR ', $keywordfull2).' )'; + + $sql = "SELECT * FROM {$CFG->prefix}user WHERE deleted = 0 AND id <> {$USER->id} AND $conditions"; // Exclude oneself + $sql2= "SELECT u.*, p.summary FROM {$CFG->prefix}user AS u, {$CFG->prefix}post AS p WHERE $conditions2 AND u.deleted = 0 AND u.id=p.userid AND u.id <> {$USER->id}"; + $spamusers_desc = get_recordset_sql($sql); + $spamusers_blog = get_recordset_sql($sql2); + + $keywordlist = implode(', ', $keywords); + print_simple_box(get_string('spamresult', 'report_spamcleaner').s($keywordlist)).' ...'; + + print_user_list(array($spamusers_desc, $spamusers_blog), $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 $key=>$rs) { + while(!$rs->EOF) { + $user = (object)$rs->fields; + if (!$count) { + echo ''; + } + $rs->MoveNext(); + $count++; + filter_user($user, $keywords, $count); + } + } + + if (!$count) { + echo get_string('spamcannotfinduser', 'report_spamcleaner'); + + } else { + echo '
 '.get_string('user','admin').''.get_string('spamdesc', 'report_spamcleaner').''.get_string('spamoperation', 'report_spamcleaner').'
'; + echo '
+ +
'; + } +} +function filter_user($user, $keywords, $count) { + global $CFG; + $image_search = false; + if (in_array('summary)) { + $user->description = '

'.get_string('spamfromblog', 'report_spamcleaner').'

'.$user->summary; + unset($user->summary); + } + if (preg_match('#pixpath.')#', $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; + + 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); + } + + $html .= ''.format_text($user->description, FORMAT_MOODLE).''; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= ''; + return $html; + } else { + return null; + } + + +} + +function print_spamcleaner_javascript() { + global $CFG; + +$sesskey = sesskey(); + +?> + + + + + diff --git a/admin/report/spamcleaner/mod.php b/admin/report/spamcleaner/mod.php new file mode 100644 index 00000000000..95ee71d2eba --- /dev/null +++ b/admin/report/spamcleaner/mod.php @@ -0,0 +1,318 @@ + + +
+ +
+
+ + + +
+
+

+ +
+ +
+
+ +
+
+ + +
+ +'; + +// 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; + + if (!is_array($keywords)) { + $keywords = array($keywords); // Make it into an array + } + + $like = sql_ilike(); + + $keywordfull = array(); + foreach ($keywords as $keyword) { + $keyword = addslashes($keyword); // Just to be safe + $keywordfull[] = " description $like '%$keyword%' "; + $keywordfull2[] = " p.summary $like '%$keyword%' "; + } + $conditions = '( '.implode(' OR ', $keywordfull).' )'; + $conditions2 = '( '.implode(' OR ', $keywordfull2).' )'; + + $sql = "SELECT * FROM {$CFG->prefix}user WHERE deleted = 0 AND id <> {$USER->id} AND $conditions"; // Exclude oneself + $sql2= "SELECT u.*, p.summary FROM {$CFG->prefix}user AS u, {$CFG->prefix}post AS p WHERE $conditions2 AND u.deleted = 0 AND u.id=p.userid AND u.id <> {$USER->id}"; + $spamusers_desc = get_recordset_sql($sql); + $spamusers_blog = get_recordset_sql($sql2); + + $keywordlist = implode(', ', $keywords); + print_simple_box(get_string('spamresult', 'report_spamcleaner').s($keywordlist)).' ...'; + + print_user_list(array($spamusers_desc, $spamusers_blog), $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 $key=>$rs) { + while(!$rs->EOF) { + $user = (object)$rs->fields; + if (!$count) { + echo ''; + } + $rs->MoveNext(); + $count++; + filter_user($user, $keywords, $count); + } + } + + if (!$count) { + echo get_string('spamcannotfinduser', 'report_spamcleaner'); + + } else { + echo '
 '.get_string('user','admin').''.get_string('spamdesc', 'report_spamcleaner').''.get_string('spamoperation', 'report_spamcleaner').'
'; + echo '
+ +
'; + } +} +function filter_user($user, $keywords, $count) { + global $CFG; + $image_search = false; + if (in_array('summary)) { + $user->description = '

'.get_string('spamfromblog', 'report_spamcleaner').'

'.$user->summary; + unset($user->summary); + } + if (preg_match('#pixpath.')#', $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; + + 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); + } + + $html .= ''.format_text($user->description, FORMAT_MOODLE).''; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= ''; + return $html; + } else { + return null; + } + + +} + +function print_spamcleaner_javascript() { + global $CFG; + +$sesskey = sesskey(); + +?> + + + diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 73bc0287357..63ffa992387 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -141,6 +141,7 @@ $string['dbmigratewarning2'] = 'Warning: You are about to start the database $string['dbmigrateconnecerror'] = 'Could not connect to the database specified.'; $string['dbmigrateencodingerror'] = 'The database specified has encoding $a rather than required UNICODE/UTF8.
Please specify another.'; $string['dbmigratepostgres'] = 'It seems that you are using PostgreSQL as the database server. To continue the migration process you need to manually create a new database with encoding \"UNICODE\"(PostgreSQL 7) or \"UTF8\" (PostgreSQL 8) to store the migrated data. Please enter your new database connection settings below to continue:'; +$string['deleteuser'] = 'Delete user'; $string['density'] = 'Density'; $string['download'] = 'Download'; $string['edithelpdocs'] = 'Edit help documents'; @@ -169,6 +170,7 @@ $string['helpupcominglookahead'] = 'How many days in the future does the calenda $string['helpupcomingmaxevents'] = 'How many (maximum) upcoming events are shown to users by default?'; $string['helpweekenddays'] = 'Which days of the week are treated as \"weekend\" and shown with a different colour?'; $string['iconvrecommended'] = 'Installing the optional ICONV library is highly recommended in order to improve site performance, particularly if your site is supporting non-latin languages.'; +$string['ignore'] = 'Ignore'; $string['importlangreminder'] = 'The database migration process is commencing. You will need to log in again for the upgrade to take effect. Please install unicode language packs as soon as possible from Admin->Lang->Lang Import Utility after the database migration process is completed. '; $string['importtimezones'] = 'Update complete list of timezones'; $string['importtimezonescount'] = '$a->count entries imported from $a->source'; @@ -235,6 +237,7 @@ $string['stickyblocksduplicatenotice'] = 'If any block you add here is already p $string['stickyblockspagetype'] = 'Page type to configure'; $string['stickyblocksmymoodle'] = 'My moodle'; $string['stickyblockscourseview'] = 'Course page'; +$string['spamcleaner'] = 'Spam cleaner'; $string['releasenoteslink'] = 'For information about this version of Moodle, please see the online Release Notes'; $string['renameerrors'] = 'Errors in renames'; $string['tabselectedtofront'] = 'On tables with tabs, should the row with the currently selected tag be placed at the front'; @@ -257,6 +260,7 @@ Once you do this you can not go back again.

Are you sure you want to upgrade this server to this version?'; $string['upgradingdata'] = 'Upgrading data'; $string['upgradinglogs'] = 'Upgrading logs'; +$string['user'] = 'User'; $string['userrenamed'] = 'User renamed'; $string['useraccountupdated'] = 'User updated'; $string['userscreated'] = 'Users created'; diff --git a/lang/en_utf8/report_spamcleaner.php b/lang/en_utf8/report_spamcleaner.php new file mode 100644 index 00000000000..319eca9d599 --- /dev/null +++ b/lang/en_utf8/report_spamcleaner.php @@ -0,0 +1,17 @@ +
Moodle docs has more information about Reducing spam in Moodle.'; +$string['spamdesc'] = 'Description'; +$string['spamdeleteall'] = 'Delete all these user accounts'; +$string['spamdeleteconfirm'] = 'Are you sure you want to delete this entry? You can not undo this.'; +$string['spamdeleteallconfirm'] = 'Are you sure you want to delete all these user accounts? You can not undo this.'; +$string['spameg'] = 'eg: casino, porn, xxx '; +$string['spamfromblog'] = 'From blog post:'; +$string['spaminvalidresult'] = 'Unknown but invalid result'; +$string['spamoperation'] = 'Operation'; +$string['spamresult'] = 'Results of searching user profiles containing: '; +$string['spamsearch'] = 'Search for these keywords'; +?>