[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/inc/tasks/ -> delayedmoderation.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$
  10   */
  11  
  12  function task_delayedmoderation($task)
  13  {
  14      global $db, $lang;
  15      
  16      require_once  MYBB_ROOT."inc/class_moderation.php";
  17      $moderation = new Moderation;
  18      
  19      require_once  MYBB_ROOT."inc/class_custommoderation.php";
  20      $custommod = new CustomModeration;
  21  
  22      // Iterate through all our delayed moderation actions
  23      $query = $db->simple_select("delayedmoderation", "*", "delaydateline <= '".TIME_NOW."'");
  24      while($delayedmoderation = $db->fetch_array($query))
  25      {
  26          $tids = explode(',', $delayedmoderation['tids']);
  27          $input = unserialize($delayedmoderation['inputs']);
  28          
  29          if(my_strpos($delayedmoderation['type'], "modtool") !== false)
  30          {
  31              list(, $custom_id) = explode('_', $delayedmoderation['type'], 2);
  32              $custommod->execute($custom_id, $tids);
  33          }
  34          else
  35          {
  36              switch($delayedmoderation['type'])
  37              {
  38                  case "openclosethread":
  39                      $closed_tids = $open_tids = array();
  40                      $query2 = $db->simple_select("threads", "tid,closed", "tid IN({$delayedmoderation['tids']})");
  41                      while($thread = $db->fetch_array($query2))
  42                      {
  43                          if($thread['closed'] == 1)
  44                          {
  45                              $closed_tids[] = $thread['tid'];
  46                          }
  47                          else
  48                          {
  49                              $open_tids[] = $thread['tid'];
  50                          }
  51                      }
  52                      
  53                      if(!empty($closed_tids))
  54                      {
  55                          $moderation->open_threads($closed_tids);
  56                      }
  57                      
  58                      if(!empty($open_tids))
  59                      {
  60                          $moderation->close_threads($open_tids);
  61                      }
  62                      break;
  63                  case "deletethread":
  64                      foreach($tids as $tid)
  65                      {
  66                          $moderation->delete_thread($tid);
  67                      }
  68                      break;
  69                  case "move":
  70                      foreach($tids as $tid)
  71                      {
  72                          $moderation->move_thread($tid, $input['new_forum']);
  73                      }
  74                      break;
  75                  case "stick":
  76                      $unstuck_tids = $stuck_tids = array();
  77                      $query2 = $db->simple_select("threads", "tid,sticky", "tid IN({$delayedmoderation['tids']})");
  78                      while($thread = $db->fetch_array($query2))
  79                      {
  80                          if($thread['sticky'] == 1)
  81                          {
  82                              $stuck_tids[] = $thread['tid'];
  83                          }
  84                          else
  85                          {
  86                              $unstuck_tids[] = $thread['tid'];
  87                          }
  88                      }
  89                      
  90                      if(!empty($stuck_tids))
  91                      {
  92                          $moderation->unstick_threads($stuck_tids);
  93                      }
  94                      
  95                      if(!empty($unstuck_tids))
  96                      {
  97                          $moderation->stick_threads($unstuck_tids);
  98                      }
  99                      break;
 100                  case "merge":
 101                      if(count($tids) != 1)
 102                      {
 103                          continue;
 104                      }
 105                      
 106                      // explode at # sign in a url (indicates a name reference) and reassign to the url
 107                      $realurl = explode("#", $input['threadurl']);
 108                      $input['threadurl'] = $realurl[0];
 109                      
 110                      // Are we using an SEO URL?
 111                      if(substr($input['threadurl'], -4) == "html")
 112                      {
 113                          // Get thread to merge's tid the SEO way
 114                          preg_match("#thread-([0-9]+)?#i", $input['threadurl'], $threadmatch);
 115                          preg_match("#post-([0-9]+)?#i", $input['threadurl'], $postmatch);
 116                          
 117                          if($threadmatch[1])
 118                          {
 119                              $parameters['tid'] = $threadmatch[1];
 120                          }
 121                          
 122                          if($postmatch[1])
 123                          {
 124                              $parameters['pid'] = $postmatch[1];
 125                          }
 126                      }
 127                      else
 128                      {
 129                          // Get thread to merge's tid the normal way
 130                          $splitloc = explode(".php", $input['threadurl']);
 131                          $temp = explode("&", my_substr($splitloc[1], 1));
 132  
 133                          if(!empty($temp))
 134                          {
 135                              for($i = 0; $i < count($temp); $i++)
 136                              {
 137                                  $temp2 = explode("=", $temp[$i], 2);
 138                                  $parameters[$temp2[0]] = $temp2[1];
 139                              }
 140                          }
 141                          else
 142                          {
 143                              $temp2 = explode("=", $splitloc[1], 2);
 144                              $parameters[$temp2[0]] = $temp2[1];
 145                          }
 146                      }
 147                      
 148                      if($parameters['pid'] && !$parameters['tid'])
 149                      {
 150                          $query = $db->simple_select("posts", "*", "pid='".intval($parameters['pid'])."'");
 151                          $post = $db->fetch_array($query);
 152                          $mergetid = $post['tid'];
 153                      }
 154                      else if($parameters['tid'])
 155                      {
 156                          $mergetid = $parameters['tid'];
 157                      }
 158                      
 159                      $mergetid = intval($mergetid);
 160                      
 161                      $query = $db->simple_select("threads", "*", "tid='".intval($mergetid)."'");
 162                      $mergethread = $db->fetch_array($query);
 163                      
 164                      if(!$mergethread['tid'])
 165                      {
 166                          continue;
 167                      }
 168                      
 169                      if($mergetid == $delayedmoderation['tid'])
 170                      {
 171                          // sanity check
 172                          continue;
 173                      }
 174                      
 175                      if($input['subject'])
 176                      {
 177                          $subject = $input['subject'];
 178                      }
 179                      else
 180                      {
 181                          $query = $db->simple_select("thread", "subject", "tid='{$delayedmoderation['tids']}'");
 182                          $subject = $db->fetch_field($query, "subject");
 183                      }
 184  
 185                      $moderation->merge_threads($mergetid, $delayedmoderation['tids'], $subject);
 186                      break;
 187                  case "removeredirects":
 188                      foreach($tids as $tid)
 189                      {
 190                          $moderation->remove_redirects($tid);
 191                      }
 192                      break;
 193                  case "removesubscriptions":
 194                      $moderation->remove_thread_subscriptions($tids, true);
 195                      break;
 196                  case "approveunapprovethread":
 197                      $approved_tids = $unapproved_tids = array();
 198                      $query2 = $db->simple_select("threads", "tid,visible", "tid IN({$delayedmoderation['tids']})");
 199                      while($thread = $db->fetch_array($query2))
 200                      {
 201                          if($thread['visible'] == 1)
 202                          {
 203                              $approved_tids[] = $thread['tid'];
 204                          }
 205                          else
 206                          {
 207                              $unapproved_tids[] = $thread['tid'];
 208                          }
 209                      }
 210                      
 211                      if(!empty($approved_tids))
 212                      {
 213                          $moderation->unapprove_threads($approved_tids);
 214                      }
 215                      
 216                      if(!empty($unapproved_tids))
 217                      {
 218                          $moderation->approve_threads($unapproved_tids);
 219                      }
 220                      break;
 221              }
 222          }
 223          
 224          $db->delete_query("delayedmoderation", "did='{$delayedmoderation['did']}'");
 225      }
 226      
 227      add_task_log($task, $lang->task_delayedmoderation_ran);
 228  }
 229  ?>


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