/** * tests a private link retrieval submission and send the link or sets an error * * @return null */ private static function _process_retrieval() { /* * we check a transient based on the user's IP; if the user tries more than 3 * times per day to get a private ID, they are blocked for 24 hours */ $max_tries = Participants_Db::current_user_has_plugin_role('admin', 'retrieve link') ? 10000 : 3; // give the plugin admin unlimited tries $transient = self::$prefix . 'retrieve-count-' . str_replace('.', '', $_SERVER['REMOTE_ADDR']); $count = get_transient($transient); if ($count === false) { set_transient($transient, 1, 60 * 60 * 24); } if ($count > $max_tries) { // too many tries, come back tomorrow error_log('Participants Database Plugin: IP blocked for too many retrieval attempts from IP ' . $_SERVER['REMOTE_ADDR'] . ' in 24-hour period.'); return; } $count++; set_transient($transient, $count, 60 * 60 * 24); $column = self::plugin_setting('retrieve_link_identifier', 'email'); if (!isset($_POST[$column]) || empty($_POST[$column])) { self::$validation_errors->add_error($column, 'empty'); return; } // a value was submitted, try to find a record with it //$match_id = self::_get_participant_id_by_term($column, $_POST[$column]); $match_id = self::find_record_match($column, $_POST); if (!is_object(self::$validation_errors)) { self::$validation_errors = new PDb_FormValidation(); } if ($match_id === false) { self::$validation_errors->add_error($column, 'identifier'); return; } else { $participant_values = self::get_participant($match_id); } $retrieve_link_email = new stdClass(); $retrieve_link_email->body_template = self::set_filter('translate_string', self::plugin_setting('retrieve_link_email_body')); $retrieve_link_email->subject = self::set_filter('translate_string', self::plugin_setting('retrieve_link_email_subject')); $retrieve_link_email->recipient = $participant_values[self::plugin_setting('primary_email_address_field', 'email')]; /** * @version 1.6 * * filter pdb-before_send_retrieve_link_email */ self::set_filter('before_send_retrieve_link_email', $retrieve_link_email); if (!empty($retrieve_link_email->recipient)) { $body = self::proc_tags($retrieve_link_email->body_template, $match_id); $sent = wp_mail($retrieve_link_email->recipient, self::proc_tags($retrieve_link_email->subject, $match_id), self::plugin_setting('html_email') ? self::process_rich_text($body) : $body, self::$email_headers); if (false === $sent) { error_log(__METHOD__ . ' sending returned false'); } } else { error_log(__METHOD__ . ' primary email address field undefined'); } if (self::plugin_setting_is_true('send_retrieve_link_notify_email')) { $body = self::proc_tags(self::plugin_setting('retrieve_link_notify_body'), $match_id); $sent = wp_mail(self::plugin_setting('email_signup_notify_addresses'), self::proc_tags(self::plugin_setting('retrieve_link_notify_subject'), $match_id, 'all'), self::plugin_setting('html_email') ? self::process_rich_text($body) : $body, self::$email_headers); } //self::$validation_errors->add_error('', 'success'); $_POST['action'] = 'success'; return; }
/** * tests a private link retrieval submission and send the link or sets an error * * @return null */ private static function _process_retrieval() { /* * we check a transient based on the user's IP; if the user tries more than 3 * times per day to get a private ID, they are blocked for 24 hours */ setup_userdata(); $transient = self::$prefix . 'retrieve-count-' . str_replace('.', '', $_SERVER['REMOTE_ADDR']); $count = get_transient($transient); $max_tries = current_user_can(Participants_Db::$plugin_options['plugin_admin_capability']) ? 100 : 3; // give the plugin admin unlimited tries if ($count > 0 and $count <= $max_tries) { // ok, they have a few more tries... } elseif ($count > $max_tries) { // too many tries, come back tomorrow error_log('Participants Database Plugin: IP blocked for too many retrieval attempts in 24-hour period: ' . $_SERVER['REMOTE_ADDR']); return; } else { // first time through... $count = 0; } $count++; set_transient($transient, $count, 60 * 60 * 24); $column = self::get_column(self::$plugin_options['retrieve_link_identifier']); if (!isset($_POST[$column->name]) || empty($_POST[$column->name])) { self::$validation_errors->add_error($column->name, 'empty'); return; } // a value was submitted, try to find a record with it $participant_id = self::_get_participant_id_by_term($column->name, $_POST[$column->name]); if (!is_object(self::$validation_errors)) { self::$validation_errors = new PDb_FormValidation(); } if ($participant_id === false) { self::$validation_errors->add_error($column->name, 'identifier'); return; } else { $participant_values = self::get_participant($participant_id); } if (!empty(Participants_Db::$plugin_options['primary_email_address_field'])) { $body = self::proc_tags(self::$plugin_options['retrieve_link_email_body'], $participant_id); $sent = wp_mail($participant_values[Participants_Db::$plugin_options['primary_email_address_field']], self::proc_tags(self::$plugin_options['retrieve_link_email_subject'], $participant_id), Participants_Db::$plugin_options['html_email'] ? self::process_rich_text($body) : $body, self::$email_headers); if (false === $sent) { error_log(__METHOD__ . ' sending returned false'); } } else { error_log(__METHOD__ . ' primary email address field undefined'); } if (self::$plugin_options['send_retrieve_link_notify_email'] != 0) { $body = self::proc_tags(self::$plugin_options['retrieve_link_notify_body'], $participant_id); $sent = wp_mail(self::$plugin_options['email_signup_notify_addresses'], self::proc_tags(self::$plugin_options['retrieve_link_notify_subject'], $participant_id, 'all'), Participants_Db::$plugin_options['html_email'] ? self::process_rich_text($body) : $body, self::$email_headers); } //self::$validation_errors->add_error('', 'success'); $_POST['action'] = 'success'; return; }