[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

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

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  function task_userpruning($task)
  12  {
  13      global $db, $lang, $mybb, $cache, $plugins;
  14  
  15      if($mybb->settings['enablepruning'] != 1)
  16      {
  17          return;
  18      }
  19  
  20      // Are we pruning by posts?
  21      if($mybb->settings['enableprunebyposts'] == 1)
  22      {
  23          $in_usergroups = array();
  24          $users = array();
  25  
  26          $usergroups = $cache->read('usergroups');
  27          foreach($usergroups as $gid => $usergroup)
  28          {
  29              // Exclude admin, moderators, super moderators, banned
  30              if($usergroup['canmodcp'] == 1 || $usergroup['cancp'] == 1 || $usergroup['issupermod'] == 1 || $usergroup['isbannedgroup'] == 1)
  31              {
  32                  continue;
  33              }
  34              $in_usergroups[] = $gid;
  35          }
  36  
  37          // If we're not pruning unactivated users, then remove them from the criteria
  38          if($mybb->settings['pruneunactived'] == 0)
  39          {
  40              $key = array_search('5', $in_usergroups);
  41              unset($in_usergroups[$key]);
  42          }
  43  
  44          $prunepostcount = (int)$mybb->settings['prunepostcount'];
  45  
  46          $regdate = TIME_NOW-((int)$mybb->settings['dayspruneregistered']*24*60*60);
  47  
  48          $usergroups = $db->escape_string(implode(',', $in_usergroups));
  49  
  50          $query = $db->simple_select('users', 'uid', "regdate<={$regdate} AND postnum<={$prunepostcount} AND usergroup IN({$usergroups})");
  51          while($uid = $db->fetch_field($query, 'uid'))
  52          {
  53              $users[$uid] = $uid;
  54          }
  55  
  56          if($users && $mybb->settings['prunepostcountall'])
  57          {
  58              $query = $db->simple_select('posts', 'uid, COUNT(pid) as posts', "uid IN ('".implode("','", $users)."') AND visible>0", array('group_by' => 'uid'));
  59              while($user = $db->fetch_array($query))
  60              {
  61                  if($user['posts'] >= $prunepostcount)
  62                  {
  63                      unset($users[$user['uid']]);
  64                  }
  65              }
  66          }
  67      }
  68  
  69      // Are we pruning unactivated users?
  70      if($mybb->settings['pruneunactived'] == 1)
  71      {
  72          $regdate = TIME_NOW-((int)$mybb->settings['dayspruneunactivated']*24*60*60);
  73          $query = $db->simple_select("users", "uid", "regdate<={$regdate} AND usergroup='5'");
  74          while($user = $db->fetch_array($query))
  75          {
  76              $users[$user['uid']] = $user['uid'];
  77          }
  78      }
  79  
  80      if(is_object($plugins))
  81      {
  82          $args = array(
  83              'task' => &$task,
  84              'in_usergroups' => &$in_usergroups,
  85              'users' => &$users,
  86          );
  87          $plugins->run_hooks('task_userpruning', $args);
  88      }
  89  
  90      if(!empty($users))
  91      {
  92          // Set up user handler.
  93          require_once  MYBB_ROOT.'inc/datahandlers/user.php';
  94          $userhandler = new UserDataHandler('delete');
  95  
  96          // Delete the prunned users
  97          $userhandler->delete_user($users, $mybb->settings['prunethreads']);
  98      }
  99  
 100      add_task_log($task, $lang->task_userpruning_ran);
 101  }


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref