1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139:
<?php
class Register_Notify_Background extends SMF_BackgroundTask
{
public function execute()
{
global $smcFunc, $sourcedir, $modSettings, $language, $scripturl;
require_once($sourcedir . '/Subs-Members.php');
$members = membersAllowedTo('moderate_forum');
require_once($sourcedir . '/Subs-Notify.php');
$prefs = getNotifyPrefs($members, 'member_register', true);
$alert_bits = array(
'alert' => self::RECEIVE_NOTIFY_ALERT,
'email' => self::RECEIVE_NOTIFY_EMAIL,
);
$notifies = array();
foreach ($prefs as $member => $pref_option)
{
foreach ($alert_bits as $type => $bitvalue)
if ($pref_option['member_register'] & $bitvalue)
$notifies[$type][] = $member;
}
if (!empty($notifies['alert']))
{
$insert_rows = array();
foreach ($notifies['alert'] as $member)
{
$insert_rows[] = array(
'alert_time' => $this->_details['time'],
'id_member' => $member,
'id_member_started' => $this->_details['new_member_id'],
'member_name' => $this->_details['new_member_name'],
'content_type' => 'member',
'content_id' => $this->_details['new_member_id'],
'content_action' => 'register_' . $this->_details['notify_type'],
'is_read' => 0,
'extra' => '',
);
}
$smcFunc['db_insert']('insert',
'{db_prefix}user_alerts',
array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int',
'member_name' => 'string', 'content_type' => 'string', 'content_id' => 'int',
'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
$insert_rows,
array('id_alert')
);
updateMemberData($notifies['alert'], array('alerts' => '+'));
}
if (!empty($notifies['email']))
{
require_once($sourcedir . '/Subs-Post.php');
require_once($sourcedir . '/ScheduledTasks.php');
loadEssentialThemeData();
$emails = array();
$request = $smcFunc['db_query']('', '
SELECT id_member, lngfile, email_address
FROM {db_prefix}members
WHERE id_member IN ({array_int:members})',
array(
'members' => $notifies['email'],
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (empty($row['lngfile']))
$row['lngfile'] = $language;
$emails[$row['lngfile']][$row['id_member']] = $row['email_address'];
}
$smcFunc['db_free_result']($request);
foreach ($emails as $this_lang => $recipients)
{
$replacements = array(
'USERNAME' => $this->_details['new_member_name'],
'PROFILELINK' => $scripturl . '?action=profile;u=' . $this->_details['new_member_id']
);
$emailtype = 'admin_notify';
if ($this->_details['notify_type'] == 'approval')
{
$replacements['APPROVALLINK'] = $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve';
$emailtype .= '_approval';
}
$emaildata = loadEmailTemplate($emailtype, $replacements, empty($modSettings['userLanguage']) ? $language : $this_lang);
foreach ($recipients as $id_member => $email_address)
sendmail($email_address, $emaildata['subject'], $emaildata['body'], null, 'newmember' . $this->_details['new_member_id'], $emaildata['is_html'], 0);
}
}
return true;
}
}
?>