External Links - Version 6.3

Version Description

  • Changed link detection to err on the side of a link being local rather than external to avoid false positives.
  • Fixed double inclusion of class attribute under certain link attribute ordering conditions
Download this release

Release Info

Developer Mike_Koepke
Plugin Icon wp plugin External Links
Version 6.3
Comparing to
See all releases

Code changes from version 6.2 to 6.3

Files changed (2) hide show
  1. readme.txt +5 -0
  2. sem-external-links.php +27 -22
readme.txt CHANGED
@@ -60,6 +60,11 @@ The plugin supports a non-started rel="follow" attribute on links to override th
60
 
61
  == Change Log ==
62
 
 
 
 
 
 
63
  = 6.2 =
64
 
65
  - Additional performance changes for long post/page when Apply Globally is off.
60
 
61
  == Change Log ==
62
 
63
+ = 6.3 =
64
+
65
+ - Changed link detection to err on the side of a link being local rather than external to avoid false positives.
66
+ - Fixed double inclusion of class attribute under certain link attribute ordering conditions
67
+
68
  = 6.2 =
69
 
70
  - Additional performance changes for long post/page when Apply Globally is off.
sem-external-links.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: External Links
4
  Plugin URI: http://www.semiologic.com/software/external-links/
5
  Description: Marks outbound links as such, with various effects that are configurable under <a href="options-general.php?page=external-links">Settings / External Links</a>.
6
- Version: 6.2
7
  Author: Denis de Bernardy & Mike Koepke
8
  Author URI: https://www.semiologic.com
9
  Text Domain: external-links
@@ -19,7 +19,7 @@ This software is copyright Denis de Bernardy & Mike Koepke, and is distributed u
19
 
20
  **/
21
 
22
- define('sem_external_links_version', '6.2');
23
 
24
  /**
25
  * external_links
@@ -368,7 +368,6 @@ class sem_external_links {
368
 
369
  function parse_anchor($match) {
370
  $anchor = array();
371
- // $anchor['attr'] = $this->parse_attrs( $match[1] );
372
  $anchor['attr'] = $this->parseAttributes( $match[1] );
373
 
374
  if ( !is_array($anchor['attr']) || empty($anchor['attr']['href']) # parser error or no link
@@ -438,11 +437,11 @@ class sem_external_links {
438
  $attr_value = false;
439
  $quote = false; // quotes to wrap attribute values
440
 
441
- if (preg_match('/<\s*a\s+' . $attr_name . '="([^"]*)\s*>"/iu', $html, $matches)
442
- || preg_match('/<\s*a\s+' . $attr_name . "='([^']*)\s*>'/iu", $html, $matches)
443
  ) {
444
  // two possible ways to get existing attributes
445
- $attr_value = $matches[1];
446
 
447
  $quote = false !== stripos($html, $attr_name . "='") ? "'" : '"';
448
  }
@@ -502,7 +501,7 @@ class sem_external_links {
502
  return null;
503
  }
504
  # ignore local urls
505
- elseif ( sem_external_links::is_local_url($anchor['attr']['href']) )
506
  return null;
507
 
508
  # no icons for images
@@ -565,20 +564,24 @@ class sem_external_links {
565
  }
566
 
567
  /**
568
- * is_local_url()
569
  *
570
  * @param string $url
571
- * @return bool $is_local_url
572
  **/
573
 
