[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/inc/tasks/ -> userpruning.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id: userpruning.php 5297 2010-12-28 22:01:14Z Tomm $
  10   */
  11  
  12  function task_userpruning($task)
  13  {
  14      global $db, $lang, $mybb, $cache;
  15      
  16      if($mybb->settings['enablepruning'] != 1)
  17      {
  18          return;
  19      }
  20      
  21      // Are we pruning by posts?
  22      if($mybb->settings['enableprunebyposts'] == 1)
  23      {
  24          $in_usergroups = array();
  25          $users = array();
  26          
  27          $usergroups = $cache->read("usergroups");
  28          foreach($usergroups as $gid => $usergroup)
  29          {
  30              // Exclude admin, moderators, super moderators, banned
  31              if($usergroup['canmodcp'] == 1 || $usergroup['cancp'] == 1 || $usergroup['issupermod'] == 1 || $usergroup['isbannedgroup'] == 1)
  32              {
  33                  continue;
  34              }
  35              $in_usergroups[] = $gid;
  36          }
  37          
  38          // If we're not pruning unactivated users, then remove them from the criteria
  39          if($mybb->settings['pruneunactived'] == 0)
  40          {
  41              $key = array_search('5', $in_usergroups);
  42              unset($in_usergroups[$key]);
  43          }
  44          
  45          $regdate = TIME_NOW-(intval($mybb->settings['dayspruneregistered'])*24*60*60);
  46          $query = $db->simple_select("users", "uid", "regdate <= ".intval($regdate)." AND postnum <= ".intval($mybb->settings['prunepostcount'])." AND usergroup IN(".$db->escape_string(implode(',', $in_usergroups)).")");
  47          while($user = $db->fetch_array($query))
  48          {
  49              $users[$user['uid']] = $user['uid'];
  50          }
  51      }
  52      
  53      // Are we pruning unactivated users?
  54      if($mybb->settings['pruneunactived'] == 1)
  55      {
  56          $regdate = TIME_NOW-(intval($mybb->settings['dayspruneunactivated'])*24*60*60);
  57          $query = $db->simple_select("users", "uid", "regdate <= ".intval($regdate)." AND usergroup='5'");
  58          while($user = $db->fetch_array($query))
  59          {
  60              $users[$user['uid']] = $user['uid'];
  61          }
  62      }
  63      
  64      if(!empty($users))
  65      {
  66          $uid_list = $db->escape_string(implode(',', $users));
  67          
  68          // Delete the user
  69          $db->delete_query("userfields", "ufid IN({$uid_list})");
  70          $db->delete_query("privatemessages", "uid IN({$uid_list})");
  71          $db->delete_query("events", "uid IN({$uid_list})");
  72          $db->delete_query("moderators", "id IN({$uid_list}) AND isgroup='0'");
  73          $db->delete_query("forumsubscriptions", "uid IN({$uid_list})");
  74          $db->delete_query("threadsubscriptions", "uid IN({$uid_list})");
  75          $db->delete_query("sessions", "uid IN({$uid_list})");
  76          $db->delete_query("banned", "uid IN({$uid_list})");
  77          $db->delete_query("threadratings", "uid IN({$uid_list})");
  78          $db->delete_query("joinrequests", "uid IN({$uid_list})");
  79          $db->delete_query("awaitingactivation", "uid IN({$uid_list})");
  80          $query = $db->delete_query("users", "uid IN({$uid_list})");
  81          $num_deleted = $db->affected_rows($query);
  82  
  83          // Remove any of the user(s) uploaded avatars
  84          $query = $db->simple_select("users", "avatar", "uid IN ({$uid_list}) AND avatartype = 'upload'");
  85          if($db->num_rows($query))
  86          {
  87              while($avatar = $db->fetch_field($query, "avatar"))
  88              {
  89                  $avatar = substr($avatar, 2, -20);
  90                  @unlink(MYBB_ROOT.$avatar);
  91              }
  92          }
  93  
  94          // Are we removing the posts/threads of a user?
  95          if($mybb->settings['prunethreads'] == 1)
  96          {
  97              require_once  MYBB_ROOT."inc/class_moderation.php";
  98              $moderation = new Moderation();
  99  
 100              // Threads
 101              $query = $db->simple_select("threads", "tid", "uid IN({$uid_list})");
 102              while($thread = $db->fetch_array($query))
 103              {
 104                  $moderation->delete_thread($thread['tid']);
 105              }
 106  
 107              // Posts
 108              $query = $db->simple_select("posts", "pid", "uid IN({$uid_list})");
 109              while($post = $db->fetch_array($query))
 110              {
 111                  $moderation->delete_post($post['pid']);
 112              }
 113          }
 114          else
 115          {
 116              // We're just updating the UID
 117              $db->update_query("posts", array('uid' => 0), "uid IN({$uid_list})");
 118          }
 119  
 120          // Update forum stats
 121          update_stats(array('numusers' => '-'.intval($num_deleted)));
 122          
 123          $cache->update_moderators();
 124          $cache->update_banned();
 125      }
 126      
 127      add_task_log($task, $lang->task_userpruning_ran);
 128  }
 129  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1