[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/inc/tasks/ -> massmail.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  // Disallow direct access to this file for security reasons
  12  if(!defined("IN_MYBB"))
  13  {
  14      die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  15  }
  16  
  17  require_once  MYBB_ROOT."/inc/functions_massmail.php";
  18  require_once  MYBB_ROOT."inc/datahandlers/pm.php";
  19  
  20  function task_massmail($task)
  21  {
  22      global $db, $mybb, $lang, $plugins;
  23  
  24      $query = $db->simple_select("massemails", "*", "senddate <= '".TIME_NOW."' AND status IN (1,2)");
  25      while($mass_email = $db->fetch_array($query))
  26      {
  27          if(is_object($plugins))
  28          {
  29              $args = array(
  30                  'task' => &$task,
  31                  'mass_email' => &$mass_email
  32              );
  33              $plugins->run_hooks('task_massmail', $args);
  34          }
  35  
  36          if($mass_email['status'] == 1)
  37          {
  38              $db->update_query("massemails", array('status' => 2), "mid='{$mass_email['mid']}'");
  39          }
  40  
  41          $sentcount = 0;
  42  
  43          if(!$mass_email['perpage'])
  44          {
  45              $mass_email['perpage'] = 50;
  46          }
  47  
  48          if(strpos($mass_email['htmlmessage'], '<br />') === false && strpos($mass_email['htmlmessage'], '<br>') === false)
  49          {
  50              $mass_email['htmlmessage'] = nl2br($mass_email['htmlmessage']);
  51          }
  52  
  53          $mass_email['orig_message'] = $mass_email['message'];
  54          $mass_email['orig_htmlmessage'] = $mass_email['htmlmessage'];
  55  
  56          // Need to perform the search to fetch the number of users we're emailing
  57          $member_query = build_mass_mail_query(my_unserialize($mass_email['conditions']));
  58  
  59          $count_query = $db->simple_select("users u", "COUNT(uid) AS num", $member_query);
  60          $mass_email['totalcount'] = $db->fetch_field($count_query, "num");
  61  
  62          $query2 = $db->simple_select("users u", "u.uid, u.language, u.pmnotify, u.lastactive, u.username, u.email", $member_query, array('limit_start' => $mass_email['sentcount'], 'limit' => $mass_email['perpage'], 'order_by' => 'u.uid', 'order_dir' => 'asc'));
  63          while($user = $db->fetch_array($query2))
  64          {
  65              $replacement_fields = array(
  66                  "{uid}" => $user['uid'],
  67                  "{username}" => $user['username'],
  68                  "{email}" => $user['email'],
  69                  "{bbname}" => $mybb->settings['bbname'],
  70                  "{bburl}" => $mybb->settings['bburl'],
  71                  "[".$lang->massmail_username."]" => $user['username'],
  72                  "[".$lang->email_addr."]" => $user['email'],
  73                  "[".$lang->board_name."]" => $mybb->settings['bbname'],
  74                  "[".$lang->board_url."]" => $mybb->settings['bburl']
  75              );
  76  
  77              foreach($replacement_fields as $find => $replace)
  78              {
  79                  $mass_email['message'] = str_replace($find, $replace, $mass_email['message']);
  80                  $mass_email['htmlmessage'] = str_replace($find, $replace, $mass_email['htmlmessage']);
  81              }
  82  
  83              // Private Message
  84              if($mass_email['type'] == 1)
  85              {
  86                  $pm_handler = new PMDataHandler();
  87                  $pm_handler->admin_override = true;
  88  
  89                  $pm = array(
  90                      "subject" => $mass_email['subject'],
  91                      "message" => $mass_email['message'],
  92                      "fromid" => $mass_email['uid'],
  93                      "options" => array("savecopy" => 0),
  94                  );
  95  
  96                  $pm['to'] = explode(",", $user['username']);
  97                  $pm_handler->set_data($pm);
  98                  if(!$pm_handler->validate_pm())
  99                  {
 100                      $friendly_errors = implode('\n', $pm_handler->get_friendly_errors());
 101                      add_task_log($task, $lang->sprintf($lang->task_massmail_ran_errors, htmlspecialchars_uni($user['username']), $friendly_errors));
 102                      $friendly_errors = "";
 103                  }
 104                  else
 105                  {
 106                      $pm_handler->insert_pm();
 107                  }
 108              }
 109              // Normal Email
 110              else
 111              {
 112                  switch($mass_email['format'])
 113                  {
 114                      case 2:
 115                          $format = "both";
 116                          $text_message = $mass_email['message'];
 117                          $mass_email['message'] = $mass_email['htmlmessage'];
 118                          break;
 119                      case 1:
 120                          $format = "html";
 121                          $text_message = "";
 122                          $mass_email['message'] = $mass_email['htmlmessage'];
 123                          break;
 124                      default:
 125                          $format = "text";
 126                          $text_message = "";
 127                  }
 128                  my_mail($user['email'], $mass_email['subject'], $mass_email['message'], "", "", "", false, $format, $text_message);
 129              }
 130              ++$sentcount;
 131  
 132              $mass_email['message'] = $mass_email['orig_message'];
 133              $mass_email['htmlmessage'] = $mass_email['orig_htmlmessage'];
 134          }
 135  
 136          $update_array = array();
 137  
 138          $update_array['sentcount'] = $mass_email['sentcount'] + $sentcount;
 139          $update_array['totalcount'] = $mass_email['totalcount'];
 140  
 141          if($update_array['sentcount'] >= $mass_email['totalcount'])
 142          {
 143              $update_array['status'] = 3;
 144          }
 145  
 146          $db->update_query("massemails", $update_array, "mid='{$mass_email['mid']}'");
 147      }
 148  
 149      add_task_log($task, $lang->task_massmail_ran);
 150  }


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