Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
/**
 * 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);
    }
}
 /**
  * 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;
 }
Ejemplo n.º 4
0
        $db = new DB_MySQLi();
        break;
    default:
        $db = new DB_MySQL();
}
// Check if our DB engine is loaded
if (!extension_loaded($db->engine)) {
    // Throw our super awesome db loading error
    $mybb->trigger_generic_error("sql_load_error");
}
require_once MYBB_ROOT . "inc/class_templates.php";
$templates = new templates();
require_once MYBB_ROOT . "inc/class_datacache.php";
$cache = new datacache();
require_once MYBB_ROOT . "inc/class_plugins.php";
$plugins = new pluginSystem();
// Include our base data handler class
require_once MYBB_ROOT . "inc/datahandler.php";
// Connect to Database
define("TABLE_PREFIX", $config['database']['table_prefix']);
$db->connect($config['database']);
$db->set_table_prefix(TABLE_PREFIX);
$db->type = $config['database']['type'];
// Language initialisation
require_once MYBB_ROOT . "inc/class_language.php";
$lang = new MyLanguage();
$lang->set_path(MYBB_ROOT . "inc/languages");
// Load cache
$cache->cache();
// Load Settings
if (file_exists(MYBB_ROOT . "inc/settings.php")) {
Ejemplo n.º 5
0
/**
 * Runs the shutdown items after the page has been sent to the browser.
 *
 */
function run_shutdown()
{
    global $config, $db, $cache, $plugins, $error_handler, $shutdown_functions, $shutdown_queries, $done_shutdown, $mybb;
    if ($done_shutdown == true || !$config || $error_handler->has_errors) {
        return;
    }
    // Missing the core? Build
    if (!is_object($mybb)) {
        require_once MYBB_ROOT . "inc/class_core.php";
        $mybb = new MyBB();
        // Load the settings
        require MYBB_ROOT . "inc/settings.php";
        $mybb->settings =& $settings;
    }
    // If our DB has been deconstructed already (bad PHP 5.2.0), reconstruct
    if (!is_object($db)) {
        if (!isset($config) || empty($config['database']['type'])) {
            require MYBB_ROOT . "inc/config.php";
        }
        if (isset($config)) {
            require_once MYBB_ROOT . "inc/db_" . $config['database']['type'] . ".php";
            switch ($config['database']['type']) {
                case "sqlite":
                    $db = new DB_SQLite();
                    break;
                case "pgsql":
                    $db = new DB_PgSQL();
                    break;
                case "mysqli":
                    $db = new DB_MySQLi();
                    break;
                default:
                    $db = new DB_MySQL();
            }
            $db->connect($config['database']);
            define("TABLE_PREFIX", $config['database']['table_prefix']);
            $db->set_table_prefix(TABLE_PREFIX);
        }
    }
    // Cache object deconstructed? reconstruct
    if (!is_object($cache)) {
        require_once MYBB_ROOT . "inc/class_datacache.php";
        $cache = new datacache();
        $cache->cache();
    }
    // And finally.. plugins
    if (!is_object($plugins) && !defined("NO_PLUGINS") && !($mybb->settings['no_plugins'] == 1)) {
        require_once MYBB_ROOT . "inc/class_plugins.php";
        $plugins = new pluginSystem();
        $plugins->load();
    }
    // We have some shutdown queries needing to be run
    if (is_array($shutdown_queries)) {
        // Loop through and run them all
        foreach ($shutdown_queries as $query) {
            $db->query($query);
        }
    }
    // Run any shutdown functions if we have them
    if (is_array($shutdown_functions)) {
        foreach ($shutdown_functions as $function) {
            call_user_func_array($function['function'], $function['arguments']);
        }
    }
    $done_shutdown = true;
}