From 764b858de6caaf397e675f8e04255d03f70ee18b Mon Sep 17 00:00:00 2001 From: Maingron Date: Sat, 13 Sep 2025 02:35:18 +0200 Subject: [PATCH] Bump version in plugin.php and remove tabs that someone put there by sleeping on the keyboard, I guess. whoops --- plugin.php | 278 ++++++++++++++++++++++++++--------------------------- 1 file changed, 139 insertions(+), 139 deletions(-) diff --git a/plugin.php b/plugin.php index a67e73d..c70bf41 100644 --- a/plugin.php +++ b/plugin.php @@ -1,158 +1,158 @@ - 'fail', - 'code' => 'error:url', - 'message' => 'This domain is blacklisted', - 'errorCode' => '403', - ); + // No match, allow the URL + return $shunt; +} + +// Return failure response for blacklisted URLs +function blacklist_fail_response() { + return array( + 'status' => '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 ) ); } - // 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' ); - } + echo <<Blacklist Domains +
+ + +

Enter domains to blacklist (one per line):

- // 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 ) ); - } - - echo <<Blacklist Domains - - - -

Enter domains to blacklist (one per line):

- -
- Advanced Usage (Regex) -
-

- You can use regular expressions (Regex) to define more complex patterns for blacklisting domains.
- To use Regex, enter your pattern between slashes (/).
- - For example, to block all subdomains of example.com, you could enter /\.example\.com$/i.
- The i flag at the end makes the match case-insensitive. Usually you want to use this flag. -

- -

- Further examples:
- /.*\.xxx$/i - Blocks all domains ending with .xxx
-
- - Be cautious when using Regex, as incorrect patterns can lead to unintended blocking of domains.
- Always test your Regex patterns to ensure they work as expected. -

-
-

- -

-
- HTML; - } - - // 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:

"; +
+ Advanced Usage (Regex) +
+

+ You can use regular expressions (Regex) to define more complex patterns for blacklisting domains.
+ To use Regex, enter your pattern between slashes (/).
+ + For example, to block all subdomains of example.com, you could enter /\.example\.com$/i.
+ The i flag at the end makes the match case-insensitive. Usually you want to use this flag. +

+ +

+ Further examples:
+ /.*\.xxx$/i - Blocks all domains ending with .xxx
+
+ + Be cautious when using Regex, as incorrect patterns can lead to unintended blocking of domains.
+ Always test your Regex patterns to ensure they work as expected. +

+
+

+ +

+ +HTML; +} + +// 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:

"; } +}