/** * Validate and sanitize our options before saving to the DB. * * Callback from {@link register_setting()}. * * @param array $input The submitted values from the form * @return array $output The validated values to be inserted into the DB */ public function validate($input) { $messages = false; $output = array(); $output['mode'] = wp_filter_nohtml_kses($input['mode']); // switching from IMAP to inbound email mode if ('inbound' == $output['mode'] && 'imap' == bp_rbe_get_setting('mode')) { // stop RBE if still connected via IMAP if (bp_rbe_is_connected()) { bp_rbe_stop_imap(); } bp_rbe_log('- Operating mode switched to inbound -'); } // check if key is alphanumeric if (ctype_alnum($input['key'])) { $output['key'] = $input['key']; } /** INBOUND-related ***************************************************/ $inbound_provider = wp_filter_nohtml_kses($input['inbound-provider']); if (!empty($inbound_provider)) { $output['inbound-provider'] = $inbound_provider; } $inbound_domain = isset($input['inbound-domain']) ? wp_filter_nohtml_kses($input['inbound-domain']) : ''; if (!empty($inbound_domain)) { $output['inbound-domain'] = $inbound_domain; } /** IMAP-related ******************************************************/ $username = wp_filter_nohtml_kses($input['username']); $password = wp_filter_nohtml_kses($input['password']); if ($email = is_email($input['email'])) { $output['email'] = $email; if ($input['gmail'] == 1) { $output['username'] = $email; } } if (!empty($username)) { $output['username'] = $username; if (is_email($username)) { $output['email'] = $username; } } if (!empty($password)) { $output['password'] = $password; } // check if port is numeric if (is_numeric($input['port'])) { $output['port'] = $input['port']; } // check if address tag is one character if (strlen($input['tag']) == 1) { $output['tag'] = $input['tag']; } // override certain settings if "gmail" setting is true if (!empty($input['gmail']) && $input['gmail'] == 1) { $output['servername'] = 'imap.gmail.com'; $output['port'] = 993; $output['tag'] = '+'; $output['gmail'] = 1; $output['email'] = $username; // use alternate server settings as defined by the user } else { $output['servername'] = wp_filter_nohtml_kses($input['servername']); $output['port'] = absint($input['port']); $output['tag'] = wp_filter_nohtml_kses($input['tag']); $output['gmail'] = 0; } if (is_numeric($input['keepalive']) && $input['keepalive'] < 30) { $output['keepalive'] = $input['keepalive']; } // keepalive for safe mode will never exceed the execution time if (ini_get('safe_mode')) { $output['keepalive'] = $input['keepalive'] = bp_rbe_get_execution_time('minutes'); } // automatically reconnect after keep-alive limit if (!empty($input['keepaliveauto'])) { $output['keepaliveauto'] = 1; } else { $output['keepaliveauto'] = 0; } // do a quick imap check if we have valid credentials to check if ($output['mode'] == 'imap' && !empty($output['servername']) && !empty($output['port']) && !empty($output['username']) && !empty($output['password'])) { if (function_exists('imap_open')) { $imap = BP_Reply_By_Email_Connect::init(array('host' => $output['servername'], 'port' => $output['port'], 'username' => $output['username'], 'password' => $output['password'])); // if connection failed, add an error if ($imap === false) { $errors = imap_errors(); $messages['connect_error'] = sprintf(__('Error: Unable to connect to inbox - %s', 'bp-rbe'), $errors[0]); $output['connect'] = 0; // connection was successful, now close our temporary connection } else { // this tells bp_rbe_is_required_completed() that we're good to go! $output['connect'] = 1; imap_close($imap); } } } // encode the password if (!empty($password)) { $output['password'] = bp_rbe_encode(array('string' => $password, 'key' => wp_salt())); } /**********************************************************************/ /* error time! */ if (strlen($input['tag']) > 1 && !$output['tag']) { $messages['tag_error'] = __('Error: <strong>Address tag</strong> must only be one character.', 'bp-rbe'); } if (!empty($input['port']) && !is_numeric($input['port']) && !$output['port']) { $messages['port_error'] = __('Error: <strong>Port</strong> must be numeric.', 'bp-rbe'); } if (!empty($input['key']) && !$output['key']) { $messages['key_error'] = __('Error: <strong>Key</strong> must only contain letters and / or numbers.', 'bp-rbe'); } if (!empty($input['keepalive']) && !is_numeric($input['keepalive']) && !$output['keepalive']) { $messages['keepalive_error'] = __('Error: <strong>Keep Alive Connection</strong> value must be less than 30.', 'bp-rbe'); } if (is_array($messages)) { $output['messages'] = $messages; } // For sites using an external object cache, make sure they get the new value. // This is all sorts of ugly! :( // I think this is a WP core bug with the WP Settings API... wp_cache_delete('alloptions', 'options'); return $output; }
/** * Replace "Post New Topics via Email" email address to work with bbPress * plugin. * * @param str $querystring Encoded querystring used in the email address * @param int $user_id The user ID * @return str Encoded querystring used in the email address */ public function new_topic_querystring($querystring = '', $user_id = false) { if (empty($user_id)) { $user_id = bp_loggedin_user_id(); } if (empty($user_id)) { return false; } // bundled forums has been disabled and replaced with bbPress plugin if (!class_exists('BP_Forums_Component')) { // setup default string $string = $this->forum_id_param . '=' . bbp_get_forum_id(); // if on a BP group, add an extra param if (bp_is_group()) { $string .= "&{$this->item_id_param}=" . bp_get_current_group_id(); } $querystring = bp_rbe_encode(array('string' => $string, 'param' => $user_id)); } return $querystring; }
/** * Returns the encoded group email address for a user. * Note: Each user gets their own, individual email address per group. * * Takes $user_id and $group_id as parameters. * If no parameters are passed, uses logged in user and current group respectively. * * @since 1.0-beta */ function bp_rbe_groups_get_encoded_email_address($user_id = false, $group_id = false) { $user_id = !$user_id ? bp_loggedin_user_id() : $user_id; $group_id = !$group_id ? bp_get_current_group_id() : $group_id; if (!$user_id || !$group_id) { return false; } $gstring = 'g=' . $group_id; $querystring = apply_filters('bp_rbe_encode_group_querystring', bp_rbe_encode(array('string' => $gstring, 'param' => $user_id)), $user_id, $group_id); return bp_rbe_inject_qs_in_email($querystring . '-new'); }
/** * Get the email address used for the 'Reply-To' email header. * * @since 1.0-RC4 * * @param array $headers Email headers. */ protected function get_reply_to_address($headers = array()) { if (empty($this->listener->item_id)) { return ''; } // Setup our querystring which we'll add to the Reply-To header $querystring = ''; switch ($this->listener->component) { case 'activity': $querystring = "a={$this->listener->item_id}&p={$this->listener->secondary_item_id}"; break; // BP Group Email Subscripton (GES) plugin compatibility // GES will send out group forum emails, so let's setup our param. // BP Group Email Subscripton (GES) plugin compatibility // GES will send out group forum emails, so let's setup our param. case 'forums': $querystring = "t={$this->listener->item_id}&g={$this->listener->secondary_item_id}"; break; case 'messages': $querystring = "m={$this->listener->item_id}"; break; // 3rd party plugins can hook into this // 3rd party plugins can hook into this default: $querystring = apply_filters('bp_rbe_extend_querystring', $querystring, $this->listener); break; } // last chance to disable the querystring with this filter! $querystring = apply_filters('bp_rbe_querystring', $querystring, $this->listener, $headers); // Add our special querystring to the Reply-To header! if (!empty($querystring)) { // Encode the qs // Don't like this? there's a filter for that! $querystring = apply_filters('bp_rbe_encode_querystring', bp_rbe_encode(array('string' => $querystring)), $querystring); // Inject the querystring into the email address $querystring = bp_rbe_inject_qs_in_email($querystring); } return $querystring; }