Mercurial > hg > rc1
comparison plugins/emoticons/emoticons.php @ 0:1e000243b222
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:50:29 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1e000243b222 |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Emoticons | |
5 * | |
6 * Plugin to replace emoticons in plain text message body with real icons. | |
7 * Also it enables emoticons in HTML compose editor. Both features are optional. | |
8 * | |
9 * @license GNU GPLv3+ | |
10 * @author Thomas Bruederli | |
11 * @author Aleksander Machniak | |
12 * @website http://roundcube.net | |
13 */ | |
14 class emoticons extends rcube_plugin | |
15 { | |
16 public $task = 'mail|settings|utils'; | |
17 | |
18 | |
19 /** | |
20 * Plugin initilization. | |
21 */ | |
22 function init() | |
23 { | |
24 $rcube = rcube::get_instance(); | |
25 | |
26 $this->add_hook('message_part_after', array($this, 'message_part_after')); | |
27 $this->add_hook('message_outgoing_body', array($this, 'message_outgoing_body')); | |
28 $this->add_hook('html2text', array($this, 'html2text')); | |
29 $this->add_hook('html_editor', array($this, 'html_editor')); | |
30 | |
31 if ($rcube->task == 'settings') { | |
32 $this->add_hook('preferences_list', array($this, 'preferences_list')); | |
33 $this->add_hook('preferences_save', array($this, 'preferences_save')); | |
34 } | |
35 } | |
36 | |
37 /** | |
38 * 'message_part_after' hook handler to replace common plain text emoticons | |
39 * with emoticon images (<img>) | |
40 */ | |
41 function message_part_after($args) | |
42 { | |
43 if ($args['type'] == 'plain') { | |
44 $this->load_config(); | |
45 | |
46 $rcube = rcube::get_instance(); | |
47 if (!$rcube->config->get('emoticons_display', false)) { | |
48 return $args; | |
49 } | |
50 | |
51 require_once __DIR__ . '/emoticons_engine.php'; | |
52 | |
53 $args['body'] = emoticons_engine::text2icons($args['body']); | |
54 } | |
55 | |
56 return $args; | |
57 } | |
58 | |
59 /** | |
60 * 'message_outgoing_body' hook handler to replace image emoticons from TinyMCE | |
61 * editor with image attachments. | |
62 */ | |
63 function message_outgoing_body($args) | |
64 { | |
65 if ($args['type'] == 'html') { | |
66 $this->load_config(); | |
67 | |
68 $rcube = rcube::get_instance(); | |
69 if (!$rcube->config->get('emoticons_compose', true)) { | |
70 return $args; | |
71 } | |
72 | |
73 require_once __DIR__ . '/emoticons_engine.php'; | |
74 | |
75 // look for "emoticon" images from TinyMCE and change their src paths to | |
76 // be file paths on the server instead of URL paths. | |
77 $images = emoticons_engine::replace($args['body']); | |
78 | |
79 // add these images as attachments to the MIME message | |
80 foreach ($images as $img_name => $img_file) { | |
81 $args['message']->addHTMLImage($img_file, 'image/gif', '', true, $img_name); | |
82 } | |
83 } | |
84 | |
85 return $args; | |
86 } | |
87 | |
88 /** | |
89 * 'html2text' hook handler to replace image emoticons from TinyMCE | |
90 * editor with plain text emoticons. | |
91 * | |
92 * This is executed on html2text action, i.e. when switching from HTML to text | |
93 * in compose window (or similar place). Also when generating alternative | |
94 * text/plain part. | |
95 */ | |
96 function html2text($args) | |
97 { | |
98 $rcube = rcube::get_instance(); | |
99 | |
100 if ($rcube->action == 'html2text' || $rcube->action == 'send') { | |
101 $this->load_config(); | |
102 | |
103 if (!$rcube->config->get('emoticons_compose', true)) { | |
104 return $args; | |
105 } | |
106 | |
107 require_once __DIR__ . '/emoticons_engine.php'; | |
108 | |
109 $args['body'] = emoticons_engine::icons2text($args['body']); | |
110 } | |
111 | |
112 return $args; | |
113 } | |
114 | |
115 /** | |
116 * 'html_editor' hook handler, where we enable emoticons in TinyMCE | |
117 */ | |
118 function html_editor($args) | |
119 { | |
120 $rcube = rcube::get_instance(); | |
121 | |
122 $this->load_config(); | |
123 | |
124 if ($rcube->config->get('emoticons_compose', true)) { | |
125 $args['extra_plugins'][] = 'emoticons'; | |
126 $args['extra_buttons'][] = 'emoticons'; | |
127 } | |
128 | |
129 return $args; | |
130 } | |
131 | |
132 /** | |
133 * 'preferences_list' hook handler | |
134 */ | |
135 function preferences_list($args) | |
136 { | |
137 $rcube = rcube::get_instance(); | |
138 $dont_override = $rcube->config->get('dont_override', array()); | |
139 | |
140 if ($args['section'] == 'mailview' && !in_array('emoticons_display', $dont_override)) { | |
141 $this->load_config(); | |
142 $this->add_texts('localization'); | |
143 | |
144 $field_id = 'emoticons_display'; | |
145 $checkbox = new html_checkbox(array('name' => '_' . $field_id, 'id' => $field_id, 'value' => 1)); | |
146 | |
147 $args['blocks']['main']['options']['emoticons_display'] = array( | |
148 'title' => $this->gettext('emoticonsdisplay'), | |
149 'content' => $checkbox->show(intval($rcube->config->get('emoticons_display', false))) | |
150 ); | |
151 } | |
152 else if ($args['section'] == 'compose' && !in_array('emoticons_compose', $dont_override)) { | |
153 $this->load_config(); | |
154 $this->add_texts('localization'); | |
155 | |
156 $field_id = 'emoticons_compose'; | |
157 $checkbox = new html_checkbox(array('name' => '_' . $field_id, 'id' => $field_id, 'value' => 1)); | |
158 | |
159 $args['blocks']['main']['options']['emoticons_compose'] = array( | |
160 'title' => $this->gettext('emoticonscompose'), | |
161 'content' => $checkbox->show(intval($rcube->config->get('emoticons_compose', true))) | |
162 ); | |
163 } | |
164 | |
165 return $args; | |
166 } | |
167 | |
168 /** | |
169 * 'preferences_save' hook handler | |
170 */ | |
171 function preferences_save($args) | |
172 { | |
173 $rcube = rcube::get_instance(); | |
174 $dont_override = $rcube->config->get('dont_override', array()); | |
175 | |
176 if ($args['section'] == 'mailview' && !in_array('emoticons_display', $dont_override)) { | |
177 $args['prefs']['emoticons_display'] = rcube_utils::get_input_value('_emoticons_display', rcube_utils::INPUT_POST) ? true : false; | |
178 } | |
179 else if ($args['section'] == 'compose' && !in_array('emoticons_compose', $dont_override)) { | |
180 $args['prefs']['emoticons_compose'] = rcube_utils::get_input_value('_emoticons_compose', rcube_utils::INPUT_POST) ? true : false; | |
181 } | |
182 | |
183 return $args; | |
184 } | |
185 } |