Skip to content

Commit

Permalink
Merge pull request #48 from erikyo/php/psr
Browse files Browse the repository at this point in the history
psr autoload
  • Loading branch information
erikyo authored Oct 13, 2023
2 parents bc2a140 + 7e51316 commit 8e26419
Show file tree
Hide file tree
Showing 29 changed files with 207 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ Thumbs.db

# lock files
.lock

composer.lock
**/dist/
12 changes: 9 additions & 3 deletions admin/admin.php → admin/CF7_AntiSpam_Admin_Core.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php

namespace CF7_AntiSpam\Admin;

use CF7_AntiSpam\Core\CF7_Antispam_Geoip;
use WP_Query;

/**
* The admin-specific functionality of the plugin.
*
Expand All @@ -13,7 +19,7 @@
/**
* It creates a class called CF7_AntiSpam_Admin.
*/
class CF7_AntiSpam_Admin {
class CF7_AntiSpam_Admin_Core {

/**
* The ID of this plugin.
Expand Down Expand Up @@ -182,8 +188,8 @@ public function enqueue_scripts() {
* class.
*/

$asset = include CF7ANTISPAM_PLUGIN_DIR . '/admin/dist/admin-scripts.asset.php';
wp_register_script( $this->plugin_name, CF7ANTISPAM_PLUGIN_URL . '/admin/dist/admin-scripts.js', $asset['dependencies'], $asset['version'], true );
$asset = include CF7ANTISPAM_PLUGIN_DIR . '/build/admin-scripts.asset.php';
wp_register_script( $this->plugin_name, CF7ANTISPAM_PLUGIN_URL . '/build/admin-scripts.js', $asset['dependencies'], $asset['version'], true );
wp_enqueue_script( $this->plugin_name );

wp_localize_script(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php

namespace CF7_AntiSpam\Admin;

use CF7_AntiSpam\Core\CF7_AntiSpam;
use CF7_AntiSpam\Core\CF7_Antispam_Geoip;
/**
* The plugin settings.
*
Expand Down Expand Up @@ -66,15 +71,15 @@ public function cf7a_options_init() {
array( $this, 'cf7a_print_section_main_subtitle' ),
'cf7a-settings'
);

/* Section Bot Fingerprint */
add_settings_section(
'cf7a_auto_blacklist',
__( 'Ban automatically spammers', 'cf7-antispam' ),
array( $this, 'cf7a_print_section_auto_blacklist' ),
'cf7a-settings'
);

/* Settings autostore_bad_ip */
add_settings_field(
'autostore_bad_ip',
Expand Down Expand Up @@ -974,6 +979,7 @@ private function cf7a_input_cron_schedule( $input, $input_name, $cron_task, $sch
* @return array $options sanitized
*/
public function cf7a_sanitize_options( $input ) {
$new_input['cf7a_enabled'] = isset( $input['cf7a_enabled'] ) ? 1 : 0;

/* get the existing options */
$new_input = $this->options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<?php

namespace CF7_AntiSpam\Admin;

use Exception;

use CF7_AntiSpam\Core\CF7_AntiSpam;
use CF7_AntiSpam\Core\CF7_Antispam_Geoip;
use CF7_AntiSpam\Core\CF7_AntiSpam_Filters;
/**
* The plugin notices and ui stuff.
*
Expand Down
10 changes: 8 additions & 2 deletions admin/admin-tools.php → admin/CF7_AntiSpam_Admin_Tools.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<?php

namespace CF7_AntiSpam\Admin;

use CF7_AntiSpam\Core\CF7_AntiSpam;
use CF7_AntiSpam\Core\CF7_AntiSpam_Filters;
use CF7_AntiSpam\Core\CF7_AntiSpam_Flamingo;
use CF7_AntiSpam\Core\CF7_AntiSpam_Uninstaller;

/**
* The plugin admin tools
*
Expand Down Expand Up @@ -114,7 +122,6 @@ public function cf7a_handle_actions() {
if ( 'reset-blacklist' === $action ) {

/* uninstall class contains the database utility functions */
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-uninstall.php';
$r = CF7_AntiSpam_Uninstaller::cf7a_clean_blacklist();

if ( $r ) {
Expand Down Expand Up @@ -146,7 +153,6 @@ public function cf7a_handle_actions() {
if ( 'cf7a-full-reset' === $action ) {

/* uninstall class contains the database utility functions */
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-uninstall.php';
$r = CF7_AntiSpam_Uninstaller::cf7a_full_reset();

if ( $r ) {
Expand Down
42 changes: 14 additions & 28 deletions cf7-antispam.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
*/

/* If this file is called directly, abort. */

use CF7_AntiSpam\Core\CF7_AntiSpam;
use CF7_AntiSpam\Core\CF7_AntiSpam_Activator;
use CF7_AntiSpam\Core\CF7_AntiSpam_Deactivator;
use CF7_AntiSpam\Core\WPCF7_Service;
use CF7_AntiSpam\Core\CF7_AntiSpam_Uninstaller;

if ( ! defined( 'WPINC' ) ) {
die;
}
Expand Down Expand Up @@ -62,13 +69,12 @@
/**
* CF7-AntiSpam functions
*/
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-functions.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/core/functions.php';

/**
* The code that runs during plugin activation.
*/
function activate_cf7_antispam( $network_wide ) {
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-activator.php';
CF7_AntiSpam_Activator::on_activate( $network_wide );
}
register_activation_hook( CF7ANTISPAM_PLUGIN, 'activate_cf7_antispam' );
Expand All @@ -82,7 +88,6 @@ function activate_cf7_antispam( $network_wide ) {
*/
function on_create_blog( $blog_id ) {
if ( is_plugin_active_for_network( 'cf7-antispam/cf7-antispam.php' ) ) {
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-activator.php';
switch_to_blog( $blog_id );
CF7_AntiSpam_Activator::activate();
restore_current_blog();
Expand All @@ -109,7 +114,6 @@ function on_delete_blog( $tables ) {
* The code that runs during plugin deactivation.
*/
function deactivate_cf7_antispam() {
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-deactivator.php';
CF7_AntiSpam_Deactivator::deactivate();
}
register_deactivation_hook( CF7ANTISPAM_PLUGIN, 'deactivate_cf7_antispam' );
Expand All @@ -118,51 +122,33 @@ function deactivate_cf7_antispam() {
* The code that runs during plugin un-installation.
*/
function uninstall_cf7_antispam() {
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-uninstall.php';
CF7_AntiSpam_Uninstaller::uninstall();
}
register_uninstall_hook( CF7ANTISPAM_PLUGIN, 'uninstall_cf7_antispam' );


/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-core.php';

/**
* Initialize the plugin once all other plugins have finished loading.
*/


/**
* call the integration action to mount our plugin as a component
* Call the integration action to mount our plugin as a component
* into the intefration page
*/

function cf7_antispam_register_service() {
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/service.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/core/WPCF7_Service.php';
$integration = WPCF7_Integration::get_instance();
$integration->add_service(
'cf7-antispam',
WPCF7_Antispam::get_instance()
\CF7_AntiSpam\Core\WPCF7_Antispam::get_instance()
);

}
add_action( 'wpcf7_init', 'cf7_antispam_register_service', 1, 0 );




function run_cf7a() {
$enabled = get_option( 'cf7a_options' );
if ( $enabled && $enabled['cf7a_enable'] === true ) {
if ( $enabled && ! empty( $enabled['cf7a_enable'] ) ) {
$cf7a = new CF7_AntiSpam();
$cf7a->run();
}

}
add_action( 'init', 'run_cf7a', 11, 0 );




19 changes: 15 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"wp-coding-standards/wpcs": "^2.3",
"automattic/vipwpcs": "^2.3",
"phpcompatibility/phpcompatibility-wp": "*",
"phpunit/phpunit": "^8|^9",
"phpunit/phpunit": "^9.6.13",
"wp-phpunit/wp-phpunit": "^5.9.5",
"yoast/phpunit-polyfills": "^1.0",
"yoast/phpunit-polyfills": "^1.1",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7"
},
"require": {
Expand All @@ -30,7 +30,7 @@
},
"scripts": {
"PHPCS": "vendor/bin/phpcbf --standard=phpcs.ruleset.xml -s --report=full,summary,source",
"test": "vendor/bin/phpunit -c phpunit.xml.dist --verbose",
"test": "vendor/bin/phpunit -c phpunit.xml.dist",
"test-multisite": "WP_MULTISITE=1 vendor/bin/phpunit -c tests/multisite.xml --verbose"
},
"minimum-stability": "dev",
Expand All @@ -55,5 +55,16 @@
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
}
},
"autoload": {
"psr-4": {
"CF7_AntiSpam\\Core\\": "core/",
"CF7_AntiSpam\\Admin\\": "admin/"
}
},
"autoload-dev": {
"psr-4": {
"CF7_AntiSpam\\Tests\\": "tests/"
}
}
}
81 changes: 45 additions & 36 deletions includes/cf7a-core.php → core/CF7_AntiSpam.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* The core plugin class.
*
Expand All @@ -14,6 +15,15 @@
* @author Codekraft Studio <info@codekraft.it>
*/

namespace CF7_AntiSpam\Core;

use CF7_AntiSpam\Admin\CF7_AntiSpam_Admin_Core;
use CF7_AntiSpam\Admin\CF7_AntiSpam_Admin_Tools;

use CF7_AntiSpam\Core\CF7_AntiSpam_i18n;
use CF7_AntiSpam\Core\CF7_AntiSpam_Loader;
use CF7_AntiSpam\Core\CF7_AntiSpam_Flamingo;
use CF7_AntiSpam\Core\CF7_AntiSpam_Frontend;
/**
* It sets the version, plugin name, and options. It loads
* the dependencies, sets the locale, updates the plugin, and loads the admin and frontend areas
Expand Down Expand Up @@ -117,7 +127,6 @@ public function __construct() {
*/
protected function update() {

require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-activator.php';
do_action( 'cf7a_update' );
CF7_AntiSpam_Activator::update_options();

Expand All @@ -128,40 +137,40 @@ protected function update() {
*/
private function load_dependencies() {

/**
* The class responsible for orchestrating the actions and filters of the
* core plugin.
*/
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-loader.php';

/**
* The class responsible for defining internationalization functionality
* of the plugin.
*/
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-i18n.php';

/**
* The class responsible for defining frontend functionality
* of the plugin.
*/
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-frontend.php';

/**
* The classes responsible for defining antispam functionality and the related filters
* of the plugin.
*/
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-filters.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-geoip.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-flamingo.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-b8.php';

/**
* The classes responsible for defining admin backend functionality
*/
require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin-customizations.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin-display.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin-tools.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin.php';
// **
// * The class responsible for orchestrating the actions and filters of the
// * core plugin.
// */
// require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-loader.php';
//
// **
// * The class responsible for defining internationalization functionality
// * of the plugin.
// */
// require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-i18n.php';
//
// **
// * The class responsible for defining frontend functionality
// * of the plugin.
// */
// require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-frontend.php';
//
// **
// * The classes responsible for defining antispam functionality and the related filters
// * of the plugin.
// */
// require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-filters.php';
// require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-geoip.php';
// require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-flamingo.php';
// require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-b8.php';
//
// **
// * The classes responsible for defining admin backend functionality
// */
// require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin-customizations.php';
// require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin-display.php';
// require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin-tools.php';
// require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin.php';

$this->loader = new CF7_AntiSpam_Loader();
}
Expand Down Expand Up @@ -236,7 +245,7 @@ private function load_admin() {
add_action( 'admin_init', array( $tools, 'cf7a_handle_actions' ), 1 );

/* the admin area */
$plugin_admin = new CF7_AntiSpam_Admin( $this->get_plugin_name(), $this->get_version() );
$plugin_admin = new CF7_AntiSpam_Admin_Core( $this->get_plugin_name(), $this->get_version() );

/* add the admin menu */
$this->loader->add_action( 'admin_menu', $plugin_admin, 'cf7a_admin_menu' );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace CF7_AntiSpam\Core;

/**
* Fired during plugin activation.
*
Expand All @@ -9,7 +12,7 @@
* @subpackage CF7_AntiSpam/includes
* @author Codekraft Studio <info@codekraft.it>
*/

use CF7_AntiSpam\Admin\CF7_AntiSpam_Admin_Tools;
/**
* It's a class that activates the plugin.
*/
Expand Down Expand Up @@ -232,8 +235,6 @@ public static function update_options( $reset_options = false ) {

cf7a_log( $new_options, 1 );

require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin-tools.php';

CF7_AntiSpam_Admin_Tools::cf7a_push_notice( esc_html__( 'CF7 AntiSpam updated successful! Please flush cache to refresh hidden form data', 'cf7-antispam' ), 'success cf7-antispam' );

}
Expand Down
Loading

0 comments on commit 8e26419

Please sign in to comment.