summaryrefslogtreecommitdiff
path: root/plugins/emoticons
diff options
context:
space:
mode:
authorHugues Hiegel <root@paranoid>2015-04-21 12:49:44 +0200
committerHugues Hiegel <root@paranoid>2015-04-21 12:49:44 +0200
commit733f8e8d0ce6217d906d06dc4fb08e36d48ed794 (patch)
treecff28366ff63ea6596f8026e1698090bd0b9405c /plugins/emoticons
parentef2e7b3f9d264ec146d4dae257b1e295ab3b462a (diff)
parenta4ba3df54834ee90fb2c9930669f1229dc80261a (diff)
Merge remote-tracking branch 'origin/master'HEADmaster
Conflicts: composer.json-dist config/defaults.inc.php plugins plugins/acl/acl.js plugins/acl/acl.php plugins/acl/skins/classic/templates/table.html plugins/acl/skins/larry/templates/table.html plugins/enigma/README plugins/enigma/config.inc.php.dist plugins/enigma/enigma.js plugins/enigma/enigma.php plugins/enigma/lib/enigma_driver.php plugins/enigma/lib/enigma_driver_gnupg.php plugins/enigma/lib/enigma_driver_phpssl.php plugins/enigma/lib/enigma_engine.php plugins/enigma/lib/enigma_error.php plugins/enigma/lib/enigma_key.php plugins/enigma/lib/enigma_signature.php plugins/enigma/lib/enigma_subkey.php plugins/enigma/lib/enigma_ui.php plugins/enigma/lib/enigma_userid.php plugins/enigma/localization/en_US.inc plugins/enigma/localization/ja_JP.inc plugins/enigma/localization/ru_RU.inc plugins/enigma/skins/classic/enigma.css plugins/enigma/skins/classic/templates/keys.html plugins/help/config.inc.php.dist plugins/help/help.php plugins/help/localization/en_US.inc plugins/jqueryui/jqueryui.php plugins/managesieve/Changelog plugins/managesieve/composer.json plugins/managesieve/config.inc.php.dist plugins/managesieve/lib/Roundcube/rcube_sieve.php plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php plugins/managesieve/localization/en_US.inc plugins/managesieve/managesieve.js plugins/managesieve/skins/classic/managesieve.css plugins/managesieve/skins/larry/managesieve.css plugins/password/README plugins/password/config.inc.php.dist plugins/password/drivers/ldap.php plugins/password/drivers/poppassd.php plugins/password/drivers/vpopmaild.php plugins/vcard_attachments/vcardattach.js plugins/zipdownload/zipdownload.php
Diffstat (limited to 'plugins/emoticons')
-rw-r--r--plugins/emoticons/composer.json29
-rw-r--r--plugins/emoticons/emoticons.php78
-rw-r--r--plugins/emoticons/tests/Emoticons.php23
3 files changed, 130 insertions, 0 deletions
diff --git a/plugins/emoticons/composer.json b/plugins/emoticons/composer.json
new file mode 100644
index 000000000..8e7b90ae9
--- /dev/null
+++ b/plugins/emoticons/composer.json
@@ -0,0 +1,29 @@
+{
+ "name": "roundcube/emoticons",
+ "type": "roundcube-plugin",
+ "description": "Sample plugin to replace emoticons in plain text message body with real icons.",
+ "license": "GPLv3+",
+ "version": "1.3",
+ "authors": [
+ {
+ "name": "Thomas Bruederli",
+ "email": "roundcube@gmail.com",
+ "role": "Lead"
+ },
+ {
+ "name": "Aleksander Machniak",
+ "email": "alec@alec.pl",
+ "role": "Developer"
+ }
+ ],
+ "repositories": [
+ {
+ "type": "composer",
+ "url": "http://plugins.roundcube.net"
+ }
+ ],
+ "require": {
+ "php": ">=5.3.0",
+ "roundcube/plugin-installer": ">=0.1.3"
+ }
+}
diff --git a/plugins/emoticons/emoticons.php b/plugins/emoticons/emoticons.php
new file mode 100644
index 000000000..187e83827
--- /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/tinymce/plugins/emoticons/img/';
+ return html::img(array('src' => $path.$ico, 'title' => $title));
+ }
+}
diff --git a/plugins/emoticons/tests/Emoticons.php b/plugins/emoticons/tests/Emoticons.php
new file mode 100644
index 000000000..e04502285
--- /dev/null
+++ b/plugins/emoticons/tests/Emoticons.php
@@ -0,0 +1,23 @@
+<?php
+
+class Emoticons_Plugin extends PHPUnit_Framework_TestCase
+{
+
+ function setUp()
+ {
+ include_once __DIR__ . '/../emoticons.php';
+ }
+
+ /**
+ * Plugin object construction test
+ */
+ function test_constructor()
+ {
+ $rcube = rcube::get_instance();
+ $plugin = new emoticons($rcube->api);
+
+ $this->assertInstanceOf('emoticons', $plugin);
+ $this->assertInstanceOf('rcube_plugin', $plugin);
+ }
+}
+