summaryrefslogtreecommitdiff
path: root/plugins/emoticons
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/emoticons')
-rw-r--r--plugins/emoticons/emoticons.php78
-rw-r--r--plugins/emoticons/package.xml53
2 files changed, 131 insertions, 0 deletions
diff --git a/plugins/emoticons/emoticons.php b/plugins/emoticons/emoticons.php
new file mode 100644
index 000000000..c986686e3
--- /dev/null
+++ b/plugins/emoticons/emoticons.php
@@ -0,0 +1,78 @@
+<?php
+
+/**
+ * Display Emoticons
+ *
+ * Sample plugin to replace emoticons in plain text message body with real icons
+ *
+ * @version @package_version@
+ * @license GNU GPLv3+
+ * @author Thomas Bruederli
+ * @author Aleksander Machniak
+ * @website http://roundcube.net
+ */
+class emoticons extends rcube_plugin
+{
+ public $task = 'mail';
+
+ function init()
+ {
+ $this->add_hook('message_part_after', array($this, 'replace'));
+ }
+
+ function replace($args)
+ {
+ // This is a lookbehind assertion which will exclude html entities
+ // E.g. situation when ";)" in "&quot;)" shouldn't be replaced by the icon
+ // It's so long because of assertion format restrictions
+ $entity = '(?<!&'
+ . '[a-zA-Z0-9]{2}' . '|' . '#[0-9]{2}' . '|'
+ . '[a-zA-Z0-9]{3}' . '|' . '#[0-9]{3}' . '|'
+ . '[a-zA-Z0-9]{4}' . '|' . '#[0-9]{4}' . '|'
+ . '[a-zA-Z0-9]{5}' . '|'
+ . '[a-zA-Z0-9]{6}' . '|'
+ . '[a-zA-Z0-9]{7}'
+ . ')';
+
+ // map of emoticon replacements
+ $map = array(
+ '/:\)/' => $this->img_tag('smiley-smile.gif', ':)' ),
+ '/:-\)/' => $this->img_tag('smiley-smile.gif', ':-)' ),
+ '/(?<!mailto):D/' => $this->img_tag('smiley-laughing.gif', ':D' ),
+ '/:-D/' => $this->img_tag('smiley-laughing.gif', ':-D' ),
+ '/:\(/' => $this->img_tag('smiley-frown.gif', ':(' ),
+ '/:-\(/' => $this->img_tag('smiley-frown.gif', ':-(' ),
+ '/'.$entity.';\)/' => $this->img_tag('smiley-wink.gif', ';)' ),
+ '/'.$entity.';-\)/' => $this->img_tag('smiley-wink.gif', ';-)' ),
+ '/8\)/' => $this->img_tag('smiley-cool.gif', '8)' ),
+ '/8-\)/' => $this->img_tag('smiley-cool.gif', '8-)' ),
+ '/(?<!mailto):O/i' => $this->img_tag('smiley-surprised.gif', ':O' ),
+ '/(?<!mailto):-O/i' => $this->img_tag('smiley-surprised.gif', ':-O' ),
+ '/(?<!mailto):P/i' => $this->img_tag('smiley-tongue-out.gif', ':P' ),
+ '/(?<!mailto):-P/i' => $this->img_tag('smiley-tongue-out.gif', ':-P' ),
+ '/(?<!mailto):@/i' => $this->img_tag('smiley-yell.gif', ':@' ),
+ '/(?<!mailto):-@/i' => $this->img_tag('smiley-yell.gif', ':-@' ),
+ '/O:\)/i' => $this->img_tag('smiley-innocent.gif', 'O:)' ),
+ '/O:-\)/i' => $this->img_tag('smiley-innocent.gif', 'O:-)' ),
+ '/(?<!mailto):$/' => $this->img_tag('smiley-embarassed.gif', ':$' ),
+ '/(?<!mailto):-$/' => $this->img_tag('smiley-embarassed.gif', ':-$' ),
+ '/(?<!mailto):\*/i' => $this->img_tag('smiley-kiss.gif', ':*' ),
+ '/(?<!mailto):-\*/i' => $this->img_tag('smiley-kiss.gif', ':-*' ),
+ '/(?<!mailto):S/i' => $this->img_tag('smiley-undecided.gif', ':S' ),
+ '/(?<!mailto):-S/i' => $this->img_tag('smiley-undecided.gif', ':-S' ),
+ );
+
+ if ($args['type'] == 'plain') {
+ $args['body'] = preg_replace(
+ array_keys($map), array_values($map), $args['body']);
+ }
+
+ return $args;
+ }
+
+ private function img_tag($ico, $title)
+ {
+ $path = './program/js/tiny_mce/plugins/emotions/img/';
+ return html::img(array('src' => $path.$ico, 'title' => $title));
+ }
+}
diff --git a/plugins/emoticons/package.xml b/plugins/emoticons/package.xml
new file mode 100644
index 000000000..b4218103c
--- /dev/null
+++ b/plugins/emoticons/package.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" packagerversion="1.9.0" version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
+ http://pear.php.net/dtd/tasks-1.0.xsd
+ http://pear.php.net/dtd/package-2.0
+ http://pear.php.net/dtd/package-2.0.xsd">
+ <name>emoticons</name>
+ <channel>pear.roundcube.net</channel>
+ <summary>Display emoticons in text messages</summary>
+ <description>Sample plugin to replace emoticons in plain text message body with real icons.</description>
+ <lead>
+ <name>Thomas Bruederli</name>
+ <user>thomasb</user>
+ <email>roundcube@gmail.com</email>
+ <active>yes</active>
+ </lead>
+ <developer>
+ <name>Aleksander Machniak</name>
+ <user>alec</user>
+ <email>alec@alec.pl</email>
+ <active>yes</active>
+ </developer>
+ <date>2011-11-21</date>
+ <version>
+ <release>1.3</release>
+ <api>1.3</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <license uri="http://www.gnu.org/licenses/gpl.html">GNU GPLv3+</license>
+ <notes>-</notes>
+ <contents>
+ <dir baseinstalldir="/" name="/">
+ <file name="emoticons.php" role="php">
+ <tasks:replace from="@name@" to="name" type="package-info"/>
+ <tasks:replace from="@package_version@" to="version" type="package-info"/>
+ </file>
+ </dir>
+ <!-- / -->
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>5.2.1</min>
+ </php>
+ <pearinstaller>
+ <min>1.7.0</min>
+ </pearinstaller>
+ </required>
+ </dependencies>
+ <phprelease/>
+</package>