comparison program/include/rcmail_string_replacer.php @ 0:4681f974d28b

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