diff --git a/plugin.php b/plugin.php index 7dfbb25..4c1c7b2 100644 --- a/plugin.php +++ b/plugin.php @@ -2,8 +2,8 @@ /* Plugin Name: ICC Webmaster Settings Plugin URI: https://git.icc.gg/ivancarlos/yourlsiccwebmastersettings -Description: Customize Logo, Title, Footer, CSS & Favicons. Add reCAPTCHA v3, HTTP Redirect, 301/302 Redirects -Version: 2.0 +Description: Customize Logo, Title, Footer, CSS & Favicons. Add reCAPTCHA v3, HTTP Redirect, 301/302 Redirects, Dash/Underscore, Force Lowercase & Share features. +Version: 2.3 Author: Ivan Carlos Author URI: https://ivancarlos.com.br/ */ @@ -78,10 +78,24 @@ function icc_config_do_page() } $escaped_delay = (int) $icc_mrdr_delay; + // 302 Redirect options + $icc_302_redirect_enabled = yourls_get_option('icc_302_redirect_enabled'); // 302 Redirect options $icc_302_redirect_enabled = yourls_get_option('icc_302_redirect_enabled'); $redirect_302_checked = $icc_302_redirect_enabled ? 'checked' : ''; + // Remove Share options + $icc_remove_share_enabled = yourls_get_option('icc_remove_share_enabled'); + $remove_share_checked = $icc_remove_share_enabled ? 'checked' : ''; + + // Allow Dash/Underscore options + $icc_allow_dash_underscore_enabled = yourls_get_option('icc_allow_dash_underscore_enabled'); + $allow_dash_underscore_checked = $icc_allow_dash_underscore_enabled ? 'checked' : ''; + + // Force Lowercase options + $icc_force_lowercase_enabled = yourls_get_option('icc_force_lowercase_enabled'); + $force_lowercase_checked = $icc_force_lowercase_enabled ? 'checked' : ''; + echo <<Webmaster Settings
@@ -143,6 +157,23 @@ function icc_config_do_page()
Use 302 (Temporary) instead of 301 (Permanent) for standard redirects.

+

Interface Settings

+

+ + +
Remove the Share button and box from the Admin Dashboard. +

+

+ + +
Allow dashes (-) and underscores (_) in custom short URLs. +

+

+ + +
Force uppercase keywords to be converted to lowercase (e.g., ABC -> abc). +

+


@@ -205,6 +236,20 @@ function icc_config_update_option() // 302 Redirect update $redirect_302_enabled = isset($_POST['icc_302_redirect_enabled']); yourls_update_option('icc_302_redirect_enabled', $redirect_302_enabled); + $redirect_302_enabled = isset($_POST['icc_302_redirect_enabled']); + yourls_update_option('icc_302_redirect_enabled', $redirect_302_enabled); + + // Remove Share update + $remove_share_enabled = isset($_POST['icc_remove_share_enabled']); + yourls_update_option('icc_remove_share_enabled', $remove_share_enabled); + + // Allow Dash/Underscore update + $allow_dash_underscore_enabled = isset($_POST['icc_allow_dash_underscore_enabled']); + yourls_update_option('icc_allow_dash_underscore_enabled', $allow_dash_underscore_enabled); + + // Force Lowercase update + $force_lowercase_enabled = isset($_POST['icc_force_lowercase_enabled']); + yourls_update_option('icc_force_lowercase_enabled', $force_lowercase_enabled); } // Show custom logo @@ -276,10 +321,12 @@ function icc_print_custom_css() // reCAPTCHA v3 Integration yourls_add_action('html_head', 'icc_recaptcha_v3_html_head'); + function icc_recaptcha_v3_html_head() { if (!yourls_get_option('icc_recaptcha_enabled')) return; + $site_key = yourls_get_option('icc_recaptcha_site_key'); if ($site_key) { echo ''; @@ -403,3 +450,68 @@ function icc_force_302_redirect($args) die(); } } + +// Allow dash and underscore in custom short URLs +if (yourls_get_option('icc_allow_dash_underscore_enabled')) { + yourls_add_filter('get_shorturl_charset', 'icc_custom_shorturl_charset'); + yourls_add_filter('get_shorturl_charset_regex', 'icc_custom_shorturl_charset_regex'); +} + +function icc_custom_shorturl_charset($charset) +{ + return $charset . '-_'; +} + +function icc_custom_shorturl_charset_regex($pattern) +{ + return $pattern . '|[-_]'; +} + +// Force Lowercase Logic +if (yourls_get_option('icc_force_lowercase_enabled')) { + // Redirection: http://sho.rt/ABC first converted to http://sho.rt/abc + yourls_add_filter('get_request', 'icc_break_the_web_lowercase'); + + // Short URL creation: custom keyword 'ABC' converted to 'abc' + yourls_add_action('add_new_link_custom_keyword', 'icc_break_the_web_add_filter'); + + // Force random keywords to be lowercase + yourls_add_filter('random_keyword', 'icc_break_the_web_lowercase'); +} + +function icc_break_the_web_lowercase($keyword) +{ + return strtolower($keyword); +} + +function icc_break_the_web_add_filter() +{ + yourls_add_filter('get_shorturl_charset', 'icc_break_the_web_add_uppercase'); + yourls_add_filter('custom_keyword', 'icc_break_the_web_lowercase'); +} + +function icc_break_the_web_add_uppercase($charset) +{ + return $charset . strtoupper($charset); +} + +// Remove Share Functionality +if (yourls_get_option('icc_remove_share_enabled')) { + // Dump the Share button + yourls_add_filter('table_add_row_action_array', 'icc_rmv_row_action_share'); + // No Share Box either + yourls_add_filter('shunt_share_box', 'icc_shunt_share_box'); +} + +function icc_rmv_row_action_share($links) +{ + if (array_key_exists('share', $links)) + unset($links['share']); + + return $links; +} + +function icc_shunt_share_box($shunt) +{ + return true; +}