b96bc758 |
1 | <?php |
244ec72c |
2 | defined( 'ABSPATH' ) || die( 'No script kiddies please!' ); |
b96bc758 |
3 | |
8c3e9b00 |
4 | /* |
b96bc758 |
5 | Plugin Name: danixland contact form |
6 | Description: A simple yet powerful contact form plugin |
7 | Plugin URI: https://danix.xyz/?p=3577 |
244ec72c |
8 | Version: 1.3 |
b96bc758 |
9 | Author: Danilo 'danix' Macrì |
10 | Author URI: http://danix.xyz |
11 | License: GPL2 |
12 | License URI: https://www.gnu.org/licenses/gpl-2.0.html |
13 | Domain Path: /languages |
14 | Text Domain: dnxcf |
15 | */ |
16 | |
17 | global $dnxcf_form_version; |
244ec72c |
18 | $dnxcf_form_version = '1.3'; |
b96bc758 |
19 | |
20 | /** |
21 | * Add plugin i18n domain: dnxcf |
22 | * @since 0.2 |
23 | */ |
8c3e9b00 |
24 | load_plugin_textdomain( 'dnxcf', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
b96bc758 |
25 | |
26 | /** |
27 | * Let's load our helper file ( DB initialization and stuff ) |
28 | * @since 0.2 |
29 | */ |
30 | require( dirname( __FILE__ ) . '/include/dnxcf_helper.php' ); |
31 | |
32 | /** |
33 | * Check / create the database for the plugin data |
34 | * @since 1.1.3 |
35 | */ |
36 | register_activation_hook( __FILE__, 'dnxcf_set_db_version' ); |
37 | register_activation_hook( __FILE__, 'dnxcf_db_check' ); |
38 | |
8c3e9b00 |
39 | if ( is_admin() ) { |
40 | require_once( dirname( __FILE__ ) . '/include/dnxcf_settings.php' ); |
b96bc758 |
41 | } |
42 | |
43 | // Add Genericons, used in the contact form. |
44 | function dnxcf_scripts() { |
244ec72c |
45 | wp_enqueue_style( 'dnxcf_icons', plugins_url( '/style/dnxcf-font.css', __FILE__ ), array(), '1.3' ); |
8c3e9b00 |
46 | wp_enqueue_style( 'dnxcf_helper_style', plugins_url( '/style/dnxcf_style.css', __FILE__ ), array(), '4.4.2' ); |
b96bc758 |
47 | } |
48 | add_action( 'wp_enqueue_scripts', 'dnxcf_scripts' ); |
49 | |
b96bc758 |
50 | /* |
51 | * The actual contact form displayed using a shortcode |
52 | * @since 0.1 |
53 | */ |
8c3e9b00 |
54 | add_shortcode( 'dnx_contactform', 'dnxcf_return_form' ); |
b96bc758 |
55 | |
56 | /* |
57 | * we use output buffer so that the form will stay at the bottom of content |
8c3e9b00 |
58 | * allowing the user to write some text in the body of the page before |
b96bc758 |
59 | * displaying the form with the shortcode |
60 | * @since 0.5 |
61 | */ |
62 | function dnxcf_return_form() { |
8c3e9b00 |
63 | ob_start(); |
64 | dnxcf_display_form(); |
65 | $output = ob_get_contents(); |
66 | ob_end_clean(); |
67 | return $output; |
b96bc758 |
68 | } |
69 | |
70 | /* |
71 | * Here we handle the input/output flow |
72 | * @since 0.2 |
73 | */ |
74 | function dnxcf_display_form() { |
8c3e9b00 |
75 | global $dnxcf_form_version, $dnxcf_options; |
76 | $dnxcf_options = get_option( 'dnxcf_options' ); |
b96bc758 |
77 | |
8c3e9b00 |
78 | $dnxcf_pid = md5( $dnxcf_options['dnxcf_pid_key'] ); |
79 | $dnxcf_vers_id = md5( $dnxcf_form_version ); |
80 | $dnxcf_date_id = md5( date( 'TOZ' ) ); |
81 | $dnxcf_eml_id = md5( $dnxcf_options['dnxcf_recv_email'] ); |
82 | $dnxcf_form_id = $dnxcf_pid . $dnxcf_vers_id . $dnxcf_eml_id . $dnxcf_date_id; |
83 | $dnxcf_form_id = strtoupper( md5( $dnxcf_form_id ) ); |
84 | $dnxcf_form_id = 'ID' . $dnxcf_form_id . 'DNX'; |
85 | $dnxcf_send_value = trim( strtolower( 'submit_' . md5( $dnxcf_form_id ) ) ); |
b96bc758 |
86 | |
8c3e9b00 |
87 | if ( isset( $_POST[ $dnxcf_send_value ] ) ) { // the form has been submitted |
88 | $dnxcf_email_output = ( '1' == $dnxcf_options['dnxcf_content_type'] ) ? 'text/plain' : 'text/html'; |
89 | $dnxcf_form_name = 'dnxcf_form_' . $dnxcf_pid; |
90 | $dnxcf_form_action = 'dnxcf_submit_' . $dnxcf_form_id; |
91 | // valid html used to validate the comment content. |
92 | $valid_html = array( |
93 | 'a' => array( |
94 | 'href' => array(), |
95 | 'title' => array(), |
96 | ), |
97 | 'br' => array(), |
98 | 'em' => array(), |
99 | 'strong' => array(), |
100 | 'p' => array(), |
101 | 'pre' => array(), |
102 | 'code' => array(), |
103 | ); |
104 | // security checks before submitting the form |
105 | if ( $_SERVER['REQUEST_URI'] == $_POST['_wp_http_referer'] && wp_verify_nonce( $_POST[ $dnxcf_form_name ], $dnxcf_form_action ) ) { |
b96bc758 |
106 | |
244ec72c |
107 | // nonce and referrer are correct. Let's verify if the honeypot field is empty. |
108 | if ( empty( $_POST['dnxcf_pagelikes'] ) ) { |
b96bc758 |
109 | |
244ec72c |
110 | $dnxcf_posted = array(); |
111 | // let's gather some data about the user submitting the form |
112 | $dnxcf_ltd = trim( strip_tags( stripslashes( current_time( 'mysql' ) ) ) ); |
113 | $dnxcf_hst = trim( strip_tags( stripslashes( getenv( 'REMOTE_ADDR' ) ) ) ); |
114 | $dnxcf_ua = trim( strip_tags( stripslashes( $_SERVER['HTTP_USER_AGENT'] ) ) ); |
115 | // our posted options, arranged in one nice array |
116 | $dnxcf_posted['dnxcf_name'] = sanitize_text_field( $_POST['dnxcf_name'] ); |
117 | $dnxcf_posted['dnxcf_email'] = sanitize_email( $_POST['dnxcf_email'] ); |
118 | $dnxcf_posted['dnxcf_website'] = esc_url( $_POST['dnxcf_website'] ); |
119 | $dnxcf_posted['dnxcf_subject'] = sanitize_text_field( $_POST['dnxcf_subject'] ); |
120 | $dnxcf_posted['dnxcf_message'] = wp_kses( $_POST['dnxcf_message'], $valid_html ); |
121 | // let's begin with our email data, like receiver email, subject ecc. |
122 | $dnxcf_to = $dnxcf_options['dnxcf_recv_email']; |
123 | $dnxcf_headers = 'Reply-To: ' . $dnxcf_posted['dnxcf_email']; |
124 | $dnxcf_subject = __( 'Contact from "', 'dnxcf' ) . get_bloginfo( 'name' ) . '" - ' . $dnxcf_posted['dnxcf_subject']; |
b96bc758 |
125 | |
244ec72c |
126 | // check for our content type and arrange our info accordingly |
127 | if ( 'text/html' == $dnxcf_email_output ) { |
128 | require( apply_filters( 'dnxcf_template_file', dirname( __FILE__ ) . '/include/dnxcf_mail_template_danixland.php' ) ); |
129 | $dnxcf_email_data = array( |
130 | 'ownname' => $dnxcf_options['dnxcf_recv_name'], |
131 | 'site' => get_bloginfo( 'name' ), |
132 | 'time' => $dnxcf_ltd, |
133 | 'host' => $dnxcf_hst, |
134 | 'ua' => $dnxcf_ua, |
135 | ); |
136 | $dnxcf_message = dnxcf_email_content( $dnxcf_email_data, $dnxcf_posted ); |
137 | } else { // content_type is set to text/plain |
138 | $dnxcf_message = sprintf( |
139 | __( "Hello \"%1\$s\",\nyou are being contacted by %2\$s on %3\$s.\n%4\$s has provided the following informations:\n\tEmail:\t\t%5\$s\n\tWebsite:\t%6\$s\n\tMessage:\n\n%7\$s", 'dnxcf' ), |
140 | $dnxcf_options['dnxcf_recv_name'], |
141 | $dnxcf_posted['dnxcf_name'], |
142 | get_bloginfo( 'name' ), |
143 | $dnxcf_posted['dnxcf_name'], |
144 | $dnxcf_posted['dnxcf_email'], |
145 | $dnxcf_posted['dnxcf_website'], |
146 | $dnxcf_posted['dnxcf_message'] |
147 | ); |
148 | $dnxcf_message .= "\n\n##-----------#-----------#-----------##\n\n"; |
149 | $dnxcf_message .= sprintf( |
150 | __( "We have also collected the following informations:\n\tBrowser:\t%1\$s\n\tTime:\t\t%2\$s\n\tIP Address:\t%3\$s\n", 'dnxcf' ), |
151 | $dnxcf_ua, |
152 | $dnxcf_ltd, |
153 | $dnxcf_hst |
154 | ); |
155 | } // end check for mail_content_type |
156 | |
157 | $dnxcf_mailed = wp_mail( $dnxcf_to, $dnxcf_subject, $dnxcf_message, $dnxcf_headers ); |
158 | |
159 | if ( $dnxcf_mailed ) { |
160 | ?> |
161 | <p id="dnxcf_success"><?php _e( 'your email was sent successfully. Here\'s the data you submitted via our form.', 'dnxcf' ); ?></p> |
162 | <p> |
163 | <dl> |
164 | <dt><?php _e( 'Your Name:', 'dnxcf' ); ?></dt> |
165 | <dd><?php echo $dnxcf_posted['dnxcf_name']; ?></dd> |
166 | <dt><?php _e( 'Your e-mail:', 'dnxcf' ); ?></dt> |
167 | <dd><?php echo $dnxcf_posted['dnxcf_email']; ?></dd> |
168 | <dt><?php _e( 'Subject of your message:', 'dnxcf' ); ?></dt> |
169 | <dd><?php echo $dnxcf_posted['dnxcf_subject']; ?></dd> |
170 | <dt><?php _e( 'Text of your Message:', 'dnxcf' ); ?></dt> |
171 | <dd><blockquote><?php echo wptexturize( wpautop( $dnxcf_posted['dnxcf_message'] ) ); ?></blockquote></dd> |
172 | </dl> |
173 | </p> |
174 | <p><?php _e( 'we also collected some data for tecnical reasons.', 'dnxcf' ); ?></p> |
175 | <p> |
176 | <dl> |
177 | <dt><?php _e( 'Your IP address:', 'dnxcf' ); ?></dt> |
178 | <dd><?php echo $dnxcf_hst; ?></dd> |
179 | <dt><?php _e( 'Your Browser:', 'dnxcf' ); ?></dt> |
180 | <dd><?php echo $dnxcf_ua; ?></dd> |
181 | </dl> |
182 | </p> |
183 | <?php } else { ?> |
184 | <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> |
185 | <?php } |
186 | } else { |
187 | // dnxcf_pagelikes was not empty. This is a problem. ?> |
188 | <p id="dnxcf_spammer"><?php _e( 'looks like you don\'t belong here. We don\'t like spammers. Go away now!', 'dnxcf' ); ?></p> |
189 | <?php } |
8c3e9b00 |
190 | } else { // Houston we have a problem, spammer detected |
191 | // we might want to use the data we have and send a mail to the admin just in case... |
192 | ?> |
193 | <p id="dnxcf_spammer"><?php _e( 'looks like you don\'t belong here. We don\'t like spammers. Go away now!', 'dnxcf' ); ?></p> |
194 | <?php |
195 | } // end check for wp_nonce |
196 | } else { // the post hasn't been submitted. Let's show the form |
197 | global $dnxcf_options; |
198 | $dnxcf_options = get_option( 'dnxcf_options' ); |
199 | ?> |
200 | <!-- begin #dnxcf_form --> |
244ec72c |
201 | <form id="dnxcf_form" method="post" action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>"> |
202 | <?php wp_nonce_field( 'dnxcf_submit_' . $dnxcf_form_id, 'dnxcf_form_' . $dnxcf_pid, true, true ); ?> |
8c3e9b00 |
203 | <p class="comment-notes"><?php _e( 'Required fields are marked ', 'dnxcf' ); ?><span class="required">*</span></p> |
244ec72c |
204 | <section id="dnxcf_formwrap"> |
8c3e9b00 |
205 | <?php if ( $dnxcf_options['dnxcf_privacy'] ) : ?> |
244ec72c |
206 | <section id="dnxcf_privacy"> |
8c3e9b00 |
207 | <h4><?php _e( 'Privacy:', 'dnxcf' ); ?></h4> |
208 | <div class="policy"><?php echo wpautop( wptexturize( $dnxcf_options['dnxcf_privacy'] ) ); ?></div> |
244ec72c |
209 | </section> |
8c3e9b00 |
210 | <?php endif; ?> |
244ec72c |
211 | <section id="dnxcf_personal"> |
8c3e9b00 |
212 | <h4><?php _e( 'Personal Informations:', 'dnxcf' ); ?></h4> |
244ec72c |
213 | <p class="dnxcf-form-name"> |
214 | <label class="dnxcf-user" for="name"><span class="screen-reader-text"><?php _e( 'Full Name', 'dnxcf' ); ?></span><span class="required">*</span></label> |
8c3e9b00 |
215 | <input name="dnxcf_name" id="name" size="35" maxlength="40" type="text" placeholder="<?php _e( 'name', 'dnxcf' ); ?>" required autocomplete="name"> |
216 | </p> |
244ec72c |
217 | <p class="dnxcf-form-email"> |
218 | <label class="dnxcf-mail" for="email"><span class="screen-reader-text"><?php _e( 'email address', 'dnxcf' ); ?></span><span class="required">*</span></label> |
8c3e9b00 |
219 | <input name="dnxcf_email" id="email" size="35" maxlength="50" type="email" placeholder="<?php _e( 'e-mail', 'dnxcf' ); ?>" required autocomplete="email"> |
220 | </p> |
244ec72c |
221 | <p class="dnxcf-form-website"> |
222 | <label for="website" class="dnxcf-website"><span class="screen-reader-text"><?php _e( 'website', 'dnxcf' ); ?></span></label> |
8c3e9b00 |
223 | <input name="dnxcf_website" id="website" size="35" maxlength="50" type="url" placeholder="<?php _e( 'website', 'dnxcf' ); ?>" autocomplete="url"> |
224 | </p> |
244ec72c |
225 | <p class="dnxcf-form-pagelikes"> |
226 | <label for="pagelikes" class="dnxcf-like"><span class="screen-reader-text"><?php _e( 'pages you liked', 'dnxcf' ); ?></span></label> |
227 | <input name="dnxcf_pagelikes" id="pagelikes" size="35" maxlength="50" type="text" placeholder="<?php _e( 'what pages you liked?', 'dnxcf' ); ?>" autocomplete="off"> |
228 | </p> |
229 | </section> |
230 | <section id="dnxcf_message"> |
8c3e9b00 |
231 | <h4><?php _e( 'your message:', 'dnxcf' ); ?></h4> |
244ec72c |
232 | <p class="dnxcf-form-subject"> |
233 | <label class="dnxcf-tag" for="subject"><span class="screen-reader-text"><?php _e( 'subject', 'dnxcf' ); ?></span><span class="required">*</span></label> |
8c3e9b00 |
234 | <select name="dnxcf_subject" id="subject" required> |
235 | <?php |
236 | global $dnxcf_options; |
237 | $dnxcf_options = get_option( 'dnxcf_options' ); |
238 | $subject_options = $dnxcf_options['dnxcf_subject']; |
239 | foreach ( $subject_options as $option ) { |
240 | echo '<option value="' . $option . '">' . $option . '</option>'; |
241 | } |
242 | ?> |
243 | </select> |
244 | </p> |
244ec72c |
245 | <p class="dnxcf-form-message"> |
246 | <label class="dnxcf-message" for="message"><span class="screen-reader-text"><?php _e( 'message', 'dnxcf' ); ?></span><span class="required">*</span></label> |
8c3e9b00 |
247 | <textarea name="dnxcf_message" id="message" cols="60" rows="12" placeholder="<?php _e( 'Comment Here', 'dnxcf' ); ?>" required></textarea> |
248 | </p> |
244ec72c |
249 | </section> |
250 | <section id="dnxcf_send"> |
8c3e9b00 |
251 | <input type="submit" name="<?php echo $dnxcf_send_value; ?>" id="<?php echo $dnxcf_send_value; ?>" value="<?php _e( 'send message', 'dnxcf' ); ?>"> |
244ec72c |
252 | </section> |
253 | </section><!-- #formwrap --> |
8c3e9b00 |
254 | </form> |
255 | <!-- end #dnxcf_form --> |
256 | <?php |
b96bc758 |
257 | |
8c3e9b00 |
258 | } // end check for post submission |
b96bc758 |
259 | } // end dnxcf_display_form() |
8c3e9b00 |
260 | ?> |