Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

emoticons.php 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * Emoticons
  4. *
  5. * Plugin to replace emoticons in plain text message body with real icons.
  6. * Also it enables emoticons in HTML compose editor. Both features are optional.
  7. *
  8. * @version @package_version@
  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. * Plugin initilization.
  19. */
  20. function init()
  21. {
  22. $rcube = rcube::get_instance();
  23. $this->add_hook('message_part_after', array($this, 'message_part_after'));
  24. $this->add_hook('message_outgoing_body', array($this, 'message_outgoing_body'));
  25. $this->add_hook('html2text', array($this, 'html2text'));
  26. $this->add_hook('html_editor', array($this, 'html_editor'));
  27. if ($rcube->task == 'settings') {
  28. $this->add_hook('preferences_list', array($this, 'preferences_list'));
  29. $this->add_hook('preferences_save', array($this, 'preferences_save'));
  30. }
  31. }
  32. /**
  33. * 'message_part_after' hook handler to replace common plain text emoticons
  34. * with emoticon images (<img>)
  35. */
  36. function message_part_after($args)
  37. {
  38. if ($args['type'] == 'plain') {
  39. $this->load_config();
  40. $rcube = rcube::get_instance();
  41. if (!$rcube->config->get('emoticons_display', false)) {
  42. return $args;
  43. }
  44. require_once __DIR__ . '/emoticons_engine.php';
  45. $args['body'] = emoticons_engine::text2icons($args['body']);
  46. }
  47. return $args;
  48. }
  49. /**
  50. * 'message_outgoing_body' hook handler to replace image emoticons from TinyMCE
  51. * editor with image attachments.
  52. */
  53. function message_outgoing_body($args)
  54. {
  55. if ($args['type'] == 'html') {
  56. $this->load_config();
  57. $rcube = rcube::get_instance();
  58. if (!$rcube->config->get('emoticons_compose', true)) {
  59. return $args;
  60. }
  61. require_once __DIR__ . '/emoticons_engine.php';
  62. // look for "emoticon" images from TinyMCE and change their src paths to
  63. // be file paths on the server instead of URL paths.
  64. $images = emoticons_engine::replace($args['body']);
  65. // add these images as attachments to the MIME message
  66. foreach ($images as $img_name => $img_file) {
  67. $args['message']->addHTMLImage($img_file, 'image/gif', '', true, $img_name);
  68. }
  69. }
  70. return $args;
  71. }
  72. /**
  73. * 'html2text' hook handler to replace image emoticons from TinyMCE
  74. * editor with plain text emoticons.
  75. *
  76. * This is executed on html2text action, i.e. when switching from HTML to text
  77. * in compose window (or similiar place). Also when generating alternative
  78. * text/plain part.
  79. */
  80. function html2text($args)
  81. {
  82. $rcube = rcube::get_instance();
  83. if ($rcube->action == 'html2text' || $rcube->action == 'send') {
  84. $this->load_config();
  85. if (!$rcube->config->get('emoticons_compose', true)) {
  86. return $args;
  87. }
  88. require_once __DIR__ . '/emoticons_engine.php';
  89. $args['body'] = emoticons_engine::icons2text($args['body']);
  90. }
  91. return $args;
  92. }
  93. /**
  94. * 'html_editor' hook handler, where we enable emoticons in TinyMCE
  95. */
  96. function html_editor($args)
  97. {
  98. $rcube = rcube::get_instance();
  99. $this->load_config();
  100. if ($rcube->config->get('emoticons_compose', true)) {
  101. $args['extra_plugins'][] = 'emoticons';
  102. $args['extra_buttons'][] = 'emoticons';
  103. }
  104. return $args;
  105. }
  106. /**
  107. * 'preferences_list' hook handler
  108. */
  109. function preferences_list($args)
  110. {
  111. $rcube = rcube::get_instance();
  112. $dont_override = $rcube->config->get('dont_override', array());
  113. if ($args['section'] == 'mailview' && !in_array('emoticons_display', $dont_override)) {
  114. $this->load_config();
  115. $this->add_texts('localization');
  116. $field_id = 'emoticons_display';
  117. $checkbox = new html_checkbox(array('name' => '_' . $field_id, 'id' => $field_id, 'value' => 1));
  118. $args['blocks']['main']['options']['emoticons_display'] = array(
  119. 'title' => $this->gettext('emoticonsdisplay'),
  120. 'content' => $checkbox->show(intval($rcube->config->get('emoticons_display', false)))
  121. );
  122. }
  123. else if ($args['section'] == 'compose' && !in_array('emoticons_compose', $dont_override)) {
  124. $this->load_config();
  125. $this->add_texts('localization');
  126. $field_id = 'emoticons_compose';
  127. $checkbox = new html_checkbox(array('name' => '_' . $field_id, 'id' => $field_id, 'value' => 1));
  128. $args['blocks']['main']['options']['emoticons_compose'] = array(
  129. 'title' => $this->gettext('emoticonscompose'),
  130. 'content' => $checkbox->show(intval($rcube->config->get('emoticons_compose', true)))
  131. );
  132. }
  133. return $args;
  134. }
  135. /**
  136. * 'preferences_save' hook handler
  137. */
  138. function preferences_save($args)
  139. {
  140. $rcube = rcube::get_instance();
  141. $dont_override = $rcube->config->get('dont_override', array());
  142. if ($args['section'] == 'mailview' && !in_array('emoticons_display', $dont_override)) {
  143. $args['prefs']['emoticons_display'] = rcube_utils::get_input_value('_emoticons_display', rcube_utils::INPUT_POST) ? true : false;
  144. }
  145. else if ($args['section'] == 'compose' && !in_array('emoticons_compose', $dont_override)) {
  146. $args['prefs']['emoticons_compose'] = rcube_utils::get_input_value('_emoticons_compose', rcube_utils::INPUT_POST) ? true : false;
  147. }
  148. return $args;
  149. }
  150. }