You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rcmail_string_replacer.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/include/rcmail_string_replacer.php |
  5. | |
  6. | This file is part of the Roundcube Webmail client |
  7. | Copyright (C) 2012-2013, The Roundcube Dev Team |
  8. | |
  9. | Licensed under the GNU General Public License version 3 or |
  10. | any later version with exceptions for skins & plugins. |
  11. | See the README file for a full license statement. |
  12. | |
  13. | PURPOSE: |
  14. | Turn URLs and email addresses into clickable links |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. /**
  21. * Helper class for turning URLs and email addresses in plaintext content
  22. * into clickable links.
  23. *
  24. * @package Webmail
  25. * @subpackage Utils
  26. */
  27. class rcmail_string_replacer extends rcube_string_replacer
  28. {
  29. /**
  30. * Callback function used to build mailto: links around e-mail strings
  31. *
  32. * This also adds an onclick-handler to open the Rouncube compose message screen on such links
  33. *
  34. * @param array Matches result from preg_replace_callback
  35. * @return int Index of saved string value
  36. * @see rcube_string_replacer::mailto_callback()
  37. */
  38. public function mailto_callback($matches)
  39. {
  40. $href = $matches[1];
  41. $suffix = $this->parse_url_brackets($href);
  42. $email = $href;
  43. if (strpos($email, '?')) {
  44. list($email,) = explode('?', $email);
  45. }
  46. // skip invalid emails
  47. if (!rcube_utils::check_email($email, false)) {
  48. return $matches[1];
  49. }
  50. $i = $this->add(html::a(array(
  51. 'href' => 'mailto:' . $href,
  52. 'onclick' => "return ".rcmail_output::JS_OBJECT_NAME.".command('compose','".rcube::JQ($href)."',this)",
  53. ),
  54. rcube::Q($href)) . $suffix);
  55. return $i >= 0 ? $this->get_replacement($i) : '';
  56. }
  57. }