diff --git a/admin/Admin.php b/admin/Admin.php index ecdb8f8..be77bfb 100644 --- a/admin/Admin.php +++ b/admin/Admin.php @@ -141,15 +141,13 @@ public function site_health(): void { * @since 4.0.0 */ public function enqueue_styles(): void { - wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/mihdan-noexternallinks-admin.min.css', [], - $this->version, + filemtime( plugin_dir_path( __FILE__ ) . 'css/mihdan-noexternallinks-admin.min.css' ), 'all' ); - } /** @@ -158,19 +156,17 @@ public function enqueue_styles(): void { * @since 4.0.0 */ public function enqueue_scripts(): void { - wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/mihdan-noexternallinks-admin.min.js', [ 'jquery' ], - $this->version, + filemtime( plugin_dir_path( __FILE__ ) . 'js/mihdan-noexternallinks-admin.min.js', ), false ); wp_enqueue_script( 'plugin_install' ); wp_enqueue_script( 'updates' ); add_thickbox(); - } /** @@ -215,7 +211,7 @@ public function add_admin_pages(): void { add_menu_page( __( 'No External Links', $this->plugin_name ), - __( 'External Links', $this->plugin_name ), + __( 'No External Links', $this->plugin_name ), 'manage_options', $this->plugin_name, [ $this, 'display_settings_page' ], @@ -520,22 +516,82 @@ public function register_setting(): void { ); add_settings_field( - $this->options_prefix . 'seo_hide_list', + $this->options_prefix . 'seo_hide_mode_specific', + __( 'Mode', $this->plugin_name ), + [ $this, 'radio_cb' ], + $this->plugin_name . '-settings-seo-hide', + $this->options_prefix . 'settings_seo_hide_section', + [ + 'name' => $this->options_prefix . 'seo_hide_mode', + 'id' => $this->options_prefix . 'seo_hide_mode_specific', + 'value' => 'specific', + 'checked' => 'specific' === $this->options->seo_hide_mode, + 'title' => __( 'Specific links', $this->plugin_name ), + ] + ); + + add_settings_field( + $this->options_prefix . 'seo_hide_include_list', __( 'Include', $this->plugin_name ), [ $this, 'textarea_cb' ], $this->plugin_name . '-settings-seo-hide', $this->options_prefix . 'settings_seo_hide_section', [ - 'name' => $this->options_prefix . 'seo_hide_list', - 'id' => $this->options_prefix . 'seo_hide_list', - 'value' => $this->options->seo_hide_list, - 'title' => __( 'Enter domains you wish to be masked. One domain per line. All other domain will be ignored.', $this->plugin_name ), + 'name' => $this->options_prefix . 'seo_hide_include_list', + 'id' => $this->options_prefix . 'seo_hide_include_list', + 'value' => $this->options->seo_hide_include_list, + 'description' => __( 'Enter domains you wish TO BE masked. One domain per line. All other domain will be ignored.', $this->plugin_name ), + 'class' => ( 'all' === $this->options->seo_hide_mode ) + ? $this->options_prefix . 'seo_hide_mode ' . $this->options_prefix . 'hidden' + : $this->options_prefix . 'seo_hide_mode', ] ); register_setting( $this->plugin_name . '-settings-seo-hide', - $this->options_prefix . 'seo_hide_list' + $this->options_prefix . 'seo_hide_include_list' + ); + + add_settings_field( + $this->options_prefix . 'seo_hide_mode_all', + __( 'Mode', $this->plugin_name ), + [ $this, 'radio_cb' ], + $this->plugin_name . '-settings-seo-hide', + $this->options_prefix . 'settings_seo_hide_section', + [ + 'name' => $this->options_prefix . 'seo_hide_mode', + 'id' => $this->options_prefix . 'seo_hide_mode_all', + 'value' => 'all', + 'checked' => 'all' === $this->options->seo_hide_mode, + 'title' => __( 'All links', $this->plugin_name ), + ] + ); + + register_setting( + $this->plugin_name . '-settings-seo-hide', + $this->options_prefix . 'seo_hide_mode' + ); + + add_settings_field( + $this->options_prefix . 'seo_hide_exclude_list', + __( 'Exclude', $this->plugin_name ), + [ $this, 'textarea_cb' ], + $this->plugin_name . '-settings-seo-hide', + $this->options_prefix . 'settings_seo_hide_section', + [ + 'name' => $this->options_prefix . 'seo_hide_exclude_list', + 'id' => $this->options_prefix . 'seo_hide_exclude_list', + 'value' => $this->options->seo_hide_exclude_list, + 'description' => __( 'Enter domains you wish NOT TO BE masked. One domain per line. All other domain will be ignored.', $this->plugin_name ), + 'class' => ( 'specific' === $this->options->seo_hide_mode ) + ? $this->options_prefix . 'seo_hide_mode ' . $this->options_prefix . 'hidden' + : $this->options_prefix . 'seo_hide_mode', + ] + ); + + register_setting( + $this->plugin_name . '-settings-seo-hide', + $this->options_prefix . 'seo_hide_exclude_list' ); add_settings_field( @@ -1232,6 +1288,32 @@ public function checkbox_cb( $data ): void { + + +
+ +
+ +- +
diff --git a/admin/css/mihdan-noexternallinks-admin.css b/admin/css/mihdan-noexternallinks-admin.css index 56115f6..0892d41 100644 --- a/admin/css/mihdan-noexternallinks-admin.css +++ b/admin/css/mihdan-noexternallinks-admin.css @@ -42,3 +42,6 @@ div.list-tree li::after { div.list-tree ul > li:last-child::after { height: 14px; } +.mihdan_noexternallinks_hidden { + display: none !important; +} diff --git a/admin/css/mihdan-noexternallinks-admin.min.css b/admin/css/mihdan-noexternallinks-admin.min.css index 26d93b2..39dd102 100644 --- a/admin/css/mihdan-noexternallinks-admin.min.css +++ b/admin/css/mihdan-noexternallinks-admin.min.css @@ -1 +1 @@ -input[name^=mihdan_noexternallinks_]:read-only,textarea[name^=mihdan_noexternallinks_]:read-only{background:rgba(255,255,255,.5);border-color:rgba(222,222,222,.75);-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,.04);box-shadow:inset 0 1px 2px rgba(0,0,0,.04);color:rgba(51,51,51,.5)}div.list-tree,div.list-tree li,div.list-tree ul{position:relative}div.list-tree>ul{margin:0;padding-left:20px}div.list-tree li::after,div.list-tree li::before{content:"";left:-12px;position:absolute}div.list-tree li::before{border-top:1px solid #b4b9be;height:0;top:12px;width:8px}div.list-tree li::after{border-left:1px solid #b4b9be;height:120%;top:-2px;width:0}div.list-tree ul>li:last-child::after{height:14px} \ No newline at end of file +input[name^=mihdan_noexternallinks_]:read-only,textarea[name^=mihdan_noexternallinks_]:read-only{background:rgba(255,255,255,.5);border-color:rgba(222,222,222,.75);-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,.04);box-shadow:inset 0 1px 2px rgba(0,0,0,.04);color:rgba(51,51,51,.5)}div.list-tree,div.list-tree li,div.list-tree ul{position:relative}div.list-tree>ul{margin:0;padding-left:20px}div.list-tree li::after,div.list-tree li::before{content:"";left:-12px;position:absolute}div.list-tree li::before{border-top:1px solid #b4b9be;height:0;top:12px;width:8px}div.list-tree li::after{border-left:1px solid #b4b9be;height:120%;top:-2px;width:0}div.list-tree ul>li:last-child::after{height:14px}.mihdan_noexternallinks_hidden{display:none!important} \ No newline at end of file diff --git a/admin/js/mihdan-noexternallinks-admin.js b/admin/js/mihdan-noexternallinks-admin.js index c41c7e9..7f92bb9 100644 --- a/admin/js/mihdan-noexternallinks-admin.js +++ b/admin/js/mihdan-noexternallinks-admin.js @@ -19,7 +19,15 @@ enable_anonymize_links = $('input#mihdan_noexternallinks_anonymize_links'), anonymous_link_provider = $('input#mihdan_noexternallinks_anonymous_link_provider'), bot_targeting = $('input#mihdan_noexternallinks_bot_targeting'), - bots_selector = $('select#mihdan_noexternallinks_bots_selector'); + bots_selector = $('select#mihdan_noexternallinks_bots_selector'), + seo_hide_mode = $('input[name="mihdan_noexternallinks_seo_hide_mode"]'); + + seo_hide_mode.on( + 'change', + function () { + $( '.mihdan_noexternallinks_seo_hide_mode' ).toggleClass( 'mihdan_noexternallinks_hidden' ); + } + ); masking_type.on("change", function() { var masking_type_value = $(this).val(); @@ -94,4 +102,4 @@ }); -})( jQuery ); \ No newline at end of file +})( jQuery ); diff --git a/admin/js/mihdan-noexternallinks-admin.min.js b/admin/js/mihdan-noexternallinks-admin.min.js index e838b59..cff640f 100644 --- a/admin/js/mihdan-noexternallinks-admin.min.js +++ b/admin/js/mihdan-noexternallinks-admin.min.js @@ -1 +1 @@ -!function(n){"use strict";n(function(){var e=n('input[name="mihdan_noexternallinks_masking_type"]'),o=n("input#mihdan_noexternallinks_redirect_time"),t=n('input[name="mihdan_noexternallinks_mask_links"]'),i=n("div.list-tree input"),p=n('input[name="mihdan_noexternallinks_link_structure"]'),r=n("input#mihdan_noexternallinks_link_structure_default"),c=n("input#mihdan_noexternallinks_link_structure_custom"),a=n('input[name="mihdan_noexternallinks_separator"]'),l=n(".link-separator"),s=n('input[name="mihdan_noexternallinks_link_encoding"]'),_=n('input[name="mihdan_noexternallinks_link_shortening"]'),u=n("input#mihdan_noexternallinks_logging"),k=n("input#mihdan_noexternallinks_log_duration"),d=n("input#mihdan_noexternallinks_anonymize_links"),h=n("input#mihdan_noexternallinks_anonymous_link_provider"),f=n("input#mihdan_noexternallinks_bot_targeting"),g=n("select#mihdan_noexternallinks_bots_selector");e.on("change",function(){"javascript"===n(this).val()?o.prop("readonly",!1):o.prop("readonly",!0)}),t.on("change",function(){"specific"===n(this).val()?i.prop("disabled",!1):i.prop("disabled",!0),i.prop("checked",!0)}),a.on("focus",function(){r.prop("checked",0),c.prop("checked",1),_.prop("checked",0),_.first().prop("checked",1)}),a.on("keyup",function(){var n=a.val();l.text(n)}),p.on("change",function(){"custom"===n(this).val()&&(_.prop("checked",0),_.first().prop("checked",1))}),r.on("change",function(){a.val(""),l.text("goto")}),s.on("change",function(){"none"!==n(this).val()&&(_.prop("checked",0),_.first().prop("checked",1))}),_.on("change",function(){n(this).val();r.prop("checked",1),c.prop("checked",0),s.prop("checked",0),s.first().prop("checked",1),a.val(""),l.text("goto")}),u.on("change",function(){u.is(":checked")?k.prop("readonly",!1):k.prop("readonly",!0)}),d.on("change",function(){d.is(":checked")?h.prop("readonly",!1):h.prop("readonly",!0)}),f.on("change",function(){"specific"===n(this).val()?g.prop("disabled",!1):g.prop("disabled",!0)})})}(jQuery); \ No newline at end of file +(function($){"use strict";$(function(){var masking_type=$('input[name="mihdan_noexternallinks_masking_type"]'),redirect_time=$("input#mihdan_noexternallinks_redirect_time"),mask_links=$('input[name="mihdan_noexternallinks_mask_links"]'),mask_links_inputs=$("div.list-tree input"),link_structure=$('input[name="mihdan_noexternallinks_link_structure"]'),link_structure_default=$("input#mihdan_noexternallinks_link_structure_default"),link_structure_custom=$("input#mihdan_noexternallinks_link_structure_custom"),link_separator=$('input[name="mihdan_noexternallinks_separator"]'),link_separator_display=$(".link-separator"),link_encoding=$('input[name="mihdan_noexternallinks_link_encoding"]'),link_shortening=$('input[name="mihdan_noexternallinks_link_shortening"]'),enable_logging=$("input#mihdan_noexternallinks_logging"),log_duration=$("input#mihdan_noexternallinks_log_duration"),enable_anonymize_links=$("input#mihdan_noexternallinks_anonymize_links"),anonymous_link_provider=$("input#mihdan_noexternallinks_anonymous_link_provider"),bot_targeting=$("input#mihdan_noexternallinks_bot_targeting"),bots_selector=$("select#mihdan_noexternallinks_bots_selector"),seo_hide_mode=$('input[name="mihdan_noexternallinks_seo_hide_mode"]');seo_hide_mode.on("change",function(){$(".mihdan_noexternallinks_seo_hide_mode").toggleClass("mihdan_noexternallinks_hidden")});masking_type.on("change",function(){var masking_type_value=$(this).val();"javascript"===masking_type_value?redirect_time.prop("readonly",!1):redirect_time.prop("readonly",!0)});mask_links.on("change",function(){var mask_links_value=$(this).val();"specific"===mask_links_value?mask_links_inputs.prop("disabled",!1):mask_links_inputs.prop("disabled",!0);mask_links_inputs.prop("checked",!0)});link_separator.on("focus",function(){link_structure_default.prop("checked",0);link_structure_custom.prop("checked",1);link_shortening.prop("checked",0);link_shortening.first().prop("checked",1)});link_separator.on("keyup",function(){var separator_val=link_separator.val();link_separator_display.text(separator_val)});link_structure.on("change",function(){var link_structure_value=$(this).val();if("custom"===link_structure_value){link_shortening.prop("checked",0);link_shortening.first().prop("checked",1)}});link_structure_default.on("change",function(){link_separator.val("");link_separator_display.text("goto")});link_encoding.on("change",function(){var link_encoding_value=$(this).val();if("none"!==link_encoding_value){link_shortening.prop("checked",0);link_shortening.first().prop("checked",1)}});link_shortening.on("change",function(){link_structure_default.prop("checked",1);link_structure_custom.prop("checked",0);link_encoding.prop("checked",0);link_encoding.first().prop("checked",1);link_separator.val("");link_separator_display.text("goto")});enable_logging.on("change",function(){enable_logging.is(":checked")?log_duration.prop("readonly",!1):log_duration.prop("readonly",!0)});enable_anonymize_links.on("change",function(){enable_anonymize_links.is(":checked")?anonymous_link_provider.prop("readonly",!1):anonymous_link_provider.prop("readonly",!0)});bot_targeting.on("change",function(){var bot_targeting_value=$(this).val();"specific"===bot_targeting_value?bots_selector.prop("disabled",!1):bots_selector.prop("disabled",!0)})})})(jQuery); \ No newline at end of file diff --git a/includes/Main.php b/includes/Main.php index f808360..65c158a 100644 --- a/includes/Main.php +++ b/includes/Main.php @@ -308,7 +308,9 @@ private function set_options(): void { 'noindex_tag' => false, 'noindex_comment' => false, 'seo_hide' => false, - 'seo_hide_list' => '', + 'seo_hide_mode' => 'specific', + 'seo_hide_include_list' => '', + 'seo_hide_exclude_list' => '', 'link_structure' => 'default', 'separator' => 'goto', 'link_encoding' => 'none', @@ -375,7 +377,9 @@ private function validate_options( $options ) { case 'link_shortening': case 'anonymous_link_provider': case 'inclusion_list': - case 'seo_hide_list': + case 'seo_hide_mode': + case 'seo_hide_include_list': + case 'seo_hide_exclude_list': case 'exclusion_list': case 'bot_targeting': case 'redirect_message': diff --git a/mihdan-no-external-links.php b/mihdan-no-external-links.php index 0c5436e..86c0a07 100644 --- a/mihdan-no-external-links.php +++ b/mihdan-no-external-links.php @@ -1,16 +1,16 @@ options->nofollow ? ' rel="nofollow"' : ''; if ( $this->options->seo_hide ) { - $seo_hide_list = $this->textarea_to_array( $this->options->seo_hide_list ); + // Get classes. + $classes = 'waslinkname'; - if ( $seo_hide_list && in_array( $this->get_domain_from_url( $url ), $seo_hide_list, true ) ) { - // Get classes. - $classes = 'waslinkname'; + preg_match( '/class="([^"]+)"/si', $attributes, $maybe_classes ); - preg_match( '/class="([^"]+)"/si', $attributes, $maybe_classes ); + if ( ! empty( $maybe_classes[1] ) ) { + $classes .= ' ' . $maybe_classes[1]; + } + + $current_domain = $this->get_domain_from_url( $url ); + + // Список включений. + $seo_hide_include_list = $this->textarea_to_array( $this->options->seo_hide_include_list ); - if ( ! empty( $maybe_classes[1] ) ) { - $classes .= ' ' . $maybe_classes[1]; + // Список исключений. + $seo_hide_exclude_list = $this->textarea_to_array( $this->options->seo_hide_exclude_list ); + + // Маскировать только указанные ссылки. + if ( 'specific' === $this->options->seo_hide_mode ) { + if ( in_array( $current_domain, $seo_hide_include_list, true ) ) { + return sprintf( + '%s', + esc_attr( $classes ), + esc_attr( base64_encode( $url ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode + str_replace( 'target', 'data-target', $blank ), + $anchor_text + ); } + } - return sprintf( - '%s', - esc_attr( $classes ), - esc_attr( base64_encode( $url ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode - str_replace( 'target', 'data-target', $blank ), - $anchor_text - ); + // Маскировать все ссылки, кроме указанных. + if ( 'all' === $this->options->seo_hide_mode ) { + if ( ! in_array( $current_domain, $seo_hide_exclude_list, true ) ) { + return sprintf( + '%s', + esc_attr( $classes ), + esc_attr( base64_encode( $url ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode + str_replace( 'target', 'data-target', $blank ), + $anchor_text + ); + } } } diff --git a/readme.txt b/readme.txt index 08e4894..66452e2 100644 --- a/readme.txt +++ b/readme.txt @@ -1,30 +1,30 @@ -=== Mihdan: No External Links === +=== No External Links === Author: mihdan Contributors: mihdan, kaggdesign Tags: seo, seo-hide, link, links, publisher, post, posts, comments Requires at least: 5.7.4 -Tested up to: 6.2 -Stable tag: 5.0.7 +Tested up to: 6.4 +Stable tag: 5.1.0 Requires PHP: 7.4 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Convert external links into internal links, site wide or post/page specific. Add NoFollow, Click logging, and more... == Description == -Mihdan: No External Links converts external links to internal links. Featuring *Full Page or Targeted Content Filtering*, *Custom Redirect Page/Message*, *Encoded Masks*, *External Link Click Logging*, *Individual Link Exclusion*, *Post/Page Specific Exclusion*, and many more... +No External Links converts external links to internal links. Featuring *Full Page or Targeted Content Filtering*, *Custom Redirect Page/Message*, *Encoded Masks*, *External Link Click Logging*, *Individual Link Exclusion*, *Post/Page Specific Exclusion*, and many more... = Example = Links like "*https://wordpress.org*" will be masked into "*http://www.example.com/goto/https://wordpress.org*". = Warning = -Mihdan: No External Links may conflict with cache plugins. +No External Links may conflict with cache plugins. Usually adding the redirect page to the caching plugin exclusions works fine, but there are no guarantees. Create a [support topic](https://wordpress.org/support/plugin/mihdan-no-external-links) if you need assistance resolving a caching issue. **_Please provide as much detail as possible, for example, what version of WordPress & PHP you are using. Which caching plugin you are using. The more information you include the better._** = Details = -Mihdan: No External Links is designed for specialists who sell different kinds of advertisements on their web site and care about the number of outgoing links that can be found by search engines. Now you can make all external links internal. +No External Links is designed for specialists who sell different kinds of advertisements on their web site and care about the number of outgoing links that can be found by search engines. Now you can make all external links internal. = How To Use = Just do everything like you would normally, and as long as the plugin is active, external links will be automatically masked. @@ -45,24 +45,29 @@ We apologize that the latest version has changed so much that existing localizat If you would like to contribute to the translations please get in touch. = Note = -Mihdan: No External Links **does not** make any changes to your database, it just processes the output. So you will not see these changes within the WYSIWYG editor. +No External Links **does not** make any changes to your database, it just processes the output. So you will not see these changes within the WYSIWYG editor. == Installation == = From your WordPress dashboard = 1. Visit 'Plugins > Add New' -2. Search for 'Mihdan: No External Links' -3. Activate Mihdan: No External Links from your Plugins page. -4. [Optional] Configure Mihdan: No External Links settings. +2. Search for 'No External Links' +3. Activate No External Links from your Plugins page. +4. [Optional] Configure No External Links settings. = From WordPress.org = -1. Download Mihdan: No External Links. +1. Download No External Links. 2. Upload the 'mihdan-noexternallinks' directory to your '/wp-content/plugins/' directory, using your favorite method (ftp, sftp, scp, etc...) -3. Activate Mihdan: No External Links from your Plugins page. -4. [Optional] Configure Mihdan: No External Links settings. +3. Activate No External Links from your Plugins page. +4. [Optional] Configure No External Links settings. == Changelog == += 5.1.0 (25.11.2023) = +* Tested with WordPress 6.4+. +* Added PHP 8.3 support +* Added excluded list for SEO hide + = 5.0.7 (03.05.2023) = * Fixed ampersand conversion in links * Fixed PHP notices