/** * Add a new alert. * * @param MybbStuff_MyAlerts_Entity_Alert $alert The alert to add. * * @return $this */ public function addAlert(MybbStuff_MyAlerts_Entity_Alert $alert) { $fromUser = $alert->getFromUser(); if (!isset($fromUser['uid'])) { $alert->setFromUser($this->mybb->user); } $alertType = $alert->getType(); $usersWhoWantAlert = $this->doUsersWantAlert($alert->getType(), array($alert->getUserId())); if ($alertType->getEnabled() && (!empty($usersWhoWantAlert) || !$alertType->getCanBeUserDisabled())) { if ($alertType->getCode() === 'quoted') { // If there is already an alert queued to the user of the type // 'post_threadauthor', don't add the alert. $extraDetails = $alert->getExtraDetails(); $tid = $extraDetails['tid']; if (isset(static::$alertQueue['post_threadauthor_' . $alert->getUserId() . '_' . $tid])) { return $this; } } $passToHook = array('alertManager' => &$this, 'alert' => &$alert); $this->plugins->run_hooks('myalerts_alert_manager_add_alert', $passToHook); // Basic duplicate checking by overwrite - only one alert for each alert type/object id combination static::$alertQueue[$alert->getType()->getCode() . '_' . $alert->getUserId() . '_' . $alert->getObjectId()] = $alert; } return $this; }
/** * Check a user against the 3rd party service to determine whether they are a spammer. * * @param string $username The username of the user to check. * @param string $email The email address of the user to check. * @param string $ip_address The IP address sof the user to check. * @return bool Whether the user is considered a spammer or not. * @throws Exception Thrown when there's an error fetching from the StopForumSpam API or when the data cannot be decoded. */ public function is_user_a_spammer($username = '', $email = '', $ip_address = '') { $is_spammer = false; $confidence = 0; if (filter_var($email, FILTER_VALIDATE_EMAIL) && filter_var($ip_address, FILTER_VALIDATE_IP)) { $username_encoded = urlencode($username); $email_encoded = urlencode($email); $check_url = sprintf(self::STOP_FORUM_SPAM_API_URL_FORMAT, $username_encoded, $email_encoded, $ip_address); $result = fetch_remote_file($check_url); if ($result !== false) { $result_json = @json_decode($result); if ($result_json != null && !isset($result_json->error)) { if ($this->check_usernames && $result_json->username->appears) { $confidence += $result_json->username->confidence; } if ($this->check_emails && $result_json->email->appears) { $confidence += $result_json->email->confidence; } if ($this->check_ips && $result_json->ip->appears) { $confidence += $result_json->ip->confidence; } if ($confidence > $this->min_weighting_before_spam) { $is_spammer = true; } } else { throw new Exception('stopforumspam_error_decoding'); } } else { throw new Exception('stopforumspam_error_retrieving'); } } if ($this->plugins) { $params = array('username' => &$username, 'email' => &$email, 'ip_address' => &$ip_address, 'is_spammer' => &$is_spammer, 'confidence' => &$confidence); $this->plugins->run_hooks('stopforumspam_check_spammer_pre_return', $params); } if ($this->log_blocks && $is_spammer) { log_spam_block($username, $email, $ip_address, array('confidence' => (double) $confidence)); } return $is_spammer; }
/** * Show a user their settings for MyAlerts. * * @param MyBB $mybb MyBB core object. * @param DB_MySQLi|DB_MySQL $db Database object. * @param MyLanguage $lang Language object. * @param pluginSystem $plugins MyBB plugin system. * @param templates $templates Template manager. * @param array $theme Details about the current theme. */ function myalerts_alert_settings($mybb, $db, $lang, $plugins, $templates, $theme) { $alertTypes = MybbStuff_MyAlerts_AlertTypeManager::getInstance()->getAlertTypes(); if (strtolower($mybb->request_method) == 'post') { // Saving alert type settings $disabledAlerts = array(); foreach ($alertTypes as $alertCode => $alertType) { if (!isset($_POST[$alertCode]) && $alertType['can_be_user_disabled']) { $disabledAlerts[] = (int) $alertType['id']; } } if ($disabledAlerts != $mybb->user['myalerts_disabled_alert_types']) { // Different settings, so update $jsonEncodedDisabledAlerts = json_encode($disabledAlerts); $db->update_query('users', array('myalerts_disabled_alert_types' => $db->escape_string($jsonEncodedDisabledAlerts)), 'uid=' . (int) $mybb->user['uid']); } redirect('alerts.php?action=settings', $lang->myalerts_settings_updated, $lang->myalerts_settings_updated_title); } else { // Displaying alert type settings form $content = ''; global $headerinclude, $header, $footer, $usercpnav; add_breadcrumb($lang->myalerts_settings_page_title, 'alerts.php?action=settings'); require_once __DIR__ . '/inc/functions_user.php'; usercp_menu(); foreach ($alertTypes as $key => $value) { if ($value['enabled'] && $value['can_be_user_disabled']) { $altbg = alt_trow(); $tempKey = 'myalerts_setting_' . $key; $plugins->run_hooks('myalerts_load_lang'); $langline = $lang->{$tempKey}; $checked = ''; if (!in_array($value['id'], $mybb->user['myalerts_disabled_alert_types'])) { $checked = ' checked="checked"'; } eval("\$alertSettings .= \"" . $templates->get('myalerts_setting_row') . "\";"); } } eval("\$content = \"" . $templates->get('myalerts_settings_page') . "\";"); output_page($content); } }