function gwolle_gb_frontend_write($shortcode_atts) { global $gwolle_gb_errors, $gwolle_gb_error_fields, $gwolle_gb_messages, $gwolle_gb_data; $html5 = current_theme_supports('html5'); $output = ''; // Set data up for refilling an already submitted form that had errors $name = ''; $origin = ''; $email = ''; $website = ''; $antispam = ''; $content = ''; // Auto-fill the form if the user is already logged in $user_id = get_current_user_id(); // returns 0 if no current user if ($user_id > 0) { $userdata = get_userdata($user_id); if (is_object($userdata)) { if (isset($userdata->display_name)) { $name = $userdata->display_name; } else { $name = $userdata->user_login; } $email = $userdata->user_email; $website = $userdata->user_url; } } // Only show old data when there are errors if ($gwolle_gb_errors) { if (is_array($gwolle_gb_data) && !empty($gwolle_gb_data)) { if (isset($gwolle_gb_data['author_name'])) { $name = stripslashes($gwolle_gb_data['author_name']); } if (isset($gwolle_gb_data['author_origin'])) { $origin = stripslashes($gwolle_gb_data['author_origin']); } if (isset($gwolle_gb_data['author_email'])) { $email = stripslashes($gwolle_gb_data['author_email']); } if (isset($gwolle_gb_data['author_website'])) { $website = stripslashes($gwolle_gb_data['author_website']); } if (isset($gwolle_gb_data['antispam'])) { $antispam = stripslashes($gwolle_gb_data['antispam']); } if (isset($gwolle_gb_data['content'])) { $content = stripslashes($gwolle_gb_data['content']); } } } // Initialize errors, if not set if (empty($gwolle_gb_error_fields)) { $gwolle_gb_error_fields = array(); } /* * Handle Messaging to the user */ $class = ""; if ($gwolle_gb_errors) { $class = "error"; } if (isset($gwolle_gb_messages) && $gwolle_gb_messages != '') { $output .= "<div id='gwolle_gb_messages' class='{$class}'>"; $output .= $gwolle_gb_messages; $output .= "</div>"; } $popuptitle = 'Merci ...'; if (strpos($gwolle_gb_messages, 'signature') !== false && strpos($gwolle_gb_messages, 'doux') !== false) { $popuptitle = 'Oups ...'; $gwolle_gb_messages = '<p class="error_fields"><strong>Ni les mots doux, ni le nom .. Quelle tristesse.</strong></p>'; } if (strpos($gwolle_gb_messages, 'signature') !== false) { $popuptitle = 'Oups ...'; } if (strpos($gwolle_gb_messages, 'doux') !== false) { $popuptitle = 'Oups ...'; } $output .= '<div id="myModal" class="modal fade" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">'; $output .= $popuptitle; $output .= '</h4> </div> <div class="modal-body"> <p>'; $output .= $gwolle_gb_messages; $output .= '</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button> </div> </div> </div> </div>'; /* * Button 'write a new entry.' */ // $output .= ' // <div id="gwolle_gb_write_button"> // <input type="button" value="» ' . esc_attr__('Write a new entry.', 'gwolle-gb') . '" /> // </div>'; // Option to allow only logged-in users to post. Don't show the form if not logged-in. We still see the messages above. if (!is_user_logged_in() && get_option('gwolle_gb-require_login', 'false') == 'true') { $output .= ' <div id="gwolle_gb_new_entry"> <h3>' . __('Log in to post an entry', 'gwolle-gb') . '</h3>'; $args = array('echo' => false, 'redirect' => (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); $output .= wp_login_form($args); $output .= wp_register('', '', false); $output .= '</div>'; return $output; } /* * Build up Form including possible error_fields */ $form_setting = gwolle_gb_get_setting('form'); $autofocus = 'autofocus="autofocus"'; // Form for submitting new entries $header = gwolle_gb_sanitize_output(get_option('gwolle_gb-header', false)); if ($header == false) { $header = __('Write a new entry for the Guestbook', 'gwolle-gb'); } $output .= ' <form id="gwolle_gb_new_entry" action="#" method="POST" > <input type="hidden" name="gwolle_gb_function" id="gwolle_gb_function" value="add_entry" />'; // The book_id from the shortcode, to be used by the posthandling function again. $output .= '<input type="hidden" name="gwolle_gb_book_id" id="gwolle_gb_book_id" value="' . $shortcode_atts['book_id'] . '" />'; // Use this filter to just add something $output .= apply_filters('gwolle_gb_write_add_before', ''); /* Name */ if (isset($form_setting['form_name_enabled']) && $form_setting['form_name_enabled'] === 'true') { $output .= '<div class="gwolle_gb_author_name">'; if (isset($form_setting['form_name_mandatory']) && $form_setting['form_name_mandatory'] === 'true') { } $output .= ' <div class="input"><input class="'; if (in_array('name', $gwolle_gb_error_fields)) { $output .= ' error'; } $output .= '" value="' . $name . '" type="text" name="gwolle_gb_author_name" id="gwolle_gb_author_name" placeholder="' . __('Name', 'gwolle-gb') . '" '; if (in_array('name', $gwolle_gb_error_fields) && isset($autofocus)) { $output .= $autofocus; $autofocus = false; // disable it for the next error. } $output .= ' /></div> </div>'; } // /* City / Origin */ // if ( isset($form_setting['form_city_enabled']) && $form_setting['form_city_enabled'] === 'true' ) { // $output .= '<div class="gwolle_gb_author_origin"> // <div class="label"><label for="gwolle_gb_author_origin">' . __('City', 'gwolle-gb') . ':'; // if ( isset($form_setting['form_city_mandatory']) && $form_setting['form_city_mandatory'] === 'true' ) { $output .= ' *';} // $output .= '</label></div> // <div class="input"><input class="'; // if (in_array('author_origin', $gwolle_gb_error_fields)) { // $output .= ' error'; // } // $output .= '" value="' . $origin . '" type="text" name="gwolle_gb_author_origin" id="gwolle_gb_author_origin" placeholder="' . __('City', 'gwolle-gb') . '" '; // if ( in_array('author_origin', $gwolle_gb_error_fields) && isset($autofocus) ) { // $output .= $autofocus; // $autofocus = false; // disable it for the next error. // } // $output .= ' /></div> // </div> // <div class="clearBoth"> </div>'; // } /* Email */ // if ( isset($form_setting['form_email_enabled']) && $form_setting['form_email_enabled'] === 'true' ) { // $output .= '<div class="gwolle_gb_author_email"> // <div class="label"><label for="gwolle_gb_author_email">' . __('Email', 'gwolle-gb') . ':'; // if ( isset($form_setting['form_email_mandatory']) && $form_setting['form_email_mandatory'] === 'true' ) { $output .= ' *';} // $output .= '</label></div> // <div class="input"><input class="'; // if (in_array('author_email', $gwolle_gb_error_fields)) { // $output .= ' error'; // } // $output .= '" value="' . $email . '" ' . ($html5 ? 'type="email"' : 'type="text"') . ' name="gwolle_gb_author_email" id="gwolle_gb_author_email" placeholder="' . __('Email', 'gwolle-gb') . '" '; // if ( in_array('author_email', $gwolle_gb_error_fields) && isset($autofocus) ) { // $output .= $autofocus; // $autofocus = false; // disable it for the next error. // } // $output .= ' /></div> // </div> // <div class="clearBoth"> </div>'; // } else { // if ( isset($email) && strlen($email) > 0 ) { // // For logged in users, just save the email anyway. // $output .= '<input class="" value="' . $email . '" type="hidden" name="gwolle_gb_author_email" id="gwolle_gb_author_email" />'; // } // } /* Website / Homepage */ // if ( isset($form_setting['form_homepage_enabled']) && $form_setting['form_homepage_enabled'] === 'true' ) { // $output .= '<div class="gwolle_gb_author_website"> // <div class="label"><label for="gwolle_gb_author_website">' . __('Website', 'gwolle-gb') . ':'; // if ( isset($form_setting['form_homepage_mandatory']) && $form_setting['form_homepage_mandatory'] === 'true' ) { $output .= ' *';} // $output .= '</label></div> // <div class="input"><input class="'; // if (in_array('author_website', $gwolle_gb_error_fields)) { // $output .= ' error'; // } // $output .= '" value="' . $website . '" ' . ($html5 ? 'type="url"' : 'type="text"') . ' name="gwolle_gb_author_website" id="gwolle_gb_author_website" placeholder="' . __('Website', 'gwolle-gb') . '" '; // if ( in_array('author_website', $gwolle_gb_error_fields) && isset($autofocus) ) { // $output .= $autofocus; // $autofocus = false; // disable it for the next error. // } // $output .= ' /></div> // </div> // <div class="clearBoth"> </div>'; // } /* Content */ if (isset($form_setting['form_message_enabled']) && $form_setting['form_message_enabled'] === 'true') { $output .= '<div class="gwolle_gb_content">'; if (isset($form_setting['form_message_mandatory']) && $form_setting['form_message_mandatory'] === 'true') { } $output .= '<div class="input"><textarea name="gwolle_gb_content" id="gwolle_gb_content" class="'; if (in_array('content', $gwolle_gb_error_fields)) { $output .= ' error'; } $output .= '" placeholder="' . __('Message', 'gwolle-gb') . '" '; if (in_array('content', $gwolle_gb_error_fields) && isset($autofocus)) { $output .= $autofocus; $autofocus = false; // disable it for the next error. } $output .= ' >' . $content . '</textarea>'; if (isset($form_setting['form_bbcode_enabled']) && $form_setting['form_bbcode_enabled'] === 'true') { // BBcode and MarkItUp wp_enqueue_script('markitup', plugins_url('markitup/jquery.markitup.js', __FILE__), 'jquery', GWOLLE_GB_VER, false); wp_enqueue_script('markitup_set', plugins_url('markitup/set.js', __FILE__), 'jquery', GWOLLE_GB_VER, false); wp_enqueue_style('gwolle_gb_markitup_css', plugins_url('markitup/style.css', __FILE__), false, GWOLLE_GB_VER, 'screen'); $dataToBePassed = array('bold' => __('Bold', 'gwolle-gb'), 'italic' => __('Italic', 'gwolle-gb'), 'bullet' => __('Bulleted List', 'gwolle-gb'), 'numeric' => __('Numeric List', 'gwolle-gb'), 'picture' => __('Picture', 'gwolle-gb'), 'source' => __('Source', 'gwolle-gb'), 'link' => __('Link', 'gwolle-gb'), 'linktext' => __('Your text to link...', 'gwolle-gb'), 'clean' => __('Clean', 'gwolle-gb'), 'emoji' => __('Emoji', 'gwolle-gb')); wp_localize_script('markitup_set', 'gwolle_gb_localize', $dataToBePassed); // Emoji symbols $output .= '<div class="gwolle_gb_emoji" style="display:none;">'; $output .= gwolle_gb_get_emoji(); $output .= '</div>'; } $output .= '</div>'; // .input } /* Custom Anti-Spam */ // if ( isset($form_setting['form_antispam_enabled']) && $form_setting['form_antispam_enabled'] === 'true' ) { // $antispam_question = gwolle_gb_sanitize_output( get_option('gwolle_gb-antispam-question') ); // $antispam_answer = gwolle_gb_sanitize_output( get_option('gwolle_gb-antispam-answer') ); // // if ( isset($antispam_question) && strlen($antispam_question) > 0 && isset($antispam_answer) && strlen($antispam_answer) > 0 ) { // $output .= ' // <div class="gwolle_gb_antispam"> // <div class="label"> // <label for="gwolle_gb_antispam_answer">' . __('Anti-spam', 'gwolle-gb') . ': *<br /> // ' . __('Question:', 'gwolle-gb') . " " . $antispam_question . '</label> // </div> // <div class="input"><input class="'; // if (in_array('antispam', $gwolle_gb_error_fields)) { // $output .= ' error'; // } // $output .= '" value="' . $antispam . '" type="text" name="gwolle_gb_antispam_answer" id="gwolle_gb_antispam_answer" placeholder="' . __('Answer', 'gwolle-gb') . '" '; // if ( in_array('antispam', $gwolle_gb_error_fields) && isset($autofocus) ) { // $output .= $autofocus; // $autofocus = false; // disable it for the next error. // } // $output .= ' /> // </div> // </div> // <div class="clearBoth"> </div>'; // } // } // // /* CAPTCHA */ // if ( isset($form_setting['form_recaptcha_enabled']) && $form_setting['form_recaptcha_enabled'] === 'true' ) { // if ( class_exists('ReallySimpleCaptcha') ) { // // Disable page caching, we want a new CAPTCHA image each time. // if ( ! defined( 'DONOTCACHEPAGE' ) ) // define( "DONOTCACHEPAGE", "true" ); // // // Instantiate the ReallySimpleCaptcha class, which will handle all of the heavy lifting // $gwolle_gb_captcha = new ReallySimpleCaptcha(); // // // Set Really Simple CAPTCHA Options // $gwolle_gb_captcha->chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; // $gwolle_gb_captcha->char_length = '4'; // $gwolle_gb_captcha->img_size = array( '72', '24' ); // $gwolle_gb_captcha->fg = array( '0', '0', '0' ); // $gwolle_gb_captcha->bg = array( '255', '255', '255' ); // $gwolle_gb_captcha->font_size = '16'; // $gwolle_gb_captcha->font_char_width = '15'; // $gwolle_gb_captcha->img_type = 'png'; // $gwolle_gb_captcha->base = array( '6', '18' ); // // // Generate random word and image prefix // $gwolle_gb_captcha_word = $gwolle_gb_captcha->generate_random_word(); // $gwolle_gb_captcha_prefix = mt_rand(); // // Generate CAPTCHA image // $gwolle_gb_captcha_image_name = $gwolle_gb_captcha->generate_image($gwolle_gb_captcha_prefix, $gwolle_gb_captcha_word); // // Define values for CAPTCHA fields // $gwolle_gb_captcha_image_url = content_url('plugins/really-simple-captcha/tmp/'); // $gwolle_gb_captcha_image_src = $gwolle_gb_captcha_image_url . $gwolle_gb_captcha_image_name; // $gwolle_gb_captcha_image_width = $gwolle_gb_captcha->img_size[0]; // $gwolle_gb_captcha_image_height = $gwolle_gb_captcha->img_size[1]; // $gwolle_gb_captcha_field_size = $gwolle_gb_captcha->char_length; // // // Enqueue and localize the frontend script for CAPTCHA. // wp_enqueue_script('gwolle_gb_captcha_js', plugins_url('js/captcha.js', __FILE__), 'jquery', GWOLLE_GB_VER, true ); // $dataToBePassed = array( // // URL to wp-admin/admin-ajax.php to process the request // 'ajaxurl' => admin_url( 'admin-ajax.php' ), // // generate a nonce with a unique ID "gwolle_gb_captcha_ajax" // // so that you can check it later when an AJAX request is sent // 'security' => wp_create_nonce( 'gwolle_gb_captcha_ajax' ), // 'correct' => __ ('Correct CAPTCHA value.', 'gwolle-gb' ), // 'incorrect' => __( 'Incorrect CAPTCHA value.', 'gwolle-gb' ), // 'gwolle_gb_captcha_prefix' => $gwolle_gb_captcha_prefix // ); // wp_localize_script( 'gwolle_gb_captcha_js', 'gwolle_gb_captcha', $dataToBePassed ); // // // Output the CAPTCHA fields // $output .= ' // <div class="gwolle_gb_captcha"> // <div class="label"> // <label for="gwolle_gb_captcha_code">' . __('Anti-spam', 'gwolle-gb') . ': *<br /> // <img src="' . $gwolle_gb_captcha_image_src . '" alt="captcha" width="' . $gwolle_gb_captcha_image_width . '" height="' . $gwolle_gb_captcha_image_height . '" /> // </label> // </div> // <div class="input"> // <input class="'; // if (in_array('captcha', $gwolle_gb_error_fields)) { // $output .= 'error'; // } // $output .= '" value="" type="text" name="gwolle_gb_captcha_code" id="gwolle_gb_captcha_code" placeholder="' . __('CAPTCHA', 'gwolle-gb') . '" '; // if ( in_array('captcha', $gwolle_gb_error_fields) && isset($autofocus) ) { // $output .= $autofocus; // $autofocus = false; // disable it for the next error. // } // $output .= ' /> // <input type="hidden" name="gwolle_gb_captcha_prefix" id="gwolle_gb_captcha_prefix" value="' . $gwolle_gb_captcha_prefix . '" /> // <span id="gwolle_gb_captcha_verify"></span> // </div> // </div> // '; // } // } // Use this filter to just add something $output .= apply_filters('gwolle_gb_write_add_form', ''); $output .= ' <div class="gwolle_gb_submit"> <div class="input_button"><input type="submit" name="gwolle_gb_submit" value="' . esc_attr__('Valider', 'gwolle-gb') . '" /></div> </div></div> <div class="gwolle_gb_notice"> '; $notice = gwolle_gb_sanitize_output(get_option('gwolle_gb-notice', false)); if ($notice == false) { // No text set by the user. Use the default text. } $notice = nl2br($notice); $output .= str_replace('%ip%', $_SERVER['REMOTE_ADDR'], $notice); $output .= ' </div>'; // Use this filter to just add something $output .= apply_filters('gwolle_gb_write_add_after', ''); $output .= '</form>'; if (get_option('gwolle_gb-labels_float', 'true') === 'true') { $output .= ' <style type="text/css" scoped> </style> '; } // Add filter for the form, so devs can manipulate it. $output = apply_filters('gwolle_gb_write', $output); return $output; }
function gwolle_gb_page_editor() { if (function_exists('current_user_can') && !current_user_can('moderate_comments')) { die(__('Cheatin’ uh?', 'gwolle-gb')); } ?> <!-- Do not replace Emoji with <img> elements in textarea, it screws saving the entry --> <script type="text/javascript"> window._wpemojiSettings = ''; </script> <?php if (!get_option('gwolle_gb_version')) { // FIXME: do this on activation gwolle_gb_installSplash(); } else { $gwolle_gb_errors = ''; $gwolle_gb_messages = ''; $sectionHeading = __('Edit guestbook entry', 'gwolle-gb'); // Always fetch the requested entry, so we can compare the $entry and the $_POST. $entry = new gwolle_gb_entry(); if (isset($_POST['entry_id'])) { // _POST has preference over _GET $entry_id = intval($_POST['entry_id']); } else { if (isset($_GET['entry_id'])) { $entry_id = intval($_GET['entry_id']); } } if (isset($entry_id) && $entry_id > 0) { $result = $entry->load($entry_id); if (!$result) { $gwolle_gb_messages .= '<p class="error">' . __('Entry could not be found.', 'gwolle-gb') . '</p>'; $gwolle_gb_errors = 'error'; $sectionHeading = __('Guestbook entry (error)', 'gwolle-gb'); } } else { $sectionHeading = __('New guestbook entry', 'gwolle-gb'); } /* * Handle the $_POST */ if (isset($_POST['gwolle_gb_page']) && $_POST['gwolle_gb_page'] == 'editor' && $gwolle_gb_errors == '') { if (!isset($_POST['entry_id']) || $_POST['entry_id'] != $entry->get_id()) { $gwolle_gb_messages .= '<p class="error">' . __('Something strange happened.', 'gwolle-gb') . '</p>'; $gwolle_gb_errors = 'error'; } else { if ($_POST['entry_id'] > 0 && $entry->get_id() > 0) { /* * Check for changes, and update accordingly. This is on an Existing Entry! */ $changed = false; /* Set as checked or unchecked, and by whom */ if (isset($_POST['ischecked']) && $_POST['ischecked'] == 'on') { if ($_POST['ischecked'] == 'on' && $entry->get_ischecked() == 0) { $entry->set_ischecked(true); $user_id = get_current_user_id(); // returns 0 if no current user $entry->set_checkedby($user_id); gwolle_gb_add_log_entry($entry->get_id(), 'entry-checked'); gwolle_gb_clear_cache(); $changed = true; } } else { if ($entry->get_ischecked() == 1) { $entry->set_ischecked(false); gwolle_gb_add_log_entry($entry->get_id(), 'entry-unchecked'); $changed = true; } } /* Set as spam or not, and submit as ham or spam to Akismet service */ if (isset($_POST['isspam']) && $_POST['isspam'] == 'on') { if ($_POST['isspam'] == 'on' && $entry->get_isspam() == 0) { $entry->set_isspam(true); $result = gwolle_gb_akismet($entry, 'submit-spam'); if ($result) { $gwolle_gb_messages .= '<p>' . __('Submitted as Spam to the Akismet service.', 'gwolle-gb') . '</p>'; } gwolle_gb_add_log_entry($entry->get_id(), 'marked-as-spam'); $changed = true; } } else { if ($entry->get_isspam() == 1) { $entry->set_isspam(false); $result = gwolle_gb_akismet($entry, 'submit-ham'); if ($result) { $gwolle_gb_messages .= '<p>' . __('Submitted as Ham to the Akismet service.', 'gwolle-gb') . '</p>'; } gwolle_gb_add_log_entry($entry->get_id(), 'marked-as-not-spam'); $changed = true; } } /* Set as trash or not */ if (isset($_POST['istrash']) && $_POST['istrash'] == 'on') { if ($_POST['istrash'] == 'on' && $entry->get_istrash() == 0) { $entry->set_istrash(true); gwolle_gb_add_log_entry($entry->get_id(), 'entry-trashed'); $changed = true; } } else { if ($entry->get_istrash() == 1) { $entry->set_istrash(false); gwolle_gb_add_log_entry($entry->get_id(), 'entry-untrashed'); $changed = true; } } /* Check if the content changed, and update accordingly */ if (isset($_POST['gwolle_gb_content']) && $_POST['gwolle_gb_content'] != '') { if (trim($_POST['gwolle_gb_content']) != $entry->get_content()) { $entry_content = gwolle_gb_maybe_encode_emoji($_POST['gwolle_gb_content'], 'content'); $entry->set_content($entry_content); $changed = true; } } /* Check if the website changed, and update accordingly */ if (isset($_POST['gwolle_gb_author_website'])) { if ($_POST['gwolle_gb_author_website'] != $entry->get_author_website()) { $entry->set_author_website($_POST['gwolle_gb_author_website']); $changed = true; } } /* Check if the author_origin changed, and update accordingly */ if (isset($_POST['gwolle_gb_author_origin'])) { if ($_POST['gwolle_gb_author_origin'] != $entry->get_author_origin()) { $entry_origin = gwolle_gb_maybe_encode_emoji($_POST['gwolle_gb_author_origin'], 'author_origin'); $entry->set_author_origin($entry_origin); $changed = true; } } /* Check if the admin_reply changed, and update and log accordingly */ if (isset($_POST['gwolle_gb_admin_reply'])) { if (trim($_POST['gwolle_gb_admin_reply']) != $entry->get_admin_reply()) { $gwolle_gb_admin_reply = gwolle_gb_maybe_encode_emoji($_POST['gwolle_gb_admin_reply'], 'admin_reply'); if ($gwolle_gb_admin_reply != '' && $entry->get_admin_reply() == '') { $entry->set_admin_reply_uid(get_current_user_id()); gwolle_gb_add_log_entry($entry->get_id(), 'admin-reply-added'); } else { if ($gwolle_gb_admin_reply == '' && $entry->get_admin_reply() != '') { $entry->set_admin_reply_uid(0); gwolle_gb_add_log_entry($entry->get_id(), 'admin-reply-removed'); } else { if ($gwolle_gb_admin_reply != '' && $entry->get_admin_reply() != '') { gwolle_gb_add_log_entry($entry->get_id(), 'admin-reply-updated'); } } } $entry->set_admin_reply($gwolle_gb_admin_reply); $changed = true; } } /* Mail the author about the Admin Reply, if so requested */ if (isset($_POST['gwolle_gb_admin_reply_mail_author'])) { if ($_POST['gwolle_gb_admin_reply_mail_author'] == 'on') { gwolle_gb_mail_author_on_admin_reply($entry); } } /* Check if the author_name changed, and update accordingly */ if (isset($_POST['gwolle_gb_author_name'])) { if ($_POST['gwolle_gb_author_name'] != $entry->get_author_name()) { $entry_name = gwolle_gb_maybe_encode_emoji($_POST['gwolle_gb_author_name'], 'author_name'); $entry->set_author_name($entry_name); $changed = true; } } /* Check if the datetime changed, and update accordingly */ if (isset($_POST['gwolle_gb_timestamp']) && is_numeric($_POST['gwolle_gb_timestamp'])) { if ($_POST['gwolle_gb_timestamp'] != $entry->get_datetime()) { $entry->set_datetime((int) $_POST['gwolle_gb_timestamp']); $changed = true; } } /* Check if the book_id changed, and update accordingly */ if (isset($_POST['gwolle_gb_book_id']) && is_numeric($_POST['gwolle_gb_book_id'])) { if ($_POST['gwolle_gb_book_id'] != $entry->get_book_id()) { $entry->set_book_id((int) $_POST['gwolle_gb_book_id']); $changed = true; } } /* Save the entry */ if ($changed) { $result = $entry->save(); if ($result) { gwolle_gb_add_log_entry($entry->get_id(), 'entry-edited'); $gwolle_gb_messages .= '<p>' . __('Changes saved.', 'gwolle-gb') . '</p>'; } else { $gwolle_gb_messages .= '<p>' . __('Error happened during saving.', 'gwolle-gb') . '</p>'; $gwolle_gb_errors = 'error'; } } else { $gwolle_gb_messages .= '<p>' . __('Entry was not changed.', 'gwolle-gb') . '</p>'; } /* Remove permanently */ if (isset($_POST['istrash']) && $_POST['istrash'] == 'on' && isset($_POST['remove']) && $_POST['remove'] == 'on') { if ($entry->get_istrash() == 1) { $entry->delete(); $entry->set_id(0); $changed = true; // Overwrite any other message, only removal is relevant. $gwolle_gb_messages = '<p>' . __('Entry removed.', 'gwolle-gb') . '</p>'; $entry = new gwolle_gb_entry(); } } } else { if ($_POST['entry_id'] == 0 && $entry->get_id() == 0) { /* * Check for input, and save accordingly. This is on a New Entry! (So no logging) */ $saved = false; $data = array(); /* Set as checked anyway, new entry is always by an admin */ $data['ischecked'] = true; $user_id = get_current_user_id(); // returns 0 if no current user $data['checkedby'] = $user_id; $data['author_id'] = $user_id; /* Set metadata of the admin */ $userdata = get_userdata($user_id); if (is_object($userdata)) { if (isset($userdata->display_name)) { $author_name = $userdata->display_name; } else { $author_name = $userdata->user_login; } $author_email = $userdata->user_email; } $data['author_name'] = $author_name; $data['author_name'] = gwolle_gb_maybe_encode_emoji($data['author_name'], 'author_name'); $data['author_email'] = $author_email; /* Set as Not Spam */ $data['isspam'] = false; /* Do not set as trash */ $data['istrash'] = false; /* Check if the content is filled in, and save accordingly */ if (isset($_POST['gwolle_gb_content']) && $_POST['gwolle_gb_content'] != '') { $data['content'] = $_POST['gwolle_gb_content']; $data['content'] = gwolle_gb_maybe_encode_emoji($data['content'], 'content'); $saved = true; } else { $form_setting = gwolle_gb_get_setting('form'); if (isset($form_setting['form_message_enabled']) && $form_setting['form_message_enabled'] === 'true' && isset($form_setting['form_message_mandatory']) && $form_setting['form_message_mandatory'] === 'true') { $gwolle_gb_messages .= '<p>' . __('Entry has no content, even though that is mandatory.', 'gwolle-gb') . '</p>'; $gwolle_gb_errors = 'error'; } else { $data['content'] = ''; $saved = true; } } /* Check if the website is set, and save accordingly */ if (isset($_POST['gwolle_gb_author_website'])) { if ($_POST['gwolle_gb_author_website'] != '') { $data['author_website'] = $_POST['gwolle_gb_author_website']; } else { $data['author_website'] = home_url(); } } /* Check if the author_origin is set, and save accordingly */ if (isset($_POST['gwolle_gb_author_origin'])) { if ($_POST['gwolle_gb_author_origin'] != '') { $data['author_origin'] = $_POST['gwolle_gb_author_origin']; $data['author_origin'] = gwolle_gb_maybe_encode_emoji($data['author_origin'], 'author_origin'); } } /* Check if the admin_reply is set, and save accordingly */ if (isset($_POST['gwolle_gb_admin_reply'])) { if ($_POST['gwolle_gb_admin_reply'] != '') { $data['admin_reply'] = gwolle_gb_maybe_encode_emoji($_POST['gwolle_gb_admin_reply'], 'admin_reply'); $data['admin_reply_uid'] = get_current_user_id(); gwolle_gb_add_log_entry($entry->get_id(), 'admin-reply-added'); } } /* Check if the book_id is set, and save accordingly */ if (isset($_POST['gwolle_gb_book_id']) && is_numeric($_POST['gwolle_gb_book_id'])) { $entry->set_book_id((int) $_POST['gwolle_gb_book_id']); } /* Network Information */ $entry->set_author_ip($_SERVER['REMOTE_ADDR']); $entry->set_author_host(gethostbyaddr($_SERVER['REMOTE_ADDR'])); $result1 = $entry->set_data($data); if ($saved) { $result2 = $entry->save(); if ($result1 && $result2) { $gwolle_gb_messages .= '<p>' . __('Entry saved.', 'gwolle-gb') . '</p>'; gwolle_gb_clear_cache(); } else { $gwolle_gb_messages .= '<p>' . __('Error happened during saving.', 'gwolle-gb') . '</p>'; $gwolle_gb_errors = 'error'; } } else { $gwolle_gb_messages .= '<p>' . __('Entry was not saved.', 'gwolle-gb') . '</p>'; } } } } } // FIXME: reload the entry, just for consistency? /* * Build the Page and the Form */ ?> <div class="wrap gwolle_gb"> <div id="icon-gwolle-gb"><br /></div> <h1><?php echo $sectionHeading; ?> </h1> <?php if ($gwolle_gb_messages) { echo ' <div id="message" class="updated fade notice is-dismissible ' . $gwolle_gb_errors . ' ">' . $gwolle_gb_messages . '</div>'; } ?> <form name="gwolle_gb_editor" id="gwolle_gb_editor" method="POST" action="" accept-charset="UTF-8"> <input type="hidden" name="gwolle_gb_page" value="editor" /> <input type="hidden" name="entry_id" value="<?php echo $entry->get_id(); ?> " /> <div id="poststuff" class="metabox-holder"> <div id="post-body" class="metabox-holder columns-2"> <div id="post-body-content"> <div id='normal-sortables' class='meta-box-sortables'> <div id="contentdiv" class="postbox" > <div class="handlediv"></div> <h3 class='hndle' title="<?php esc_attr_e('Click to open or close', 'gwolle-gb'); ?> "><span><?php _e('Guestbook entry', 'gwolle-gb'); ?> </span></h3> <div class="inside"> <textarea rows="10" name="gwolle_gb_content" id="gwolle_gb_content" tabindex="1" placeholder="<?php _e('Message', 'gwolle-gb'); ?> "><?php echo gwolle_gb_sanitize_output($entry->get_content()); ?> </textarea> <?php if (get_option('gwolle_gb-showLineBreaks', 'false') == 'false') { echo '<p>' . sprintf(__('Line breaks will not be visible to the visitors due to your <a href="%s">settings</a>.', 'gwolle-gb'), 'admin.php?page=' . GWOLLE_GB_FOLDER . '/settings.php') . '</p>'; } $form_setting = gwolle_gb_get_setting('form'); if (isset($form_setting['form_bbcode_enabled']) && $form_setting['form_bbcode_enabled'] === 'true') { wp_enqueue_script('markitup', plugins_url('../frontend/markitup/jquery.markitup.js', __FILE__), 'jquery', GWOLLE_GB_VER, false); wp_enqueue_script('markitup_set', plugins_url('../frontend/markitup/set.js', __FILE__), 'jquery', GWOLLE_GB_VER, false); wp_enqueue_style('gwolle_gb_markitup_css', plugins_url('../frontend/markitup/style.css', __FILE__), false, GWOLLE_GB_VER, 'screen'); $dataToBePassed = array('bold' => __('Bold', 'gwolle-gb'), 'italic' => __('Italic', 'gwolle-gb'), 'bullet' => __('Bulleted List', 'gwolle-gb'), 'numeric' => __('Numeric List', 'gwolle-gb'), 'picture' => __('Picture', 'gwolle-gb'), 'source' => __('Source', 'gwolle-gb'), 'link' => __('Link', 'gwolle-gb'), 'linktext' => __('Your text to link...', 'gwolle-gb'), 'clean' => __('Clean', 'gwolle-gb'), 'emoji' => __('Emoji', 'gwolle-gb')); wp_localize_script('markitup_set', 'gwolle_gb_localize', $dataToBePassed); // Emoji symbols echo '<div class="gwolle_gb_emoji" style="display:none;">'; $emoji = gwolle_gb_get_emoji(); // make it into images for nice colors. if (function_exists('wp_staticize_emoji')) { $emoji = wp_staticize_emoji($emoji); } echo $emoji; echo '</div>'; } ?> </div> </div> <div id="authordiv" class="postbox " > <div class="handlediv"></div> <h3 class='hndle' title="<?php esc_attr_e('Click to open or close', 'gwolle-gb'); ?> "><span><?php _e('Website', 'gwolle-gb'); ?> </span></h3> <div class="inside"> <input type="url" name="gwolle_gb_author_website" tabindex="2" value="<?php echo gwolle_gb_sanitize_output($entry->get_author_website()); ?> " id="author_website" placeholder="<?php _e('Website', 'gwolle-gb'); ?> " /> <p><?php _e("Example: <code>http://www.example.com/</code>", 'gwolle-gb'); ?> </p> </div> </div> <div id="authordiv" class="postbox "> <div class="handlediv"></div> <h3 class='hndle' title="<?php esc_attr_e('Click to open or close', 'gwolle-gb'); ?> "><span><?php _e('Origin', 'gwolle-gb'); ?> </span></h3> <div class="inside"> <input type="text" name="gwolle_gb_author_origin" tabindex="3" placeholder="<?php _e('City', 'gwolle-gb'); ?> " value="<?php echo gwolle_gb_sanitize_output($entry->get_author_origin()); ?> " id="author_origin" /> </div> </div> <div id="admin_reply" class="postbox" > <div class="handlediv"></div> <h3 class='hndle' title="<?php esc_attr_e('Click to open or close', 'gwolle-gb'); ?> "> <span><?php _e('Admin Reply by:', 'gwolle-gb'); echo ' ' . gwolle_gb_is_moderator($entry->get_admin_reply_uid()); ?> </span> </h3> <div class="inside"> <textarea rows="10" name="gwolle_gb_admin_reply" id="gwolle_gb_admin_reply" tabindex="4" placeholder="<?php _e('Admin Reply', 'gwolle-gb'); ?> "><?php echo gwolle_gb_sanitize_output($entry->get_admin_reply()); ?> </textarea> <input type="checkbox" name="gwolle_gb_admin_reply_mail_author" id="gwolle_gb_admin_reply_mail_author"> <label for="gwolle_gb_admin_reply_mail_author"> <?php _e('Mail the author a notification about this reply.', 'gwolle-gb'); ?> </label><br /> <?php if (get_option('gwolle_gb-showLineBreaks', 'false') == 'false') { echo '<p>' . sprintf(__('Line breaks will not be visible to the visitors due to your <a href="%s">settings</a>.', 'gwolle-gb'), 'admin.php?page=' . GWOLLE_GB_FOLDER . '/settings.php') . '</p>'; } ?> </div> </div> </div><!-- .normal-sortables --> </div><!-- .post-body-content --> <div id="postbox-container-1" class="postbox-container"> <div id='side-sortables' class='meta-box-sortables'> <?php $class = ''; // Attach 'spam' to class if the entry is spam if ($entry->get_isspam() === 1) { $class .= ' spam'; } else { $class .= ' nospam'; } // Attach 'trash' to class if the entry is in trash if ($entry->get_istrash() === 1) { $class .= ' trash'; } else { $class .= ' notrash'; } // Attach 'checked/unchecked' to class if ($entry->get_ischecked() === 1) { $class .= ' checked'; } else { $class .= ' unchecked'; } // Attach 'visible/invisible' to class if ($entry->get_isspam() === 1 || $entry->get_istrash() === 1 || $entry->get_ischecked() === 0) { $class .= ' invisible'; } else { $class .= ' visible'; } // Add admin-entry class to an entry from an admin $author_id = $entry->get_author_id(); $is_moderator = gwolle_gb_is_moderator($author_id); if ($is_moderator) { $class .= ' admin-entry'; } ?> <?php $postid = gwolle_gb_get_postid(); if ($postid) { $permalink = get_bloginfo('url') . '?p=' . $postid; ?> <div id="tagsdiv-post_tag" class="postbox"> <div class="handlediv"></div> <h3 class='hndle' title="<?php esc_attr_e('Click to open or close', 'gwolle-gb'); ?> "><span><?php _e('View Frontend', 'gwolle-gb'); ?> </span></h3> <div class="inside"> <div class="tagsdiv" id="post_tag"> <div id="categories-pop" class="tabs-panel gwolle_gb_frontend"> <a class="button rbutton button" href="<?php echo $permalink; ?> "><?php esc_attr_e('View Guestbook', 'gwolle-gb'); ?> </a> </div> </div> </div> </div> <?php } ?> <div id="submitdiv" class="postbox"> <div class="handlediv"></div> <h3 class='hndle' title="<?php esc_attr_e('Click to open or close', 'gwolle-gb'); ?> "><span><?php _e('Options', 'gwolle-gb'); ?> </span></h3> <div class="inside"> <div class="submitbox" id="submitpost"> <div id="minor-publishing"> <div id="misc-publishing-actions"> <div class="misc-pub-section misc-pub-section-last"> <?php // Optional Icon column where CSS is being used to show them or not if (get_option('gwolle_gb-showEntryIcons', 'true') === 'true') { ?> <span class="entry-icons <?php echo $class; ?> "> <span class="visible-icon" title="<?php _e('Visible', 'gwolle-gb'); ?> "></span> <span class="invisible-icon" title="<?php _e('Invisible', 'gwolle-gb'); ?> "></span> <span class="spam-icon" title="<?php _e('Spam', 'gwolle-gb'); ?> "></span> <!--<span class="trash-icon" title="<?php _e('Trash', 'gwolle-gb'); ?> "></span>--> <?php $admin_reply = gwolle_gb_sanitize_output($entry->get_admin_reply()); if (strlen(trim($admin_reply)) > 0) { ?> <span class="admin_reply-icon" title="<?php _e('Admin Replied', 'gwolle-gb'); ?> "></span><?php } ?> <span class="gwolle_gb_ajax" title="<?php _e('Wait...', 'gwolle-gb'); ?> "></span> </span> <?php } if ($entry->get_id() == 0) { echo '<h3 class="h3_invisible">' . __('This entry is not yet visible.', 'gwolle-gb') . '</h3>'; } else { if ($entry->get_ischecked() == 1 && $entry->get_isspam() == 0 && $entry->get_istrash() == 0) { echo ' <h3 class="h3_visible">' . __('This entry is Visible.', 'gwolle-gb') . '</h3> <h3 class="h3_invisible" style="display:none;">' . __('This entry is Not Visible.', 'gwolle-gb') . '</h3> '; } else { echo ' <h3 class="h3_visible" style="display:none;">' . __('This entry is Visible.', 'gwolle-gb') . '</h3> <h3 class="h3_invisible">' . __('This entry is Not Visible.', 'gwolle-gb') . '</h3> '; } ?> <label for="ischecked" class="selectit"> <input id="ischecked" name="ischecked" type="checkbox" <?php if ($entry->get_ischecked() == '1' || $entry->get_id() == 0) { echo 'checked="checked"'; } ?> /> <?php _e('Checked', 'gwolle-gb'); ?> </label> <br /> <label for="isspam" class="selectit"> <input id="isspam" name="isspam" type="checkbox" <?php if ($entry->get_isspam() == '1') { echo 'checked="checked"'; } ?> /> <?php _e('Spam', 'gwolle-gb'); ?> </label> <br /> <label for="istrash" class="selectit"> <input id="istrash" name="istrash" type="checkbox" <?php if ($entry->get_istrash() == '1') { echo 'checked="checked"'; } ?> /> <?php _e('Trash', 'gwolle-gb'); ?> </label> <?php if ($entry->get_istrash() == '1') { ?> <br /> <label for="remove" class="selectit"> <input id="remove" name="remove" type="checkbox" /> <?php _e('Remove this entry Permanently.', 'gwolle-gb'); ?> </label> <?php } } ?> </div> </div><!-- .misc-publishing-actions --> <div class="clear"></div> </div> <!-- .minor-publishing --> <div id="major-publishing-actions"> <div id="publishing-action"> <input name="save" type="submit" class="button-primary" id="publish" tabindex="5" accesskey="p" value="<?php esc_attr_e('Save', 'gwolle-gb'); ?> " /> </div> <!-- .publishing-action --> <div class="clear"></div> </div><!-- major-publishing-actions --> </div><!-- .submitbox --> </div><!-- .inside --> </div><!-- .submitdiv --> <?php if ($entry->get_id() > 0) { ?> <div id="submitdiv" class="postbox"> <div class="handlediv"></div> <h3 class='hndle' title="<?php esc_attr_e('Click to open or close', 'gwolle-gb'); ?> "><span><?php _e('Actions', 'gwolle-gb'); ?> </span></h3> <div class="inside"> <div class="submitbox" id="submitpost"> <div id="minor-publishing"> <div id="misc-publishing-actions"> <div class="misc-pub-section misc-pub-section-last"> <?php echo ' <div class="gwolle_gb_actions ' . $class . '"> <span class="gwolle_gb_check"> <a id="check_' . $entry->get_id() . '" href="#" class="vim-a" title="' . __('Check entry', 'gwolle-gb') . '">' . __('Check', 'gwolle-gb') . '</a> </span> <span class="gwolle_gb_uncheck"> <a id="uncheck_' . $entry->get_id() . '" href="#" class="vim-u" title="' . __('Uncheck entry', 'gwolle-gb') . '">' . __('Uncheck', 'gwolle-gb') . '</a> </span> <span class="gwolle_gb_spam"> | <a id="spam_' . $entry->get_id() . '" href="#" class="vim-s vim-destructive" title="' . __('Mark entry as spam.', 'gwolle-gb') . '">' . __('Spam', 'gwolle-gb') . '</a> </span> <span class="gwolle_gb_unspam"> | <a id="unspam_' . $entry->get_id() . '" href="#" class="vim-a" title="' . __('Mark entry as not-spam.', 'gwolle-gb') . '">' . __('Not spam', 'gwolle-gb') . '</a> </span> <span class="gwolle_gb_trash"> | <a id="trash_' . $entry->get_id() . '" href="#" class="vim-d vim-destructive" title="' . __('Move entry to trash.', 'gwolle-gb') . '">' . __('Trash', 'gwolle-gb') . '</a> </span> <span class="gwolle_gb_untrash"> | <a id="untrash_' . $entry->get_id() . '" href="#" class="vim-d" title="' . __('Recover entry from trash.', 'gwolle-gb') . '">' . __('Untrash', 'gwolle-gb') . '</a> </span><br /> <span class="gwolle_gb_ajax"> <a id="ajax_' . $entry->get_id() . '" href="#" class="ajax vim-d vim-destructive" title="' . __('Please wait...', 'gwolle-gb') . '">' . __('Wait...', 'gwolle-gb') . '</a> </span><br /> </div> '; ?> </div> </div><!-- .misc-publishing-actions --> <div class="clear"></div> </div> <!-- .minor-publishing --> </div><!-- .submitbox --> </div><!-- .inside --> </div><!-- .submitdiv --> <?php } ?> <div id="gwolle_gb-entry-details" class="postbox " > <div class="handlediv"></div> <h3 class='hndle' title="<?php esc_attr_e('Click to open or close', 'gwolle-gb'); ?> "><span><?php _e('Details', 'gwolle-gb'); ?> </span></h3> <div class="inside"> <div class="tagsdiv" id="post_tag"> <p> <?php _e('Author', 'gwolle-gb'); ?> : <span><?php if ($entry->get_author_name()) { echo gwolle_gb_sanitize_output($entry->get_author_name()); } else { echo '<i>(' . __('Unknown', 'gwolle-gb') . ')</i>'; } ?> </span><br /> <?php _e('E-Mail', 'gwolle-gb'); ?> : <span><?php if (strlen(str_replace(' ', '', $entry->get_author_email())) > 0) { echo gwolle_gb_sanitize_output($entry->get_author_email()); } else { echo '<i>(' . __('Unknown', 'gwolle-gb') . ')</i>'; } ?> </span><br /> <?php _e('Written', 'gwolle-gb'); ?> : <span><?php if ($entry->get_datetime() > 0) { echo date_i18n(get_option('date_format'), $entry->get_datetime()) . ', '; echo date_i18n(get_option('time_format'), $entry->get_datetime()); } else { echo '(' . __('Not yet', 'gwolle-gb') . ')'; } ?> </span><br /> <?php _e("Author's IP-address", 'gwolle-gb'); ?> : <span><?php if (strlen($entry->get_author_ip()) > 0) { echo '<a href="http://www.db.ripe.net/whois?form_type=simple&searchtext=' . $entry->get_author_ip() . '" title="' . __('Whois search for this IP', 'gwolle-gb') . '" target="_blank"> ' . $entry->get_author_ip() . ' </a>'; } else { echo '<i>(' . __('Unknown', 'gwolle-gb') . ')</i>'; } ?> </span><br /> <?php _e('Host', 'gwolle-gb'); ?> : <span><?php if (strlen($entry->get_author_host()) > 0) { echo $entry->get_author_host(); } else { echo '<i>(' . __('Unknown', 'gwolle-gb') . ')</i>'; } ?> </span><br /> <?php _e('Book', 'gwolle-gb'); ?> : <span><?php echo $entry->get_book_id(); ?> </span><br /> <span class="gwolle_gb_edit_meta"> <a href="#" title="<?php _e('Edit metadata', 'gwolle-gb'); ?> "><?php _e('Edit', 'gwolle-gb'); ?> </a> </span> </p> <div class="gwolle_gb_edit_meta_inputs"> <label for="gwolle_gb_author_name"><?php _e('Author', 'gwolle-gb'); ?> : </label><br /> <input type="text" name="gwolle_gb_author_name" size="24" value="<?php echo gwolle_gb_sanitize_output($entry->get_author_name()); ?> " id="gwolle_gb_author_name" /><br /> <span><?php _e('Date and time', 'gwolle-gb'); ?> : </span><br /> <div class="gwolle_gb_date"><?php gwolle_gb_touch_time($entry); ?> </div> <label for="gwolle_gb_book_id"><?php _e('Book ID', 'gwolle-gb'); ?> : </label><br /> <input type="text" name="gwolle_gb_book_id" size="4" value="<?php echo (int) $entry->get_book_id(); ?> " id="gwolle_gb_book_id" /> </div> </div><!-- .tagsdiv --> </div> </div><!-- .postbox --> <div id="tagsdiv-post_tag" class="postbox"> <div class="handlediv"></div> <h3 class='hndle' title="<?php esc_attr_e('Click to open or close', 'gwolle-gb'); ?> "><span><?php _e('Entry log', 'gwolle-gb'); ?> </span></h3> <div class="inside"> <div class="tagsdiv" id="post_tag"> <div id="categories-pop" class="tabs-panel gwolle_gb_log"> <ul> <?php if ($entry->get_datetime() > 0) { echo '<li>'; echo date_i18n(get_option('date_format'), $entry->get_datetime()) . ', '; echo date_i18n(get_option('time_format'), $entry->get_datetime()); echo ': ' . __('Written', 'gwolle-gb') . '</li>'; $log_entries = gwolle_gb_get_log_entries($entry->get_id()); if (is_array($log_entries) && !empty($log_entries)) { foreach ($log_entries as $log_entry) { echo '<li class="log_id_' . $log_entry['id'] . '">' . $log_entry['msg_html'] . '</li>'; } } } else { echo '<li>(' . __('No log yet.', 'gwolle-gb') . ')</li>'; } ?> </ul> </div> </div> </div> </div><!-- .postbox --> </div><!-- .side-sortables --> </div><!-- #postbox-container-1 --> <br class="clear" /> </div><!-- .post-body --> </div><!-- .poststuff --> </form> </div> <?php } }
function gwolle_gb_frontend_write() { global $gwolle_gb_errors, $gwolle_gb_error_fields, $gwolle_gb_messages, $gwolle_gb_data; $output = ''; // Set data up for refilling an already submitted form that had errors $name = ''; $origin = ''; $email = ''; $website = ''; $antispam = ''; $content = ''; // Auto-fill the form if the user is already logged in $user_id = get_current_user_id(); // returns 0 if no current user if ($user_id > 0) { $userdata = get_userdata($user_id); if (is_object($userdata)) { if (isset($userdata->display_name)) { $name = $userdata->display_name; } else { $name = $userdata->user_login; } $email = $userdata->user_email; $website = $userdata->user_url; } } // Only show old data when there are errors if ($gwolle_gb_errors) { if (is_array($gwolle_gb_data) && !empty($gwolle_gb_data)) { if (isset($gwolle_gb_data['author_name'])) { $name = stripslashes($gwolle_gb_data['author_name']); } if (isset($gwolle_gb_data['author_origin'])) { $origin = stripslashes($gwolle_gb_data['author_origin']); } if (isset($gwolle_gb_data['author_email'])) { $email = stripslashes($gwolle_gb_data['author_email']); } if (isset($gwolle_gb_data['author_website'])) { $website = stripslashes($gwolle_gb_data['author_website']); } if (isset($gwolle_gb_data['antispam'])) { $antispam = stripslashes($gwolle_gb_data['antispam']); } if (isset($gwolle_gb_data['content'])) { $content = stripslashes($gwolle_gb_data['content']); } } } // Initialize errors, if not set if (empty($gwolle_gb_error_fields)) { $gwolle_gb_error_fields = array(); } /* * Handle Messaging to the user */ $class = ""; if ($gwolle_gb_errors) { $class = "error"; } if (isset($gwolle_gb_messages) && $gwolle_gb_messages != '') { $output .= "<div id='gwolle_gb_messages' class='{$class}'>"; $output .= $gwolle_gb_messages; $output .= "</div>"; } /* * Button 'write a new entry.' */ $output .= ' <div id="gwolle_gb_write_button"> <input type="button" value="» ' . esc_attr__('Write a new entry.', GWOLLE_GB_TEXTDOMAIN) . '" /> </div>'; // Option to allow only logged-in users to post. Don't show the form if not logged-in. We still see the messages above. if (!is_user_logged_in() && get_option('gwolle_gb-require_login', 'false') == 'true') { $output .= ' <div id="gwolle_gb_new_entry"> <h3>' . __('Log in to post an entry', GWOLLE_GB_TEXTDOMAIN) . '</h3>'; $args = array('echo' => false, 'redirect' => (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); $output .= wp_login_form($args); $output .= wp_register('', '', false); $output .= '</div>'; return $output; } /* * Build up Form including possible error_fields */ $form_setting = gwolle_gb_get_setting('form'); $autofocus = 'autofocus="autofocus"'; // Form for submitting new entries $header = gwolle_gb_sanitize_output(get_option('gwolle_gb-header', false)); if ($header == false) { $header = __('Write a new entry for the Guestbook', GWOLLE_GB_TEXTDOMAIN); } $output .= ' <form id="gwolle_gb_new_entry" action="#" method="POST"> <h3>' . $header . '</h3> <input type="hidden" name="gwolle_gb_function" value="add_entry" />'; /* Name */ if (isset($form_setting['form_name_enabled']) && $form_setting['form_name_enabled'] === 'true') { $output .= '<div class="gwolle_gb_author_name"> <div class="label"><label for="gwolle_gb_author_name">' . __('Name', GWOLLE_GB_TEXTDOMAIN) . ':'; if (isset($form_setting['form_name_mandatory']) && $form_setting['form_name_mandatory'] === 'true') { $output .= ' *'; } $output .= '</label></div> <div class="input"><input class="'; if (in_array('name', $gwolle_gb_error_fields)) { $output .= ' error'; } $output .= '" value="' . $name . '" type="text" name="gwolle_gb_author_name" id="gwolle_gb_author_name" placeholder="' . __('Name', GWOLLE_GB_TEXTDOMAIN) . '" '; if (in_array('name', $gwolle_gb_error_fields) && isset($autofocus)) { $output .= $autofocus; $autofocus = false; // disable it for the next error. } $output .= ' /></div> </div> <div class="clearBoth"> </div>'; } /* City / Origin */ if (isset($form_setting['form_city_enabled']) && $form_setting['form_city_enabled'] === 'true') { $output .= '<div class="gwolle_gb_author_origin"> <div class="label"><label for="gwolle_gb_author_origin">' . __('City', GWOLLE_GB_TEXTDOMAIN) . ':'; if (isset($form_setting['form_city_mandatory']) && $form_setting['form_city_mandatory'] === 'true') { $output .= ' *'; } $output .= '</label></div> <div class="input"><input class="'; if (in_array('author_origin', $gwolle_gb_error_fields)) { $output .= ' error'; } $output .= '" value="' . $origin . '" type="text" name="gwolle_gb_author_origin" id="gwolle_gb_author_origin" placeholder="' . __('City', GWOLLE_GB_TEXTDOMAIN) . '" '; if (in_array('author_origin', $gwolle_gb_error_fields) && isset($autofocus)) { $output .= $autofocus; $autofocus = false; // disable it for the next error. } $output .= ' /></div> </div> <div class="clearBoth"> </div>'; } /* Email */ if (isset($form_setting['form_email_enabled']) && $form_setting['form_email_enabled'] === 'true') { $output .= '<div class="gwolle_gb_author_email"> <div class="label"><label for="gwolle_gb_author_email">' . __('Email', GWOLLE_GB_TEXTDOMAIN) . ':'; if (isset($form_setting['form_email_mandatory']) && $form_setting['form_email_mandatory'] === 'true') { $output .= ' *'; } $output .= '</label></div> <div class="input"><input class="'; if (in_array('author_email', $gwolle_gb_error_fields)) { $output .= ' error'; } $output .= '" value="' . $email . '" type="text" name="gwolle_gb_author_email" id="gwolle_gb_author_email" placeholder="' . __('Email', GWOLLE_GB_TEXTDOMAIN) . '" '; if (in_array('author_email', $gwolle_gb_error_fields) && isset($autofocus)) { $output .= $autofocus; $autofocus = false; // disable it for the next error. } $output .= ' /></div> </div> <div class="clearBoth"> </div>'; } /* Website / Homepage */ if (isset($form_setting['form_homepage_enabled']) && $form_setting['form_homepage_enabled'] === 'true') { $output .= '<div class="gwolle_gb_author_website"> <div class="label"><label for="gwolle_gb_author_website">' . __('Website', GWOLLE_GB_TEXTDOMAIN) . ':'; if (isset($form_setting['form_homepage_mandatory']) && $form_setting['form_homepage_mandatory'] === 'true') { $output .= ' *'; } $output .= '</label></div> <div class="input"><input class="'; if (in_array('author_website', $gwolle_gb_error_fields)) { $output .= ' error'; } $output .= '" value="' . $website . '" type="text" name="gwolle_gb_author_website" id="gwolle_gb_author_website" placeholder="' . __('Website', GWOLLE_GB_TEXTDOMAIN) . '" '; if (in_array('author_website', $gwolle_gb_error_fields) && isset($autofocus)) { $output .= $autofocus; $autofocus = false; // disable it for the next error. } $output .= ' /></div> </div> <div class="clearBoth"> </div>'; } /* Content */ if (isset($form_setting['form_message_enabled']) && $form_setting['form_message_enabled'] === 'true') { $output .= '<div class="gwolle_gb_content"> <div class="label"><label for="gwolle_gb_content">' . __('Guestbook entry', GWOLLE_GB_TEXTDOMAIN) . ':'; if (isset($form_setting['form_message_mandatory']) && $form_setting['form_message_mandatory'] === 'true') { $output .= ' *'; } $output .= '</label></div> <div class="input"><textarea name="gwolle_gb_content" id="gwolle_gb_content" class="'; if (in_array('content', $gwolle_gb_error_fields)) { $output .= ' error'; } $output .= '" placeholder="' . __('Message', GWOLLE_GB_TEXTDOMAIN) . '" '; if (in_array('content', $gwolle_gb_error_fields) && isset($autofocus)) { $output .= $autofocus; $autofocus = false; // disable it for the next error. } $output .= ' >' . $content . '</textarea>'; if (isset($form_setting['form_bbcode_enabled']) && $form_setting['form_bbcode_enabled'] === 'true') { // BBcode and MarkItUp wp_enqueue_script('markitup', plugins_url('markitup/jquery.markitup.js', __FILE__), 'jquery', GWOLLE_GB_VER, false); wp_enqueue_script('markitup_set', plugins_url('markitup/set.js', __FILE__), 'jquery', GWOLLE_GB_VER, false); wp_enqueue_style('gwolle_gb_markitup_css', plugins_url('markitup/style.css', __FILE__), false, GWOLLE_GB_VER, 'screen'); // Emoji symbols $output .= '<div class="gwolle_gb_emoji" style="display:none;">'; $output .= gwolle_gb_get_emoji(); $output .= '</div>'; } $output .= '</div>'; // .input $output .= ' </div> <div class="clearBoth"> </div>'; } /* Custom Anti-Spam */ if (isset($form_setting['form_antispam_enabled']) && $form_setting['form_antispam_enabled'] === 'true') { $antispam_question = gwolle_gb_sanitize_output(get_option('gwolle_gb-antispam-question')); $antispam_answer = gwolle_gb_sanitize_output(get_option('gwolle_gb-antispam-answer')); if (isset($antispam_question) && strlen($antispam_question) > 0 && isset($antispam_answer) && strlen($antispam_answer) > 0) { $output .= ' <div class="gwolle_gb_antispam"> <div class="label"> <label for="gwolle_gb_antispam_answer">' . __('Anti-spam', GWOLLE_GB_TEXTDOMAIN) . ': *<br /> ' . __('Question:', GWOLLE_GB_TEXTDOMAIN) . " " . $antispam_question . '</label> </div> <div class="input"><input class="'; if (in_array('antispam', $gwolle_gb_error_fields)) { $output .= ' error'; } $output .= '" value="' . $antispam . '" type="text" name="gwolle_gb_antispam_answer" id="gwolle_gb_antispam_answer" placeholder="' . __('Answer', GWOLLE_GB_TEXTDOMAIN) . '" '; if (in_array('antispam', $gwolle_gb_error_fields) && isset($autofocus)) { $output .= $autofocus; $autofocus = false; // disable it for the next error. } $output .= ' /> </div> </div> <div class="clearBoth"> </div>'; } } /* CAPTCHA */ if (isset($form_setting['form_recaptcha_enabled']) && $form_setting['form_recaptcha_enabled'] === 'true') { if (class_exists('ReallySimpleCaptcha')) { // Instantiate the ReallySimpleCaptcha class, which will handle all of the heavy lifting $gwolle_gb_captcha = new ReallySimpleCaptcha(); // Set Really Simple CAPTCHA Options $gwolle_gb_captcha->chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; $gwolle_gb_captcha->char_length = '4'; $gwolle_gb_captcha->img_size = array('72', '24'); $gwolle_gb_captcha->fg = array('0', '0', '0'); $gwolle_gb_captcha->bg = array('255', '255', '255'); $gwolle_gb_captcha->font_size = '16'; $gwolle_gb_captcha->font_char_width = '15'; $gwolle_gb_captcha->img_type = 'png'; $gwolle_gb_captcha->base = array('6', '18'); // Generate random word and image prefix $gwolle_gb_captcha_word = $gwolle_gb_captcha->generate_random_word(); $gwolle_gb_captcha_prefix = mt_rand(); // Generate CAPTCHA image $gwolle_gb_captcha_image_name = $gwolle_gb_captcha->generate_image($gwolle_gb_captcha_prefix, $gwolle_gb_captcha_word); // Define values for CAPTCHA fields $gwolle_gb_captcha_image_url = get_bloginfo('wpurl') . '/wp-content/plugins/really-simple-captcha/tmp/'; $gwolle_gb_captcha_image_src = $gwolle_gb_captcha_image_url . $gwolle_gb_captcha_image_name; $gwolle_gb_captcha_image_width = $gwolle_gb_captcha->img_size[0]; $gwolle_gb_captcha_image_height = $gwolle_gb_captcha->img_size[1]; $gwolle_gb_captcha_field_size = $gwolle_gb_captcha->char_length; // AJAX url $gwolle_gb_captcha_ajax_url = GWOLLE_GB_URL . '/frontend/captcha/ajaxresponse.php'; // ABSPATH $gwolle_gb_abspath = urlencode(ABSPATH); // Output the CAPTCHA fields ?> <script> function gwolle_gb_captcha_check( code, prefix, url, abspath ) { // Setup variables var code_string = '?code=' + code; var prefix_string = '&prefix=' + prefix; var abspath_string = '&abspath=' + abspath; var request_url_base = url; var request_url = request_url_base + code_string + prefix_string + abspath_string; // Instantiate request var xmlhttp = new XMLHttpRequest(); // Parse resonse xmlhttp.onreadystatechange = function() { if ( 4 == xmlhttp.readyState && 200 == xmlhttp.status ) { var ajax_response = xmlhttp.responseText; // Update form verification feedback if ( 'true' == ajax_response ) { document.getElementById( 'gwolle_gb_captcha_verify' ).innerHTML = '<span style="color:green"><?php _e('Correct CAPTCHA value.', GWOLLE_GB_TEXTDOMAIN); ?> </span>'; jQuery( '#gwolle_gb_captcha_code' ).removeClass('error'); } else if ( 'false' == ajax_response ) { document.getElementById( 'gwolle_gb_captcha_verify' ).innerHTML = '<span style="color:red"><?php _e('Incorrect CAPTCHA value.', GWOLLE_GB_TEXTDOMAIN); ?> </span>'; jQuery( '#gwolle_gb_captcha_code' ).addClass('error'); } } } // Send request xmlhttp.open( 'GET', request_url, true ); xmlhttp.send(); } </script> <?php $output .= ' <div class="gwolle_gb_captcha"> <div class="label"> <label for="gwolle_gb_captcha_code">' . __('Anti-spam', GWOLLE_GB_TEXTDOMAIN) . ': *<br /> <img src="' . $gwolle_gb_captcha_image_src . '" alt="captcha" width="' . $gwolle_gb_captcha_image_width . '" height="' . $gwolle_gb_captcha_image_height . '" /> </label> </div> <div class="input"> <input class="'; if (in_array('captcha', $gwolle_gb_error_fields)) { $output .= 'error'; } $output .= '" value="" type="text" name="gwolle_gb_captcha_code" id="gwolle_gb_captcha_code" placeholder="' . __('CAPTCHA', GWOLLE_GB_TEXTDOMAIN) . '" onblur="gwolle_gb_captcha_check( this.value, \'' . $gwolle_gb_captcha_prefix . '\', \'' . $gwolle_gb_captcha_ajax_url . '\', \'' . $gwolle_gb_abspath . '\' )" '; if (in_array('captcha', $gwolle_gb_error_fields) && isset($autofocus)) { $output .= $autofocus; $autofocus = false; // disable it for the next error. } $output .= ' /> <input type="hidden" name="gwolle_gb_captcha_prefix" id="gwolle_gb_captcha_prefix" value="' . $gwolle_gb_captcha_prefix . '" /> <span id="gwolle_gb_captcha_verify"></span> </div> </div> <div class="clearBoth"> </div>'; } } $output .= ' <div class="gwolle_gb_submit"> <div class="label"> </div> <div class="input"><input type="submit" name="gwolle_gb_submit" value="' . esc_attr__('Submit', GWOLLE_GB_TEXTDOMAIN) . '" /></div> </div> <div class="clearBoth"> </div> <div class="gwolle_gb_notice"> '; $notice = gwolle_gb_sanitize_output(get_option('gwolle_gb-notice', false)); if ($notice == false) { // No text set by the user. Use the default text. $notice = __(' Fields marked with * are obligatory. Your E-mail address wil not be published. For security reasons we save the ip address %ip%. It might be that your entry will only be visible in the guestbook after we reviewed it. We reserve our right to edit, delete, or not publish entries. ', GWOLLE_GB_TEXTDOMAIN); } $notice = nl2br($notice); $output .= str_replace('%ip%', $_SERVER['REMOTE_ADDR'], $notice); $output .= ' </div> </form>'; if (get_option('gwolle_gb-labels_float', 'true') === 'true') { $output .= ' <style type="text/css" scoped> #gwolle_gb .label, #gwolle_gb .input { float: left; } </style> '; } // Add filter for the form, so devs can manipulate it. $output = apply_filters('gwolle_gb_write', $output); return $output; }