Changeset 2080637
- Timestamp:
- 05/04/2019 09:47:04 PM (7 years ago)
- Location:
- serious-duplicated-terms
- Files:
-
- 5 edited
-
assets/screenshot-1.png (modified) (previous)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/admin/class-serious-duplicated-terms-admin-ext.php (modified) (9 diffs)
-
trunk/admin/partials/class-serious-duplicated-terms-admin-display-ext.php (modified) (3 diffs)
-
trunk/admin/partials/class-serious-duplicated-terms-admin-settings.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
serious-duplicated-terms/trunk/README.txt
r2077519 r2080637 47 47 No. If you do index individual tag and category pages (not always recommended) you will need to create the redirections manually. 48 48 49 = I see too many similar tags/categories in the analysis page = 50 51 Try checking the *Equal names only* in the *Configuration* page to avoid considering as similars tags/categories that are substring of other ones (which could trigger many results if you use very short term names). 49 52 50 53 == Screenshots == … … 55 58 == Changelog == 56 59 60 = 1.1 = 61 * Added option to signal as duplicates only terms with the same exact name 62 57 63 = 1.0 = 58 64 * Initial release 65 66 67 == Upgrade Notice == 68 69 = 1.1 = 70 * Now you can reduce the number of false positives in large sites by enforcing equal names in the detection of duplicates -
serious-duplicated-terms/trunk/admin/class-serious-duplicated-terms-admin-ext.php
r2077519 r2080637 26 26 * 27 27 **/ 28 public function compare_terms( $a, $b, $levenshtein, $max_distance){ 29 $similars=false; 30 if( strcasecmp($a, $b) == 0 ) return true; //case insensitive comparison 28 public function compare_terms( $a, $b, $strict, $levenshtein, $max_distance) { 29 if ( strcasecmp( $a, $b ) == 0 ) { 30 return true; 31 } //case insensitive comparison 31 32 32 $pos1 = stripos($a, $b); 33 $pos2 = stripos($b, $a); 34 if ($pos1 !== false || $pos2 !== false) return true; 33 if ( ! $strict ) { // If we're not restricting the comparison to equal names then we keep trying 34 $pos1 = stripos( $a, $b ); 35 $pos2 = stripos( $b, $a ); 36 if ( $pos1 !== false || $pos2 !== false ) { 37 return true; 38 } 35 39 36 if($levenshtein) 37 { 38 $distance = levenshtein($a, $b); 39 if($distance>-1 && $distance<=$max_distance) return true; 40 if ( $levenshtein ) { 41 $distance = levenshtein( $a, $b ); 42 if ( $distance > - 1 && $distance <= $max_distance ) { 43 return true; 44 } 45 } 40 46 } 47 41 48 return false; 42 49 } … … 45 52 { 46 53 $options = get_option( 'duplicated-configuration' ); 54 if(isset($options['strict'])) $strict=true; 55 else $strict=false; 47 56 if(isset($options['levenshtein'])) $levenshtein=true; 48 57 else $levenshtein=false; … … 61 70 { 62 71 $tag2=$tags2[$j]; 63 if($this->compare_terms($tag1->name, $tag2->name, $ levenshtein, $maxdistance))72 if($this->compare_terms($tag1->name, $tag2->name, $strict, $levenshtein, $maxdistance)) 64 73 array_push($similar_tags, array($tag1,$tag2)); 65 74 } … … 71 80 { 72 81 $options = get_option( 'duplicated-configuration' ); 82 if(isset($options['strict'])) $strict=true; 83 else $strict=false; 73 84 if(isset($options['levenshtein'])) $levenshtein=true; 74 85 else $levenshtein=false; 86 75 87 $maxdistance = $options['maxDistance']; 76 88 if($maxdistance=="") $maxdistance=0; … … 86 98 { 87 99 $cat2=$cats2[$j]; 88 if($this->compare_terms($cat1->name, $cat2->name, $levenshtein, $maxdistance)) 100 // error_log(print_r($cat1 ,true)); 101 if($this->compare_terms($cat1->name, $cat2->name, $strict, $levenshtein, $maxdistance)) 89 102 array_push($similar_cats, array($cat1,$cat2)); 90 103 … … 97 110 { 98 111 $options = get_option( 'duplicated-configuration' ); 112 if(isset($options['strict'])) $strict=true; 113 else $strict=false; 99 114 if(isset($options['levenshtein'])) $levenshtein=true; 100 115 else $levenshtein=false; … … 112 127 { 113 128 $tag=$tags[$j]; 114 if($this->compare_terms($cat->name, $tag->name, $ levenshtein, $maxdistance))129 if($this->compare_terms($cat->name, $tag->name, $strict, $levenshtein, $maxdistance)) 115 130 array_push($similar_terms, array($cat,$tag)); 116 131 … … 121 136 122 137 public function manage_duplicates() { 138 error_log('---- Managing duplicates ---'); 123 139 global $wpdb; 124 140 foreach($_POST as $key=>$post_data) { … … 126 142 //echo "You posted:" . $key . " = " . $post_data . "<br>"; 127 143 //get the term_taxonomy_id for the terms 144 error_log(print_r($key ,true)); 128 145 if($key!='action' && $key!='submit') { 129 $term_keep = get_term( $key, '', OBJECT );146 $term_keep = get_term( substr($key,4), '', OBJECT ); 130 147 $term_remove = get_term( $post_data, '', OBJECT ); 131 148 -
serious-duplicated-terms/trunk/admin/partials/class-serious-duplicated-terms-admin-display-ext.php
r2077519 r2080637 47 47 $tag1 = $couple[0]; 48 48 $tag2 = $couple[1]; 49 echo '<tr><td>' . $tag1->name . '</td><td>' . $tag2->name . '</td><td><input type="checkbox" name="' . $tag1->term_id . '" value="' . $tag2->term_id . '" /> </td></tr>';49 echo '<tr><td>' . $tag1->name . '</td><td>' . $tag2->name . '</td><td><input type="checkbox" name="' . "term".$tag1->term_id . '" value="' . $tag2->term_id . '" /> </td></tr>'; 50 50 } 51 51 echo '</table>'; … … 76 76 $cat1 = $couple[0]; 77 77 $cat2 = $couple[1]; 78 echo '<tr><td>' . $cat1->name . '</td><td>' . $cat2->name . '</td><td><input type="checkbox" name="' . $cat1->term_id . '" value="' . $cat2->term_id . '" /> </td></tr>';78 echo '<tr><td>' . $cat1->name . '</td><td>' . $cat2->name . '</td><td><input type="checkbox" name="' . "term". $cat1->term_id . '" value="' . $cat2->term_id . '" /> </td></tr>'; 79 79 } 80 80 echo '</table>'; … … 105 105 $cat = $couple[0]; 106 106 $tag = $couple[1]; 107 echo '<tr><td>' . $cat->name . '</td><td>' . $tag->name . '</td><td><input type="checkbox" name="' . $cat->term_id . '" value="' . $tag->term_id . '" /> </td></tr>';107 echo '<tr><td>' . $cat->name . '</td><td>' . $tag->name . '</td><td><input type="checkbox" name="' . "term". $cat->term_id . '" value="' . $tag->term_id . '" /> </td></tr>'; 108 108 } 109 109 echo '</table>'; -
serious-duplicated-terms/trunk/admin/partials/class-serious-duplicated-terms-admin-settings.php
r2077519 r2080637 71 71 add_settings_section( 72 72 'distance', 73 'Co nsider Levenshtein Distance',73 'Comparison configuration', 74 74 false, 'duplicated-configuration' 75 75 … … 78 78 79 79 add_settings_field( 80 'strict', 81 'Equal names only', 82 array($this,'render_strict_field'), 83 'duplicated-configuration', 84 'distance' 85 ); 86 87 88 add_settings_field( 80 89 'levenshtein', 81 ' Levenshtein',90 'Use Levenshtein distance', 82 91 array($this,'render_levenshtein_field'), 83 92 'duplicated-configuration', … … 134 143 echo '<input type="checkbox" name="duplicated-configuration[categories]" value="1"' . checked(1, $checked, false) .'/>'; 135 144 } 145 public function render_strict_field() { 146 // Retrieve the full set of options 147 $options = get_option( 'duplicated-configuration' ); 148 // Field output. 149 $checked = isset( $options['strict'] ) ? $options['strict'] : '0'; 150 echo '<input type="checkbox" name="duplicated-configuration[strict]" value="1"' . checked(1, $checked, false) .'/>'; 151 } 136 152 public function render_levenshtein_field() { 137 153 // Retrieve the full set of options
Note: See TracChangeset
for help on using the changeset viewer.