Skip to content

Commit

Permalink
Release 5.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mihdan committed Nov 25, 2023
1 parent 9b8d3bd commit d8e7add
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 51 deletions.
110 changes: 96 additions & 14 deletions admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);

}

/**
Expand 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();

}

/**
Expand Down Expand Up @@ -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' ],
Expand Down Expand Up @@ -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 <b>TO BE</b> 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 <b>NOT TO BE</b> 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(
Expand Down Expand Up @@ -1232,6 +1288,32 @@ public function checkbox_cb( $data ): void {
<?php
}

/**
* Print radio.
*
* @param array $data Data.
*
* @return void
*/
public function radio_cb( $data ): void {
?>
<label>
<input
type="radio"
name="<?php echo esc_attr( $data['name'] ); ?>"
id="<?php echo esc_attr( $data['id'] ); ?>"
value="<?php echo esc_attr( $data['value'] ); ?>"
<?php checked( $data['checked'] ); ?> />
<?php echo esc_html( $data['title'] ); ?>
</label>
<?php if ( ! empty( $data['description'] ) ) : ?>
<p class="description">
<?php echo esc_html( $data['description'] ); ?>
</p>
<?php endif; ?>
<?php
}

/**
* Print textarea.
*
Expand All @@ -1256,7 +1338,7 @@ class="large-text"
rows="10"><?php echo esc_textarea( $data['value'] ); ?></textarea>
<?php if ( ! empty( $data['description'] ) ) : ?>
<p class="description">
<?php echo esc_html( $data['description'] ); ?>
<?php echo wp_kses_post( $data['description'] ); ?>
</p>
<?php endif; ?>
</fieldset>
Expand Down
3 changes: 3 additions & 0 deletions admin/css/mihdan-noexternallinks-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion admin/css/mihdan-noexternallinks-admin.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions admin/js/mihdan-noexternallinks-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -94,4 +102,4 @@

});

})( jQuery );
})( jQuery );
2 changes: 1 addition & 1 deletion admin/js/mihdan-noexternallinks-admin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions includes/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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':
Expand Down
8 changes: 4 additions & 4 deletions mihdan-no-external-links.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php
/**
* Mihdan: No External Links bootstrap file.
* No External Links bootstrap file.
*
* @link https://wordpress.org/plugins/mihdan-no-external-links/
* @since 4.0.0
* @package mihdan-no-external-links
*
* @wordpress-plugin
* Plugin Name: Mihdan: No External Links
* Plugin Name: No External Links
* Plugin URI: https://wordpress.org/plugins/mihdan-no-external-links/
* Description: Convert external links into internal links, site wide or post/page specific. Add NoFollow, Click logging, and more...
* Version: 5.0.7
* Version: 5.1.0
* Author: Mikhail Kobzarev
* Author URI: https://www.kobzarev.com/
* License: GPL-2.0+
Expand All @@ -28,7 +28,7 @@
}

const MIHDAN_NO_EXTERNAL_LINKS_DIR = __DIR__;
const MIHDAN_NO_EXTERNAL_LINKS_VERSION = '5.0.7';
const MIHDAN_NO_EXTERNAL_LINKS_VERSION = '5.1.0';
const MIHDAN_NO_EXTERNAL_LINKS_SLUG = 'mihdan-no-external-links';

define( 'MIHDAN_NO_EXTERNAL_LINKS_BASENAME', plugin_basename( __FILE__ ) );
Expand Down
50 changes: 36 additions & 14 deletions public/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,25 +313,47 @@ public function mask_link( $matches ): string {
$nofollow = $this->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(
'<span class="%s" data-link="%s"%s>%s</span>',
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(
'<span class="%s" data-link="%s"%s>%s</span>',
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(
'<span class="%s" data-link="%s"%s>%s</span>',
esc_attr( $classes ),
esc_attr( base64_encode( $url ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
str_replace( 'target', 'data-target', $blank ),
$anchor_text
);
}
}
}

Expand Down
Loading

0 comments on commit d8e7add

Please sign in to comment.