Plugin Directory

Changeset 3459566


Ignore:
Timestamp:
02/12/2026 06:13:04 AM (8 weeks ago)
Author:
cifi
Message:

Fix - seo image normalization in focus pages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • squirrly-seo/tags/12.4.15/models/focuspages/Image.php

    r3123012 r3459566  
    163163                }
    164164
     165                $image = $this->normalizeFilename($image);
     166
    165167                //Check if all words are present in the image URL
    166168                $allwords = true;
    167169                foreach ( $words as $word ) {
     170                    $word = trim($word);
     171                    if ($word === '') continue;
     172
     173                    $wordNorm = $this->normalizeFilename($word);
     174
    168175                    //Find the string with normalization
    169                     if ( $word <> '' && SQ_Classes_Helpers_Tools::findStr( $image, $word, true ) === false ) {
     176                    if ( $word <> '' && SQ_Classes_Helpers_Tools::findStr( $image, $wordNorm, true ) === false ) {
    170177                        $allwords = false;
    171178                    }
     
    182189    }
    183190
     191    /**
     192     * @param $string
     193     *
     194     * @return array|string|string[]|null
     195     */
     196    private function normalizeFilename($string) {
     197        $string = html_entity_decode($string, ENT_QUOTES, 'UTF-8');
     198        $string = strtolower($string);
     199
     200        // remove query and extension
     201        $string = preg_replace('~\?.*$~', '', $string);
     202        $string = preg_replace('~\.[a-z0-9]{2,5}$~i', '', $string);
     203
     204        // German folding (I would do digraphs first)
     205        $string = str_replace(array('ae','oe','ue'), array('a','o','u'), $string);
     206        $string = str_replace(array('ä','ö','ü'), array('a','o','u'), $string);
     207        $string = str_replace('ß', 'ss', $string);
     208
     209        // Transliterate remaining accents
     210        if (class_exists('Transliterator')) {
     211            $tmp = transliterator_transliterate('Any-Latin; Latin-ASCII', $string);
     212            if (is_string($tmp) && $tmp !== '') $string = $tmp;
     213        } else {
     214            $tmp = @iconv('UTF-8', 'ASCII//TRANSLIT', $string);
     215            if (is_string($tmp) && $tmp !== '') $string = $tmp;
     216        }
     217
     218        $string = preg_replace('~[^\p{L}\p{N}]+~u', ' ', $string);
     219        $string = preg_replace('~\s{2,}~u', ' ', trim($string));
     220
     221        return $string;
     222    }
     223
    184224}
Note: See TracChangeset for help on using the changeset viewer.