Make WordPress Core


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

Faster smilies. Props johanee. fixes #6464

File:
1 edited

Legend:

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

    r10298 r10322  
    12191219}
    12201220
     1221
     1222/**
     1223 * Convert one smiley code to the icon graphic file equivalent.
     1224 *
     1225 * Looks up one smiley code in the $wpsmiliestrans global array and returns an
     1226 * <img> string for that smiley.
     1227 *
     1228 * @global array $wpsmiliestrans
     1229 * @since 2.8.0
     1230 *
     1231 * @param string $smiley Smiley code to convert to image.
     1232 * @return string Image string for smiley.
     1233 */
     1234function translate_smiley($smiley) {
     1235    global $wpsmiliestrans;
     1236
     1237    if (count($smiley) == 0) {
     1238        return '';
     1239    }
     1240
     1241    $siteurl = get_option( 'siteurl' );
     1242
     1243    $smiley = trim(reset($smiley));
     1244    $img = $wpsmiliestrans[$smiley];
     1245    $smiley_masked = attribute_escape($smiley);
     1246
     1247    return " <img src='$siteurl/wp-includes/images/smilies/$img' alt='$smiley_masked' class='wp-smiley' /> ";
     1248}
     1249
     1250
    12211251/**
    12221252 * Convert text equivalent of smilies to images.
    12231253 *
    1224  * Will only convert smilies if the option 'use_smilies' is true and the globals
    1225  * used in the function aren't empty.
     1254 * Will only convert smilies if the option 'use_smilies' is true and the global
     1255 * used in the function isn't empty.
    12261256 *
    12271257 * @since 0.71
    1228  * @uses $wp_smiliessearch, $wp_smiliesreplace Smiley replacement arrays.
     1258 * @uses $wp_smiliessearch
    12291259 *
    12301260 * @param string $text Content to convert smilies from text.
     
    12321262 */
    12331263function convert_smilies($text) {
    1234     global $wp_smiliessearch, $wp_smiliesreplace;
     1264    global $wp_smiliessearch;
    12351265    $output = '';
    1236     if ( get_option('use_smilies') && !empty($wp_smiliessearch) && !empty($wp_smiliesreplace) ) {
     1266    if ( get_option('use_smilies') && !empty($wp_smiliessearch) ) {
    12371267        // HTML loop taken from texturize function, could possible be consolidated
    12381268        $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
     
    12411271            $content = $textarr[$i];
    12421272            if ((strlen($content) > 0) && ('<' != $content{0})) { // If it's not a tag
    1243                 $content = preg_replace($wp_smiliessearch, $wp_smiliesreplace, $content);
     1273                $content = preg_replace_callback($wp_smiliessearch, 'translate_smiley', $content);
    12441274            }
    12451275            $output .= $content;
Note: See TracChangeset for help on using the changeset viewer.