Plugin Directory

Changeset 2080637


Ignore:
Timestamp:
05/04/2019 09:47:04 PM (7 years ago)
Author:
softmodeling
Message:

Version 1.1 of the plugin

Location:
serious-duplicated-terms
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • serious-duplicated-terms/trunk/README.txt

    r2077519 r2080637  
    4747No. If you do index individual tag and category pages (not always recommended) you will need to create the redirections manually.
    4848
     49= I see too many similar tags/categories in the analysis page =
     50
     51Try 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).
    4952
    5053== Screenshots ==
     
    5558== Changelog ==
    5659
     60= 1.1 =
     61* Added option to signal as duplicates only terms with the same exact name
     62
    5763= 1.0 =
    5864* 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  
    2626     *
    2727     **/
    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
    3132
    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            }
    3539
    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            }
    4046        }
     47
    4148        return false;
    4249    }
     
    4552    {
    4653        $options = get_option( 'duplicated-configuration' );
     54        if(isset($options['strict']))   $strict=true;
     55        else $strict=false;
    4756        if(isset($options['levenshtein']))  $levenshtein=true;
    4857        else $levenshtein=false;
     
    6170            {
    6271                $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))
    6473                    array_push($similar_tags, array($tag1,$tag2));
    6574            }
     
    7180    {
    7281        $options = get_option( 'duplicated-configuration' );
     82        if(isset($options['strict']))   $strict=true;
     83        else $strict=false;
    7384        if(isset($options['levenshtein']))  $levenshtein=true;
    7485        else $levenshtein=false;
     86
    7587        $maxdistance = $options['maxDistance'];
    7688        if($maxdistance=="") $maxdistance=0;
     
    8698            {
    8799                $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))
    89102                    array_push($similar_cats, array($cat1,$cat2));
    90103
     
    97110    {
    98111        $options = get_option( 'duplicated-configuration' );
     112        if(isset($options['strict']))   $strict=true;
     113        else $strict=false;
    99114        if(isset($options['levenshtein']))  $levenshtein=true;
    100115        else $levenshtein=false;
     
    112127            {
    113128                $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))
    115130                    array_push($similar_terms, array($cat,$tag));
    116131
     
    121136
    122137    public function manage_duplicates() {
     138        error_log('---- Managing duplicates ---');
    123139        global $wpdb;
    124140        foreach($_POST as $key=>$post_data) {
     
    126142            //echo "You posted:" . $key . " = " . $post_data . "<br>";
    127143            //get the term_taxonomy_id for the terms
     144            error_log(print_r($key ,true));
    128145            if($key!='action' && $key!='submit') {
    129                 $term_keep   = get_term( $key, '', OBJECT );
     146                $term_keep   = get_term( substr($key,4), '', OBJECT );
    130147                $term_remove = get_term( $post_data, '', OBJECT );
    131148
  • serious-duplicated-terms/trunk/admin/partials/class-serious-duplicated-terms-admin-display-ext.php

    r2077519 r2080637  
    4747                    $tag1 = $couple[0];
    4848                    $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>';
    5050                }
    5151                echo '</table>';
     
    7676                    $cat1 = $couple[0];
    7777                    $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>';
    7979                }
    8080                echo '</table>';
     
    105105                    $cat = $couple[0];
    106106                    $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>';
    108108                }
    109109                echo '</table>';
  • serious-duplicated-terms/trunk/admin/partials/class-serious-duplicated-terms-admin-settings.php

    r2077519 r2080637  
    7171            add_settings_section(
    7272                'distance',
    73                 'Consider Levenshtein Distance',
     73                'Comparison configuration',
    7474                false, 'duplicated-configuration'
    7575           
     
    7878                       
    7979                    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(
    8089                        'levenshtein',
    81                         'Levenshtein',
     90                        'Use Levenshtein distance',
    8291                        array($this,'render_levenshtein_field'),
    8392                        'duplicated-configuration',
     
    134143        echo '<input type="checkbox" name="duplicated-configuration[categories]" value="1"'  . checked(1, $checked, false) .'/>';
    135144    }
     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    }
    136152    public function render_levenshtein_field() {
    137153        // Retrieve the full set of options
Note: See TracChangeset for help on using the changeset viewer.