Aleksander Machniak
2015-09-15 c91d4975ffa3bb4e6da907855b77296f34823aa4
commit | author | age
60226a 1 <?php
TB 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/include/rcmail_string_replacer.php                            |
6  |                                                                       |
7  | This file is part of the Roundcube Webmail client                     |
0301d9 8  | Copyright (C) 2012-2013, The Roundcube Dev Team                       |
60226a 9  |                                                                       |
TB 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  *
9ba496 26  * @package Webmail
60226a 27  * @subpackage Utils
TB 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 result from preg_replace_callback
37      * @return int Index of saved string value
38      * @see rcube_string_replacer::mailto_callback()
39      */
40     public function mailto_callback($matches)
41     {
0301d9 42         $href   = $matches[1];
AM 43         $suffix = $this->parse_url_brackets($href);
c91d49 44         $email  = $href;
AM 45
46         if (strpos($email, '?')) {
47             list($email,) = explode('?', $email);
48         }
49
50         // skip invalid emails
51         if (!rcube_utils::check_email($email, false)) {
52             return $matches[1];
53         }
60226a 54
0301d9 55         $i = $this->add(html::a(array(
AM 56             'href'    => 'mailto:' . $href,
57             'onclick' => "return ".rcmail_output::JS_OBJECT_NAME.".command('compose','".rcube::JQ($href)."',this)",
58             ),
59             rcube::Q($href)) . $suffix);
60226a 60
0301d9 61         return $i >= 0 ? $this->get_replacement($i) : '';
60226a 62     }
0301d9 63 }