[geeklog-devel] New function for lib-common

Blaine Lang geeklog at langfamily.ca
Tue May 13 19:49:06 EDT 2003


I've used emoticons in a few of my projects and I'm working on a new plugin that also supports them. I've reworked the function that I'm now pretty happy with. We also have had requests to add support for emoticons and smilies in the core GL story and comment engine. Not really a key requirement for business use but the basic ones are handy.

Anyway, my new function uses a table for the mappings of emoticons to images and will be easy to extend - just need to now create a admin module. You can have multiple emoticons map to the same image as in :) and :-) to the smile image.

Any concerns in adding this function to CVS?
- need to update lib-databases
- add a new config parm $_CONF['SMILE_PATH']
- update the 1.3.8 updgrade SQL script

Blaine

The function is shown below
---------------
/**
* Replace emoticons in string with formated HTML of smilies.
* Emoticon mapping to images are defined in a the table.
* This function will replace all the emoticons in the past string. 
* @param   string  $text  The text
* @return    string  The text, possibly with emoticons replaced with the HTML img tags for the smilie image.
*/
function COM_replaceEmoticons( $text ) {
    global $_CONF, $_TABLES;

    $arr_smilies = array();
    $sql = DB_query("SELECT code,smile_url from {$_TABLES['smilies']}");
    while ( list($key,$icon) = DB_fetchARRAY($sql)) {
        $arr_smilies[$key] = $icon;
    }

    foreach ($arr_smilies as $key => $icon) {
        $text = str_replace($key,'<img src='.$_CONF['SMILE_PATH']. $icon . ' BORDER="0">',$text);
    }
   
    return $text;

}


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist8.pair.net/pipermail/geeklog-devel/attachments/20030513/88171093/attachment.html>


More information about the geeklog-devel mailing list