Make WordPress Core


Ignore:
Timestamp:
01/06/2009 06:20:47 PM (18 years ago)
Author:
ryan
Message:

Faster smilies. Props johanee. fixes #6464

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r10287 r10322  
    23672367}
    23682368
     2369
    23692370/**
    23702371 * Convert smiley code to the icon graphic file equivalent.
     
    23772378 * image file.
    23782379 *
    2379  * The $wp_smiliessearch global is for the regular expression array and is
    2380  * set each time the function is called. The $wp_smiliesreplace is the full
    2381  * replacement. Supposely, the $wp_smiliessearch array is looped over using
    2382  * preg_replace() or just setting the array of $wp_smiliessearch along with the
    2383  * array of $wp_smiliesreplace in the search and replace parameters of
    2384  * preg_replace(), which would be faster and less overhead. Either way, both are
    2385  * used with preg_replace() and can be defined after the function is called.
     2380 * The $wp_smiliessearch global is for the regular expression and is set each
     2381 * time the function is called.
    23862382 *
    23872383 * The full list of smilies can be found in the function and won't be listed in
     
    23902386 *
    23912387 * @global array $wpsmiliestrans
    2392  * @global array $wp_smiliesreplace
    23932388 * @global array $wp_smiliessearch
    23942389 * @since 2.2.0
    23952390 */
    23962391function smilies_init() {
    2397         global $wpsmiliestrans, $wp_smiliessearch, $wp_smiliesreplace;
     2392        global $wpsmiliestrans, $wp_smiliessearch;
    23982393
    23992394        // don't bother setting up smilies if they are disabled
     
    24502445        }
    24512446
    2452         $siteurl = get_option( 'siteurl' );
     2447        if (count($wpsmiliestrans) == 0) {
     2448                return;
     2449        }
     2450
     2451        /*
     2452         * NOTE: we sort the smilies in reverse key order. This is to make sure
     2453         * we match the longest possible smilie (:???: vs :?) as the regular
     2454         * expression used below is first-match
     2455         */
     2456        krsort($wpsmiliestrans);
     2457
     2458        $wp_smiliessearch = '/(?:\s|^)';
     2459
     2460        $subchar = '';
    24532461        foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
    2454                 $wp_smiliessearch[] = '/(\s|^)' . preg_quote( $smiley, '/' ) . '(\s|$)/';
    2455                 $smiley_masked = attribute_escape( trim( $smiley ) );
    2456                 $wp_smiliesreplace[] = " <img src='$siteurl/wp-includes/images/smilies/$img' alt='$smiley_masked' class='wp-smiley' /> ";
    2457         }
     2462                $firstchar = substr($smiley, 0, 1);
     2463                $rest = substr($smiley, 1);
     2464
     2465                // new subpattern?
     2466                if ($firstchar != $subchar) {
     2467                        if ($subchar != '') {
     2468                                $wp_smiliessearch .= ')|';
     2469                        }
     2470                        $subchar = $firstchar;
     2471                        $wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:';
     2472                } else {
     2473                        $wp_smiliessearch .= '|';
     2474                }
     2475                $wp_smiliessearch .= preg_quote($rest);
     2476        }
     2477
     2478        $wp_smiliessearch .= ')(?:\s|$)/';
    24582479}
    24592480
Note: See TracChangeset for help on using the changeset viewer.