Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

rcmail_string_replacer.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 Matches result from preg_replace_callback
  35. *
  36. * @return int Index of saved string value
  37. * @see rcube_string_replacer::mailto_callback()
  38. */
  39. public function mailto_callback($matches)
  40. {
  41. $href = $matches[1];
  42. $suffix = $this->parse_url_brackets($href);
  43. $email = $href;
  44. if (strpos($email, '?')) {
  45. list($email,) = explode('?', $email);
  46. }
  47. // skip invalid emails
  48. if (!rcube_utils::check_email($email, false)) {
  49. return $matches[1];
  50. }
  51. $i = $this->add(html::a(array(
  52. 'href' => 'mailto:' . $href,
  53. 'onclick' => "return ".rcmail_output::JS_OBJECT_NAME.".command('compose','".rcube::JQ($href)."',this)",
  54. ),
  55. rcube::Q($href)) . $suffix);
  56. return $i >= 0 ? $this->get_replacement($i) : '';
  57. }
  58. }