Skip to content

Commit

Permalink
style: auto-fix some space, newline and indentation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
stklcode committed Mar 17, 2024
1 parent 3e1f6a3 commit 19f17ab
Show file tree
Hide file tree
Showing 40 changed files with 165 additions and 168 deletions.
16 changes: 8 additions & 8 deletions src/Admin/CommentsColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function register_plugin_columns( $columns ) {
/**
* Display plugin column values on comments screen
*
* @param string $column Currently selected column.
* @param string $column Currently selected column.
* @param integer $comment_id Comment ID.
*
* @since 2.6.0
Expand Down Expand Up @@ -141,19 +141,19 @@ public static function filter_columns() {
global $wpdb;
?>
<label class="screen-reader-text"
for="filter-by-comment-spam-reason"><?php esc_html_e( 'Filter by spam reason', 'antispam-bee' ); ?></label>
for="filter-by-comment-spam-reason"><?php esc_html_e( 'Filter by spam reason', 'antispam-bee' ); ?></label>
<select id="filter-by-comment-spam-reason" name="comment_spam_reason">
<option value=""><?php esc_html_e( 'All spam reasons', 'antispam-bee' ); ?></option>
<?php
$spam_reason = isset( $_GET['comment_spam_reason'] ) ? sanitize_text_field( wp_unslash( $_GET['comment_spam_reason'] ) ) : '';
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
$tmp = $wpdb->get_results( "SELECT meta_value FROM {$wpdb->prefix}commentmeta WHERE meta_key = 'antispam_bee_reason' GROUP BY meta_value", ARRAY_A );
$tmp = $wpdb->get_results( "SELECT meta_value FROM {$wpdb->prefix}commentmeta WHERE meta_key = 'antispam_bee_reason' GROUP BY meta_value", ARRAY_A );
$reasons = [];
foreach ( $tmp as $t ) {
$reasons = array_merge( $reasons, explode( ',', $t['meta_value'] ) );
}

$reasons = array_unique( $reasons );
$reasons = array_unique( $reasons );
$reason_mapping = PluginUpdate::$spam_reasons_mapping;

foreach ( $reasons as $reason ) {
Expand Down Expand Up @@ -202,13 +202,13 @@ public static function filter_by_spam_reason( $query ) {
$query->query_vars['meta_query'] = [
'relation' => 'OR',
[
'key' => 'antispam_bee_reason',
'value' => $spam_reason,
'key' => 'antispam_bee_reason',
'value' => $spam_reason,
'compare' => 'LIKE',
],
[
'key' => 'antispam_bee_reason',
'value' => array_flip( $reasons_mapping )[ $spam_reason ],
'key' => 'antispam_bee_reason',
'value' => array_flip( $reasons_mapping )[ $spam_reason ],
'compare' => 'LIKE',
],
];
Expand Down
24 changes: 12 additions & 12 deletions src/Admin/DashboardWidgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ public static function add_dashboard_count( $items = array() ) {
echo '<style>#dashboard_right_now .ab-count::before {content: "\f117"} #dashboard_right_now .ab-current-spam::before {content: "\f17e"}</style>';

$items[] = '<span class="ab-count">' . esc_html(
sprintf(
sprintf(
// translators: The number of spam comments Antispam Bee blocked so far.
__( '%s comments blocked', 'antispam-bee' ),
self::get_spam_count()
)
) . '</span>';
__( '%s comments blocked', 'antispam-bee' ),
self::get_spam_count()
)
) . '</span>';

$link = add_query_arg( 'comment_status', 'spam', admin_url( 'edit-comments.php' ) );
$link = add_query_arg( 'comment_status', 'spam', admin_url( 'edit-comments.php' ) );
$comments_number = wp_count_comments();
$items[] = '<a href="' . $link . '" class="ab-current-spam">' . esc_html(
sprintf(
$items[] = '<a href="' . $link . '" class="ab-current-spam">' . esc_html(
sprintf(
// translators: The number of spam comments in the local spam database.
__( '%s comments in local spam db', 'antispam-bee' ),
self::format_number( $comments_number->spam )
)
) . '</a>';
__( '%s comments in local spam db', 'antispam-bee' ),
self::format_number( $comments_number->spam )
)
) . '</a>';

return $items;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Admin/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ abstract class Field {
/**
* Initializing field
*
* @param string $type Item type.
* @param array $option Field options.
* @param string $type Item type.
* @param array $option Field options.
* @param class-string<Controllable> $controllable The related controllable.
*/
public function __construct( $type, $option, $controllable ) {
Expand All @@ -64,7 +64,7 @@ public function get_name() {
* @return string Label of the field.
*/
public function get_label() {
$kses = isset( $this->option['label_kses'] ) ? $this->option['label_kses'] : [];
$kses = isset( $this->option['label_kses'] ) ? $this->option['label_kses'] : [];
$label = isset( $this->option['label'] ) ? $this->option['label'] : '';
if ( ! $kses ) {
return esc_html( $label );
Expand Down
19 changes: 12 additions & 7 deletions src/Admin/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class Section {
/**
* Initializing Tab.
*
* @param string $slug Slug of the tab.
* @param string $title Title for tab.
* @param string $description Description of the tab.
* @param string $slug Slug of the tab.
* @param string $title Title for tab.
* @param string $description Description of the tab.
* @param string|null $type Item type (e.g. comment, trackback).
*/
public function __construct( $slug, $title, $description = '', $type = null ) {
Expand Down Expand Up @@ -189,10 +189,15 @@ public function get_callback() {
* Renders the settings section.
*/
public function render() {
add_settings_section( $this->get_slug(), $this->get_title(), [
$this,
'get_callback'
], SettingsPage::SETTINGS_PAGE_SLUG );
add_settings_section(
$this->get_slug(),
$this->get_title(),
[
$this,
'get_callback',
],
SettingsPage::SETTINGS_PAGE_SLUG
);

foreach ( $this->get_rows() as $row ) {
add_settings_field(
Expand Down
4 changes: 2 additions & 2 deletions src/Admin/SettingsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ public function options_page() {
<li>
<?php if ( $tab->get_slug() === $this->active_tab ) : ?>
<a href="?page=antispam_bee&tab=<?php echo esc_attr( $tab->get_slug() ); ?>"
class="nav-tab nav-tab-active"><?php echo esc_html( $tab->get_title() ); ?></a>
class="nav-tab nav-tab-active"><?php echo esc_html( $tab->get_title() ); ?></a>
<?php else : ?>
<a href="?page=antispam_bee&tab=<?php echo esc_attr( $tab->get_slug() ); ?>"
class="nav-tab"><?php echo esc_html( $tab->get_title() ); ?></a>
class="nav-tab"><?php echo esc_html( $tab->get_title() ); ?></a>
<?php endif; ?>
</li>
<?php endforeach; ?>
Expand Down
4 changes: 2 additions & 2 deletions src/Admin/Tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class Tab {
/**
* Initialize the tab.
*
* @param string $slug Title for tab
* @param string $title Title for tab
* @param string $slug Title for tab
* @param string $title Title for tab
* @param Section[] $sections Sections object array.
*/
public function __construct( $slug, $title, $sections = [] ) {
Expand Down
2 changes: 0 additions & 2 deletions src/GeneralOptions/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public static function get_options() {
*
* @return void
* @since 3.0.0
*
*/
public static function init() {
add_filter( 'antispam_bee_general_options', [ static::class, 'add_general_option' ] );
Expand All @@ -48,7 +47,6 @@ public static function init() {
*
* @return mixed
* @since 3.0.0
*
*/
public static function add_general_option( $options ) {
$options[] = static::class;
Expand Down
2 changes: 1 addition & 1 deletion src/Handlers/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function process( $comment ) {
/**
* Filter processable comment types.
*
* @param array $types List of comment types
* @param array $types List of comment types
*/
$comment_types = (array) apply_filters( 'antispam_bee_comment_types', [ '', 'comment', 'review' ] );

Expand Down
1 change: 0 additions & 1 deletion src/Handlers/PluginStateChangeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public static function uninstall() {
self::maybe_remove_antispam_bee_data();
restore_current_blog();
}

}

private static function maybe_remove_antispam_bee_data() {
Expand Down
70 changes: 35 additions & 35 deletions src/Handlers/PluginUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,46 +109,46 @@ private static function maybe_update_database() {

$new_options = [
'comment' => [
'post_processor_asb_delete_spam_active' => isset( $options['flag_spam'] ) && ! $options['flag_spam'] ? 'on' : '',
'post_processor_asb_send_email_active' => $options['email_notify'] ? 'on' : '',
'post_processor_asb_save_reason_active' => isset( $options['no_notice'] ) && ! $options['no_notice'] ? 'on' : '',
'rule_asb_regexp_active' => $options['regexp_check'] ? 'on' : '',
'rule_asb_honeypot_active' => 'on',
'rule_asb_db_spam_active' => $options['spam_ip'] ? 'on' : '',
'rule_asb_approved_email_active' => $options['already_commented'] ? 'on' : '',
'rule_asb_too_fast_submit_active' => $options['time_check'] ? 'on' : '',
'post_processor_asb_delete_for_reasons_active' => $options['reasons_enable'] ? 'on' : '',
'post_processor_asb_delete_for_reasons_reasons' => $delete_reasons,
'rule_asb_bbcode_active' => $options['bbcode_check'] ? 'on' : '',
'rule_asb_valid_gravatar_active' => $options['gravatar_check'] ? 'on' : '',
'rule_asb_country_spam_active' => $options['country_code'] ? 'on' : '',
'rule_asb_country_spam_denied' => $options['country_denied'] ?? '',
'rule_asb_country_spam_allowed' => $options['country_allowed'] ?? '',
'rule_asb_lang_spam_active' => $options['translate_api'] ? 'on' : '',
'rule_asb_lang_spam_allowed' => $allowed_languages,
'post_processor_asb_delete_spam_active' => isset( $options['flag_spam'] ) && ! $options['flag_spam'] ? 'on' : '',
'post_processor_asb_send_email_active' => $options['email_notify'] ? 'on' : '',
'post_processor_asb_save_reason_active' => isset( $options['no_notice'] ) && ! $options['no_notice'] ? 'on' : '',
'rule_asb_regexp_active' => $options['regexp_check'] ? 'on' : '',
'rule_asb_honeypot_active' => 'on',
'rule_asb_db_spam_active' => $options['spam_ip'] ? 'on' : '',
'rule_asb_approved_email_active' => $options['already_commented'] ? 'on' : '',
'rule_asb_too_fast_submit_active' => $options['time_check'] ? 'on' : '',
'post_processor_asb_delete_for_reasons_active' => $options['reasons_enable'] ? 'on' : '',
'post_processor_asb_delete_for_reasons_reasons' => $delete_reasons,
'rule_asb_bbcode_active' => $options['bbcode_check'] ? 'on' : '',
'rule_asb_valid_gravatar_active' => $options['gravatar_check'] ? 'on' : '',
'rule_asb_country_spam_active' => $options['country_code'] ? 'on' : '',
'rule_asb_country_spam_denied' => $options['country_denied'] ?? '',
'rule_asb_country_spam_allowed' => $options['country_allowed'] ?? '',
'rule_asb_lang_spam_active' => $options['translate_api'] ? 'on' : '',
'rule_asb_lang_spam_allowed' => $allowed_languages,
],
'linkback' => [
'post_processor_asb_delete_spam_active' => isset( $options['flag_spam'] ) && ! $options['flag_spam'] ? 'on' : '',
'post_processor_asb_send_email_active' => $options['email_notify'] ? 'on' : '',
'post_processor_asb_save_reason_active' => isset( $options['no_notice'] ) && ! $options['no_notice'] ? 'on' : '',
'rule_asb_regexp_active' => $options['regexp_check'] ? 'on' : '',
'rule_asb_db_spam_active' => $options['spam_ip'] ? 'on' : '',
'post_processor_asb_delete_for_reasons_active' => $options['reasons_enable'] ? 'on' : '',
'post_processor_asb_delete_spam_active' => isset( $options['flag_spam'] ) && ! $options['flag_spam'] ? 'on' : '',
'post_processor_asb_send_email_active' => $options['email_notify'] ? 'on' : '',
'post_processor_asb_save_reason_active' => isset( $options['no_notice'] ) && ! $options['no_notice'] ? 'on' : '',
'rule_asb_regexp_active' => $options['regexp_check'] ? 'on' : '',
'rule_asb_db_spam_active' => $options['spam_ip'] ? 'on' : '',
'post_processor_asb_delete_for_reasons_active' => $options['reasons_enable'] ? 'on' : '',
'post_processor_asb_delete_for_reasons_reasons' => $delete_reasons,
'rule_asb_bbcode_active' => $options['bbcode_check'] ? 'on' : '',
'rule_asb_valid_gravatar_active' => $options['gravatar_check'] ? 'on' : '',
'rule_asb_country_spam_active' => $options['country_code'] ? 'on' : '',
'rule_asb_country_spam_denied' => $options['country_denied'] ?? '',
'rule_asb_country_spam_allowed' => $options['country_allowed'] ?? '',
'rule_asb_lang_spam_active' => $options['translate_api'] ? 'on' : '',
'rule_asb_lang_spam_allowed' => $allowed_languages,
'rule_asb_bbcode_active' => $options['bbcode_check'] ? 'on' : '',
'rule_asb_valid_gravatar_active' => $options['gravatar_check'] ? 'on' : '',
'rule_asb_country_spam_active' => $options['country_code'] ? 'on' : '',
'rule_asb_country_spam_denied' => $options['country_denied'] ?? '',
'rule_asb_country_spam_allowed' => $options['country_allowed'] ?? '',
'rule_asb_lang_spam_active' => $options['translate_api'] ? 'on' : '',
'rule_asb_lang_spam_allowed' => $allowed_languages,
],
'general' => [
'general_delete_spam_cronjob_enabled_active' => $options['cronjob_enable'] ? 'on' : '',
'general_delete_spam_cronjob_enabled_active' => $options['cronjob_enable'] ? 'on' : '',
'general_delete_spam_cronjob_enabled_delete_spam_cronjob_days' => $options['cronjob_interval'] ?? 30,
'general_statistics_on_dashboard_active' => $options['dashboard_count'] ? 'on' : '',
'general_ignore_linkbacks_active' => $options['ignore_pings'] ? 'on' : '',
'general_delete_data_on_uninstall_active' => $options['delete_data_on_uninstall'] ? 'on' : '',
'general_statistics_on_dashboard_active' => $options['dashboard_count'] ? 'on' : '',
'general_ignore_linkbacks_active' => $options['ignore_pings'] ? 'on' : '',
'general_delete_data_on_uninstall_active' => $options['delete_data_on_uninstall'] ? 'on' : '',
],
'spam_count' => $options['spam_count'] ?? 0,
];
Expand All @@ -171,7 +171,7 @@ private static function convert_multiselect_values( $values, $mapping = [] ) {
}

$flipped_values = array_flip( $values );
$new_array = [];
$new_array = [];
foreach ( $flipped_values as $key => $value ) {
if ( ! empty( $mapping ) && array_key_exists( $key, $mapping ) ) {
$key = $mapping[ $key ];
Expand Down
6 changes: 3 additions & 3 deletions src/Handlers/PostProcessors.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class PostProcessors {
/**
* @param string $reaction_type one of the supported content types.
* @param string $reaction_type one of the supported content types.
* @param $item
* @param $reasons
*
Expand All @@ -17,12 +17,12 @@ class PostProcessors {
public static function apply( $reaction_type, $item, $reasons = [] ) {
$post_processors = self::get( $reaction_type, true );

$item['asb_reasons'] = $reasons;
$item['asb_reasons'] = $reasons;
$item['reaction_type'] = $reaction_type;

// Move the post processors that mark an item as to delete to front,
// so that following processors know if they handle an item that will be deleted.
for ( $i = 0; $i < count( $post_processors ); $i ++ ) {
for ( $i = 0; $i < count( $post_processors ); $i++ ) {
if ( $post_processors[ $i ]::marks_as_delete() ) {
$post_processor = $post_processors[ $i ];
unset( $post_processors[ $i ] );
Expand Down
11 changes: 7 additions & 4 deletions src/Handlers/Reaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ public static function init() {
);

// Add our manual spam reason to the list of reasons.
add_filter( 'antispam_bee_additional_spam_reasons', function ( $reasons ) {
$reasons['asb-marked-manually'] = __( 'Manually', 'antispam-bee' );
return $reasons;
} );
add_filter(
'antispam_bee_additional_spam_reasons',
function ( $reasons ) {
$reasons['asb-marked-manually'] = __( 'Manually', 'antispam-bee' );
return $reasons;
}
);
}

public static function always_init() {
Expand Down
6 changes: 3 additions & 3 deletions src/Handlers/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Rules {
protected $type;
protected $spam_reasons = [];
protected $spam_reasons = [];
protected $no_spam_reasons = [];

public function __construct( $type ) {
Expand All @@ -19,7 +19,7 @@ public function __construct( $type ) {

public function apply( $item ) {
$item['reaction_type'] = $this->type;
$rules = self::get( $this->type, true );
$rules = self::get( $this->type, true );

$no_spam_threshold = (float) apply_filters( 'antispam_bee_no_spam_threshold', 0.0 );
$spam_threshold = (float) apply_filters( 'antispam_bee_spam_threshold', 0.0 );
Expand All @@ -37,7 +37,7 @@ public function apply( $item ) {
DebugMode::log( "Checking »{$rule::get_name()}« rule" );

$rule_score = $rule::verify( $item ) * $rule::get_weight();

DebugMode::log( "Score: {$rule_score}" );

if ( $rule_score > 0.0 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/ComponentsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ComponentsHelper {
*/
public static function filter( $components, $options ) {
$reaction_type = isset( $options['reaction_type'] ) ? $options['reaction_type'] : null;
$only_active = isset( $options['only_active'] ) ? $options['only_active'] : false;
$only_active = isset( $options['only_active'] ) ? $options['only_active'] : false;

$filtered_components = [];
foreach ( $components as $component ) {
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/ContentTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class ContentTypeHelper {

const GENERAL_TYPE = 'general';
const COMMENT_TYPE = 'comment';
const GENERAL_TYPE = 'general';
const COMMENT_TYPE = 'comment';
const LINKBACK_TYPE = 'linkback';

public static function get_type_name( $item_type ) {
Expand Down
Loading

0 comments on commit 19f17ab

Please sign in to comment.