574
- function is_local_url($url) {
575
- if ( (substr($url, 0, 2) != '//') && (strpos($url, 'http://') === false) && (strpos($url, 'https://') === false) )
576
- return true;
577
- elseif ( $url == 'http://' || $url == 'https://' )
578
- return true;
579
- elseif ( preg_match("~/go(/|\.)~i", $url) )
580
  return false;
581
 
 
 
 
 
 
 
 
582
  static $site_domain;
583
 
584
  if ( !isset($site_domain) ) {
@@ -593,7 +596,7 @@ class sem_external_links {
593
  else
594
  return false;
595
  }
596
- $site_domain = preg_replace("/^www\./i", '', $site_domain);
597
 
598
  # The following is not bullet proof, but it's good enough for a WP site
599
  if ( $site_domain != 'localhost' && !preg_match("/\d+(\.\d+){3}/", $site_domain) ) {
@@ -646,11 +649,11 @@ class sem_external_links {
646
  }
647
 
648
  if ( $site_domain == $link_domain ) {
649
- return true;
650
- } elseif ( function_exists('is_multisite') && is_multisite() ) {
651
  return false;
652
- } else {
653
  return false;
 
 
654
  $site_elts = explode('.', $site_domain);
655
  $link_elts = explode('.', $link_domain);
656
 
@@ -660,10 +663,12 @@ class sem_external_links {
660
  }
661
 
662
  return empty($link_elts) || empty($site_elts);
663
-
664
  }
665
- } # is_local_url()
666
-
 
 
 
667
  /**
668
  * extract_domain()
669
  *
3
  Plugin Name: External Links
4
  Plugin URI: http://www.semiologic.com/software/external-links/
5
  Description: Marks outbound links as such, with various effects that are configurable under <a href="options-general.php?page=external-links">Settings / External Links</a>.
6
+ Version: 6.3
7
  Author: Denis de Bernardy & Mike Koepke
8
  Author URI: https://www.semiologic.com
9
  Text Domain: external-links
19
 
20
  **/
21
 
22
+ define('sem_external_links_version', '6.3');
23
 
24
  /**
25
  * external_links
368
 
369
  function parse_anchor($match) {
370
  $anchor = array();
 
371
  $anchor['attr'] = $this->parseAttributes( $match[1] );
372
 
373
  if ( !is_array($anchor['attr']) || empty($anchor['attr']['href']) # parser error or no link
437
  $attr_value = false;
438
  $quote = false; // quotes to wrap attribute values
439
 
440
+ $re = '/' . preg_quote($attr_name) . '=([\'"])?((?(1).+?|[^\s>]+))(?(1)\1)/is';
441
+ if (preg_match($re, $html, $matches)
442
  ) {
443
  // two possible ways to get existing attributes
444
+ $attr_value = $matches[2];
445
 
446
  $quote = false !== stripos($html, $attr_name . "='") ? "'" : '"';
447
  }
501
  return null;
502
  }
503
  # ignore local urls
504
+ elseif ( !sem_external_links::is_external($anchor['attr']['href']) )
505
  return null;
506
 
507
  # no icons for images
564
  }
565
 
566
  /**
567
+ * is_external()
568
  *
569
  * @param string $url
570
+ * @return bool $is_external
571
  **/
572
 
573
+ function is_external($url) {
574
+ if ( (substr($url, 0, 2) != '//') && (strpos($url, 'http://') !== false)
575
+ && (strpos($url, 'https://') !== false) )
 
 
 
576
  return false;
577
 
578
+ if ( $url == 'http://' || $url == 'https://' )
579
+ return false;
580
+
581
+ /* if ( preg_match("~/go(/|\.)~i", $url) )
582
+ return false;
583
+ */
584
+
585
  static $site_domain;
586
 
587
  if ( !isset($site_domain) ) {
596
  else
597
  return false;
598
  }
599
+ $site_domain = str_replace('www.', '', $site_domain);
600
 
601
  # The following is not bullet proof, but it's good enough for a WP site
602
  if ( $site_domain != 'localhost' && !preg_match("/\d+(\.\d+){3}/", $site_domain) ) {
649
  }
650
 
651
  if ( $site_domain == $link_domain ) {
 
 
652
  return false;
653
+ } elseif ( function_exists('is_multisite') && is_multisite() ) {
654
  return false;
655
+ }
656
+ /* else {
657
  $site_elts = explode('.', $site_domain);
658
  $link_elts = explode('.', $link_domain);
659
 
663
  }
664
 
665
  return empty($link_elts) || empty($site_elts);
 
666
  }
667
+ */
668
+ // we made it to the end so we must have an external link
669
+ return true;
670
+ } # is_external()
671
+
672
  /**
673
  * extract_domain()
674
  *