function gwolle_gb_akismet($entry, $action) { $actions = array('comment-check', 'submit-ham', 'submit-spam'); if (!in_array($action, $actions)) { return false; } $akismet_active = get_option('gwolle_gb-akismet-active', 'false'); if ($akismet_active != 'true') { // Akismet is not active, so we don't do anything return false; } if (is_callable(array('Akismet', 'get_api_key'))) { // Akismet v3.0+ $api_key = (bool) Akismet::get_api_key(); } else { if (function_exists('akismet_get_key')) { $api_key = (bool) akismet_get_key(); } } if (!$api_key) { // No api key, no glory return false; } if (!is_object($entry)) { // No object, no fuss return false; } $comment = array(); $comment['comment_author'] = $entry->get_author_name(); $comment['comment_author_email'] = $entry->get_author_email(); $comment['comment_author_origin'] = $entry->get_author_origin(); $comment['comment_author_url'] = $entry->get_author_website(); $comment['comment_content'] = gwolle_gb_bbcode_strip($entry->get_content()); $comment['blog'] = get_option('home'); $comment['blog_lang'] = get_locale(); $comment['blog_charset'] = get_option('blog_charset'); $comment['user_ip'] = preg_replace('/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR']); $comment['user_agent'] = $_SERVER['HTTP_USER_AGENT']; if (isset($_SERVER['HTTP_REFERER'])) { $comment['referrer'] = $_SERVER['HTTP_REFERER']; } // http://blog.akismet.com/2012/06/19/pro-tip-tell-us-your-comment_type/ $comment['comment_type'] = 'comment'; $permalink = get_permalink(get_the_ID()); if ($permalink) { $comment['permalink'] = $permalink; } $ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'); foreach ($_SERVER as $key => $value) { if (!in_array($key, (array) $ignore)) { $comment["{$key}"] = $value; } } // Send the thing to the Akismet service return gwolle_gb_akismet_entry_check($comment, $action); }
function gwolle_gb_entry_template($entry, $first, $counter) { $html5 = current_theme_supports('html5'); // Get the needed settings. $form_setting = gwolle_gb_get_setting('form'); $read_setting = gwolle_gb_get_setting('read'); // Main Author div $entry_output = '<div class="'; $entry_output .= ' gb-entry'; $entry_output .= ' gb-entry_' . $entry->get_id(); $entry_output .= ' gb-entry-count_' . $counter; if (is_int($counter / 2)) { $entry_output .= ' gwolle_gb_even'; } else { $entry_output .= ' gwolle_gb_uneven'; } if ($first == true) { $entry_output .= ' gwolle_gb_first'; } if (get_option('gwolle_gb-admin_style', 'true') === 'true') { $author_id = $entry->get_author_id(); $is_moderator = gwolle_gb_is_moderator($author_id); if ($is_moderator) { $entry_output .= ' admin-entry'; } } $entry_output .= '">'; if ($html5) { $entry_output .= '<article>'; } // Use this filter to just add something $entry_output .= apply_filters('gwolle_gb_entry_read_add_before', '', $entry); // Author Avatar // if ( isset($read_setting['read_avatar']) && $read_setting['read_avatar'] === 'true' ) { // $avatar = get_avatar( $entry->get_author_email(), 32, '', $entry->get_author_name() ); // if ($avatar) { // $entry_output .= '<span class="gb-author-avatar">' . $avatar . '</span>'; // } // } // Author Origin // if ( isset($read_setting['read_city']) && $read_setting['read_city'] === 'true' ) { // $origin = $entry->get_author_origin(); // if ( strlen(str_replace(' ', '', $origin)) > 0 ) { // $entry_output .= '<span class="gb-author-origin"> ' . __('from', 'gwolle-gb') . ' ' . gwolle_gb_sanitize_output($origin) . '</span>'; // } // } // Entry Date and Time // if ( ( isset($read_setting['read_datetime']) && $read_setting['read_datetime'] === 'true' ) || ( isset($read_setting['read_date']) && $read_setting['read_date'] === 'true' ) ) { // $entry_output .= '<span class="gb-datetime"> // <span class="gb-date"> '; // if ( isset($read_setting['read_name']) && $read_setting['read_name'] === 'true' ) { // $entry_output .= __('wrote on', 'gwolle-gb') . ' '; // } // $entry_output .= date_i18n( get_option('date_format'), $entry->get_datetime() ) . '</span>'; // if ( isset($read_setting['read_datetime']) && $read_setting['read_datetime'] === 'true' ) { // $entry_output .= '<span class="gb-time"> ' . __('on', 'gwolle-gb') . ' ' . trim(date_i18n( get_option('time_format'), $entry->get_datetime() )) . '</span>'; // } // $entry_output .= ':</span> '; // } // Main Content if (isset($read_setting['read_content']) && $read_setting['read_content'] === 'true') { $entry_output .= '<div class="gb-entry-content">'; $entry_content = gwolle_gb_sanitize_output($entry->get_content()); if (get_option('gwolle_gb-showSmilies', 'true') === 'true') { $entry_content = convert_smilies($entry_content); } if (get_option('gwolle_gb-showLineBreaks', 'false') === 'true') { $entry_content = nl2br($entry_content); } $excerpt_length = (int) get_option('gwolle_gb-excerpt_length', 0); if ($excerpt_length > 0) { $entry_content = wp_trim_words($entry_content, $excerpt_length, '...'); // FIXME: add readmore link } if (isset($form_setting['form_bbcode_enabled']) && $form_setting['form_bbcode_enabled'] === 'true') { $entry_content = gwolle_gb_bbcode_parse($entry_content); } else { $entry_content = gwolle_gb_bbcode_strip($entry_content); } $entry_output .= $entry_content; // // Edit Link for Moderators // if ( function_exists('current_user_can') && current_user_can('moderate_comments') ) { // $entry_output .= ' // <a class="gwolle_gb_edit_link" href="' . admin_url('admin.php?page=' . GWOLLE_GB_FOLDER . '/editor.php&entry_id=' . $entry->get_id() ) . '" title="' . __('Edit entry', 'gwolle-gb') . '">' . __('Edit', 'gwolle-gb') . '</a>'; // } // Use this filter to just add something $entry_output .= apply_filters('gwolle_gb_entry_read_add_content', '', $entry); $entry_output .= '</div> '; /* Admin Reply */ $admin_reply_content = gwolle_gb_sanitize_output($entry->get_admin_reply()); if ($admin_reply_content != '') { $class = ''; if (get_option('gwolle_gb-admin_style', 'true') === 'true') { $class = ' admin-entry'; } $admin_reply = '<div class="gb-entry-admin_reply' . $class . '">'; /* Admin Reply Author */ $admin_reply .= '<div class="gb-admin_reply_uid">'; $admin_reply_name = gwolle_gb_is_moderator($entry->get_admin_reply_uid()); if (isset($read_setting['read_name']) && $read_setting['read_name'] === 'true' && $admin_reply_name) { $admin_reply .= '<strong>' . __('Admin Reply by:', 'gwolle-gb') . '</strong> ' . $admin_reply_name; } else { $admin_reply .= '<strong>' . __('Admin Reply:', 'gwolle-gb') . '</strong>'; } $admin_reply .= '</div> '; /* Admin Reply Content */ if (get_option('gwolle_gb-showSmilies', 'true') === 'true') { $admin_reply_content = convert_smilies($admin_reply_content); } if (get_option('gwolle_gb-showLineBreaks', 'false') === 'true') { $admin_reply_content = nl2br($admin_reply_content); } if ($excerpt_length > 0) { $admin_reply_content = wp_trim_words($admin_reply_content, $excerpt_length, '...'); } if (isset($form_setting['form_bbcode_enabled']) && $form_setting['form_bbcode_enabled'] === 'true') { $admin_reply_content = gwolle_gb_bbcode_parse($admin_reply_content); } else { $admin_reply_content = gwolle_gb_bbcode_strip($admin_reply_content); } $admin_reply .= '<div class="gb-admin_reply_content"> ' . $admin_reply_content . ' </div>'; $admin_reply .= '</div>'; $entry_output .= $admin_reply; } } // Author Info $entry_output .= '<div class="gb-author-info">'; // Author Name if (isset($read_setting['read_name']) && $read_setting['read_name'] === 'true') { $author_name_html = gwolle_gb_get_author_name_html($entry); $entry_output .= '<span class="gb-author-name">' . $author_name_html . '</span>'; } $entry_output .= '</div>'; // <div class="gb-author-info"> // Use this filter to just add something $entry_output .= apply_filters('gwolle_gb_entry_read_add_after', '', $entry); if ($html5) { $entry_output .= '</article>'; } $entry_output .= '</div> '; return $entry_output; }
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'); } }
function gwolle_gb_entry_template($entry, $first, $counter) { // Get the needed settings. $form_setting = gwolle_gb_get_setting('form'); $read_setting = gwolle_gb_get_setting('read'); // Main Author div $entry_output = '<div class="'; $entry_output .= ' gb-entry'; $entry_output .= ' gb-entry_' . $entry->get_id(); if (is_int($counter / 2)) { $entry_output .= ' gwolle_gb_even'; } else { $entry_output .= ' gwolle_gb_uneven'; } if ($first == true) { $entry_output .= ' gwolle_gb_first'; } if (get_option('gwolle_gb-admin_style', 'true') === 'true') { $author_id = $entry->get_author_id(); $is_moderator = gwolle_gb_is_moderator($author_id); if ($is_moderator) { $entry_output .= ' admin-entry'; } } $entry_output .= '">'; // Author Info $entry_output .= '<div class="gb-author-info">'; // Author Avatar if (isset($read_setting['read_avatar']) && $read_setting['read_avatar'] === 'true') { $avatar = get_avatar($entry->get_author_email(), 32, '', $entry->get_author_name()); if ($avatar) { $entry_output .= '<span class="gb-author-avatar">' . $avatar . '</span>'; } } // Author Name if (isset($read_setting['read_name']) && $read_setting['read_name'] === 'true') { $author_name_html = gwolle_gb_get_author_name_html($entry); $entry_output .= '<span class="gb-author-name">' . $author_name_html . '</span>'; } // Author Origin if (isset($read_setting['read_city']) && $read_setting['read_city'] === 'true') { $origin = $entry->get_author_origin(); if (strlen(str_replace(' ', '', $origin)) > 0) { $entry_output .= '<span class="gb-author-origin"> ' . __('from', GWOLLE_GB_TEXTDOMAIN) . ' ' . gwolle_gb_sanitize_output($origin) . '</span>'; } } // Entry Date and Time if (isset($read_setting['read_datetime']) && $read_setting['read_datetime'] === 'true' || isset($read_setting['read_date']) && $read_setting['read_date'] === 'true') { $entry_output .= '<span class="gb-datetime"> <span class="gb-date"> '; if (isset($read_setting['read_name']) && $read_setting['read_name'] === 'true') { $entry_output .= __('wrote on', GWOLLE_GB_TEXTDOMAIN) . ' '; } $entry_output .= date_i18n(get_option('date_format'), $entry->get_datetime()) . '</span>'; if (isset($read_setting['read_datetime']) && $read_setting['read_datetime'] === 'true') { $entry_output .= '<span class="gb-time"> ' . __('on', GWOLLE_GB_TEXTDOMAIN) . ' ' . trim(date_i18n(get_option('time_format'), $entry->get_datetime())) . '</span>'; } $entry_output .= ':</span> '; } $entry_output .= '</div>'; // <div class="gb-author-info"> // Main Content if (isset($read_setting['read_content']) && $read_setting['read_content'] === 'true') { $entry_output .= '<div class="gb-entry-content">'; $entry_content = gwolle_gb_sanitize_output($entry->get_content()); if (get_option('gwolle_gb-showSmilies', 'true') === 'true') { $entry_content = convert_smilies($entry_content); } if (get_option('gwolle_gb-showLineBreaks', 'false') === 'true') { $entry_content = nl2br($entry_content); } $excerpt_length = (int) get_option('gwolle_gb-excerpt_length', 0); if ($excerpt_length > 0) { $entry_content = wp_trim_words($entry_content, $excerpt_length, '...'); } if (isset($form_setting['form_bbcode_enabled']) && $form_setting['form_bbcode_enabled'] === 'true') { $entry_content = gwolle_gb_bbcode_parse($entry_content); } else { $entry_content = gwolle_gb_bbcode_strip($entry_content); } $entry_output .= $entry_content; // Edit Link for Moderators if (function_exists('current_user_can') && current_user_can('moderate_comments')) { $entry_output .= ' <a class="gwolle_gb_edit_link" href="' . admin_url('admin.php?page=' . GWOLLE_GB_FOLDER . '/editor.php&entry_id=' . $entry->get_id()) . '" title="' . __('Edit entry', GWOLLE_GB_TEXTDOMAIN) . '">' . __('Edit', GWOLLE_GB_TEXTDOMAIN) . '</a>'; } $entry_output .= '</div> '; } $entry_output .= '</div> '; return $entry_output; }