diff --git a/plugin.php b/plugin.php index 8d6366d..a67e73d 100644 --- a/plugin.php +++ b/plugin.php @@ -1,136 +1,158 @@ - 'fail', - 'code' => 'error:url', - 'message' => 'This domain is blacklisted', - 'errorCode' => '403', - ); -} - -// Add admin page to handle blacklist management -function better_blacklist_add_admin_page() { - yourls_register_plugin_page( 'better_blacklist_domain', 'Blacklist Domains', 'better_blacklist_admin_page' ); -} - -// Display the blacklist admin page -function better_blacklist_admin_page() { - if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'blacklist_domain' ) { - better_blacklist_process_form(); - } else { - better_blacklist_display_form(); - } -} - -// Display the form to update the blacklist -function better_blacklist_display_form() { - $nonce = yourls_create_nonce( 'blacklist_domain' ); - $blacklist_domains = yourls_get_option( 'better_blacklist_domain_list', 'Enter domain addresses here, one per line' ); - - if ( $blacklist_domains !== 'Enter domain addresses here, one per line' ) { - $blacklist_domains = implode( "\r\n", unserialize( $blacklist_domains ) ); + // Return failure response for blacklisted URLs + function blacklist_fail_response() { + return array( + 'status' => 'fail', + 'code' => 'error:url', + 'message' => 'This domain is blacklisted', + 'errorCode' => '403', + ); } - echo <<Blacklist Domains -
- - -

Enter domains to blacklist (one per line):

- -

-
-HTML; -} + // Add admin page to handle blacklist management + function better_blacklist_add_admin_page() { + yourls_register_plugin_page( 'better_blacklist_domain', 'Blacklist Domains', 'better_blacklist_admin_page' ); + } -// Process the blacklist form submission -function better_blacklist_process_form() { - // Verify nonce for security - yourls_verify_nonce( 'blacklist_domain' ); - - // Sanitize and process the form input - $blacklist_form = array_filter( array_map( 'trim', explode( "\r\n", $_POST['blacklist_form'] ) ) ); - - // Alphabetize the blacklist - sort($blacklist_form, SORT_STRING | SORT_FLAG_CASE); - - // Update the option with serialized data - yourls_update_option( 'better_blacklist_domain_list', serialize( $blacklist_form ) ); - - echo "

Blacklist updated!

"; - if ( empty( $blacklist_form ) ) { - echo "

The blacklist is currently empty.

"; - } else { - echo "

Current blacklisted domains:

"; } -}