From b2034fdfec040a67988e543a911208ef2491ce7a Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Sun, 22 Feb 2015 12:58:46 +0100 Subject: New RoundCube Plugins Git folder --- emoticons/composer.json | 29 ++++++++++++++++ emoticons/emoticons.php | 78 +++++++++++++++++++++++++++++++++++++++++++ emoticons/tests/Emoticons.php | 23 +++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 emoticons/composer.json create mode 100644 emoticons/emoticons.php create mode 100644 emoticons/tests/Emoticons.php (limited to 'emoticons') diff --git a/emoticons/composer.json b/emoticons/composer.json new file mode 100644 index 0000000..8e7b90a --- /dev/null +++ b/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/emoticons/emoticons.php b/emoticons/emoticons.php new file mode 100644 index 0000000..187e838 --- /dev/null +++ b/emoticons/emoticons.php @@ -0,0 +1,78 @@ +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 "")" shouldn't be replaced by the icon + // It's so long because of assertion format restrictions + $entity = '(? $this->img_tag('smiley-smile.gif', ':)' ), + '/:-\)/' => $this->img_tag('smiley-smile.gif', ':-)' ), + '/(? $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-)' ), + '/(? $this->img_tag('smiley-surprised.gif', ':O' ), + '/(? $this->img_tag('smiley-surprised.gif', ':-O' ), + '/(? $this->img_tag('smiley-tongue-out.gif', ':P' ), + '/(? $this->img_tag('smiley-tongue-out.gif', ':-P' ), + '/(? $this->img_tag('smiley-yell.gif', ':@' ), + '/(? $this->img_tag('smiley-yell.gif', ':-@' ), + '/O:\)/i' => $this->img_tag('smiley-innocent.gif', 'O:)' ), + '/O:-\)/i' => $this->img_tag('smiley-innocent.gif', 'O:-)' ), + '/(? $this->img_tag('smiley-embarassed.gif', ':$' ), + '/(? $this->img_tag('smiley-embarassed.gif', ':-$' ), + '/(? $this->img_tag('smiley-kiss.gif', ':*' ), + '/(? $this->img_tag('smiley-kiss.gif', ':-*' ), + '/(? $this->img_tag('smiley-undecided.gif', ':S' ), + '/(? $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/emoticons/tests/Emoticons.php b/emoticons/tests/Emoticons.php new file mode 100644 index 0000000..e045022 --- /dev/null +++ b/emoticons/tests/Emoticons.php @@ -0,0 +1,23 @@ +api); + + $this->assertInstanceOf('emoticons', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + -- cgit v1.2.3