2 defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
5 Plugin Name: danixland contact form
6 Description: A simple yet powerful contact form plugin
7 Plugin URI: https://danix.xyz/?p=3577
9 Author: Danilo 'danix' Macrì
10 Author URI: http://danix.xyz
12 License URI: https://www.gnu.org/licenses/gpl-2.0.html
13 Domain Path: /languages
17 global $dnxcf_form_version;
18 $dnxcf_form_version = '1.2';
21 * Add plugin i18n domain: dnxcf
24 load_plugin_textdomain('dnxcf', false, dirname( plugin_basename( __FILE__
) ) . '/languages/');
27 * Let's load our helper file ( DB initialization and stuff )
30 require( dirname( __FILE__
) . '/include/dnxcf_helper.php' );
33 * Check / create the database for the plugin data
36 register_activation_hook( __FILE__
, 'dnxcf_set_db_version' );
37 register_activation_hook( __FILE__
, 'dnxcf_db_check' );
40 require_once( dirname(__FILE__
) . '/include/dnxcf_settings.php' );
43 // Add Genericons, used in the contact form.
44 function dnxcf_scripts() {
45 wp_enqueue_style( 'dnxcf_genericons', plugins_url( '/style/genericons/genericons.css', __FILE__
), array(), '3.4.1' );
46 wp_enqueue_style( 'dnxcf_helper_style', plugins_url( '/style/dnxcf_style.css', __FILE__
), array(), '4.4.2' );
48 add_action( 'wp_enqueue_scripts', 'dnxcf_scripts' );
51 * This function displays a google map by adding a js script to the wp_footer
54 function dnxcf_gmap_enqueue() {
55 global $dnxcf_options;
56 $dnxcf_options = get_option('dnxcf_options');
57 $latitude = $dnxcf_options['dnxcf_latitude'];
58 $longitude = $dnxcf_options['dnxcf_longitude'];
59 $apikey = $dnxcf_options['dnxcf_apikey'];
60 $sitename = get_bloginfo('name');
61 $siteurl = get_bloginfo('url');
62 $sitemsg = $dnxcf_options['dnxcf_gmap_message'];
63 $visitus = __('Come visit us', 'dnxcf');
65 $popup_content = <<< DNX6655788EOT
69 <h1 id
="firstHeading" class="firstHeading">$sitename</h1
>
70 <div id
="bodyContent">
72 <p
><a href
="$siteurl">$visitus</a
></p
>
79 var location
= {lat
: <?php
echo $latitude; ?
>, lng
: <?php
echo $longitude; ?
> };
80 var map
= new google
.maps
.Map( document
.getElementById('dnxcf_gmap'), {zoom
: 15, center
: location
} );
82 contentString
= <?php
echo json_encode($popup_content); ?
>;
83 var infowindow
= new google
.maps
.InfoWindow( {content
: contentString
} );
85 var marker
= new google
.maps
.Marker( {position
: location
, map
: map
, animation
: google
.maps
.Animation
.DROP
} );
86 marker
.addListener('click', function() { infowindow
.open(map
, marker
); });
90 <script src
="https://maps.googleapis.com/maps/api/js?key=<?php echo $apikey; ?>&callback=initMap" async defer
></script
>
94 global $dnxcf_options;
95 $dnxcf_options = get_option('dnxcf_options');
96 if ( ! empty($dnxcf_options['dnxcf_apikey']) ) {
97 add_action('wp_footer', 'dnxcf_gmap_enqueue');
102 * The actual contact form displayed using a shortcode
105 add_shortcode( 'dnx_contactform', 'dnxcf_return_form');
108 * we use output buffer so that the form will stay at the bottom of content
109 * allowing the user to write some text in the body of the page before
110 * displaying the form with the shortcode
113 function dnxcf_return_form() {
115 dnxcf_display_form();
116 $output = ob_get_contents();
122 * Here we handle the input/output flow
125 function dnxcf_display_form() {
126 global $dnxcf_form_version, $dnxcf_options;
127 $dnxcf_options = get_option('dnxcf_options');
129 $dnxcf_pid = md5($dnxcf_options['dnxcf_pid_key']);
130 $dnxcf_vers_id = md5($dnxcf_form_version);
131 $dnxcf_date_id = md5(date('TOZ'));
132 $dnxcf_eml_id = md5($dnxcf_options['dnxcf_recv_email']);
133 $dnxcf_form_id = $dnxcf_pid . $dnxcf_vers_id . $dnxcf_eml_id . $dnxcf_date_id;
134 $dnxcf_form_id = strtoupper(md5($dnxcf_form_id));
135 $dnxcf_form_id = 'ID' . $dnxcf_form_id . 'DNX';
136 $dnxcf_send_value = trim( strtolower( 'submit_' . md5($dnxcf_form_id) ) );
138 if ( isset( $_POST[$dnxcf_send_value] ) ) { // the form has been submitted
139 $dnxcf_email_output = ( '1' == $dnxcf_options['dnxcf_content_type'] ) ?
'text/plain' : 'text/html';
140 $dnxcf_form_name = 'dnxcf_form_' . $dnxcf_pid;
141 $dnxcf_form_action = 'dnxcf_submit_' . $dnxcf_form_id;
142 // valid html used to validate the comment content.
155 // security checks before submitting the form
156 if ( $_SERVER['REQUEST_URI'] == $_POST['_wp_http_referer'] && wp_verify_nonce( $_POST[ $dnxcf_form_name], $dnxcf_form_action ) ) {
158 $dnxcf_posted = array();
159 // let's gather some data about the user submitting the form
160 $dnxcf_ltd = trim(strip_tags(stripslashes(current_time("mysql"))));
161 $dnxcf_hst = trim(strip_tags(stripslashes(getenv("REMOTE_ADDR"))));
162 $dnxcf_ua = trim(strip_tags(stripslashes($_SERVER['HTTP_USER_AGENT'])));
163 // our posted options, arranged in one nice array
164 $dnxcf_posted['dnxcf_name'] = sanitize_text_field($_POST['dnxcf_name']);
165 $dnxcf_posted['dnxcf_email'] = sanitize_email($_POST['dnxcf_email']);
166 $dnxcf_posted['dnxcf_website'] = esc_url($_POST['dnxcf_website']);
167 $dnxcf_posted['dnxcf_subject'] = sanitize_text_field($_POST['dnxcf_subject']);
168 $dnxcf_posted['dnxcf_message'] = wp_kses($_POST['dnxcf_message'], $valid_html);
169 // let's begin with our email data, like receiver email, subject ecc.
170 $dnxcf_to = $dnxcf_options['dnxcf_recv_email'];
171 $dnxcf_headers = "Reply-To: " . $dnxcf_posted['dnxcf_email'];
172 $dnxcf_subject = __('Contact from "', 'dnxcf') . get_bloginfo('name') . '" - ' . $dnxcf_posted['dnxcf_subject'];
174 // check for our content type and arrange our info accordingly
175 if ( 'text/html' == $dnxcf_email_output ) {
176 require( apply_filters( 'dnxcf_template_file', dirname( __FILE__
) . '/include/dnxcf_mail_template_danixland.php') );
177 $dnxcf_email_data = array(
178 'ownname' => $dnxcf_options['dnxcf_recv_name'],
179 'site' => get_bloginfo('name'),
180 'time' => $dnxcf_ltd,
181 'host' => $dnxcf_hst,
184 $dnxcf_message = dnxcf_email_content( $dnxcf_email_data, $dnxcf_posted );
185 } else { // content_type is set to text/plain
186 $dnxcf_message = sprintf(
187 __("Hello \"%s\",\nyou are being contacted by %s on %s.\n%s has provided the following informations:\n\tEmail:\t\t%s\n\tWebsite:\t%s\n\tMessage:\n\n%s", 'dnxcf'),
188 $dnxcf_options['dnxcf_recv_name'],
189 $dnxcf_posted['dnxcf_name'],
190 get_bloginfo('name'),
191 $dnxcf_posted['dnxcf_name'],
192 $dnxcf_posted['dnxcf_email'],
193 $dnxcf_posted['dnxcf_website'],
194 $dnxcf_posted['dnxcf_message']
196 $dnxcf_message .= "\n\n##-----------#-----------#-----------##\n\n";
197 $dnxcf_message .= sprintf(
198 __("We have also collected the following informations:\n\tBrowser:\t%s\n\tTime:\t\t%s\n\tIP Address:\t%s\n", 'dnxcf'),
203 } // end check for mail_content_type
204 $dnxcf_mailed = wp_mail( $dnxcf_to, $dnxcf_subject, $dnxcf_message, $dnxcf_headers );
205 if ( $dnxcf_mailed ) { ?
>
206 <p id
="dnxcf_success"><?php
_e('your email was sent successfully. Here\'s the data you submitted via our form.', 'dnxcf' ); ?
></p
>
209 <dt
><?php
_e('Your Name:', 'dnxcf'); ?
></dt
>
210 <dd
><?php
echo $dnxcf_posted['dnxcf_name']; ?
></dd
>
211 <dt
><?php
_e('Your e-mail:', 'dnxcf'); ?
></dt
>
212 <dd
><?php
echo $dnxcf_posted['dnxcf_email']; ?
></dd
>
213 <dt
><?php
_e('Subject of your message:', 'dnxcf'); ?
></dt
>
214 <dd
><?php
echo $dnxcf_posted['dnxcf_subject']; ?
></dd
>
215 <dt
><?php
_e('Text of your Message:', 'dnxcf'); ?
></dt
>
216 <dd
><blockquote
><?php
echo wptexturize( wpautop( $dnxcf_posted['dnxcf_message'] ) ); ?
></blockquote
></dd
>
219 <p
><?php
_e('we also collected some data for tecnical reasons.', 'dnxcf'); ?
></p
>
222 <dt
><?php
_e('Your IP address:', 'dnxcf'); ?
></dt
>
223 <dd
><?php
echo $dnxcf_hst; ?
></dd
>
224 <dt
><?php
_e('Your Browser:', 'dnxcf'); ?
></dt
>
225 <dd
><?php
echo $dnxcf_ua; ?
></dd
>
229 <p id
="dnxcf_result_failure"><?php
printf( __('there was a problem processing your email. Please contact the <a href="mailto:%s">administrator</a>.', 'dnxcf'), get_bloginfo('admin_email') ); ?
></p
>
233 } else { // Houston we have a problem, spammer detected
234 // we might want to use the data we have and send a mail to the admin just in case...
236 <p id
="dnxcf_spammer"><?php
_e('looks like you don\'t belong here. We don\'t like spammers. Go away now!', 'dnxcf'); ?
></p
>
238 } // end check for wp_nonce
240 } else { // the post hasn't been submitted. Let's show the form
241 global $dnxcf_options;
242 $dnxcf_options = get_option('dnxcf_options');
244 <!-- begin
#dnxcf_form -->
245 <form id
="dnxcf_form" method
="post" action
="<?php echo htmlentities( $_SERVER['REQUEST_URI'] ); ?>">
246 <?php
wp_nonce_field( 'dnxcf_submit_' . $dnxcf_form_id, 'dnxcf_form_' . $dnxcf_pid, true, true );
247 if ( ! empty($dnxcf_options['dnxcf_apikey']) ) : ?
>
248 <h4
><?php
_e('Our location', 'dnxcf'); ?
></h4
>
249 <div id
="dnxcf_gmap"></div
>
251 <p
class="comment-notes"><?php
_e('Required fields are marked ', 'dnxcf'); ?
><span
class="required">*</span
></p
>
252 <fieldset id
="dnxcf_formwrap">
253 <?php
if ( $dnxcf_options['dnxcf_privacy'] ) : ?
>
254 <fieldset id
="dnxcf_privacy">
255 <h4
><?php
_e('Privacy:', 'dnxcf'); ?
></h4
>
256 <div
class="policy"><?php
echo wpautop( wptexturize( $dnxcf_options['dnxcf_privacy'] ) ); ?
></div
>
259 <fieldset id
="dnxcf_personal">
260 <h4
><?php
_e('Personal Informations:', 'dnxcf'); ?
></h4
>
261 <p
class="dnxcf-name">
262 <label
class="genericon genericon-user" for="name"><span
class="screen-reader-text"><?php
_e('Full Name', 'dnxcf'); ?
></span
><span
class="required">*</span
></label
>
263 <input name
="dnxcf_name" id
="name" size
="35" maxlength
="40" type
="text" placeholder
="<?php _e('name', 'dnxcf'); ?>" required autocomplete
="name">
265 <p
class="dnxcf-email">
266 <label
class="genericon genericon-mail" for="email"><span
class="screen-reader-text"><?php
_e('email address', 'dnxcf'); ?
></span
><span
class="required">*</span
></label
>
267 <input name
="dnxcf_email" id
="email" size
="35" maxlength
="50" type
="email" placeholder
="<?php _e('e-mail', 'dnxcf'); ?>" required autocomplete
="email">
269 <p
class="dnxcf-website">
270 <label
for="website" class="genericon genericon-website"><span
class="screen-reader-text"><?php
_e('website', 'dnxcf'); ?
></span
></label
>
271 <input name
="dnxcf_website" id
="website" size
="35" maxlength
="50" type
="url" placeholder
="<?php _e('website', 'dnxcf'); ?>" autocomplete
="url">
274 <fieldset id
="dnxcf_message">
275 <h4
><?php
_e('your message:', 'dnxcf'); ?
></h4
>
276 <p
class="dnxcf-subject">
277 <label
class="genericon genericon-tag" for="subject"><span
class="screen-reader-text"><?php
_e('subject', 'dnxcf'); ?
></span
><span
class="required">*</span
></label
>
278 <select name
="dnxcf_subject" id
="subject" required
>
279 <?php
global $dnxcf_options;
280 $dnxcf_options = get_option('dnxcf_options');
281 $subject_options = $dnxcf_options['dnxcf_subject'];
282 foreach ($subject_options as $option) {
283 echo '<option value="' . $option . '">' . $option . '</option>';
287 <p
class="dnxcf-message">
288 <label
class="genericon genericon-comment" for="message"><span
class="screen-reader-text"><?php
_e('message', 'dnxcf'); ?
></span
><span
class="required">*</span
></label
>
289 <textarea name
="dnxcf_message" id
="message" cols
="60" rows
="12" placeholder
="<?php _e('Comment Here', 'dnxcf'); ?>" required
></textarea
>
292 <fieldset id
="dnxcf_send">
293 <input type
="submit" name
="<?php echo $dnxcf_send_value; ?>" id
="<?php echo $dnxcf_send_value; ?>" value
="<?php _e('send message', 'dnxcf'); ?>">
295 </fieldset
><!-- #formwrap -->
297 <!-- end
#dnxcf_form -->
300 } // end check for post submission
301 } // end dnxcf_display_form()