6 * Sample plugin to replace emoticons in plain text message body with real icons
9 * @author Thomas Bruederli
10 * @author Aleksander Machniak
11 * @website http://roundcube.net
13 class emoticons extends rcube_plugin
15 public $task = 'mail';
19 $this->add_hook('message_part_after', array($this, 'replace'));
22 function replace($args)
24 // This is a lookbehind assertion which will exclude html entities
25 // E.g. situation when ";)" in "")" shouldn't be replaced by the icon
26 // It's so long because of assertion format restrictions
28 . '[a-zA-Z0-9]{2}' . '|' . '#[0-9]{2}' . '|'
29 . '[a-zA-Z0-9]{3}' . '|' . '#[0-9]{3}' . '|'
30 . '[a-zA-Z0-9]{4}' . '|' . '#[0-9]{4}' . '|'
31 . '[a-zA-Z0-9]{5}' . '|'
32 . '[a-zA-Z0-9]{6}' . '|'
36 // map of emoticon replacements
38 '/:\)/' => $this->img_tag('smiley-smile.gif', ':)' ),
39 '/:-\)/' => $this->img_tag('smiley-smile.gif', ':-)' ),
40 '/(?<!mailto):D/' => $this->img_tag('smiley-laughing.gif', ':D' ),
41 '/:-D/' => $this->img_tag('smiley-laughing.gif', ':-D' ),
42 '/:\(/' => $this->img_tag('smiley-frown.gif', ':(' ),
43 '/:-\(/' => $this->img_tag('smiley-frown.gif', ':-(' ),
44 '/'.$entity.';\)/' => $this->img_tag('smiley-wink.gif', ';)' ),
45 '/'.$entity.';-\)/' => $this->img_tag('smiley-wink.gif', ';-)' ),
46 '/8\)/' => $this->img_tag('smiley-cool.gif', '8)' ),
47 '/8-\)/' => $this->img_tag('smiley-cool.gif', '8-)' ),
48 '/(?<!mailto):O/i' => $this->img_tag('smiley-surprised.gif', ':O' ),
49 '/(?<!mailto):-O/i' => $this->img_tag('smiley-surprised.gif', ':-O' ),
50 '/(?<!mailto):P/i' => $this->img_tag('smiley-tongue-out.gif', ':P' ),
51 '/(?<!mailto):-P/i' => $this->img_tag('smiley-tongue-out.gif', ':-P' ),
52 '/(?<!mailto):@/i' => $this->img_tag('smiley-yell.gif', ':@' ),
53 '/(?<!mailto):-@/i' => $this->img_tag('smiley-yell.gif', ':-@' ),
54 '/O:\)/i' => $this->img_tag('smiley-innocent.gif', 'O:)' ),
55 '/O:-\)/i' => $this->img_tag('smiley-innocent.gif', 'O:-)' ),
56 '/(?<!mailto):$/' => $this->img_tag('smiley-embarassed.gif', ':$' ),
57 '/(?<!mailto):-$/' => $this->img_tag('smiley-embarassed.gif', ':-$' ),
58 '/(?<!mailto):\*/i' => $this->img_tag('smiley-kiss.gif', ':*' ),
59 '/(?<!mailto):-\*/i' => $this->img_tag('smiley-kiss.gif', ':-*' ),
60 '/(?<!mailto):S/i' => $this->img_tag('smiley-undecided.gif', ':S' ),
61 '/(?<!mailto):-S/i' => $this->img_tag('smiley-undecided.gif', ':-S' ),
64 if ($args['type'] == 'plain') {
65 $args['body'] = preg_replace(
66 array_keys($map), array_values($map), $args['body']);
72 private function img_tag($ico, $title)
74 $path = './program/js/tiny_mce/plugins/emotions/img/';
75 return html::img(array('src' => $path.$ico, 'title' => $title));