<!-- contactform --> into an entry or page.' );
}
private static function default_options()
{
return array(
'send_to' => $_SERVER['SERVER_ADMIN'],
'subject_prefix' => _t( '[CONTACT FORM] ' ),
'show_form_on_success' => 1,
'success_msg' => _t( 'Thank you for your feedback. I\'ll get back to you as soon as possible.' ),
'error_msg' => _t( 'The following errors occurred with the information you submitted. Please correct them and re-submit the form.' )
);
}
public function action_plugin_activation( $file )
{
if ( Plugins::id_from_file( $file ) == Plugins::id_from_file( __FILE__ ) ) {
foreach ( self::default_options() as $name => $value ) {
Options::set( self::OPTION_NAME . '__' . $name, $value );
}
}
}
// helper function to return option values
public static function get( $name ) {
return Options::get( self::OPTION_NAME . '__' . $name );
}
public function set_priorities()
{
return array(
'filter_post_content_out' => 11
);
}
/* Set up options */
public function filter_plugin_config( $actions, $plugin_id )
{
if ( $plugin_id == $this->plugin_id() ) {
$actions[]= _t('Configure');
}
return $actions;
}
public function action_plugin_ui( $plugin_id, $action )
{
if ( $plugin_id == $this->plugin_id() ) {
switch ( $action ) {
case _t('Configure') :
$ui = new FormUI( self::OPTION_NAME );
// Add a text control for the address you want the email sent to
$send_to = $ui->append( 'text', 'send_to', 'option:jambo__send_to', _t( 'Where To Send Email: ' ) );
$send_to->add_validator( 'validate_required' );
// Add a text control for the prefix to the subject field
$subject_prefix = $ui->append( 'text', 'subject_prefix', 'option:jambo__subject_prefix', _t( 'Subject Prefix: ' ) );
$subject_prefix->add_validator( 'validate_required' );
$show_form_on_success = $ui->append( 'checkbox', 'show_form_on_success', 'option:jambo__show_form_on_success', _t( 'Show Contact Form After Sending?: ' ) );
// Add a text control for the prefix to the success message
$success_msg = $ui->append( 'textarea', 'success_msg', 'option:jambo__success_msg', _t( 'Success Message: ' ) );
$success_msg->add_validator( 'validate_required' );
// Add a text control for the prefix to the subject field
$error_msg = $ui->append( 'textarea', 'error_msg', 'option:jambo__error_msg', _t( 'Error Message: ') );
$error_msg->add_validator( 'validate_required' );
$ui->append( 'submit', 'save', 'Save' );
$ui->out();
break;
}
}
}
public function filter_rewrite_rules( $rules )
{
$rules[] = new RewriteRule(array(
'name' => 'jambo',
'parse_regex' => '/^jambo\/send\/(?PPlease enable cookies in your browser.
')); } if ( ! $this->verify_OSA( $handlervars['osa'], $handlervars['osa_time'] ) ) { ob_end_clean(); header('HTTP/1.1 403 Forbidden'); die(_t('You are submitting the form too fast and look like a spam bot.
')); } if ( empty( $email['name'] ) ) { $email['valid']= false; $email['errors']['name']= _t( 'Your Name is a required field.' ); } if ( empty( $email['email'] ) ) { $email['valid']= false; $email['errors']['email']= _t( 'Your Email is a required field.' ); } // validate email addy as per RFC2822 and RFC2821 with a little exception (see: http://www.regular-expressions.info/email.html) elseif( !preg_match("@^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*\@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$@i", $email['email'] ) ) { $email['valid']= false; $email['errors']['email']= _t( 'Your Email must be a valid email address.' ); } if ( empty( $email['message'] ) ) { $email['valid']= false; $email['errors']['message']= _t( 'Your Remarks is a required field.' ); } if( $email['valid'] !== false ) { $comment = new Comment( array( 'name' => $email['name'], 'email' => $email['email'], 'content' => $email['message'], 'ip' => sprintf("%u", ip2long( $_SERVER['REMOTE_ADDR'] ) ), 'post_id' => ( isset( $post ) ? $post->id : 0 ), ) ); $handlervars['ccode'] = $handlervars['jcode']; $_SESSION['comments_allowed'][] = $handlervars['ccode']; Plugins::act('comment_insert_before', $comment); if( Comment::STATUS_SPAM == $comment->status ) { ob_end_clean(); header('HTTP/1.1 403 Forbidden'); die(_t('Your attempted contact appears to be spam. If it wasn\'t, return to the previous page and try again.
')); } } return $email; } /** * Get a 10-digit hex code that identifies the user submitting the feedback * @param The IP address of the commenter * @return A 10-digit hex code **/ private function get_code( $ip = '' ) { if( $ip == '' ) { $ip = ip2long($_SERVER['REMOTE_ADDR']); } $code = substr(md5( Options::get('GUID') . 'more salt' . $ip ), 0, 10); $code = Plugins::filter('jambo_code', $code, $ip); return $code; } /** * Verify a 10-digit hex code that identifies the user submitting the feedback * @param The IP address of the commenter * @return True if the code is valid, false if not **/ private function verify_code( $suspect_code, $ip = '' ) { return ( $suspect_code == $this->get_code( $ip ) ); } private function get_OSA( $time ) { $osa = 'osa_' . substr( md5( $time . Options::get( 'GUID' ) . self::VERSION ), 0, 10 ); $osa = Plugins::filter('jambo_OSA', $osa, $time); return $osa; } private function verify_OSA( $osa, $time ) { if ( $osa == $this->get_OSA( $time ) ) { if ( ( time() > ($time + 5) ) && ( time() < ($time + 5*60) ) ) { return true; } } return false; } private function OSA( $vars ) { if ( array_key_exists( 'osa', $vars ) && array_key_exists( 'osa_time', $vars ) ) { $osa = $vars['osa']; $time = $vars['osa_time']; } else { $time = time(); $osa = $this->get_OSA( $time ); } return "\n\n"; } /** * */ public static function input( $type, $name, $label, $vars = array() ) { $style = ( array_key_exists( 'errors', $vars ) && array_key_exists( $name, $vars['errors'] ) ) ? 'class="input-warning"' : ''; $value = array_key_exists( $name, $vars ) ? $vars[$name] : ''; switch ( $type ) { default: case 'text': return ''; break; case 'textarea': return ''; break; } } private function get_form() { if ( $this->theme instanceof Theme && $this->theme->template_exists( 'jambo.form' ) ) { $vars = array_merge( User::commenter(), Session::get_set( 'jambo_email' ) ); $this->theme->jambo = new stdClass; $jambo = $this->theme->jambo; $jambo->form_action = URL::get('jambo'); $jambo->success_msg = self::get( 'success_msg' ); $jambo->error_msg = self::get('error_msg'); $jambo->show_form = true; $jambo->success = false; $jambo->error = false; if ( array_key_exists( 'valid', $vars ) && $vars['valid'] ) { $jambo->success = true; $jambo->show_form = self::get( 'show_form_on_success' ); } if ( array_key_exists( 'errors', $vars ) ) { $jambo->error = true; $jambo->errors = $vars['errors']; } $jambo->name = $this->input( 'text', 'name', 'Your Name: (Required)', $vars ); $jambo->email = $this->input( 'text', 'email', 'Your Email: (Required)', $vars ); $jambo->subject = $this->input( 'text', 'subject', 'Subject: ', $vars ); $jambo->message = $this->input( 'textarea', 'message', 'Your Remarks: (Required)', $vars ); $jambo->osa = $this->OSA( $vars ); return $this->theme->fetch( 'jambo.form' ); } return null; } } ?>