function gwolle_gb_rss() { // Only show the first page of entries. $entriesPerPage = (int) get_option('gwolle_gb-entriesPerPage', 20); /* Get the entries for the RSS Feed */ $entries = gwolle_gb_get_entries(array('offset' => 0, 'num_entries' => $entriesPerPage, 'checked' => 'checked', 'trash' => 'notrash', 'spam' => 'nospam')); /* Get the time of the last entry, else of the last edited post */ if (is_array($entries) && !empty($entries)) { $lastbuild = gmdate('D, d M Y H:i:s', $entries[0]->get_datetime()); } else { $lastbuild = mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); } $postid = gwolle_gb_get_postid(); if ($postid) { $permalink = get_bloginfo('url') . '?p=' . $postid; } else { $permalink = get_bloginfo('url'); } /* Get the Language setting */ $WPLANG = get_option('WPLANG', false); if (!$WPLANG) { $WPLANG = WPLANG; } if (!$WPLANG) { $WPLANG = 'en-us'; } $WPLANG = str_replace('_', '-', $WPLANG); $WPLANG = strtolower($WPLANG); /* Build the XML content */ header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true); echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?' . '>'; ?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" <?php do_action('rss2_ns'); ?> > <channel> <title><?php bloginfo_rss('name'); echo " - " . __('Guestbook Feed', GWOLLE_GB_TEXTDOMAIN); ?> </title> <atom:link href="<?php self_link(); ?> " rel="self" type="application/rss+xml" /> <link><?php echo $permalink; ?> </link> <description><?php bloginfo_rss('description'); echo " - " . __('Guestbook Feed', GWOLLE_GB_TEXTDOMAIN); ?> </description> <lastBuildDate><?php echo $lastbuild; ?> </lastBuildDate> <language><?php echo $WPLANG; ?> </language> <sy:updatePeriod><?php echo apply_filters('rss_update_period', 'hourly'); ?> </sy:updatePeriod> <sy:updateFrequency><?php echo apply_filters('rss_update_frequency', '1'); ?> </sy:updateFrequency> <?php do_action('rss2_head'); ?> <?php if (is_array($entries) && !empty($entries)) { foreach ($entries as $entry) { ?> <item> <title><?php _e('Guestbook Entry by', GWOLLE_GB_TEXTDOMAIN); echo " " . trim($entry->get_author_name()); ?> </title> <link><?php echo $permalink; ?> </link> <pubDate><?php echo gmdate('D, d M Y H:i:s', $entry->get_datetime()); ?> </pubDate> <dc:creator><?php echo trim($entry->get_author_name()); ?> </dc:creator> <guid isPermaLink="false"><?php echo $permalink; ?> </guid> <description><![CDATA[<?php echo wp_trim_words($entry->get_content(), 12, '...'); ?> ]]></description> <content:encoded><![CDATA[<?php echo wp_trim_words($entry->get_content(), 25, '...'); ?> ]]></content:encoded> <?php rss_enclosure(); ?> <?php do_action('rss2_item'); ?> </item> <?php } } ?> </channel> </rss> <?php }
function gwolle_gb_export_callback() { if (function_exists('current_user_can') && !current_user_can('manage_options')) { echo "error, no permission."; die; } $entries = gwolle_gb_get_entries(array('num_entries' => -1, 'all' => 'all')); if (is_array($entries) && !empty($entries)) { // Clean everything before here ob_end_clean(); // output headers so that the file is downloaded rather than displayed header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=gwolle_gb_export_' . GWOLLE_GB_VER . '_' . date('Y-m-d_H-i') . '.csv'); // create a file pointer connected to the output stream $output = fopen('php://output', 'w'); // output the column headings fputcsv($output, array('id', 'author_name', 'author_email', 'author_origin', 'author_website', 'author_ip', 'author_host', 'content', 'datetime', 'isspam', 'ischecked', 'istrash')); $saved = 0; foreach ($entries as $entry) { $row = array(); $row[] = $entry->get_id(); $row[] = addslashes($entry->get_author_name()); $row[] = addslashes($entry->get_author_email()); $row[] = addslashes($entry->get_author_origin()); $row[] = addslashes($entry->get_author_website()); $row[] = $entry->get_author_ip(); $row[] = $entry->get_author_host(); $row[] = addslashes($entry->get_content()); $row[] = $entry->get_datetime(); $row[] = $entry->get_isspam(); $row[] = $entry->get_ischecked(); $row[] = $entry->get_istrash(); fputcsv($output, $row); gwolle_gb_add_log_entry($entry->get_id(), 'exported-to-csv'); $saved++; } fclose($output); die; } echo "(Gwolle-GB) Error, no entries."; die; }
function gwolle_gb_frontend_posthandling() { global $wpdb, $gwolle_gb_errors, $gwolle_gb_error_fields, $gwolle_gb_messages, $gwolle_gb_data; /* * Handle $_POST and check and save entry. */ if (isset($_POST['gwolle_gb_function']) && $_POST['gwolle_gb_function'] == 'add_entry') { // Initialize errors $gwolle_gb_errors = false; $gwolle_gb_error_fields = array(); // Initialize messages $gwolle_gb_messages = ''; // Option to allow only logged-in users to post. Don't show the form if not logged-in. if (!is_user_logged_in() && get_option('gwolle_gb-require_login', 'false') == 'true') { $gwolle_gb_errors = true; $gwolle_gb_messages .= '<p class="require_login"><strong>' . __('Submitting a new guestbook entry is only allowed for logged-in users.', GWOLLE_GB_TEXTDOMAIN) . '</strong></p>'; return; } /* * Collect data from the Form */ $gwolle_gb_data = array(); $form_setting = gwolle_gb_get_setting('form'); /* Name */ if (isset($form_setting['form_name_enabled']) && $form_setting['form_name_enabled'] === 'true') { if (isset($_POST['gwolle_gb_author_name'])) { $gwolle_gb_data['author_name'] = trim($_POST['gwolle_gb_author_name']); $gwolle_gb_data['author_name'] = gwolle_gb_maybe_encode_emoji($gwolle_gb_data['author_name'], 'author_name'); if ($gwolle_gb_data['author_name'] == "") { if (isset($form_setting['form_name_mandatory']) && $form_setting['form_name_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'name'; // mandatory } } } else { if (isset($form_setting['form_name_mandatory']) && $form_setting['form_name_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'name'; // mandatory } } } /* City / Origin */ if (isset($form_setting['form_city_enabled']) && $form_setting['form_city_enabled'] === 'true') { if (isset($_POST['gwolle_gb_author_origin'])) { $gwolle_gb_data['author_origin'] = trim($_POST['gwolle_gb_author_origin']); $gwolle_gb_data['author_origin'] = gwolle_gb_maybe_encode_emoji($gwolle_gb_data['author_origin'], 'author_origin'); if ($gwolle_gb_data['author_origin'] == "") { if (isset($form_setting['form_city_mandatory']) && $form_setting['form_city_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'author_origin'; // mandatory } } } else { if (isset($form_setting['form_city_mandatory']) && $form_setting['form_city_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'author_origin'; // mandatory } } } /* Email */ if (isset($form_setting['form_email_enabled']) && $form_setting['form_email_enabled'] === 'true') { if (isset($_POST['gwolle_gb_author_email'])) { $gwolle_gb_data['author_email'] = trim($_POST['gwolle_gb_author_email']); if (filter_var($gwolle_gb_data['author_email'], FILTER_VALIDATE_EMAIL)) { // Valid Email address. } else { if (isset($form_setting['form_email_mandatory']) && $form_setting['form_email_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'author_email'; // mandatory } } } else { if (isset($form_setting['form_email_mandatory']) && $form_setting['form_email_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'author_email'; // mandatory } } } /* Website / Homepage */ if (isset($form_setting['form_homepage_enabled']) && $form_setting['form_homepage_enabled'] === 'true') { if (isset($_POST['gwolle_gb_author_website'])) { $gwolle_gb_data['author_website'] = trim($_POST['gwolle_gb_author_website']); $pattern = '/^http/'; if (!preg_match($pattern, $gwolle_gb_data['author_website'], $matches)) { $gwolle_gb_data['author_website'] = "http://" . $gwolle_gb_data['author_website']; } if (filter_var($gwolle_gb_data['author_website'], FILTER_VALIDATE_URL)) { // Valid Website URL. } else { if (isset($form_setting['form_homepage_mandatory']) && $form_setting['form_homepage_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'author_website'; // mandatory } } } else { if (isset($form_setting['form_homepage_mandatory']) && $form_setting['form_homepage_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'author_website'; // mandatory } } } /* Message */ if (isset($form_setting['form_message_enabled']) && $form_setting['form_message_enabled'] === 'true') { if (isset($_POST['gwolle_gb_content'])) { $gwolle_gb_data['content'] = trim($_POST['gwolle_gb_content']); if ($gwolle_gb_data['content'] == "") { if (isset($form_setting['form_message_mandatory']) && $form_setting['form_message_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'content'; // mandatory } } else { $gwolle_gb_data['content'] = gwolle_gb_maybe_encode_emoji($gwolle_gb_data['content'], 'content'); } } else { if (isset($form_setting['form_message_mandatory']) && $form_setting['form_message_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'content'; // mandatory } } } /* 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) { if (isset($_POST["gwolle_gb_antispam_answer"]) && trim($_POST["gwolle_gb_antispam_answer"]) == trim($antispam_answer)) { //echo "You got it!"; } else { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'antispam'; // mandatory } } if (isset($_POST["gwolle_gb_antispam_answer"])) { $gwolle_gb_data['antispam'] = trim($_POST['gwolle_gb_antispam_answer']); } } /* CAPTCHA */ if (isset($form_setting['form_recaptcha_enabled']) && $form_setting['form_recaptcha_enabled'] === 'true') { if (class_exists('ReallySimpleCaptcha')) { $gwolle_gb_captcha = new ReallySimpleCaptcha(); // This variable holds the CAPTCHA image prefix, which corresponds to the correct answer $gwolle_gb_captcha_prefix = $_POST['gwolle_gb_captcha_prefix']; // This variable holds the CAPTCHA response, entered by the user $gwolle_gb_captcha_code = $_POST['gwolle_gb_captcha_code']; // Validate the CAPTCHA response $gwolle_gb_captcha_correct = $gwolle_gb_captcha->check($gwolle_gb_captcha_prefix, $gwolle_gb_captcha_code); // If CAPTCHA validation fails (incorrect value entered in CAPTCHA field) mark comment as spam. if (true != $gwolle_gb_captcha_correct) { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'captcha'; // mandatory //$gwolle_gb_messages .= '<p style="display_:none"><strong>' . $gwolle_gb_captcha_correct . '</strong></p>'; } else { // verified! //$gwolle_gb_messages .= '<p class="error_fields"><strong>Verified.</strong></p>'; } // clean up the tmp directory $gwolle_gb_captcha->remove($gwolle_gb_captcha_prefix); $gwolle_gb_captcha->cleanup(); } } /* If there are errors, stop here and return false */ if (is_array($gwolle_gb_error_fields) && !empty($gwolle_gb_error_fields)) { // There was no data filled in, even though that was mandatory. $gwolle_gb_messages .= '<p class="error_fields"><strong>' . __('There were errors submitting your guestbook entry.', GWOLLE_GB_TEXTDOMAIN) . '</strong></p>'; if (isset($gwolle_gb_error_fields)) { foreach ($gwolle_gb_error_fields as $field) { switch ($field) { case 'name': $gwolle_gb_messages .= '<p class="error_fields"><strong>' . __('Your name is not filled in, even though it is mandatory.', GWOLLE_GB_TEXTDOMAIN) . '</strong></p>'; break; case 'author_origin': $gwolle_gb_messages .= '<p class="error_fields"><strong>' . __('Your origin is not filled in, even though it is mandatory.', GWOLLE_GB_TEXTDOMAIN) . '</strong></p>'; break; case 'author_email': $gwolle_gb_messages .= '<p class="error_fields"><strong>' . __('Your e-mail address is not filled in correctly, even though it is mandatory.', GWOLLE_GB_TEXTDOMAIN) . '</strong></p>'; break; case 'author_website': $gwolle_gb_messages .= '<p class="error_fields"><strong>' . __('Your website is not filled in, even though it is mandatory.', GWOLLE_GB_TEXTDOMAIN) . '</strong></p>'; break; case 'content': $gwolle_gb_messages .= '<p class="error_fields"><strong>' . __('There is no message, even though it is mandatory.', GWOLLE_GB_TEXTDOMAIN) . '</strong></p>'; break; case 'antispam': $gwolle_gb_messages .= '<p class="error_fields"><strong>' . __('The anti-spam question was not answered correctly, even though it is mandatory.', GWOLLE_GB_TEXTDOMAIN) . '</strong></p>'; break; case 'captcha': $gwolle_gb_messages .= '<p class="error_fields"><strong>' . __('The CAPTCHA was not filled in correctly, even though it is mandatory.', GWOLLE_GB_TEXTDOMAIN) . '</strong></p>'; break; } } } $gwolle_gb_messages .= '<p class="error_fields" style="display: none;">' . print_r($gwolle_gb_error_fields, true) . '</p>'; return false; // no need to check and save } /* New Instance of gwolle_gb_entry. */ $entry = new gwolle_gb_entry(); /* Set the data in the instance */ $set_data = $entry->set_data($gwolle_gb_data); if (!$set_data) { // Data is not set in the Instance, something happened $gwolle_gb_errors = true; $gwolle_gb_messages .= '<p class="set_data"><strong>' . __('There were errors submitting your guestbook entry.', GWOLLE_GB_TEXTDOMAIN) . '</strong></p>'; return false; } /* Check for spam and set accordingly */ $isspam = gwolle_gb_akismet($entry, 'comment-check'); if ($isspam) { // Returned true, so considered spam $entry->set_isspam(true); // Is it wise to make them any wiser? Probably not... // $gwolle_gb_messages .= '<p><strong>' . __('Your guestbook entry is probably spam. A moderator will decide upon it.', GWOLLE_GB_TEXTDOMAIN) . '</strong></p>'; } /* if Moderation is off, set it to "ischecked" */ $user_id = get_current_user_id(); // returns 0 if no current user if (get_option('gwolle_gb-moderate-entries', 'true') == 'true') { if (gwolle_gb_is_moderator($user_id)) { $entry->set_ischecked(true); } else { $entry->set_ischecked(false); } } else { // First set to checked $entry->set_ischecked(true); // Check for abusive content (too long words). Set it to unchecked, so manual moderation is needed. $maxlength = 100; $words = explode(" ", $entry->get_content()); foreach ($words as $word) { if (strlen($word) > $maxlength) { $entry->set_ischecked(false); break; } } $maxlength = 60; $words = explode(" ", $entry->get_author_name()); foreach ($words as $word) { if (strlen($word) > $maxlength) { $entry->set_ischecked(false); break; } } } /* Check for logged in user, and set the userid as author_id, just in case someone is also admin, or gets promoted some day */ $entry->set_author_id($user_id); /* * Network Information */ $entry->set_author_ip($_SERVER['REMOTE_ADDR']); $entry->set_author_host(gethostbyaddr($_SERVER['REMOTE_ADDR'])); /* * Check for double post using email field and content. * Only if content is mandatory. */ if (isset($form_setting['form_message_mandatory']) && $form_setting['form_message_mandatory'] === 'true') { $entries = gwolle_gb_get_entries(array('email' => $entry->get_author_email())); if (is_array($entries) && !empty($entries)) { foreach ($entries as $entry_email) { if ($entry_email->get_content() == $entry->get_content()) { // Match is double entry $gwolle_gb_errors = true; $gwolle_gb_messages .= '<p class="double_post"><strong>' . __('Double post: An entry with the data you entered has already been saved.', GWOLLE_GB_TEXTDOMAIN) . '</strong></p>'; return false; } } } } /* * Save the Entry */ // $save = ""; // Testing mode $save = $entry->save(); //if ( WP_DEBUG ) { echo "save: "; var_dump($save); } if ($save) { // We have been saved to the Database $gwolle_gb_messages .= '<p class="entry_saved">' . __('Thank you for your entry.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; if ($entry->get_ischecked() == 0) { $gwolle_gb_messages .= '<p>' . __('We will review it and unlock it in a short while.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } } /* * Update Cache plugins */ if ($entry->get_ischecked() == 1) { gwolle_gb_clear_cache(); } /* * Send the Notification Mail to moderators that have subscribed (only when it is not Spam) */ if (!$isspam) { $subscribers = array(); $recipients = get_option('gwolle_gb-notifyByMail', array()); if (count($recipients) > 0) { $recipients = explode(",", $recipients); foreach ($recipients as $recipient) { if (is_numeric($recipient)) { $userdata = get_userdata($recipient); $subscribers[] = $userdata->user_email; } } } @ini_set('sendmail_from', get_bloginfo('admin_mail')); // Set the Mail Content $mailTags = array('user_email', 'user_name', 'status', 'entry_management_url', 'blog_name', 'blog_url', 'wp_admin_url', 'entry_content', 'author_ip'); $mail_body = gwolle_gb_sanitize_output(get_option('gwolle_gb-adminMailContent', false)); if (!$mail_body) { $mail_body = __("\nHello,\n\nThere is a new guestbook entry at '%blog_name%'.\nYou can check it at %entry_management_url%.\n\nHave a nice day.\nYour Gwolle-GB-Mailer\n\n\nWebsite address: %blog_url%\nUser name: %user_name%\nUser email: %user_email%\nEntry status: %status%\nEntry content:\n%entry_content%\n", GWOLLE_GB_TEXTDOMAIN); } // Set the Mail Headers $subject = '[' . gwolle_gb_format_values_for_mail(get_bloginfo('name')) . '] ' . __('New Guestbook Entry', GWOLLE_GB_TEXTDOMAIN); $header = ""; if (get_option('gwolle_gb-mail-from', false)) { $header .= "From: " . gwolle_gb_format_values_for_mail(get_bloginfo('name')) . " <" . get_option('gwolle_gb-mail-from') . ">\r\n"; } else { $header .= "From: " . gwolle_gb_format_values_for_mail(get_bloginfo('name')) . " <" . get_bloginfo('admin_email') . ">\r\n"; } $header .= "Content-Type: text/plain; charset=UTF-8\r\n"; // Encoding of the mail // Replace the tags from the mailtemplate with real data from the website and entry $info['user_name'] = gwolle_gb_sanitize_output($entry->get_author_name()); $info['user_email'] = $entry->get_author_email(); $info['blog_name'] = get_bloginfo('name'); $info['blog_url'] = get_bloginfo('wpurl'); $info['wp_admin_url'] = $info['blog_url'] . '/wp-admin'; $info['entry_management_url'] = $info['wp_admin_url'] . '/admin.php?page=' . GWOLLE_GB_FOLDER . '/editor.php&entry_id=' . $entry->get_id(); $info['entry_content'] = gwolle_gb_format_values_for_mail(gwolle_gb_sanitize_output($entry->get_content())); $info['author_ip'] = $_SERVER['REMOTE_ADDR']; if ($entry->get_ischecked()) { $info['status'] = __('Checked', GWOLLE_GB_TEXTDOMAIN); } else { $info['status'] = __('Unchecked', GWOLLE_GB_TEXTDOMAIN); } // The last tags are bloginfo-based for ($tagNum = 0; $tagNum < count($mailTags); $tagNum++) { $mail_body = str_replace('%' . $mailTags[$tagNum] . '%', $info[$mailTags[$tagNum]], $mail_body); $mail_body = gwolle_gb_format_values_for_mail($mail_body); } if (is_array($subscribers) && !empty($subscribers)) { foreach ($subscribers as $subscriber) { wp_mail($subscriber, $subject, $mail_body, $header); } } } /* * Send Notification Mail to the author if set to true in an option */ if (!$isspam) { if (get_option('gwolle_gb-mail_author', 'false') == 'true') { // Set the Mail Content $mailTags = array('user_email', 'user_name', 'blog_name', 'blog_url', 'entry_content'); $mail_body = gwolle_gb_sanitize_output(get_option('gwolle_gb-authorMailContent', false)); if (!$mail_body) { $mail_body = __("\nHello,\n\nYou have just posted a new guestbook entry at '%blog_name%'.\n\nHave a nice day.\nThe editors at %blog_name%.\n\n\nWebsite address: %blog_url%\nUser name: %user_name%\nUser email: %user_email%\nEntry content:\n%entry_content%\n", GWOLLE_GB_TEXTDOMAIN); } // Set the Mail Headers $subject = '[' . gwolle_gb_format_values_for_mail(get_bloginfo('name')) . '] ' . __('New Guestbook Entry', GWOLLE_GB_TEXTDOMAIN); $header = ""; if (get_option('gwolle_gb-mail-from', false)) { $header .= "From: " . gwolle_gb_format_values_for_mail(get_bloginfo('name')) . " <" . gwolle_gb_sanitize_output(get_option('gwolle_gb-mail-from')) . ">\r\n"; } else { $header .= "From: " . gwolle_gb_format_values_for_mail(get_bloginfo('name')) . " <" . get_bloginfo('admin_email') . ">\r\n"; } $header .= "Content-Type: text/plain; charset=UTF-8\r\n"; // Encoding of the mail // Replace the tags from the mailtemplate with real data from the website and entry $info['user_name'] = gwolle_gb_sanitize_output($entry->get_author_name()); $info['user_email'] = $entry->get_author_email(); $info['blog_name'] = get_bloginfo('name'); $info['blog_url'] = get_bloginfo('wpurl'); $info['entry_content'] = gwolle_gb_format_values_for_mail(gwolle_gb_sanitize_output($entry->get_content())); for ($tagNum = 0; $tagNum < count($mailTags); $tagNum++) { $mail_body = str_replace('%' . $mailTags[$tagNum] . '%', $info[$mailTags[$tagNum]], $mail_body); $mail_body = gwolle_gb_format_values_for_mail($mail_body); } wp_mail($entry->get_author_email(), $subject, $mail_body, $header); } } /* * No Log for the Entry needed, it has a default post date in the Entry itself. */ } }
function gwolle_gb_page_entries() { if (function_exists('current_user_can') && !current_user_can('moderate_comments')) { die(__('Cheatin’ uh?', GWOLLE_GB_TEXTDOMAIN)); } if (!get_option('gwolle_gb_version')) { // FIXME: do this on activation gwolle_gb_installSplash(); } else { $gwolle_gb_errors = ''; $gwolle_gb_messages = ''; if (isset($_POST['gwolle_gb_page']) && $_POST['gwolle_gb_page'] == 'entries') { $action = ''; if (isset($_POST['massEditAction1']) && $_POST['massEditAction1'] == 'check' || isset($_POST['massEditAction2']) && $_POST['massEditAction2'] == 'check') { $action = 'check'; } else { if (isset($_POST['massEditAction1']) && $_POST['massEditAction1'] == 'uncheck' || isset($_POST['massEditAction2']) && $_POST['massEditAction2'] == 'uncheck') { $action = 'uncheck'; } else { if (isset($_POST['massEditAction1']) && $_POST['massEditAction1'] == 'spam' || isset($_POST['massEditAction2']) && $_POST['massEditAction2'] == 'spam') { $action = 'spam'; } else { if (isset($_POST['massEditAction1']) && $_POST['massEditAction1'] == 'no-spam' || isset($_POST['massEditAction2']) && $_POST['massEditAction2'] == 'no-spam') { $action = 'no-spam'; } else { if (isset($_POST['massEditAction1']) && $_POST['massEditAction1'] == 'akismet' || isset($_POST['massEditAction2']) && $_POST['massEditAction2'] == 'akismet') { $action = 'akismet'; } else { if (isset($_POST['massEditAction1']) && $_POST['massEditAction1'] == 'trash' || isset($_POST['massEditAction2']) && $_POST['massEditAction2'] == 'trash') { $action = 'trash'; } else { if (isset($_POST['massEditAction1']) && $_POST['massEditAction1'] == 'untrash' || isset($_POST['massEditAction2']) && $_POST['massEditAction2'] == 'untrash') { $action = 'untrash'; } else { if (isset($_POST['massEditAction1']) && $_POST['massEditAction1'] == 'remove' || isset($_POST['massEditAction2']) && $_POST['massEditAction2'] == 'remove') { $action = 'remove'; } } } } } } } } if ($action != '') { // Initialize variables to generate messages with $entries_handled = 0; $entries_not_handled = 0; $akismet_spam = 0; $akismet_not_spam = 0; $akismet_already_spam = 0; $akismet_already_not_spam = 0; /* Handle the $_POST entries */ foreach (array_keys($_POST) as $postElementName) { if (strpos($postElementName, 'check') > -1 && !strpos($postElementName, '-all-') && $_POST[$postElementName] == 'on') { $entry_id = str_replace('check-', '', $postElementName); $entry_id = intval($entry_id); if (isset($entry_id) && $entry_id > 0) { $entry = new gwolle_gb_entry(); $result = $entry->load($entry_id); if ($result) { if ($action == 'check') { if ($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'); $result = $entry->save(); if ($result) { $entries_handled++; } else { $entries_not_handled++; } } else { $entries_not_handled++; } } else { if ($action == 'uncheck') { if ($entry->get_ischecked() == 1) { $entry->set_ischecked(false); $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-unchecked'); $result = $entry->save(); if ($result) { $entries_handled++; } else { $entries_not_handled++; } } else { $entries_not_handled++; } } else { if ($action == 'spam') { if ($entry->get_isspam() == 0) { $entry->set_isspam(true); if (get_option('gwolle_gb-akismet-active', 'false') == 'true') { gwolle_gb_akismet($entry, 'submit-spam'); } gwolle_gb_add_log_entry($entry->get_id(), 'marked-as-spam'); $result = $entry->save(); if ($result) { $entries_handled++; } else { $entries_not_handled++; } } else { $entries_not_handled++; } } else { if ($action == 'no-spam') { if ($entry->get_isspam() == 1) { $entry->set_isspam(false); if (get_option('gwolle_gb-akismet-active', 'false') == 'true') { gwolle_gb_akismet($entry, 'submit-ham'); } gwolle_gb_add_log_entry($entry->get_id(), 'marked-as-not-spam'); $result = $entry->save(); if ($result) { $entries_handled++; } else { $entries_not_handled++; } } else { $entries_not_handled++; } } else { if ($action == 'akismet') { /* Check for spam and set accordingly */ if (get_option('gwolle_gb-akismet-active', 'false') == 'true') { $isspam = gwolle_gb_akismet($entry, 'comment-check'); if ($isspam) { // Returned true, so considered spam if ($entry->get_isspam() == 0) { $entry->set_isspam(true); gwolle_gb_add_log_entry($entry->get_id(), 'marked-as-spam'); $result = $entry->save(); if ($result) { $akismet_spam++; } else { $akismet_not_spam++; } } else { $akismet_already_spam++; } } else { if ($entry->get_isspam() == 1) { $entry->set_isspam(false); gwolle_gb_add_log_entry($entry->get_id(), 'marked-as-not-spam'); $result = $entry->save(); if ($result) { $akismet_not_spam++; } else { $akismet_spam++; } } else { $akismet_already_not_spam++; } } } } else { if ($action == 'trash') { if ($entry->get_istrash() == 0) { $entry->set_istrash(true); gwolle_gb_add_log_entry($entry->get_id(), 'entry-trashed'); $result = $entry->save(); if ($result) { $entries_handled++; } else { $entries_not_handled++; } } else { $entries_not_handled++; } } else { if ($action == 'untrash') { if ($entry->get_istrash() == 1) { $entry->set_istrash(false); gwolle_gb_add_log_entry($entry->get_id(), 'entry-untrashed'); $result = $entry->save(); if ($result) { $entries_handled++; } else { $entries_not_handled++; } } else { $entries_not_handled++; } } else { if ($action == 'remove') { $result = $entry->delete(); if ($result) { $entries_handled++; } else { $entries_not_handled++; } } } } } } } } } } else { // no result on load() $entries_not_handled++; } } else { // entry_id is not set or not > 0 $entries_not_handled++; } } // no entry with the check-'entry_id' input, continue } // foreach /* Construct Message */ if ($action == 'check') { if ($entries_handled == 1) { $gwolle_gb_messages .= '<p>' . $entries_handled . " " . __('entry checked.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { if ($entries_handled > 1) { $gwolle_gb_messages .= '<p>' . $entries_handled . " " . __('entries checked.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { $gwolle_gb_messages .= '<p>' . __('No entries checked.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } } } else { if ($action == 'uncheck') { if ($entries_handled == 1) { $gwolle_gb_messages .= '<p>' . $entries_handled . " " . __('entry unchecked.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { if ($entries_handled > 1) { $gwolle_gb_messages .= '<p>' . $entries_handled . " " . __('entries unchecked.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { $gwolle_gb_messages .= '<p>' . __('No entries unchecked.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } } } else { if ($action == 'spam') { if ($entries_handled == 1) { $gwolle_gb_messages .= '<p>' . $entries_handled . " " . __('entry marked as spam and submitted to Akismet as spam (if Akismet was enabled).', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { if ($entries_handled > 1) { $gwolle_gb_messages .= '<p>' . $entries_handled . " " . __('entries marked as spam and submitted to Akismet as spam (if Akismet was enabled).', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { $gwolle_gb_messages .= '<p>' . __('No entries marked as spam.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } } } else { if ($action == 'no-spam') { if ($entries_handled == 1) { $gwolle_gb_messages .= '<p>' . $entries_handled . " " . __('entry marked as not spam and submitted to Akismet as ham (if Akismet was enabled).', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { if ($entries_handled > 1) { $gwolle_gb_messages .= '<p>' . $entries_handled . " " . __('entries marked as not spam and submitted to Akismet as ham (if Akismet was enabled).', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { $gwolle_gb_messages .= '<p>' . __('No entries marked as not spam.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } } } else { if ($action == 'akismet') { if ($akismet_spam == 1) { $gwolle_gb_messages .= '<p>' . $akismet_spam . " " . __('entry considered spam and marked as such.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { if ($akismet_spam > 1) { $gwolle_gb_messages .= '<p>' . $akismet_spam . " " . __('entries considered spam and marked as such.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } } if ($akismet_not_spam == 1) { $gwolle_gb_messages .= '<p>' . $akismet_not_spam . " " . __('entry not considered spam and marked as such.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { if ($akismet_not_spam > 1) { $gwolle_gb_messages .= '<p>' . $akismet_not_spam . " " . __('entries not considered spam and marked as such.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } } if ($akismet_already_spam == 1) { $gwolle_gb_messages .= '<p>' . $akismet_already_spam . " " . __('entry already considered spam and not changed.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { if ($akismet_already_spam > 1) { $gwolle_gb_messages .= '<p>' . $akismet_already_spam . " " . __('entries already considered spam and not changed.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } } if ($akismet_already_not_spam == 1) { $gwolle_gb_messages .= '<p>' . $akismet_already_not_spam . " " . __('entry already considered not spam and not changed.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { if ($akismet_already_not_spam > 1) { $gwolle_gb_messages .= '<p>' . $akismet_already_not_spam . " " . __('entries already considered not spam and not changed.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } } } else { if ($action == 'trash') { if ($entries_handled == 1) { $gwolle_gb_messages .= '<p>' . $entries_handled . " " . __('entry moved to trash.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { if ($entries_handled > 1) { $gwolle_gb_messages .= '<p>' . $entries_handled . " " . __('entries moved to trash.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { $gwolle_gb_messages .= '<p>' . __('No entries moved to trash.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } } } else { if ($action == 'untrash') { if ($entries_handled == 1) { $gwolle_gb_messages .= '<p>' . $entries_handled . " " . __('entry recovered from trash.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { if ($entries_handled > 1) { $gwolle_gb_messages .= '<p>' . $entries_handled . " " . __('entries recovered from trash.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { $gwolle_gb_messages .= '<p>' . __('No entries recovered from trash.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } } } else { if ($action == 'remove') { if ($entries_handled == 1) { $gwolle_gb_messages .= '<p>' . $entries_handled . " " . __('entry removed permanently.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { if ($entries_handled > 1) { $gwolle_gb_messages .= '<p>' . $entries_handled . " " . __('entries removed permanently.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { $gwolle_gb_messages .= '<p>' . __('No entries permanently removed.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } } } } } } } } } } } if (isset($_POST['delete_all']) || isset($_POST['delete_all2'])) { // Delete all entries in spam or trash if (isset($_POST['show']) && in_array($_POST['show'], array('spam', 'trash'))) { $delstatus = $_POST['show']; $deleted = gwolle_gb_del_entries($delstatus); if ($deleted == 1) { $gwolle_gb_messages .= '<p>' . $deleted . " " . __('entry removed permanently.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { if ($deleted > 1) { $gwolle_gb_messages .= '<p>' . $deleted . " " . __('entries removed permanently.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } else { $gwolle_gb_messages .= '<p>' . __('No entries permanently removed.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } } } } } // Get entry counts $count = array(); $count['checked'] = gwolle_gb_get_entry_count(array('checked' => 'checked', 'trash' => 'notrash', 'spam' => 'nospam')); $count['unchecked'] = gwolle_gb_get_entry_count(array('checked' => 'unchecked', 'trash' => 'notrash', 'spam' => 'nospam')); $count['spam'] = gwolle_gb_get_entry_count(array('spam' => 'spam')); $count['trash'] = gwolle_gb_get_entry_count(array('trash' => 'trash')); $count['all'] = gwolle_gb_get_entry_count(array('all' => 'all')); $show = isset($_REQUEST['show']) && in_array($_REQUEST['show'], array('checked', 'unchecked', 'spam', 'trash')) ? $_REQUEST['show'] : 'all'; $entries_per_page = get_option('gwolle_gb-entries_per_page', 20); // If Akimet has not been activated yet and the user is looking at the spam tell him to activate Akismet. if ($show == 'spam' && get_option('gwolle_gb-akismet-active', 'false') != 'true') { $gwolle_gb_messages .= '<p>' . __('Please activate Akismet if you want to battle spam.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } // Check if the requested page number is an integer > 0 $pageNum = isset($_REQUEST['pageNum']) && $_REQUEST['pageNum'] && (int) $_REQUEST['pageNum'] > 0 ? (int) $_REQUEST['pageNum'] : 1; // Pagination: Calculate the number of pages. $countPages = ceil($count[$show] / $entries_per_page); if ($pageNum > $countPages) { $pageNum = 1; // page doesnot exist, return to first page } // Calculate Query if ($pageNum == 1 && $count[$show] > 0) { $mysqlFirstRow = 0; } elseif ($count[$show] == 0) { $mysqlFirstRow = 0; } else { $firstEntryNum = ($pageNum - 1) * $entries_per_page + 1; $mysqlFirstRow = $firstEntryNum - 1; } // Get the entries if ($show == 'checked') { $entries = gwolle_gb_get_entries(array('num_entries' => $entries_per_page, 'offset' => $mysqlFirstRow, 'checked' => 'checked', 'trash' => 'notrash', 'spam' => 'nospam')); } else { if ($show == 'unchecked') { $entries = gwolle_gb_get_entries(array('num_entries' => $entries_per_page, 'offset' => $mysqlFirstRow, 'checked' => 'unchecked', 'trash' => 'notrash', 'spam' => 'nospam')); } else { if ($show == 'spam') { $entries = gwolle_gb_get_entries(array('num_entries' => $entries_per_page, 'offset' => $mysqlFirstRow, 'spam' => 'spam')); } else { if ($show == 'trash') { $entries = gwolle_gb_get_entries(array('num_entries' => $entries_per_page, 'offset' => $mysqlFirstRow, 'trash' => 'trash')); } else { $entries = gwolle_gb_get_entries(array('num_entries' => $entries_per_page, 'offset' => $mysqlFirstRow, 'all' => 'all')); } } } } ?> <div class="wrap gwolle_gb"> <div id="icon-gwolle-gb"><br /></div> <h1><?php _e('Guestbook entries', GWOLLE_GB_TEXTDOMAIN); ?> </h1> <?php if ($gwolle_gb_messages) { echo ' <div id="message" class="updated fade notice is-dismissible ' . $gwolle_gb_errors . ' ">' . $gwolle_gb_messages . '</div>'; } // FIXME: add a searchform someday? ?> <form name="gwolle_gb_entries" id="gwolle_gb_entries" action="" method="POST" accept-charset="UTF-8"> <input type="hidden" name="gwolle_gb_page" value="entries" /> <!-- the following fields give us some information we're going to use processing the mass edit --> <input type="hidden" name="pageNum" value="<?php echo $pageNum; ?> "> <input type="hidden" name="entriesOnThisPage" value="<?php echo count($entries); ?> "> <input type="hidden" name="show" value="<?php echo $show; ?> "> <ul class="subsubsub"> <li><a href='admin.php?page=<?php echo GWOLLE_GB_FOLDER; ?> /entries.php' <?php if ($show == 'all') { echo 'class="current"'; } ?> > <?php _e('All', GWOLLE_GB_TEXTDOMAIN); ?> <span class="count">(<?php echo $count['all']; ?> )</span></a> | </li> <li><a href='admin.php?page=<?php echo GWOLLE_GB_FOLDER; ?> /entries.php&show=checked' <?php if ($show == 'checked') { echo 'class="current"'; } ?> > <?php _e('Unlocked', GWOLLE_GB_TEXTDOMAIN); ?> <span class="count">(<?php echo $count['checked']; ?> )</span></a> | </li> <li><a href='admin.php?page=<?php echo GWOLLE_GB_FOLDER; ?> /entries.php&show=unchecked' <?php if ($show == 'unchecked') { echo 'class="current"'; } ?> ><?php _e('New', GWOLLE_GB_TEXTDOMAIN); ?> <span class="count">(<?php echo $count['unchecked']; ?> )</span></a> | </li> <li><a href='admin.php?page=<?php echo GWOLLE_GB_FOLDER; ?> /entries.php&show=spam' <?php if ($show == 'spam') { echo 'class="current"'; } ?> ><?php _e('Spam', GWOLLE_GB_TEXTDOMAIN); ?> <span class="count">(<?php echo $count['spam']; ?> )</span></a> | </li> <li><a href='admin.php?page=<?php echo GWOLLE_GB_FOLDER; ?> /entries.php&show=trash' <?php if ($show == 'trash') { echo 'class="current"'; } ?> ><?php _e('Trash', GWOLLE_GB_TEXTDOMAIN); ?> <span class="count">(<?php echo $count['trash']; ?> )</span></a> </li> </ul> <div class="tablenav"> <div class="alignleft actions"> <?php $massEditControls_select = '<select name="massEditAction1">'; $massEditControls = '<option value="-1" selected="selected">' . __('Mass edit actions', GWOLLE_GB_TEXTDOMAIN) . '</option>'; if ($show == 'trash') { $massEditControls .= ' <option value="untrash">' . __('Recover from trash', GWOLLE_GB_TEXTDOMAIN) . '</option> <option value="remove">' . __('Remove permanently', GWOLLE_GB_TEXTDOMAIN) . '</option>'; } else { if ($show != 'checked') { $massEditControls .= '<option value="check">' . __('Mark as checked', GWOLLE_GB_TEXTDOMAIN) . '</option>'; } if ($show != 'unchecked') { $massEditControls .= '<option value="uncheck">' . __('Mark as not checked', GWOLLE_GB_TEXTDOMAIN) . '</option>'; } if ($show != 'spam') { $massEditControls .= '<option value="spam">' . __('Mark as spam', GWOLLE_GB_TEXTDOMAIN) . '</option>'; } $massEditControls .= '<option value="no-spam">' . __('Mark as not spam', GWOLLE_GB_TEXTDOMAIN) . '</option>'; if (get_option('gwolle_gb-akismet-active', 'false') == 'true') { $massEditControls .= '<option value="akismet">' . __('Check with Akismet', GWOLLE_GB_TEXTDOMAIN) . '</option>'; } $massEditControls .= '<option value="trash">' . __('Move to trash', GWOLLE_GB_TEXTDOMAIN) . '</option>'; if ($show == 'spam') { $massEditControls .= '<option value="remove">' . __('Remove permanently', GWOLLE_GB_TEXTDOMAIN) . '</option>'; } } $massEditControls .= '</select>'; $massEditControls .= '<input type="submit" value="' . esc_attr__('Apply', GWOLLE_GB_TEXTDOMAIN) . '" name="doaction" id="doaction" class="button-secondary action" />'; $empty_button = ''; if ($show == 'spam') { $empty_button = '<input type="submit" name="delete_all" id="delete_all" class="button apply" value="' . esc_attr__('Empty Spam', GWOLLE_GB_TEXTDOMAIN) . '" />'; } else { if ($show == 'trash') { $empty_button = '<input type="submit" name="delete_all" id="delete_all" class="button apply" value="' . esc_attr__('Empty Trash', GWOLLE_GB_TEXTDOMAIN) . '" />'; } } // Only show controls when there are entries if (is_array($entries) && !empty($entries)) { echo $massEditControls_select . $massEditControls . $empty_button; } ?> </div> <?php $pagination = gwolle_gb_pagination_admin($pageNum, $countPages, $count, $show); echo $pagination; ?> </div> <div> <table class="widefat"> <thead> <tr> <th scope="col" class="manage-column column-cb check-column"><input name="check-all-top" id="check-all-top" type="checkbox"></th> <th scope="col"><?php _e('ID', GWOLLE_GB_TEXTDOMAIN); ?> </th> <?php if (get_option('gwolle_gb-showEntryIcons', 'true') === 'true') { ?> <th scope="col"> </th><!-- this is the icon-column --> <?php } ?> <th scope="col"><?php _e('Date', GWOLLE_GB_TEXTDOMAIN); ?> </th> <th scope="col"><?php _e('Author', GWOLLE_GB_TEXTDOMAIN); ?> </th> <th scope="col"><?php _e('Entry (excerpt)', GWOLLE_GB_TEXTDOMAIN); ?> </th> <th scope="col"><?php _e('Action', GWOLLE_GB_TEXTDOMAIN); ?> </th> </tr> </thead> <tfoot> <tr> <th scope="col" class="manage-column column-cb check-column"><input name="check-all-bottom" id="check-all-bottom" type="checkbox"></th> <th scope="col"><?php _e('ID', GWOLLE_GB_TEXTDOMAIN); ?> </th> <?php if (get_option('gwolle_gb-showEntryIcons', 'true') === 'true') { ?> <th scope="col"> </th><!-- this is the icon-column --> <?php } ?> <th scope="col"><?php _e('Date', GWOLLE_GB_TEXTDOMAIN); ?> </th> <th scope="col"><?php _e('Author', GWOLLE_GB_TEXTDOMAIN); ?> </th> <th scope="col"><?php _e('Entry (excerpt)', GWOLLE_GB_TEXTDOMAIN); ?> </th> <th scope="col"><?php _e('Action', GWOLLE_GB_TEXTDOMAIN); ?> </th> </tr> </tfoot> <tbody> <?php $rowOdd = true; $html_output = ''; if (!is_array($entries) || empty($entries)) { $colspan = get_option('gwolle_gb-showEntryIcons', 'true') === 'true' ? 7 : 6; $html_output .= ' <tr> <td colspan="' . $colspan . '" align="center"> <strong>' . __('No entries found.', GWOLLE_GB_TEXTDOMAIN) . '</strong> </td> </tr>'; } else { foreach ($entries as $entry) { // rows have a different color. if ($rowOdd) { $rowOdd = false; $class = ' alternate'; } else { $rowOdd = true; $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'; } // Checkbox and ID columns $html_output .= ' <tr id="entry_' . $entry->get_id() . '" class="entry ' . $class . '"> <td class="check"> <input name="check-' . $entry->get_id() . '" id="check-' . $entry->get_id() . '" type="checkbox"> </td> <td class="id">' . $entry->get_id() . '</td>'; // Optional Icon column where CSS is being used to show them or not if (get_option('gwolle_gb-showEntryIcons', 'true') === 'true') { $html_output .= ' <td class="entry-icons"> <span class="visible-icon"></span> <span class="invisible-icon"></span> <span class="spam-icon"></span> <span class="trash-icon"></span> <span class="gwolle_gb_ajax"></span> </td>'; } // Date column $html_output .= ' <td class="entry-date">' . date_i18n(get_option('date_format'), $entry->get_datetime()) . ', ' . date_i18n(get_option('time_format'), $entry->get_datetime()) . '</td>'; // Author column $author_name_html = gwolle_gb_get_author_name_html($entry); $html_output .= ' <td class="entry-author-name"><span class="author-name">' . $author_name_html . '</span><br />' . '<span class="author-email">' . $entry->get_author_email() . '</span>' . '</td>'; // Excerpt column $html_output .= ' <td class="entry-content"> <label for="check-' . $entry->get_id() . '">'; $entry_content = gwolle_gb_get_excerpt($entry->get_content(), 17); if (get_option('gwolle_gb-showSmilies', 'true') === 'true') { $entry_content = convert_smilies($entry_content); } $html_output .= $entry_content . '</label> </td>'; // Actions column $html_output .= ' <td class="gwolle_gb_actions"> <span class="gwolle_gb_edit"> <a href="admin.php?page=' . GWOLLE_GB_FOLDER . '/editor.php&entry_id=' . $entry->get_id() . '" title="' . __('Edit entry', GWOLLE_GB_TEXTDOMAIN) . '">' . __('Edit', GWOLLE_GB_TEXTDOMAIN) . '</a> </span> <span class="gwolle_gb_check"> | <a id="check_' . $entry->get_id() . '" href="#" class="vim-a" title="' . __('Check entry', GWOLLE_GB_TEXTDOMAIN) . '">' . __('Check', GWOLLE_GB_TEXTDOMAIN) . '</a> </span> <span class="gwolle_gb_uncheck"> | <a id="uncheck_' . $entry->get_id() . '" href="#" class="vim-u" title="' . __('Uncheck entry', GWOLLE_GB_TEXTDOMAIN) . '">' . __('Uncheck', GWOLLE_GB_TEXTDOMAIN) . '</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_TEXTDOMAIN) . '">' . __('Spam', GWOLLE_GB_TEXTDOMAIN) . '</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_TEXTDOMAIN) . '">' . __('Not spam', GWOLLE_GB_TEXTDOMAIN) . '</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_TEXTDOMAIN) . '">' . __('Trash', GWOLLE_GB_TEXTDOMAIN) . '</a> </span> <span class="gwolle_gb_untrash"> | <a id="untrash_' . $entry->get_id() . '" href="#" class="vim-d" title="' . __('Recover entry from trash.', GWOLLE_GB_TEXTDOMAIN) . '">' . __('Untrash', GWOLLE_GB_TEXTDOMAIN) . '</a> </span> <span class="gwolle_gb_ajax"> | <a id="ajax_' . $entry->get_id() . '" href="#" class="ajax vim-d vim-destructive" title="' . __('Please wait...', GWOLLE_GB_TEXTDOMAIN) . '">' . __('Wait...', GWOLLE_GB_TEXTDOMAIN) . '</a> </span> </td> </tr>'; } } echo $html_output; ?> </tbody> </table> </div> <div class="tablenav"> <div class="alignleft actions"> <?php $massEditControls_select = '<select name="massEditAction2">'; $empty_button = ''; if ($show == 'spam') { $empty_button = '<input type="submit" name="delete_all2" id="delete_all2" class="button apply" value="' . esc_attr__('Empty Spam', GWOLLE_GB_TEXTDOMAIN) . '" />'; } else { if ($show == 'trash') { $empty_button = '<input type="submit" name="delete_all2" id="delete_all2" class="button apply" value="' . esc_attr__('Empty Trash', GWOLLE_GB_TEXTDOMAIN) . '" />'; } } // Only show controls when there are entries if (is_array($entries) && !empty($entries)) { echo $massEditControls_select . $massEditControls . $empty_button; } ?> </div> <?php echo $pagination; ?> </div> </form> </div> <?php } }
function gwolle_gb_frontend_posthandling() { global $wpdb, $gwolle_gb_errors, $gwolle_gb_error_fields, $gwolle_gb_messages, $gwolle_gb_data; /* * Handle $_POST and check and save entry. */ if (isset($_POST['gwolle_gb_function']) && $_POST['gwolle_gb_function'] == 'add_entry') { // Initialize errors $gwolle_gb_errors = false; $gwolle_gb_error_fields = array(); // Initialize messages $gwolle_gb_messages = ''; // Option to allow only logged-in users to post. Don't show the form if not logged-in. if (!is_user_logged_in() && get_option('gwolle_gb-require_login', 'false') == 'true') { $gwolle_gb_errors = true; $gwolle_gb_messages .= '<p class="require_login"><strong>' . __('Submitting a new guestbook entry is only allowed for logged-in users.', 'gwolle-gb') . '</strong></p>'; return; } /* * Collect data from the Form */ $gwolle_gb_data = array(); $form_setting = gwolle_gb_get_setting('form'); /* Name */ if (isset($form_setting['form_name_enabled']) && $form_setting['form_name_enabled'] === 'true') { if (isset($_POST['gwolle_gb_author_name'])) { $gwolle_gb_data['author_name'] = trim($_POST['gwolle_gb_author_name']); $gwolle_gb_data['author_name'] = gwolle_gb_maybe_encode_emoji($gwolle_gb_data['author_name'], 'author_name'); if ($gwolle_gb_data['author_name'] == "") { if (isset($form_setting['form_name_mandatory']) && $form_setting['form_name_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'name'; // mandatory } } } else { if (isset($form_setting['form_name_mandatory']) && $form_setting['form_name_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'name'; // mandatory } } } /* City / Origin */ if (isset($form_setting['form_city_enabled']) && $form_setting['form_city_enabled'] === 'true') { if (isset($_POST['gwolle_gb_author_origin'])) { $gwolle_gb_data['author_origin'] = trim($_POST['gwolle_gb_author_origin']); $gwolle_gb_data['author_origin'] = gwolle_gb_maybe_encode_emoji($gwolle_gb_data['author_origin'], 'author_origin'); if ($gwolle_gb_data['author_origin'] == "") { if (isset($form_setting['form_city_mandatory']) && $form_setting['form_city_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'author_origin'; // mandatory } } } else { if (isset($form_setting['form_city_mandatory']) && $form_setting['form_city_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'author_origin'; // mandatory } } } /* Email */ if (isset($form_setting['form_email_enabled']) && $form_setting['form_email_enabled'] === 'true') { if (isset($_POST['gwolle_gb_author_email'])) { $gwolle_gb_data['author_email'] = trim($_POST['gwolle_gb_author_email']); if (filter_var($gwolle_gb_data['author_email'], FILTER_VALIDATE_EMAIL)) { // Valid Email address. } else { if (isset($form_setting['form_email_mandatory']) && $form_setting['form_email_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'author_email'; // mandatory } } } else { if (isset($form_setting['form_email_mandatory']) && $form_setting['form_email_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'author_email'; // mandatory } } } else { if (isset($_POST['gwolle_gb_author_email'])) { $gwolle_gb_data['author_email'] = trim($_POST['gwolle_gb_author_email']); } } /* Website / Homepage */ if (isset($form_setting['form_homepage_enabled']) && $form_setting['form_homepage_enabled'] === 'true') { if (isset($_POST['gwolle_gb_author_website'])) { $gwolle_gb_data['author_website'] = trim($_POST['gwolle_gb_author_website']); $pattern = '/^http/'; if (!preg_match($pattern, $gwolle_gb_data['author_website'], $matches)) { $gwolle_gb_data['author_website'] = "http://" . $gwolle_gb_data['author_website']; } if (filter_var($gwolle_gb_data['author_website'], FILTER_VALIDATE_URL)) { // Valid Website URL. } else { if (isset($form_setting['form_homepage_mandatory']) && $form_setting['form_homepage_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'author_website'; // mandatory } } } else { if (isset($form_setting['form_homepage_mandatory']) && $form_setting['form_homepage_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'author_website'; // mandatory } } } /* Message */ if (isset($form_setting['form_message_enabled']) && $form_setting['form_message_enabled'] === 'true') { if (isset($_POST['gwolle_gb_content'])) { $gwolle_gb_data['content'] = trim($_POST['gwolle_gb_content']); if ($gwolle_gb_data['content'] == "") { if (isset($form_setting['form_message_mandatory']) && $form_setting['form_message_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'content'; // mandatory } } else { $gwolle_gb_data['content'] = gwolle_gb_maybe_encode_emoji($gwolle_gb_data['content'], 'content'); } } else { if (isset($form_setting['form_message_mandatory']) && $form_setting['form_message_mandatory'] === 'true') { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'content'; // mandatory } } } /* 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) { if (isset($_POST["gwolle_gb_antispam_answer"]) && trim($_POST["gwolle_gb_antispam_answer"]) == trim($antispam_answer)) { //echo "You got it!"; } else { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'antispam'; // mandatory } } if (isset($_POST["gwolle_gb_antispam_answer"])) { $gwolle_gb_data['antispam'] = trim($_POST['gwolle_gb_antispam_answer']); } } /* CAPTCHA */ if (isset($form_setting['form_recaptcha_enabled']) && $form_setting['form_recaptcha_enabled'] === 'true') { if (class_exists('ReallySimpleCaptcha')) { $gwolle_gb_captcha = new ReallySimpleCaptcha(); // This variable holds the CAPTCHA image prefix, which corresponds to the correct answer $gwolle_gb_captcha_prefix = $_POST['gwolle_gb_captcha_prefix']; // This variable holds the CAPTCHA response, entered by the user $gwolle_gb_captcha_code = $_POST['gwolle_gb_captcha_code']; // Validate the CAPTCHA response $gwolle_gb_captcha_correct = $gwolle_gb_captcha->check($gwolle_gb_captcha_prefix, $gwolle_gb_captcha_code); // If CAPTCHA validation fails (incorrect value entered in CAPTCHA field) mark comment as spam. if (true != $gwolle_gb_captcha_correct) { $gwolle_gb_errors = true; $gwolle_gb_error_fields[] = 'captcha'; // mandatory //$gwolle_gb_messages .= '<p style="display_:none"><strong>' . $gwolle_gb_captcha_correct . '</strong></p>'; } else { // verified! //$gwolle_gb_messages .= '<p class="error_fields"><strong>Verified.</strong></p>'; } // clean up the tmp directory $gwolle_gb_captcha->remove($gwolle_gb_captcha_prefix); $gwolle_gb_captcha->cleanup(); } } /* If there are errors, stop here and return false */ if (is_array($gwolle_gb_error_fields) && !empty($gwolle_gb_error_fields)) { // There was no data filled in, even though that was mandatory. // $gwolle_gb_messages .= '<p class="error_fields"><strong>' . __('There were errors submitting your guestbook entry.', 'gwolle-gb') . '</strong></p>'; if (isset($gwolle_gb_error_fields)) { foreach ($gwolle_gb_error_fields as $field) { switch ($field) { case 'name': $gwolle_gb_messages .= '<p class="error_fields"><strong>Des mots aussi beaux, ça mérite une signature non ?</strong></p>'; break; case 'author_origin': $gwolle_gb_messages .= '<p class="error_fields"><strong>' . __('Your origin is not filled in, even though it is mandatory.', 'gwolle-gb') . '</strong></p>'; break; case 'author_email': $gwolle_gb_messages .= '<p class="error_fields"><strong>' . __('Your e-mail address is not filled in correctly, even though it is mandatory.', 'gwolle-gb') . '</strong></p>'; break; case 'author_website': $gwolle_gb_messages .= '<p class="error_fields"><strong>' . __('Your website is not filled in, even though it is mandatory.', 'gwolle-gb') . '</strong></p>'; break; case 'content': $gwolle_gb_messages .= '<p class="error_fields"><strong>Tu as oublié les mots doux ' . $gwolle_gb_data['author_name'] . ' :) !</strong></p>'; break; case 'antispam': $gwolle_gb_messages .= '<p class="error_fields"><strong>' . __('The anti-spam question was not answered correctly, even though it is mandatory.', 'gwolle-gb') . '</strong></p>'; break; case 'captcha': $gwolle_gb_messages .= '<p class="error_fields"><strong>' . __('The CAPTCHA was not filled in correctly, even though it is mandatory.', 'gwolle-gb') . '</strong></p>'; break; } } } $gwolle_gb_messages .= '<p class="error_fields" style="display: none;">' . print_r($gwolle_gb_error_fields, true) . '</p>'; return false; // no need to check and save } /* New Instance of gwolle_gb_entry. */ $entry = new gwolle_gb_entry(); /* Set the data in the instance */ $set_data = $entry->set_data($gwolle_gb_data); if (!$set_data) { // Data is not set in the Instance, something happened $gwolle_gb_errors = true; $gwolle_gb_messages .= '<p class="set_data"><strong>' . __('There were errors submitting your guestbook entry.', 'gwolle-gb') . '</strong></p>'; return false; } /* Check for spam and set accordingly */ $isspam = gwolle_gb_akismet($entry, 'comment-check'); if ($isspam) { // Returned true, so considered spam $entry->set_isspam(true); // Is it wise to make them any wiser? Probably not... // $gwolle_gb_messages .= '<p><strong>' . __('Your guestbook entry is probably spam. A moderator will decide upon it.', 'gwolle-gb') . '</strong></p>'; } /* if Moderation is off, set it to "ischecked" */ $user_id = get_current_user_id(); // returns 0 if no current user if (get_option('gwolle_gb-moderate-entries', 'true') == 'true') { if (gwolle_gb_is_moderator($user_id)) { $entry->set_ischecked(true); } else { $entry->set_ischecked(false); } } else { // First set to checked $entry->set_ischecked(true); // Check for abusive content (too long words). Set it to unchecked, so manual moderation is needed. $maxlength = 100; $words = explode(" ", $entry->get_content()); foreach ($words as $word) { if (strlen($word) > $maxlength) { $entry->set_ischecked(false); break; } } $maxlength = 60; $words = explode(" ", $entry->get_author_name()); foreach ($words as $word) { if (strlen($word) > $maxlength) { $entry->set_ischecked(false); break; } } } $entry->set_ischecked(false); /* Check for logged in user, and set the userid as author_id, just in case someone is also admin, or gets promoted some day */ $entry->set_author_id($user_id); /* * Network Information */ $entry->set_author_ip($_SERVER['REMOTE_ADDR']); $entry->set_author_host(gethostbyaddr($_SERVER['REMOTE_ADDR'])); /* * Book ID */ if (isset($_POST['gwolle_gb_book_id'])) { $gwolle_gb_data['book_id'] = (int) $_POST['gwolle_gb_book_id']; } if ($gwolle_gb_data['book_id'] < 1) { $gwolle_gb_data['book_id'] = 1; } $entry->set_book_id($gwolle_gb_data['book_id']); /* * Check for double post using email field and content. * Only if content is mandatory. */ if (isset($form_setting['form_message_mandatory']) && $form_setting['form_message_mandatory'] === 'true') { $entries = gwolle_gb_get_entries(array('email' => $entry->get_author_email())); if (is_array($entries) && !empty($entries)) { foreach ($entries as $entry_email) { if ($entry_email->get_content() == $entry->get_content()) { // Match is double entry $gwolle_gb_errors = true; $gwolle_gb_messages .= '<p class="double_post"><strong>' . __('Double post: An entry with the data you entered has already been saved.', 'gwolle-gb') . '</strong></p>'; return false; } } } } /* * Save the Entry */ // $save = ""; // Testing mode $save = $entry->save(); //if ( WP_DEBUG ) { echo "save: "; var_dump($save); } if ($save) { // We have been saved to the Database $gwolle_gb_messages .= '<p class="entry_saved">Merci pour ton message ' . $gwolle_gb_data['author_name'] . ' !</p>'; if ($entry->get_ischecked() == 0) { $gwolle_gb_messages .= '<p>Il apparaîtra bientôt sur le site !</p>'; } } /* * Update Cache plugins */ if ($entry->get_ischecked() == 1) { gwolle_gb_clear_cache(); } /* * Send the Notification Mail to moderators that have subscribed (only when it is not Spam) */ gwolle_gb_mail_moderators($entry); /* * Send Notification Mail to the author if set to true in an option */ gwolle_gb_mail_author($entry); /* * No Log for the Entry needed, it has a default post date in the Entry itself. */ } }
function gwolle_gb_frontend_read($shortcode_atts) { $output = ''; $entriesPerPage = (int) get_option('gwolle_gb-entriesPerPage', 20); $entriesCount = gwolle_gb_get_entry_count(array('checked' => 'checked', 'trash' => 'notrash', 'spam' => 'nospam', 'book_id' => $shortcode_atts['book_id'])); $countPages = ceil($entriesCount / $entriesPerPage); $pageNum = 1; if (isset($_GET['pageNum']) && is_numeric($_GET['pageNum'])) { $pageNum = intval($_GET['pageNum']); } if ($pageNum > $countPages) { // Page doesnot exist $pageNum = 1; } if ($pageNum == 1 && $entriesCount > 0) { $firstEntryNum = 1; $mysqlFirstRow = 0; } elseif ($entriesCount == 0) { $firstEntryNum = 0; $mysqlFirstRow = 0; } else { $firstEntryNum = ($pageNum - 1) * $entriesPerPage + 1; $mysqlFirstRow = $firstEntryNum - 1; } /* Get the entries for the frontend */ if (isset($_GET['show_all']) && $_GET['show_all'] == 'true') { $entries = gwolle_gb_get_entries(array('offset' => 0, 'num_entries' => -1, 'checked' => 'checked', 'trash' => 'notrash', 'spam' => 'nospam', 'book_id' => $shortcode_atts['book_id'])); $pageNum = 0; // do not have it set to 1, this way the '1' will be clickable too. } else { $entries = gwolle_gb_get_entries(array('offset' => $mysqlFirstRow, 'num_entries' => $entriesPerPage, 'checked' => 'checked', 'trash' => 'notrash', 'spam' => 'nospam', 'book_id' => $shortcode_atts['book_id'])); } /* Page navigation on top */ $pagination = gwolle_gb_pagination_frontend($pageNum, $countPages); $output .= $pagination; /* Entries from the template */ if (!is_array($entries) || empty($entries)) { $output .= __('(no entries yet)', 'gwolle-gb'); } else { $first = true; $output .= '<div id="gwolle_gb_entries">'; // Try to load and require_once the template from the themes folders. if (locate_template(array('gwolle_gb-entry.php'), true, true) == '') { $output .= '<!-- Gwolle-GB Entry: Default Template Loaded --> '; // No template found and loaded in the theme folders. // Load the template from the plugin folder. require_once 'gwolle_gb-entry.php'; } else { $output .= '<!-- Gwolle-GB Entry: Custom Template Loaded --> '; } $counter = 0; foreach ($entries as $entry) { $counter++; // Run the function from the template to get the entry. $entry_output = gwolle_gb_entry_template($entry, $first, $counter); $first = false; // Add a filter for each entry, so devs can add or remove parts. $output .= apply_filters('gwolle_gb_entry_read', $entry_output, $entry); } $output .= '</div>'; } /* Page navigation on bottom */ $output .= $pagination; // Add filter for the complete output. $output = apply_filters('gwolle_gb_entries_read', $output); return $output; }
function gwolle_gb_deleted_user($user_id) { $entries = gwolle_gb_get_entries(array('author_id' => $user_id, 'num_entries' => -1)); if (is_array($entries) && !empty($entries)) { foreach ($entries as $entry) { // method will take care of it... $save = $entry->save(); } } }
function gwolle_gb_dashboard() { if (function_exists('current_user_can') && !current_user_can('moderate_comments')) { return; } // Only get new and unchecked entries $entries = gwolle_gb_get_entries(array('num_entries' => 5, 'checked' => 'unchecked', 'trash' => 'notrash', 'spam' => 'nospam')); if (is_array($entries) && !empty($entries)) { // List of guestbook entries echo '<div class="gwolle-gb-dashboard gwolle-gb">'; $rowOdd = false; foreach ($entries as $entry) { $class = ''; // rows have a different color. if ($rowOdd) { $rowOdd = false; $class = ' alternate'; } else { $rowOdd = true; $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'; } ?> <div id="entry_<?php echo $entry->get_id(); ?> " class="comment depth-1 comment-item <?php echo $class; ?> "> <div class="dashboard-comment-wrap"> <h4 class="comment-meta"> <?php // Author info ?> <cite class="comment-author"><?php echo gwolle_gb_get_author_name_html($entry); ?> </cite> </h4> <?php // Optional Icon column where CSS is being used to show them or not /* if ( get_option('gwolle_gb-showEntryIcons', 'true') === 'true' ) { ?> <div class="entry-icons"> <span class="visible-icon"></span> <span class="invisible-icon"></span> <span class="spam-icon"></span> <span class="trash-icon"></span> <span class="gwolle_gb_ajax"></span> </div><?php } */ // Date column echo ' <div class="date">' . date_i18n(get_option('date_format'), $entry->get_datetime()) . ', ' . date_i18n(get_option('time_format'), $entry->get_datetime()) . '</div>'; ?> <blockquote class="excerpt"> <p> <?php // Content / Excerpt $entry_content = gwolle_gb_get_excerpt(gwolle_gb_bbcode_strip($entry->get_content()), 16); if (get_option('gwolle_gb-showSmilies', 'true') === 'true') { $entry_content = convert_smilies($entry_content); } echo $entry_content; ?> </p> </blockquote><?php // Actions, to be made with AJAX ?> <p class="row-actions" id="entry-actions-<?php echo $entry->get_id(); ?> "> <span class="gwolle_gb_edit"> <a href="admin.php?page=<?php echo GWOLLE_GB_FOLDER; ?> /editor.php&entry_id=<?php echo $entry->get_id(); ?> " title="<?php _e('Edit entry', GWOLLE_GB_TEXTDOMAIN); ?> "><?php _e('Edit', GWOLLE_GB_TEXTDOMAIN); ?> </a> </span> <span class="gwolle_gb_check"> | <a id="check_<?php echo $entry->get_id(); ?> " href="#" class="vim-a" title="<?php _e('Check entry', GWOLLE_GB_TEXTDOMAIN); ?> "><?php _e('Check', GWOLLE_GB_TEXTDOMAIN); ?> </a> </span> <span class="gwolle_gb_uncheck"> | <a id="uncheck_<?php echo $entry->get_id(); ?> " href="#" class="vim-u" title="<?php _e('Uncheck entry', GWOLLE_GB_TEXTDOMAIN); ?> "><?php _e('Uncheck', GWOLLE_GB_TEXTDOMAIN); ?> </a> </span> <span class="gwolle_gb_spam"> | <a id="spam_<?php echo $entry->get_id(); ?> " href="#" class="vim-s vim-destructive" title="<?php _e('Mark entry as spam.', GWOLLE_GB_TEXTDOMAIN); ?> "><?php _e('Spam', GWOLLE_GB_TEXTDOMAIN); ?> </a> </span> <span class="gwolle_gb_unspam"> | <a id="unspam_<?php echo $entry->get_id(); ?> " href="#" class="vim-a" title="<?php _e('Mark entry as not-spam.', GWOLLE_GB_TEXTDOMAIN); ?> "><?php _e('Not spam', GWOLLE_GB_TEXTDOMAIN); ?> </a> </span> <span class="gwolle_gb_trash"> | <a id="trash_<?php echo $entry->get_id(); ?> " href="#" class="vim-d vim-destructive" title="<?php _e('Move entry to trash.', GWOLLE_GB_TEXTDOMAIN); ?> "><?php _e('Trash', GWOLLE_GB_TEXTDOMAIN); ?> </a> </span> <span class="gwolle_gb_untrash"> | <a id="untrash_<?php echo $entry->get_id(); ?> " href="#" class="vim-d" title="<?php _e('Recover entry from trash.', GWOLLE_GB_TEXTDOMAIN); ?> "><?php _e('Untrash', GWOLLE_GB_TEXTDOMAIN); ?> </a> </span> <span class="gwolle_gb_ajax"> | <a id="ajax_<?php echo $entry->get_id(); ?> " href="#" class="ajax vim-d vim-destructive" title="<?php _e('Please wait...', GWOLLE_GB_TEXTDOMAIN); ?> "><?php _e('Wait...', GWOLLE_GB_TEXTDOMAIN); ?> </a> </span> </p> </div> </div> <?php } ?> </div> <p class="textright"> <a href="<?php echo $_SERVER['PHP_SELF']; ?> " class="button"><?php _e('Refresh', GWOLLE_GB_TEXTDOMAIN); ?> </a> <a href="admin.php?page=<?php echo GWOLLE_GB_FOLDER; ?> /entries.php&show=all" class="button button-primary"><?php _e('View all', GWOLLE_GB_TEXTDOMAIN); ?> </a> <a href="admin.php?page=<?php echo GWOLLE_GB_FOLDER; ?> /entries.php&show=unchecked" class="button button-primary"><?php _e('View new', GWOLLE_GB_TEXTDOMAIN); ?> </a> </p><?php } else { echo '<p>' . __('No new and unchecked guestbook entries.', GWOLLE_GB_TEXTDOMAIN) . '</p>'; } }
/** @see WP_Widget::widget */ function widget($args, $instance) { extract($args); $default_value = array("title" => __('Guestbook', GWOLLE_GB_TEXTDOMAIN), "num_entries" => 5, "best" => '', "name" => 1, "date" => 1, "num_words" => 10, "link_text" => __('Visit guestbook', GWOLLE_GB_TEXTDOMAIN), "postid" => 0); $instance = wp_parse_args((array) $instance, $default_value); $widget_title = esc_attr($instance['title']); $num_entries = (int) esc_attr($instance['num_entries']); $best = esc_attr($instance['best']); $best = explode(",", $best); $name = (int) esc_attr($instance['name']); $date = (int) esc_attr($instance['date']); $num_words = (int) esc_attr($instance['num_words']); $link_text = esc_attr($instance['link_text']); $postid = (int) esc_attr($instance['postid']); // Init $widget_html = ''; $widget_html .= $before_widget; $widget_html .= '<div class="gwolle_gb_widget">'; if ($widget_title !== FALSE) { $widget_html .= $before_title . apply_filters('widget_title', $widget_title) . $after_title; } $widget_html .= '<ul class="gwolle_gb_widget">'; $counter = 0; // Get the best entries first if (is_array($best) && !empty($best)) { foreach ($best as $entry_id) { if ($counter == $num_entries) { break; } // we have enough $entry = new gwolle_gb_entry(); $entry_id = intval($entry_id); if (isset($entry_id) && $entry_id > 0) { $result = $entry->load($entry_id); if (!$result) { // No entry loaded continue; } // Main Content $widget_html .= ' <li class="gwolle_gb_widget"> '; if ($name) { $widget_html .= '<span class="gb-author-name">' . $entry->get_author_name() . '</span>'; } if ($name && $date) { $widget_html .= " / "; } if ($date) { $widget_html .= '<span class="gb-date">' . date_i18n(get_option('date_format'), $entry->get_datetime()) . '</span>'; } if ($name || $date) { $widget_html .= ":<br />"; } $entry_content = gwolle_gb_get_excerpt(gwolle_gb_bbcode_strip($entry->get_content()), $num_words); if (get_option('gwolle_gb-showSmilies', 'true') === 'true') { $entry_content = convert_smilies($entry_content); } $widget_html .= '<span class="gb-entry-content">' . $entry_content . '</span'; $widget_html .= ' </li> '; $counter++; } } } // Get the latest $num_entries guestbook entries if ($counter != $num_entries) { // we have enough $entries = gwolle_gb_get_entries(array('num_entries' => $num_entries, 'checked' => 'checked', 'trash' => 'notrash', 'spam' => 'nospam')); if (is_array($entries) && !empty($entries)) { foreach ($entries as $entry) { if ($counter == $num_entries) { break; } // we have enough if (is_array($best) && in_array($entry->get_id(), $best)) { continue; } // already listed // Main Content $widget_html .= ' <li class="gwolle_gb_widget"> '; if ($name) { $widget_html .= '<span class="gb-author-name">' . $entry->get_author_name() . '</span>'; } if ($name && $date) { $widget_html .= " / "; } if ($date) { $widget_html .= '<span class="gb-date">' . date_i18n(get_option('date_format'), $entry->get_datetime()) . '</span>'; } if ($name || $date) { $widget_html .= ":<br />"; } $entry_content = gwolle_gb_get_excerpt(gwolle_gb_bbcode_strip($entry->get_content()), $num_words); if (get_option('gwolle_gb-showSmilies', 'true') === 'true') { $entry_content = convert_smilies($entry_content); } $widget_html .= '<span class="gb-entry-content">' . $entry_content . '</span>'; $widget_html .= ' </li> '; $counter++; } } } $widget_html .= '</ul>'; // Post the link to the Guestbook. if ((int) $postid > 0) { $widget_html .= ' <p class="gwolle_gb_link"> <a href="' . add_query_arg('p', $postid, get_home_url()) . '" title="' . __('Click here to get to the guestbook.', GWOLLE_GB_TEXTDOMAIN) . '">' . $link_text . ' »</a> </p>'; } $widget_html .= '</div>' . $after_widget; if ($counter > 0) { // Only display widget if there are any entries echo $widget_html; // Load Frontend CSS in Footer, only when it's active wp_enqueue_style('gwolle_gb_frontend_css'); } }